• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 #include <gtest/gtest.h>
17 
18 #include "ability_context_impl.h"
19 
20 #include "mock_session.h"
21 #include "mock_uicontent.h"
22 #include "window_scene_session_impl.h"
23 #include "window_test_utils.h"
24 
25 using namespace testing;
26 using namespace testing::ext;
27 
28 namespace OHOS {
29 namespace Rosen {
30 using Utils = WindowTestUtils;
31 
32 class WindowDecorTest : public testing::Test {
33 public:
34     void SetUp() override;
35     void TearDown() override;
36 
37 private:
38     static constexpr uint32_t TEST_SLEEP_S = 1; // test sleep time
39     std::shared_ptr<AbilityRuntime::AbilityContext> abilityContext_;
40 };
41 
SetUp()42 void WindowDecorTest::SetUp()
43 {
44     abilityContext_ = std::make_shared<AbilityRuntime::AbilityContextImpl>();
45 }
46 
TearDown()47 void WindowDecorTest::TearDown()
48 {
49     abilityContext_ = nullptr;
50 }
51 
52 namespace {
53 /**
54  * @tc.name: SetDecorVisible01
55  * @tc.desc: SetDecorVisible
56  * @tc.type: FUNC
57  */
58 HWTEST_F(WindowDecorTest, SetDecorVisible01, Function | MediumTest | Level0)
59 {
60     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
61     option->SetWindowName("Window1_1");
62     option->SetWindowType(WindowType::WINDOW_TYPE_FLOAT);
63     option->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
64 
65     sptr<WindowSceneSessionImpl> window = sptr<WindowSceneSessionImpl>::MakeSptr(option);
66     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
67     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
68     ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session));
69 
70     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->SetDecorVisible(true));
71 
72     window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
73     window->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
74     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->SetDecorVisible(true));
75     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->SetDecorVisible(false));
76 
77     window->Destroy(true, true);
78 }
79 
80 /**
81  * @tc.name: SetDecorVisible02
82  * @tc.desc: SetDecorVisible
83  * @tc.type: FUNC
84  */
85 HWTEST_F(WindowDecorTest, SetDecorVisible02, Function | MediumTest | Level0)
86 {
87     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
88     option->SetWindowName("Window1_2");
89     option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
90     option->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
91 
92     sptr<WindowSceneSessionImpl> window = sptr<WindowSceneSessionImpl>::MakeSptr(option);
93     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
94     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
95     ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session));
96 
97     window->property_->SetPersistentId(10012);
98     window->hostSession_ = session;
99 
100     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->SetDecorVisible(true));
101 
102     window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
103     window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
104     ASSERT_EQ(WMError::WM_OK, window->SetDecorVisible(true));
105     ASSERT_EQ(WMError::WM_OK, window->SetDecorVisible(false));
106 
107     window->Destroy(true, true);
108 }
109 
110 /**
111  * @tc.name: SetDecorVisible03
112  * @tc.desc: SetDecorVisible
113  * @tc.type: FUNC
114  */
115 HWTEST_F(WindowDecorTest, SetDecorVisible03, Function | MediumTest | Level0)
116 {
117     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
118     option->SetWindowName("Window1_3");
119     option->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
120     option->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
121 
122     sptr<WindowSceneSessionImpl> window = sptr<WindowSceneSessionImpl>::MakeSptr(option);
123     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
124     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
125     ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session));
126 
127     window->property_->SetPersistentId(10013);
128     window->hostSession_ = session;
129 
130     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->SetDecorVisible(true));
131 
132     window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
133     window->windowSystemConfig_.windowUIType_ = WindowUIType::PAD_WINDOW;
134     ASSERT_EQ(WMError::WM_OK, window->SetDecorVisible(true));
135     ASSERT_EQ(WMError::WM_OK, window->SetDecorVisible(false));
136 
137     window->Destroy(true, true);
138 }
139 
140 /**
141  * @tc.name: DecorHeight01
142  * @tc.desc: DecorHeight
143  * @tc.type: FUNC
144  */
145 HWTEST_F(WindowDecorTest, DecorHeight01, Function | MediumTest | Level0)
146 {
147     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
148     option->SetWindowName("Window2_1");
149     option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
150     option->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
151 
152     sptr<WindowSceneSessionImpl> window = sptr<WindowSceneSessionImpl>::MakeSptr(option);
153     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
154     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
155     ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session));
156 
157     window->hostSession_ = session;
158     window->property_->SetPersistentId(10021);
159     window->property_->SetDisplayId(0);
160 
161     int32_t height = 40;
162     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->SetDecorHeight(height));
163     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->GetDecorHeight(height));
164 
165     window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
166     window->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
167     ASSERT_EQ(WMError::WM_OK, window->SetDecorHeight(height));
168     ASSERT_EQ(WMError::WM_OK, window->GetDecorHeight(height));
169 
170     window->Destroy(true, true);
171 }
172 
173 /**
174  * @tc.name: DecorHeight02
175  * @tc.desc: DecorHeight
176  * @tc.type: FUNC
177  */
178 HWTEST_F(WindowDecorTest, DecorHeight02, Function | MediumTest | Level0)
179 {
180     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
181     option->SetWindowName("Window2_2");
182     option->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
183     option->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
184 
185     sptr<WindowSceneSessionImpl> window = sptr<WindowSceneSessionImpl>::MakeSptr(option);
186     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
187     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
188     ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session));
189 
190     window->hostSession_ = session;
191     window->property_->SetPersistentId(10022);
192     window->property_->SetDisplayId(0);
193 
194     int32_t height = 50;
195     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->SetDecorHeight(height));
196     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->GetDecorHeight(height));
197 
198     window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
199     window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
200     ASSERT_EQ(WMError::WM_OK, window->SetDecorHeight(height));
201     ASSERT_EQ(WMError::WM_OK, window->GetDecorHeight(height));
202 
203     window->Destroy(true, true);
204 }
205 
206 /**
207  * @tc.name: DecorHeight03
208  * @tc.desc: DecorHeight
209  * @tc.type: FUNC
210  */
211 HWTEST_F(WindowDecorTest, DecorHeight03, Function | MediumTest | Level0)
212 {
213     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
214     option->SetWindowName("Window2_3");
215     option->SetWindowType(WindowType::SYSTEM_SUB_WINDOW_BASE);
216     option->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
217 
218     sptr<WindowSceneSessionImpl> window = sptr<WindowSceneSessionImpl>::MakeSptr(option);
219     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
220     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
221     ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session));
222 
223     window->hostSession_ = session;
224     window->property_->SetPersistentId(10023);
225     window->property_->SetDisplayId(0);
226 
227     int32_t height = 60;
228     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->SetDecorHeight(height));
229     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->GetDecorHeight(height));
230 
231     window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
232     window->windowSystemConfig_.windowUIType_ = WindowUIType::PAD_WINDOW;
233     ASSERT_EQ(WMError::WM_OK, window->SetDecorHeight(height));
234     ASSERT_EQ(WMError::WM_OK, window->GetDecorHeight(height));
235 
236     window->Destroy(true, true);
237 }
238 
239 /**
240  * @tc.name: TitleButtonVisible01
241  * @tc.desc: TitleButtonVisible
242  * @tc.type: FUNC
243  */
244 HWTEST_F(WindowDecorTest, TitleButtonVisible01, Function | MediumTest | Level0)
245 {
246     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
247     option->SetWindowName("Window3_1");
248     option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
249     option->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
250 
251     sptr<WindowSceneSessionImpl> window = sptr<WindowSceneSessionImpl>::MakeSptr(option);
252     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
253     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
254     ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session));
255 
256     window->hostSession_ = session;
257     window->property_->SetPersistentId(10031);
258     window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
259 
260     window->windowSystemConfig_.isSystemDecorEnable_ = false;
261     window->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
262     ASSERT_EQ(WMError::WM_ERROR_DEVICE_NOT_SUPPORT, window->SetTitleButtonVisible(false, false, false, true));
263     window->windowSystemConfig_.windowUIType_ = WindowUIType::PAD_WINDOW;
264     ASSERT_EQ(WMError::WM_ERROR_DEVICE_NOT_SUPPORT, window->SetTitleButtonVisible(false, false, false, true));
265     window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
266     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->SetTitleButtonVisible(false, false, false, true));
267     window->windowSystemConfig_.isSystemDecorEnable_ = true;
268     ASSERT_EQ(WMError::WM_OK, window->SetTitleButtonVisible(false, false, false, true));
269 
270     ASSERT_EQ(WMError::WM_OK, window->SetTitleButtonVisible(true, true, true, true));
271     ASSERT_EQ(WMError::WM_OK, window->SetTitleButtonVisible(false, true, true, true));
272     ASSERT_EQ(WMError::WM_OK, window->SetTitleButtonVisible(true, false, true, true));
273     ASSERT_EQ(WMError::WM_OK, window->SetTitleButtonVisible(true, true, false, true));
274     ASSERT_EQ(WMError::WM_OK, window->SetTitleButtonVisible(true, false, false, true));
275     ASSERT_EQ(WMError::WM_OK, window->SetTitleButtonVisible(false, true, false, true));
276     ASSERT_EQ(WMError::WM_OK, window->SetTitleButtonVisible(false, false, true, true));
277     ASSERT_EQ(WMError::WM_OK, window->SetTitleButtonVisible(false, false, false, true));
278 
279     window->Destroy(true, true);
280 }
281 
282 /**
283  * @tc.name: TitleButtonVisible02
284  * @tc.desc: TitleButtonVisible
285  * @tc.type: FUNC
286  */
287 HWTEST_F(WindowDecorTest, TitleButtonVisible02, Function | MediumTest | Level0)
288 {
289     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
290     option->SetWindowName("Window3_2");
291     option->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
292     option->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
293 
294     sptr<WindowSceneSessionImpl> window = sptr<WindowSceneSessionImpl>::MakeSptr(option);
295     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
296     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
297     ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session));
298 
299     window->hostSession_ = session;
300     window->property_->SetPersistentId(10032);
301     window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
302 
303     window->windowSystemConfig_.isSystemDecorEnable_ = false;
304     window->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
305     ASSERT_EQ(WMError::WM_ERROR_INVALID_CALLING, window->SetTitleButtonVisible(false, false, false, true));
306     window->windowSystemConfig_.windowUIType_ = WindowUIType::PAD_WINDOW;
307     ASSERT_EQ(WMError::WM_ERROR_INVALID_CALLING, window->SetTitleButtonVisible(false, false, false, true));
308     window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
309     ASSERT_EQ(WMError::WM_ERROR_INVALID_CALLING, window->SetTitleButtonVisible(false, false, false, true));
310     window->windowSystemConfig_.isSystemDecorEnable_ = true;
311     ASSERT_EQ(WMError::WM_ERROR_INVALID_CALLING, window->SetTitleButtonVisible(false, false, false, true));
312 
313     window->Destroy(true, true);
314 }
315 
316 /**
317  * @tc.name: TitleButtonVisible03
318  * @tc.desc: TitleButtonVisible
319  * @tc.type: FUNC
320  */
321 HWTEST_F(WindowDecorTest, TitleButtonVisible03, Function | MediumTest | Level0)
322 {
323     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
324     option->SetWindowName("Window3_3");
325     option->SetWindowType(WindowType::SYSTEM_SUB_WINDOW_BASE);
326     option->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
327 
328     sptr<WindowSceneSessionImpl> window = sptr<WindowSceneSessionImpl>::MakeSptr(option);
329     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
330     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
331     ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session));
332 
333     window->hostSession_ = session;
334     window->property_->SetPersistentId(10033);
335     window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
336 
337     window->windowSystemConfig_.isSystemDecorEnable_ = false;
338     window->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
339     ASSERT_EQ(WMError::WM_ERROR_INVALID_CALLING, window->SetTitleButtonVisible(false, false, false, true));
340     window->windowSystemConfig_.windowUIType_ = WindowUIType::PAD_WINDOW;
341     ASSERT_EQ(WMError::WM_ERROR_INVALID_CALLING, window->SetTitleButtonVisible(false, false, false, true));
342     window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
343     ASSERT_EQ(WMError::WM_ERROR_INVALID_CALLING, window->SetTitleButtonVisible(false, false, false, true));
344     window->windowSystemConfig_.isSystemDecorEnable_ = true;
345     ASSERT_EQ(WMError::WM_ERROR_INVALID_CALLING, window->SetTitleButtonVisible(false, false, false, true));
346 
347     window->Destroy(true, true);
348 }
349 
350 /**
351  * @tc.name: DisableAppWindowDecor01
352  * @tc.desc: DisableAppWindowDecor
353  * @tc.type: FUNC
354  */
355 HWTEST_F(WindowDecorTest, DisableAppWindowDecor01, Function | MediumTest | Level0)
356 {
357     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
358     option->SetWindowName("Window4_1");
359     option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
360     option->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
361 
362     sptr<WindowSceneSessionImpl> window = sptr<WindowSceneSessionImpl>::MakeSptr(option);
363     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
364     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
365     ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session));
366 
367     window->hostSession_ = session;
368     window->property_->SetPersistentId(10041);
369     window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
370 
371     window->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
372     ASSERT_EQ(WMError::WM_OK, window->DisableAppWindowDecor());
373 
374     window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
375     ASSERT_EQ(WMError::WM_OK, window->DisableAppWindowDecor());
376 
377     window->windowSystemConfig_.windowUIType_ = WindowUIType::PAD_WINDOW;
378     ASSERT_EQ(WMError::WM_OK, window->DisableAppWindowDecor());
379 
380     window->Destroy(true, true);
381 }
382 
383 /**
384  * @tc.name: DisableAppWindowDecor02
385  * @tc.desc: DisableAppWindowDecor
386  * @tc.type: FUNC
387  */
388 HWTEST_F(WindowDecorTest, DisableAppWindowDecor02, Function | MediumTest | Level0)
389 {
390     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
391     option->SetWindowName("Window4_2");
392     option->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
393     option->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
394 
395     sptr<WindowSceneSessionImpl> window = sptr<WindowSceneSessionImpl>::MakeSptr(option);
396     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
397     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
398     ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session));
399 
400     window->hostSession_ = session;
401     window->property_->SetPersistentId(10042);
402     window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
403 
404     window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
405     ASSERT_EQ(WMError::WM_ERROR_INVALID_OPERATION, window->DisableAppWindowDecor());
406 
407     window->Destroy(true, true);
408 }
409 
410 /**
411  * @tc.name: DisableAppWindowDecor03
412  * @tc.desc: DisableAppWindowDecor
413  * @tc.type: FUNC
414  */
415 HWTEST_F(WindowDecorTest, DisableAppWindowDecor03, Function | MediumTest | Level0)
416 {
417     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
418     option->SetWindowName("Window4_3");
419     option->SetWindowType(WindowType::SYSTEM_SUB_WINDOW_BASE);
420     option->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
421 
422     sptr<WindowSceneSessionImpl> window = sptr<WindowSceneSessionImpl>::MakeSptr(option);
423     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
424     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
425     ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session));
426 
427     window->hostSession_ = session;
428     window->property_->SetPersistentId(10043);
429     window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
430 
431     window->windowSystemConfig_.windowUIType_ = WindowUIType::PAD_WINDOW;
432     ASSERT_EQ(WMError::WM_ERROR_INVALID_OPERATION, window->DisableAppWindowDecor());
433 
434     window->Destroy(true, true);
435 }
436 
437 }
438 
439 } // namespace Rosen
440 } // namespace OHOS