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