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