1 /*
2 * Copyright (c) 2024 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 "color_parser.h"
22 #include "mock_session.h"
23 #include "window_helper.h"
24 #include "window_session_impl.h"
25 #include "wm_common.h"
26 #include "mock_uicontent.h"
27 #include "mock_window.h"
28 #include "parameters.h"
29 #include "scene_board_judgement.h"
30
31 using namespace testing;
32 using namespace testing::ext;
33
34 namespace OHOS {
35 namespace Rosen {
36 class WindowSessionImplTest4 : public testing::Test {
37 public:
38 static void SetUpTestCase();
39 static void TearDownTestCase();
40 void SetUp() override;
41 void TearDown() override;
42
43 std::shared_ptr<AbilityRuntime::AbilityContext> abilityContext_;
44 private:
45 static constexpr uint32_t WAIT_SYNC_IN_NS = 50000;
46 };
47
SetUpTestCase()48 void WindowSessionImplTest4::SetUpTestCase()
49 {
50 }
51
TearDownTestCase()52 void WindowSessionImplTest4::TearDownTestCase()
53 {
54 }
55
SetUp()56 void WindowSessionImplTest4::SetUp()
57 {
58 abilityContext_ = std::make_shared<AbilityRuntime::AbilityContextImpl>();
59 }
60
TearDown()61 void WindowSessionImplTest4::TearDown()
62 {
63 usleep(WAIT_SYNC_IN_NS);
64 abilityContext_ = nullptr;
65 }
66
67 namespace {
68 /**
69 * @tc.name: GetRequestWindowStatetest01
70 * @tc.desc: GetRequestWindowState
71 * @tc.type: FUNC
72 */
73 HWTEST_F(WindowSessionImplTest4, GetRequestWindowState, Function | SmallTest | Level2)
74 {
75 GTEST_LOG_(INFO) << "WindowSessionImplTest4: GetRequestWindowStatetest01 start";
76 sptr<WindowOption> option = new WindowOption();
77 ASSERT_NE(option, nullptr);
78 option->SetWindowName("GetRequestWindowState");
79 sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
80 ASSERT_NE(window, nullptr);
81 auto ret = window->GetRequestWindowState();
82 ASSERT_EQ(ret, WindowState::STATE_INITIAL);
83 GTEST_LOG_(INFO) << "WindowSessionImplTest4: GetRequestWindowStatetest01 end";
84 }
85
86 /**
87 * @tc.name: GetFocusabletest01
88 * @tc.desc: GetFocusable
89 * @tc.type: FUNC
90 */
91 HWTEST_F(WindowSessionImplTest4, GetFocusable, Function | SmallTest | Level2)
92 {
93 GTEST_LOG_(INFO) << "WindowSessionImplTest4: GetFocusabletest01 start";
94 sptr<WindowOption> option = new WindowOption();
95 ASSERT_NE(option, nullptr);
96 option->SetWindowName("GetFocusable");
97 sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
98 ASSERT_NE(window, nullptr);
99 bool ret = window->GetFocusable();
100 ASSERT_EQ(ret, true);
101 GTEST_LOG_(INFO) << "WindowSessionImplTest4: GetFocusabletest01 end";
102 }
103
104
105 /**
106 * @tc.name: TransferAccessibilityEvent
107 * @tc.desc: TransferAccessibilityEvent
108 * @tc.type: FUNC
109 */
110 HWTEST_F(WindowSessionImplTest4, TransferAccessibilityEvent, Function | SmallTest | Level2)
111 {
112 GTEST_LOG_(INFO) << "WindowSessionImplTest4: TransferAccessibilityEvent start";
113 sptr<WindowOption> option = new WindowOption();
114 ASSERT_NE(option, nullptr);
115 sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
116 ASSERT_NE(window, nullptr);
117 Accessibility::AccessibilityEventInfo info;
118 int64_t uiExtensionIdLevel = 0;
119 ASSERT_EQ(WMError::WM_OK, window->TransferAccessibilityEvent(info, uiExtensionIdLevel));
120 GTEST_LOG_(INFO) << "WindowSessionImplTest4: TransferAccessibilityEvent end";
121 }
122
123 /**
124 * @tc.name: SetSingleFrameComposerEnabled01
125 * @tc.desc: SetSingleFrameComposerEnabled and check the retCode
126 * @tc.type: FUNC
127 */
128 HWTEST_F(WindowSessionImplTest4, SetSingleFrameComposerEnabled01, Function | SmallTest | Level2)
129 {
130 sptr<WindowOption> option = new WindowOption();
131 option->SetWindowName("SetSingleFrameComposerEnabled01");
132 sptr<WindowSessionImpl> window = new(std::nothrow) WindowSessionImpl(option);
133 ASSERT_NE(nullptr, window);
134 WMError retCode = window->SetSingleFrameComposerEnabled(false);
135 ASSERT_EQ(retCode, WMError::WM_ERROR_INVALID_WINDOW);
136 window->property_->SetPersistentId(1);
137 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
138 sptr<SessionMocker> session = new(std::nothrow) SessionMocker(sessionInfo);
139 ASSERT_NE(nullptr, session);
140 window->hostSession_ = session;
141 window->state_ = WindowState::STATE_CREATED;
142 retCode = window->SetSingleFrameComposerEnabled(false);
143 ASSERT_EQ(retCode, WMError::WM_OK);
144
145 window->surfaceNode_ = nullptr;
146 retCode = window->SetSingleFrameComposerEnabled(false);
147 ASSERT_EQ(retCode, WMError::WM_ERROR_INVALID_WINDOW);
148 }
149
150 /**
151 * @tc.name: SetTopmost
152 * @tc.desc: SetTopmost
153 * @tc.type: FUNC
154 */
155 HWTEST_F(WindowSessionImplTest4, SetTopmost, Function | SmallTest | Level2)
156 {
157 sptr<WindowOption> option = new WindowOption();
158 option->SetWindowName("SetTopmost");
159 sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
160 ASSERT_NE(nullptr, window);
161 window->windowSystemConfig_.uiType_ = "phone";
162 WMError res = window->SetTopmost(true);
163 ASSERT_EQ(WMError::WM_ERROR_DEVICE_NOT_SUPPORT, res);
164 window->windowSystemConfig_.uiType_ = "pc";
165 res = window->SetTopmost(true);
166 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, res);
167
168 window->property_->SetPersistentId(1);
169 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
170 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
171 ASSERT_NE(nullptr, session);
172 window->hostSession_ = session;
173 window->state_ = WindowState::STATE_CREATED;
174 res = window->SetTopmost(true);
175 ASSERT_EQ(WMError::WM_OK, res);
176 }
177
178 /**
179 * @tc.name: IsTopmost
180 * @tc.desc: IsTopmost
181 * @tc.type: FUNC
182 */
183 HWTEST_F(WindowSessionImplTest4, IsTopmost, Function | SmallTest | Level2)
184 {
185 sptr<WindowOption> option = new WindowOption();
186 option->SetWindowName("IsTopmost");
187 sptr<WindowSessionImpl> window = new WindowSessionImpl(option);
188 ASSERT_NE(window, nullptr);
189 bool res = window->IsTopmost();
190 ASSERT_FALSE(res);
191 }
192
193 /**
194 * @tc.name: SetDecorVisible
195 * @tc.desc: SetDecorVisible and check the retCode
196 * @tc.type: FUNC
197 */
198 HWTEST_F(WindowSessionImplTest4, SetDecorVisible, Function | SmallTest | Level2)
199 {
200 GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetDecorVisibletest01 start";
201 sptr<WindowOption> option = new WindowOption();
202 ASSERT_NE(option, nullptr);
203 option->SetWindowName("SetDecorVisible");
204 sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
205 ASSERT_NE(window, nullptr);
206 ASSERT_NE(window->property_, nullptr);
207 window->property_->SetPersistentId(1);
208 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
209 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
210 ASSERT_NE(nullptr, session);
211 window->hostSession_ = session;
212
213 bool isVisible = true;
214 WMError res = window->SetDecorVisible(isVisible);
215 ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
216
217 window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
218 res = window->SetDecorVisible(isVisible);
219 ASSERT_EQ(res, WMError::WM_OK);
220 GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetDecorVisibletest01 end";
221 }
222
223 /**
224 * @tc.name: SetSubWindowModal
225 * @tc.desc: SetSubWindowModal and check the retCode
226 * @tc.type: FUNC
227 */
228 HWTEST_F(WindowSessionImplTest4, SetSubWindowModal, Function | SmallTest | Level2)
229 {
230 GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetSubWindowModaltest01 start";
231 sptr<WindowOption> option = new WindowOption();
232 ASSERT_NE(option, nullptr);
233 option->SetWindowName("SetSubWindowModal");
234 option->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
235 sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
236 ASSERT_NE(window, nullptr);
237 WMError res = window->SetSubWindowModal(true);
238 ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW);
239 GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetSubWindowModaltest01 end";
240 }
241
242 /**
243 * @tc.name: GetDecorHeight
244 * @tc.desc: GetDecorHeight and check the retCode
245 * @tc.type: FUNC
246 */
247 HWTEST_F(WindowSessionImplTest4, GetDecorHeight, Function | SmallTest | Level2)
248 {
249 GTEST_LOG_(INFO) << "WindowSessionImplTest4: GetDecorHeighttest01 start";
250 sptr<WindowOption> option = new WindowOption();
251 ASSERT_NE(option, nullptr);
252 option->SetWindowName("GetDecorHeight");
253 sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
254 ASSERT_NE(window, nullptr);
255 ASSERT_NE(window->property_, nullptr);
256 window->property_->SetPersistentId(1);
257 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
258 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
259 ASSERT_NE(nullptr, session);
260 window->hostSession_ = session;
261 int32_t height = 0;
262 WMError res = window->GetDecorHeight(height);
263 ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
264 GTEST_LOG_(INFO) << "WindowSessionImplTest4: GetDecorHeighttest01 end";
265 }
266
267 /**
268 * @tc.name: GetTitleButtonArea
269 * @tc.desc: GetTitleButtonArea and check the retCode
270 * @tc.type: FUNC
271 */
272 HWTEST_F(WindowSessionImplTest4, GetTitleButtonArea, Function | SmallTest | Level2)
273 {
274 GTEST_LOG_(INFO) << "WindowSessionImplTest4: GetTitleButtonAreatest01 start";
275 sptr<WindowOption> option = new WindowOption();
276 ASSERT_NE(option, nullptr);
277 option->SetWindowName("GetTitleButtonArea");
278 sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
279 ASSERT_NE(window, nullptr);
280 ASSERT_NE(window->property_, nullptr);
281 window->property_->SetPersistentId(1);
282 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
283 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
284 ASSERT_NE(nullptr, session);
285 window->hostSession_ = session;
286 TitleButtonRect titleButtonRect;
287 WMError res = window->GetTitleButtonArea(titleButtonRect);
288 ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
289 GTEST_LOG_(INFO) << "WindowSessionImplTest4: GetDecorHeighttest01 end";
290 }
291
292 /**
293 * @tc.name: RegisterExtensionAvoidAreaChangeListener
294 * @tc.desc: RegisterExtensionAvoidAreaChangeListener Test
295 * @tc.type: FUNC
296 */
297 HWTEST_F(WindowSessionImplTest4, RegisterExtensionAvoidAreaChangeListener, Function | SmallTest | Level2)
298 {
299 GTEST_LOG_(INFO) << "WindowSessionImplTest4: RegisterExtensionAvoidAreaChangeListener start";
300 sptr<WindowOption> option = new WindowOption();
301 ASSERT_NE(option, nullptr);
302 option->SetWindowName("GetTitleButtonArea");
303 sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
304 ASSERT_NE(window, nullptr);
305 sptr<IAvoidAreaChangedListener> listener = nullptr;
306 WMError res = window->RegisterExtensionAvoidAreaChangeListener(listener);
307 ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
308 GTEST_LOG_(INFO) << "WindowSessionImplTest4: RegisterExtensionAvoidAreaChangeListener end";
309 }
310
311 /**
312 * @tc.name: UnregisterExtensionAvoidAreaChangeListener
313 * @tc.desc: UnregisterExtensionAvoidAreaChangeListener Test
314 * @tc.type: FUNC
315 */
316 HWTEST_F(WindowSessionImplTest4, UnregisterExtensionAvoidAreaChangeListener, Function | SmallTest | Level2)
317 {
318 GTEST_LOG_(INFO) << "WindowSessionImplTest4: UnregisterExtensionAvoidAreaChangeListener start";
319 sptr<WindowOption> option = new WindowOption();
320 ASSERT_NE(option, nullptr);
321 option->SetWindowName("GetTitleButtonArea");
322 sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
323 ASSERT_NE(window, nullptr);
324 sptr<IAvoidAreaChangedListener> listener = nullptr;
325 WMError res = window->UnregisterExtensionAvoidAreaChangeListener(listener);
326 ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
327 GTEST_LOG_(INFO) << "WindowSessionImplTest4: UnregisterExtensionAvoidAreaChangeListener end";
328 }
329
330 /**
331 * @tc.name: SetPipActionEvent
332 * @tc.desc: SetPipActionEvent Test
333 * @tc.type: FUNC
334 */
335 HWTEST_F(WindowSessionImplTest4, SetPipActionEvent, Function | SmallTest | Level2)
336 {
337 GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetPipActionEvent start";
338 sptr<WindowOption> option = new WindowOption();
339 ASSERT_NE(option, nullptr);
340 option->SetWindowName("GetTitleButtonArea");
341 sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
342 ASSERT_NE(window, nullptr);
343 ASSERT_EQ(nullptr, window->GetUIContentWithId(10000));
344 window->property_->SetPersistentId(1);
345
346 SessionInfo sessionInfo = { "CreateTestBundle", "TestGetUIContentWithId", "CreateTestAbility" };
347 sptr<SessionMocker> session = new(std::nothrow) SessionMocker(sessionInfo);
348 ASSERT_NE(nullptr, session);
349 ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
350 window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
351 ASSERT_EQ(window->FindWindowById(1), nullptr);
352 ASSERT_EQ(nullptr, window->GetUIContentWithId(1));
353 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
354 GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetPipActionEvent end";
355 }
356
357 /**
358 * @tc.name: SetPiPControlEvent
359 * @tc.desc: SetPiPControlEvent Test
360 * @tc.type: FUNC
361 */
362 HWTEST_F(WindowSessionImplTest4, SetPiPControlEvent, Function | SmallTest | Level2)
363 {
364 GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetPiPControlEvent start";
365 auto option = sptr<WindowOption>::MakeSptr();
366 ASSERT_NE(option, nullptr);
367 option->SetWindowName("GetTitleButtonArea");
368 auto window = sptr<WindowSessionImpl>::MakeSptr(option);
369 ASSERT_NE(window, nullptr);
370 auto controlType = WsPiPControlType::VIDEO_PLAY_PAUSE;
371 auto status = WsPiPControlStatus::PLAY;
372 WSError res = window->SetPiPControlEvent(controlType, status);
373 ASSERT_EQ(res, WSError::WS_OK);
374 GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetPiPControlEvent end";
375 }
376
377 /**
378 * @tc.name: SetAutoStartPiP
379 * @tc.desc: SetAutoStartPiP
380 * @tc.type: FUNC
381 */
382 HWTEST_F(WindowSessionImplTest4, SetAutoStartPiP, Function | SmallTest | Level2)
383 {
384 auto option = sptr<WindowOption>::MakeSptr();
385 ASSERT_NE(option, nullptr);
386 option->SetWindowName("SetAutoStartPiP");
387 auto window = sptr<WindowSessionImpl>::MakeSptr(option);
388 ASSERT_NE(window, nullptr);
389 window->property_->SetPersistentId(1);
390 SessionInfo sessionInfo = { "SetAutoStartPiP", "SetAutoStartPiP", "SetAutoStartPiP" };
391 auto session = sptr<SessionMocker>::MakeSptr(sessionInfo);
392 ASSERT_NE(nullptr, session);
393 window->hostSession_ = session;
394 bool isAutoStart = true;
395 uint32_t priority = 1;
396 window->SetAutoStartPiP(isAutoStart, priority);
397 window->hostSession_ = nullptr;
398 window->SetAutoStartPiP(isAutoStart, priority);
399 }
400
401 /**
402 * @tc.name: TestGetUIContentWithId
403 * @tc.desc: Get uicontent with id
404 * @tc.type: FUNC
405 */
406 HWTEST_F(WindowSessionImplTest4, TestGetUIContentWithId, Function | SmallTest | Level2)
407 {
408 GTEST_LOG_(INFO) << "WindowSessionImplTest4: TestGetUIContentWithId start";
409 sptr<WindowOption> option = new WindowOption();
410 ASSERT_NE(nullptr, option);
411 option->SetWindowName("TestGetUIContentWithId");
412 sptr<WindowSessionImpl> window = new WindowSessionImpl(option);
413 ASSERT_NE(nullptr, window);
414 ASSERT_EQ(nullptr, window->GetUIContentWithId(10000));
415 window->property_->SetPersistentId(1);
416
417 SessionInfo sessionInfo = { "CreateTestBundle", "TestGetUIContentWithId", "CreateTestAbility" };
418 sptr<SessionMocker> session = new(std::nothrow) SessionMocker(sessionInfo);
419 ASSERT_NE(nullptr, session);
420 ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
421 window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
422 if (SceneBoardJudgement::IsSceneBoardEnabled()) {
423 ASSERT_NE(window->FindWindowById(1), nullptr);
424 ASSERT_EQ(nullptr, window->GetUIContentWithId(1));
425 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
426 }
427 GTEST_LOG_(INFO) << "WindowSessionImplTest4: TestGetUIContentWithId end";
428 }
429
430 /**
431 * @tc.name: GetCallingWindowRect
432 * @tc.desc: GetCallingWindowRect Test
433 * @tc.type: FUNC
434 */
435 HWTEST_F(WindowSessionImplTest4, GetCallingWindowRect, Function | SmallTest | Level2)
436 {
437 sptr<WindowOption> option = new WindowOption();
438 option->SetWindowName("GetCallingWindowRect");
439 sptr<WindowSessionImpl> window = new(std::nothrow) WindowSessionImpl(option);
440 ASSERT_NE(nullptr, window);
441 Rect rect = {0, 0, 0, 0};
442 WMError retCode = window->GetCallingWindowRect(rect);
443 ASSERT_EQ(retCode, WMError::WM_ERROR_INVALID_WINDOW);
444 window->property_->SetPersistentId(1);
445 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
446 sptr<SessionMocker> session = new(std::nothrow) SessionMocker(sessionInfo);
447 ASSERT_NE(nullptr, session);
448 window->hostSession_ = session;
449 window->state_ = WindowState::STATE_CREATED;
450 window->GetCallingWindowRect(rect);
451 }
452
453 /**
454 * @tc.name: GetCallingWindowWindowStatus
455 * @tc.desc: GetCallingWindowWindowStatus Test
456 * @tc.type: FUNC
457 */
458 HWTEST_F(WindowSessionImplTest4, GetCallingWindowWindowStatus, Function | SmallTest | Level2)
459 {
460 sptr<WindowOption> option = new WindowOption();
461 option->SetWindowName("GetCallingWindowWindowStatus");
462 sptr<WindowSessionImpl> window = new(std::nothrow) WindowSessionImpl(option);
463 ASSERT_NE(nullptr, window);
464 WindowStatus windowStatus = WindowStatus::WINDOW_STATUS_UNDEFINED;
465 WMError retCode = window->GetCallingWindowWindowStatus(windowStatus);
466 ASSERT_EQ(retCode, WMError::WM_ERROR_INVALID_WINDOW);
467 window->property_->SetPersistentId(1);
468 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
469 sptr<SessionMocker> session = new(std::nothrow) SessionMocker(sessionInfo);
470 ASSERT_NE(nullptr, session);
471 window->hostSession_ = session;
472 window->state_ = WindowState::STATE_CREATED;
473 window->GetCallingWindowWindowStatus(windowStatus);
474 }
475
476 /**
477 * @tc.name: GetParentId
478 * @tc.desc: GetParentId Test
479 * @tc.type: FUNC
480 */
481 HWTEST_F(WindowSessionImplTest4, GetParentId, Function | SmallTest | Level2)
482 {
483 sptr<WindowOption> option = new WindowOption();
484 sptr<WindowSessionImpl> window = new WindowSessionImpl(option);
485 const int32_t res = window->GetParentId();
486 ASSERT_EQ(res, 0);
487 ASSERT_EQ(true, window->IsSupportWideGamut());
488 }
489
490 /**
491 * @tc.name: PreNotifyKeyEvent
492 * @tc.desc: PreNotifyKeyEvent Test
493 * @tc.type: FUNC
494 */
495 HWTEST_F(WindowSessionImplTest4, PreNotifyKeyEvent, Function | SmallTest | Level2)
496 {
497 sptr<WindowOption> option = new (std::nothrow) WindowOption();
498 ASSERT_NE(nullptr, option);
499 sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
500 ASSERT_NE(nullptr, window);
501 std::shared_ptr<MMI::PointerEvent> pointerEvent;
502 window->ConsumePointerEvent(pointerEvent);
503
504 std::shared_ptr<MMI::KeyEvent> keyEvent;
505 window->ConsumeKeyEvent(keyEvent);
506 ASSERT_EQ(nullptr, window->GetUIContentSharedPtr());
507 ASSERT_EQ(false, window->PreNotifyKeyEvent(keyEvent));
508 ASSERT_EQ(false, window->NotifyOnKeyPreImeEvent(keyEvent));
509 window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
510 ASSERT_NE(nullptr, window->GetUIContentSharedPtr());
511 ASSERT_EQ(false, window->PreNotifyKeyEvent(keyEvent));
512 ASSERT_EQ(false, window->NotifyOnKeyPreImeEvent(keyEvent));
513 }
514
515 /**
516 * @tc.name: UpdateRectForRotation
517 * @tc.desc: UpdateRectForRotation Test
518 * @tc.type: FUNC
519 */
520 HWTEST_F(WindowSessionImplTest4, UpdateRectForRotation, Function | SmallTest | Level2)
521 {
522 sptr<WindowOption> option = new WindowOption();
523 option->SetWindowName("WindowSessionCreateCheck");
524 sptr<WindowSessionImpl> window =
525 new (std::nothrow) WindowSessionImpl(option);
526 ASSERT_NE(window, nullptr);
527
528 Rect wmRect;
529 wmRect.posX_ = 0;
530 wmRect.posY_ = 0;
531 wmRect.height_ = 50;
532 wmRect.width_ = 50;
533
534 WSRect rect;
535 wmRect.posX_ = 0;
536 wmRect.posY_ = 0;
537 wmRect.height_ = 50;
538 wmRect.width_ = 50;
539
540 Rect preRect;
541 preRect.posX_ = 0;
542 preRect.posY_ = 0;
543 preRect.height_ = 200;
544 preRect.width_ = 200;
545
546 window->property_->SetWindowRect(preRect);
547 WindowSizeChangeReason wmReason = WindowSizeChangeReason{0};
548 std::shared_ptr<RSTransaction> rsTransaction;
549 SceneAnimationConfig config { .rsTransaction_ = rsTransaction };
550 window->UpdateRectForRotation(wmRect, preRect, wmReason, config);
551
552 SizeChangeReason reason = SizeChangeReason::UNDEFINED;
553 auto res = window->UpdateRect(rect, reason);
554 ASSERT_EQ(res, WSError::WS_OK);
555 }
556
557 /**
558 * @tc.name: SetTitleButtonVisible
559 * @tc.desc: SetTitleButtonVisible and GetTitleButtonVisible
560 * @tc.type: FUNC
561 */
562 HWTEST_F(WindowSessionImplTest4, SetTitleButtonVisible, Function | SmallTest | Level2)
563 {
564 sptr<WindowOption> option = new WindowOption();
565 sptr<WindowSessionImpl> window = new WindowSessionImpl(option);
566 ASSERT_NE(window, nullptr);
567 bool isMaximizeVisible = true;
568 bool isMinimizeVisible = true;
569 bool isSplitVisible = true;
570 auto res = window->SetTitleButtonVisible(isMaximizeVisible, isMinimizeVisible,
571 isSplitVisible);
572
573 bool &hideMaximizeButton = isMaximizeVisible;
574 bool &hideMinimizeButton = isMinimizeVisible;
575 bool &hideSplitButton = isSplitVisible;
576 window->GetTitleButtonVisible(true, hideMaximizeButton, hideMinimizeButton,
577 hideSplitButton);
578 ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW);
579 }
580
581 /**
582 * @tc.name: IsFocused
583 * @tc.desc: IsFocused
584 * @tc.type: FUNC
585 */
586 HWTEST_F(WindowSessionImplTest4, IsFocused, Function | SmallTest | Level2)
587 {
588 sptr<WindowOption> option = new WindowOption();
589 option->SetWindowName("WindowSessionCreateCheck");
590 sptr<WindowSessionImpl> window =
591 new (std::nothrow) WindowSessionImpl(option);
592 ASSERT_NE(window, nullptr);
593 bool res = window->IsFocused();
594 ASSERT_EQ(res, false);
595
596 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->RequestFocus());
597
598 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule",
599 "CreateTestAbility"};
600 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
601 ASSERT_NE(nullptr, session);
602 ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
603 int32_t persistentId = window->GetPersistentId();
604 if (persistentId == INVALID_SESSION_ID) {
605 persistentId = 1;
606 window->property_->SetPersistentId(persistentId);
607 }
608 if (window->state_ == WindowState::STATE_DESTROYED) {
609 window->state_ = WindowState::STATE_SHOWN;
610 }
611 window->hostSession_ = session;
612 window->RequestFocus();
613 ASSERT_FALSE(window->IsWindowSessionInvalid());
614 ASSERT_EQ(persistentId, window->GetPersistentId());
615 ASSERT_EQ(WMError::WM_OK, window->Destroy());
616 }
617
618 /**
619 * @tc.name: GetAbcContent
620 * @tc.desc: GetAbcContent Test
621 * @tc.type: FUNC
622 */
623 HWTEST_F(WindowSessionImplTest4, GetAbcContent, Function | SmallTest | Level2)
624 {
625 sptr<WindowOption> option = new WindowOption();
626 ASSERT_NE(option, nullptr);
627 option->SetWindowName("GetAbcContent");
628 sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
629 ASSERT_NE(window, nullptr);
630 std::string abcPath = "";
631 std::shared_ptr<std::vector<uint8_t>> res = window->GetAbcContent(abcPath);
632 std::filesystem::path abcFile{abcPath};
633 ASSERT_TRUE(abcFile.empty());
634 ASSERT_TRUE(!abcFile.is_absolute());
635 ASSERT_TRUE(!std::filesystem::exists(abcFile));
636 ASSERT_EQ(res, nullptr);
637
638 abcPath = "/abc";
639 res = window->GetAbcContent(abcPath);
640 std::filesystem::path abcFile2{abcPath};
641 ASSERT_FALSE(abcFile2.empty());
642 ASSERT_FALSE(!abcFile2.is_absolute());
643 ASSERT_TRUE(!std::filesystem::exists(abcFile2));
644 ASSERT_EQ(res, nullptr);
645
646 abcPath = "abc";
647 res = window->GetAbcContent(abcPath);
648 std::filesystem::path abcFile3{abcPath};
649 ASSERT_FALSE(abcFile3.empty());
650 ASSERT_TRUE(!abcFile3.is_absolute());
651 ASSERT_TRUE(!std::filesystem::exists(abcFile3));
652 ASSERT_EQ(res, nullptr);
653
654 abcPath = "/log";
655 res = window->GetAbcContent(abcPath);
656 std::filesystem::path abcFile4{abcPath};
657 ASSERT_FALSE(abcFile4.empty());
658 ASSERT_FALSE(!abcFile4.is_absolute());
659 if (SceneBoardJudgement::IsSceneBoardEnabled()) {
660 ASSERT_FALSE(!std::filesystem::exists(abcFile4));
661 ASSERT_NE(res, nullptr);
662 std::fstream file(abcFile, std::ios::in | std::ios::binary);
663 ASSERT_FALSE(file);
664 }
665 window->Destroy();
666 }
667
668 /**
669 * @tc.name: SetLandscapeMultiWindow
670 * @tc.desc: SetLandscapeMultiWindow and check the retCode
671 * @tc.type: FUNC
672 */
673 HWTEST_F(WindowSessionImplTest4, SetLandscapeMultiWindow, Function | SmallTest | Level2)
674 {
675 sptr<WindowOption> option = new WindowOption();
676 option->SetWindowName("SetLandscapeMultiWindow");
677 sptr<WindowSessionImpl> window = new(std::nothrow) WindowSessionImpl(option);
678 ASSERT_NE(nullptr, window);
679 WMError retCode = window->SetLandscapeMultiWindow(false);
680 ASSERT_EQ(retCode, WMError::WM_ERROR_INVALID_WINDOW);
681 window->property_->SetPersistentId(1);
682 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
683 sptr<SessionMocker> session = new(std::nothrow) SessionMocker(sessionInfo);
684 ASSERT_NE(nullptr, session);
685 window->hostSession_ = session;
686 window->state_ = WindowState::STATE_CREATED;
687 retCode = window->SetLandscapeMultiWindow(false);
688 ASSERT_EQ(retCode, WMError::WM_OK);
689 }
690
691 /**
692 * @tc.name: GetTouchable
693 * @tc.desc: GetTouchable
694 * @tc.type: FUNC
695 */
696 HWTEST_F(WindowSessionImplTest4, GetTouchable, Function | SmallTest | Level2)
697 {
698 sptr<WindowOption> option = new WindowOption();
699 ASSERT_NE(option, nullptr);
700 option->SetWindowName("GetTouchable");
701 sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
702 ASSERT_NE(window, nullptr);
703 window->GetTouchable();
704 window->GetBrightness();
705 ASSERT_NE(window, nullptr);
706 }
707
708 /**
709 * @tc.name: Notify03
710 * @tc.desc: NotifyCloseExistPipWindow NotifyAfterResumed NotifyAfterPaused
711 * @tc.type: FUNC
712 */
713 HWTEST_F(WindowSessionImplTest4, Notify03, Function | SmallTest | Level2)
714 {
715 sptr<WindowOption> option = new WindowOption();
716 option->SetWindowName("Notify03");
717 sptr<WindowSessionImpl> window = new WindowSessionImpl(option);
718
719 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule",
720 "CreateTestAbility"};
721 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
722 ASSERT_NE(nullptr, session);
723 ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session));
724
725 window->NotifyAfterResumed();
726 window->NotifyAfterPaused();
727 WSError res = window->NotifyCloseExistPipWindow();
728 ASSERT_EQ(res, WSError::WS_OK);
729 AAFwk::WantParams wantParams;
730 WSError ret = window->NotifyTransferComponentData(wantParams);
731 ASSERT_EQ(ret, WSError::WS_OK);
732 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
733 }
734
735 /**
736 * @tc.name: Filter
737 * @tc.desc: Filter
738 * @tc.type: FUNC
739 */
740 HWTEST_F(WindowSessionImplTest4, Filter, Function | SmallTest | Level2)
741 {
742 sptr<WindowOption> option = new WindowOption();
743 ASSERT_NE(option, nullptr);
744 option->SetWindowName("Filter");
745 sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
746 ASSERT_NE(window, nullptr);
747 std::shared_ptr<MMI::KeyEvent> keyEvent = MMI::KeyEvent::Create();
748 window->FilterKeyEvent(keyEvent);
749 ASSERT_EQ(window->keyEventFilter_, nullptr);
__anonb1bed7980202(MMI::KeyEvent& keyEvent) 750 window->SetKeyEventFilter([](MMI::KeyEvent& keyEvent) {
751 GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetKeyEventFilter";
752 return true;
753 });
754 ASSERT_NE(window->keyEventFilter_, nullptr);
755 window->FilterKeyEvent(keyEvent);
756 auto ret = window->ClearKeyEventFilter();
757 ASSERT_EQ(ret, WMError::WM_OK);
758 }
759
760 /**
761 * @tc.name: UpdateOrientation
762 * @tc.desc: UpdateOrientation
763 * @tc.type: FUNC
764 */
765 HWTEST_F(WindowSessionImplTest4, UpdateOrientation, Function | SmallTest | Level2)
766 {
767 sptr<WindowOption> option = new WindowOption();
768 ASSERT_NE(option, nullptr);
769 option->SetWindowName("UpdateOrientation");
770 sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
771 ASSERT_NE(window, nullptr);
772 auto ret = window->UpdateOrientation();
773 ASSERT_EQ(WSError::WS_OK, ret);
774 }
775
776 /**
777 * @tc.name: SetTitleButtonVisible01
778 * @tc.desc: SetTitleButtonVisible
779 * @tc.type: FUNC
780 */
781 HWTEST_F(WindowSessionImplTest4, SetTitleButtonVisible01, Function | SmallTest | Level2)
782 {
783 GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetTitleButtonVisible01 start";
784 sptr<WindowOption> option = new (std::nothrow) WindowOption();
785 ASSERT_NE(option, nullptr);
786 option->SetWindowName("SetTitleButtonVisible");
787 sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
788 ASSERT_NE(window, nullptr);
789 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
790 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
791 ASSERT_NE(nullptr, session);
792 window->hostSession_ = session;
793 ASSERT_NE(window->property_, nullptr);
794 window->property_->SetPersistentId(1);
795 window->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
796 WMError res = window->SetTitleButtonVisible(false, false, false);
797 ASSERT_EQ(res, WMError::WM_ERROR_INVALID_CALLING);
798 GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetTitleButtonVisible01 end";
799 }
800
801 /**
802 * @tc.name: SetTitleButtonVisible02
803 * @tc.desc: SetTitleButtonVisible
804 * @tc.type: FUNC
805 */
806 HWTEST_F(WindowSessionImplTest4, SetTitleButtonVisible02, Function | SmallTest | Level2)
807 {
808 GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetTitleButtonVisible02 start";
809 sptr<WindowOption> option = new (std::nothrow) WindowOption();
810 ASSERT_NE(option, nullptr);
811 option->SetWindowName("SetTitleButtonVisible");
812 sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
813 ASSERT_NE(window, nullptr);
814 ASSERT_NE(window->property_, nullptr);
815 window->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
816 WMError res = window->SetTitleButtonVisible(false, false, false);
817 ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW);
818 GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetTitleButtonVisible02 end";
819 }
820
821 /**
822 * @tc.name: SetTitleButtonVisible03
823 * @tc.desc: SetTitleButtonVisible
824 * @tc.type: FUNC
825 */
826 HWTEST_F(WindowSessionImplTest4, SetTitleButtonVisible03, Function | SmallTest | Level2)
827 {
828 GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetTitleButtonVisible03 start";
829 sptr option = new (std::nothrow) WindowOption();
830 ASSERT_NE(option, nullptr);
831 option->SetWindowName("SetTitleButtonVisible");
832 sptr window = new (std::nothrow) WindowSessionImpl(option);
833 ASSERT_NE(window, nullptr);
834 ASSERT_NE(window->property_, nullptr);
835 window->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
836 window->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
837 window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
838 window->windowSystemConfig_.freeMultiWindowSupport_ = true;
839 window->windowSystemConfig_.isSystemDecorEnable_ = true;
840 window->windowSystemConfig_.uiType_ = "phone";
841 WMError res = window->SetTitleButtonVisible(false, false, false);
842 ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW);
843 window->windowSystemConfig_.uiType_ = "pc";
844 res = window->SetTitleButtonVisible(false, false, false);
845 ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW);
846 GTEST_LOG_(INFO) << "WindowSessionImplTest4: SetTitleButtonVisible03 end";
847 }
848
849 /**
850 * @tc.name: GetTitleButtonVisible01
851 * @tc.desc: GetTitleButtonVisible
852 * @tc.type: FUNC
853 */
854 HWTEST_F(WindowSessionImplTest4, GetTitleButtonVisible01, Function | SmallTest | Level2)
855 {
856 sptr<WindowOption> option = new (std::nothrow) WindowOption();
857 ASSERT_NE(option, nullptr);
858 option->SetWindowName("GetTitleButtonVisible01");
859 sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
860 ASSERT_NE(window, nullptr);
861 ASSERT_NE(window->property_, nullptr);
862 uint32_t modeSupportInfo = 1 | (1 << 1) | (1 << 2);
863 window->property_->SetModeSupportInfo(modeSupportInfo);
864 window->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
865 // show Maximize, Minimize, Split buttons.
866 window->windowTitleVisibleFlags_ = { false, false, false };
867 bool hideMaximizeButton = false;
868 bool hideMinimizeButton = false;
869 bool hideSplitButton = false;
870 window->GetTitleButtonVisible(true, hideMaximizeButton, hideMinimizeButton, hideSplitButton);
871 ASSERT_EQ(hideMaximizeButton, true);
872 ASSERT_EQ(hideMinimizeButton, true);
873 ASSERT_EQ(hideSplitButton, true);
874 }
875
876 /**
877 * @tc.name: UpdateRect03
878 * @tc.desc: UpdateRect
879 * @tc.type: FUNC
880 */
881 HWTEST_F(WindowSessionImplTest4, UpdateRect03, Function | SmallTest | Level2)
882 {
883 sptr<WindowOption> option = new WindowOption();
884 option->SetWindowName("WindowSessionCreateCheck");
885 sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
886 ASSERT_NE(window, nullptr);
887
888 WSRect rect;
889 rect.posX_ = 0;
890 rect.posY_ = 0;
891 rect.height_ = 0;
892 rect.width_ = 0;
893
894 Rect rectW; // GetRect().IsUninitializedRect is true
895 rectW.posX_ = 0;
896 rectW.posY_ = 0;
897 rectW.height_ = 0; // rectW - rect > 50
898 rectW.width_ = 0; // rectW - rect > 50
899
900 window->property_->SetWindowRect(rectW);
901 SizeChangeReason reason = SizeChangeReason::UNDEFINED;
902 WSError res = window->UpdateRect(rect, reason);
903 ASSERT_EQ(res, WSError::WS_OK);
904
905 rect.height_ = 50;
906 rect.width_ = 50;
907 rectW.height_ = 50;
908 rectW.width_ = 50;
909 window->property_->SetWindowRect(rectW);
910 res = window->UpdateRect(rect, reason);
911 ASSERT_EQ(res, WSError::WS_OK);
912 }
913
914 /**
915 * @tc.name: GetTitleButtonVisible02
916 * @tc.desc: GetTitleButtonVisible
917 * @tc.type: FUNC
918 */
919 HWTEST_F(WindowSessionImplTest4, GetTitleButtonVisible02, Function | SmallTest | Level2)
920 {
921 sptr<WindowOption> option = new (std::nothrow) WindowOption();
922 ASSERT_NE(option, nullptr);
923 option->SetWindowName("GetTitleButtonVisible02");
924 sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
925 ASSERT_NE(window, nullptr);
926 ASSERT_NE(window->property_, nullptr);
927 // only not support WINDOW_MODE_SUPPORT_SPLIT
928 uint32_t modeSupportInfo = 1 | (1 << 1);
929 window->property_->SetModeSupportInfo(modeSupportInfo);
930 window->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
931 // show Maximize, Minimize, Split buttons.
932 window->windowTitleVisibleFlags_ = { true, true, true };
933 bool hideMaximizeButton = false;
934 bool hideMinimizeButton = false;
935 bool hideSplitButton = false;
936 window->GetTitleButtonVisible(true, hideMaximizeButton, hideMinimizeButton, hideSplitButton);
937 ASSERT_EQ(hideMaximizeButton, false);
938 ASSERT_EQ(hideMinimizeButton, false);
939 ASSERT_EQ(hideSplitButton, false);
940 }
941
942 /**
943 * @tc.name: GetTitleButtonVisible03
944 * @tc.desc: GetTitleButtonVisible
945 * @tc.type: FUNC
946 */
947 HWTEST_F(WindowSessionImplTest4, GetTitleButtonVisible03, Function | SmallTest | Level2)
948 {
949 sptr<WindowOption> option = new (std::nothrow) WindowOption();
950 ASSERT_NE(option, nullptr);
951 option->SetWindowName("GetTitleButtonVisible03");
952 option->SetDisplayId(1);
953 sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
954 ASSERT_NE(window, nullptr);
955 ASSERT_NE(window->property_, nullptr);
956 ASSERT_EQ(1, window->GetDisplayId());
957 // only not support WINDOW_MODE_SUPPORT_SPLIT
958 uint32_t modeSupportInfo = 1 | (1 << 1) | (1 << 2);
959 window->property_->SetModeSupportInfo(modeSupportInfo);
960 window->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
961 // show Maximize, Minimize, Split buttons.
962 window->windowTitleVisibleFlags_ = { false, false, false };
963 bool hideMaximizeButton = true;
964 bool hideMinimizeButton = true;
965 bool hideSplitButton = true;
966 window->GetTitleButtonVisible(false, hideMaximizeButton, hideMinimizeButton, hideSplitButton);
967 ASSERT_EQ(hideMaximizeButton, true);
968 ASSERT_EQ(hideMinimizeButton, true);
969 ASSERT_EQ(hideSplitButton, true);
970 }
971
972 /**
973 * @tc.name: SetUiDvsyncSwitch
974 * @tc.desc: SetUiDvsyncSwitch
975 * @tc.type: FUNC
976 */
977 HWTEST_F(WindowSessionImplTest4, SetUiDvsyncSwitch, Function | SmallTest | Level2)
978 {
979 sptr<WindowOption> option = new (std::nothrow) WindowOption();
980 ASSERT_NE(option, nullptr);
981 option->SetWindowName("SetUiDvsyncSwitch");
982 sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
983 ASSERT_NE(window, nullptr);
984 window->SetUiDvsyncSwitch(true);
985 window->vsyncStation_ = nullptr;
986 window->SetUiDvsyncSwitch(true);
987 }
988
989 /**
990 * @tc.name: GetVSyncPeriod
991 * @tc.desc: GetVSyncPeriod
992 * @tc.type: FUNC
993 */
994 HWTEST_F(WindowSessionImplTest4, GetVSyncPeriod, Function | SmallTest | Level2)
995 {
996 sptr<WindowOption> option = new (std::nothrow) WindowOption();
997 ASSERT_NE(option, nullptr);
998 option->SetWindowName("GetVSyncPeriod");
999 sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
1000 ASSERT_NE(window, nullptr);
1001 window->GetVSyncPeriod();
1002 window->vsyncStation_ = nullptr;
1003 window->GetVSyncPeriod();
1004 }
1005
1006 /**
1007 * @tc.name: UpdatePiPControlStatus01
1008 * @tc.desc: UpdatePiPControlStatus
1009 * @tc.type: FUNC
1010 */
1011 HWTEST_F(WindowSessionImplTest4, UpdatePiPControlStatus01, Function | SmallTest | Level2)
1012 {
1013 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1014 ASSERT_NE(option, nullptr);
1015 option->SetWindowName("UpdatePiPControlStatus01");
1016 sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
1017 ASSERT_NE(window, nullptr);
1018 ASSERT_NE(window->property_, nullptr);
1019 window->property_->SetPersistentId(1);
1020 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1021 sptr<SessionMocker> session = new(std::nothrow) SessionMocker(sessionInfo);
1022 ASSERT_NE(nullptr, session);
1023 window->hostSession_ = session;
1024 auto controlType = PiPControlType::VIDEO_PLAY_PAUSE;
1025 auto status = PiPControlStatus::ENABLED;
1026 window->UpdatePiPControlStatus(controlType, status);
1027 window->hostSession_ = nullptr;
1028 window->UpdatePiPControlStatus(controlType, status);
1029 }
1030
1031 /**
1032 * @tc.name: NotifyWindowVisibility01
1033 * @tc.desc: NotifyWindowVisibility
1034 * @tc.type: FUNC
1035 */
1036 HWTEST_F(WindowSessionImplTest4, NotifyWindowVisibility01, Function | SmallTest | Level2)
1037 {
1038 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1039 ASSERT_NE(option, nullptr);
1040 option->SetWindowName("NotifyWindowVisibility01");
1041 sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
1042 ASSERT_NE(window, nullptr);
1043 ASSERT_NE(window->property_, nullptr);
1044 window->property_->SetPersistentId(1);
1045 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1046 sptr<SessionMocker> session = new(std::nothrow) SessionMocker(sessionInfo);
1047 ASSERT_NE(nullptr, session);
1048 window->hostSession_ = session;
1049 window->NotifyWindowVisibility(false);
1050 sptr<IWindowVisibilityChangedListener> listener = new IWindowVisibilityChangedListener();
1051 window->RegisterWindowVisibilityChangeListener(listener);
1052 window->NotifyWindowVisibility(false);
1053 window->UnregisterWindowVisibilityChangeListener(listener);
1054 }
1055
1056 /**
1057 * @tc.name: UpdateVirtualPixelRatio
1058 * @tc.desc: test UpdateVirtualPixelRatio
1059 * @tc.type: FUNC
1060 */
1061 HWTEST_F(WindowSessionImplTest4, UpdateVirtualPixelRatio, Function | SmallTest | Level2)
1062 {
1063 GTEST_LOG_(INFO) << "WindowSessionImplTest4: UpdateVirtualPixelRatio start";
1064 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1065 option->SetWindowName("UpdateVirtualPixelRatio");
1066 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1067 window->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1068 window->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
1069
1070 window->property_->SetDisplayId(-1);
1071 sptr<Display> display = nullptr;
1072 window->UpdateVirtualPixelRatio(display);
1073 ASSERT_EQ(window->virtualPixelRatio_, 1.0f);
1074
1075 window->property_->SetDisplayId(0);
1076 display = SingletonContainer::Get<DisplayManager>().GetDisplayById(window->property_->GetDisplayId());
1077 window->UpdateVirtualPixelRatio(display);
1078 ASSERT_NE(window->virtualPixelRatio_, 1.0f);
1079 GTEST_LOG_(INFO) << "WindowSessionImplTest4: UpdateVirtualPixelRatio end";
1080 }
1081
1082 /**
1083 * @tc.name: IsPcOrPadCapabilityEnabled
1084 * @tc.desc: IsPcOrPadCapabilityEnabled test
1085 * @tc.type: FUNC
1086 */
1087 HWTEST_F(WindowSessionImplTest4, IsPcOrPadCapabilityEnabled, Function | SmallTest | Level2)
1088 {
1089 GTEST_LOG_(INFO) << "WindowSessionImplTest4: IsPcOrPadCapabilityEnabled start";
1090 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1091 option->SetWindowName("IsPcOrPadCapabilityEnabled");
1092 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1093 ASSERT_NE(window->property_, nullptr);
1094 window->property_->SetPersistentId(1);
1095 window->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1096 window->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
1097 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1098 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
1099 ASSERT_NE(nullptr, session);
1100 window->hostSession_ = session;
1101
1102 window->windowSystemConfig_.uiType_ = "pc";
1103 EXPECT_EQ(true, window->IsPcOrPadCapabilityEnabled());
1104 window->windowSystemConfig_.uiType_ = "phone";
1105 EXPECT_EQ(false, window->IsPcOrPadCapabilityEnabled());
1106 window->windowSystemConfig_.uiType_ = "pad";
1107 EXPECT_EQ(false, window->IsPcOrPadCapabilityEnabled());
1108 window->property_->SetIsPcAppInPad(true);
1109 EXPECT_EQ(true, window->IsPcOrPadCapabilityEnabled());
1110 EXPECT_EQ(WMError::WM_OK, window->Destroy(true));
1111 GTEST_LOG_(INFO) << "WindowSessionImplTest4: IsPcOrPadCapabilityEnabled end";
1112 }
1113
1114 /**
1115 * @tc.name: DestroySubWindow
1116 * @tc.desc: DestroySubWindow test
1117 * @tc.type: FUNC
1118 */
1119 HWTEST_F(WindowSessionImplTest4, DestroySubWindow, Function | SmallTest | Level2)
1120 {
1121 GTEST_LOG_(INFO) << "WindowSessionImplTest4: DestroySubWindow start";
1122 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1123 ASSERT_NE(option, nullptr);
1124 option->SetWindowName("DestroySubWindow");
1125 option->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1126 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1127 ASSERT_NE(window->property_, nullptr);
1128 window->property_->SetPersistentId(1);
1129 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1130 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
1131 ASSERT_NE(nullptr, session);
1132 window->hostSession_ = session;
1133 window->windowSystemConfig_.uiType_ = "pc";
1134
1135 sptr<WindowOption> subOption = sptr<WindowOption>::MakeSptr();
1136 ASSERT_NE(subOption, nullptr);
1137 subOption->SetWindowName("DestroySubWindow01");
1138 subOption->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
1139 sptr<WindowSessionImpl> subWindow = sptr<WindowSessionImpl>::MakeSptr(subOption);
1140 ASSERT_NE(subWindow, nullptr);
1141 ASSERT_NE(subWindow->property_, nullptr);
1142 subWindow->property_->SetPersistentId(2);
1143 SessionInfo subSessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1144 sptr<SessionMocker> subSession = sptr<SessionMocker>::MakeSptr(subSessionInfo);
1145 ASSERT_NE(nullptr, subSession);
1146 subWindow->hostSession_ = subSession;
1147 window->windowSystemConfig_.uiType_ = "pc";
1148 std::vector<sptr<WindowSessionImpl>> vec;
1149 WindowSessionImpl::subWindowSessionMap_.insert(std::pair<int32_t,
1150 std::vector<sptr<WindowSessionImpl>>>(1, vec));
1151 WindowSessionImpl::subWindowSessionMap_[1].push_back(subWindow);
1152 window->DestroySubWindow();
1153 EXPECT_EQ(WMError::WM_OK, window->Destroy(true));
1154 }
1155
1156 /**
1157 * @tc.name: UpdateSubWindowStateAndNotify01
1158 * @tc.desc: UpdateSubWindowStateAndNotify
1159 * @tc.type: FUNC
1160 */
1161 HWTEST_F(WindowSessionImplTest4, UpdateSubWindowStateAndNotify01, Function | SmallTest | Level2)
1162 {
1163 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1164 ASSERT_NE(option, nullptr);
1165 option->SetWindowName("UpdateSubWindowStateAndNotify01");
1166 option->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1167 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1168 ASSERT_NE(window->property_, nullptr);
1169 window->property_->SetPersistentId(1);
1170 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1171 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
1172 ASSERT_NE(nullptr, session);
1173 window->hostSession_ = session;
1174 window->windowSystemConfig_.uiType_ = "pc";
1175
1176 sptr<WindowOption> subOption = sptr<WindowOption>::MakeSptr();
1177 ASSERT_NE(subOption, nullptr);
1178 subOption->SetWindowName("UpdateSubWindowStateAndNotify011");
1179 subOption->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
1180 sptr<WindowSessionImpl> subWindow = sptr<WindowSessionImpl>::MakeSptr(subOption);
1181 ASSERT_NE(subWindow, nullptr);
1182 ASSERT_NE(subWindow->property_, nullptr);
1183 subWindow->property_->SetPersistentId(2);
1184 SessionInfo subSessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1185 sptr<SessionMocker> subSession = sptr<SessionMocker>::MakeSptr(subSessionInfo);
1186 ASSERT_NE(nullptr, subSession);
1187 subWindow->hostSession_ = subSession;
1188 window->windowSystemConfig_.uiType_ = "pc";
1189 std::vector<sptr<WindowSessionImpl>> vec;
1190 WindowSessionImpl::subWindowSessionMap_.insert(std::pair<int32_t,
1191 std::vector<sptr<WindowSessionImpl>>>(1, vec));
1192 subWindow->UpdateSubWindowStateAndNotify(1, WindowState::STATE_HIDDEN);
1193 WindowSessionImpl::subWindowSessionMap_[1].push_back(subWindow);
1194 subWindow->state_ = WindowState::STATE_SHOWN;
1195 window->UpdateSubWindowStateAndNotify(1, WindowState::STATE_HIDDEN);
1196 window->state_ = WindowState::STATE_HIDDEN;
1197 window->UpdateSubWindowStateAndNotify(1, WindowState::STATE_HIDDEN);
1198 window->state_ = WindowState::STATE_SHOWN;
1199 window->UpdateSubWindowStateAndNotify(1, WindowState::STATE_SHOWN);
1200 window->state_ = WindowState::STATE_SHOWN;
1201 window->UpdateSubWindowStateAndNotify(1, WindowState::STATE_SHOWN);
1202 EXPECT_EQ(WMError::WM_OK, subWindow->Destroy(true));
1203 EXPECT_EQ(WMError::WM_OK, window->Destroy(true));
1204 }
1205
1206 /**
1207 * @tc.name: SetEnableDragBySystem
1208 * @tc.desc: test SetEnableDragBySystem
1209 * @tc.type: FUNC
1210 */
1211 HWTEST_F(WindowSessionImplTest4, SetEnableDragBySystem, Function | SmallTest | Level2)
1212 {
1213 GTEST_LOG_(INFO) << "WindowSessionImplTest4: GetSubWindow start";
1214 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1215 option->SetWindowName("GetSubWindow");
1216 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
1217 ASSERT_NE(nullptr, window);
1218 window->property_->SetDragEnabled(true);
1219 window->SetEnableDragBySystem(false);
1220 ASSERT_FALSE(window->property_->GetDragEnabled());
1221 }
1222 }
1223 } // namespace Rosen
1224 } // namespace OHOS
1225