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