1 /*
2 * Copyright (c) 2023 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 <event_handler.h>
17 #include <gtest/gtest.h>
18 #include <input_manager.h>
19 #include <ui_content.h>
20 #include "mock_uicontent.h"
21 #include <viewport_config.h>
22 #include "root_scene.h"
23 #include "screen_scene.h"
24
25 #include "app_mgr_client.h"
26 #include "mock_uicontent.h"
27 #include "singleton.h"
28 #include "singleton_container.h"
29
30 #include "vsync_station.h"
31 #include "window_manager_hilog.h"
32
33 using namespace testing;
34 using namespace testing::ext;
35
36 namespace OHOS {
37 namespace Rosen {
38 const uint32_t MOCK_LEM_SUB_WIDTH = 340;
39 const uint32_t MOCK_LEM_SUB_HEIGHT = 340;
40
41 class RootSceneTest : public testing::Test {
42 public:
43 static void SetUpTestCase();
44 static void TearDownTestCase();
45 void SetUp() override;
46 void TearDown() override;
47
48 private:
49 static constexpr uint32_t WAIT_SYNC_IN_NS = 200000;
50 };
51
SetUpTestCase()52 void RootSceneTest::SetUpTestCase() {}
53
TearDownTestCase()54 void RootSceneTest::TearDownTestCase() {}
55
SetUp()56 void RootSceneTest::SetUp() {}
57
TearDown()58 void RootSceneTest::TearDown()
59 {
60 usleep(WAIT_SYNC_IN_NS);
61 }
62
63 namespace {
64 /**
65 * @tc.name: LoadContent01
66 * @tc.desc: context is nullptr
67 * @tc.type: FUNC
68 */
69 HWTEST_F(RootSceneTest, LoadContent01, TestSize.Level1)
70 {
71 RootScene rootScene;
72 rootScene.LoadContent("a", nullptr, nullptr, nullptr);
73 ASSERT_EQ(1, rootScene.GetWindowId());
74 }
75
76 /**
77 * @tc.name: UpdateViewportConfig01
78 * @tc.desc: UpdateViewportConfig Test
79 * @tc.type: FUNC
80 */
81 HWTEST_F(RootSceneTest, UpdateViewportConfig01, TestSize.Level1)
82 {
83 RootScene rootScene;
84 Rect rect;
85
86 rootScene.uiContent_ = nullptr;
87 rootScene.UpdateViewportConfig(rect, WindowSizeChangeReason::UNDEFINED);
88
89 rootScene.uiContent_ = std::make_unique<Ace::UIContentMocker>();
90 rootScene.UpdateViewportConfig(rect, WindowSizeChangeReason::UNDEFINED);
91
92 rect.width_ = MOCK_LEM_SUB_WIDTH;
93 rect.height_ = MOCK_LEM_SUB_HEIGHT;
94 rootScene.UpdateViewportConfig(rect, WindowSizeChangeReason::UNDEFINED);
95 ASSERT_EQ(1, rootScene.GetWindowId());
96 }
97
98 /**
99 * @tc.name: UpdateConfiguration
100 * @tc.desc: UpdateConfiguration Test
101 * @tc.type: FUNC
102 */
103 HWTEST_F(RootSceneTest, UpdateConfiguration, TestSize.Level1)
104 {
105 RootScene rootScene;
106 sptr<RootScene> staticRootScene = sptr<RootScene>::MakeSptr();
107 wptr<Window> weakWindow(staticRootScene);
108 rootScene.AddRootScene(DEFAULT_DISPLAY_ID, weakWindow);
109 rootScene.AddRootScene(100, nullptr);
110 std::shared_ptr<AppExecFwk::Configuration> configuration = std::make_shared<AppExecFwk::Configuration>();
111 rootScene.uiContent_ = nullptr;
112 rootScene.UpdateConfiguration(configuration);
113
114 rootScene.uiContent_ = std::make_unique<Ace::UIContentMocker>();
115 rootScene.UpdateConfiguration(configuration);
116 ASSERT_EQ(1, rootScene.GetWindowId());
117 }
118
119 /**
120 * @tc.name: UpdateConfigurationForSpecified
121 * @tc.desc: UpdateConfigurationForSpecified Test
122 * @tc.type: FUNC
123 */
124 HWTEST_F(RootSceneTest, UpdateConfigurationForSpecified, TestSize.Level1)
125 {
126 RootScene rootScene;
127 std::shared_ptr<AppExecFwk::Configuration> configuration;
128 std::shared_ptr<Global::Resource::ResourceManager> resourceManager;
129
130 rootScene.uiContent_ = std::make_unique<Ace::UIContentMocker>();
131 rootScene.UpdateConfigurationForSpecified(configuration, resourceManager);
132 ASSERT_EQ(1, rootScene.GetWindowId());
133 }
134
135 /**
136 * @tc.name: UpdateConfigurationForAll
137 * @tc.desc: UpdateConfigurationForAll Test
138 * @tc.type: FUNC
139 */
140 HWTEST_F(RootSceneTest, UpdateConfigurationForAll, TestSize.Level1)
141 {
142 RootScene rootScene;
143 std::shared_ptr<AppExecFwk::Configuration> configuration = std::make_shared<AppExecFwk::Configuration>();
144
145 auto prevStaticRootScene = RootScene::staticRootScene_;
146 rootScene.UpdateConfigurationForAll(configuration);
147
148 sptr<RootScene> staticRootScene = sptr<RootScene>::MakeSptr();
149 RootScene::staticRootScene_ = staticRootScene;
150 rootScene.UpdateConfigurationForAll(configuration);
151
152 RootScene::staticRootScene_ = prevStaticRootScene;
153 ASSERT_EQ(1, rootScene.GetWindowId());
154 }
155
156 /**
157 * @tc.name: RegisterInputEventListener01
158 * @tc.desc: RegisterInputEventListener Test
159 * @tc.type: FUNC
160 */
161 HWTEST_F(RootSceneTest, RegisterInputEventListener01, TestSize.Level1)
162 {
163 sptr<RootScene> rootScene = sptr<RootScene>::MakeSptr();
164 rootScene->RegisterInputEventListener();
165 ASSERT_EQ(1, rootScene->GetWindowId());
166 }
167
168 /**
169 * @tc.name: RequestVsyncErr
170 * @tc.desc: RequestVsync Test Err
171 * @tc.type: FUNC
172 */
173 HWTEST_F(RootSceneTest, RequestVsyncErr, TestSize.Level1)
174 {
175 RootScene rootScene;
176 std::shared_ptr<VsyncCallback> vsyncCallback = std::make_shared<VsyncCallback>();
177 rootScene.RequestVsync(vsyncCallback);
178 ASSERT_EQ(1, rootScene.GetWindowId());
179 }
180
181 /**
182 * @tc.name: GetVSyncPeriod
183 * @tc.desc: GetVSyncPeriod Test
184 * @tc.type: FUNC
185 */
186 HWTEST_F(RootSceneTest, GetVSyncPeriod, TestSize.Level1)
187 {
188 RootScene rootScene;
189 rootScene.GetVSyncPeriod();
190 ASSERT_EQ(1, rootScene.GetWindowId());
191 }
192
193 /**
194 * @tc.name: FlushFrameRate
195 * @tc.desc: FlushFrameRate Test
196 * @tc.type: FUNC
197 */
198 HWTEST_F(RootSceneTest, FlushFrameRate, TestSize.Level1)
199 {
200 RootScene rootScene;
201 uint32_t rate = 120;
202 int32_t animatorExpectedFrameRate = -1;
203 rootScene.FlushFrameRate(rate, animatorExpectedFrameRate);
204 ASSERT_EQ(1, rootScene.GetWindowId());
205 }
206
207 /**
208 * @tc.name: SetFrameLayoutFinishCallback
209 * @tc.desc: SetFrameLayoutFinishCallback Test
210 * @tc.type: FUNC
211 */
212 HWTEST_F(RootSceneTest, SetFrameLayoutFinishCallback, TestSize.Level1)
213 {
214 RootScene rootScene;
215 rootScene.SetFrameLayoutFinishCallback(nullptr);
216 ASSERT_EQ(rootScene.frameLayoutFinishCb_, nullptr);
217
218 rootScene.uiContent_ = std::make_unique<Ace::UIContentMocker>();
219 rootScene.SetFrameLayoutFinishCallback(nullptr);
220 ASSERT_EQ(rootScene.frameLayoutFinishCb_, nullptr);
221 ASSERT_EQ(1, rootScene.GetWindowId());
222 }
223
224 /**
225 * @tc.name: SetUiDvsyncSwitch
226 * @tc.desc: SetUiDvsyncSwitch Test
227 * @tc.type: FUNC
228 */
229 HWTEST_F(RootSceneTest, SetUiDvsyncSwitchSucc, TestSize.Level1)
230 {
231 RootScene rootScene;
232 rootScene.SetUiDvsyncSwitch(true);
233 rootScene.SetUiDvsyncSwitch(false);
234 ASSERT_EQ(1, rootScene.GetWindowId());
235 }
236
237 /**
238 * @tc.name: SetUiDvsyncSwitch
239 * @tc.desc: SetUiDvsyncSwitch Test
240 * @tc.type: FUNC
241 */
242 HWTEST_F(RootSceneTest, SetUiDvsyncSwitchErr, TestSize.Level1)
243 {
244 RootScene rootScene;
245 rootScene.SetUiDvsyncSwitch(true);
246 rootScene.SetUiDvsyncSwitch(false);
247 ASSERT_EQ(1, rootScene.GetWindowId());
248 }
249
250 /**
251 * @tc.name: SetTouchEvent
252 * @tc.desc: SetTouchEvent Test
253 * @tc.type: FUNC
254 */
255 HWTEST_F(RootSceneTest, SetTouchEventSucc, TestSize.Level1)
256 {
257 RootScene rootScene;
258 rootScene.SetTouchEvent(0);
259 rootScene.SetTouchEvent(1);
260 ASSERT_EQ(1, rootScene.GetWindowId());
261 }
262
263 /**
264 * @tc.name: SetTouchEvent
265 * @tc.desc: SetTouchEvent Test
266 * @tc.type: FUNC
267 */
268 HWTEST_F(RootSceneTest, SetTouchEventErr, TestSize.Level1)
269 {
270 RootScene rootScene;
271 rootScene.SetTouchEvent(0);
272 rootScene.SetTouchEvent(1);
273 ASSERT_EQ(1, rootScene.GetWindowId());
274 }
275
276 /**
277 * @tc.name: IsLastFrameLayoutFinished
278 * @tc.desc: IsLastFrameLayoutFinished Test
279 * @tc.type: FUNC
280 */
281 HWTEST_F(RootSceneTest, IsLastFrameLayoutFinished, TestSize.Level1)
282 {
283 RootScene rootScene;
284 auto ret = rootScene.IsLastFrameLayoutFinished();
285 ASSERT_EQ(ret, true);
286 ASSERT_EQ(1, rootScene.GetWindowId());
287 }
288
289 /**
290 * @tc.name: OnFlushUIParams
291 * @tc.desc: OnFlushUIParams Test
292 * @tc.type: FUNC
293 */
294 HWTEST_F(RootSceneTest, OnFlushUIParams, TestSize.Level1)
295 {
296 RootScene rootScene;
297 rootScene.OnFlushUIParams();
298 ASSERT_EQ(1, rootScene.GetWindowId());
299 }
300
301 /**
302 * @tc.name: OnBundleUpdated
303 * @tc.desc: OnBundleUpdated Test
304 * @tc.type: FUNC
305 */
306 HWTEST_F(RootSceneTest, OnBundleUpdated, TestSize.Level1)
307 {
308 RootScene rootScene;
309 std::string bundleName = "test";
310 rootScene.OnBundleUpdated(bundleName);
311 ASSERT_EQ(1, rootScene.GetWindowId());
312 }
313
314 /**
315 * @tc.name: SetDisplayOrientation
316 * @tc.desc: SetDisplayOrientation Test01
317 * @tc.type: FUNC
318 */
319 HWTEST_F(RootSceneTest, SetDisplayOrientationTest01, TestSize.Level1)
320 {
321 RootScene rootScene;
322 int32_t orientation = 0;
323 rootScene.SetDisplayOrientation(orientation);
324 ASSERT_EQ(1, rootScene.GetWindowId());
325 }
326
327 /**
328 * @tc.name: SetDisplayOrientation
329 * @tc.desc: SetDisplayOrientation Test02
330 * @tc.type: FUNC
331 */
332 HWTEST_F(RootSceneTest, SetDisplayOrientationTest02, TestSize.Level1)
333 {
334 RootScene rootScene;
335 int32_t orientation = 100;
336 rootScene.SetDisplayOrientation(orientation);
337 ASSERT_EQ(1, rootScene.GetWindowId());
338 }
339
340 /**
341 * @tc.name: RegisterAvoidAreaChangeListener
342 * @tc.desc: RegisterAvoidAreaChangeListener Test
343 * @tc.type: FUNC
344 */
345 HWTEST_F(RootSceneTest, RegisterAvoidAreaChangeListener, TestSize.Level1)
346 {
347 RootScene rootScene;
__anon8949d94b0202null348 rootScene.updateRootSceneAvoidAreaCallback_ = [] {};
349 sptr<IAvoidAreaChangedListener> listener = sptr<IAvoidAreaChangedListener>::MakeSptr();
350 auto ret = rootScene.RegisterAvoidAreaChangeListener(listener);
351 ASSERT_EQ(WMError::WM_OK, ret);
352 listener = nullptr;
353 ret = rootScene.RegisterAvoidAreaChangeListener(listener);
354 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, ret);
355 }
356
357 /**
358 * @tc.name: UnregisterAvoidAreaChangeListener
359 * @tc.desc: UnregisterAvoidAreaChangeListener Test
360 * @tc.type: FUNC
361 */
362 HWTEST_F(RootSceneTest, UnregisterAvoidAreaChangeListener, TestSize.Level1)
363 {
364 RootScene rootScene;
365 sptr<IAvoidAreaChangedListener> listener = sptr<IAvoidAreaChangedListener>::MakeSptr();
366 auto ret = rootScene.UnregisterAvoidAreaChangeListener(listener);
367 ASSERT_EQ(WMError::WM_OK, ret);
368 listener = nullptr;
369 ret = rootScene.UnregisterAvoidAreaChangeListener(listener);
370 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, ret);
371 }
372
373 /**
374 * @tc.name: NotifyAvoidAreaChangeForRoot
375 * @tc.desc: NotifyAvoidAreaChangeForRoot Test
376 * @tc.type: FUNC
377 */
378 HWTEST_F(RootSceneTest, NotifyAvoidAreaChangeForRoot, TestSize.Level1)
379 {
380 RootScene rootScene;
381 sptr<IAvoidAreaChangedListener> listener = sptr<IAvoidAreaChangedListener>::MakeSptr();
382 ASSERT_NE(nullptr, listener);
383 rootScene.avoidAreaChangeListeners_.insert(listener);
384 AvoidAreaType type = AvoidAreaType::TYPE_SYSTEM_GESTURE;
385 AvoidArea avoidArea;
386 rootScene.NotifyAvoidAreaChangeForRoot(new AvoidArea(avoidArea), type);
387 }
388
389 /**
390 * @tc.name: GetAvoidAreaByType
391 * @tc.desc: GetAvoidAreaByType Test err
392 * @tc.type: FUNC
393 */
394 HWTEST_F(RootSceneTest, GetAvoidAreaByType, TestSize.Level1)
395 {
396 RootScene rootScene;
397 AvoidAreaType type = AvoidAreaType::TYPE_SYSTEM_GESTURE;
398 AvoidArea avoidArea;
399 rootScene.getSessionAvoidAreaByTypeCallback_ = nullptr;
400
401 auto ret = rootScene.GetAvoidAreaByType(type, avoidArea);
402 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, ret);
403 }
404
405 /**
406 * @tc.name: GetAvoidAreaByTypeTest
407 * @tc.desc: GetAvoidAreaByType Test err
408 * @tc.type: FUNC
409 */
410 HWTEST_F(RootSceneTest, GetAvoidAreaByTypeTest, TestSize.Level1)
411 {
412 RootScene rootScene;
413 AvoidAreaType type = AvoidAreaType::TYPE_SYSTEM_GESTURE;
414 AvoidArea avoidArea;
415 AvoidArea testAvoidArea;
416 testAvoidArea.topRect_ = {1, 1, 1, 1};
__anon8949d94b0302(AvoidAreaType type)417 GetSessionAvoidAreaByTypeCallback func = [testAvoidArea](AvoidAreaType type)->AvoidArea {
418 return testAvoidArea;
419 };
420 rootScene.getSessionAvoidAreaByTypeCallback_ = func;
421
422 auto ret = rootScene.GetAvoidAreaByType(type, avoidArea, Rect::EMPTY_RECT, 15);
423 ASSERT_EQ(WMError::WM_DO_NOTHING, ret);
424 }
425
426 /**
427 * @tc.name: GetAvoidAreaByTypeTest001
428 * @tc.desc: GetAvoidAreaByType Test err
429 * @tc.type: FUNC
430 */
431 HWTEST_F(RootSceneTest, GetAvoidAreaByTypeTest001, TestSize.Level1)
432 {
433 RootScene rootScene;
434 AvoidAreaType type = AvoidAreaType::TYPE_SYSTEM_GESTURE;
435 AvoidArea avoidArea;
436 AvoidArea testAvoidArea;
437 testAvoidArea.topRect_ = {1, 1, 1, 1};
__anon8949d94b0402(AvoidAreaType type)438 GetSessionAvoidAreaByTypeCallback func = [testAvoidArea](AvoidAreaType type)->AvoidArea {
439 return testAvoidArea;
440 };
441 rootScene.getSessionAvoidAreaByTypeCallback_ = func;
442
443 constexpr int32_t API_VERSION_18 = 18;
444 auto ret = rootScene.GetAvoidAreaByType(type, avoidArea, Rect::EMPTY_RECT, API_VERSION_18);
445 ASSERT_EQ(WMError::WM_OK, ret);
446 ASSERT_EQ(avoidArea.topRect_, testAvoidArea.topRect_);
447 }
448
449 /**
450 * @tc.name: UpdateConfigurationSync
451 * @tc.desc: UpdateConfigurationSync Test
452 * @tc.type: FUNC
453 */
454 HWTEST_F(RootSceneTest, UpdateConfigurationSync, TestSize.Level1)
455 {
456 RootScene rootScene;
457 sptr<RootScene> staticRootScene = sptr<RootScene>::MakeSptr();
458 wptr<Window> weakWindow(staticRootScene);
459 rootScene.AddRootScene(DEFAULT_DISPLAY_ID, weakWindow);
460 rootScene.AddRootScene(100, nullptr);
461 std::shared_ptr<AppExecFwk::Configuration> configuration = std::make_shared<AppExecFwk::Configuration>();
462
463 rootScene.uiContent_ = nullptr;
464 rootScene.UpdateConfigurationSync(configuration);
465 rootScene.uiContent_ = std::make_unique<Ace::UIContentMocker>();
466 rootScene.UpdateConfigurationSync(configuration);
467 ASSERT_EQ(1, rootScene.GetWindowId());
468 }
469
470 /**
471 * @tc.name: UpdateConfigurationSyncForAll
472 * @tc.desc: UpdateConfigurationSyncForAll Test
473 * @tc.type: FUNC
474 */
475 HWTEST_F(RootSceneTest, UpdateConfigurationSyncForAll, TestSize.Level1)
476 {
477 RootScene rootScene;
478 std::shared_ptr<AppExecFwk::Configuration> configuration = std::make_shared<AppExecFwk::Configuration>();
479
480 auto prevStaticRootScene = RootScene::staticRootScene_;
481 rootScene.UpdateConfigurationSyncForAll(configuration);
482
483 sptr<RootScene> staticRootScene;
484 RootScene::staticRootScene_ = staticRootScene;
485 rootScene.UpdateConfigurationSyncForAll(configuration);
486
487 RootScene::staticRootScene_ = prevStaticRootScene;
488 ASSERT_EQ(1, rootScene.GetWindowId());
489 }
490
491 /**
492 * @tc.name: IsSystemWindow
493 * @tc.desc: IsSystemWindow Test
494 * @tc.type: FUNC
495 */
496 HWTEST_F(RootSceneTest, IsSystemWindow, TestSize.Level1)
497 {
498 RootScene rootScene;
499 bool res = rootScene.IsSystemWindow();
500 ASSERT_EQ(true, res);
501 }
502
503 /**
504 * @tc.name: IsAppWindow
505 * @tc.desc: IsAppWindow Test
506 * @tc.type: FUNC
507 */
508 HWTEST_F(RootSceneTest, IsAppWindow, TestSize.Level1)
509 {
510 RootScene rootScene;
511 bool res = rootScene.IsAppWindow();
512 ASSERT_EQ(false, res);
513 }
514
515 /**
516 * @tc.name: RegisterOccupiedAreaChangeListener
517 * @tc.desc: RegisterOccupiedAreaChangeListener Test
518 * @tc.type: FUNC
519 */
520 HWTEST_F(RootSceneTest, RegisterOccupiedAreaChangeListener, TestSize.Level1)
521 {
522 RootScene rootScene;
523 sptr<IOccupiedAreaChangeListener> listener = sptr<IOccupiedAreaChangeListener>::MakeSptr();
524 auto ret = rootScene.RegisterOccupiedAreaChangeListener(listener);
525 ASSERT_EQ(WMError::WM_OK, ret);
526 listener = nullptr;
527 ret = rootScene.RegisterOccupiedAreaChangeListener(listener);
528 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, ret);
529 }
530
531 /**
532 * @tc.name: UnregisterOccupiedAreaChangeListener
533 * @tc.desc: UnregisterOccupiedAreaChangeListener Test
534 * @tc.type: FUNC
535 */
536 HWTEST_F(RootSceneTest, UnregisterOccupiedAreaChangeListener, TestSize.Level1)
537 {
538 RootScene rootScene;
539 sptr<IOccupiedAreaChangeListener> listener = sptr<IOccupiedAreaChangeListener>::MakeSptr();
540 auto ret = rootScene.UnregisterOccupiedAreaChangeListener(listener);
541 ASSERT_EQ(WMError::WM_OK, ret);
542 listener = nullptr;
543 ret = rootScene.UnregisterOccupiedAreaChangeListener(listener);
544 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, ret);
545 }
546
547 /**
548 * @tc.name: NotifyOccupiedAreaChangeForRoot
549 * @tc.desc: NotifyOccupiedAreaChangeForRoot Test
550 * @tc.type: FUNC
551 */
552 HWTEST_F(RootSceneTest, NotifyOccupiedAreaChangeForRoot, TestSize.Level1)
553 {
554 auto rootScene = sptr<RootScene>::MakeSptr();
555 sptr<IOccupiedAreaChangeListener> listener = sptr<IOccupiedAreaChangeListener>::MakeSptr();
556 ASSERT_NE(nullptr, listener);
557 auto ret = rootScene->RegisterOccupiedAreaChangeListener(listener);
558 ASSERT_EQ(WMError::WM_OK, ret);
559 sptr<OccupiedAreaChangeInfo> info = nullptr;
560 rootScene->NotifyOccupiedAreaChangeForRoot(info);
561 info = sptr<OccupiedAreaChangeInfo>::MakeSptr();
562 ASSERT_NE(nullptr, info);
563 rootScene->NotifyOccupiedAreaChangeForRoot(info);
564 }
565
566 /**
567 * @tc.name: GetRSNodeByStringIDTest
568 * @tc.desc: For GetRSNodeByStringID Test
569 * @tc.type: FUNC
570 */
571 HWTEST_F(RootSceneTest, GetRSNodeByStringIDTest, TestSize.Level1)
572 {
573 string stringId = "GetRSNodeByStringIDTest";
574 sptr<RootScene> rootScene = sptr<RootScene>::MakeSptr();
575 rootScene->uiContent_ = std::make_unique<Ace::UIContentMocker>();
576 rootScene->SetTopWindowBoundaryByID(stringId);
577 rootScene->OnBundleUpdated(stringId);
578
579 auto res = rootScene->GetRSNodeByStringID(stringId);
580 ASSERT_EQ(res, nullptr);
581 }
582
583 /**
584 * @tc.name: GetRSNodeByStringIDTest001
585 * @tc.desc: For GetRSNodeByStringID Test
586 * @tc.type: FUNC
587 */
588 HWTEST_F(RootSceneTest, GetRSNodeByStringIDTest001, TestSize.Level1)
589 {
590 string stringId = "GetRSNodeByStringIDTest";
591 sptr<RootScene> rootScene = sptr<RootScene>::MakeSptr();
592 rootScene->uiContent_ = nullptr;
593 rootScene->SetTopWindowBoundaryByID(stringId);
594 rootScene->OnBundleUpdated(stringId);
595
596 auto res = rootScene->GetRSNodeByStringID(stringId);
597 ASSERT_EQ(res, nullptr);
598 }
599
600 /**
601 * @tc.name: GetStatusBarHeight
602 * @tc.desc: GetStatusBarHeight test
603 * @tc.type: FUNC
604 */
605 HWTEST_F(RootSceneTest, GetStatusBarHeight, TestSize.Level1)
606 {
607 RootScene rootScene;
608 auto height = rootScene.GetStatusBarHeight();
609 EXPECT_EQ(0, height);
__anon8949d94b0502() 610 rootScene.getStatusBarHeightCallback_ = []() -> uint32_t { return 100; };
611 height = rootScene.GetStatusBarHeight();
612 EXPECT_EQ(100, height);
613 }
614
615 /**
616 * @tc.name: AddRootScene
617 * @tc.desc: For AddRootScene Test
618 * @tc.type: FUNC
619 */
620 HWTEST_F(RootSceneTest, AddRootScene, TestSize.Level1)
621 {
622 sptr<RootScene> rootScene = sptr<RootScene>::MakeSptr();
623 sptr<ScreenScene> screenScene = sptr<ScreenScene>::MakeSptr("AddRootScene");
624 rootScene->uiContent_ = std::make_unique<Ace::UIContentMocker>();
625 wptr<Window> weakWindow(rootScene);
626 wptr<Window> weakWindow1(screenScene);
627 rootScene->AddRootScene(1, weakWindow);
628 rootScene->AddRootScene(12, weakWindow1);
629
630 auto res = rootScene->GetUIContentByDisplayId(1);
631 ASSERT_EQ(res.second, true);
632 res = rootScene->GetUIContentByDisplayId(12);
633 }
634
635 /**
636 * @tc.name: RemoveRootScene
637 * @tc.desc: For RemoveRootScene Test
638 * @tc.type: FUNC
639 */
640 HWTEST_F(RootSceneTest, RemoveRootScene, TestSize.Level1)
641 {
642 sptr<RootScene> rootScene = sptr<RootScene>::MakeSptr();
643 rootScene->uiContent_ = std::make_unique<Ace::UIContentMocker>();
644 wptr<Window> weakWindow(rootScene);
645 rootScene->AddRootScene(0, weakWindow);
646
647 auto res = rootScene->GetUIContentByDisplayId(0);
648 ASSERT_EQ(res.second, true);
649 rootScene->RemoveRootScene(0);
650 res = rootScene->GetUIContentByDisplayId(0);
651 ASSERT_EQ(res.second, false);
652 }
653
654 } // namespace
655 } // namespace Rosen
656 } // namespace OHOS