• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 "window_test_utils.h"
19 #include "wm_common.h"
20 using namespace testing;
21 using namespace testing::ext;
22 
23 namespace OHOS {
24 namespace Rosen {
25 using Utils = WindowTestUtils;
26 class WindowSplitTest : public testing::Test {
27 public:
28     static void SetUpTestCase();
29     static void TearDownTestCase();
30     virtual void SetUp() override;
31     virtual void TearDown() override;
32     std::vector<sptr<Window>> activeWindows_;
33     Utils::TestWindowInfo fullInfo_;
34     Utils::TestWindowInfo splitInfo_;
35 
36 private:
37     static constexpr uint32_t SPLIT_TEST_SLEEP_S = 1; // split test sleep time
38 };
39 
SetUpTestCase()40 void WindowSplitTest::SetUpTestCase()
41 {
42 }
43 
TearDownTestCase()44 void WindowSplitTest::TearDownTestCase()
45 {
46 }
47 
SetUp()48 void WindowSplitTest::SetUp()
49 {
50     fullInfo_ = {
51         .name = "",
52         .rect = Utils::customAppRect_,
53         .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW,
54         .mode = WindowMode::WINDOW_MODE_SPLIT_PRIMARY,
55         .needAvoid = true,
56         .parentLimit = false,
57         .parentId = INVALID_WINDOW_ID,
58     };
59 
60     splitInfo_ = {
61         .name = "",
62         .rect = Utils::customAppRect_,
63         .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW,
64         .mode = WindowMode::WINDOW_MODE_FULLSCREEN,
65         .needAvoid = true,
66         .parentLimit = false,
67         .parentId = INVALID_WINDOW_ID,
68     };
69 
70     activeWindows_.clear();
71 }
72 
TearDown()73 void WindowSplitTest::TearDown()
74 {
75     while (!activeWindows_.empty()) {
76         ASSERT_EQ(WMError::WM_OK, activeWindows_.back()->Destroy());
77         activeWindows_.pop_back();
78     }
79 }
80 
81 namespace {
82 /**
83  * @tc.name: SplitWindow01
84  * @tc.desc: first create a secondary window, then create a primary window, test mode change
85  * @tc.type: FUNC
86  */
87 HWTEST_F(WindowSplitTest, SplitWindow01, Function | MediumTest | Level3)
88 {
89     fullInfo_.name  = "fullscreen.1";
90     fullInfo_.mode = WindowMode::WINDOW_MODE_FULLSCREEN;
91     splitInfo_.name = "primary.1";
92     splitInfo_.mode = WindowMode::WINDOW_MODE_FULLSCREEN;
93 
94     const sptr<Window>& priWindow = Utils::CreateTestWindow(splitInfo_);
95     if (priWindow == nullptr) {
96         return;
97     }
98     activeWindows_.push_back(priWindow);
99     priWindow->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_PRIMARY);
100     sleep(SPLIT_TEST_SLEEP_S);
101     ASSERT_EQ(WMError::WM_OK, priWindow->Show());
102     sleep(SPLIT_TEST_SLEEP_S);
103 
104     const sptr<Window>& fullWindow = Utils::CreateTestWindow(fullInfo_);
105     if (fullWindow == nullptr) {
106         return;
107     }
108     activeWindows_.push_back(fullWindow);
109     fullWindow->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_SECONDARY);
110     sleep(SPLIT_TEST_SLEEP_S);
111     ASSERT_EQ(WMError::WM_OK, fullWindow->Show());
112     sleep(SPLIT_TEST_SLEEP_S);
113 
114 
115     ASSERT_EQ(WindowMode::WINDOW_MODE_SPLIT_PRIMARY, priWindow->GetMode());
116     ASSERT_EQ(WindowMode::WINDOW_MODE_SPLIT_SECONDARY, fullWindow->GetMode());
117 
118     ASSERT_EQ(WMError::WM_OK, priWindow->Hide());
119     sleep(SPLIT_TEST_SLEEP_S);
120     ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, fullWindow->GetMode());
121     ASSERT_EQ(WMError::WM_OK, fullWindow->Hide());
122     sleep(SPLIT_TEST_SLEEP_S);
123 }
124 
125 /**
126  * @tc.name: SplitWindow02
127  * @tc.desc: first create a primary window, then create a secondary window, test mode change
128  * @tc.type: FUNC
129  */
130 HWTEST_F(WindowSplitTest, SplitWindow02, Function | MediumTest | Level3)
131 {
132     fullInfo_.name  = "fullscreen.2";
133     fullInfo_.mode = WindowMode::WINDOW_MODE_FULLSCREEN;
134     splitInfo_.name = "secondary.2";
135     splitInfo_.mode = WindowMode::WINDOW_MODE_FULLSCREEN;
136 
137     const sptr<Window>& fullWindow = Utils::CreateTestWindow(fullInfo_);
138     if (fullWindow == nullptr) {
139         return;
140     }
141     activeWindows_.push_back(fullWindow);
142     fullWindow->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_PRIMARY);
143     sleep(SPLIT_TEST_SLEEP_S);
144     ASSERT_EQ(WMError::WM_OK, fullWindow->Show());
145     sleep(SPLIT_TEST_SLEEP_S);
146 
147     const sptr<Window>& secWindow = Utils::CreateTestWindow(splitInfo_);
148     activeWindows_.push_back(secWindow);
149     secWindow->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_SECONDARY);
150     sleep(SPLIT_TEST_SLEEP_S);
151     ASSERT_EQ(WMError::WM_OK, secWindow->Show());
152     sleep(SPLIT_TEST_SLEEP_S);
153 
154 
155     ASSERT_EQ(WindowMode::WINDOW_MODE_SPLIT_SECONDARY, secWindow->GetMode());
156     ASSERT_EQ(WindowMode::WINDOW_MODE_SPLIT_PRIMARY, fullWindow->GetMode());
157 
158     ASSERT_EQ(WMError::WM_OK, fullWindow->Hide());
159     sleep(SPLIT_TEST_SLEEP_S);
160     ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, secWindow->GetMode());
161     ASSERT_EQ(WMError::WM_OK, secWindow->Hide());
162     sleep(SPLIT_TEST_SLEEP_S);
163 }
164 
165 /**
166  * @tc.name: SplitScreen03
167  * @tc.desc: first create a secondary window, then create a primary window, test rects
168  * @tc.type: FUNC
169  */
170 HWTEST_F(WindowSplitTest, SplitScreen03, Function | MediumTest | Level3)
171 {
172     fullInfo_.name  = "fullscreen.3";
173     fullInfo_.mode = WindowMode::WINDOW_MODE_SPLIT_SECONDARY;
174     splitInfo_.name = "primary.3";
175     splitInfo_.mode = WindowMode::WINDOW_MODE_SPLIT_PRIMARY;
176 
177     ASSERT_TRUE(Utils::InitSplitRects());
178 
179     const sptr<Window>& fullWindow = Utils::CreateTestWindow(fullInfo_);
180     if (fullWindow == nullptr) {
181         return;
182     }
183     activeWindows_.push_back(fullWindow);
184     ASSERT_EQ(WMError::WM_OK, fullWindow->Show());
185     sleep(SPLIT_TEST_SLEEP_S);
186     const sptr<Window>& priWindow = Utils::CreateTestWindow(splitInfo_);
187     activeWindows_.push_back(priWindow);
188     ASSERT_EQ(WMError::WM_OK, priWindow->Show());
189     sleep(SPLIT_TEST_SLEEP_S);
190 
191     Utils::UpdateSplitRects(fullWindow);
192 
193     ASSERT_TRUE(Utils::RectEqualTo(fullWindow, Utils::splitRects_.secondaryRect));
194     ASSERT_TRUE(Utils::RectEqualTo(priWindow, Utils::splitRects_.primaryRect));
195 
196     ASSERT_EQ(WMError::WM_OK, fullWindow->Hide());
197     sleep(SPLIT_TEST_SLEEP_S);
198     ASSERT_EQ(WMError::WM_OK, priWindow->Hide());
199     sleep(SPLIT_TEST_SLEEP_S);
200 }
201 
202 /**
203  * @tc.name: SplitScreen04
204  * @tc.desc: first create a primary window, then create a secondary window, test rects
205  * @tc.type: FUNC
206  */
207 HWTEST_F(WindowSplitTest, SplitScreen04, Function | MediumTest | Level3)
208 {
209     fullInfo_.name  = "fullscreen.4";
210     splitInfo_.name = "secondary.4";
211     splitInfo_.mode = WindowMode::WINDOW_MODE_SPLIT_SECONDARY;
212 
213     ASSERT_TRUE(Utils::InitSplitRects());
214 
215     const sptr<Window>& fullWindow = Utils::CreateTestWindow(fullInfo_);
216     if (fullWindow == nullptr) {
217         return;
218     }
219 
220     activeWindows_.push_back(fullWindow);
221     ASSERT_EQ(WMError::WM_OK, fullWindow->Show());
222     sleep(SPLIT_TEST_SLEEP_S);
223     const sptr<Window>& secWindow = Utils::CreateTestWindow(splitInfo_);
224     activeWindows_.push_back(secWindow);
225     ASSERT_EQ(WMError::WM_OK, secWindow->Show());
226     sleep(SPLIT_TEST_SLEEP_S);
227 
228     Utils::UpdateSplitRects(fullWindow);
229 
230     ASSERT_TRUE(Utils::RectEqualTo(fullWindow, Utils::splitRects_.primaryRect));
231     ASSERT_TRUE(Utils::RectEqualTo(secWindow, Utils::splitRects_.secondaryRect));
232 
233     ASSERT_EQ(WMError::WM_OK, fullWindow->Hide());
234     sleep(SPLIT_TEST_SLEEP_S);
235     ASSERT_EQ(WMError::WM_OK, secWindow->Hide());
236     sleep(SPLIT_TEST_SLEEP_S);
237 }
238 }
239 } // namespace Rosen
240 } // namespace OHOS
241