1 /*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <gtest/gtest.h>
17 #include <parameters.h>
18 #include "display_info.h"
19 #include "ability_context_impl.h"
20 #include "mock_session.h"
21 #include "window_session_impl.h"
22 #include "mock_uicontent.h"
23 #include "window_scene_session_impl.h"
24 #include "mock_window_adapter.h"
25 #include "singleton_mocker.h"
26
27 using namespace testing;
28 using namespace testing::ext;
29
30 namespace OHOS {
31 namespace Rosen {
32 using Mocker = SingletonMocker<WindowAdapter, MockWindowAdapter>;
33 uint32_t MaxWith = 32;
34
35 class WindowSceneSessionImplTest2 : public testing::Test {
36 public:
37 static void SetUpTestCase();
38 static void TearDownTestCase();
39 void SetUp() override;
40 void TearDown() override;
41
42 std::shared_ptr<AbilityRuntime::AbilityContext> abilityContext_;
43 std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
44
45 private:
46 RSSurfaceNode::SharedPtr CreateRSSurfaceNode();
47 static constexpr uint32_t WAIT_SYNC_IN_NS = 200000;
48 };
49
SetUpTestCase()50 void WindowSceneSessionImplTest2::SetUpTestCase() {}
51
TearDownTestCase()52 void WindowSceneSessionImplTest2::TearDownTestCase() {}
53
SetUp()54 void WindowSceneSessionImplTest2::SetUp()
55 {
56 abilityContext_ = std::make_shared<AbilityRuntime::AbilityContextImpl>();
57 }
58
TearDown()59 void WindowSceneSessionImplTest2::TearDown()
60 {
61 usleep(WAIT_SYNC_IN_NS);
62 abilityContext_ = nullptr;
63 }
64
CreateRSSurfaceNode()65 RSSurfaceNode::SharedPtr WindowSceneSessionImplTest2::CreateRSSurfaceNode()
66 {
67 struct RSSurfaceNodeConfig rsSurfaceNodeConfig;
68 rsSurfaceNodeConfig.SurfaceNodeName = "startingWindowTestSurfaceNode";
69 auto surfaceNode = RSSurfaceNode::Create(rsSurfaceNodeConfig, RSSurfaceNodeType::DEFAULT);
70 return surfaceNode;
71 }
72
73 namespace {
74 /*
75 * @tc.name: SetBackdropBlur
76 * @tc.desc: SetBackdropBlur test
77 * @tc.type: FUNC
78 */
79 HWTEST_F(WindowSceneSessionImplTest2, SetBackdropBlur, Function | SmallTest | Level3)
80 {
81 sptr<WindowOption> option = new (std::nothrow) WindowOption();
82 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
83 window->property_->SetWindowName("SetBackdropBlur");
84 window->property_->SetWindowType(WindowType::SYSTEM_SUB_WINDOW_BASE);
85
86 auto surfaceNode = window->GetSurfaceNode();
87 if (surfaceNode == nullptr) {
88 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->CheckParmAndPermission());
89 } else {
90 ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetBackdropBlur(-1.0));
91 ASSERT_EQ(WMError::WM_OK, window->SetBackdropBlur(1.0));
92 }
93 }
94
95 /*
96 * @tc.name: SetShadowColor
97 * @tc.desc: SetShadowColor test
98 * @tc.type: FUNC
99 */
100 HWTEST_F(WindowSceneSessionImplTest2, SetShadowColor, Function | SmallTest | Level3)
101 {
102 sptr<WindowOption> option = new (std::nothrow) WindowOption();
103 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
104 window->property_->SetWindowName("SetShadowColor");
105 window->property_->SetWindowType(WindowType::SYSTEM_SUB_WINDOW_BASE);
106
107 auto surfaceNode = window->GetSurfaceNode();
108 if (surfaceNode == nullptr) {
109 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->CheckParmAndPermission());
110 } else {
111 ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetShadowColor("111ff22ee44"));
112 ASSERT_EQ(WMError::WM_OK, window->SetShadowColor("#ff22ee44"));
113 ASSERT_EQ(WMError::WM_OK, window->SetShadowColor("#000999"));
114 }
115 }
116
117 /*
118 * @tc.name: SetCornerRadius
119 * @tc.desc: SetCornerRadius test
120 * @tc.type: FUNC
121 */
122 HWTEST_F(WindowSceneSessionImplTest2, SetCornerRadius, Function | SmallTest | Level3)
123 {
124 sptr<WindowOption> option = new (std::nothrow) WindowOption();
125 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
126 window->property_->SetWindowName("SetCornerRadius");
127 window->property_->SetWindowType(WindowType::SYSTEM_SUB_WINDOW_BASE);
128
129 auto surfaceNode = window->GetSurfaceNode();
130 if (surfaceNode == nullptr) {
131 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->SetCornerRadius(1.0));
132 } else {
133 ASSERT_EQ(WMError::WM_OK, window->SetCornerRadius(1.0));
134 }
135 }
136
137 /*
138 * @tc.name: SetShadowRadius
139 * @tc.desc: SetShadowRadius test
140 * @tc.type: FUNC
141 */
142 HWTEST_F(WindowSceneSessionImplTest2, SetShadowRadius, Function | SmallTest | Level3)
143 {
144 sptr<WindowOption> option = new (std::nothrow) WindowOption();
145 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
146 window->property_->SetWindowName("SetShadowRadius");
147 window->property_->SetWindowType(WindowType::SYSTEM_SUB_WINDOW_BASE);
148
149 auto surfaceNode = window->GetSurfaceNode();
150 if (surfaceNode == nullptr) {
151 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->CheckParmAndPermission());
152 } else {
153 ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetShadowRadius(-1.0));
154 ASSERT_EQ(WMError::WM_OK, window->SetShadowRadius(1.0));
155 }
156 }
157
158 /**
159 * @tc.name: SetTransform01
160 * @tc.desc: set transform
161 * @tc.type: FUNC
162 * @tc.require:issueI7IJVV
163 */
164 HWTEST_F(WindowSceneSessionImplTest2, SetTransform01, Function | SmallTest | Level3)
165 {
166 std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
167 sptr<WindowOption> option = new WindowOption();
168 option->SetWindowName("SetTransform01");
169 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
170 ASSERT_NE(nullptr, window);
171 window->property_->SetPersistentId(1);
172 Transform trans_;
173 window->SetTransform(trans_);
174 ASSERT_TRUE(trans_ == window->GetTransform());
175 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy(false));
176 }
177
178 /**
179 * @tc.name: RegisterAnimationTransitionController01
180 * @tc.desc: RegisterAnimationTransitionController
181 * @tc.type: FUNC
182 * @tc.require:issueI7IJVV
183 */
184 HWTEST_F(WindowSceneSessionImplTest2, RegisterAnimationTransitionController01, Function | SmallTest | Level3)
185 {
186 std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
187 sptr<WindowOption> option = new WindowOption();
188 option->SetWindowName("RegisterAnimationTransitionController01");
189 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
190 ASSERT_NE(nullptr, window);
191 window->property_->SetPersistentId(1);
192 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->RegisterAnimationTransitionController(nullptr));
193 }
194
195 /**
196 * @tc.name: SetNeedDefaultAnimation01
197 * @tc.desc: SetNeedDefaultAnimation
198 * @tc.type: FUNC
199 * @tc.require:issueI7IJVV
200 */
201 HWTEST_F(WindowSceneSessionImplTest2, SetNeedDefaultAnimation01, Function | SmallTest | Level3)
202 {
203 std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
204 sptr<WindowOption> option = new WindowOption();
205 option->SetWindowName("SetNeedDefaultAnimation01");
206 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
207 ASSERT_NE(nullptr, window);
208 auto ret = true;
209 window->property_->SetPersistentId(1);
210
211 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
212 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
213 ASSERT_NE(nullptr, session);
214 window->hostSession_ = session;
215 window->SetNeedDefaultAnimation(false);
216 ASSERT_TRUE(ret);
217 }
218
219 /**
220 * @tc.desc: UpdateSurfaceNodeAfterCustomAnimation01
221 * @tc.desc: UpdateSurfaceNodeAfterCustomAnimation
222 * @tc.type: FUNC
223 * @tc.require:issueI7IJVV
224 */
225 HWTEST_F(WindowSceneSessionImplTest2, UpdateSurfaceNodeAfterCustomAnimation, Function | SmallTest | Level3)
226 {
227 std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
228 sptr<WindowOption> option = new WindowOption();
229 option->SetWindowName("UpdateSurfaceNodeAfterCustomAnimation");
230 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
231 ASSERT_NE(nullptr, window);
232
233 window->property_->SetPersistentId(1);
234
235 window->UpdateSurfaceNodeAfterCustomAnimation(false);
236 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->UpdateSurfaceNodeAfterCustomAnimation(false));
237 window->property_->SetPersistentId(1);
238 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
239 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
240 ASSERT_NE(nullptr, session);
241 window->hostSession_ = session;
242 window->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
243 ASSERT_EQ(WMError::WM_ERROR_INVALID_OPERATION, window->UpdateSurfaceNodeAfterCustomAnimation(false));
244 }
245
246 /**
247 * @tc.name: SetAlpha01
248 * @tc.desc: SetAlpha
249 * @tc.type: FUNC
250 */
251 HWTEST_F(WindowSceneSessionImplTest2, SetAlpha01, Function | SmallTest | Level2)
252 {
253 sptr<WindowOption> option = new (std::nothrow) WindowOption();
254 option->SetWindowName("SetAlpha01");
255 option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
256
257 sptr<WindowSceneSessionImpl> windowSceneSession = new (std::nothrow) WindowSceneSessionImpl(option);
258
259 ASSERT_NE(nullptr, windowSceneSession);
260 windowSceneSession->property_->SetPersistentId(11);
261 windowSceneSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
262
263 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, windowSceneSession->SetAlpha(1.0));
264 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
265 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
266 ASSERT_NE(nullptr, session);
267
268 ASSERT_EQ(WMError::WM_OK, windowSceneSession->Create(abilityContext_, session));
269 windowSceneSession->hostSession_ = session;
270
271 auto surfaceNode = windowSceneSession->GetSurfaceNode();
272 if (surfaceNode == nullptr) {
273 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, windowSceneSession->CheckParmAndPermission());
274 } else {
275 ASSERT_EQ(WMError::WM_OK, windowSceneSession->SetAlpha(1.0));
276 }
277 windowSceneSession->Destroy(true);
278 }
279
280 /**
281 * @tc.name: DestroySubWindow01
282 * @tc.desc: DestroySubWindow
283 * @tc.type: FUNC
284 */
285 HWTEST_F(WindowSceneSessionImplTest2, DestroySubWindow01, Function | SmallTest | Level2)
286 {
287 sptr<WindowOption> option = new (std::nothrow) WindowOption();
288 option->SetWindowName("DestroySubWindow01");
289 option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
290
291 sptr<WindowSceneSessionImpl> windowSceneSession = new (std::nothrow) WindowSceneSessionImpl(option);
292
293 ASSERT_NE(nullptr, windowSceneSession);
294 int ret = 0;
295 windowSceneSession->DestroySubWindow();
296 ASSERT_EQ(0, ret);
297 }
298
299 /**
300 * @tc.name: UpdateFloatingWindowSizeBySizeLimits01
301 * @tc.desc: UpdateFloatingWindowSizeBySizeLimits
302 * @tc.type: FUNC
303 */
304 HWTEST_F(WindowSceneSessionImplTest2, UpdateFloatingWindowSizeBySizeLimits01, Function | SmallTest | Level2)
305 {
306 sptr<WindowOption> option = new (std::nothrow) WindowOption();
307 option->SetWindowName("UpdateFloatingWindowSizeBySizeLimits01");
308 option->SetWindowType(WindowType::WINDOW_TYPE_FLOAT_CAMERA);
309
310 sptr<WindowSceneSessionImpl> windowSceneSession = new (std::nothrow) WindowSceneSessionImpl(option);
311 ASSERT_NE(nullptr, windowSceneSession);
312 int ret = 0;
313 windowSceneSession->UpdateFloatingWindowSizeBySizeLimits(MaxWith, MaxWith);
314 ASSERT_EQ(0, ret);
315 }
316
317 /**
318 * @tc.name: UpdateAnimationFlagProperty01
319 * @tc.desc: UpdateAnimationFlagProperty
320 * @tc.type: FUNC
321 */
322 HWTEST_F(WindowSceneSessionImplTest2, UpdateAnimationFlagProperty01, Function | SmallTest | Level2)
323 {
324 sptr<WindowOption> option = new (std::nothrow) WindowOption();
325 option->SetWindowName("UpdateAnimationFlagProperty01");
326 option->SetWindowType(WindowType::SYSTEM_WINDOW_BASE);
327
328 sptr<WindowSceneSessionImpl> windowSceneSession = new (std::nothrow) WindowSceneSessionImpl(option);
329 ASSERT_NE(nullptr, windowSceneSession);
330 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, windowSceneSession->UpdateAnimationFlagProperty(false));
331 }
332
333 /**
334 * @tc.name: UpdateWindowModeImmediately01
335 * @tc.desc: UpdateWindowModeImmediately
336 * @tc.type: FUNC
337 */
338 HWTEST_F(WindowSceneSessionImplTest2, UpdateWindowModeImmediately01, Function | SmallTest | Level2)
339 {
340 sptr<WindowOption> option = new (std::nothrow) WindowOption();
341 option->SetWindowName("UpdateWindowModeImmediately01");
342 option->SetWindowType(WindowType::SYSTEM_WINDOW_BASE);
343
344 sptr<WindowSceneSessionImpl> windowSceneSession = new (std::nothrow) WindowSceneSessionImpl(option);
345 ASSERT_NE(nullptr, windowSceneSession);
346 ASSERT_EQ(WMError::WM_OK, windowSceneSession->UpdateWindowModeImmediately(WindowMode::WINDOW_MODE_UNDEFINED));
347 windowSceneSession->state_ = WindowState::STATE_CREATED;
348 ASSERT_EQ(WMError::WM_OK, windowSceneSession->UpdateWindowModeImmediately(WindowMode::WINDOW_MODE_UNDEFINED));
349 }
350
351 /**
352 * @tc.name: UpdateWindowMode01
353 * @tc.desc: UpdateWindowMode
354 * @tc.type: FUNC
355 */
356 HWTEST_F(WindowSceneSessionImplTest2, UpdateWindowMode01, Function | SmallTest | Level2)
357 {
358 sptr<WindowOption> option = new (std::nothrow) WindowOption();
359 option->SetWindowName("UpdateWindowMode01");
360 option->SetWindowType(WindowType::SYSTEM_WINDOW_BASE);
361
362 sptr<WindowSceneSessionImpl> windowSceneSession = new (std::nothrow) WindowSceneSessionImpl(option);
363 ASSERT_NE(nullptr, windowSceneSession);
364 ASSERT_EQ(WSError::WS_ERROR_INVALID_WINDOW,
365 windowSceneSession->UpdateWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN));
366 windowSceneSession->state_ = WindowState::STATE_CREATED;
367 ASSERT_EQ(WSError::WS_ERROR_INVALID_WINDOW,
368 windowSceneSession->UpdateWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN));
369
370 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
371 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
372 ASSERT_NE(nullptr, session);
373 windowSceneSession->hostSession_ = session;
374 ASSERT_EQ(WSError::WS_ERROR_INVALID_WINDOW,
375 windowSceneSession->UpdateWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN));
376 }
377
378 /**
379 * @tc.name: UpdateWindowMode02
380 * @tc.desc: UpdateWindowMode
381 * @tc.type: FUNC
382 */
383 HWTEST_F(WindowSceneSessionImplTest2, UpdateWindowMode02, Function | SmallTest | Level2)
384 {
385 sptr<WindowOption> option = new (std::nothrow) WindowOption();
386 option->SetWindowName("UpdateWindowMode02");
387 option->SetWindowType(WindowType::SYSTEM_WINDOW_BASE);
388
389 sptr<WindowSceneSessionImpl> windowSceneSession = new (std::nothrow) WindowSceneSessionImpl(option);
390 ASSERT_NE(nullptr, windowSceneSession);
391 ASSERT_EQ(WSError::WS_ERROR_INVALID_WINDOW,
392 windowSceneSession->UpdateWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN));
393 windowSceneSession->state_ = WindowState::STATE_CREATED;
394 ASSERT_EQ(WSError::WS_ERROR_INVALID_WINDOW,
395 windowSceneSession->UpdateWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN));
396
397 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
398 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
399 ASSERT_NE(nullptr, session);
400 windowSceneSession->hostSession_ = session;
401 ASSERT_EQ(WSError::WS_ERROR_INVALID_WINDOW,
402 windowSceneSession->UpdateWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN));
403 windowSceneSession->property_->SetPersistentId(1);
404 ASSERT_EQ(WSError::WS_OK,
405 windowSceneSession->UpdateWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN));
406 }
407
408 /**
409 * @tc.name: RemoveWindowFlag01
410 * @tc.desc: RemoveWindowFlag
411 * @tc.type: FUNC
412 */
413 HWTEST_F(WindowSceneSessionImplTest2, RemoveWindowFlag01, Function | SmallTest | Level2)
414 {
415 sptr<WindowOption> option = new (std::nothrow) WindowOption();
416 option->SetWindowName("RemoveWindowFlag01");
417 option->SetWindowType(WindowType::SYSTEM_WINDOW_BASE);
418
419 sptr<WindowSceneSessionImpl> windowSceneSession = new (std::nothrow) WindowSceneSessionImpl(option);
420 ASSERT_NE(nullptr, windowSceneSession);
421 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW,
422 windowSceneSession->RemoveWindowFlag(WindowFlag::WINDOW_FLAG_NEED_AVOID));
423 windowSceneSession->state_ = WindowState::STATE_CREATED;
424 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW,
425 windowSceneSession->RemoveWindowFlag(WindowFlag::WINDOW_FLAG_NEED_AVOID));
426
427 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
428 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
429 ASSERT_NE(nullptr, session);
430 windowSceneSession->hostSession_ = session;
431 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW,
432 windowSceneSession->RemoveWindowFlag(WindowFlag::WINDOW_FLAG_NEED_AVOID));
433 }
434
435 /**
436 * @tc.name: GetConfigurationFromAbilityInfo01
437 * @tc.desc: GetConfigurationFromAbilityInfo
438 * @tc.type: FUNC
439 */
440 HWTEST_F(WindowSceneSessionImplTest2, GetConfigurationFromAbilityInfo01, Function | SmallTest | Level2)
441 {
442 sptr<WindowOption> option = new (std::nothrow) WindowOption();
443 option->SetWindowName("GetConfigurationFromAbilityInfo01");
444 option->SetWindowType(WindowType::SYSTEM_WINDOW_BASE);
445 sptr<WindowSceneSessionImpl> windowSceneSession = new (std::nothrow) WindowSceneSessionImpl(option);
446 ASSERT_NE(nullptr, windowSceneSession);
447 int ret = 0;
448 windowSceneSession->GetConfigurationFromAbilityInfo();
449 ASSERT_EQ(ret, 0);
450 }
451
452 /**
453 * @tc.name: PreProcessCreate01
454 * @tc.desc: PreProcessCreate
455 * @tc.type: FUNC
456 */
457 HWTEST_F(WindowSceneSessionImplTest2, PreProcessCreate01, Function | SmallTest | Level2)
458 {
459 sptr<WindowOption> option = new (std::nothrow) WindowOption();
460 option->SetWindowName("PreProcessCreate01");
461 option->SetWindowType(WindowType::SYSTEM_WINDOW_BASE);
462 sptr<WindowSceneSessionImpl> windowSceneSession = new (std::nothrow) WindowSceneSessionImpl(option);
463 ASSERT_NE(nullptr, windowSceneSession);
464 int ret = 0;
465 windowSceneSession->PreProcessCreate();
466 ASSERT_EQ(ret, 0);
467 }
468
469 /**
470 * @tc.name: SetDefaultProperty01
471 * @tc.desc: SetDefaultProperty
472 * @tc.type: FUNC
473 */
474 HWTEST_F(WindowSceneSessionImplTest2, SetDefaultProperty01, Function | SmallTest | Level2)
475 {
476 sptr<WindowOption> option = new (std::nothrow) WindowOption();
477 option->SetWindowName("SetDefaultProperty01");
478 option->SetWindowType(WindowType::SYSTEM_WINDOW_BASE);
479 sptr<WindowSceneSessionImpl> windowSceneSession = new (std::nothrow) WindowSceneSessionImpl(option);
480 ASSERT_NE(nullptr, windowSceneSession);
481 int ret = 0;
482 windowSceneSession->SetDefaultProperty();
483 ASSERT_EQ(ret, 0);
484 }
485
486 /**
487 * @tc.name: UpdateConfiguration01
488 * @tc.desc: UpdateConfiguration
489 * @tc.type: FUNC
490 */
491 HWTEST_F(WindowSceneSessionImplTest2, UpdateConfiguration01, Function | SmallTest | Level2)
492 {
493 sptr<WindowOption> option = new (std::nothrow) WindowOption();
494 option->SetWindowName("UpdateConfiguration01");
495 option->SetWindowType(WindowType::SYSTEM_WINDOW_BASE);
496 sptr<WindowSceneSessionImpl> windowSceneSession = new (std::nothrow) WindowSceneSessionImpl(option);
497 ASSERT_NE(nullptr, windowSceneSession);
498 int ret = 0;
499 std::shared_ptr<AppExecFwk::Configuration> configuration;
500 windowSceneSession->UpdateConfiguration(configuration);
501 windowSceneSession->uiContent_ = std::make_unique<Ace::UIContentMocker>();
502 windowSceneSession->UpdateConfiguration(configuration);
503 ASSERT_EQ(ret, 0);
504 }
505
506
507 /**
508 * @tc.name: UpdateConfigurationForAll01
509 * @tc.desc: UpdateConfigurationForAll
510 * @tc.type: FUNC
511 */
512 HWTEST_F(WindowSceneSessionImplTest2, UpdateConfigurationForAll01, Function | SmallTest | Level2)
513 {
514 sptr<WindowOption> option = new (std::nothrow) WindowOption();
515 option->SetWindowName("UpdateConfigurationForAll01");
516 option->SetWindowType(WindowType::SYSTEM_WINDOW_BASE);
517 sptr<WindowSceneSessionImpl> windowSceneSession = new (std::nothrow) WindowSceneSessionImpl(option);
518 ASSERT_NE(nullptr, windowSceneSession);
519 int ret = 0;
520 std::shared_ptr<AppExecFwk::Configuration> configuration;
521 windowSceneSession->UpdateConfigurationForAll(configuration);
522 ASSERT_EQ(ret, 0);
523 }
524
525 /**
526 * @tc.name: GetTopWindowWithContext01
527 * @tc.desc: GetTopWindowWithContext
528 * @tc.type: FUNC
529 */
530 HWTEST_F(WindowSceneSessionImplTest2, GetTopWindowWithContext01, Function | SmallTest | Level2)
531 {
532 sptr<WindowOption> option = new (std::nothrow) WindowOption();
533 option->SetWindowName("GetTopWindowWithContext01");
534 option->SetWindowType(WindowType::SYSTEM_WINDOW_BASE);
535 std::shared_ptr<AbilityRuntime::Context> context;
536 sptr<WindowSceneSessionImpl> windowSceneSession = new (std::nothrow) WindowSceneSessionImpl(option);
537 ASSERT_NE(nullptr, windowSceneSession);
538 if (windowSceneSession->GetTopWindowWithContext(context) == nullptr) {
539 ASSERT_EQ(nullptr, windowSceneSession->GetTopWindowWithContext(context));
540 }
541 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
542 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
543 ASSERT_NE(nullptr, session);
544 ASSERT_EQ(WMError::WM_OK, windowSceneSession->Create(abilityContext_, session));
545 windowSceneSession->GetTopWindowWithContext(context);
546 windowSceneSession->Destroy(true);
547 }
548
549 /**
550 * @tc.name: GetMainWindowWithContext01
551 * @tc.desc: GetMainWindowWithContext
552 * @tc.type: FUNC
553 */
554 HWTEST_F(WindowSceneSessionImplTest2, GetMainWindowWithContext01, Function | SmallTest | Level2)
555 {
556 sptr<WindowOption> option = new (std::nothrow) WindowOption();
557 option->SetWindowName("GetMainWindowWithContext01");
558 option->SetWindowType(WindowType::SYSTEM_WINDOW_BASE);
559 std::shared_ptr<AbilityRuntime::Context> context;
560 sptr<WindowSceneSessionImpl> windowSceneSession = new (std::nothrow) WindowSceneSessionImpl(option);
561 ASSERT_NE(nullptr, windowSceneSession);
562 if (windowSceneSession->GetMainWindowWithContext(context) == nullptr) {
563 ASSERT_EQ(nullptr, windowSceneSession->GetMainWindowWithContext(context));
564 }
565 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
566 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
567 ASSERT_NE(nullptr, session);
568 ASSERT_EQ(WMError::WM_OK, windowSceneSession->Create(abilityContext_, session));
569 windowSceneSession->GetMainWindowWithContext(context);
570 windowSceneSession->Destroy(true);
571 }
572
573 /**
574 * @tc.name: NotifyMemoryLevel01
575 * @tc.desc: NotifyMemoryLevel
576 * @tc.type: FUNC
577 */
578 HWTEST_F(WindowSceneSessionImplTest2, NotifyMemoryLevel01, Function | SmallTest | Level2)
579 {
580 sptr<WindowOption> option = new (std::nothrow) WindowOption();
581 option->SetWindowName("NotifyMemoryLevel01");
582 option->SetWindowType(WindowType::SYSTEM_WINDOW_BASE);
583 sptr<WindowSceneSessionImpl> windowSceneSession = new (std::nothrow) WindowSceneSessionImpl(option);
584 ASSERT_NE(nullptr, windowSceneSession);
585 std::shared_ptr<AppExecFwk::Configuration> configuration;
586 windowSceneSession->NotifyMemoryLevel(2);
587 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, windowSceneSession->NotifyMemoryLevel(2));
588 windowSceneSession->uiContent_ = std::make_unique<Ace::UIContentMocker>();
589 ASSERT_EQ(WMError::WM_OK, windowSceneSession->NotifyMemoryLevel(2));
590 }
591
592 /**
593 * @tc.name: GetSystemSizeLimits01
594 * @tc.desc: GetSystemSizeLimits
595 * @tc.type: FUNC
596 */
597 HWTEST_F(WindowSceneSessionImplTest2, GetSystemSizeLimits01, Function | SmallTest | Level2)
598 {
599 constexpr uint32_t minMainWidth = 10;
600 constexpr uint32_t minMainHeight = 20;
601 constexpr uint32_t minSubWidth = 30;
602 constexpr uint32_t minSubHeight = 40;
603 constexpr uint32_t displayWidth = 100;
604 constexpr uint32_t displayHeight = 100;
605 constexpr float displayVpr = 1;
606
607 sptr<WindowOption> option = new (std::nothrow) WindowOption();
608 option->SetWindowName("GetSystemSizeLimits01");
609 option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
610
611 sptr<WindowSceneSessionImpl> windowSceneSession = new (std::nothrow) WindowSceneSessionImpl(option);
612
613 ASSERT_NE(nullptr, windowSceneSession);
614 windowSceneSession->windowSystemConfig_.miniWidthOfMainWindow_ = minMainWidth;
615 windowSceneSession->windowSystemConfig_.miniHeightOfMainWindow_ = minMainHeight;
616 windowSceneSession->windowSystemConfig_.miniWidthOfSubWindow_ = minSubWidth;
617 windowSceneSession->windowSystemConfig_.miniHeightOfSubWindow_ = minSubHeight;
618
619 WindowLimits limits = windowSceneSession->GetSystemSizeLimits(displayWidth, displayHeight, displayVpr);
620 ASSERT_EQ(limits.minWidth_, minMainWidth);
621 ASSERT_EQ(limits.minHeight_, minMainHeight);
622
623 windowSceneSession->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
624 limits = windowSceneSession->GetSystemSizeLimits(displayWidth, displayHeight, displayVpr);
625 ASSERT_EQ(limits.minWidth_, minMainWidth);
626 ASSERT_EQ(limits.minHeight_, minMainHeight);
627
628 windowSceneSession->SetWindowType(WindowType::SYSTEM_WINDOW_BASE);
629 limits = windowSceneSession->GetSystemSizeLimits(displayWidth, displayHeight, displayVpr);
630 ASSERT_EQ(limits.minWidth_, minMainWidth);
631 ASSERT_EQ(limits.minHeight_, minMainHeight);
632 }
633
634 /**
635 * @tc.name: DumpSessionElementInfo
636 * @tc.desc: DumpSessionElementInfo 1: params num
637 * @tc.type: FUNC
638 */
639 HWTEST_F(WindowSceneSessionImplTest2, DumpSessionElementInfo1, Function | SmallTest | Level2)
640 {
641 sptr<WindowOption> option = new (std::nothrow) WindowOption();
642 option->SetWindowName("DumpSessionElementInfo1");
643 option->SetWindowType(WindowType::SYSTEM_WINDOW_BASE);
644 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
645 ASSERT_NE(nullptr, window);
646 std::vector<std::string> params;
647 params.push_back("-h");
648 window->DumpSessionElementInfo(params);
649 window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
650 ASSERT_EQ(WMError::WM_OK, window->NotifyMemoryLevel(2));
651 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy(false));
652 }
653
654 /**
655 * @tc.name: DumpSessionElementInfo
656 * @tc.desc: DumpSessionElementInfo2
657 * @tc.type: FUNC
658 */
659 HWTEST_F(WindowSceneSessionImplTest2, DumpSessionElementInfo2, Function | SmallTest | Level2)
660 {
661 sptr<WindowOption> option = new (std::nothrow) WindowOption();
662 option->SetWindowName("DumpSessionElementInfo2");
663 option->SetWindowType(WindowType::SYSTEM_WINDOW_BASE);
664 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
665 ASSERT_NE(nullptr, window);
666 std::vector<std::string> params;
667 params.push_back("-h");
668 window->DumpSessionElementInfo(params);
669 params.push_back("-s");
670 window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
671 window->DumpSessionElementInfo(params);
672 ASSERT_EQ(WMError::WM_OK, window->NotifyMemoryLevel(2));
673 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy(false));
674 }
675
676 /**
677 * @tc.name: DumpSessionElementInfo
678 * @tc.desc: DumpSessionElementInfo3
679 * @tc.type: FUNC
680 */
681 HWTEST_F(WindowSceneSessionImplTest2, DumpSessionElementInfo3, Function | SmallTest | Level2)
682 {
683 sptr<WindowOption> option = new (std::nothrow) WindowOption();
684 option->SetWindowName("DumpSessionElementInfo3");
685 option->SetWindowType(WindowType::SYSTEM_WINDOW_BASE);
686 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
687 ASSERT_NE(nullptr, window);
688 std::vector<std::string> params;
689 params.push_back("-s");
690 window->DumpSessionElementInfo(params);
691 window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
692 ASSERT_EQ(WMError::WM_OK, window->NotifyMemoryLevel(2));
693 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy(false));
694 }
695
696 /**
697 * @tc.name: DisableAppWindowDecor02
698 * @tc.desc: DisableAppWindowDecor
699 * @tc.type: FUNC
700 */
701 HWTEST_F(WindowSceneSessionImplTest2, DisableAppWindowDecor02, Function | SmallTest | Level2)
702 {
703 sptr<WindowOption> option = new (std::nothrow) WindowOption();
704 option->SetWindowName("DisableAppWindowDecor02");
705 option->SetWindowType(WindowType::SYSTEM_WINDOW_BASE);
706 sptr<WindowSceneSessionImpl> windowSceneSession = new (std::nothrow) WindowSceneSessionImpl(option);
707 ASSERT_NE(nullptr, windowSceneSession);
708 int ret = 0;
709 windowSceneSession->DisableAppWindowDecor();
710 ASSERT_EQ(ret, 0);
711 }
712
713 /**
714 * @tc.name: RaiseAboveTarget01
715 * @tc.desc: RaiseAboveTarget
716 * @tc.type: FUNC
717 */
718 HWTEST_F(WindowSceneSessionImplTest2, RaiseAboveTarget01, Function | SmallTest | Level2)
719 {
720 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
721 ASSERT_NE(nullptr, option);
722 option->SetWindowName("RaiseAboveTarget01");
723 sptr<WindowSceneSessionImpl> windowSceneSessionImpl = sptr<WindowSceneSessionImpl>::MakeSptr(option);
724 ASSERT_NE(nullptr, windowSceneSessionImpl);
725
726 ASSERT_NE(nullptr, windowSceneSessionImpl->property_);
727 windowSceneSessionImpl->property_->SetPersistentId(6);
728 ASSERT_NE(nullptr, windowSceneSessionImpl->property_);
729 windowSceneSessionImpl->property_->SetParentPersistentId(0);
730 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
731 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
732 windowSceneSessionImpl->hostSession_ = session;
733 auto ret = windowSceneSessionImpl->RaiseAboveTarget(1);
734 EXPECT_EQ(WMError::WM_ERROR_INVALID_PARENT, ret);
735
736 windowSceneSessionImpl->property_->SetParentPersistentId(1);
737 ret = windowSceneSessionImpl->RaiseAboveTarget(1);
738 EXPECT_EQ(WMError::WM_ERROR_INVALID_PARAM, ret);
739
740 sptr<WindowSessionImpl> winSession = sptr<WindowSessionImpl>::MakeSptr(option);
741 WindowSessionImpl::subWindowSessionMap_.insert(
742 std::make_pair<int32_t, std::vector<sptr<WindowSessionImpl>>>(1, {winSession}));
743 winSession->property_->SetPersistentId(6);
744 windowSceneSessionImpl->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
745 ret = windowSceneSessionImpl->RaiseAboveTarget(6);
746 EXPECT_EQ(WMError::WM_ERROR_INVALID_CALLING, ret);
747
748 winSession->state_ = WindowState::STATE_CREATED;
749 windowSceneSessionImpl->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
750 ret = windowSceneSessionImpl->RaiseAboveTarget(6);
751 EXPECT_EQ(WMError::WM_DO_NOTHING, ret);
752
753 windowSceneSessionImpl->state_ = WindowState::STATE_SHOWN;
754 winSession->state_ = WindowState::STATE_SHOWN;
755 ret = windowSceneSessionImpl->RaiseAboveTarget(6);
756 EXPECT_EQ(WMError::WM_OK, ret);
757
758 windowSceneSessionImpl->property_->SetPersistentId(3);
759 ret = windowSceneSessionImpl->RaiseAboveTarget(6);
760 EXPECT_EQ(WMError::WM_OK, ret);
761
762 WindowSessionImpl::subWindowSessionMap_.erase(1);
763 }
764
765 /**
766 * @tc.name: FindParentSessionByParentId02
767 * @tc.desc: FindParentSessionByParentId
768 * @tc.type: FUNC
769 */
770 HWTEST_F(WindowSceneSessionImplTest2, FindParentSessionByParentId02, Function | SmallTest | Level2)
771 {
772 sptr<WindowOption> option = new (std::nothrow) WindowOption();
773 option->SetWindowTag(WindowTag::MAIN_WINDOW);
774 option->SetWindowName("FindParentSessionByParentId02");
775 sptr<WindowSceneSessionImpl> parentSceneSession = new (std::nothrow) WindowSceneSessionImpl(option);
776 ASSERT_NE(nullptr, parentSceneSession);
777
778 ASSERT_EQ(nullptr, parentSceneSession->FindParentSessionByParentId(-1));
779 }
780
781 /**
782 * @tc.name: GetConfigurationFromAbilityInfo02
783 * @tc.desc: GetConfigurationFromAbilityInfo
784 * @tc.type: FUNC
785 */
786 HWTEST_F(WindowSceneSessionImplTest2, GetConfigurationFromAbilityInfo02, Function | SmallTest | Level2)
787 {
788 sptr<WindowOption> option = new (std::nothrow) WindowOption();
789 option->SetWindowName("GetConfigurationFromAbilityInfo02");
790 option->SetWindowType(WindowType::SYSTEM_WINDOW_BASE);
791 sptr<WindowSceneSessionImpl> windowSceneSession = new (std::nothrow) WindowSceneSessionImpl(option);
792 ASSERT_NE(nullptr, windowSceneSession);
793 int ret = 0;
794 windowSceneSession->GetConfigurationFromAbilityInfo();
795 ASSERT_EQ(ret, 0);
796 }
797
798 /**
799 * @tc.name: NotifyWindowSessionProperty01
800 * @tc.desc: NotifyWindowSessionProperty
801 * @tc.type: FUNC
802 */
803 HWTEST_F(WindowSceneSessionImplTest2, NotifyWindowSessionProperty01, Function | SmallTest | Level2)
804 {
805 sptr<WindowOption> option = new (std::nothrow) WindowOption();
806 option->SetWindowName("NotifyWindowSessionProperty01");
807 option->SetWindowType(WindowType::SYSTEM_WINDOW_BASE);
808 sptr<WindowSceneSessionImpl> windowSceneSession = new (std::nothrow) WindowSceneSessionImpl(option);
809 ASSERT_NE(nullptr, windowSceneSession);
810 int ret = 0;
811 windowSceneSession->NotifyWindowSessionProperty();
812 ASSERT_EQ(ret, 0);
813 }
814
815 HWTEST_F(WindowSceneSessionImplTest2, IsTransparent01, Function | SmallTest | Level2)
816 {
817 sptr<WindowOption> option = new (std::nothrow) WindowOption();
818 option->SetWindowName("IsTransparent01");
819 option->SetWindowType(WindowType::SYSTEM_WINDOW_BASE);
820 sptr<WindowSceneSessionImpl> windowSceneSession = new (std::nothrow) WindowSceneSessionImpl(option);
821 ASSERT_NE(nullptr, windowSceneSession);
822 int ret = 0;
823 windowSceneSession->IsTransparent();
824 ASSERT_EQ(ret, 0);
825 }
826
827 /**
828 * @tc.name: SetTransparent02
829 * @tc.desc: SetTransparent
830 * @tc.type: FUNC
831 */
832 HWTEST_F(WindowSceneSessionImplTest2, SetTransparent02, Function | SmallTest | Level2)
833 {
834 sptr<WindowOption> option = new (std::nothrow) WindowOption();
835 option->SetWindowName("SetTransparent02");
836 option->SetWindowType(WindowType::SYSTEM_WINDOW_BASE);
837 sptr<WindowSceneSessionImpl> windowSceneSession = new (std::nothrow) WindowSceneSessionImpl(option);
838 ASSERT_NE(nullptr, windowSceneSession);
839 int ret = 0;
840 bool isTransparent = false;
841 windowSceneSession->SetTransparent(isTransparent);
842 ASSERT_EQ(ret, 0);
843 }
844
845 /**
846 * @tc.name: Snapshot01
847 * @tc.desc: Snapshot
848 * @tc.type: FUNC
849 */
850 HWTEST_F(WindowSceneSessionImplTest2, Snapshot01, Function | SmallTest | Level2)
851 {
852 sptr<WindowOption> option = new (std::nothrow) WindowOption();
853 option->SetWindowName("Snapshot01");
854 option->SetWindowType(WindowType::SYSTEM_WINDOW_BASE);
855 sptr<WindowSceneSessionImpl> windowSceneSession = new (std::nothrow) WindowSceneSessionImpl(option);
856 ASSERT_NE(nullptr, windowSceneSession);
857 int ret = 0;
858 windowSceneSession->Snapshot();
859 ASSERT_EQ(ret, 0);
860 }
861
862 /**
863 * @tc.name: BindDialogTarget01
864 * @tc.desc: BindDialogTarget
865 * @tc.type: FUNC
866 */
867 HWTEST_F(WindowSceneSessionImplTest2, BindDialogTarget01, Function | SmallTest | Level2)
868 {
869 sptr<WindowOption> option = new (std::nothrow) WindowOption();
870 option->SetWindowName("BindDialogTarget01");
871 option->SetWindowType(WindowType::SYSTEM_WINDOW_BASE);
872 sptr<WindowSceneSessionImpl> windowSceneSession = new (std::nothrow) WindowSceneSessionImpl(option);
873 ASSERT_NE(nullptr, windowSceneSession);
874 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
875 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
876 ASSERT_NE(nullptr, session);
877 windowSceneSession->property_->SetPersistentId(1);
878 windowSceneSession->hostSession_ = session;
879 sptr<IRemoteObject> targetToken;
880 WMError ret = windowSceneSession->BindDialogTarget(targetToken);
881 ASSERT_EQ(ret, WMError::WM_OK);
882 }
883
884 /**
885 * @tc.name: SetDialogBackGestureEnabled01
886 * @tc.desc: SetDialogBackGestureEnabled
887 * @tc.type: FUNC
888 */
889 HWTEST_F(WindowSceneSessionImplTest2, SetDialogBackGestureEnabled01, Function | SmallTest | Level2)
890 {
891 sptr<WindowOption> option = new (std::nothrow) WindowOption();
892 ASSERT_NE(nullptr, option);
893 option->SetWindowName("SetDialogBackGestureEnabled01");
894 option->SetWindowType(WindowType::SYSTEM_WINDOW_BASE);
895 sptr<WindowSceneSessionImpl> windowSceneSession = new (std::nothrow) WindowSceneSessionImpl(option);
896 ASSERT_NE(nullptr, windowSceneSession);
897 WMError ret = windowSceneSession->SetDialogBackGestureEnabled(true);
898 ASSERT_EQ(ret, WMError::WM_ERROR_INVALID_CALLING);
899 }
900
901 /**
902 * @tc.name: SetDialogBackGestureEnabled02
903 * @tc.desc: SetDialogBackGestureEnabled
904 * @tc.type: FUNC
905 */
906 HWTEST_F(WindowSceneSessionImplTest2, SetDialogBackGestureEnabled02, Function | SmallTest | Level2)
907 {
908 sptr<WindowOption> option = new (std::nothrow) WindowOption();
909 ASSERT_NE(nullptr, option);
910 option->SetWindowName("SetDialogBackGestureEnabled02");
911 option->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
912 sptr<WindowSceneSessionImpl> windowSceneSession = new (std::nothrow) WindowSceneSessionImpl(option);
913 ASSERT_NE(nullptr, windowSceneSession);
914
915 WMError ret = windowSceneSession->SetDialogBackGestureEnabled(true);
916 ASSERT_EQ(ret, WMError::WM_ERROR_NULLPTR);
917 }
918
919 /**
920 * @tc.name: NotifySessionForeground
921 * @tc.desc: NotifySessionForeground
922 * @tc.type: FUNC
923 */
924 HWTEST_F(WindowSceneSessionImplTest2, NotifySessionForeground, Function | SmallTest | Level2)
925 {
926 sptr<WindowOption> option = new (std::nothrow) WindowOption();
927 option->SetWindowName("NotifySessionForeground");
928 option->SetWindowType(WindowType::SYSTEM_WINDOW_BASE);
929 sptr<WindowSceneSessionImpl> windowSceneSession = new (std::nothrow) WindowSceneSessionImpl(option);
930 ASSERT_NE(nullptr, windowSceneSession);
931
932 uint32_t reason = 1;
933 bool withAnimation = true;
934 windowSceneSession->NotifySessionForeground(reason, withAnimation);
935 }
936
937 /**
938 * @tc.name: NotifySessionBackground
939 * @tc.desc: NotifySessionBackground
940 * @tc.type: FUNC
941 */
942 HWTEST_F(WindowSceneSessionImplTest2, NotifySessionBackground, Function | SmallTest | Level2)
943 {
944 sptr<WindowOption> option = new (std::nothrow) WindowOption();
945 option->SetWindowName("NotifySessionBackground");
946 option->SetWindowType(WindowType::SYSTEM_WINDOW_BASE);
947 sptr<WindowSceneSessionImpl> windowSceneSession = new (std::nothrow) WindowSceneSessionImpl(option);
948 ASSERT_NE(nullptr, windowSceneSession);
949
950 uint32_t reason = 1;
951 bool withAnimation = true;
952 bool isFromInnerkits = true;
953 windowSceneSession->NotifySessionBackground(reason, withAnimation, isFromInnerkits);
954 }
955
956 /**
957 * @tc.name: NotifySessionFullScreen
958 * @tc.desc: NotifySessionFullScreen
959 * @tc.type: FUNC
960 */
961 HWTEST_F(WindowSceneSessionImplTest2, NotifySessionFullScreen, Function | SmallTest | Level2)
962 {
963 sptr<WindowOption> option = new (std::nothrow) WindowOption();
964 ASSERT_NE(nullptr, option);
965 option->SetWindowName("NotifySessionFullScreen");
966 option->SetWindowType(WindowType::SYSTEM_WINDOW_BASE);
967 sptr<WindowSceneSessionImpl> windowSceneSession = new (std::nothrow) WindowSceneSessionImpl(option);
968 ASSERT_NE(nullptr, windowSceneSession);
969
970 bool fullScreen = true;
971 windowSceneSession->NotifySessionFullScreen(fullScreen);
972 }
973
974 /**
975 * @tc.name: NotifyPrepareClosePiPWindow01
976 * @tc.desc: NotifyPrepareClosePiPWindow
977 * @tc.type: FUNC
978 */
979 HWTEST_F(WindowSceneSessionImplTest2, NotifyPrepareClosePiPWindow01, Function | SmallTest | Level2)
980 {
981 sptr<WindowOption> option = new (std::nothrow) WindowOption();
982 option->SetWindowName("NotifyPrepareClosePiPWindow01");
983 option->SetWindowType(WindowType::WINDOW_TYPE_PIP);
984 sptr<WindowSceneSessionImpl> windowSceneSession = new (std::nothrow) WindowSceneSessionImpl(option);
985 ASSERT_NE(nullptr, windowSceneSession);
986 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
987 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
988 ASSERT_NE(nullptr, session);
989 windowSceneSession->hostSession_ = session;
990 ASSERT_EQ(WMError::WM_OK, windowSceneSession->NotifyPrepareClosePiPWindow());
991 }
992
993 /**
994 * @tc.name: SetDefaultDensityEnabled01
995 * @tc.desc: normal test
996 * @tc.type: FUNC
997 */
998 HWTEST_F(WindowSceneSessionImplTest2, SetDefaultDensityEnabled01, Function | SmallTest | Level2)
999 {
1000 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1001 option->SetWindowName("SetDefaultDensityEnabled01");
1002 option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1003 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
1004 ASSERT_NE(nullptr, window);
1005
1006 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
1007 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1008 ASSERT_NE(nullptr, session);
1009 window->property_->SetPersistentId(1);
1010 window->hostSession_ = session;
1011 window->state_ = WindowState::STATE_SHOWN;
1012 window->property_->SetDisplayId(0);
1013
1014 WindowSceneSessionImpl::windowSessionMap_.insert(std::make_pair(window->GetWindowName(),
1015 std::pair<uint64_t, sptr<WindowSessionImpl>>(window->GetWindowId(), window)));
1016 ASSERT_EQ(WMError::WM_OK, window->SetDefaultDensityEnabled(true));
1017 ASSERT_EQ(true, window->GetDefaultDensityEnabled());
1018 WindowSceneSessionImpl::windowSessionMap_.erase(window->GetWindowName());
1019 }
1020
1021 /**
1022 * @tc.name: SetDefaultDensityEnabled02
1023 * @tc.desc: window session is invalid
1024 * @tc.type: FUNC
1025 */
1026 HWTEST_F(WindowSceneSessionImplTest2, SetDefaultDensityEnabled02, Function | SmallTest | Level2)
1027 {
1028 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1029 option->SetWindowName("SetDefaultDensityEnabled02");
1030 option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1031 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
1032 ASSERT_NE(nullptr, window);
1033 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
1034 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1035 ASSERT_NE(nullptr, session);
1036 window->property_->SetPersistentId(1);
1037 window->state_ = WindowState::STATE_SHOWN;
1038 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->SetDefaultDensityEnabled(true));
1039 }
1040
1041 /**
1042 * @tc.name: SetDefaultDensityEnabled03
1043 * @tc.desc: not app main window
1044 * @tc.type: FUNC
1045 */
1046 HWTEST_F(WindowSceneSessionImplTest2, SetDefaultDensityEnabled03, Function | SmallTest | Level2)
1047 {
1048 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1049 option->SetWindowName("SetDefaultDensityEnabled03");
1050 option->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
1051 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
1052 ASSERT_NE(nullptr, window);
1053 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
1054 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1055 ASSERT_NE(nullptr, session);
1056 window->property_->SetPersistentId(1);
1057 window->hostSession_ = session;
1058 window->state_ = WindowState::STATE_SHOWN;
1059 ASSERT_EQ(WMError::WM_ERROR_INVALID_CALLING, window->SetDefaultDensityEnabled(true));
1060 }
1061
1062 /**
1063 * @tc.name: SetDefaultDensityEnabled04
1064 * @tc.desc: isDefaultDensityEnabled_ not change
1065 * @tc.type: FUNC
1066 */
1067 HWTEST_F(WindowSceneSessionImplTest2, SetDefaultDensityEnabled04, Function | SmallTest | Level2)
1068 {
1069 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1070 option->SetWindowName("SetDefaultDensityEnabled04");
1071 option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1072 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
1073 ASSERT_NE(nullptr, window);
1074 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
1075 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1076 ASSERT_NE(nullptr, session);
1077 window->property_->SetPersistentId(1);
1078 window->hostSession_ = session;
1079 window->state_ = WindowState::STATE_SHOWN;
1080 ASSERT_EQ(WMError::WM_OK, window->SetDefaultDensityEnabled(false));
1081 }
1082
1083 /**
1084 * @tc.name: GetDefaultDensityEnabled01
1085 * @tc.desc: normal test
1086 * @tc.type: FUNC
1087 */
1088 HWTEST_F(WindowSceneSessionImplTest2, GetDefaultDensityEnabled01, Function | SmallTest | Level2)
1089 {
1090 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1091 option->SetWindowName("GetDefaultDensityEnabled01");
1092 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
1093 window->isDefaultDensityEnabled_ = true;
1094 ASSERT_EQ(true, window->GetDefaultDensityEnabled());
1095 }
1096
1097 /**
1098 * @tc.name: GetDefaultDensityEnabled02
1099 * @tc.desc: test default value
1100 * @tc.type: FUNC
1101 */
1102 HWTEST_F(WindowSceneSessionImplTest2, GetDefaultDensityEnabled02, Function | SmallTest | Level2)
1103 {
1104 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1105 option->SetWindowName("GetDefaultDensityEnabled02");
1106 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
1107 ASSERT_EQ(false, window->GetDefaultDensityEnabled());
1108 }
1109
1110 /**
1111 * @tc.name: GetVirtualPixelRatio01
1112 * @tc.desc: main window isDefaultDensityEnabled_ true
1113 * @tc.type: FUNC
1114 */
1115 HWTEST_F(WindowSceneSessionImplTest2, GetVirtualPixelRatio01, Function | SmallTest | Level2)
1116 {
1117 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1118 option->SetWindowName("GetVirtualPixelRatio01");
1119 option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1120 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
1121 ASSERT_NE(nullptr, window);
1122
1123 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
1124 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1125 ASSERT_NE(nullptr, session);
1126 window->property_->SetPersistentId(1);
1127 window->hostSession_ = session;
1128 window->state_ = WindowState::STATE_SHOWN;
1129 window->property_->SetDisplayId(0);
1130
1131 window->isDefaultDensityEnabled_ = true;
1132 sptr<DisplayInfo> displayInfo = new DisplayInfo();
1133 auto defautDensity = 1.0f;
1134 auto density = 2.0f;
1135 displayInfo->SetDefaultVirtualPixelRatio(defautDensity);
1136 displayInfo->SetVirtualPixelRatio(density);
1137 ASSERT_EQ(defautDensity, window->GetVirtualPixelRatio(displayInfo));
1138 }
1139
1140 /**
1141 * @tc.name: GetVirtualPixelRatio02
1142 * @tc.desc: main window isDefaultDensityEnabled_ false
1143 * @tc.type: FUNC
1144 */
1145 HWTEST_F(WindowSceneSessionImplTest2, GetVirtualPixelRatio02, Function | SmallTest | Level2)
1146 {
1147 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1148 option->SetWindowName("GetVirtualPixelRatio02");
1149 option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1150 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
1151 ASSERT_NE(nullptr, window);
1152
1153 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
1154 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1155 ASSERT_NE(nullptr, session);
1156 window->property_->SetPersistentId(1);
1157 window->hostSession_ = session;
1158 window->state_ = WindowState::STATE_SHOWN;
1159 window->property_->SetDisplayId(0);
1160
1161 window->isDefaultDensityEnabled_ = false;
1162 sptr<DisplayInfo> displayInfo = new DisplayInfo();
1163 auto defautDensity = 1.0f;
1164 auto density = 2.0f;
1165 displayInfo->SetDefaultVirtualPixelRatio(defautDensity);
1166 displayInfo->SetVirtualPixelRatio(density);
1167 ASSERT_EQ(density, window->GetVirtualPixelRatio(displayInfo));
1168 }
1169
1170 /**
1171 * @tc.name: GetVirtualPixelRatio03
1172 * @tc.desc: sub window isDefaultDensityEnabled_ true
1173 * @tc.type: FUNC
1174 */
1175 HWTEST_F(WindowSceneSessionImplTest2, GetVirtualPixelRatio03, Function | SmallTest | Level2)
1176 {
1177 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1178 option->SetWindowName("GetVirtualPixelRatio03");
1179 option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1180 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
1181 ASSERT_NE(nullptr, window);
1182
1183 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
1184 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1185 ASSERT_NE(nullptr, session);
1186 window->property_->SetPersistentId(1);
1187 window->hostSession_ = session;
1188 window->state_ = WindowState::STATE_SHOWN;
1189 window->property_->SetDisplayId(0);
1190
1191 window->isDefaultDensityEnabled_ = true;
1192 sptr<DisplayInfo> displayInfo = new DisplayInfo();
1193 auto defautDensity = 1.0f;
1194 auto density = 2.0f;
1195 displayInfo->SetDefaultVirtualPixelRatio(defautDensity);
1196 displayInfo->SetVirtualPixelRatio(density);
1197
1198 sptr<WindowOption> subOption = new (std::nothrow) WindowOption();
1199 subOption->SetWindowName("GetVirtualPixelRatio03SubWindow");
1200 subOption->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
1201 sptr<WindowSceneSessionImpl> subWindow = new (std::nothrow) WindowSceneSessionImpl(subOption);
1202 ASSERT_NE(nullptr, subWindow);
1203 subWindow->property_->SetParentPersistentId(window->GetWindowId());
1204
1205 WindowSceneSessionImpl::windowSessionMap_.insert(std::make_pair(window->GetWindowName(),
1206 std::pair<uint64_t, sptr<WindowSessionImpl>>(window->GetWindowId(), window)));
1207 ASSERT_EQ(defautDensity, subWindow->GetVirtualPixelRatio(displayInfo));
1208 WindowSceneSessionImpl::windowSessionMap_.erase(window->GetWindowName());
1209 }
1210
1211 /**
1212 * @tc.name: GetVirtualPixelRatio04
1213 * @tc.desc: sub window isDefaultDensityEnabled_ false
1214 * @tc.type: FUNC
1215 */
1216 HWTEST_F(WindowSceneSessionImplTest2, GetVirtualPixelRatio04, Function | SmallTest | Level2)
1217 {
1218 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1219 option->SetWindowName("GetVirtualPixelRatio04");
1220 option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1221 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
1222 ASSERT_NE(nullptr, window);
1223
1224 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
1225 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1226 ASSERT_NE(nullptr, session);
1227 window->property_->SetPersistentId(1);
1228 window->hostSession_ = session;
1229 window->state_ = WindowState::STATE_SHOWN;
1230 window->property_->SetDisplayId(0);
1231
1232 window->isDefaultDensityEnabled_ = false;
1233 sptr<DisplayInfo> displayInfo = new DisplayInfo();
1234 auto defautDensity = 1.0f;
1235 auto density = 2.0f;
1236 displayInfo->SetDefaultVirtualPixelRatio(defautDensity);
1237 displayInfo->SetVirtualPixelRatio(density);
1238
1239 sptr<WindowOption> subOption = new (std::nothrow) WindowOption();
1240 subOption->SetWindowName("GetVirtualPixelRatio04SubWindow");
1241 subOption->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
1242 sptr<WindowSceneSessionImpl> subWindow = new (std::nothrow) WindowSceneSessionImpl(subOption);
1243 ASSERT_NE(nullptr, subWindow);
1244 subWindow->property_->SetParentPersistentId(window->GetWindowId());
1245
1246 WindowSceneSessionImpl::windowSessionMap_.insert(std::make_pair(window->GetWindowName(),
1247 std::pair<uint64_t, sptr<WindowSessionImpl>>(window->GetWindowId(), window)));
1248 ASSERT_EQ(density, subWindow->GetVirtualPixelRatio(displayInfo));
1249 WindowSceneSessionImpl::windowSessionMap_.erase(window->GetWindowName());
1250 }
1251
1252 /**
1253 * @tc.name: GetWindowLimits01
1254 * @tc.desc: GetWindowLimits
1255 * @tc.type: FUNC
1256 */
1257 HWTEST_F(WindowSceneSessionImplTest2, GetWindowLimits01, Function | SmallTest | Level2)
1258 {
1259 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1260 option->SetWindowName("GetWindowLimits01");
1261
1262 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
1263 ASSERT_NE(nullptr, window);
1264
1265 WindowLimits windowLimits = {1000, 1000, 1000, 1000, 0.0f, 0.0f};
1266 window->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1267 window->property_->SetWindowLimits(windowLimits);
1268 window->property_->SetPersistentId(1);
1269 window->state_ = WindowState::STATE_HIDDEN;
1270 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1271 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1272 ASSERT_NE(nullptr, session);
1273 window->hostSession_ = session;
1274
1275 WindowLimits windowSizeLimits;
1276 ASSERT_EQ(WMError::WM_OK, window->GetWindowLimits(windowSizeLimits));
1277 ASSERT_EQ(windowSizeLimits.maxWidth_, 1000);
1278 ASSERT_EQ(windowSizeLimits.maxHeight_, 1000);
1279 ASSERT_EQ(windowSizeLimits.minWidth_, 1000);
1280 ASSERT_EQ(windowSizeLimits.minHeight_, 1000);
1281 }
1282
1283 /**
1284 * @tc.name: AdjustKeyboardLayout01
1285 * @tc.desc: adjust keyboard layout
1286 * @tc.type: FUNC
1287 */
1288 HWTEST_F(WindowSceneSessionImplTest2, AdjustKeyboardLayout01, Function | SmallTest | Level2)
1289 {
1290 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1291 option->SetWindowName("AdjustKeyboardLayout01");
1292 option->SetDisplayId(0);
1293
1294 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
1295 ASSERT_NE(nullptr, window);
1296
1297 window->property_->SetPersistentId(123);
1298 window->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1299 window->state_ = WindowState::STATE_FROZEN;
1300 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
1301 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1302 ASSERT_NE(nullptr, session);
1303 window->hostSession_ = session;
1304
1305 KeyboardLayoutParams params;
1306 params.gravity_ = WindowGravity::WINDOW_GRAVITY_FLOAT;
1307 params.LandscapeKeyboardRect_ = {1, 2, 3, 4};
1308 params.PortraitKeyboardRect_ = {1, 2, 3, 4};
1309 params.LandscapePanelRect_ = {1, 2, 3, 4};
1310 params.PortraitPanelRect_ = {1, 2, 3, 4};
1311 ASSERT_EQ(WMError::WM_OK, window->AdjustKeyboardLayout(params));
1312 }
1313 /**
1314 * @tc.name: HideNonSecureWindows01
1315 * @tc.desc: HideNonSecureWindows
1316 * @tc.type: FUNC
1317 */
1318 HWTEST_F(WindowSceneSessionImplTest2, HideNonSecureWindows01, Function | SmallTest | Level2)
1319 {
1320 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1321 option->SetWindowName("HideNonSecureWindows01");
1322
1323 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
1324 ASSERT_NE(nullptr, window);
1325
1326 ASSERT_EQ(WMError::WM_OK, window->HideNonSecureWindows(true));
1327 }
1328
1329 /**
1330 * @tc.name: SetGrayScale01
1331 * @tc.desc: SetGrayScale
1332 * @tc.type: FUNC
1333 */
1334 HWTEST_F(WindowSceneSessionImplTest2, SetGrayScale01, Function | SmallTest | Level3)
1335 {
1336 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1337 ASSERT_NE(nullptr, option);
1338 option->SetWindowMode(WindowMode::WINDOW_MODE_PIP);
1339 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
1340 ASSERT_NE(nullptr, window);
1341
1342 constexpr float grayScale = 0.5f;
1343 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->SetGrayScale(grayScale));
1344 }
1345
1346 /**
1347 * @tc.name: SetGrayScale02
1348 * @tc.desc: SetGrayScale
1349 * @tc.type: FUNC
1350 */
1351 HWTEST_F(WindowSceneSessionImplTest2, SetGrayScale02, Function | SmallTest | Level3)
1352 {
1353 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1354 ASSERT_NE(nullptr, option);
1355 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
1356 ASSERT_NE(nullptr, window);
1357
1358 window->state_ = WindowState::STATE_SHOWN;
1359 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1360 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1361 ASSERT_NE(nullptr, session);
1362 window->property_->SetPersistentId(1);
1363 window->hostSession_ = session;
1364 window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
1365
1366 std::vector<WindowType> types = { WindowType::WINDOW_TYPE_APP_MAIN_WINDOW,
1367 WindowType::WINDOW_TYPE_APP_SUB_WINDOW,
1368 WindowType::SYSTEM_WINDOW_BASE };
1369 for (WindowType type : types) {
1370 window->SetWindowType(type);
1371 float grayScale = -0.001f;
1372 ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetGrayScale(grayScale));
1373 grayScale = 1.001f;
1374 ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetGrayScale(grayScale));
1375 }
1376 }
1377
1378 /**
1379 * @tc.name: SetGrayScale03
1380 * @tc.desc: SetGrayScale
1381 * @tc.type: FUNC
1382 */
1383 HWTEST_F(WindowSceneSessionImplTest2, SetGrayScale03, Function | SmallTest | Level3)
1384 {
1385 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1386 ASSERT_NE(nullptr, option);
1387 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
1388 ASSERT_NE(nullptr, window);
1389
1390 window->state_ = WindowState::STATE_SHOWN;
1391 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1392 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1393 ASSERT_NE(nullptr, session);
1394 window->property_->SetPersistentId(1);
1395 window->hostSession_ = session;
1396 window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
1397
1398 std::vector<WindowType> types = { WindowType::WINDOW_TYPE_APP_MAIN_WINDOW,
1399 WindowType::WINDOW_TYPE_APP_SUB_WINDOW,
1400 WindowType::SYSTEM_WINDOW_BASE };
1401 for (WindowType type : types) {
1402 window->SetWindowType(type);
1403 float grayScale = 0.0f;
1404 ASSERT_EQ(WMError::WM_OK, window->SetGrayScale(grayScale));
1405 grayScale = 1.0f;
1406 ASSERT_EQ(WMError::WM_OK, window->SetGrayScale(grayScale));
1407 grayScale = 0.5f;
1408 ASSERT_EQ(WMError::WM_OK, window->SetGrayScale(grayScale));
1409 }
1410 }
1411
1412 /**
1413 * @tc.name: Maximize02
1414 * @tc.desc: test errorCode
1415 * @tc.type: FUNC
1416 */
1417 HWTEST_F(WindowSceneSessionImplTest2, Maximize02, Function | SmallTest | Level2)
1418 {
1419 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1420 option->SetWindowName("Maximize02");
1421 option->SetDisplayId(0);
1422
1423 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
1424 ASSERT_NE(nullptr, window);
1425
1426 window->property_->SetWindowName("Maximize02");
1427 window->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
1428 window->property_->SetPersistentId(2);
1429
1430 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
1431 sptr session = new (std::nothrow) SessionMocker(sessionInfo);
1432 ASSERT_NE(nullptr, session);
1433 window->hostSession_ = session;
1434
1435 MaximizePresentation presentation = MaximizePresentation::ENTER_IMMERSIVE;
1436 // not support subWinodw call
1437 ASSERT_EQ(WMError::WM_ERROR_INVALID_CALLING, window->Maximize(presentation));
1438
1439 // window not support fullscreen
1440 window->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1441 window->property_->SetWindowModeSupportType(WindowModeSupport::WINDOW_MODE_SUPPORT_PIP);
1442 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Maximize(presentation));
1443 }
1444
1445 /**
1446 * @tc.name: Test01
1447 * @tc.desc: Test01
1448 * @tc.type: FUNC
1449 */
1450 HWTEST_F(WindowSceneSessionImplTest2, Test01, Function | SmallTest | Level3)
1451 {
1452 WindowLimits windowLimits = {3, 3, 3, 3, 2.0, 2.0};
1453 ASSERT_EQ(windowLimits.IsEmpty(), false);
1454 Rect rect = {2, 2, 2, 2};
1455 Rect rect1 = {2, 2, 2, 2};
1456 ASSERT_EQ(rect.IsInsideOf(rect1), true);
1457 TitleButtonRect titleButtonRect = {3, 3, 3, 3};
1458 TitleButtonRect titleButtonRect1 = {3, 3, 3, 3};
1459 ASSERT_EQ(titleButtonRect.IsUninitializedRect(), false);
1460 ASSERT_EQ(titleButtonRect.IsInsideOf(titleButtonRect1), true);
1461 AvoidArea avoidArea;
1462 AvoidArea avoidArea1;
1463 ASSERT_EQ((avoidArea != avoidArea1), false);
1464 }
1465
1466 /**
1467 * @tc.name: RegisterSessionRecoverListenerInputMethodFloat
1468 * @tc.desc: Register session recover listener
1469 * @tc.type: FUNC
1470 */
1471 HWTEST_F(WindowSceneSessionImplTest2, RegisterSessionRecoverListenerInputMethodFloat, Function | SmallTest | Level2)
1472 {
1473 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1474 ASSERT_NE(nullptr, option);
1475 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
1476 ASSERT_NE(nullptr, window);
1477 ASSERT_NE(nullptr, window->property_);
1478 window->property_->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT);
1479 window->RegisterSessionRecoverListener(false);
1480 }
1481
1482 /**
1483 * @tc.name: RegisterSessionRecoverListenerNonDefaultCollaboratorType01
1484 * @tc.desc: Register session recover listener
1485 * @tc.type: FUNC
1486 */
1487 HWTEST_F(WindowSceneSessionImplTest2, RegisterSessionRecoverListenerNonDefaultCollaboratorType01,
1488 Function | SmallTest | Level2)
1489 {
1490 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1491 ASSERT_NE(nullptr, option);
1492 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
1493 ASSERT_NE(nullptr, window);
1494 ASSERT_NE(nullptr, window->property_);
1495 window->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1496 window->property_->SetCollaboratorType(CollaboratorType::OTHERS_TYPE);
1497 window->RegisterSessionRecoverListener(false); // false is main window
1498 }
1499
1500 /**
1501 * @tc.name: RegisterSessionRecoverListenerNonDefaultCollaboratorType02
1502 * @tc.desc: Register session recover listener
1503 * @tc.type: FUNC
1504 */
1505 HWTEST_F(WindowSceneSessionImplTest2, RegisterSessionRecoverListenerNonDefaultCollaboratorType02,
1506 Function | SmallTest | Level2)
1507 {
1508 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1509 ASSERT_NE(nullptr, option);
1510 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
1511 ASSERT_NE(nullptr, window);
1512 ASSERT_NE(nullptr, window->property_);
1513 window->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1514 window->property_->SetCollaboratorType(CollaboratorType::OTHERS_TYPE);
1515 window->RegisterSessionRecoverListener(true); // true is sub window
1516 }
1517
1518 /**
1519 * @tc.name: RegisterSessionRecoverListenerSuccess01
1520 * @tc.desc: Register session recover listener
1521 * @tc.type: FUNC
1522 */
1523 HWTEST_F(WindowSceneSessionImplTest2, RegisterSessionRecoverListenerSuccess01, Function | SmallTest | Level2)
1524 {
1525 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1526 ASSERT_NE(nullptr, option);
1527 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
1528 ASSERT_NE(nullptr, window);
1529 ASSERT_NE(nullptr, window->property_);
1530 window->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1531 window->property_->SetCollaboratorType(CollaboratorType::DEFAULT_TYPE);
1532 window->RegisterSessionRecoverListener(false); // false is main window
1533 }
1534
1535 /**
1536 * @tc.name: RegisterSessionRecoverListenerSuccess02
1537 * @tc.desc: Register session recover listener
1538 * @tc.type: FUNC
1539 */
1540 HWTEST_F(WindowSceneSessionImplTest2, RegisterSessionRecoverListenerSuccess02, Function | SmallTest | Level2)
1541 {
1542 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1543 ASSERT_NE(nullptr, option);
1544 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
1545 ASSERT_NE(nullptr, window);
1546 ASSERT_NE(nullptr, window->property_);
1547 window->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1548 window->property_->SetCollaboratorType(CollaboratorType::DEFAULT_TYPE);
1549 window->RegisterSessionRecoverListener(true); // true is sub window
1550 }
1551
1552 /**
1553 * @tc.name: GetTitleButtonVisible01
1554 * @tc.desc: GetTitleButtonVisible
1555 * @tc.type: FUNC
1556 */
1557 HWTEST_F(WindowSceneSessionImplTest2, GetTitleButtonVisible01, Function | SmallTest | Level2)
1558 {
1559 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1560 option->SetWindowName("GetTitleButtonVisible01");
1561 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
1562 ASSERT_NE(nullptr, window);
1563 uint32_t windowModeSupportType = 1 | (1 << 1) | (1 << 2);
1564 window->property_->SetWindowModeSupportType(windowModeSupportType);
1565 window->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
1566 // show Maximize, Minimize, Split buttons.
1567 window->windowTitleVisibleFlags_ = { false, false, false, false };
1568 bool hideMaximizeButton = false;
1569 bool hideMinimizeButton = false;
1570 bool hideSplitButton = false;
1571 bool hideCloseButton = false;
1572 window->windowSystemConfig_.uiType_ = "pc";
1573 window->GetTitleButtonVisible(hideMaximizeButton, hideMinimizeButton, hideSplitButton, hideCloseButton);
1574 ASSERT_EQ(hideMaximizeButton, true);
1575 ASSERT_EQ(hideMinimizeButton, true);
1576 ASSERT_EQ(hideSplitButton, true);
1577 ASSERT_EQ(hideCloseButton, true);
1578 }
1579
1580 /**
1581 * @tc.name: GetTitleButtonVisible02
1582 * @tc.desc: GetTitleButtonVisible
1583 * @tc.type: FUNC
1584 */
1585 HWTEST_F(WindowSceneSessionImplTest2, GetTitleButtonVisible02, Function | SmallTest | Level2)
1586 {
1587 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1588 option->SetWindowName("GetTitleButtonVisible02");
1589 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
1590 ASSERT_NE(nullptr, window);
1591 // only not support WINDOW_MODE_SUPPORT_SPLIT
1592 uint32_t windowModeSupportType = 1 | (1 << 1);
1593 window->property_->SetWindowModeSupportType(windowModeSupportType);
1594 window->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
1595 // show Maximize, Minimize, Split buttons.
1596 window->windowTitleVisibleFlags_ = { true, true, true, true };
1597 bool hideMaximizeButton = false;
1598 bool hideMinimizeButton = false;
1599 bool hideSplitButton = false;
1600 bool hideCloseButton = false;
1601 window->windowSystemConfig_.uiType_ = "pc";
1602 window->GetTitleButtonVisible(hideMaximizeButton, hideMinimizeButton, hideSplitButton, hideCloseButton);
1603 ASSERT_EQ(hideMaximizeButton, false);
1604 ASSERT_EQ(hideMinimizeButton, false);
1605 ASSERT_EQ(hideSplitButton, false);
1606 ASSERT_EQ(hideCloseButton, false);
1607 }
1608
1609 /**
1610 * @tc.name: GetTitleButtonVisible03
1611 * @tc.desc: GetTitleButtonVisible
1612 * @tc.type: FUNC
1613 */
1614 HWTEST_F(WindowSceneSessionImplTest2, GetTitleButtonVisible03, Function | SmallTest | Level2)
1615 {
1616 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1617 option->SetWindowName("GetTitleButtonVisible03");
1618 sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
1619 ASSERT_NE(nullptr, window);
1620 // only not support WINDOW_MODE_SUPPORT_SPLIT
1621 uint32_t windowModeSupportType = 1 | (1 << 1) | (1 << 2);
1622 window->property_->SetWindowModeSupportType(windowModeSupportType);
1623 window->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
1624 // show Maximize, Minimize, Split buttons.
1625 window->windowTitleVisibleFlags_ = { false, false, false, false };
1626 bool hideMaximizeButton = true;
1627 bool hideMinimizeButton = true;
1628 bool hideSplitButton = true;
1629 bool hideCloseButton = true;
1630 window->windowSystemConfig_.uiType_ = "phone";
1631 window->GetTitleButtonVisible(hideMaximizeButton, hideMinimizeButton, hideSplitButton, hideCloseButton);
1632 ASSERT_EQ(hideMaximizeButton, true);
1633 ASSERT_EQ(hideMinimizeButton, true);
1634 ASSERT_EQ(hideSplitButton, true);
1635 ASSERT_EQ(hideCloseButton, true);
1636 }
1637
1638 /**
1639 * @tc.name: SetTitleButtonVisible01
1640 * @tc.desc: SetTitleButtonVisible
1641 * @tc.type: FUNC
1642 */
1643 HWTEST_F(WindowSceneSessionImplTest2, SetTitleButtonVisible01, Function | SmallTest | Level2)
1644 {
1645 sptr<WindowOption> option = new WindowOption();
1646 ASSERT_NE(option, nullptr);
1647 option->SetWindowName("SetTitleButtonVisible");
1648 sptr<WindowSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
1649 ASSERT_NE(window, nullptr);
1650 window->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
1651 window->SetTitleButtonVisible(false, false, false, true);
1652 }
1653
1654 /**
1655 * @tc.name: SetTitleButtonVisible02
1656 * @tc.desc: SetTitleButtonVisible
1657 * @tc.type: FUNC
1658 */
1659 HWTEST_F(WindowSceneSessionImplTest2, SetTitleButtonVisible02, Function | SmallTest | Level2)
1660 {
1661 sptr<WindowOption> option = new WindowOption();
1662 ASSERT_NE(option, nullptr);
1663 option->SetWindowName("SetTitleButtonVisible");
1664 sptr<WindowSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
1665 ASSERT_NE(window, nullptr);
1666 window->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1667 WMError res = window->SetTitleButtonVisible(false, false, false, true);
1668 ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW);
1669 }
1670
1671 /**
1672 * @tc.name: SetTitleButtonVisible03
1673 * @tc.desc: SetTitleButtonVisible
1674 * @tc.type: FUNC
1675 */
1676 HWTEST_F(WindowSceneSessionImplTest2, SetTitleButtonVisible03, Function | SmallTest | Level2)
1677 {
1678 sptr option = new WindowOption();
1679 ASSERT_NE(option, nullptr);
1680 option->SetWindowName("SetTitleButtonVisible");
1681 sptr window = new (std::nothrow) WindowSceneSessionImpl(option);
1682 ASSERT_NE(window, nullptr);
1683 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
1684 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
1685 ASSERT_NE(nullptr, session);
1686 window->hostSession_ = session;
1687 window->property_->SetPersistentId(1);
1688 window->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1689 window->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
1690 window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
1691 window->windowSystemConfig_.freeMultiWindowSupport_ = true;
1692 window->windowSystemConfig_.isSystemDecorEnable_ = false;
1693 window->windowSystemConfig_.uiType_ = "phone";
1694 WMError res = window->SetTitleButtonVisible(false, false, false, true);
1695 ASSERT_EQ(res, WMError::WM_ERROR_DEVICE_NOT_SUPPORT);
1696 window->windowSystemConfig_.uiType_ = "pc";
1697 res = window->SetTitleButtonVisible(false, false, false, true);
1698 ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW);
1699 window->windowSystemConfig_.isSystemDecorEnable_ = true;
1700 res = window->SetTitleButtonVisible(false, false, false, true);
1701 ASSERT_EQ(res, WMError::WM_OK);
1702 }
1703
1704 /**
1705 * @tc.name: IsWindowRectAutoSave
1706 * @tc.desc: IsWindowRectAutoSave
1707 * @tc.type: FUNC
1708 */
1709 HWTEST_F(WindowSceneSessionImplTest2, IsWindowRectAutoSave, Function | SmallTest | Level2)
1710 {
1711 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1712 option->SetWindowName("IsWindowRectAutoSave");
1713 sptr<WindowSceneSessionImpl> windowSceneSessionImpl = sptr<WindowSceneSessionImpl>::MakeSptr(option);
1714 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
1715 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
1716 windowSceneSessionImpl->property_->SetPersistentId(1);
1717 windowSceneSessionImpl->context_ = abilityContext_;
1718 windowSceneSessionImpl->hostSession_ = session;
1719 windowSceneSessionImpl->windowSystemConfig_.uiType_ = UI_TYPE_PC;
1720 bool enabled = false;
1721 auto ret = windowSceneSessionImpl->IsWindowRectAutoSave(enabled);
1722 EXPECT_EQ(WMError::WM_OK, ret);
1723 windowSceneSessionImpl->windowSystemConfig_.uiType_ = UI_TYPE_PAD;
1724 ret = windowSceneSessionImpl->IsWindowRectAutoSave(enabled);
1725 EXPECT_EQ(WMError::WM_ERROR_DEVICE_NOT_SUPPORT, ret);
1726 windowSceneSessionImpl->windowSystemConfig_.uiType_ = UI_TYPE_PHONE;
1727 ret = windowSceneSessionImpl->IsWindowRectAutoSave(enabled);
1728 EXPECT_EQ(WMError::WM_ERROR_DEVICE_NOT_SUPPORT, ret);
1729 }
1730 }
1731 } // namespace Rosen
1732 } // namespace OHOS