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