1 /*
2 * Copyright (c) 2023 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 #include <filesystem>
16 #include <fstream>
17 #include <gtest/gtest.h>
18
19 #include "ability_context_impl.h"
20 #include "accessibility_event_info.h"
21 #include "mock_session.h"
22 #include "window_helper.h"
23 #include "window_session_impl.h"
24 #include "wm_common.h"
25 #include "mock_uicontent.h"
26 #include "mock_window.h"
27 #include "parameters.h"
28
29 using namespace testing;
30 using namespace testing::ext;
31
32 namespace OHOS {
33 namespace Rosen {
34 class WindowSessionImplTest : public testing::Test {
35 public:
36 static void SetUpTestCase();
37 static void TearDownTestCase();
38 void SetUp() override;
39 void TearDown() override;
40
41 std::shared_ptr<AbilityRuntime::AbilityContext> abilityContext_;
42 private:
43 static constexpr uint32_t WAIT_SYNC_IN_NS = 50000;
44 };
45
SetUpTestCase()46 void WindowSessionImplTest::SetUpTestCase()
47 {
48 }
49
TearDownTestCase()50 void WindowSessionImplTest::TearDownTestCase()
51 {
52 }
53
SetUp()54 void WindowSessionImplTest::SetUp()
55 {
56 abilityContext_ = std::make_shared<AbilityRuntime::AbilityContextImpl>();
57 }
58
TearDown()59 void WindowSessionImplTest::TearDown()
60 {
61 usleep(WAIT_SYNC_IN_NS);
62 abilityContext_ = nullptr;
63 }
64
65 namespace {
66 /**
67 * @tc.name: CreateWindowAndDestroy01
68 * @tc.desc: Create window and destroy window
69 * @tc.type: FUNC
70 */
71 HWTEST_F(WindowSessionImplTest, CreateWindowAndDestroy01, Function | SmallTest | Level2)
72 {
73 sptr<WindowOption> option = new WindowOption();
74 option->SetWindowName("CreateWindow01");
75 sptr<WindowSessionImpl> window = new WindowSessionImpl(option);
76
77 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
78 sptr<SessionMocker> session = new(std::nothrow) SessionMocker(sessionInfo);
79 ASSERT_NE(nullptr, session);
80 ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
81 ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session));
82 ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session));
83 window->property_->SetPersistentId(1);
84 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
85 // session is null
86 window = new WindowSessionImpl(option);
87 ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, nullptr));
88 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
89
90 window = new WindowSessionImpl(option);
91 ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session));
92 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy(false));
93 }
94
95 /**
96 * @tc.name: CreateWindowAndDestroy02
97 * @tc.desc: Create window and destroy window
98 * @tc.type: FUNC
99 */
100 HWTEST_F(WindowSessionImplTest, CreateWindowAndDestroy02, Function | SmallTest | Level2)
101 {
102 std::string identityToken = "testToken";
103 sptr<WindowOption> option = new WindowOption();
104 ASSERT_NE(nullptr, option);
105 option->SetWindowName("CreateWindow01");
106 sptr<WindowSessionImpl> window = new WindowSessionImpl(option);
107
108 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
109 sptr<SessionMocker> session = new(std::nothrow) SessionMocker(sessionInfo);
110 ASSERT_NE(nullptr, session);
111 ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session, identityToken));
112 ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session, identityToken));
113 ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session, identityToken));
114 window->property_->SetPersistentId(1);
115 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
116 // session is null
117 window = new WindowSessionImpl(option);
118 ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, nullptr));
119 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
120
121 window = new WindowSessionImpl(option);
122 ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session, identityToken));
123 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy(false));
124 }
125
126 /**
127 * @tc.name: Connect01
128 * @tc.desc: Connect session
129 * @tc.type: FUNC
130 */
131 HWTEST_F(WindowSessionImplTest, Connect01, Function | SmallTest | Level2)
132 {
133 sptr<WindowOption> option = new WindowOption();
134 option->SetWindowName("Connect01");
135 sptr<WindowSessionImpl> window = new(std::nothrow) WindowSessionImpl(option);
136 ASSERT_NE(nullptr, window);
137 window->property_->SetPersistentId(1);
138 // connect with null session
139 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->Connect());
140
141 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
142 sptr<SessionMocker> session = new(std::nothrow) SessionMocker(sessionInfo);
143 ASSERT_NE(nullptr, session);
144 window->hostSession_ = session;
145 EXPECT_CALL(*(session), Connect(_, _, _, _, _, _, _)).WillOnce(Return(WSError::WS_ERROR_NULLPTR));
146 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->Connect());
147 EXPECT_CALL(*(session), Connect(_, _, _, _, _, _, _)).WillOnce(Return(WSError::WS_OK));
148 ASSERT_EQ(WMError::WM_OK, window->Connect());
149 ASSERT_EQ(WMError::WM_OK, window->Destroy());
150 }
151
152 /**
153 * @tc.name: Show01
154 * @tc.desc: Show session
155 * @tc.type: FUNC
156 */
157 HWTEST_F(WindowSessionImplTest, Show01, Function | SmallTest | Level2)
158 {
159 sptr<WindowOption> option = new WindowOption();
160 option->SetWindowName("Show01");
161 sptr<WindowSessionImpl> window = new(std::nothrow) WindowSessionImpl(option);
162 ASSERT_NE(nullptr, window);
163 window->property_->SetPersistentId(1);
164 // show with null session
165 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Show());
166
167 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
168 sptr<SessionMocker> session = new(std::nothrow) SessionMocker(sessionInfo);
169 ASSERT_NE(nullptr, session);
170 window->hostSession_ = session;
171 EXPECT_CALL(*(session), Foreground(_, _, _)).WillOnce(Return(WSError::WS_OK));
172 ASSERT_EQ(WMError::WM_OK, window->Show());
173 ASSERT_EQ(WMError::WM_OK, window->Show());
174 window->state_ = WindowState::STATE_CREATED;
175 EXPECT_CALL(*(session), Foreground(_, _, _)).WillOnce(Return(WSError::WS_ERROR_INVALID_SESSION));
176 ASSERT_EQ(WMError::WM_ERROR_INVALID_SESSION, window->Show());
177 ASSERT_EQ(WMError::WM_OK, window->Destroy());
178 }
179
180 /**
181 * @tc.name: Hide01
182 * @tc.desc: Hide session
183 * @tc.type: FUNC
184 */
185 HWTEST_F(WindowSessionImplTest, Hide01, Function | SmallTest | Level2)
186 {
187 sptr<WindowOption> option = new WindowOption();
188 option->SetWindowName("Hide01");
189 sptr<WindowSessionImpl> window = new(std::nothrow) WindowSessionImpl(option);
190 ASSERT_NE(nullptr, window);
191 window->property_->SetPersistentId(1);
192 // show with null session
193 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Hide());
194
195 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
196 sptr<SessionMocker> session = new(std::nothrow) SessionMocker(sessionInfo);
197 ASSERT_NE(nullptr, session);
198 window->hostSession_ = session;
199 ASSERT_EQ(WMError::WM_OK, window->Hide());
200 ASSERT_EQ(WMError::WM_OK, window->Hide());
201 window->state_ = WindowState::STATE_CREATED;
202 ASSERT_EQ(WMError::WM_OK, window->Hide());
203 window->state_ = WindowState::STATE_SHOWN;
204 window->property_->type_ = WindowType::WINDOW_TYPE_FLOAT;
205 ASSERT_EQ(WMError::WM_OK, window->Hide());
206 window->property_->type_ = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW;
207 ASSERT_EQ(WMError::WM_OK, window->Destroy());
208 }
209
210 /**
211 * @tc.name: SetResizeByDragEnabled01
212 * @tc.desc: SetResizeByDragEnabled and check the retCode
213 * @tc.type: FUNC
214 */
215 HWTEST_F(WindowSessionImplTest, SetResizeByDragEnabled01, Function | SmallTest | Level2)
216 {
217 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
218 option->SetWindowName("SetResizeByDragEnabled01");
219 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
220 WMError retCode = window->SetResizeByDragEnabled(true);
221 ASSERT_EQ(retCode, WMError::WM_ERROR_INVALID_WINDOW);
222 }
223
224 /**
225 * @tc.name: SetResizeByDragEnabled02
226 * @tc.desc: SetResizeByDragEnabled and check the retCode
227 * @tc.type: FUNC
228 */
229 HWTEST_F(WindowSessionImplTest, SetResizeByDragEnabled02, Function | SmallTest | Level2)
230 {
231 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
232 option->SetWindowName("SetResizeByDragEnabled02");
233 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
234 window->property_->SetPersistentId(1);
235 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
236 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
237 window->hostSession_ = session;
238 window->state_ = WindowState::STATE_CREATED;
239 ASSERT_FALSE(window->IsWindowSessionInvalid());
240 WMError retCode = window->SetResizeByDragEnabled(true);
241 ASSERT_EQ(retCode, WMError::WM_OK);
242 ASSERT_EQ(true, window->property_->GetDragEnabled());
243 }
244
245 /**
246 * @tc.name: SetResizeByDragEnabled03
247 * @tc.desc: SetResizeByDragEnabled and check the retCode
248 * @tc.type: FUNC
249 */
250 HWTEST_F(WindowSessionImplTest, SetResizeByDragEnabled03, Function | SmallTest | Level2)
251 {
252 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
253 option->SetWindowName("SetResizeByDragEnabled03");
254 option->SetSubWindowDecorEnable(true);
255 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
256
257 window->property_->SetPersistentId(1);
258 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
259 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
260 window->hostSession_ = session;
261
262 window->property_->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
263 WMError retCode = window->SetResizeByDragEnabled(true);
264 ASSERT_EQ(retCode, WMError::WM_OK);
265
266 window->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
267 retCode = window->SetResizeByDragEnabled(true);
268 ASSERT_EQ(retCode, WMError::WM_OK);
269
270 window->property_->SetWindowType(WindowType::SYSTEM_SUB_WINDOW_BASE);
271 retCode = window->SetResizeByDragEnabled(true);
272 ASSERT_EQ(retCode, WMError::WM_ERROR_INVALID_TYPE);
273 }
274
275 /**
276 * @tc.name: SetWindowType01
277 * @tc.desc: SetWindowType
278 * @tc.type: FUNC
279 */
280 HWTEST_F(WindowSessionImplTest, SetWindowType01, Function | SmallTest | Level2)
281 {
282 GTEST_LOG_(INFO) << "WindowSessionImplTest: SetWindowType01 start";
283 sptr<WindowOption> option = new WindowOption();
284 sptr<WindowSessionImpl> window = new WindowSessionImpl(option);
285 ASSERT_NE(window->property_, nullptr);
286
287 window->property_->SetPersistentId(1);
288 option->SetWindowName("SetWindowType01");
289 WindowType type = WindowType::WINDOW_TYPE_BOOT_ANIMATION;
290 option->SetWindowType(type);
291 window = new WindowSessionImpl(option);
292 ASSERT_NE(window, nullptr);
293
294 WindowType type1 = WindowType::WINDOW_TYPE_POINTER;
295 option->SetWindowType(type1);
296 window = new WindowSessionImpl(option);
297 ASSERT_NE(window, nullptr);
298
299 WindowType type2 = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW;
300 option->SetWindowType(type2);
301 window = new WindowSessionImpl(option);
302 ASSERT_NE(window, nullptr);
303
304 WindowType type3 = WindowType::APP_MAIN_WINDOW_END;
305 option->SetWindowType(type3);
306 window = new WindowSessionImpl(option);
307 ASSERT_NE(window, nullptr);
308
309 GTEST_LOG_(INFO) << "WindowSessionImplTest: SetWindowType01 end";
310 }
311
312 /**
313 * @tc.name: ColorSpace
314 * @tc.desc: SetColorSpace and GetColorSpace
315 * @tc.type: FUNC
316 */
317 HWTEST_F(WindowSessionImplTest, ColorSpace, Function | SmallTest | Level2)
318 {
319 GTEST_LOG_(INFO) << "WindowSessionImplTest: ColorSpace start";
320 sptr<WindowOption> option = new WindowOption();
321 option->SetWindowName("ColorSpace");
322 sptr<WindowSessionImpl> window =
323 new (std::nothrow) WindowSessionImpl(option);
324 ASSERT_NE(nullptr, window);
325 window->property_->SetPersistentId(1);
326
327 window->SetColorSpace(ColorSpace::COLOR_SPACE_DEFAULT);
328 ColorSpace colorSpace = window->GetColorSpace();
329 ASSERT_EQ(colorSpace, ColorSpace::COLOR_SPACE_DEFAULT);
330
331 window->SetColorSpace(ColorSpace::COLOR_SPACE_WIDE_GAMUT);
332 ColorSpace colorSpace1 = window->GetColorSpace();
333 ASSERT_EQ(colorSpace1, ColorSpace::COLOR_SPACE_DEFAULT);
334 GTEST_LOG_(INFO) << "WindowSessionImplTest: ColorSpace end";
335 }
336
337 /**
338 * @tc.name: MakeSubOrDialogWindowDragableAndMoveble01
339 * @tc.desc: MakeSubOrDialogWindowDragableAndMoveble
340 * @tc.type: FUNC
341 */
342 HWTEST_F(WindowSessionImplTest, MakeSubOrDialogWindowDragableAndMoveble01, Function | SmallTest | Level2)
343 {
344 GTEST_LOG_(INFO) << "WindowSessionImplTest: MakeSubOrDialogWindowDragableAndMoveble01 start";
345 sptr<WindowOption> option = new WindowOption();
346 ASSERT_NE(nullptr, option);
347 option->SetSubWindowDecorEnable(true);
348 option->SetWindowName("MakeSubOrDialogWindowDragableAndMoveble01");
349 sptr<WindowSessionImpl> window =
350 new (std::nothrow) WindowSessionImpl(option);
351 ASSERT_NE(nullptr, window);
352 window->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
353 window->windowSystemConfig_.uiType_ = "pc";
354 window->MakeSubOrDialogWindowDragableAndMoveble();
355 ASSERT_EQ(true, window->property_->IsDecorEnable());
356 GTEST_LOG_(INFO) << "WindowSessionImplTest: MakeSubOrDialogWindowDragableAndMoveble01 end";
357 }
358
359 /**
360 * @tc.name: MakeSubOrDialogWindowDragableAndMoveble02
361 * @tc.desc: MakeSubOrDialogWindowDragableAndMoveble
362 * @tc.type: FUNC
363 */
364 HWTEST_F(WindowSessionImplTest, MakeSubOrDialogWindowDragableAndMoveble02, Function | SmallTest | Level2)
365 {
366 GTEST_LOG_(INFO) << "WindowSessionImplTest: MakeSubOrDialogWindowDragableAndMoveble02 start";
367 sptr<WindowOption> option = new WindowOption();
368 ASSERT_NE(nullptr, option);
369 option->SetDialogDecorEnable(true);
370 option->SetWindowName("MakeSubOrDialogWindowDragableAndMoveble02");
371 sptr<WindowSessionImpl> window =
372 new (std::nothrow) WindowSessionImpl(option);
373 ASSERT_NE(nullptr, window);
374 window->property_->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
375 window->windowSystemConfig_.uiType_ = "pc";
376 window->MakeSubOrDialogWindowDragableAndMoveble();
377 ASSERT_EQ(true, window->property_->IsDecorEnable());
378 GTEST_LOG_(INFO) << "WindowSessionImplTest: MakeSubOrDialogWindowDragableAndMoveble02 end";
379 }
380
381 /**
382 * @tc.name: MakeSubOrDialogWindowDragableAndMoveble03
383 * @tc.desc: MakeSubOrDialogWindowDragableAndMoveble
384 * @tc.type: FUNC
385 */
386 HWTEST_F(WindowSessionImplTest, MakeSubOrDialogWindowDragableAndMoveble03, Function | SmallTest | Level2)
387 {
388 GTEST_LOG_(INFO) << "WindowSessionImplTest: MakeSubOrDialogWindowDragableAndMoveble03 start";
389 sptr<WindowOption> option = new WindowOption();
390 ASSERT_NE(nullptr, option);
391 option->SetDialogDecorEnable(true);
392 option->SetWindowName("MakeSubOrDialogWindowDragableAndMoveble03");
393 sptr<WindowSessionImpl> window =
394 new (std::nothrow) WindowSessionImpl(option);
395 ASSERT_NE(nullptr, window);
396 window->property_->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
397 window->windowSystemConfig_.uiType_ = "phone";
398 window->MakeSubOrDialogWindowDragableAndMoveble();
399 ASSERT_EQ(false, window->property_->IsDecorEnable());
400 GTEST_LOG_(INFO) << "WindowSessionImplTest: MakeSubOrDialogWindowDragableAndMoveble03 end";
401 }
402
403 /**
404 * @tc.name: WindowSessionCreateCheck01
405 * @tc.desc: WindowSessionCreateCheck01
406 * @tc.type: FUNC
407 */
408 HWTEST_F(WindowSessionImplTest, WindowSessionCreateCheck01, Function | SmallTest | Level2)
409 {
410 GTEST_LOG_(INFO) << "WindowSessionImplTest: WindowSessionCreateCheck01 start";
411 sptr<WindowOption> option = new WindowOption();
412 option->SetWindowName("WindowSessionCreateCheck");
413 sptr<WindowSessionImpl> window =
414 new (std::nothrow) WindowSessionImpl(option);
415 ASSERT_NE(nullptr, window);
416
417 sptr<WindowOption> option1 = new WindowOption();
418 option1->SetWindowName("WindowSessionCreateCheck"); // set the same name
419 sptr<WindowSessionImpl> window1 =
420 new (std::nothrow) WindowSessionImpl(option1);
421 ASSERT_NE(nullptr, window1);
422
423 WMError res = window1->WindowSessionCreateCheck();
424 ASSERT_EQ(res, WMError::WM_OK);
425 GTEST_LOG_(INFO) << "WindowSessionImplTest: WindowSessionCreateCheck01 end";
426 }
427
428 /**
429 * @tc.name: WindowSessionCreateCheck02
430 * @tc.desc: WindowSessionCreateCheck02
431 * @tc.type: FUNC
432 */
433 HWTEST_F(WindowSessionImplTest, WindowSessionCreateCheck02, Function | SmallTest | Level2)
434 {
435 GTEST_LOG_(INFO) << "WindowSessionImplTest: WindowSessionCreateCheck02 start";
436 sptr<WindowOption> option = new WindowOption();
437 option->SetWindowName("WindowSessionCreateCheck");
438 sptr<WindowSessionImpl> window =
439 new (std::nothrow) WindowSessionImpl(option);
440 ASSERT_NE(window, nullptr);
441
442 window->property_->SetWindowType(WindowType::WINDOW_TYPE_FLOAT_CAMERA);
443 WMError res1 = window->WindowSessionCreateCheck();
444 ASSERT_EQ(res1, WMError::WM_OK);
445
446 GTEST_LOG_(INFO) << "WindowSessionImplTest: WindowSessionCreateCheck02 end";
447 }
448
449 /**
450 * @tc.name: SetActive
451 * @tc.desc: SetActive
452 * @tc.type: FUNC
453 */
454 HWTEST_F(WindowSessionImplTest, SetActive, Function | SmallTest | Level2)
455 {
456 GTEST_LOG_(INFO) << "WindowSessionImplTest: SetActive start";
457 sptr<WindowOption> option = new WindowOption();
458 option->SetWindowName("WindowSessionCreateCheck");
459 sptr<WindowSessionImpl> window =
460 new (std::nothrow) WindowSessionImpl(option);
461 ASSERT_NE(window, nullptr);
462
463 WSError res1 = window->SetActive(true);
464 ASSERT_EQ(res1, WSError::WS_OK);
465 res1 = window->SetActive(false);
466 ASSERT_EQ(res1, WSError::WS_OK);
467
468 GTEST_LOG_(INFO) << "WindowSessionImplTest: SetActive end";
469 }
470
471 /**
472 * @tc.name: UpdateRect01
473 * @tc.desc: UpdateRect
474 * @tc.type: FUNC
475 */
476 HWTEST_F(WindowSessionImplTest, UpdateRect01, Function | SmallTest | Level2)
477 {
478 GTEST_LOG_(INFO) << "WindowSessionImplTest: UpdateRect01 start";
479 sptr<WindowOption> option = new WindowOption();
480 option->SetWindowName("WindowSessionCreateCheck");
481 sptr<WindowSessionImpl> window =
482 new (std::nothrow) WindowSessionImpl(option);
483 ASSERT_NE(window, nullptr);
484
485 WSRect rect;
486 rect.posX_ = 0;
487 rect.posY_ = 0;
488 rect.height_ = 50;
489 rect.width_ = 50;
490
491 Rect rectW; // GetRect().IsUninitializedRect is false
492 rectW.posX_ = 0;
493 rectW.posY_ = 0;
494 rectW.height_ = 200; // rectW - rect > 50
495 rectW.width_ = 200; // rectW - rect > 50
496
497 window->property_->SetWindowRect(rectW);
498 SizeChangeReason reason = SizeChangeReason::UNDEFINED;
499 WSError res = window->UpdateRect(rect, reason);
500 ASSERT_EQ(res, WSError::WS_OK);
501
502 rectW.height_ = 50;
503 window->property_->SetWindowRect(rectW);
504 res = window->UpdateRect(rect, reason);
505 ASSERT_EQ(res, WSError::WS_OK);
506
507 rectW.height_ = 200;
508 rectW.width_ = 50;
509 window->property_->SetWindowRect(rectW);
510 res = window->UpdateRect(rect, reason);
511 ASSERT_EQ(res, WSError::WS_OK);
512 GTEST_LOG_(INFO) << "WindowSessionImplTest: UpdateRect01 end";
513 }
514
515 /**
516 * @tc.name: UpdateRect02
517 * @tc.desc: UpdateRect
518 * @tc.type: FUNC
519 */
520 HWTEST_F(WindowSessionImplTest, UpdateRect02, Function | SmallTest | Level2)
521 {
522 GTEST_LOG_(INFO) << "WindowSessionImplTest: UpdateRect02 start";
523 sptr<WindowOption> option = new WindowOption();
524 option->SetWindowName("WindowSessionCreateCheck");
525 sptr<WindowSessionImpl> window =
526 new (std::nothrow) WindowSessionImpl(option);
527 ASSERT_NE(window, nullptr);
528
529 WSRect rect;
530 rect.posX_ = 0;
531 rect.posY_ = 0;
532 rect.height_ = 0;
533 rect.width_ = 0;
534
535 Rect rectW; // GetRect().IsUninitializedRect is true
536 rectW.posX_ = 0;
537 rectW.posY_ = 0;
538 rectW.height_ = 0; // rectW - rect > 50
539 rectW.width_ = 0; // rectW - rect > 50
540
541 window->property_->SetWindowRect(rectW);
542 SizeChangeReason reason = SizeChangeReason::UNDEFINED;
543 WSError res = window->UpdateRect(rect, reason);
544 ASSERT_EQ(res, WSError::WS_OK);
545
546 rect.height_ = 50;
547 rect.width_ = 50;
548 rectW.height_ = 50;
549 rectW.width_ = 50;
550 window->property_->SetWindowRect(rectW);
551 res = window->UpdateRect(rect, reason);
552 ASSERT_EQ(res, WSError::WS_OK);
553 GTEST_LOG_(INFO) << "WindowSessionImplTest: UpdateRect02 end";
554 }
555
556 /**
557 * @tc.name: UpdateFocus
558 * @tc.desc: UpdateFocus
559 * @tc.type: FUNC
560 */
561 HWTEST_F(WindowSessionImplTest, UpdateFocus, Function | SmallTest | Level2)
562 {
563 GTEST_LOG_(INFO) << "WindowSessionImplTest: UpdateFocus start";
564 sptr<WindowOption> option = new WindowOption();
565 option->SetWindowName("WindowSessionCreateCheck");
566 sptr<WindowSessionImpl> window =
567 new (std::nothrow) WindowSessionImpl(option);
568 ASSERT_NE(window, nullptr);
569
570 WSError res = window->UpdateFocus(true);
571 ASSERT_EQ(res, WSError::WS_OK);
572 res = window->UpdateFocus(false);
573 ASSERT_EQ(res, WSError::WS_OK);
574
575 GTEST_LOG_(INFO) << "WindowSessionImplTest: UpdateFocus end";
576 }
577
578 /**
579 * @tc.name: RequestFocusByClient
580 * @tc.desc: RequestFocusByClient Test
581 * @tc.type: FUNC
582 */
583 HWTEST_F(WindowSessionImplTest, RequestFocusByClient, Function | SmallTest | Level2)
584 {
585 GTEST_LOG_(INFO) << "WindowSessionImplTest: RequestFocusByClient start";
586 sptr<WindowOption> option = new WindowOption();
587 ASSERT_NE(nullptr, option);
588 option->SetWindowName("WindowRequestFocusByClientCheck");
589 sptr<WindowSessionImpl> window =
590 new (std::nothrow) WindowSessionImpl(option);
591 ASSERT_NE(window, nullptr);
592
593 WMError res = window->RequestFocusByClient(true);
594 ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW);
595 res = window->RequestFocusByClient(false);
596 ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW);
597
598 window->property_->SetPersistentId(1);
599 SessionInfo sessionInfo = { "RequestFocusByClient", "RequestFocusByClient", "RequestFocusByClient" };
600 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
601 ASSERT_NE(session, nullptr);
602 window->hostSession_ = session;
603 window->state_ = WindowState::STATE_INITIAL;
604 res = window->RequestFocusByClient(true);
605 ASSERT_EQ(res, WMError::WM_OK);
606 res = window->RequestFocusByClient(false);
607 ASSERT_EQ(res, WMError::WM_OK);
608
609 GTEST_LOG_(INFO) << "WindowSessionImplTest: RequestFocusByClient end";
610 }
611
612 /**
613 * @tc.name: UpdateViewportConfig
614 * @tc.desc: UpdateViewportConfig
615 * @tc.type: FUNC
616 */
617 HWTEST_F(WindowSessionImplTest, UpdateViewportConfig, Function | SmallTest | Level2)
618 {
619 GTEST_LOG_(INFO) << "WindowSessionImplTest: UpdateViewportConfig start";
620 sptr<WindowOption> option = new WindowOption();
621 option->SetWindowName("WindowSessionCreateCheck");
622 sptr<WindowSessionImpl> window =
623 new (std::nothrow) WindowSessionImpl(option);
624 ASSERT_NE(window, nullptr);
625
626 Rect rectW; // GetRect().IsUninitializedRect is true
627 rectW.posX_ = 0;
628 rectW.posY_ = 0;
629 rectW.height_ = 0; // rectW - rect > 50
630 rectW.width_ = 0; // rectW - rect > 50
631
632 WindowSizeChangeReason reason = WindowSizeChangeReason::UNDEFINED;
633 int32_t res = 0;
634 window->UpdateViewportConfig(rectW, reason);
635 ASSERT_EQ(res, 0);
636
637 DisplayId displayId = 1;
638 window->property_->SetDisplayId(displayId);
639 window->UpdateViewportConfig(rectW, reason);
640 ASSERT_EQ(res, 0);
641
642 GTEST_LOG_(INFO) << "WindowSessionImplTest: UpdateViewportConfig end";
643 }
644
645 /**
646 * @tc.name: UpdateViewportConfig01
647 * @tc.desc: UpdateViewportConfig
648 * @tc.type: FUNC
649 */
650 HWTEST_F(WindowSessionImplTest, UpdateViewportConfig01, Function | SmallTest | Level2)
651 {
652 sptr<WindowOption> option = new WindowOption();
653 option->SetWindowName("UpdateViewportConfig01");
654 sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
655 Rect rectW;
656 rectW.posX_ = 0;
657 rectW.posY_ = 0;
658 rectW.height_ = 0;
659 rectW.width_ = 0;
660 WindowSizeChangeReason reason = WindowSizeChangeReason::UNDEFINED;
661 sptr<DisplayInfo> displayInfo = sptr<DisplayInfo>::MakeSptr();
662 window->UpdateViewportConfig(rectW, reason, nullptr, displayInfo);
663 rectW.width_ = 10;
664 rectW.height_ = 0;
665 window->UpdateViewportConfig(rectW, reason, nullptr, displayInfo);
666 rectW.width_ = 10;
667 rectW.height_ = 10;
668 window->UpdateViewportConfig(rectW, reason, nullptr, displayInfo);
669 ASSERT_NE(window, nullptr);
670 }
671
672 /**
673 * @tc.name: CreateWindowAndDestroy01
674 * @tc.desc: GetPersistentId
675 * @tc.type: FUNC
676 */
677 HWTEST_F(WindowSessionImplTest, GetPersistentId01, Function | SmallTest | Level2)
678 {
679 GTEST_LOG_(INFO) << "WindowSessionImplTest: GetPersistentId start";
680 sptr<WindowOption> option = new WindowOption();
681 sptr<WindowSessionImpl> window = new WindowSessionImpl(option);
682 ASSERT_NE(window->property_, nullptr);
683
684 window->property_->SetPersistentId(1);
685 const int32_t res2 = window->GetPersistentId();
686 ASSERT_EQ(res2, 1);
687 GTEST_LOG_(INFO) << "WindowSessionImplTest: GetPersistentId end";
688 }
689
690 /**
691 * @tc.name: GetFloatingWindowParentId
692 * @tc.desc: GetFloatingWindowParentId and UpdateTitleButtonVisibility
693 * @tc.type: FUNC
694 */
695 HWTEST_F(WindowSessionImplTest, GetFloatingWindowParentId, Function | SmallTest | Level2) {
696 GTEST_LOG_(INFO) << "WindowSessionImplTest: GetFloatingWindowParentId start";
697 sptr<WindowOption> option = new WindowOption();
698 option->SetWindowName("Connect");
699 sptr<WindowSessionImpl> window =
700 new (std::nothrow) WindowSessionImpl(option);
701 ASSERT_NE(nullptr, window);
702 window->property_->SetPersistentId(1);
703 // connect with null session
704 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->Connect());
705
706 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule",
707 "CreateTestAbility"};
708 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
709 ASSERT_NE(nullptr, session);
710 window->hostSession_ = session;
711 EXPECT_CALL(*(session), Connect(_, _, _, _, _, _, _))
712 .WillOnce(Return(WSError::WS_ERROR_NULLPTR));
713 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->Connect());
714 EXPECT_CALL(*(session), Connect(_, _, _, _, _, _, _))
715 .WillOnce(Return(WSError::WS_OK));
716 ASSERT_EQ(WMError::WM_OK, window->Connect());
717
718 window->UpdateTitleButtonVisibility();
719 int32_t res = window->GetFloatingWindowParentId();
720 ASSERT_EQ(res, INVALID_SESSION_ID);
721 GTEST_LOG_(INFO) << "WindowSessionImplTest: GetFloatingWindowParentId start";
722 }
723
724 /**
725 * @tc.name: UpdateDecorEnable
726 * @tc.desc: UpdateDecorEnable
727 * @tc.type: FUNC
728 */
729 HWTEST_F(WindowSessionImplTest, UpdateDecorEnable, Function | SmallTest | Level2)
730 {
731 GTEST_LOG_(INFO) << "WindowSessionImplTest: UpdateDecorEnable start";
732 sptr<WindowOption> option = new WindowOption();
733 option->SetWindowName("UpdateDecorEnable");
734 sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
735 ASSERT_NE(window, nullptr);
736
737 int res = 1;
738 window->UpdateDecorEnable(true);
739 window->UpdateDecorEnable(false);
740 ASSERT_EQ(res, 1);
741 GTEST_LOG_(INFO) << "WindowSessionImplTest: UpdateDecorEnable end";
742 }
743
744 /**
745 * @tc.name: NotifyModeChange
746 * @tc.desc: NotifyModeChange
747 * @tc.type: FUNC
748 */
749 HWTEST_F(WindowSessionImplTest, NotifyModeChange, Function | SmallTest | Level2)
750 {
751 GTEST_LOG_(INFO) << "WindowSessionImplTest: NotifyModeChange start";
752 sptr<WindowOption> option = new WindowOption();
753 option->SetWindowName("NotifyModeChange");
754 sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
755 ASSERT_NE(window, nullptr);
756
757 WindowMode mode = WindowMode::WINDOW_MODE_UNDEFINED;
758 int res = 1;
759 window->NotifyModeChange(mode, true);
760 window->NotifyModeChange(mode, false);
761 ASSERT_EQ(res, 1);
762 GTEST_LOG_(INFO) << "WindowSessionImplTest: NotifyModeChange end";
763 }
764
765 /**
766 * @tc.name: RequestVsyncSucc
767 * @tc.desc: RequestVsync Test Succ
768 * @tc.type: FUNC
769 */
770 HWTEST_F(WindowSessionImplTest, RequestVsyncSucc, Function | SmallTest | Level2)
771 {
772 sptr<WindowOption> option = new WindowOption();
773 option->SetWindowName("RequestVsyncSucc");
774 sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
775 ASSERT_NE(window, nullptr);
776 std::shared_ptr<VsyncCallback> vsyncCallback = std::make_shared<VsyncCallback>();
777 window->state_ = WindowState::STATE_DESTROYED;
778 ASSERT_EQ(WindowState::STATE_DESTROYED, window->GetWindowState());
779 window->RequestVsync(vsyncCallback);
780 }
781
782
783 /**
784 * @tc.name: RequestVsyncErr
785 * @tc.desc: RequestVsync Test Err
786 * @tc.type: FUNC
787 */
788 HWTEST_F(WindowSessionImplTest, RequestVsyncErr, Function | SmallTest | Level2)
789 {
790 sptr<WindowOption> option = new WindowOption();
791 option->SetWindowName("RequestVsyncErr");
792 sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
793 ASSERT_NE(window, nullptr);
794 std::shared_ptr<VsyncCallback> vsyncCallback = std::make_shared<VsyncCallback>();
795 window->state_ = WindowState::STATE_DESTROYED;
796 ASSERT_EQ(WindowState::STATE_DESTROYED, window->GetWindowState());
797 window->vsyncStation_ = nullptr;
798 window->RequestVsync(vsyncCallback);
799 }
800
801 /**
802 * @tc.name: ClearVsync
803 * @tc.desc: Clear vsync test
804 * @tc.type: FUNC
805 */
806 HWTEST_F(WindowSessionImplTest, ClearVsync, Function | SmallTest | Level2)
807 {
808 sptr<WindowOption> option = new WindowOption();
809 ASSERT_NE(option, nullptr);
810 option->SetWindowName("ClearVsync");
811 sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
812 ASSERT_NE(window, nullptr);
813 window->ClearVsyncStation();
814 ASSERT_EQ(window->vsyncStation_, nullptr);
815 }
816
817 /**
818 * @tc.name: SetFocusable
819 * @tc.desc: SetFocusable
820 * @tc.type: FUNC
821 */
822 HWTEST_F(WindowSessionImplTest, SetFocusable, Function | SmallTest | Level2)
823 {
824 GTEST_LOG_(INFO) << "WindowSessionImplTest: SetFocusable start";
825 sptr<WindowOption> option = new WindowOption();
826 option->SetWindowName("SetFocusable");
827 sptr<WindowSessionImpl> window = new WindowSessionImpl(option);
828
829 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule",
830 "CreateTestAbility"};
831 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
832 ASSERT_NE(nullptr, session);
833 ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
834 window->hostSession_ = session;
835 window->property_->SetPersistentId(1);
836 ASSERT_FALSE(window->GetPersistentId() == INVALID_SESSION_ID);
837 ASSERT_FALSE(window->IsWindowSessionInvalid());
838 WMError res = window->SetFocusable(true);
839 ASSERT_EQ(res, WMError::WM_OK);
840 ASSERT_EQ(WMError::WM_OK, window->Destroy());
841
842 // session is null
843 window = new WindowSessionImpl(option);
844 ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, nullptr));
845 res = window->SetFocusable(true);
846 ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW);
847 res = window->SetFocusable(false);
848 ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW);
849 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
850 GTEST_LOG_(INFO) << "WindowSessionImplTest: SetFocusable end";
851 }
852
853 /**
854 * @tc.name: SetTouchable
855 * @tc.desc: SetTouchable
856 * @tc.type: FUNC
857 */
858 HWTEST_F(WindowSessionImplTest, SetTouchable, Function | SmallTest | Level2)
859 {
860 GTEST_LOG_(INFO) << "WindowSessionImplTest: SetTouchable start";
861 sptr<WindowOption> option = new WindowOption();
862 option->SetWindowName("SetTouchable");
863 sptr<WindowSessionImpl> window = new WindowSessionImpl(option);
864
865 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule",
866 "CreateTestAbility"};
867 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
868 ASSERT_NE(nullptr, session);
869 ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
870 ASSERT_NE(window->property_, nullptr);
871 window->hostSession_ = session;
872 window->property_->SetPersistentId(1);
873 ASSERT_FALSE(window->IsWindowSessionInvalid());
874 WMError res = window->SetTouchable(true);
875 ASSERT_EQ(res, WMError::WM_OK);
876 ASSERT_NE(window->property_, nullptr);
877 ASSERT_TRUE(window->property_->touchable_);
878 ASSERT_EQ(WMError::WM_OK, window->Destroy());
879
880 // session is null
881 window = new WindowSessionImpl(option);
882 ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, nullptr));
883 res = window->SetTouchable(true);
884 ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW);
885 res = window->SetTouchable(false);
886 ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW);
887 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
888 GTEST_LOG_(INFO) << "WindowSessionImplTest: SetTouchable end";
889 }
890
891 /**
892 * @tc.name: SetBrightness01
893 * @tc.desc: SetBrightness
894 * @tc.type: FUNC
895 */
896 HWTEST_F(WindowSessionImplTest, SetBrightness01, Function | SmallTest | Level2)
897 {
898 GTEST_LOG_(INFO) << "WindowSessionImplTest: SetBrightness01 start";
899 sptr<WindowOption> option = new WindowOption();
900 option->SetWindowName("SetBrightness01");
901 sptr<WindowSessionImpl> window = new WindowSessionImpl(option);
902
903 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule",
904 "CreateTestAbility"};
905 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
906 ASSERT_NE(nullptr, session);
907 ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
908 window->property_->SetPersistentId(1);
909
910 float brightness = -1.0; // brightness < 0
911 WMError res = window->SetBrightness(brightness);
912 ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW);
913 brightness = 2.0; // brightness > 1
914 res = window->SetBrightness(brightness);
915 ASSERT_EQ(res, WMError::WM_ERROR_INVALID_PARAM);
916
917 brightness = 0.5;
918 res = window->SetBrightness(brightness);
919 ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW);
920 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
921 GTEST_LOG_(INFO) << "WindowSessionImplTest: SetBrightness01 end";
922 }
923
924 /**
925 * @tc.name: SetBrightness02
926 * @tc.desc: SetBrightness
927 * @tc.type: FUNC
928 */
929 HWTEST_F(WindowSessionImplTest, SetBrightness02, Function | SmallTest | Level2)
930 {
931 GTEST_LOG_(INFO) << "WindowSessionImplTest: SetBrightness02 start";
932 sptr<WindowOption> option = new WindowOption();
933 option->SetWindowName("SetBrightness02");
934 sptr<WindowSessionImpl> window = new WindowSessionImpl(option);
935
936 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule",
937 "CreateTestAbility"};
938 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
939 ASSERT_NE(nullptr, session);
940 ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
941 window->property_->SetPersistentId(1);
942 window->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_END);
943 float brightness = 0.5;
944 WMError res = window->SetBrightness(brightness);
945 ASSERT_EQ(res, WMError::WM_ERROR_INVALID_TYPE);
946
947 window->state_ = WindowState::STATE_SHOWN;
948 res = window->SetBrightness(brightness);
949 ASSERT_NE(res, WMError::WM_ERROR_NULLPTR);
950 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
951 GTEST_LOG_(INFO) << "WindowSessionImplTest: SetBrightness02 end";
952 }
953
954 /**
955 * @tc.name: SetRequestedOrientation
956 * @tc.desc: SetRequestedOrientation
957 * @tc.type: FUNC
958 */
959 HWTEST_F(WindowSessionImplTest, SetRequestedOrientation, Function | SmallTest | Level2)
960 {
961 GTEST_LOG_(INFO) << "WindowSessionImplTest: SetRequestedOrientation start";
962 sptr<WindowOption> option = new WindowOption();
963 option->SetWindowName("SetRequestedOrientation");
964 sptr<WindowSessionImpl> window = new WindowSessionImpl(option);
965
966 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule",
967 "CreateTestAbility"};
968 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
969 ASSERT_NE(nullptr, session);
970 ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
971
972 window->hostSession_ = session;
973 window->property_->SetPersistentId(1);
974
975 Orientation ori = Orientation::VERTICAL;
976 window->SetRequestedOrientation(ori);
977 Orientation ret = window->GetRequestedOrientation();
978 ASSERT_EQ(ret, ori);
979
980 window->SetRequestedOrientation(Orientation::AUTO_ROTATION_UNSPECIFIED);
981 Orientation ret1 = window->GetRequestedOrientation();
982 ASSERT_EQ(ret1, Orientation::AUTO_ROTATION_UNSPECIFIED);
983
984 window->SetRequestedOrientation(Orientation::USER_ROTATION_PORTRAIT);
985 Orientation ret2 = window->GetRequestedOrientation();
986 ASSERT_EQ(ret2, Orientation::USER_ROTATION_PORTRAIT);
987
988 window->SetRequestedOrientation(Orientation::USER_ROTATION_LANDSCAPE);
989 Orientation ret3 = window->GetRequestedOrientation();
990 ASSERT_EQ(ret3, Orientation::USER_ROTATION_LANDSCAPE);
991
992 window->SetRequestedOrientation(Orientation::USER_ROTATION_PORTRAIT_INVERTED);
993 Orientation ret4 = window->GetRequestedOrientation();
994 ASSERT_EQ(ret4, Orientation::USER_ROTATION_PORTRAIT_INVERTED);
995
996 window->SetRequestedOrientation(Orientation::USER_ROTATION_LANDSCAPE_INVERTED);
997 Orientation ret5 = window->GetRequestedOrientation();
998 ASSERT_EQ(ret5, Orientation::USER_ROTATION_LANDSCAPE_INVERTED);
999
1000 window->SetRequestedOrientation(Orientation::FOLLOW_DESKTOP);
1001 Orientation ret6 = window->GetRequestedOrientation();
1002 ASSERT_EQ(ret6, Orientation::FOLLOW_DESKTOP);
1003 ASSERT_EQ(WMError::WM_OK, window->Destroy());
1004 GTEST_LOG_(INFO) << "WindowSessionImplTest: SetRequestedOrientation end";
1005 }
1006
1007 /**
1008 * @tc.name: GetRequestedOrientationtest01
1009 * @tc.desc: GetRequestedOrientation
1010 * @tc.type: FUNC
1011 */
1012 HWTEST_F(WindowSessionImplTest, GetRequestedOrientation, Function | SmallTest | Level2)
1013 {
1014 GTEST_LOG_(INFO) << "WindowSessionImplTest: GetRequestedOrientationtest01 start";
1015 sptr<WindowOption> option = new WindowOption();
1016 ASSERT_NE(option, nullptr);
1017 option->SetWindowName("GetRequestedOrientation");
1018
1019 sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
1020 ASSERT_NE(window, nullptr);
1021
1022 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule",
1023 "CreateTestAbility"};
1024 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1025 ASSERT_NE(nullptr, session);
1026 ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
1027
1028 window->hostSession_ = session;
1029 window->property_->SetPersistentId(1);
1030
1031 Orientation ori = Orientation::HORIZONTAL;
1032 window->SetRequestedOrientation(ori);
1033 Orientation ret = window->GetRequestedOrientation();
1034 ASSERT_EQ(ret, ori);
1035
1036 window->SetRequestedOrientation(Orientation::AUTO_ROTATION_UNSPECIFIED);
1037 Orientation ret1 = window->GetRequestedOrientation();
1038 ASSERT_EQ(ret1, Orientation::AUTO_ROTATION_UNSPECIFIED);
1039
1040 window->SetRequestedOrientation(Orientation::USER_ROTATION_PORTRAIT);
1041 Orientation ret2 = window->GetRequestedOrientation();
1042 ASSERT_EQ(ret2, Orientation::USER_ROTATION_PORTRAIT);
1043
1044 window->SetRequestedOrientation(Orientation::USER_ROTATION_LANDSCAPE);
1045 Orientation ret3 = window->GetRequestedOrientation();
1046 ASSERT_EQ(ret3, Orientation::USER_ROTATION_LANDSCAPE);
1047
1048 window->SetRequestedOrientation(Orientation::USER_ROTATION_PORTRAIT_INVERTED);
1049 Orientation ret4 = window->GetRequestedOrientation();
1050 ASSERT_EQ(ret4, Orientation::USER_ROTATION_PORTRAIT_INVERTED);
1051
1052 window->SetRequestedOrientation(Orientation::USER_ROTATION_LANDSCAPE_INVERTED);
1053 Orientation ret5 = window->GetRequestedOrientation();
1054 ASSERT_EQ(ret5, Orientation::USER_ROTATION_LANDSCAPE_INVERTED);
1055
1056 window->SetRequestedOrientation(Orientation::FOLLOW_DESKTOP);
1057 Orientation ret6 = window->GetRequestedOrientation();
1058 ASSERT_EQ(ret6, Orientation::FOLLOW_DESKTOP);
1059
1060 GTEST_LOG_(INFO) << "WindowSessionImplTest: GetRequestedOrientationtest01 end";
1061 }
1062
1063 /**
1064 * @tc.name: GetContentInfo
1065 * @tc.desc: GetContentInfo
1066 * @tc.type: FUNC
1067 */
1068 HWTEST_F(WindowSessionImplTest, GetContentInfo, Function | SmallTest | Level2)
1069 {
1070 GTEST_LOG_(INFO) << "WindowSessionImplTest: GetContentInfo start";
1071 sptr<WindowOption> option = new WindowOption();
1072 option->SetWindowName("GetContentInfo");
1073 sptr<WindowSessionImpl> window = new WindowSessionImpl(option);
1074
1075 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule",
1076 "CreateTestAbility"};
1077 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1078 ASSERT_NE(nullptr, session);
1079 ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
1080
1081 std::string res = window->GetContentInfo();
1082 ASSERT_EQ(res, "");
1083 window->uiContent_ = nullptr;
1084 res = window->GetContentInfo();
1085 ASSERT_EQ(res, "");
1086 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
1087 GTEST_LOG_(INFO) << "WindowSessionImplTest: GetContentInfo end";
1088 }
1089
1090 /**
1091 * @tc.name: OnNewWant
1092 * @tc.desc: OnNewWant
1093 * @tc.type: FUNC
1094 */
1095 HWTEST_F(WindowSessionImplTest, OnNewWant, Function | SmallTest | Level2)
1096 {
1097 GTEST_LOG_(INFO) << "WindowSessionImplTest: OnNewWant start";
1098 sptr<WindowOption> option = new WindowOption();
1099 option->SetWindowName("OnNewWant");
1100 sptr<WindowSessionImpl> window = new WindowSessionImpl(option);
1101
1102 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule",
1103 "CreateTestAbility"};
1104 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1105 ASSERT_NE(nullptr, session);
1106 ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
1107
1108 AAFwk::Want want;
1109 window->uiContent_ = nullptr;
1110 window->OnNewWant(want);
1111 ASSERT_EQ(window->GetUIContentSharedPtr(), nullptr);
1112 window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
1113 window->OnNewWant(want);
1114 ASSERT_NE(window->GetUIContentSharedPtr(), nullptr);
1115
1116 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
1117 GTEST_LOG_(INFO) << "WindowSessionImplTest: OnNewWant end";
1118 }
1119
1120 /**
1121 * @tc.name: SetAPPWindowLabel
1122 * @tc.desc: SetAPPWindowLabel
1123 * @tc.type: FUNC
1124 */
1125 HWTEST_F(WindowSessionImplTest, SetAPPWindowLabel, Function | SmallTest | Level2)
1126 {
1127 GTEST_LOG_(INFO) << "WindowSessionImplTest: SetAPPWindowLabel start";
1128 sptr<WindowOption> option = new WindowOption();
1129 option->SetWindowName("SetAPPWindowLabel");
1130 sptr<WindowSessionImpl> window = new WindowSessionImpl(option);
1131
1132 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule",
1133 "CreateTestAbility"};
1134 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1135 ASSERT_NE(nullptr, session);
1136 ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
1137
1138 std::string label = "label";
1139 window->uiContent_ = nullptr;
1140 WMError res = window->SetAPPWindowLabel(label);
1141 ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
1142
1143 window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
1144 res = window->SetAPPWindowLabel(label);
1145 ASSERT_EQ(res, WMError::WM_OK);
1146 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
1147 GTEST_LOG_(INFO) << "WindowSessionImplTest: SetAPPWindowLabel end";
1148 }
1149
1150 /**
1151 * @tc.name: RegisterListener01
1152 * @tc.desc: RegisterListener and UnregisterListener
1153 * @tc.type: FUNC
1154 */
1155 HWTEST_F(WindowSessionImplTest, RegisterListener01, Function | SmallTest | Level2)
1156 {
1157 GTEST_LOG_(INFO) << "WindowSessionImplTest: RegisterListener01 start";
1158 sptr<WindowOption> option = new WindowOption();
1159 option->SetWindowName("RegisterListener01");
1160 sptr<WindowSessionImpl> window = new WindowSessionImpl(option);
1161
1162 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule",
1163 "CreateTestAbility"};
1164 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1165 ASSERT_NE(nullptr, session);
1166 ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
1167 window->hostSession_ = session;
1168 window->property_->SetPersistentId(1);
1169
1170 sptr<IWindowLifeCycle> listener = nullptr;
1171 WMError res = window->RegisterLifeCycleListener(listener);
1172 ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
1173 res = window->UnregisterLifeCycleListener(listener);
1174 ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
1175
1176 sptr<IOccupiedAreaChangeListener> listener1 = nullptr;
1177 res = window->RegisterOccupiedAreaChangeListener(listener1);
1178 ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
1179 res = window->UnregisterOccupiedAreaChangeListener(listener1);
1180 ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
1181
1182 sptr<IWindowChangeListener> listener2 = nullptr;
1183 res = window->RegisterWindowChangeListener(listener2);
1184 ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
1185 res = window->UnregisterWindowChangeListener(listener2);
1186 ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
1187
1188 sptr<IDialogDeathRecipientListener> listener3 = nullptr;
1189 window->RegisterDialogDeathRecipientListener(listener3);
1190 window->UnregisterDialogDeathRecipientListener(listener3);
1191
1192 sptr<IDialogTargetTouchListener> listener4 = nullptr;
1193 res = window->RegisterDialogTargetTouchListener(listener4);
1194 ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
1195 res = window->UnregisterDialogTargetTouchListener(listener4);
1196 ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
1197 sptr<IWindowStatusChangeListener> listener5 = nullptr;
1198 res = window->RegisterWindowStatusChangeListener(listener5);
1199 ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
1200 res = window->UnregisterWindowStatusChangeListener(listener5);
1201 ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
1202 ASSERT_EQ(WMError::WM_OK, window->Destroy());
1203 GTEST_LOG_(INFO) << "WindowSessionImplTest: RegisterListener01 end";
1204 }
1205
1206 /**
1207 * @tc.name: RegisterListener02
1208 * @tc.desc: RegisterListener and UnregisterListener
1209 * @tc.type: FUNC
1210 */
1211 HWTEST_F(WindowSessionImplTest, RegisterListener02, Function | SmallTest | Level2)
1212 {
1213 GTEST_LOG_(INFO) << "WindowSessionImplTest: RegisterListener02 start";
1214 sptr<WindowOption> option = new WindowOption();
1215 option->SetWindowName("RegisterListener02");
1216 sptr<WindowSessionImpl> window = new WindowSessionImpl(option);
1217 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule",
1218 "CreateTestAbility"};
1219 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1220 ASSERT_NE(nullptr, session);
1221 ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
1222 window->hostSession_ = session;
1223 window->property_->SetPersistentId(1);
1224
1225 sptr<IScreenshotListener> listener5 = nullptr;
1226 WMError res = window->RegisterScreenshotListener(listener5);
1227 ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
1228 res = window->UnregisterScreenshotListener(listener5);
1229 ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
1230
1231 sptr<IAvoidAreaChangedListener> listener6 = nullptr;
1232 res = window->RegisterAvoidAreaChangeListener(listener6);
1233 ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
1234 res = window->UnregisterAvoidAreaChangeListener(listener6);
1235 ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
1236
1237 sptr<ITouchOutsideListener> listener7 = nullptr;
1238 res = window->RegisterTouchOutsideListener(listener7);
1239 ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
1240 res = window->UnregisterTouchOutsideListener(listener7);
1241 ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
1242
1243 IWindowVisibilityListenerSptr listener8 = nullptr;
1244 res = window->RegisterWindowVisibilityChangeListener(listener8);
1245 ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
1246 res = window->UnregisterWindowVisibilityChangeListener(listener8);
1247 ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
1248
1249 IDisplayIdChangeListenerSptr listener9 = nullptr;
1250 res = window->RegisterDisplayIdChangeListener(listener9);
1251 ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
1252 res = window->UnregisterDisplayIdChangeListener(listener9);
1253 ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
1254
1255 sptr<IWindowTitleButtonRectChangedListener> listener10 = nullptr;
1256 res = window->RegisterWindowTitleButtonRectChangeListener(listener10);
1257 ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
1258 res = window->UnregisterWindowTitleButtonRectChangeListener(listener10);
1259 ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
1260 ASSERT_EQ(WMError::WM_OK, window->Destroy());
1261 GTEST_LOG_(INFO) << "WindowSessionImplTest: RegisterListener02 end";
1262 }
1263
1264 /**
1265 * @tc.name: RegisterListener03
1266 * @tc.desc: RegisterListener and UnregisterListener
1267 * @tc.type: FUNC
1268 */
1269 HWTEST_F(WindowSessionImplTest, RegisterListener03, Function | SmallTest | Level2)
1270 {
1271 GTEST_LOG_(INFO) << "WindowSessionImplTest: RegisterListener03 start";
1272 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1273 option->SetWindowName("RegisterListener03");
1274 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1275
1276 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule",
1277 "CreateTestAbility"};
1278 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
1279 ASSERT_NE(nullptr, session);
1280 ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
1281 window->hostSession_ = session;
1282 window->property_->SetPersistentId(1);
1283
1284 sptr<IDisplayMoveListener> listener6 = nullptr;
1285 WMError res = window->RegisterDisplayMoveListener(listener6);
1286 ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
1287 res = window->UnregisterDisplayMoveListener(listener6);
1288 ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
1289
1290 sptr<IWindowRectChangeListener> listener7 = nullptr;
1291 res = window->RegisterWindowRectChangeListener(listener7);
1292 ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
1293
1294 sptr<ISubWindowCloseListener> listener10 = nullptr;
1295 res = window->RegisterSubWindowCloseListeners(listener10);
1296 ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
1297 res = window->UnregisterSubWindowCloseListeners(listener10);
1298 ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
1299
1300 sptr<ISwitchFreeMultiWindowListener> listener11 = nullptr;
1301 res = window->RegisterSwitchFreeMultiWindowListener(listener11);
1302 ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
1303 res = window->UnregisterSwitchFreeMultiWindowListener(listener11);
1304 ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
1305
1306 sptr<IMainWindowCloseListener> listener12 = nullptr;
1307 res = window->RegisterMainWindowCloseListeners(listener12);
1308 EXPECT_EQ(res, WMError::WM_ERROR_NULLPTR);
1309 res = window->UnregisterMainWindowCloseListeners(listener12);
1310 EXPECT_EQ(res, WMError::WM_ERROR_NULLPTR);
1311
1312 EXPECT_EQ(WMError::WM_OK, window->Destroy());
1313 GTEST_LOG_(INFO) << "WindowSessionImplTest: RegisterListener03 end";
1314 }
1315
1316 /**
1317 * @tc.name: NotifyDisplayMove
1318 * @tc.desc: NotifyDisplayMove
1319 * @tc.type: FUNC
1320 */
1321 HWTEST_F(WindowSessionImplTest, NotifyDisplayMove, Function | SmallTest | Level2)
1322 {
1323 GTEST_LOG_(INFO) << "WindowSessionImplTest: NotifyDisplayMove start";
1324 sptr<WindowOption> option = new WindowOption();
1325 option->SetWindowName("NotifyDisplayMove");
1326 sptr<WindowSessionImpl> window = new WindowSessionImpl(option);
1327
1328 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule",
1329 "CreateTestAbility"};
1330 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1331 ASSERT_NE(nullptr, session);
1332 ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
1333
1334 int res = 0;
1335 DisplayId from = 0;
1336 DisplayId to = 2;
1337 window->NotifyDisplayMove(from, to);
1338 ASSERT_EQ(res, 0);
1339 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
1340 GTEST_LOG_(INFO) << "WindowSessionImplTest: NotifyDisplayMove end";
1341 }
1342
1343 /**
1344 * @tc.name: NotifyAfterForeground
1345 * @tc.desc: NotifyAfterForeground
1346 * @tc.type: FUNC
1347 */
1348 HWTEST_F(WindowSessionImplTest, NotifyAfterForeground, Function | SmallTest | Level2)
1349 {
1350 GTEST_LOG_(INFO) << "WindowSessionImplTest: NotifyAfterForeground start";
1351 sptr<WindowOption> option = new WindowOption();
1352 option->SetWindowName("NotifyAfterForeground");
1353 sptr<WindowSessionImpl> window = new WindowSessionImpl(option);
1354
1355 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule",
1356 "CreateTestAbility"};
1357 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1358 ASSERT_NE(nullptr, session);
1359 ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
1360
1361 int res = 0;
1362 window->NotifyAfterForeground(true, true);
1363 window->NotifyAfterForeground(false, false);
1364 window->vsyncStation_ = nullptr;
1365 window->NotifyAfterForeground(false, false);
1366 ASSERT_EQ(res, 0);
1367 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
1368 GTEST_LOG_(INFO) << "WindowSessionImplTest: NotifyAfterForeground end";
1369 }
1370
1371 /**
1372 * @tc.name: NotifyAfterBackground
1373 * @tc.desc: NotifyAfterBackground
1374 * @tc.type: FUNC
1375 */
1376 HWTEST_F(WindowSessionImplTest, NotifyAfterBackground, Function | SmallTest | Level2)
1377 {
1378 GTEST_LOG_(INFO) << "WindowSessionImplTest: NotifyAfterBackground start";
1379 sptr<WindowOption> option = new WindowOption();
1380 option->SetWindowName("NotifyAfterBackground");
1381 sptr<WindowSessionImpl> window = new WindowSessionImpl(option);
1382
1383 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule",
1384 "CreateTestAbility"};
1385 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1386 ASSERT_NE(nullptr, session);
1387 ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
1388
1389 int res = 0;
1390 window->NotifyAfterBackground(true, true);
1391 window->NotifyAfterBackground(false, false);
1392 window->vsyncStation_ = nullptr;
1393 window->NotifyAfterBackground(false, false);
1394 ASSERT_EQ(res, 0);
1395 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
1396 GTEST_LOG_(INFO) << "WindowSessionImplTest: NotifyAfterBackground end";
1397 }
1398
1399 /**
1400 * @tc.name: NotifyAfterUnfocused
1401 * @tc.desc: NotifyAfterUnfocused
1402 * @tc.type: FUNC
1403 */
1404 HWTEST_F(WindowSessionImplTest, NotifyAfterUnfocused, Function | SmallTest | Level2)
1405 {
1406 GTEST_LOG_(INFO) << "WindowSessionImplTest: NotifyAfterUnfocused start";
1407 sptr<WindowOption> option = new WindowOption();
1408 option->SetWindowName("NotifyAfterUnfocused");
1409 sptr<WindowSessionImpl> window = new WindowSessionImpl(option);
1410
1411 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule",
1412 "CreateTestAbility"};
1413 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1414 ASSERT_NE(nullptr, session);
1415 ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
1416
1417 int res = 0;
1418 window->NotifyAfterUnfocused(true);
1419 window->NotifyAfterUnfocused(false);
1420 ASSERT_EQ(res, 0);
1421
1422 OHOS::Ace::UIContentErrorCode aceRet = OHOS::Ace::UIContentErrorCode::NO_ERRORS;
1423 window->InitUIContent("NotifyAfterUnfocused", nullptr, nullptr, WindowSetUIContentType::DEFAULT,
1424 BackupAndRestoreType::NONE, nullptr, aceRet);
1425 window->NotifyAfterUnfocused(true);
1426 ASSERT_NE(window->GetUIContentSharedPtr(), nullptr);
1427 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
1428 GTEST_LOG_(INFO) << "WindowSessionImplTest: NotifyAfterUnfocused end";
1429 }
1430
1431 /**
1432 * @tc.name: NotifyForegroundInteractiveStatus
1433 * @tc.desc: NotifyForegroundInteractiveStatus
1434 * @tc.type: FUNC
1435 */
1436 HWTEST_F(WindowSessionImplTest, NotifyForegroundInteractiveStatus, Function | SmallTest | Level2)
1437 {
1438 GTEST_LOG_(INFO) << "WindowSessionImplTest: NotifyForegroundInteractiveStatus start";
1439 sptr<WindowOption> option = new WindowOption();
1440 ASSERT_NE(option, nullptr);
1441 option->SetWindowName("NotifyForegroundInteractiveStatus");
1442 sptr<WindowSessionImpl> window =
1443 new (std::nothrow) WindowSessionImpl(option);
1444 ASSERT_NE(window, nullptr);
1445
1446 int res = 0;
1447 window->NotifyForegroundInteractiveStatus(true);
1448 window->NotifyForegroundInteractiveStatus(false);
1449 ASSERT_EQ(res, 0);
1450
1451 GTEST_LOG_(INFO) << "WindowSessionImplTest: NotifyForegroundInteractiveStatus end";
1452 }
1453
1454 /**
1455 * @tc.name: NotifyBeforeDestroy
1456 * @tc.desc: NotifyBeforeDestroy
1457 * @tc.type: FUNC
1458 */
1459 HWTEST_F(WindowSessionImplTest, NotifyBeforeDestroy, Function | SmallTest | Level2)
1460 {
1461 GTEST_LOG_(INFO) << "WindowSessionImplTest: NotifyBeforeDestroy start";
1462 sptr<WindowOption> option = new WindowOption();
1463 option->SetWindowName("NotifyBeforeDestroy");
1464 sptr<WindowSessionImpl> window = new WindowSessionImpl(option);
1465
1466 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule",
1467 "CreateTestAbility"};
1468 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1469 ASSERT_NE(nullptr, session);
1470 ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
1471
1472 int res = 0;
1473 std::string windowName = "NotifyBeforeDestroy";
1474 window->NotifyBeforeDestroy(windowName);
1475 window->handler_ = nullptr;
1476 window->NotifyBeforeDestroy(windowName);
1477 ASSERT_EQ(res, 0);
1478
1479 // uiContent!=nullptr
1480 OHOS::Ace::UIContentErrorCode aceRet = OHOS::Ace::UIContentErrorCode::NO_ERRORS;
1481 window->InitUIContent("NotifyAfterUnfocused", nullptr, nullptr, WindowSetUIContentType::DEFAULT,
1482 BackupAndRestoreType::NONE, nullptr, aceRet);
1483 ASSERT_NE(window->uiContent_, nullptr);
1484 window->NotifyBeforeDestroy(windowName);
1485 ASSERT_EQ(window->uiContent_, nullptr);
1486
1487 // notifyNativeFunc_!=nullptr
1488 NotifyNativeWinDestroyFunc func = [&](std::string name)
__anon97316d3c0202(std::string name) 1489 {
1490 GTEST_LOG_(INFO) << "NotifyNativeWinDestroyFunc";
1491 ASSERT_EQ(windowName, name);
1492 };
1493 window->RegisterWindowDestroyedListener(func);
1494 window->NotifyBeforeDestroy(windowName);
1495
1496 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
1497 GTEST_LOG_(INFO) << "WindowSessionImplTest: NotifyBeforeDestroy end";
1498 }
1499
1500 /**
1501 * @tc.name: MarkProcessed
1502 * @tc.desc: MarkProcessed
1503 * @tc.type: FUNC
1504 */
1505 HWTEST_F(WindowSessionImplTest, MarkProcessed, Function | SmallTest | Level2)
1506 {
1507 GTEST_LOG_(INFO) << "WindowSessionImplTest: MarkProcessed start";
1508 sptr<WindowOption> option = new WindowOption();
1509 option->SetWindowName("MarkProcessed");
1510 sptr<WindowSessionImpl> window = new WindowSessionImpl(option);
1511
1512 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule",
1513 "CreateTestAbility"};
1514 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1515 ASSERT_NE(nullptr, session);
1516 ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
1517
1518 int32_t eventId = 1;
1519 window->state_ = WindowState::STATE_DESTROYED;
1520 ASSERT_EQ(window->GetPersistentId(), INVALID_SESSION_ID);
1521 ASSERT_EQ(window->state_, WindowState::STATE_DESTROYED);
1522 WSError res = window->MarkProcessed(eventId);
1523 ASSERT_EQ(res, WSError::WS_DO_NOTHING);
1524 window->hostSession_ = nullptr;
1525 res = window->MarkProcessed(eventId);
1526 ASSERT_EQ(res, WSError::WS_DO_NOTHING);
1527 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
1528 GTEST_LOG_(INFO) << "WindowSessionImplTest: MarkProcessed end";
1529 }
1530
1531 /**
1532 * @tc.name: Notify01
1533 * @tc.desc: NotifyDestroy NotifyTouchDialogTarget NotifyScreenshot
1534 * @tc.type: FUNC
1535 */
1536 HWTEST_F(WindowSessionImplTest, Notify01, Function | SmallTest | Level2)
1537 {
1538 GTEST_LOG_(INFO) << "WindowSessionImplTest: Notify01 start";
1539 sptr<WindowOption> option = new WindowOption();
1540 option->SetWindowName("Notify01");
1541 sptr<WindowSessionImpl> window = new WindowSessionImpl(option);
1542
1543 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule",
1544 "CreateTestAbility"};
1545 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1546 ASSERT_NE(nullptr, session);
1547 ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
1548
1549 window->NotifyTouchDialogTarget();
1550 window->NotifyScreenshot();
1551 WSError res = window->NotifyDestroy();
1552 ASSERT_EQ(res, WSError::WS_OK);
1553 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
1554 GTEST_LOG_(INFO) << "WindowSessionImplTest: Notify01 end";
1555 }
1556
1557 /**
1558 * @tc.name: NotifyKeyEvent
1559 * @tc.desc: NotifyKeyEvent
1560 * @tc.type: FUNC
1561 */
1562 HWTEST_F(WindowSessionImplTest, NotifyKeyEvent, Function | SmallTest | Level2)
1563 {
1564 GTEST_LOG_(INFO) << "WindowSessionImplTest: NotifyKeyEvent start";
1565 sptr<WindowOption> option = new WindowOption();
1566 option->SetWindowName("NotifyKeyEvent");
1567 sptr<WindowSessionImpl> window = new WindowSessionImpl(option);
1568
1569 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule",
1570 "CreateTestAbility"};
1571 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1572 ASSERT_NE(nullptr, session);
1573 ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
1574
1575 int res = 0;
1576 std::shared_ptr<MMI::KeyEvent> keyEvent = MMI::KeyEvent::Create();
1577 bool isConsumed = false;
1578 bool notifyInputMethod = false;
1579 keyEvent->SetKeyCode(MMI::KeyEvent::KEYCODE_VIRTUAL_MULTITASK);
1580 window->NotifyKeyEvent(keyEvent, isConsumed, notifyInputMethod);
1581
1582 keyEvent->SetKeyCode(MMI::KeyEvent::KEYCODE_BACK);
1583 window->NotifyKeyEvent(keyEvent, isConsumed, notifyInputMethod);
1584
1585 notifyInputMethod = true;
1586 window->NotifyKeyEvent(keyEvent, isConsumed, notifyInputMethod);
1587
1588 keyEvent = nullptr;
1589 window->NotifyKeyEvent(keyEvent, isConsumed, notifyInputMethod);
1590 ASSERT_EQ(res, 0);
1591 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
1592 GTEST_LOG_(INFO) << "WindowSessionImplTest: NotifyKeyEvent end";
1593 }
1594
1595 /**
1596 * @tc.name: UpdateProperty
1597 * @tc.desc: UpdateProperty
1598 * @tc.type: FUNC
1599 */
1600 HWTEST_F(WindowSessionImplTest, UpdateProperty, Function | SmallTest | Level2)
1601 {
1602 GTEST_LOG_(INFO) << "WindowSessionImplTest: UpdateProperty start";
1603 sptr<WindowOption> option = new WindowOption();
1604 option->SetWindowName("UpdateProperty");
1605 sptr<WindowSessionImpl> window = new WindowSessionImpl(option);
1606
1607 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule",
1608 "CreateTestAbility"};
1609 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1610 ASSERT_NE(nullptr, session);
1611 ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
1612
1613 WMError res = window->UpdateProperty(WSPropertyChangeAction::ACTION_UPDATE_RECT);
1614 ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW);
1615 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
1616 // session is null
1617 window = new WindowSessionImpl(option);
1618 ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, nullptr));
1619 res = window->UpdateProperty(WSPropertyChangeAction::ACTION_UPDATE_RECT);
1620 ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW);
1621 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
1622 GTEST_LOG_(INFO) << "WindowSessionImplTest: UpdateProperty end";
1623 }
1624
1625 /**
1626 * @tc.name: Find
1627 * @tc.desc: Find
1628 * @tc.type: FUNC
1629 */
1630 HWTEST_F(WindowSessionImplTest, Find, Function | SmallTest | Level2)
1631 {
1632 GTEST_LOG_(INFO) << "WindowSessionImplTest: Find start";
1633 sptr<WindowOption> option = new WindowOption();
1634 option->SetWindowName("Find");
1635 sptr<WindowSessionImpl> window = new WindowSessionImpl(option);
1636
1637 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule",
1638 "CreateTestAbility"};
1639 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1640 ASSERT_NE(nullptr, session);
1641 ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
1642
1643 std::string name = "Find";
1644 sptr<Window> res = window->Find(name);
1645 ASSERT_EQ(res, nullptr);
1646
1647 name = "111";
1648 res = window->Find(name);
1649 ASSERT_EQ(res, nullptr);
1650 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
1651 GTEST_LOG_(INFO) << "WindowSessionImplTest: Find end";
1652 }
1653
1654 /**
1655 * @tc.name: SetBackgroundColor01
1656 * @tc.desc: SetBackgroundColor string
1657 * @tc.type: FUNC
1658 */
1659 HWTEST_F(WindowSessionImplTest, SetBackgroundColor01, Function | SmallTest | Level2)
1660 {
1661 GTEST_LOG_(INFO) << "WindowSessionImplTest: SetBackgroundColor01 start";
1662 sptr<WindowOption> option = new WindowOption();
1663 option->SetWindowName("SetBackgroundColor01");
1664 sptr<WindowSessionImpl> window = new WindowSessionImpl(option);
1665
1666 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule",
1667 "CreateTestAbility"};
1668 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1669 ASSERT_NE(nullptr, session);
1670 ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session));
1671
1672 std::string color = "Blue";
1673 WMError res = window->SetBackgroundColor(color);
1674 ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW);
1675
1676 color = "111";
1677 res = window->SetBackgroundColor(color);
1678 ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW);
1679 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
1680 // session is null
1681 window = new WindowSessionImpl(option);
1682 ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, nullptr));
1683 res = window->SetBackgroundColor(color);
1684 ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW);
1685 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
1686 GTEST_LOG_(INFO) << "WindowSessionImplTest: SetBackgroundColor01 end";
1687 }
1688
1689 /**
1690 * @tc.name: SetBackgroundColor02
1691 * @tc.desc: SetBackgroundColor(uint32_t) and GetBackgroundColor
1692 * @tc.type: FUNC
1693 */
1694 HWTEST_F(WindowSessionImplTest, SetBackgroundColor02, Function | SmallTest | Level2)
1695 {
1696 GTEST_LOG_(INFO) << "WindowSessionImplTest: SetBackgroundColor02 start";
1697 sptr<WindowOption> option = new WindowOption();
1698 option->SetWindowName("SetBackgroundColor02");
1699 sptr<WindowSessionImpl> window = new WindowSessionImpl(option);
1700
1701 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule",
1702 "CreateTestAbility"};
1703 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1704 ASSERT_NE(nullptr, session);
1705 ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
1706
1707 WMError res = window->SetBackgroundColor(0xffffffff);
1708 ASSERT_EQ(res, WMError::WM_ERROR_INVALID_OPERATION);
1709 uint32_t ret = window->GetBackgroundColor();
1710 ASSERT_EQ(ret, 0xffffffff);
1711 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
1712 GTEST_LOG_(INFO) << "WindowSessionImplTest: SetBackgroundColor02 end";
1713 }
1714
1715 /**
1716 * @tc.name: SetAPPWindowIcon
1717 * @tc.desc: SetAPPWindowIcon
1718 * @tc.type: FUNC
1719 */
1720 HWTEST_F(WindowSessionImplTest, SetAPPWindowIcon, Function | SmallTest | Level2)
1721 {
1722 GTEST_LOG_(INFO) << "WindowSessionImplTest: SetAPPWindowIcon start";
1723 sptr<WindowOption> option = new WindowOption();
1724 option->SetWindowName("SetAPPWindowIcon");
1725 sptr<WindowSessionImpl> window = new WindowSessionImpl(option);
1726
1727 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule",
1728 "CreateTestAbility"};
1729 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1730 ASSERT_NE(nullptr, session);
1731 ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
1732 std::shared_ptr<Media::PixelMap> icon1(nullptr);
1733 WMError res = window->SetAPPWindowIcon(icon1);
1734 ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
1735
1736 std::shared_ptr<Media::PixelMap> icon2 = std::shared_ptr<Media::PixelMap>();
1737 res = window->SetAPPWindowIcon(icon2);
1738 ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
1739
1740 Media::InitializationOptions opts;
1741 opts.size.width = 200; // 200: test width
1742 opts.size.height = 300; // 300: test height
1743 opts.pixelFormat = Media::PixelFormat::ARGB_8888;
1744 opts.alphaType = Media::AlphaType::IMAGE_ALPHA_TYPE_OPAQUE;
1745 std::unique_ptr<Media::PixelMap> pixelMapPtr = Media::PixelMap::Create(opts);
1746 ASSERT_NE(pixelMapPtr.get(), nullptr);
1747 window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
1748 res = window->SetAPPWindowIcon(std::shared_ptr<Media::PixelMap>(pixelMapPtr.release()));
1749 ASSERT_EQ(res, WMError::WM_OK);
1750 ASSERT_NE(window->GetUIContentSharedPtr(), nullptr);
1751 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
1752 GTEST_LOG_(INFO) << "WindowSessionImplTest: SetAPPWindowIcon end";
1753 }
1754
1755 /**
1756 * @tc.name: Notify02
1757 * @tc.desc: NotifyAvoidAreaChange NotifyPointerEvent NotifyTouchOutside NotifyWindowVisibility
1758 * @tc.type: FUNC
1759 */
1760 HWTEST_F(WindowSessionImplTest, Notify02, Function | SmallTest | Level2)
1761 {
1762 GTEST_LOG_(INFO) << "WindowSessionImplTest: Notify02 start";
1763 sptr<WindowOption> option = new WindowOption();
1764 option->SetWindowName("Notify02");
1765 sptr<WindowSessionImpl> window = new WindowSessionImpl(option);
1766
1767 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule",
1768 "CreateTestAbility"};
1769 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1770 ASSERT_NE(nullptr, session);
1771 ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
1772
1773 sptr<AvoidArea> avoidArea = new AvoidArea();
1774 avoidArea->topRect_ = { 1, 0, 0, 0 };
1775 avoidArea->leftRect_ = { 0, 1, 0, 0 };
1776 avoidArea->rightRect_ = { 0, 0, 1, 0 };
1777 avoidArea->bottomRect_ = { 0, 0, 0, 1 };
1778 AvoidAreaType type = AvoidAreaType::TYPE_SYSTEM;
1779 window->NotifyAvoidAreaChange(avoidArea, type);
1780
1781 std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
1782 window->NotifyPointerEvent(pointerEvent);
1783 WSError res = window->NotifyTouchOutside();
1784 ASSERT_EQ(res, WSError::WS_OK);
1785
1786 res = window->NotifyWindowVisibility(true);
1787 ASSERT_EQ(res, WSError::WS_OK);
1788 bool terminateCloseProcess = false;
1789 window->NotifySubWindowClose(terminateCloseProcess);
1790 ASSERT_EQ(terminateCloseProcess, false);
1791
1792 bool enable = false;
1793 window->NotifySwitchFreeMultiWindow(enable);
1794
1795 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
1796 GTEST_LOG_(INFO) << "WindowSessionImplTest: Notify02 end";
1797 }
1798
1799 /**
1800 * @tc.name: SetAceAbilityHandler
1801 * @tc.desc: SetAceAbilityHandler
1802 * @tc.type: FUNC
1803 */
1804 HWTEST_F(WindowSessionImplTest, SetAceAbilityHandler, Function | SmallTest | Level2)
1805 {
1806 GTEST_LOG_(INFO) << "WindowSessionImplTest: SetAceAbilityHandler start";
1807 sptr<WindowOption> option = new WindowOption();
1808 option->SetWindowName("SetAceAbilityHandler");
1809 sptr<WindowSessionImpl> window = new WindowSessionImpl(option);
1810
1811 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule",
1812 "CreateTestAbility"};
1813 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1814 ASSERT_NE(nullptr, session);
1815 ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
1816
1817 int res = 0;
1818 sptr<IAceAbilityHandler> handler = sptr<IAceAbilityHandler>();
1819 ASSERT_EQ(handler, nullptr);
1820 GTEST_LOG_(INFO) << "WindowSessionImplTest: SetAceAbilityHandler 111";
1821 window->SetAceAbilityHandler(handler);
1822 ASSERT_EQ(res, 0);
1823 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
1824 GTEST_LOG_(INFO) << "WindowSessionImplTest: SetAceAbilityHandler end";
1825 }
1826
1827 /**
1828 * @tc.name: SetRaiseByClickEnabled01
1829 * @tc.desc: SetRaiseByClickEnabled and check the retCode
1830 * @tc.type: FUNC
1831 */
1832 HWTEST_F(WindowSessionImplTest, SetRaiseByClickEnabled01, Function | SmallTest | Level2)
1833 {
1834 sptr<WindowOption> option = new WindowOption();
1835 option->SetWindowName("SetRaiseByClickEnabled01");
1836 option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1837 sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
1838 ASSERT_NE(nullptr, window);
1839
1840 WMError retCode = window->SetRaiseByClickEnabled(true);
1841 ASSERT_EQ(retCode, WMError::WM_ERROR_INVALID_PARENT);
1842
1843 option->SetWindowName("SetRaiseByClickForFloatWindow");
1844 option->SetWindowType(WindowType::WINDOW_TYPE_FLOAT);
1845 sptr<WindowSessionImpl> floatWindow = new (std::nothrow) WindowSessionImpl(option);
1846 floatWindow->property_->SetParentPersistentId(1);
1847 ASSERT_NE(nullptr, floatWindow);
1848
1849 retCode = floatWindow->SetRaiseByClickEnabled(true);
1850 ASSERT_EQ(retCode, WMError::WM_ERROR_INVALID_CALLING);
1851
1852 option->SetWindowName("SetRaiseByClickForSubWindow");
1853 option->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
1854 sptr<WindowSessionImpl> subWindow = new (std::nothrow) WindowSessionImpl(option);
1855 ASSERT_NE(nullptr, subWindow);
1856
1857 subWindow->property_->SetParentPersistentId(1);
1858 subWindow->Hide();
1859 retCode = subWindow->SetRaiseByClickEnabled(true);
1860 ASSERT_EQ(retCode, WMError::WM_DO_NOTHING);
1861
1862 subWindow->state_ = WindowState::STATE_SHOWN;
1863 retCode = subWindow->SetRaiseByClickEnabled(true);
1864 ASSERT_EQ(retCode, WMError::WM_ERROR_INVALID_WINDOW);
1865
1866 subWindow->property_->SetParentPersistentId(2);
1867 subWindow->SetRaiseByClickEnabled(true);
1868 ASSERT_EQ(subWindow->property_->GetRaiseEnabled(), true);
1869 }
1870
1871 /**
1872 * @tc.name: HideNonSystemFloatingWindows01
1873 * @tc.desc: HideNonSystemFloatingWindows and check the retCode
1874 * @tc.type: FUNC
1875 */
1876 HWTEST_F(WindowSessionImplTest, HideNonSystemFloatingWindows01, Function | SmallTest | Level2)
1877 {
1878 sptr<WindowOption> option = new WindowOption();
1879 option->SetWindowName("HideNonSystemFloatingWindows01");
1880 sptr<WindowSessionImpl> window = new(std::nothrow) WindowSessionImpl(option);
1881 ASSERT_NE(nullptr, window);
1882 WMError retCode = window->HideNonSystemFloatingWindows(false);
1883 ASSERT_EQ(retCode, WMError::WM_ERROR_INVALID_WINDOW);
1884 window->property_->SetPersistentId(1);
1885 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1886 sptr<SessionMocker> session = new(std::nothrow) SessionMocker(sessionInfo);
1887 ASSERT_NE(nullptr, session);
1888 window->hostSession_ = session;
1889 window->state_ = WindowState::STATE_CREATED;
1890 window->HideNonSystemFloatingWindows(false);
1891 }
1892
1893 /**
1894 * @tc.name: UpdateWindowModetest01
1895 * @tc.desc: UpdateWindowMode
1896 * @tc.type: FUNC
1897 */
1898 HWTEST_F(WindowSessionImplTest, UpdateWindowMode, Function | SmallTest | Level2)
1899 {
1900 GTEST_LOG_(INFO) << "WindowSessionImplTest: UpdateWindowModetest01 start";
1901 sptr<WindowOption> option = new WindowOption();
1902 ASSERT_NE(option, nullptr);
1903 option->SetWindowName("UpdateWindowMode");
1904 sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
1905 ASSERT_NE(window, nullptr);
1906 WindowMode mode = WindowMode{0};
1907 auto ret = window->UpdateWindowMode(mode);
1908 ASSERT_EQ(ret, WSError::WS_OK);
1909 GTEST_LOG_(INFO) << "WindowSessionImplTest: UpdateWindowModetest01 end";
1910 }
1911
1912 /**
1913 * @tc.name: UpdateDensitytest01
1914 * @tc.desc: UpdateDensity
1915 * @tc.type: FUNC
1916 */
1917 HWTEST_F(WindowSessionImplTest, UpdateDensity, Function | SmallTest | Level2)
1918 {
1919 GTEST_LOG_(INFO) << "WindowSessionImplTest: UpdateDensitytest01 start";
1920 sptr<WindowOption> option = new WindowOption();
1921 ASSERT_NE(option, nullptr);
1922 option->SetWindowName("UpdateDensity");
1923 sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
1924 ASSERT_NE(window, nullptr);
1925 int ret = 0;
1926 window->UpdateDensity();
1927 ASSERT_EQ(ret, 0);
1928 GTEST_LOG_(INFO) << "WindowSessionImplTest: UpdateDensitytest01 end";
1929 }
1930
1931 /**
1932 * @tc.name: UpdateDisplayIdtest01
1933 * @tc.desc: UpdateDisplayId
1934 * @tc.type: FUNC
1935 */
1936 HWTEST_F(WindowSessionImplTest, UpdateDisplayId, Function | SmallTest | Level2)
1937 {
1938 GTEST_LOG_(INFO) << "WindowSessionImplTest: UpdateDisplayIdtest01 start";
1939 sptr<WindowOption> option = new WindowOption();
1940 ASSERT_NE(option, nullptr);
1941 option->SetWindowName("UpdateDisplayId");
1942 sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
1943 ASSERT_NE(window, nullptr);
1944 uint64_t newDisplayId = 2;
1945 auto ret = window->UpdateDisplayId(newDisplayId);
1946 ASSERT_EQ(ret, WSError::WS_OK);
1947 uint64_t displayId = window->property_->GetDisplayId();
1948 ASSERT_EQ(newDisplayId, displayId);
1949 GTEST_LOG_(INFO) << "WindowSessionImplTest: UpdateDisplayIdtest01 end";
1950 }
1951
1952 /**
1953 * @tc.name: IsFloatingWindowAppTypetest01
1954 * @tc.desc: IsFloatingWindowAppType
1955 * @tc.type: FUNC
1956 */
1957 HWTEST_F(WindowSessionImplTest, IsFloatingWindowAppType, Function | SmallTest | Level2)
1958 {
1959 GTEST_LOG_(INFO) << "WindowSessionImplTest: IsFloatingWindowAppTypetest01 start";
1960 sptr<WindowOption> option = new WindowOption();
1961 ASSERT_NE(option, nullptr);
1962 option->SetWindowName("IsFloatingWindowAppType");
1963 sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
1964 ASSERT_NE(window, nullptr);
1965 window->IsFloatingWindowAppType();
1966 ASSERT_NE(window, nullptr);
1967 GTEST_LOG_(INFO) << "WindowSessionImplTest: IsFloatingWindowAppTypetest01 end";
1968 }
1969
1970 /**
1971 * @tc.name: SetUniqueVirtualPixelRatio
1972 * @tc.desc: SetUniqueVirtualPixelRatio
1973 * @tc.type: FUNC
1974 */
1975 HWTEST_F(WindowSessionImplTest, SetUniqueVirtualPixelRatio, Function | SmallTest | Level2)
1976 {
1977 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1978 ASSERT_NE(option, nullptr);
1979 option->SetWindowName("SetUniqueVirtualPixelRatio");
1980 sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
1981 ASSERT_NE(window, nullptr);
1982 window->SetUniqueVirtualPixelRatio(true, 3.25f);
1983 window->SetUniqueVirtualPixelRatio(false, 3.25f);
1984 }
1985
1986 /**
1987 * @tc.name: GetUIContentRemoteObj
1988 * @tc.desc: GetUIContentRemoteObj and check the retCode
1989 * @tc.type: FUNC
1990 */
1991 HWTEST_F(WindowSessionImplTest, GetUIContentRemoteObj, Function | SmallTest | Level2)
1992 {
1993 GTEST_LOG_(INFO) << "WindowSessionImplTest: GetUIContentRemoteObj start";
1994 sptr<WindowOption> option = new WindowOption();
1995 ASSERT_NE(option, nullptr);
1996 sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
1997 ASSERT_NE(window, nullptr);
1998 sptr<IRemoteObject> remoteObj;
1999 WSError res = window->GetUIContentRemoteObj(remoteObj);
2000 ASSERT_EQ(res, WSError::WS_ERROR_NULLPTR);
2001 window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
2002 res = window->GetUIContentRemoteObj(remoteObj);
2003 ASSERT_EQ(res, WSError::WS_OK);
2004 GTEST_LOG_(INFO) << "WindowSessionImplTest: GetUIContentRemoteObj end";
2005 }
2006
2007 /**
2008 * @tc.name: SetUiDvsyncSwitchSucc
2009 * @tc.desc: SetUiDvsyncSwitch Test Succ
2010 * @tc.type: FUNC
2011 */
2012 HWTEST_F(WindowSessionImplTest, SetUiDvsyncSwitchSucc, Function | SmallTest | Level2)
2013 {
2014 sptr<WindowOption> option = new (std::nothrow) WindowOption();
2015 option->SetWindowName("SetUiDvsyncSwitchSucc");
2016 sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
2017 ASSERT_NE(window, nullptr);
2018 window->SetUiDvsyncSwitch(true);
2019 window->SetUiDvsyncSwitch(false);
2020 }
2021
2022 /**
2023 * @tc.name: EnableDrag
2024 * @tc.desc: EnableDrag Test
2025 * @tc.type: FUNC
2026 */
2027 HWTEST_F(WindowSessionImplTest, EnableDrag, Function | SmallTest | Level2)
2028 {
2029 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
2030 option->SetWindowName("EnableDrag");
2031 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
2032 window->property_->SetPersistentId(2101);
2033 window->property_->SetWindowType(WindowType::WINDOW_TYPE_GLOBAL_SEARCH);
2034 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
2035 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
2036 window->hostSession_ = session;
2037
2038 window->windowSystemConfig_.uiType_ = UI_TYPE_PHONE;
2039 auto result = window->EnableDrag(true);
2040 ASSERT_EQ(result, WMError::WM_ERROR_DEVICE_NOT_SUPPORT);
2041
2042 window->windowSystemConfig_.uiType_ = UI_TYPE_PC;
2043 result = window->EnableDrag(true);
2044 ASSERT_NE(result, WMError::WM_ERROR_DEVICE_NOT_SUPPORT);
2045
2046 window->windowSystemConfig_.uiType_ = UI_TYPE_PAD;
2047 window->windowSystemConfig_.freeMultiWindowEnable_ = true;
2048 window->windowSystemConfig_.freeMultiWindowSupport_ = true;
2049 result = window->EnableDrag(true);
2050 ASSERT_NE(result, WMError::WM_ERROR_DEVICE_NOT_SUPPORT);
2051 }
2052
2053 /**
2054 * @tc.name: SetUiDvsyncSwitchErr
2055 * @tc.desc: SetUiDvsyncSwitch Test Err
2056 * @tc.type: FUNC
2057 */
2058 HWTEST_F(WindowSessionImplTest, SetUiDvsyncSwitchErr, Function | SmallTest | Level2)
2059 {
2060 sptr<WindowOption> option = new (std::nothrow) WindowOption();
2061 option->SetWindowName("SetUiDvsyncSwitchErr");
2062 sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
2063 ASSERT_NE(window, nullptr);
2064 window->vsyncStation_ = nullptr;
2065 window->SetUiDvsyncSwitch(true);
2066 window->SetUiDvsyncSwitch(false);
2067 }
2068
2069 /**
2070 * @tc.name: AddSetUIContentTimeoutCheck
2071 * @tc.desc: AddSetUIContentTimeoutCheck
2072 * @tc.type: FUNC
2073 */
2074 HWTEST_F(WindowSessionImplTest, AddSetUIContentTimeoutCheck_test, Function | SmallTest | Level2)
2075 {
2076 sptr<WindowOption> option = new (std::nothrow) WindowOption();
2077 ASSERT_NE(option, nullptr);
2078 sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
2079 ASSERT_NE(window, nullptr);
2080 option->SetWindowName("AddSetUIContentTimeoutCheck_test");
2081 option->SetBundleName("UTtest");
2082 WindowType type1 = WindowType::APP_MAIN_WINDOW_BASE;
2083 option->SetWindowType(type1);
2084 sptr<WindowSessionImpl> window1 = new (std::nothrow) WindowSessionImpl(option);
2085 ASSERT_NE(window1, nullptr);
2086 window1->AddSetUIContentTimeoutCheck();
2087
2088 WindowType type2 = WindowType::WINDOW_TYPE_UI_EXTENSION;
2089 option->SetWindowType(type2);
2090 sptr<WindowSessionImpl> window2 = new (std::nothrow) WindowSessionImpl(option);
2091 ASSERT_NE(window2, nullptr);
2092 window2->AddSetUIContentTimeoutCheck();
2093 }
2094
2095 /**
2096 * @tc.name: FindMainWindowWithContext01
2097 * @tc.desc: FindMainWindowWithContext
2098 * @tc.type: FUNC
2099 */
2100 HWTEST_F(WindowSessionImplTest, FindMainWindowWithContext01, Function | SmallTest | Level2)
2101 {
2102 sptr<WindowOption> option = new (std::nothrow) WindowOption();
2103 option->SetWindowTag(WindowTag::MAIN_WINDOW);
2104 option->SetWindowName("FindMainWindowWithContext01");
2105 sptr<WindowSessionImpl> windowSession = new (std::nothrow) WindowSessionImpl(option);
2106 ASSERT_NE(nullptr, windowSession);
2107
2108 windowSession->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
2109 ASSERT_TRUE(windowSession->FindMainWindowWithContext() == nullptr);
2110 windowSession->SetWindowType(WindowType::ABOVE_APP_SYSTEM_WINDOW_END);
2111 ASSERT_TRUE(windowSession->FindMainWindowWithContext() == nullptr);
2112
2113 windowSession->property_->SetPersistentId(1002);
2114 windowSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
2115 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
2116 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
2117 ASSERT_NE(nullptr, session);
2118 ASSERT_EQ(WMError::WM_OK, windowSession->Create(abilityContext_, session));
2119 windowSession->Destroy(true);
2120 }
2121
2122 /**
2123 * @tc.name: FindExtensionWindowWithContext01
2124 * @tc.desc: FindExtensionWindowWithContext
2125 * @tc.type: FUNC
2126 */
2127 HWTEST_F(WindowSessionImplTest, FindExtensionWindowWithContext01, Function | SmallTest | Level2)
2128 {
2129 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
2130 option->SetWindowName("FindExtensionWindowWithContext01");
2131 sptr<WindowSessionImpl> windowSession = sptr<WindowSessionImpl>::MakeSptr(option);
2132
2133 ASSERT_TRUE(windowSession->FindExtensionWindowWithContext() == nullptr);
2134
2135 windowSession->property_->SetPersistentId(12345);
2136 windowSession->property_->SetWindowType(WindowType::WINDOW_TYPE_UI_EXTENSION);
2137 windowSession->context_ = abilityContext_;
2138 WindowSessionImpl::windowExtensionSessionSet_.insert(windowSession);
2139 ASSERT_TRUE(nullptr != windowSession->FindExtensionWindowWithContext());
2140 windowSession->Destroy(true);
2141 }
2142
2143 /**
2144 * @tc.name: SetUIContentComplete
2145 * @tc.desc: SetUIContentComplete
2146 * @tc.type: FUNC
2147 */
2148 HWTEST_F(WindowSessionImplTest, SetUIContentComplete, Function | SmallTest | Level2)
2149 {
2150 sptr<WindowOption> option = new (std::nothrow) WindowOption();
2151 ASSERT_NE(option, nullptr);
2152 sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
2153 ASSERT_NE(window, nullptr);
2154 window->SetUIContentComplete();
2155 EXPECT_EQ(window->setUIContentCompleted_.load(), true);
2156
2157 window->SetUIContentComplete();
2158 EXPECT_EQ(window->setUIContentCompleted_.load(), true);
2159 }
2160
2161 /**
2162 * @tc.name: NotifySetUIContentComplete
2163 * @tc.desc: NotifySetUIContentComplete
2164 * @tc.type: FUNC
2165 */
2166 HWTEST_F(WindowSessionImplTest, NotifySetUIContentComplete, Function | SmallTest | Level2)
2167 {
2168 sptr<WindowOption> option = new (std::nothrow) WindowOption();
2169 ASSERT_NE(nullptr, option);
2170 option->SetWindowName("NotifySetUIContent");
2171 option->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
2172 sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
2173 ASSERT_NE(nullptr, window);
2174 window->NotifySetUIContentComplete();
2175 EXPECT_EQ(window->setUIContentCompleted_.load(), true);
2176
2177 option->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
2178 window = new (std::nothrow) WindowSessionImpl(option);
2179 ASSERT_NE(nullptr, window);
2180 window->NotifySetUIContentComplete();
2181 EXPECT_EQ(window->setUIContentCompleted_.load(), true);
2182
2183 option->SetWindowType(WindowType::SYSTEM_WINDOW_BASE);
2184 window = new (std::nothrow) WindowSessionImpl(option);
2185 ASSERT_NE(nullptr, window);
2186 window->NotifySetUIContentComplete();
2187 EXPECT_EQ(window->setUIContentCompleted_.load(), true);
2188 }
2189
2190 /**
2191 * @tc.name: SetUIExtensionDestroyComplete
2192 * @tc.desc: SetUIExtensionDestroyComplete
2193 * @tc.type: FUNC
2194 */
2195 HWTEST_F(WindowSessionImplTest, SetUIExtensionDestroyComplete, Function | SmallTest | Level2)
2196 {
2197 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
2198 ASSERT_NE(option, nullptr);
2199 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
2200 ASSERT_NE(window, nullptr);
2201 window->SetUIExtensionDestroyComplete();
2202 EXPECT_EQ(window->setUIExtensionDestroyCompleted_.load(), true);
2203 window->SetUIExtensionDestroyComplete();
2204 EXPECT_EQ(window->setUIExtensionDestroyCompleted_.load(), true);
2205 }
2206
2207 /**
2208 * @tc.name: SetUIExtensionDestroyCompleteInSubWindow
2209 * @tc.desc: SetUIExtensionDestroyCompleteInSubWindow
2210 * @tc.type: FUNC
2211 */
2212 HWTEST_F(WindowSessionImplTest, SetUIExtensionDestroyCompleteInSubWindow, Function | SmallTest | Level2)
2213 {
2214 sptr<WindowOption> subWindowOption = sptr<WindowOption>::MakeSptr();
2215 ASSERT_NE(subWindowOption, nullptr);
2216 subWindowOption->SetWindowName("subWindow");
2217 sptr<WindowSessionImpl> subWindowSession = sptr<WindowSessionImpl>::MakeSptr(subWindowOption);
2218 ASSERT_NE(subWindowSession, nullptr);
2219 subWindowSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
2220 subWindowSession->context_ = abilityContext_;
2221 subWindowSession->SetUIExtensionDestroyCompleteInSubWindow();
2222
2223 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
2224 ASSERT_NE(option, nullptr);
2225 option->SetWindowName("SetUIExtensionDestroyCompleteInSubWindow");
2226 sptr<WindowSessionImpl> windowSession = sptr<WindowSessionImpl>::MakeSptr(option);
2227 ASSERT_NE(windowSession, nullptr);
2228 ASSERT_TRUE(windowSession->FindExtensionWindowWithContext() == nullptr);
2229 windowSession->property_->SetPersistentId(12345);
2230 windowSession->property_->SetWindowType(WindowType::WINDOW_TYPE_UI_EXTENSION);
2231 windowSession->context_ = abilityContext_;
2232 WindowSessionImpl::windowExtensionSessionSet_.insert(windowSession);
2233 ASSERT_TRUE(nullptr != windowSession->FindExtensionWindowWithContext());
2234 windowSession->AddSetUIExtensionDestroyTimeoutCheck();
2235 EXPECT_EQ(windowSession->startUIExtensionDestroyTimer_.load(), true);
2236 subWindowSession->SetUIExtensionDestroyCompleteInSubWindow();
2237 EXPECT_EQ(windowSession->startUIExtensionDestroyTimer_.load(), false);
2238 }
2239
2240 /**
2241 * @tc.name: AddSetUIExtensionDestroyTimeoutCheck
2242 * @tc.desc: AddSetUIExtensionDestroyTimeoutCheck
2243 * @tc.type: FUNC
2244 */
2245 HWTEST_F(WindowSessionImplTest, AddSetUIExtensionDestroyTimeoutCheck, Function | SmallTest | Level2)
2246 {
2247 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
2248 ASSERT_NE(option, nullptr);
2249 option->SetWindowName("AddSetUIExtensionDestroyTimeoutCheck");
2250 option->SetBundleName("UTtest");
2251 option->SetWindowType(WindowType::WINDOW_TYPE_UI_EXTENSION);
2252 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
2253 ASSERT_NE(window, nullptr);
2254 window->AddSetUIExtensionDestroyTimeoutCheck();
2255 EXPECT_EQ(WindowType::WINDOW_TYPE_UI_EXTENSION, window->property_->GetWindowType());
2256 EXPECT_EQ(window->startUIExtensionDestroyTimer_.load(), true);
2257 }
2258 }
2259 } // namespace Rosen
2260 } // namespace OHOS
2261