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 <gtest/gtest.h>
18 #include "avoid_area_controller.h"
19 #include "window_manager.h"
20 #include "window_test_utils.h"
21 #include "wm_common.h"
22 using namespace testing;
23 using namespace testing::ext;
24 
25 namespace OHOS {
26 namespace Rosen {
27 using Utils = WindowTestUtils;
28 
29 class WindowSplitImmersiveTest : public testing::Test {
30 public:
31     static void SetUpTestCase();
32     static void TearDownTestCase();
33     virtual void SetUp() override;
34     virtual void TearDown() override;
35     void IsShowTopBar(const sptr<Window>& top, bool isShow);
36     void HideAndUnregister(const sptr<Window>& fullWindow, const sptr<Window>& priWindow, const sptr<Window>& top);
37 
38     std::vector<sptr<Window>> activeWindows_;
39     Utils::TestWindowInfo fullInfo_;
40     Utils::TestWindowInfo splitInfo_;
41 
42 private:
43     static constexpr uint32_t SPLIT_TEST_SLEEP_S = 1; // split test sleep time
44 };
45 
SetUpTestCase()46 void WindowSplitImmersiveTest::SetUpTestCase()
47 {
48 }
49 
TearDownTestCase()50 void WindowSplitImmersiveTest::TearDownTestCase()
51 {
52 }
53 
SetUp()54 void WindowSplitImmersiveTest::SetUp()
55 {
56     fullInfo_ = {
57         .name = "fullscreen.1",
58         .rect = Utils::customAppRect_,
59         .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW,
60         .mode = WindowMode::WINDOW_MODE_FULLSCREEN,
61         .needAvoid = true,
62         .parentLimit = false,
63         .parentId = INVALID_WINDOW_ID,
64     };
65 
66     splitInfo_ = {
67         .name = "primary.1",
68         .rect = Utils::customAppRect_,
69         .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW,
70         .mode = WindowMode::WINDOW_MODE_FULLSCREEN,
71         .needAvoid = true,
72         .parentLimit = false,
73         .parentId = INVALID_WINDOW_ID,
74     };
75 
76     activeWindows_.clear();
77 }
78 
TearDown()79 void WindowSplitImmersiveTest::TearDown()
80 {
81     while (!activeWindows_.empty()) {
82         ASSERT_EQ(WMError::WM_OK, activeWindows_.back()->Destroy());
83         activeWindows_.pop_back();
84     }
85 }
86 
87 namespace {
88 /**
89  * @tc.name: SplitImmersive01
90  * @tc.desc: one primary window and one fullscreen window, test enter and out split immersive
91  * @tc.type: FUNC
92  */
93 HWTEST_F(WindowSplitImmersiveTest, SplitImmersive01, Function | MediumTest | Level3)
94 {
95     // create fullscreen win and show
96     fullInfo_.mode = WindowMode::WINDOW_MODE_SPLIT_SECONDARY;
97     const sptr<Window>& fullWindow = Utils::CreateTestWindow(fullInfo_);
98     if (fullWindow == nullptr) {
99         return;
100     }
101 
102     activeWindows_.push_back(fullWindow);
103     ASSERT_EQ(WMError::WM_OK, fullWindow->Show());
104     sleep(SPLIT_TEST_SLEEP_S);
105 
106     // enter split mode
107     splitInfo_.mode = WindowMode::WINDOW_MODE_SPLIT_PRIMARY;
108     const sptr<Window>& priWindow = Utils::CreateTestWindow(splitInfo_);
109     ASSERT_NE(nullptr, priWindow);
110     activeWindows_.push_back(priWindow);
111     ASSERT_EQ(WMError::WM_OK, priWindow->Show());
112     sleep(SPLIT_TEST_SLEEP_S);
113 
114     // check is enter split Immersive
115     ASSERT_EQ(WindowMode::WINDOW_MODE_SPLIT_PRIMARY, priWindow->GetMode());
116     ASSERT_EQ(WindowMode::WINDOW_MODE_SPLIT_SECONDARY, fullWindow->GetMode());
117     Rect immersivePriRect = priWindow->GetRect();
118     ASSERT_EQ(0, immersivePriRect.posX_);
119     ASSERT_EQ(0, immersivePriRect.posY_);
120     sleep(SPLIT_TEST_SLEEP_S);
121 
122     ASSERT_EQ(WMError::WM_OK, fullWindow->Hide());
123     sleep(SPLIT_TEST_SLEEP_S);
124     ASSERT_EQ(WMError::WM_OK, priWindow->Hide());
125     sleep(SPLIT_TEST_SLEEP_S);
126 }
127 }
128 } // namespace Rosen
129 } // namespace OHOS
130