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