1 /*
2 * Copyright (c) 2022 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_manager.h"
19 #include "window_test_utils.h"
20 #include "wm_common.h"
21 #include "scene_board_judgement.h"
22 using namespace testing;
23 using namespace testing::ext;
24
25 namespace OHOS {
26 namespace Rosen {
27 using Utils = WindowTestUtils;
28 class WindowModeSupportTypeTest : public testing::Test {
29 public:
30 static void SetUpTestCase();
31 static void TearDownTestCase();
32 virtual void SetUp() override;
33 virtual void TearDown() override;
34 Utils::TestWindowInfo fullAppInfo_1_;
35 Utils::TestWindowInfo fullAppInfo_2_;
36 private:
37 static constexpr uint32_t WAIT_SYANC_US = 100000;
38 };
39
SetUpTestCase()40 void WindowModeSupportTypeTest::SetUpTestCase()
41 {
42 auto display = DisplayManager::GetInstance().GetDisplayById(0);
43 ASSERT_TRUE((display != nullptr));
44 Rect displayRect = {0, 0, display->GetWidth(), display->GetHeight()};
45 Utils::InitByDisplayRect(displayRect);
46 }
47
TearDownTestCase()48 void WindowModeSupportTypeTest::TearDownTestCase()
49 {
50 }
51
SetUp()52 void WindowModeSupportTypeTest::SetUp()
53 {
54 fullAppInfo_1_ = {
55 .name = "FullWindow",
56 .rect = Utils::customAppRect_,
57 .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW,
58 .mode = WindowMode::WINDOW_MODE_FULLSCREEN,
59 .needAvoid = false,
60 .parentLimit = false,
61 .parentId = INVALID_WINDOW_ID,
62 };
63 fullAppInfo_2_ = {
64 .name = "FullWindow2",
65 .rect = Utils::customAppRect_,
66 .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW,
67 .mode = WindowMode::WINDOW_MODE_FULLSCREEN,
68 .needAvoid = false,
69 .parentLimit = false,
70 .parentId = INVALID_WINDOW_ID,
71 };
72 }
73
TearDown()74 void WindowModeSupportTypeTest::TearDown()
75 {
76 }
77
78 namespace {
79 /**
80 * @tc.name: WindowModeSupportType01
81 * @tc.desc: SetRequestWindowModeSupportType | GetRequestWindowModeSupportType
82 * @tc.type: FUNC
83 */
84 HWTEST_F(WindowModeSupportTypeTest, WindowModeSupportType01, Function | MediumTest | Level3)
85 {
86 const sptr<Window>& window = Utils::CreateTestWindow(fullAppInfo_1_);
87 if (window == nullptr) {
88 return;
89 }
90 window->SetRequestWindowModeSupportType(WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN);
91 ASSERT_EQ(WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN, window->GetRequestWindowModeSupportType());
92 window->Destroy();
93 }
94
95 /**
96 * @tc.name: WindowModeSupportType02
97 * @tc.desc: windowModeSupportType test for single window, only support fullScreen mode
98 * @tc.type: FUNC
99 */
100 HWTEST_F(WindowModeSupportTypeTest, WindowModeSupportType02, Function | MediumTest | Level3)
101 {
102 const sptr<Window>& window = Utils::CreateTestWindow(fullAppInfo_1_);
103 if (window == nullptr) {
104 return;
105 }
106 window->SetRequestWindowModeSupportType(WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN);
107 ASSERT_EQ(WMError::WM_OK, window->Show());
108 ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, window->GetWindowMode());
109
110 window->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
111 ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, window->GetWindowMode());
112
113 window->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_PRIMARY);
114 ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, window->GetWindowMode());
115
116 window->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_SECONDARY);
117 ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, window->GetWindowMode());
118
119 ASSERT_EQ(WMError::WM_OK, window->Hide());
120 window->Destroy();
121 }
122
123 /**
124 * @tc.name: WindowModeSupportType03
125 * @tc.desc: windowModeSupportType test for single window, support both fullScreen and floating mode
126 * @tc.type: FUNC
127 */
128 HWTEST_F(WindowModeSupportTypeTest, WindowModeSupportType03, Function | MediumTest | Level3)
129 {
130 const sptr<Window>& window = Utils::CreateTestWindow(fullAppInfo_1_);
131 if (window == nullptr) {
132 return;
133 }
134 window->SetRequestWindowModeSupportType(WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN |
135 WindowModeSupport::WINDOW_MODE_SUPPORT_FLOATING);
136 ASSERT_EQ(WMError::WM_OK, window->Show());
137 ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, window->GetWindowMode());
138
139 window->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
140 ASSERT_EQ(WindowMode::WINDOW_MODE_FLOATING, window->GetWindowMode());
141
142 window->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
143 ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, window->GetWindowMode());
144
145 window->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_PRIMARY);
146 ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, window->GetWindowMode());
147
148 window->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_SECONDARY);
149 ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, window->GetWindowMode());
150
151 ASSERT_EQ(WMError::WM_OK, window->Hide());
152 window->Destroy();
153 }
154
155 /**
156 * @tc.name: WindowModeSupportType04
157 * @tc.desc: windowModeSupportType test for single window, window mode is not supported when show, show failed
158 * @tc.type: FUNC
159 */
160 HWTEST_F(WindowModeSupportTypeTest, WindowModeSupportType04, Function | MediumTest | Level3)
161 {
162 const sptr<Window>& window = Utils::CreateTestWindow(fullAppInfo_1_);
163 if (window == nullptr) {
164 return;
165 }
166 window->SetRequestWindowModeSupportType(WindowModeSupport::WINDOW_MODE_SUPPORT_FLOATING |
167 WindowModeSupport::WINDOW_MODE_SUPPORT_SPLIT_PRIMARY |
168 WindowModeSupport::WINDOW_MODE_SUPPORT_SPLIT_SECONDARY);
169 ASSERT_NE(WMError::WM_OK, window->Show());
170 ASSERT_EQ(WMError::WM_OK, window->Hide());
171 window->Destroy();
172 }
173
174 /**
175 * @tc.name: WindowModeSupportType05
176 * @tc.desc: windowModeSupportType test for layout cascade
177 * @tc.type: FUNC
178 */
179 HWTEST_F(WindowModeSupportTypeTest, WindowModeSupportType05, Function | MediumTest | Level3)
180 {
181 const sptr<Window>& window1 = Utils::CreateTestWindow(fullAppInfo_1_);
182 if (window1 == nullptr) {
183 return;
184 }
185 window1->SetRequestWindowModeSupportType(WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN);
186 const sptr<Window>& window2 = Utils::CreateTestWindow(fullAppInfo_2_);
187 ASSERT_NE(nullptr, window2);
188 window2->SetRequestWindowModeSupportType(WindowModeSupport::WINDOW_MODE_SUPPORT_ALL);
189 ASSERT_EQ(WMError::WM_OK, window1->Show());
190 ASSERT_EQ(WMError::WM_OK, window2->Show());
191 WindowManager::GetInstance().SetWindowLayoutMode(WindowLayoutMode::CASCADE);
192 usleep(WAIT_SYANC_US);
193
194 ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, window1->GetWindowMode());
195 if (SceneBoardJudgement::IsSceneBoardEnabled()) {
196 ASSERT_EQ(WindowMode::WINDOW_MODE_FLOATING, window2->GetWindowMode());
197 }
198 else {
199 ASSERT_EQ(WindowMode::WINDOW_MODE_FLOATING, window2->GetWindowMode());
200 }
201 window1->Destroy();
202 window2->Destroy();
203 }
204
205 /**
206 * @tc.name: WindowModeSupportType06
207 * @tc.desc: windowModeSupportType test for layout tile
208 * @tc.type: FUNC
209 */
210 HWTEST_F(WindowModeSupportTypeTest, WindowModeSupportType06, Function | MediumTest | Level3)
211 {
212 const sptr<Window>& window = Utils::CreateTestWindow(fullAppInfo_1_);
213 if (window == nullptr) {
214 return;
215 }
216 window->SetRequestWindowModeSupportType(WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN);
217 ASSERT_EQ(WMError::WM_OK, window->Show());
218 WindowManager::GetInstance().SetWindowLayoutMode(WindowLayoutMode::TILE);
219 usleep(WAIT_SYANC_US);
220
221 ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, window->GetWindowMode());
222
223 window->Destroy();
224 WindowManager::GetInstance().SetWindowLayoutMode(WindowLayoutMode::CASCADE);
225 usleep(WAIT_SYANC_US);
226 }
227 } // namespace
228 } // namespace Rosen
229 } // namespace OHOS