• 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     activeWindows_.push_back(priWindow);
96     priWindow->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_PRIMARY);
97     sleep(SPLIT_TEST_SLEEP_S);
98     ASSERT_EQ(WMError::WM_OK, priWindow->Show());
99     sleep(SPLIT_TEST_SLEEP_S);
100 
101     const sptr<Window>& fullWindow = Utils::CreateTestWindow(fullInfo_);
102     activeWindows_.push_back(fullWindow);
103     fullWindow->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_SECONDARY);
104     sleep(SPLIT_TEST_SLEEP_S);
105     ASSERT_EQ(WMError::WM_OK, fullWindow->Show());
106     sleep(SPLIT_TEST_SLEEP_S);
107 
108 
109     ASSERT_EQ(WindowMode::WINDOW_MODE_SPLIT_PRIMARY, priWindow->GetMode());
110     ASSERT_EQ(WindowMode::WINDOW_MODE_SPLIT_SECONDARY, fullWindow->GetMode());
111 
112     ASSERT_EQ(WMError::WM_OK, priWindow->Hide());
113     sleep(SPLIT_TEST_SLEEP_S);
114     ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, fullWindow->GetMode());
115     ASSERT_EQ(WMError::WM_OK, fullWindow->Hide());
116     sleep(SPLIT_TEST_SLEEP_S);
117 }
118 
119 /**
120  * @tc.name: SplitWindow02
121  * @tc.desc: first create a primary window, then create a secondary window, test mode change
122  * @tc.type: FUNC
123  */
124 HWTEST_F(WindowSplitTest, SplitWindow02, Function | MediumTest | Level3)
125 {
126     fullInfo_.name  = "fullscreen.2";
127     fullInfo_.mode = WindowMode::WINDOW_MODE_FULLSCREEN;
128     splitInfo_.name = "secondary.2";
129     splitInfo_.mode = WindowMode::WINDOW_MODE_FULLSCREEN;
130 
131     const sptr<Window>& fullWindow = Utils::CreateTestWindow(fullInfo_);
132     activeWindows_.push_back(fullWindow);
133     fullWindow->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_PRIMARY);
134     sleep(SPLIT_TEST_SLEEP_S);
135     ASSERT_EQ(WMError::WM_OK, fullWindow->Show());
136     sleep(SPLIT_TEST_SLEEP_S);
137 
138     const sptr<Window>& secWindow = Utils::CreateTestWindow(splitInfo_);
139     activeWindows_.push_back(secWindow);
140     secWindow->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_SECONDARY);
141     sleep(SPLIT_TEST_SLEEP_S);
142     ASSERT_EQ(WMError::WM_OK, secWindow->Show());
143     sleep(SPLIT_TEST_SLEEP_S);
144 
145 
146     ASSERT_EQ(WindowMode::WINDOW_MODE_SPLIT_SECONDARY, secWindow->GetMode());
147     ASSERT_EQ(WindowMode::WINDOW_MODE_SPLIT_PRIMARY, fullWindow->GetMode());
148 
149     ASSERT_EQ(WMError::WM_OK, fullWindow->Hide());
150     sleep(SPLIT_TEST_SLEEP_S);
151     ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, secWindow->GetMode());
152     ASSERT_EQ(WMError::WM_OK, secWindow->Hide());
153     sleep(SPLIT_TEST_SLEEP_S);
154 }
155 
156 /**
157  * @tc.name: SplitScreen03
158  * @tc.desc: first create a secondary window, then create a primary window, test rects
159  * @tc.type: FUNC
160  */
161 HWTEST_F(WindowSplitTest, SplitScreen03, Function | MediumTest | Level3)
162 {
163     fullInfo_.name  = "fullscreen.3";
164     fullInfo_.mode = WindowMode::WINDOW_MODE_SPLIT_SECONDARY;
165     splitInfo_.name = "primary.3";
166     splitInfo_.mode = WindowMode::WINDOW_MODE_SPLIT_PRIMARY;
167 
168     ASSERT_TRUE(Utils::InitSplitRects());
169 
170     const sptr<Window>& fullWindow = Utils::CreateTestWindow(fullInfo_);
171     activeWindows_.push_back(fullWindow);
172     ASSERT_EQ(WMError::WM_OK, fullWindow->Show());
173     sleep(SPLIT_TEST_SLEEP_S);
174     const sptr<Window>& priWindow = Utils::CreateTestWindow(splitInfo_);
175     activeWindows_.push_back(priWindow);
176     ASSERT_EQ(WMError::WM_OK, priWindow->Show());
177     sleep(SPLIT_TEST_SLEEP_S);
178 
179     Utils::UpdateSplitRects(fullWindow);
180 
181     ASSERT_TRUE(Utils::RectEqualTo(fullWindow, Utils::splitRects_.secondaryRect));
182     ASSERT_TRUE(Utils::RectEqualTo(priWindow, Utils::splitRects_.primaryRect));
183 
184     ASSERT_EQ(WMError::WM_OK, fullWindow->Hide());
185     sleep(SPLIT_TEST_SLEEP_S);
186     ASSERT_EQ(WMError::WM_OK, priWindow->Hide());
187     sleep(SPLIT_TEST_SLEEP_S);
188 }
189 
190 /**
191  * @tc.name: SplitScreen04
192  * @tc.desc: first create a primary window, then create a secondary window, test rects
193  * @tc.type: FUNC
194  */
195 HWTEST_F(WindowSplitTest, SplitScreen04, Function | MediumTest | Level3)
196 {
197     fullInfo_.name  = "fullscreen.4";
198     splitInfo_.name = "secondary.4";
199     splitInfo_.mode = WindowMode::WINDOW_MODE_SPLIT_SECONDARY;
200 
201     ASSERT_TRUE(Utils::InitSplitRects());
202 
203     const sptr<Window>& fullWindow = Utils::CreateTestWindow(fullInfo_);
204     activeWindows_.push_back(fullWindow);
205     ASSERT_EQ(WMError::WM_OK, fullWindow->Show());
206     sleep(SPLIT_TEST_SLEEP_S);
207     const sptr<Window>& secWindow = Utils::CreateTestWindow(splitInfo_);
208     activeWindows_.push_back(secWindow);
209     ASSERT_EQ(WMError::WM_OK, secWindow->Show());
210     sleep(SPLIT_TEST_SLEEP_S);
211 
212     Utils::UpdateSplitRects(fullWindow);
213 
214     ASSERT_TRUE(Utils::RectEqualTo(fullWindow, Utils::splitRects_.primaryRect));
215     ASSERT_TRUE(Utils::RectEqualTo(secWindow, Utils::splitRects_.secondaryRect));
216 
217     ASSERT_EQ(WMError::WM_OK, fullWindow->Hide());
218     sleep(SPLIT_TEST_SLEEP_S);
219     ASSERT_EQ(WMError::WM_OK, secWindow->Hide());
220     sleep(SPLIT_TEST_SLEEP_S);
221 }
222 }
223 } // namespace Rosen
224 } // namespace OHOS
225