1 /*
2  * Copyright (c) 2021-2022 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 // gtest
17 #include "window_option.h"
18 #include <gtest/gtest.h>
19 #include "window_manager.h"
20 #include "window_test_utils.h"
21 #include "wm_common.h"
22 #include "window_session_impl.h"
23 #include "window_scene_session_impl.h"
24 #include "mock_session.h"
25 #include "js_window.h"
26 #include "js_window_utils.h"
27 using namespace testing;
28 using namespace testing::ext;
29 
30 namespace OHOS {
31 namespace Rosen {
32 namespace {
33     constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowImmersiveTest1"};
34 
35     const Rect SYS_BAR_REGION_NULL = { 0, 0, 0, 0 };
36     const SystemBarProperty SYS_BAR_PROP_DEFAULT;
37     const SystemBarProperty SYS_BAR_PROP_1(true, 0xE5111111, 0xE5222222);
38     const SystemBarProperty SYS_BAR_PROP_2(false, 0xE5222222, 0xE5333333);
39     const SystemBarProperty SYS_BAR_PROP_3(false, 0xE5333333, 0xE5444444);
40     const SystemBarProperty SYS_BAR_PROP_4(true, 0xE5444444, 0x66555555);
41     const SystemBarRegionTints TEST_PROPS_DEFAULT = {
42         { WindowType::WINDOW_TYPE_STATUS_BAR, SYS_BAR_PROP_DEFAULT, SYS_BAR_REGION_NULL },
43         { WindowType::WINDOW_TYPE_NAVIGATION_BAR, SYS_BAR_PROP_DEFAULT, SYS_BAR_REGION_NULL },
44     };
45     const SystemBarRegionTints TEST_PROPS_1 = {
46         { WindowType::WINDOW_TYPE_STATUS_BAR, SYS_BAR_PROP_1, SYS_BAR_REGION_NULL },
47         { WindowType::WINDOW_TYPE_NAVIGATION_BAR, SYS_BAR_PROP_2, SYS_BAR_REGION_NULL },
48     };
49     const SystemBarRegionTints TEST_PROPS_2 = {
50         { WindowType::WINDOW_TYPE_STATUS_BAR, SYS_BAR_PROP_1, SYS_BAR_REGION_NULL },
51         { WindowType::WINDOW_TYPE_NAVIGATION_BAR, SYS_BAR_PROP_3, SYS_BAR_REGION_NULL },
52     };
53 
54     const Rect EMPTY_RECT = {0, 0, 0, 0};
55     const float RATIO = 0.3;
56 }
57 
58 using Utils = WindowTestUtils;
59 const int WAIT_ASYNC_US = 100000;  // 100000us
60 
61 class TestSystemBarChangedListener : public ISystemBarChangedListener {
62 public:
63     SystemBarRegionTints tints_ = TEST_PROPS_DEFAULT;
64     void OnSystemBarPropertyChange(DisplayId displayId, const SystemBarRegionTints& tints) override;
65 };
66 
67 class TestAvoidAreaChangedListener : public IAvoidAreaChangedListener {
68 public:
69     AvoidArea avoidArea_;
70     void OnAvoidAreaChanged(const AvoidArea avoidArea, AvoidAreaType type) override;
71 };
72 
73 class WindowImmersiveTest1 : public testing::Test {
74 public:
75     static void SetUpTestCase();
76     void SetUp() override;
77     void TearDown() override;
78     void SetWindowSystemProps(const sptr<Window>& window, const SystemBarRegionTints& props);
79     bool SystemBarPropsEqualsTo(const SystemBarRegionTints& expect);
80     void DumpFailedInfo(const SystemBarRegionTints& expect);
81     void DumpFailedInfo(bool expectStatus, bool expectNav);
82     bool SystemBarEnableState(bool expectStatus, bool expectNav);
83     DisplayId displayId_ = 0;
84     std::vector<sptr<Window>> activeWindows_;
85     static vector<Rect> fullScreenExpecteds_;
86     static sptr<TestSystemBarChangedListener> testSystemBarChangedListener_;
87     static sptr<TestAvoidAreaChangedListener> testAvoidAreaChangedListener_;
88     Utils::TestWindowInfo fullScreenAppinfo_;
89     Utils::TestWindowInfo avoidBarInfo_;
90     uint32_t leftAvoidW_;
91     uint32_t leftAvoidH_;
92     uint32_t topAvoidW_;
93     uint32_t topAvoidH_;
94     sptr<Window> backgroundWindow_;
95 };
96 
97 vector<Rect> WindowImmersiveTest1::fullScreenExpecteds_;
98 sptr<TestSystemBarChangedListener> WindowImmersiveTest1::testSystemBarChangedListener_ =
99     new TestSystemBarChangedListener();
100 sptr<TestAvoidAreaChangedListener> WindowImmersiveTest1::testAvoidAreaChangedListener_ =
101     new TestAvoidAreaChangedListener();
102 
SetWindowSystemProps(const sptr<Window>& window, const SystemBarRegionTints& tints)103 void WindowImmersiveTest1::SetWindowSystemProps(const sptr<Window>& window, const SystemBarRegionTints& tints)
104 {
105     for (auto tint : tints) {
106         window->SetSystemBarProperty(tint.type_, tint.prop_);
107     }
108 }
109 
DumpFailedInfo(const SystemBarRegionTints& expect)110 void WindowImmersiveTest1::DumpFailedInfo(const SystemBarRegionTints& expect)
111 {
112     auto act = testSystemBarChangedListener_->tints_;
113     WLOGI("WindowImmersiveTest1 Expected:");
114     for (auto tint : expect) {
115         WLOGI("WindowType: %{public}4d, Enable: %{public}4d, Color: %{public}x | %{public}x",
116             static_cast<uint32_t>(tint.type_), tint.prop_.enable_,
117             tint.prop_.backgroundColor_, tint.prop_.contentColor_);
118     }
119     WLOGI("WindowImmersiveTest1 Act: ");
120     for (auto tint : act) {
121         WLOGI("WindowType: %{public}4d, Enable: %{public}4d, Color: %{public}x | %{public}x",
122             static_cast<uint32_t>(tint.type_), tint.prop_.enable_,
123             tint.prop_.backgroundColor_, tint.prop_.contentColor_);
124     }
125 }
126 
DumpFailedInfo(bool expectStatus, bool expectNav)127 void WindowImmersiveTest1::DumpFailedInfo(bool expectStatus, bool expectNav)
128 {
129     auto act = testSystemBarChangedListener_->tints_;
130     WLOGI("WindowImmersiveTest1 Expected:");
131     WLOGI("expectStatus: %{public}4d, expectNav: %{public}4d", expectStatus, expectNav);
132     WLOGI("WindowImmersiveTest1 Act: ");
133     for (auto tint : act) {
134         WLOGI("WindowType: %{public}4d, Enable: %{public}4d, Color: %{public}x | %{public}x",
135             static_cast<uint32_t>(tint.type_), tint.prop_.enable_,
136             tint.prop_.backgroundColor_, tint.prop_.contentColor_);
137     }
138 }
139 
SystemBarPropsEqualsTo(const SystemBarRegionTints& expect)140 bool WindowImmersiveTest1::SystemBarPropsEqualsTo(const SystemBarRegionTints& expect)
141 {
142     usleep(WAIT_ASYNC_US);
143     auto act = testSystemBarChangedListener_->tints_;
144     if (act.size() != expect.size()) {
145         DumpFailedInfo(expect);
146         return false;
147     }
148     for (auto item : expect) {
149         bool check = false;
150         for (auto tint : act) {
151             if (item.prop_ == tint.prop_ && item.type_ == tint.type_) {
152                 check = true;
153                 break;
154             }
155         }
156         if (!check) {
157             DumpFailedInfo(expect);
158             return false;
159         }
160         check = false;
161     }
162     return true;
163 }
164 
SystemBarEnableState(bool expectStatus, bool expectNav)165 bool WindowImmersiveTest1::SystemBarEnableState(bool expectStatus, bool expectNav)
166 {
167     usleep(WAIT_ASYNC_US);
168     auto act = testSystemBarChangedListener_->tints_;
169     bool check = false;
170     for (auto tint : act) {
171         if ((tint.type_ == WindowType::WINDOW_TYPE_STATUS_BAR && tint.prop_.enable_ == expectStatus)
172             || (tint.type_ == WindowType::WINDOW_TYPE_NAVIGATION_BAR && tint.prop_.enable_ == expectNav)) {
173             check = true;
174         } else {
175             check = false;
176         }
177     }
178     if (!check) {
179         DumpFailedInfo(expectStatus, expectNav);
180     }
181     return check;
182 }
183 
OnSystemBarPropertyChange(DisplayId displayId, const SystemBarRegionTints& tints)184 void TestSystemBarChangedListener::OnSystemBarPropertyChange(DisplayId displayId, const SystemBarRegionTints& tints)
185 {
186     WLOGI("TestSystemBarChangedListener Display ID: %{public}" PRIu64"", displayId);
187     WLOGI("TestSystemBarChangedListener tints size: %{public}zu", tints.size());
188     for (auto tint : tints) {
189         auto type = tint.type_;
190         for (uint32_t i = 0; i < tints_.size(); i++) {
191             if (tints_[i].type_ == type) {
192                 tints_[i] = tint;
193             }
194         }
195     }
196 }
197 
OnAvoidAreaChanged(const AvoidArea avoidArea, AvoidAreaType type)198 void TestAvoidAreaChangedListener::OnAvoidAreaChanged(const AvoidArea avoidArea, AvoidAreaType type)
199 {
200     avoidArea_ = avoidArea;
201 }
202 
SetUpTestCase()203 void WindowImmersiveTest1::SetUpTestCase()
204 {
205     auto display = DisplayManager::GetInstance().GetDisplayById(0);
206     ASSERT_TRUE((display != nullptr));
207     WLOGI("GetDefaultDisplay: id %{public}" PRIu64", w %{public}d, h %{public}d, fps %{public}u",
208         display->GetId(), display->GetWidth(), display->GetHeight(), display->GetRefreshRate());
209     Rect displayRect = {0, 0, display->GetWidth(), display->GetHeight()};
210     Utils::InitByDisplayRect(displayRect);
211 }
212 
SetUp()213 void WindowImmersiveTest1::SetUp()
214 {
215     fullScreenAppinfo_ = {
216         .name = "main",
217         .rect = Utils::customAppRect_,
218         .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW,
219         .mode = WindowMode::WINDOW_MODE_FULLSCREEN, // immersive setting
220         .needAvoid = false, // immersive setting
221         .parentLimit = false,
222         .parentId = INVALID_WINDOW_ID,
223     };
224 
225     avoidBarInfo_ = {
226         .name = "LeftAvoidTest",
227         .rect = EMPTY_RECT,
228         .type = WindowType::WINDOW_TYPE_STATUS_BAR,
229         .mode = WindowMode::WINDOW_MODE_FLOATING,
230     };
231     // makesure left avoid win w < h
232     leftAvoidW_ = std::min(Utils::displayRect_.width_, static_cast<uint32_t>(Utils::displayRect_.height_ * RATIO));
233     leftAvoidH_ = Utils::displayRect_.height_;
234     // makesure top avoid win h < w
235     topAvoidW_ = Utils::displayRect_.width_;
236     topAvoidH_ = std::min(Utils::displayRect_.height_, static_cast<uint32_t>(Utils::displayRect_.width_ * RATIO));
237 
238     WindowManager::GetInstance().RegisterSystemBarChangedListener(testSystemBarChangedListener_);
239     activeWindows_.clear();
240     sleep(1);
241 }
242 
TearDown()243 void WindowImmersiveTest1::TearDown()
244 {
245     while (!activeWindows_.empty()) {
246         EXPECT_EQ(WMError::WM_OK, activeWindows_.back()->Destroy());
247         activeWindows_.pop_back();
248     }
249     WindowManager::GetInstance().UnregisterSystemBarChangedListener(testSystemBarChangedListener_);
250     sleep(1);
251 }
252 
253 namespace {
254 
UpdateSystemBarProperties(std::map<WindowType, SystemBarProperty>& systemBarProperties, const std::map<WindowType, SystemBarPropertyFlag>& systemBarPropertyFlags, sptr<WindowSceneSessionImpl> windowToken)255 static void UpdateSystemBarProperties(std::map<WindowType, SystemBarProperty>& systemBarProperties,
256     const std::map<WindowType, SystemBarPropertyFlag>& systemBarPropertyFlags, sptr<WindowSceneSessionImpl> windowToken)
257 {
258     for (auto it : systemBarPropertyFlags) {
259         WindowType type = it.first;
260         SystemBarPropertyFlag flag = it.second;
261         auto property = windowToken->GetSystemBarPropertyByType(type);
262         if (flag.enableFlag == false) {
263             systemBarProperties[type].enable_ = property.enable_;
264         }
265         if (flag.backgroundColorFlag == false) {
266             systemBarProperties[type].backgroundColor_ = property.backgroundColor_;
267         }
268         if (flag.contentColorFlag == false) {
269             systemBarProperties[type].contentColor_ = property.contentColor_;
270         }
271         if (flag.enableAnimationFlag == false) {
272             systemBarProperties[type].enableAnimation_ = property.enableAnimation_;
273         }
274         if (flag.enableFlag == true) {
275             systemBarProperties[type].settingFlag_ =
276                 static_cast<SystemBarSettingFlag>(static_cast<uint32_t>(property.settingFlag_) |
277                 static_cast<uint32_t>(SystemBarSettingFlag::ENABLE_SETTING));
278         }
279         if (flag.backgroundColorFlag == true || flag.contentColorFlag == true) {
280             systemBarProperties[type].settingFlag_ =
281                 static_cast<SystemBarSettingFlag>(static_cast<uint32_t>(property.settingFlag_) |
282                 static_cast<uint32_t>(SystemBarSettingFlag::COLOR_SETTING));
283         }
284     }
285     return;
286 }
287 
SetSystemBarPropertiesByFlags(std::map<WindowType, SystemBarPropertyFlag>& systemBarPropertyFlags, std::map<WindowType, SystemBarProperty>& systemBarProperties, sptr<WindowSceneSessionImpl> windowToken)288 static WMError SetSystemBarPropertiesByFlags(std::map<WindowType, SystemBarPropertyFlag>& systemBarPropertyFlags,
289     std::map<WindowType, SystemBarProperty>& systemBarProperties, sptr<WindowSceneSessionImpl> windowToken)
290 {
291     WMError ret = WMError::WM_OK;
292     WMError err = WMError::WM_OK;
293 
294     for (auto it : systemBarPropertyFlags) {
295         WindowType type = it.first;
296         SystemBarPropertyFlag flag = it.second;
297         if (flag.enableFlag || flag.backgroundColorFlag || flag.contentColorFlag || flag.enableAnimationFlag) {
298             err = windowToken->SetSystemBarProperty(type, systemBarProperties.at(type));
299             if (err != WMError::WM_OK) {
300                 TLOGE(WmsLogTag::WMS_IMMS, "SetSystemBarProperty failed, ret = %{public}d", err);
301                 ret = err;
302             }
303         }
304     }
305     return ret;
306 }
307 
GetSystemBarStatus(std::map<WindowType, SystemBarProperty>& systemBarProperties, std::map<WindowType, SystemBarPropertyFlag>& systemBarPropertyFlags, WindowType type)308 void GetSystemBarStatus(std::map<WindowType, SystemBarProperty>& systemBarProperties,
309                         std::map<WindowType, SystemBarPropertyFlag>& systemBarPropertyFlags, WindowType type)
310 {
311     systemBarProperties[WindowType::WINDOW_TYPE_STATUS_BAR].enable_ = false;
312     systemBarProperties[WindowType::WINDOW_TYPE_NAVIGATION_INDICATOR].enable_ = false;
313     systemBarProperties[WindowType::WINDOW_TYPE_NAVIGATION_BAR].enable_ = false;
314     systemBarPropertyFlags[WindowType::WINDOW_TYPE_STATUS_BAR] = {true, true, true, true};
315     systemBarPropertyFlags[WindowType::WINDOW_TYPE_NAVIGATION_INDICATOR] = {true, true, true, true};
316     systemBarPropertyFlags[WindowType::WINDOW_TYPE_NAVIGATION_BAR] = {true, true, true, true};
317 
318     if (type == WindowType::WINDOW_TYPE_STATUS_BAR) {
319         systemBarProperties[WindowType::WINDOW_TYPE_STATUS_BAR].enable_ = true;
320         systemBarProperties[WindowType::WINDOW_TYPE_NAVIGATION_INDICATOR].enable_ = true;
321     } else if (type == WindowType::WINDOW_TYPE_NAVIGATION_BAR) {
322         systemBarProperties[WindowType::WINDOW_TYPE_NAVIGATION_BAR].enable_ = true;
323     }
324 }
325 
GetSystemBarStatus(std::map<WindowType, SystemBarProperty>& systemBarProperties, SystemBarProperty pro, std::map<WindowType, SystemBarPropertyFlag>& systemBarPropertyFlags, WindowType type)326 void GetSystemBarStatus(std::map<WindowType, SystemBarProperty>& systemBarProperties, SystemBarProperty pro,
327                         std::map<WindowType, SystemBarPropertyFlag>& systemBarPropertyFlags, WindowType type)
328 {
329     systemBarPropertyFlags[WindowType::WINDOW_TYPE_STATUS_BAR] = {true, true, true, true};
330     systemBarPropertyFlags[WindowType::WINDOW_TYPE_NAVIGATION_INDICATOR] = {true, true, true, true};
331     systemBarPropertyFlags[WindowType::WINDOW_TYPE_NAVIGATION_BAR] = {true, true, true, true};
332 
333     if (type == WindowType::WINDOW_TYPE_STATUS_BAR) {
334         systemBarProperties[type] = pro;
335         systemBarProperties[WindowType::WINDOW_TYPE_NAVIGATION_INDICATOR] = pro;
336     } else if (type == WindowType::WINDOW_TYPE_NAVIGATION_BAR) {
337         systemBarProperties[type] = pro;
338     }
339 }
340 
GetSpecificBarStatus( std::map<WindowType, SystemBarProperty>& systemBarProperties, std::map<WindowType, SystemBarPropertyFlag>& systemBarPropertyFlags, WindowType type)341 void GetSpecificBarStatus(
342     std::map<WindowType, SystemBarProperty>& systemBarProperties,
343     std::map<WindowType, SystemBarPropertyFlag>& systemBarPropertyFlags,
344     WindowType type)
345 {
346     systemBarProperties[WindowType::WINDOW_TYPE_STATUS_BAR].enable_ = false;
347     systemBarProperties[WindowType::WINDOW_TYPE_NAVIGATION_INDICATOR].enable_ = false;
348     systemBarProperties[WindowType::WINDOW_TYPE_NAVIGATION_BAR].enable_ = false;
349     systemBarPropertyFlags[WindowType::WINDOW_TYPE_STATUS_BAR] = {true, true, true, true};
350     systemBarPropertyFlags[WindowType::WINDOW_TYPE_NAVIGATION_INDICATOR] = {true, true, true, true};
351     systemBarPropertyFlags[WindowType::WINDOW_TYPE_NAVIGATION_BAR] = {true, true, true, true};
352     if (type == WindowType::WINDOW_TYPE_STATUS_BAR) {
353         systemBarProperties[WindowType::WINDOW_TYPE_STATUS_BAR].enable_ = true;
354     } else if (type == WindowType::WINDOW_TYPE_NAVIGATION_BAR) {
355         systemBarProperties[WindowType::WINDOW_TYPE_NAVIGATION_BAR].enable_ = true;
356     } else if (type == WindowType::WINDOW_TYPE_NAVIGATION_INDICATOR) {
357         systemBarProperties[WindowType::WINDOW_TYPE_NAVIGATION_INDICATOR].enable_ = true;
358     }
359 }
360 
361 /**
362  * @tc.name: SetFullScreen
363  * @tc.desc: SetFullScreen
364  * @tc.type: FUNC
365  */
HWTEST_F(WindowImmersiveTest1, setFullScreen, Function | MediumTest | Level3)366 HWTEST_F(WindowImmersiveTest1, setFullScreen, Function | MediumTest | Level3)
367 {
368     const vector<WindowMode>windowMode{WindowMode::WINDOW_MODE_FULLSCREEN, WindowMode::WINDOW_MODE_SPLIT_PRIMARY,
369          WindowMode::WINDOW_MODE_SPLIT_SECONDARY, WindowMode::WINDOW_MODE_FLOATING};
370 
371     for (auto mode : windowMode) {
372         sptr<WindowOption> option = new (std::nothrow) WindowOption();
373         ASSERT_NE(nullptr, option);
374         option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
375         option->SetWindowMode(mode);
376 
377         sptr<WindowSceneSessionImpl> window = new WindowSceneSessionImpl(option);
378         EXPECT_FALSE(window == nullptr);
379 
380         SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
381         sptr<SessionMocker> session = new(std::nothrow) SessionMocker(sessionInfo);
382         ASSERT_NE(nullptr, session);
383         window->property_->SetPersistentId(1);
384         window->hostSession_ = session;
385         window->state_ = WindowState::STATE_SHOWN;
386         activeWindows_.push_back(window);
387         EXPECT_EQ(WMError::WM_OK, window->SetFullScreen(true));
388 
389         if (mode != WindowMode::WINDOW_MODE_FULLSCREEN) {
390             EXPECT_EQ(WMError::WM_OK, window->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN));
391         }
392         EXPECT_EQ(true, window->IsFullScreen());
393 
394         window->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
395 
396         if (mode == WindowMode::WINDOW_MODE_FULLSCREEN) {
397             EXPECT_EQ(WMError::WM_OK, window->SetFullScreen(false));
398             EXPECT_EQ(false, window->IsFullScreen());
399         } else {
400             EXPECT_EQ(WMError::WM_OK, window->SetFullScreen(false));
401             EXPECT_EQ(WMError::WM_OK, window->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN));
402             EXPECT_EQ(false, window->IsFullScreen());
403         }
404 
405         window->SetWindowType(WindowType::WINDOW_TYPE_DESKTOP);
406         window->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
407         EXPECT_EQ(WMError::WM_OK, window->SetFullScreen(false));
408         EXPECT_EQ(false, window->IsFullScreen());
409     }
410 }
411 
412 /**
413  * @tc.name: SetLayoutFullScreen
414  * @tc.desc: SetLayoutFullScreen
415  * @tc.type: FUNC
416  */
HWTEST_F(WindowImmersiveTest1, setLayoutFullScreen, Function | MediumTest | Level3)417 HWTEST_F(WindowImmersiveTest1, setLayoutFullScreen, Function | MediumTest | Level3)
418 {
419     const vector<WindowMode>windowMode{WindowMode::WINDOW_MODE_FULLSCREEN, WindowMode::WINDOW_MODE_SPLIT_PRIMARY,
420          WindowMode::WINDOW_MODE_SPLIT_SECONDARY, WindowMode::WINDOW_MODE_FLOATING};
421 
422     for (auto mode : windowMode) {
423         sptr<WindowOption> option = new (std::nothrow) WindowOption();
424         ASSERT_NE(nullptr, option);
425         option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
426         option->SetWindowMode(mode);
427 
428         sptr<WindowSceneSessionImpl> window = new WindowSceneSessionImpl(option);
429         EXPECT_FALSE(window == nullptr);
430 
431         SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
432         sptr<SessionMocker> session = new(std::nothrow) SessionMocker(sessionInfo);
433         ASSERT_NE(nullptr, session);
434         window->property_->SetPersistentId(1);
435         window->hostSession_ = session;
436         window->state_ = WindowState::STATE_SHOWN;
437         activeWindows_.push_back(window);
438         EXPECT_EQ(WMError::WM_OK, window->SetLayoutFullScreen(true));
439 
440         if (mode != WindowMode::WINDOW_MODE_FULLSCREEN) {
441             EXPECT_EQ(WMError::WM_OK, window->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN));
442         }
443         EXPECT_EQ(true, window->IsLayoutFullScreen());
444 
445         window->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
446         if (mode == WindowMode::WINDOW_MODE_FULLSCREEN) {
447             EXPECT_EQ(WMError::WM_OK, window->SetLayoutFullScreen(false));
448             EXPECT_EQ(false, window->IsLayoutFullScreen());
449         } else {
450             EXPECT_EQ(WMError::WM_OK, window->SetLayoutFullScreen(false));
451             EXPECT_EQ(WMError::WM_OK, window->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN));
452             EXPECT_EQ(false, window->IsLayoutFullScreen());
453         }
454 
455         window->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
456         window->SetWindowType(WindowType::WINDOW_TYPE_DESKTOP);
457         EXPECT_EQ(WMError::WM_OK, window->SetLayoutFullScreen(false));
458         EXPECT_EQ(false, window->IsLayoutFullScreen());
459     }
460 }
461 
462 /**
463  * @tc.name: SetImmersiveModeEnabledState
464  * @tc.desc: SetImmersiveModeEnabledState
465  * @tc.type: FUNC
466  */
HWTEST_F(WindowImmersiveTest1, setImmersiveModeEnabledState, Function | MediumTest | Level3)467 HWTEST_F(WindowImmersiveTest1, setImmersiveModeEnabledState, Function | MediumTest | Level3)
468 {
469     sptr<WindowOption> option = new (std::nothrow) WindowOption();
470     ASSERT_NE(nullptr, option);
471     sptr<WindowSceneSessionImpl> window = new (std::nothrow) WindowSceneSessionImpl(option);
472     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->SetImmersiveModeEnabledState(false));
473 
474     window->property_->SetPersistentId(1);
475     SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
476     sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
477     ASSERT_NE(nullptr, session);
478     window->hostSession_ = session;
479     window->property_->SetWindowName("SetImmersiveModeEnabledState");
480     window->property_->SetWindowType(WindowType::WINDOW_TYPE_PIP);
481     window->state_ = WindowState::STATE_CREATED;
482     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->SetImmersiveModeEnabledState(false));
483 
484     window->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
485     ASSERT_EQ(WMError::WM_OK, window->SetImmersiveModeEnabledState(true));
486     ASSERT_EQ(true, window->GetImmersiveModeEnabledState());
487     ASSERT_EQ(WMError::WM_OK, window->SetImmersiveModeEnabledState(false));
488     ASSERT_EQ(false, window->GetImmersiveModeEnabledState());
489 
490     window->property_->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
491     ASSERT_EQ(WMError::WM_OK, window->SetLayoutFullScreen(true));
492     ASSERT_EQ(true, window->IsLayoutFullScreen());
493     ASSERT_EQ(WMError::WM_OK, window->SetLayoutFullScreen(false));
494     ASSERT_EQ(false, window->IsLayoutFullScreen());
495     ASSERT_EQ(WMError::WM_OK, window->SetImmersiveModeEnabledState(true));
496     ASSERT_EQ(true, window->IsLayoutFullScreen());
497     ASSERT_EQ(WMError::WM_OK, window->SetImmersiveModeEnabledState(false));
498     ASSERT_EQ(false, window->IsLayoutFullScreen());
499 
500     window->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
501     ASSERT_EQ(WMError::WM_OK, window->SetImmersiveModeEnabledState(true));
502     ASSERT_EQ(true, window->IsLayoutFullScreen());
503     ASSERT_EQ(true, window->GetImmersiveModeEnabledState());
504 
505     window->property_->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_PRIMARY);
506     ASSERT_EQ(WMError::WM_OK, window->SetImmersiveModeEnabledState(true));
507     ASSERT_EQ(true, window->IsLayoutFullScreen());
508     ASSERT_EQ(true, window->GetImmersiveModeEnabledState());
509 
510     window->property_->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_SECONDARY);
511     ASSERT_EQ(WMError::WM_OK, window->SetImmersiveModeEnabledState(true));
512     ASSERT_EQ(true, window->IsLayoutFullScreen());
513     ASSERT_EQ(true, window->GetImmersiveModeEnabledState());
514     ASSERT_EQ(true, window->IsLayoutFullScreen());
515 
516     window->property_->SetWindowType(WindowType::WINDOW_TYPE_DESKTOP);
517     window->property_->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
518     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->SetImmersiveModeEnabledState(true));
519     ASSERT_EQ(true, window->GetImmersiveModeEnabledState());
520     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->SetImmersiveModeEnabledState(false));
521     ASSERT_EQ(true, window->GetImmersiveModeEnabledState());
522 }
523 
524 /**
525  * @tc.name: SetWindowSystemBarEnable_1
526  * @tc.desc: SetWindowSystemBarEnable_1 WINDOW_TYPE_APP_MAIN_WINDOW
527  * @tc.type: FUNC
528  */
HWTEST_F(WindowImmersiveTest1, setWindowSystemBarEnable_1, Function | MediumTest | Level3)529 HWTEST_F(WindowImmersiveTest1, setWindowSystemBarEnable_1, Function | MediumTest | Level3)
530 {
531     const vector<WindowMode>windowMode{WindowMode::WINDOW_MODE_FULLSCREEN, WindowMode::WINDOW_MODE_SPLIT_PRIMARY,
532          WindowMode::WINDOW_MODE_SPLIT_SECONDARY, WindowMode::WINDOW_MODE_FLOATING};
533     const vector<WindowType>windowType{WindowType::WINDOW_TYPE_STATUS_BAR, WindowType::WINDOW_TYPE_NAVIGATION_BAR};
534     for (auto type : windowType) {
535         for (auto mode : windowMode) {
536             sptr<WindowOption> option = new (std::nothrow) WindowOption();
537             ASSERT_NE(nullptr, option);
538             option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
539             option->SetWindowMode(mode);
540             sptr<WindowSceneSessionImpl> window = new WindowSceneSessionImpl(option);
541             EXPECT_FALSE(window == nullptr);
542             SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
543             sptr<SessionMocker> session = new(std::nothrow) SessionMocker(sessionInfo);
544             ASSERT_NE(nullptr, session);
545             window->property_->SetPersistentId(1);
546             window->hostSession_ = session;
547             window->state_ = WindowState::STATE_SHOWN;
548             activeWindows_.push_back(window);
549             std::map<WindowType, SystemBarProperty> systemBarProperties;
550             std::map<WindowType, SystemBarPropertyFlag> systemBarPropertyFlags;
551             GetSystemBarStatus(systemBarProperties, systemBarPropertyFlags, type);
552             UpdateSystemBarProperties(systemBarProperties, systemBarPropertyFlags, window);
553             WMError ret = SetSystemBarPropertiesByFlags(systemBarPropertyFlags, systemBarProperties, window);
554             EXPECT_EQ(WMError::WM_OK, ret);
555             sleep(1);
556             if (type == WindowType::WINDOW_TYPE_STATUS_BAR) {
557                 auto sta = window->GetSystemBarPropertyByType(WindowType::WINDOW_TYPE_STATUS_BAR);
558                 auto nav = window->GetSystemBarPropertyByType(WindowType::WINDOW_TYPE_NAVIGATION_INDICATOR);
559                 EXPECT_EQ(true, sta.enable_);
560                 EXPECT_EQ(true, nav.enable_);
561             } else if (type == WindowType::WINDOW_TYPE_NAVIGATION_BAR) {
562                 auto nav = window->GetSystemBarPropertyByType(WindowType::WINDOW_TYPE_NAVIGATION_BAR);
563                 EXPECT_EQ(true, nav.enable_);
564             }
565         }
566     }
567 }
568 
569 /**
570  * @tc.name: SetWindowSystemBarEnable_2
571  * @tc.desc: SetWindowSystemBarEnable_2
572  * @tc.type: FUNC
573  */
HWTEST_F(WindowImmersiveTest1, setWindowSystemBarEnable_2, Function | MediumTest | Level3)574 HWTEST_F(WindowImmersiveTest1, setWindowSystemBarEnable_2, Function | MediumTest | Level3)
575 {
576     const vector<WindowMode>windowMode{WindowMode::WINDOW_MODE_FULLSCREEN, WindowMode::WINDOW_MODE_SPLIT_PRIMARY,
577          WindowMode::WINDOW_MODE_SPLIT_SECONDARY, WindowMode::WINDOW_MODE_FLOATING};
578     const vector<WindowType>windowType{WindowType::WINDOW_TYPE_STATUS_BAR, WindowType::WINDOW_TYPE_NAVIGATION_BAR};
579     for (auto type : windowType) {
580         for (auto mode : windowMode) {
581             sptr<WindowOption> option = new (std::nothrow) WindowOption();
582             ASSERT_NE(nullptr, option);
583             option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
584             option->SetWindowMode(mode);
585             sptr<WindowSceneSessionImpl> window = new WindowSceneSessionImpl(option);
586             EXPECT_FALSE(window == nullptr);
587             SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
588             sptr<SessionMocker> session = new(std::nothrow) SessionMocker(sessionInfo);
589             ASSERT_NE(nullptr, session);
590             window->property_->SetPersistentId(1);
591             window->hostSession_ = session;
592             window->state_ = WindowState::STATE_SHOWN;
593             activeWindows_.push_back(window);
594             std::map<WindowType, SystemBarProperty> systemBarProperties;
595             std::map<WindowType, SystemBarPropertyFlag> systemBarPropertyFlags;
596             GetSystemBarStatus(systemBarProperties, systemBarPropertyFlags, type);
597             UpdateSystemBarProperties(systemBarProperties, systemBarPropertyFlags, window);
598             WMError ret = SetSystemBarPropertiesByFlags(systemBarPropertyFlags, systemBarProperties, window);
599             EXPECT_EQ(WMError::WM_OK, ret);
600 
601             GetSystemBarStatus(systemBarProperties, systemBarPropertyFlags, WindowType::APP_WINDOW_BASE);
602             UpdateSystemBarProperties(systemBarProperties, systemBarPropertyFlags, window);
603             ret = SetSystemBarPropertiesByFlags(systemBarPropertyFlags, systemBarProperties, window);
604             EXPECT_EQ(WMError::WM_OK, ret);
605             sleep(1);
606             auto sta = window->GetSystemBarPropertyByType(WindowType::WINDOW_TYPE_STATUS_BAR);
607             auto nav = window->GetSystemBarPropertyByType(WindowType::WINDOW_TYPE_NAVIGATION_INDICATOR);
608             EXPECT_EQ(false, sta.enable_);
609             EXPECT_EQ(false, nav.enable_);
610             window->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
611             GetSystemBarStatus(systemBarProperties, systemBarPropertyFlags, type);
612             UpdateSystemBarProperties(systemBarProperties, systemBarPropertyFlags, window);
613             ret = SetSystemBarPropertiesByFlags(systemBarPropertyFlags, systemBarProperties, window);
614             EXPECT_EQ(WMError::WM_OK, ret);
615             sleep(1);
616             sta = window->GetSystemBarPropertyByType(WindowType::WINDOW_TYPE_STATUS_BAR);
617             nav = window->GetSystemBarPropertyByType(WindowType::WINDOW_TYPE_NAVIGATION_INDICATOR);
618             EXPECT_EQ(false, sta.enable_);
619             EXPECT_EQ(false, nav.enable_);
620         }
621     }
622 }
623 
624 /**
625  * @tc.name: SetSpecificBarProperty
626  * @tc.desc: SetSpecificBarProperty
627  * @tc.type: FUNC
628  */
HWTEST_F(WindowImmersiveTest1, setSpecificBarProperty, Function | MediumTest | Level3)629 HWTEST_F(WindowImmersiveTest1, setSpecificBarProperty, Function | MediumTest | Level3)
630 {
631     const vector<WindowMode>windowMode{WindowMode::WINDOW_MODE_FULLSCREEN, WindowMode::WINDOW_MODE_SPLIT_PRIMARY,
632             WindowMode::WINDOW_MODE_SPLIT_SECONDARY, WindowMode::WINDOW_MODE_FLOATING};
633     const vector<WindowType>windowType{WindowType::WINDOW_TYPE_STATUS_BAR, WindowType::WINDOW_TYPE_NAVIGATION_BAR,
634             WindowType::WINDOW_TYPE_NAVIGATION_INDICATOR};
635     for (auto mode : windowMode) {
636         for (auto type : windowType) {
637             sptr<WindowOption> option = new (std::nothrow) WindowOption();
638             ASSERT_NE(nullptr, option);
639             option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
640             option->SetWindowMode(mode);
641 
642             sptr<WindowSceneSessionImpl> window = new WindowSceneSessionImpl(option);
643             EXPECT_FALSE(window == nullptr);
644 
645             SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
646             sptr<SessionMocker> session = new(std::nothrow) SessionMocker(sessionInfo);
647             ASSERT_NE(nullptr, session);
648             window->property_->SetPersistentId(1);
649             window->hostSession_ = session;
650             window->state_ = WindowState::STATE_SHOWN;
651             activeWindows_.push_back(window);
652 
653             std::map<WindowType, SystemBarProperty> systemBarProperties;
654             std::map<WindowType, SystemBarPropertyFlag> systemBarPropertyFlags;
655             GetSpecificBarStatus(systemBarProperties, systemBarPropertyFlags, type);
656             WMError ret = window->SetSpecificBarProperty(type, systemBarProperties[type]);
657             EXPECT_EQ(WMError::WM_OK, ret);
658             auto status = window->GetSystemBarPropertyByType(type);
659             EXPECT_EQ(true, status.enable_);
660 
661             GetSpecificBarStatus(systemBarProperties, systemBarPropertyFlags, WindowType::APP_WINDOW_BASE);
662             ret = window->SetSpecificBarProperty(type, systemBarProperties[type]);
663             EXPECT_EQ(WMError::WM_OK, ret);
664             status = window->GetSystemBarPropertyByType(type);
665             EXPECT_EQ(false, status.enable_);
666 
667             window->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
668 
669             GetSpecificBarStatus(systemBarProperties, systemBarPropertyFlags, WindowType::APP_WINDOW_BASE);
670             ret = window->SetSpecificBarProperty(type, systemBarProperties[type]);
671             EXPECT_EQ(WMError::WM_OK, ret);
672             status = window->GetSystemBarPropertyByType(type);
673             EXPECT_EQ(false, status.enable_);
674         }
675     }
676 }
677 
678 /**
679  * @tc.name: SetWindowSystemBarProperties
680  * @tc.desc: SetWindowSystemBarProperties
681  * @tc.type: FUNC
682  */
HWTEST_F(WindowImmersiveTest1, setWindowSystemBarProperties, Function | MediumTest | Level3)683 HWTEST_F(WindowImmersiveTest1, setWindowSystemBarProperties, Function | MediumTest | Level3)
684 {
685     const vector<WindowMode>windowMode{WindowMode::WINDOW_MODE_FULLSCREEN, WindowMode::WINDOW_MODE_SPLIT_PRIMARY,
686          WindowMode::WINDOW_MODE_SPLIT_SECONDARY, WindowMode::WINDOW_MODE_FLOATING};
687     const vector<WindowType>windowType{WindowType::WINDOW_TYPE_STATUS_BAR, WindowType::WINDOW_TYPE_NAVIGATION_BAR};
688 
689     for (auto type : windowType) {
690         for (auto mode : windowMode) {
691             sptr<WindowOption> option = new (std::nothrow) WindowOption();
692             ASSERT_NE(nullptr, option);
693             option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
694             option->SetWindowMode(mode);
695 
696             sptr<WindowSceneSessionImpl> window = new WindowSceneSessionImpl(option);
697             EXPECT_FALSE(window == nullptr);
698 
699             SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
700             sptr<SessionMocker> session = new(std::nothrow) SessionMocker(sessionInfo);
701             ASSERT_NE(nullptr, session);
702             window->property_->SetPersistentId(1);
703             window->hostSession_ = session;
704             window->state_ = WindowState::STATE_SHOWN;
705             activeWindows_.push_back(window);
706 
707             std::map<WindowType, SystemBarProperty> systemBarProperties;
708             std::map<WindowType, SystemBarPropertyFlag> systemBarPropertyFlags;
709             GetSystemBarStatus(systemBarProperties, SYS_BAR_PROP_1, systemBarPropertyFlags, type);
710             UpdateSystemBarProperties(systemBarProperties, systemBarPropertyFlags, window);
711             WMError ret = SetSystemBarPropertiesByFlags(systemBarPropertyFlags, systemBarProperties, window);
712             EXPECT_EQ(WMError::WM_OK, ret);
713             sleep(1);
714             auto sta = window->GetSystemBarPropertyByType(type);
715             EXPECT_EQ(SYS_BAR_PROP_1, sta);
716 
717             GetSystemBarStatus(systemBarProperties, SYS_BAR_PROP_2, systemBarPropertyFlags, type);
718             UpdateSystemBarProperties(systemBarProperties, systemBarPropertyFlags, window);
719             ret = SetSystemBarPropertiesByFlags(systemBarPropertyFlags, systemBarProperties, window);
720             EXPECT_EQ(WMError::WM_OK, ret);
721             sleep(1);
722             sta = window->GetSystemBarPropertyByType(type);
723             EXPECT_EQ(SYS_BAR_PROP_2, sta);
724 
725             window->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
726 
727             GetSystemBarStatus(systemBarProperties, SYS_BAR_PROP_1, systemBarPropertyFlags, type);
728             UpdateSystemBarProperties(systemBarProperties, systemBarPropertyFlags, window);
729             ret = SetSystemBarPropertiesByFlags(systemBarPropertyFlags, systemBarProperties, window);
730             EXPECT_EQ(WMError::WM_OK, ret);
731             sleep(1);
732             sta = window->GetSystemBarPropertyByType(type);
733             EXPECT_EQ(SYS_BAR_PROP_2, sta);
734         }
735     }
736 }
737 }
738 } // namespace Rosen
739 } // namespace OHOS