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