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
16 #include <gtest/gtest.h>
17 #include <regex>
18 #include <pointer_event.h>
19 #include <ui/rs_surface_node.h>
20
21 #include "key_event.h"
22 #include "mock/mock_session_stage.h"
23 #include "mock/mock_window_event_channel.h"
24 #include "mock/mock_pattern_detach_callback.h"
25 #include "session/host/include/extension_session.h"
26 #include "session/host/include/move_drag_controller.h"
27 #include "session/host/include/scene_session.h"
28 #include "session/host/include/session.h"
29 #include "session_manager/include/scene_session_manager.h"
30 #include "session_info.h"
31 #include "session/screen/include/screen_session.h"
32 #include "screen_session_manager_client/include/screen_session_manager_client.h"
33 #include "wm_common.h"
34 #include "window_manager_hilog.h"
35
36 using namespace testing;
37 using namespace testing::ext;
38
39 namespace OHOS {
40 namespace Rosen {
41 namespace {
42 const std::string UNDEFINED = "undefined";
43 }
44
45 class WindowSessionTest3 : public testing::Test {
46 public:
47 static void SetUpTestCase();
48 static void TearDownTestCase();
49 void SetUp() override;
50 void TearDown() override;
51
52 int32_t GetTaskCount();
53 sptr<SceneSessionManager> ssm_;
54
55 private:
56 RSSurfaceNode::SharedPtr CreateRSSurfaceNode();
57 sptr<Session> session_ = nullptr;
58 static constexpr uint32_t WAIT_SYNC_IN_NS = 500000;
59 };
60
SetUpTestCase()61 void WindowSessionTest3::SetUpTestCase()
62 {
63 }
64
TearDownTestCase()65 void WindowSessionTest3::TearDownTestCase()
66 {
67 }
68
SetUp()69 void WindowSessionTest3::SetUp()
70 {
71 SessionInfo info;
72 info.abilityName_ = "testSession1";
73 info.moduleName_ = "testSession2";
74 info.bundleName_ = "testSession3";
75 session_ = sptr<Session>::MakeSptr(info);
76 EXPECT_NE(nullptr, session_);
77 session_->surfaceNode_ = CreateRSSurfaceNode();
78 ssm_ = sptr<SceneSessionManager>::MakeSptr();
79 session_->SetEventHandler(ssm_->taskScheduler_->GetEventHandler(), ssm_->eventHandler_);
80 auto isScreenLockedCallback = [this]() {
81 return ssm_->IsScreenLocked();
82 };
83 session_->RegisterIsScreenLockedCallback(isScreenLockedCallback);
84 }
85
TearDown()86 void WindowSessionTest3::TearDown()
87 {
88 session_ = nullptr;
89 usleep(WAIT_SYNC_IN_NS);
90 }
91
CreateRSSurfaceNode()92 RSSurfaceNode::SharedPtr WindowSessionTest3::CreateRSSurfaceNode()
93 {
94 struct RSSurfaceNodeConfig rsSurfaceNodeConfig;
95 rsSurfaceNodeConfig.SurfaceNodeName = "WindowSessionTest3SurfaceNode";
96 auto surfaceNode = RSSurfaceNode::Create(rsSurfaceNodeConfig);
97 if (surfaceNode == nullptr) {
98 GTEST_LOG_(INFO) << "WindowSessionTest3::CreateRSSurfaceNode surfaceNode is nullptr";
99 }
100 return surfaceNode;
101 }
102
GetTaskCount()103 int32_t WindowSessionTest3::GetTaskCount()
104 {
105 std::string dumpInfo = session_->handler_->GetEventRunner()->GetEventQueue()->DumpCurrentQueueSize();
106 std::regex pattern("\\d+");
107 std::smatch matches;
108 int32_t taskNum = 0;
109 while (std::regex_search(dumpInfo, matches, pattern)) {
110 taskNum += std::stoi(matches.str());
111 dumpInfo = matches.suffix();
112 }
113 return taskNum;
114 }
115
116 namespace {
117 /**
118 * @tc.name: NotifyContextTransparent
119 * @tc.desc: NotifyContextTransparent Test
120 * @tc.type: FUNC
121 */
122 HWTEST_F(WindowSessionTest3, NotifyContextTransparent, Function | SmallTest | Level2)
123 {
124 ASSERT_NE(session_, nullptr);
125 NotifyContextTransparentFunc contextTransparentFunc = session_->contextTransparentFunc_;
126 if (contextTransparentFunc == nullptr) {
127 contextTransparentFunc = {};
128 }
129 session_->contextTransparentFunc_ = nullptr;
130 session_->NotifyContextTransparent();
131
132 session_->SetContextTransparentFunc(contextTransparentFunc);
133 session_->NotifyContextTransparent();
134 session_->SetPendingSessionToBackgroundForDelegatorListener(nullptr);
135 EXPECT_EQ(WSError::WS_OK, session_->PendingSessionToBackgroundForDelegator(true));
136 }
137
138 /**
139 * @tc.name: SetFocusable04
140 * @tc.desc: SetFocusable Test
141 * @tc.type: FUNC
142 */
143 HWTEST_F(WindowSessionTest3, SetFocusable04, Function | SmallTest | Level2)
144 {
145 ASSERT_NE(session_, nullptr);
146 auto result = session_->SetFocusable(false);
147 ASSERT_EQ(result, WSError::WS_OK);
148
149 session_->isFocused_ = true;
150 session_->property_->SetFocusable(false);
151
152 result = session_->SetFocusable(false);
153 EXPECT_EQ(result, WSError::WS_OK);
154 EXPECT_EQ(session_->GetFocusable(), false);
155 }
156
157 /**
158 * @tc.name: SetSystemFocusable
159 * @tc.desc: SetSystemFocusable Test
160 * @tc.type: FUNC
161 */
162 HWTEST_F(WindowSessionTest3, SetSystemFocusable, Function | SmallTest | Level2)
163 {
164 ASSERT_NE(session_, nullptr);
165 ASSERT_EQ(session_->GetSystemFocusable(), true);
166 bool systemFocusable = false;
167 session_->SetSystemFocusable(systemFocusable);
168 ASSERT_EQ(session_->GetSystemFocusable(), systemFocusable);
169 }
170
171 /**
172 * @tc.name: SetFocusableOnShow
173 * @tc.desc: SetFocusableOnShow Test
174 * @tc.type: FUNC
175 */
176 HWTEST_F(WindowSessionTest3, SetFocusableOnShow, Function | SmallTest | Level2)
177 {
178 ASSERT_NE(session_, nullptr);
179 ASSERT_EQ(session_->IsFocusableOnShow(), true);
180 bool focusableOnShow = false;
181 session_->SetFocusableOnShow(focusableOnShow);
182 usleep(10000); // sleep 10ms
183 ASSERT_EQ(session_->IsFocusableOnShow(), focusableOnShow);
184 }
185
186 /**
187 * @tc.name: CheckFocusable
188 * @tc.desc: CheckFocusable Test
189 * @tc.type: FUNC
190 */
191 HWTEST_F(WindowSessionTest3, CheckFocusable, Function | SmallTest | Level2)
192 {
193 ASSERT_NE(session_, nullptr);
194 session_->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
195 ASSERT_EQ(session_->CheckFocusable(), true);
196 session_->SetSystemFocusable(false);
197 ASSERT_EQ(session_->CheckFocusable(), false);
198 }
199
200 /**
201 * @tc.name: SetTouchable03
202 * @tc.desc: IsSessionValid() and touchable return true
203 * @tc.type: FUNC
204 */
205 HWTEST_F(WindowSessionTest3, SetTouchable03, Function | SmallTest | Level2)
206 {
207 ASSERT_NE(session_, nullptr);
208 session_->SetSessionState(SessionState::STATE_FOREGROUND);
209 session_->sessionInfo_.isSystem_ = false;
210 EXPECT_EQ(WSError::WS_OK, session_->SetTouchable(true));
211 }
212
213 /**
214 * @tc.name: GetTouchable02
215 * @tc.desc: GetTouchable Test
216 * @tc.type: FUNC
217 */
218 HWTEST_F(WindowSessionTest3, GetTouchable02, Function | SmallTest | Level2)
219 {
220 ASSERT_NE(session_, nullptr);
221 EXPECT_EQ(true, session_->GetTouchable());
222 }
223
224 /**
225 * @tc.name: UpdateDensity02
226 * @tc.desc: UpdateDensity Test
227 * @tc.type: FUNC
228 */
229 HWTEST_F(WindowSessionTest3, UpdateDensity02, Function | SmallTest | Level2)
230 {
231 ASSERT_NE(session_, nullptr);
232 session_->SetSessionState(SessionState::STATE_FOREGROUND);
233 sptr<SessionStageMocker> mockSessionStage = sptr<SessionStageMocker>::MakeSptr();
234 EXPECT_NE(nullptr, mockSessionStage);
235 session_->sessionStage_ = mockSessionStage;
236 auto result = session_->UpdateDensity();
237 EXPECT_EQ(result, WSError::WS_OK);
238 }
239
240 /**
241 * @tc.name: UpdateOrientation
242 * @tc.desc: UpdateOrientation Test
243 * @tc.type: FUNC
244 */
245 HWTEST_F(WindowSessionTest3, UpdateOrientation, Function | SmallTest | Level2)
246 {
247 ASSERT_NE(session_, nullptr);
248 session_->sessionInfo_.isSystem_ = true;
249 auto result = session_->UpdateOrientation();
250 EXPECT_EQ(result, WSError::WS_ERROR_INVALID_SESSION);
251
252 session_->sessionInfo_.isSystem_ = false;
253 session_->SetSessionState(SessionState::STATE_FOREGROUND);
254 result = session_->UpdateOrientation();
255 EXPECT_EQ(result, WSError::WS_ERROR_NULLPTR);
256
257 sptr<SessionStageMocker> mockSessionStage = sptr<SessionStageMocker>::MakeSptr();
258 EXPECT_NE(nullptr, mockSessionStage);
259 session_->sessionStage_ = mockSessionStage;
260 result = session_->UpdateOrientation();
261 EXPECT_EQ(result, WSError::WS_OK);
262 }
263
264 /**
265 * @tc.name: SetActive
266 * @tc.desc: SetActive Test
267 * @tc.type: FUNC
268 */
269 HWTEST_F(WindowSessionTest3, SetActive, Function | SmallTest | Level2)
270 {
271 ASSERT_NE(session_, nullptr);
272 session_->SetSessionState(SessionState::STATE_CONNECT);
273 auto result = session_->SetActive(false);
274 EXPECT_EQ(result, WSError::WS_DO_NOTHING);
275 }
276
277 /**
278 * @tc.name: SetActive02
279 * @tc.desc: SetActive Test
280 * @tc.type: FUNC
281 */
282 HWTEST_F(WindowSessionTest3, SetActive02, Function | SmallTest | Level2)
283 {
284 ASSERT_NE(session_, nullptr);
285 session_->SetSessionState(SessionState::STATE_FOREGROUND);
286 sptr<SessionStageMocker> mockSessionStage = sptr<SessionStageMocker>::MakeSptr();
287 EXPECT_NE(nullptr, mockSessionStage);
288 session_->sessionStage_ = mockSessionStage;
289 auto result = session_->SetActive(true);
290 EXPECT_EQ(result, WSError::WS_OK);
291 }
292
293 /**
294 * @tc.name: SetActive03
295 * @tc.desc: SetActive Test
296 * @tc.type: FUNC
297 */
298 HWTEST_F(WindowSessionTest3, SetActive03, Function | SmallTest | Level2)
299 {
300 ASSERT_NE(session_, nullptr);
301 sptr<SessionStageMocker> mockSessionStage = sptr<SessionStageMocker>::MakeSptr();
302 EXPECT_NE(nullptr, mockSessionStage);
303 session_->sessionStage_ = mockSessionStage;
304
305 session_->SetSessionState(SessionState::STATE_CONNECT);
306 auto result = session_->SetActive(true);
307 EXPECT_EQ(result, WSError::WS_OK);
308
309 session_->isActive_ = true;
310 result = session_->SetActive(false);
311 EXPECT_EQ(result, WSError::WS_OK);
312
313 session_->SetSessionState(SessionState::STATE_ACTIVE);
314 session_->isActive_ = true;
315 result = session_->SetActive(false);
316 EXPECT_EQ(result, WSError::WS_OK);
317 }
318
319 /**
320 * @tc.name: PresentFocusIfPointDown
321 * @tc.desc: PresentFocusIfPointDown Test
322 * @tc.type: FUNC
323 */
324 HWTEST_F(WindowSessionTest3, PresentFocusIfPointDown, Function | SmallTest | Level2)
325 {
326 ASSERT_NE(session_, nullptr);
327 session_->isFocused_ = true;
328 session_->PresentFocusIfPointDown();
329
330 session_->isFocused_ = false;
331 session_->property_->SetFocusable(false);
332 session_->PresentFocusIfPointDown();
333 session_->SetPendingSessionToBackgroundForDelegatorListener(nullptr);
334 EXPECT_EQ(WSError::WS_OK, session_->PendingSessionToBackgroundForDelegator(true));
335 }
336
337 /**
338 * @tc.name: TransferPointerEvent06
339 * @tc.desc: TransferPointerEvent Test
340 * @tc.type: FUNC
341 */
342 HWTEST_F(WindowSessionTest3, TransferPointerEvent06, Function | SmallTest | Level2)
343 {
344 ASSERT_NE(session_, nullptr);
345 session_->SetSessionState(SessionState::STATE_CONNECT);
346 std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
347 ASSERT_NE(pointerEvent, nullptr);
348
349 SessionInfo info;
350 info.abilityName_ = "testSession1";
351 info.moduleName_ = "testSession2";
352 info.bundleName_ = "testSession3";
353 sptr<Session> dialogSession = sptr<Session>::MakeSptr(info);
354 ASSERT_NE(dialogSession, nullptr);
355 dialogSession->SetSessionState(SessionState::STATE_ACTIVE);
356 session_->dialogVec_.push_back(dialogSession);
357 pointerEvent->pointerAction_ = MMI::PointerEvent::POINTER_ACTION_DOWN;
358
359 auto result = session_->TransferPointerEvent(pointerEvent);
360 EXPECT_EQ(result, WSError::WS_ERROR_INVALID_PERMISSION);
361 }
362
363 /**
364 * @tc.name: TransferPointerEvent07
365 * @tc.desc: TransferPointerEvent Test
366 * @tc.type: FUNC
367 */
368 HWTEST_F(WindowSessionTest3, TransferPointerEvent07, Function | SmallTest | Level2)
369 {
370 ASSERT_NE(session_, nullptr);
371 session_->SetSessionState(SessionState::STATE_CONNECT);
372 std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
373 ASSERT_NE(pointerEvent, nullptr);
374 session_->property_->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
375 auto result = session_->TransferPointerEvent(pointerEvent);
376 EXPECT_EQ(result, WSError::WS_ERROR_NULLPTR);
377 }
378
379 /**
380 * @tc.name: TransferPointerEvent08
381 * @tc.desc: TransferPointerEvent Test
382 * @tc.type: FUNC
383 */
384 HWTEST_F(WindowSessionTest3, TransferPointerEvent08, Function | SmallTest | Level2)
385 {
386 ASSERT_NE(session_, nullptr);
387 session_->SetSessionState(SessionState::STATE_CONNECT);
388 std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
389 ASSERT_NE(pointerEvent, nullptr);
390
391 session_->property_->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
392 SessionInfo info;
393 info.abilityName_ = "testSession1";
394 info.moduleName_ = "testSession2";
395 info.bundleName_ = "testSession3";
396 sptr<Session> dialogSession = sptr<Session>::MakeSptr(info);
397 ASSERT_NE(dialogSession, nullptr);
398
399 session_->SetParentSession(dialogSession);
400 auto result = session_->TransferPointerEvent(pointerEvent);
401 EXPECT_EQ(result, WSError::WS_ERROR_NULLPTR);
402 }
403
404 /**
405 * @tc.name: TransferPointerEvent09
406 * @tc.desc: TransferPointerEvent Test
407 * @tc.type: FUNC
408 */
409 HWTEST_F(WindowSessionTest3, TransferPointerEvent09, Function | SmallTest | Level2)
410 {
411 ASSERT_NE(session_, nullptr);
412 session_->SetSessionState(SessionState::STATE_FOREGROUND);
413 std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
414 ASSERT_NE(pointerEvent, nullptr);
415
416 session_->property_->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
417 SessionInfo info;
418 info.abilityName_ = "testSession1";
419 info.moduleName_ = "testSession2";
420 info.bundleName_ = "testSession3";
421 sptr<Session> dialogSession = sptr<Session>::MakeSptr(info);
422 ASSERT_NE(dialogSession, nullptr);
423
424 session_->SetParentSession(dialogSession);
425 dialogSession->dialogVec_.push_back(session_);
426 pointerEvent->pointerAction_ = MMI::PointerEvent::POINTER_ACTION_MOVE;
427 auto result = session_->TransferPointerEvent(pointerEvent);
428 EXPECT_EQ(result, WSError::WS_ERROR_NULLPTR);
429 }
430
431 /**
432 * @tc.name: TransferPointerEvent10
433 * @tc.desc: TransferPointerEvent Test
434 * @tc.type: FUNC
435 */
436 HWTEST_F(WindowSessionTest3, TransferPointerEvent10, Function | SmallTest | Level2)
437 {
438 ASSERT_NE(session_, nullptr);
439 session_->SetSessionState(SessionState::STATE_FOREGROUND);
440 std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
441 ASSERT_NE(pointerEvent, nullptr);
442 pointerEvent->pointerAction_ = MMI::PointerEvent::POINTER_ACTION_DOWN;
443
444 session_->property_->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
445
446 SessionInfo info;
447 info.abilityName_ = "testSession1";
448 info.moduleName_ = "testSession2";
449 info.bundleName_ = "testSession3";
450 sptr<Session> dialogSession = sptr<Session>::MakeSptr(info);
451 sptr<Session> dialogSession2 = sptr<Session>::MakeSptr(info);
452 sptr<Session> dialogSession3 = sptr<Session>::MakeSptr(info);
453 ASSERT_NE(dialogSession, nullptr);
454 ASSERT_NE(dialogSession2, nullptr);
455 ASSERT_NE(dialogSession3, nullptr);
456 dialogSession2->SetSessionState(SessionState::STATE_FOREGROUND);
457 dialogSession3->SetSessionState(SessionState::STATE_ACTIVE);
458 dialogSession2->persistentId_ = 9;
459 session_->SetParentSession(dialogSession);
460 dialogSession->dialogVec_.push_back(dialogSession2);
461 dialogSession->dialogVec_.push_back(dialogSession3);
462 auto result = session_->TransferPointerEvent(pointerEvent);
463 EXPECT_EQ(result, WSError::WS_ERROR_NULLPTR);
464 }
465
466 /**
467 * @tc.name: TransferPointerEvent11
468 * @tc.desc: TransferPointerEvent Test
469 * @tc.type: FUNC
470 */
471 HWTEST_F(WindowSessionTest3, TransferPointerEvent11, Function | SmallTest | Level2)
472 {
473 ASSERT_NE(session_, nullptr);
474 session_->SetSessionState(SessionState::STATE_FOREGROUND);
475 std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
476 ASSERT_NE(pointerEvent, nullptr);
477
478 session_->property_->SetWindowType(WindowType::APP_WINDOW_BASE);
479
480 session_->windowEventChannel_ = nullptr;
481 auto result = session_->TransferPointerEvent(pointerEvent);
482 EXPECT_EQ(result, WSError::WS_ERROR_NULLPTR);
483 }
484
485 /**
486 * @tc.name: TransferFocusStateEvent03
487 * @tc.desc: TransferFocusStateEvent Test
488 * @tc.type: FUNC
489 */
490 HWTEST_F(WindowSessionTest3, TransferFocusStateEvent03, Function | SmallTest | Level2)
491 {
492 ASSERT_NE(session_, nullptr);
493 session_->windowEventChannel_ = nullptr;
494 session_->sessionInfo_.isSystem_ = true;
495 EXPECT_EQ(session_->TransferFocusStateEvent(true), WSError::WS_ERROR_NULLPTR);
496 }
497
498 /**
499 * @tc.name: Snapshot
500 * @tc.desc: Snapshot Test
501 * @tc.type: FUNC
502 */
503 HWTEST_F(WindowSessionTest3, Snapshot, Function | SmallTest | Level2)
504 {
505 ASSERT_NE(session_, nullptr);
506 int32_t persistentId = 1424;
507 std::string bundleName = "testBundleName";
508 session_->scenePersistence_ = sptr<ScenePersistence>::MakeSptr(bundleName, persistentId);
509 ASSERT_NE(session_->scenePersistence_, nullptr);
510 struct RSSurfaceNodeConfig config;
511 session_->surfaceNode_ = RSSurfaceNode::Create(config);
512 ASSERT_NE(session_->surfaceNode_, nullptr);
513 EXPECT_EQ(nullptr, session_->Snapshot(false, 0.0f));
514
515 session_->bufferAvailable_ = true;
516 EXPECT_EQ(nullptr, session_->Snapshot(false, 0.0f));
517
518 session_->surfaceNode_->bufferAvailable_ = true;
519 EXPECT_EQ(nullptr, session_->Snapshot(false, 0.0f));
520
521 session_->surfaceNode_ = nullptr;
522 EXPECT_EQ(nullptr, session_->Snapshot(false, 0.0f));
523 }
524
525 /**
526 * @tc.name: SetBufferAvailableChangeListener
527 * @tc.desc: SetBufferAvailableChangeListener Test
528 * @tc.type: FUNC
529 */
530 HWTEST_F(WindowSessionTest3, SetBufferAvailableChangeListener, Function | SmallTest | Level2)
531 {
532 session_->SetSessionState(SessionState::STATE_CONNECT);
533 session_->SetSessionStateChangeNotifyManagerListener(nullptr);
534
535 session_->bufferAvailable_ = true;
536 session_->SetBufferAvailableChangeListener(nullptr);
537
538 int resultValue = 0;
__anon58e439300402(const bool isAvailable) 539 NotifyBufferAvailableChangeFunc func = [&resultValue](const bool isAvailable) {
540 resultValue += 1;
541 };
542 session_->SetBufferAvailableChangeListener(func);
543 ASSERT_EQ(resultValue, 1);
544 }
545
546 /**
547 * @tc.name: NotifySessionFocusableChange
548 * @tc.desc: NotifySessionFocusableChange Test
549 * @tc.type: FUNC
550 */
551 HWTEST_F(WindowSessionTest3, NotifySessionFocusableChange, Function | SmallTest | Level2)
552 {
553 int resultValue = 0;
__anon58e439300502(const bool isFocusable) 554 NotifySessionFocusableChangeFunc func = [&resultValue](const bool isFocusable) {
555 resultValue += 1;
556 };
557 session_->SetSessionFocusableChangeListener(func);
558 session_->NotifySessionFocusableChange(true);
559 ASSERT_EQ(resultValue, 2);
560 }
561
562 /**
563 * @tc.name: GetStateFromManager
564 * @tc.desc: GetStateFromManager Test
565 * @tc.type: FUNC
566 */
567 HWTEST_F(WindowSessionTest3, GetStateFromManager, Function | SmallTest | Level2)
568 {
569 ManagerState key = ManagerState{0};
__anon58e439300602(const ManagerState key) 570 GetStateFromManagerFunc func = [](const ManagerState key) {
571 return true;
572 };
573 session_->getStateFromManagerFunc_ = func;
574 session_->GetStateFromManager(key);
575
576 session_->getStateFromManagerFunc_ = nullptr;
577 ASSERT_EQ(false, session_->GetStateFromManager(key));
578
579 // 覆盖default分支
580 key = ManagerState{-1};
581 ASSERT_EQ(false, session_->GetStateFromManager(key));
582 }
583
584 /**
585 * @tc.name: NotifyUIRequestFocus
586 * @tc.desc: NotifyUIRequestFocus Test
587 * @tc.type: FUNC
588 */
589 HWTEST_F(WindowSessionTest3, NotifyUIRequestFocus, Function | SmallTest | Level2)
590 {
__anon58e439300702() 591 session_->requestFocusFunc_ = []() {};
592 session_->NotifyUIRequestFocus();
593
594 ASSERT_NE(session_, nullptr);
595 }
596
597 /**
598 * @tc.name: SetCompatibleModeInPc
599 * @tc.desc: SetCompatibleModeInPc Test
600 * @tc.type: FUNC
601 */
602 HWTEST_F(WindowSessionTest3, SetCompatibleModeInPc, Function | SmallTest | Level2)
603 {
604 auto enable = true;
605 auto isSupportDragInPcCompatibleMode = true;
606 ASSERT_EQ(WSError::WS_OK, session_->SetCompatibleModeInPc(enable, isSupportDragInPcCompatibleMode));
607
608 ASSERT_EQ(WSError::WS_OK, session_->SetCompatibleModeInPc(enable, isSupportDragInPcCompatibleMode));
609
610 enable = false;
611 ASSERT_EQ(WSError::WS_OK, session_->SetCompatibleModeInPc(enable, isSupportDragInPcCompatibleMode));
612 }
613
614 /**
615 * @tc.name: NotifySessionTouchableChange
616 * @tc.desc: NotifySessionTouchableChange Test
617 * @tc.type: FUNC
618 */
619 HWTEST_F(WindowSessionTest3, NotifySessionTouchableChange, Function | SmallTest | Level2)
620 {
621 int resultValue = 0;
__anon58e439300802(const bool touchable) 622 NotifySessionTouchableChangeFunc func = [&resultValue](const bool touchable) {
623 resultValue += 1;
624 };
625 session_->SetSessionTouchableChangeListener(func);
626 session_->NotifySessionTouchableChange(true);
627 ASSERT_EQ(resultValue, 2);
628 }
629
630 /**
631 * @tc.name: NotifyClick
632 * @tc.desc: NotifyClick Test
633 * @tc.type: FUNC
634 */
635 HWTEST_F(WindowSessionTest3, NotifyClick, Function | SmallTest | Level2)
636 {
637 ASSERT_NE(session_, nullptr);
638 int resultValue = 0;
639 bool hasRequestFocus = true;
640 bool hasIsClick = true;
__anon58e439300902(bool requestFocus, bool isClick) 641 NotifyClickFunc func = [&resultValue, &hasRequestFocus, &hasIsClick](bool requestFocus, bool isClick) {
642 resultValue = 1;
643 hasRequestFocus = requestFocus;
644 hasIsClick = isClick;
645 };
646 session_->SetClickListener(func);
647 session_->NotifyClick(false, false);
648 EXPECT_EQ(resultValue, 1);
649 EXPECT_EQ(hasRequestFocus, false);
650 EXPECT_EQ(hasIsClick, false);
651 }
652
653 /**
654 * @tc.name: NotifyRequestFocusStatusNotifyManager
655 * @tc.desc: NotifyRequestFocusStatusNotifyManager Test
656 * @tc.type: FUNC
657 */
658 HWTEST_F(WindowSessionTest3, NotifyRequestFocusStatusNotifyManager, Function | SmallTest | Level2)
659 {
660 int resultValue = 0;
661 NotifyRequestFocusStatusNotifyManagerFunc func = [&resultValue](int32_t persistentId,
__anon58e439300a02(int32_t persistentId, const bool isFocused, const bool byForeground, FocusChangeReason reason) 662 const bool isFocused, const bool byForeground, FocusChangeReason reason) {
663 resultValue += 1;
664 };
665 session_->SetRequestFocusStatusNotifyManagerListener(func);
666 FocusChangeReason reason = FocusChangeReason::SCB_SESSION_REQUEST;
667 session_->NotifyRequestFocusStatusNotifyManager(true, false, reason);
668 EXPECT_EQ(resultValue, 1);
669 }
670
671 /**
672 * @tc.name: PresentFoucusIfNeed
673 * @tc.desc: PresentFoucusIfNeed Test
674 * @tc.type: FUNC
675 */
676 HWTEST_F(WindowSessionTest3, PresentFoucusIfNeed, Function | SmallTest | Level2)
677 {
678 ASSERT_NE(session_, nullptr);
679 int32_t pointerAction = MMI::PointerEvent::POINTER_ACTION_DOWN;
680 session_->PresentFoucusIfNeed(pointerAction);
681 pointerAction = MMI::PointerEvent::POINTER_ACTION_BUTTON_DOWN;
682 session_->PresentFoucusIfNeed(pointerAction);
683 session_->property_->focusable_ = false;
684 session_->PresentFoucusIfNeed(pointerAction);
685 session_->isFocused_ = true;
686 session_->PresentFoucusIfNeed(pointerAction);
687 EXPECT_EQ(true, session_->CheckPointerEventDispatch(nullptr));
688 }
689
690 /**
691 * @tc.name: UpdateFocus03
692 * @tc.desc: UpdateFocus Test
693 * @tc.type: FUNC
694 */
695 HWTEST_F(WindowSessionTest3, UpdateFocus03, Function | SmallTest | Level2)
696 {
697 ASSERT_NE(session_, nullptr);
698 session_->isFocused_ = true;
699 EXPECT_EQ(WSError::WS_OK, session_->UpdateFocus(false));
700 }
701
702 /**
703 * @tc.name: NotifyFocusStatus
704 * @tc.desc: NotifyFocusStatus Test
705 * @tc.type: FUNC
706 */
707 HWTEST_F(WindowSessionTest3, NotifyFocusStatus, Function | SmallTest | Level2)
708 {
709 ASSERT_NE(session_, nullptr);
710 session_->state_ = SessionState::STATE_CONNECT;
711 sptr<SessionStageMocker> mockSessionStage = sptr<SessionStageMocker>::MakeSptr();
712 EXPECT_NE(nullptr, mockSessionStage);
713 session_->sessionStage_ = mockSessionStage;
714 EXPECT_EQ(WSError::WS_OK, session_->NotifyFocusStatus(true));
715 session_->sessionStage_ = nullptr;
716 EXPECT_EQ(WSError::WS_ERROR_NULLPTR, session_->NotifyFocusStatus(true));
717 }
718
719 /**
720 * @tc.name: RequestFocus
721 * @tc.desc: RequestFocus Test
722 * @tc.type: FUNC
723 */
724 HWTEST_F(WindowSessionTest3, RequestFocus, Function | SmallTest | Level2)
725 {
726 ASSERT_NE(session_, nullptr);
727 session_->state_ = SessionState::STATE_FOREGROUND;
728 session_->sessionInfo_.isSystem_ = false;
729 EXPECT_EQ(WSError::WS_OK, session_->RequestFocus(true));
730 EXPECT_EQ(WSError::WS_OK, session_->RequestFocus(false));
731 }
732
733 /**
734 * @tc.name: UpdateWindowMode
735 * @tc.desc: UpdateWindowMode Test
736 * @tc.type: FUNC
737 */
738 HWTEST_F(WindowSessionTest3, UpdateWindowMode, Function | SmallTest | Level2)
739 {
740 ASSERT_NE(session_, nullptr);
741 sptr<SessionStageMocker> mockSessionStage = sptr<SessionStageMocker>::MakeSptr();
742 EXPECT_NE(nullptr, mockSessionStage);
743 session_->sessionStage_ = mockSessionStage;
744
745 session_->state_ = SessionState::STATE_END;
746 auto result = session_->UpdateWindowMode(WindowMode::WINDOW_MODE_UNDEFINED);
747 EXPECT_EQ(result, WSError::WS_ERROR_INVALID_SESSION);
748
749 session_->state_ = SessionState::STATE_DISCONNECT;
750 result = session_->UpdateWindowMode(WindowMode::WINDOW_MODE_UNDEFINED);
751 EXPECT_EQ(session_->property_->windowMode_, WindowMode::WINDOW_MODE_UNDEFINED);
752 EXPECT_EQ(session_->property_->isNeedUpdateWindowMode_, true);
753 EXPECT_EQ(result, WSError::WS_OK);
754
755 session_->state_ = SessionState::STATE_CONNECT;
756 result = session_->UpdateWindowMode(WindowMode::WINDOW_MODE_SPLIT_SECONDARY);
757 EXPECT_EQ(session_->property_->windowMode_, WindowMode::WINDOW_MODE_SPLIT_SECONDARY);
758 EXPECT_EQ(session_->property_->maximizeMode_, MaximizeMode::MODE_RECOVER);
759 EXPECT_EQ(result, WSError::WS_OK);
760
761 session_->state_ = SessionState::STATE_CONNECT;
762 result = session_->UpdateWindowMode(WindowMode::WINDOW_MODE_SPLIT_PRIMARY);
763 EXPECT_EQ(result, WSError::WS_OK);
764
765 session_->state_ = SessionState::STATE_CONNECT;
766 result = session_->UpdateWindowMode(WindowMode::WINDOW_MODE_UNDEFINED);
767 EXPECT_EQ(result, WSError::WS_OK);
768
769 session_->sessionStage_ = nullptr;
770 result = session_->UpdateWindowMode(WindowMode::WINDOW_MODE_UNDEFINED);
771 EXPECT_EQ(result, WSError::WS_ERROR_NULLPTR);
772 }
773
774 /**
775 * @tc.name: RectSizeCheckProcess
776 * @tc.desc: RectSizeCheckProcess Test
777 * @tc.type: FUNC
778 */
779 HWTEST_F(WindowSessionTest3, RectSizeCheckProcess, Function | SmallTest | Level2)
780 {
781 ASSERT_NE(session_, nullptr);
782 session_->RectSizeCheckProcess(1, 0, 2, 0, 0);
783 session_->RectSizeCheckProcess(1, 0, 1, 0, 0);
784 session_->RectSizeCheckProcess(0, 1, 0, 2, 0);
785 session_->RectSizeCheckProcess(0, 1, 0, 0, 0);
786 EXPECT_EQ(true, session_->CheckPointerEventDispatch(nullptr));
787 }
788
789 /**
790 * @tc.name: RectCheckProcess
791 * @tc.desc: RectCheckProcess Test
792 * @tc.type: FUNC
793 */
794 HWTEST_F(WindowSessionTest3, RectCheckProcess, Function | SmallTest | Level2)
795 {
796 ASSERT_NE(session_, nullptr);
797 session_->isVisible_ = true;
798 session_->RectCheckProcess();
799
800 session_->state_ = SessionState::STATE_FOREGROUND;
801 session_->RectCheckProcess();
802 EXPECT_EQ(true, session_->CheckPointerEventDispatch(nullptr));
803 }
804
805 /**
806 * @tc.name: RectCheckProcess01
807 * @tc.desc: RectCheckProcess01 Test
808 * @tc.type: FUNC
809 */
810 HWTEST_F(WindowSessionTest3, RectCheckProcess01, Function | SmallTest | Level2)
811 {
812 ASSERT_NE(session_, nullptr);
813 session_->state_ = SessionState::STATE_INACTIVE;
814 session_->isVisible_ = false;
815 session_->RectCheckProcess();
816
817 session_->state_ = SessionState::STATE_ACTIVE;
818 session_->isVisible_ = true;
819 session_->RectCheckProcess();
820
821 session_->property_->displayId_ = 0;
822 sptr<ScreenSession> screenSession = sptr<ScreenSession>::MakeSptr(0, ScreenProperty(), 0);
823 ASSERT_NE(screenSession, nullptr);
824 ScreenProperty screenProperty = screenSession->GetScreenProperty();
825 ASSERT_NE(&screenProperty, nullptr);
826 screenSession->screenId_ = 0;
827 screenSession->SetVirtualPixelRatio(0.0f);
828 ScreenSessionManagerClient::GetInstance().screenSessionMap_.insert(std::make_pair(0, screenSession));
829 session_->RectCheckProcess();
830
831 ScreenSessionManagerClient::GetInstance().screenSessionMap_.clear();
832 screenSession->SetVirtualPixelRatio(1.0f);
833 ScreenSessionManagerClient::GetInstance().screenSessionMap_.insert(std::make_pair(0, screenSession));
834 session_->RectCheckProcess();
835
836 WSRect rect = {0, 0, 0, 0};
837 session_->winRect_ = rect;
838 session_->RectCheckProcess();
839
840 session_->winRect_.height_ = 200;
841 session_->RectCheckProcess();
842
843 session_->aspectRatio_ = 0.0f;
844 session_->RectCheckProcess();
845
846 session_->aspectRatio_ = 0.5f;
847 session_->RectCheckProcess();
848
849 session_->winRect_.width_ = 200;
850 session_->RectCheckProcess();
851
852 session_->aspectRatio_ = 1.0f;
853 session_->RectCheckProcess();
854
855 ScreenSessionManagerClient::GetInstance().screenSessionMap_.clear();
856 }
857
858 /**
859 * @tc.name: SetAcquireRotateAnimationConfigFunc
860 * @tc.desc: SetAcquireRotateAnimationConfigFunc Test
861 * @tc.type: FUNC
862 */
863 HWTEST_F(WindowSessionTest3, SetAcquireRotateAnimationConfigFunc, Function | SmallTest | Level2)
864 {
865 ASSERT_NE(session_, nullptr);
866 session_->SetAcquireRotateAnimationConfigFunc(nullptr);
867 ASSERT_EQ(session_->acquireRotateAnimationConfigFunc_, nullptr);
868 int32_t duration = session_->GetRotateAnimationDuration();
869 ASSERT_EQ(duration, ROTATE_ANIMATION_DURATION);
870
__anon58e439300b02(RotateAnimationConfig& config) 871 AcquireRotateAnimationConfigFunc func = [](RotateAnimationConfig& config) {
872 config.duration_ = 800;
873 };
874 session_->SetAcquireRotateAnimationConfigFunc(func);
875 ASSERT_NE(session_->acquireRotateAnimationConfigFunc_, nullptr);
876 duration = session_->GetRotateAnimationDuration();
877 ASSERT_EQ(duration, 800);
878 }
879
880 /**
881 * @tc.name: SetIsPcAppInPad
882 * @tc.desc: SetIsPcAppInPad Test
883 * @tc.type: FUNC
884 */
885 HWTEST_F(WindowSessionTest3, SetIsPcAppInPad, Function | SmallTest | Level2)
886 {
887 ASSERT_NE(session_, nullptr);
888 bool isPcAppInPad = false;
889 auto result = session_->SetIsPcAppInPad(isPcAppInPad);
890 EXPECT_EQ(result, WSError::WS_OK);
891 }
892
893 /**
894 * @tc.name: SetBufferAvailable
895 * @tc.desc: SetBufferAvailable Test
896 * @tc.type: FUNC
897 */
898 HWTEST_F(WindowSessionTest3, SetBufferAvailable, Function | SmallTest | Level2)
899 {
900 int resultValue = 0;
__anon58e439300c02(const bool isAvailable) 901 NotifyBufferAvailableChangeFunc func = [&resultValue](const bool isAvailable) {
902 resultValue = 1;
903 };
904 session_->SetBufferAvailableChangeListener(func);
905 session_->SetBufferAvailable(true);
906 ASSERT_EQ(session_->bufferAvailable_, true);
907 }
908
909 /**
910 * @tc.name: NotifySessionInfoChange
911 * @tc.desc: NotifySessionInfoChange Test
912 * @tc.type: FUNC
913 */
914 HWTEST_F(WindowSessionTest3, NotifySessionInfoChange, Function | SmallTest | Level2)
915 {
916 int resultValue = 0;
__anon58e439300d02(const bool isAvailable) 917 NotifyBufferAvailableChangeFunc func = [&resultValue](const bool isAvailable) {
918 resultValue = 1;
919 };
920 session_->SetSessionInfoChangeNotifyManagerListener(func);
921 session_->NotifySessionInfoChange();
922 ASSERT_EQ(resultValue, 1);
923 }
924
925 /**
926 * @tc.name: SetCompatibleModeEnableInPad
927 * @tc.desc: SetCompatibleModeEnableInPad Test
928 * @tc.type: FUNC
929 */
930 HWTEST_F(WindowSessionTest3, SetCompatibleModeEnableInPad, Function | SmallTest | Level2)
931 {
932 ASSERT_NE(session_, nullptr);
933 session_->state_ = SessionState::STATE_FOREGROUND;
934 sptr<SessionStageMocker> mockSessionStage = sptr<SessionStageMocker>::MakeSptr();
935 bool enable = true;
936 session_->sessionStage_ = nullptr;
937 ASSERT_EQ(WSError::WS_ERROR_NULLPTR, session_->SetCompatibleModeEnableInPad(enable));
938
939 ASSERT_NE(nullptr, mockSessionStage);
940 session_->sessionStage_ = mockSessionStage;
941 ASSERT_EQ(WSError::WS_OK, session_->SetCompatibleModeEnableInPad(enable));
942
943 enable = false;
944 ASSERT_EQ(WSError::WS_OK, session_->SetCompatibleModeEnableInPad(enable));
945 }
946
947 /**
948 * @tc.name: GetSurfaceNodeForMoveDrag
949 * @tc.desc: GetSurfaceNodeForMoveDrag Test
950 * @tc.type: FUNC
951 */
952 HWTEST_F(WindowSessionTest3, GetSurfaceNodeForMoveDrag, Function | SmallTest | Level2)
953 {
954 ASSERT_NE(session_, nullptr);
955 session_->leashWinSurfaceNode_ = nullptr;
956 session_->surfaceNode_ = nullptr;
957 std::shared_ptr<RSSurfaceNode> res = session_->GetSurfaceNodeForMoveDrag();
958 ASSERT_EQ(res, nullptr);
959 }
960
961 /**
962 * @tc.name: CompatibleFullScreenRecover
963 * @tc.desc: CompatibleFullScreenRecover Test
964 * @tc.type: FUNC
965 */
966 HWTEST_F(WindowSessionTest3, CompatibleFullScreenRecover, Function | SmallTest | Level2)
967 {
968 ASSERT_NE(session_, nullptr);
969 sptr<SessionStageMocker> mockSessionStage = sptr<SessionStageMocker>::MakeSptr();
970 ASSERT_NE(nullptr, mockSessionStage);
971 session_->sessionStage_ = mockSessionStage;
972 session_->sessionInfo_.isSystem_ = true;
973 auto result = session_->CompatibleFullScreenRecover();
974 ASSERT_EQ(result, WSError::WS_ERROR_INVALID_SESSION);
975
976 session_->sessionInfo_.isSystem_ = false;
977 session_->SetSessionState(SessionState::STATE_FOREGROUND);
978 result = session_->CompatibleFullScreenRecover();
979 ASSERT_EQ(result, WSError::WS_OK);
980 }
981
982 /**
983 * @tc.name: CompatibleFullScreenMinimize
984 * @tc.desc: CompatibleFullScreenMinimize Test
985 * @tc.type: FUNC
986 */
987 HWTEST_F(WindowSessionTest3, CompatibleFullScreenMinimize, Function | SmallTest | Level2)
988 {
989 ASSERT_NE(session_, nullptr);
990 sptr<SessionStageMocker> mockSessionStage = sptr<SessionStageMocker>::MakeSptr();
991 ASSERT_NE(nullptr, mockSessionStage);
992 session_->sessionStage_ = mockSessionStage;
993 session_->sessionInfo_.isSystem_ = true;
994 auto result = session_->CompatibleFullScreenMinimize();
995 ASSERT_EQ(result, WSError::WS_ERROR_INVALID_SESSION);
996
997 session_->sessionInfo_.isSystem_ = false;
998 session_->SetSessionState(SessionState::STATE_FOREGROUND);
999 result = session_->CompatibleFullScreenMinimize();
1000 ASSERT_EQ(result, WSError::WS_OK);
1001 }
1002
1003 /**
1004 * @tc.name: CompatibleFullScreenClose
1005 * @tc.desc: CompatibleFullScreenClose Test
1006 * @tc.type: FUNC
1007 */
1008 HWTEST_F(WindowSessionTest3, CompatibleFullScreenClose, Function | SmallTest | Level2)
1009 {
1010 ASSERT_NE(session_, nullptr);
1011 sptr<SessionStageMocker> mockSessionStage = sptr<SessionStageMocker>::MakeSptr();
1012 ASSERT_NE(nullptr, mockSessionStage);
1013 session_->sessionStage_ = mockSessionStage;
1014 session_->sessionInfo_.isSystem_ = true;
1015 auto result = session_->CompatibleFullScreenClose();
1016 ASSERT_EQ(result, WSError::WS_ERROR_INVALID_SESSION);
1017
1018 session_->sessionInfo_.isSystem_ = false;
1019 session_->SetSessionState(SessionState::STATE_FOREGROUND);
1020 result = session_->CompatibleFullScreenClose();
1021 ASSERT_EQ(result, WSError::WS_OK);
1022 }
1023
1024 /**
1025 * @tc.name: PcAppInPadNormalClose
1026 * @tc.desc: PcAppInPadNormalClose Test
1027 * @tc.type: FUNC
1028 */
1029 HWTEST_F(WindowSessionTest3, PcAppInPadNormalClose, Function | SmallTest | Level2)
1030 {
1031 ASSERT_NE(session_, nullptr);
1032
1033 session_->sessionInfo_.isSystem_ = true;
1034 auto result = session_->PcAppInPadNormalClose();
1035 ASSERT_EQ(result, WSError::WS_ERROR_INVALID_SESSION);
1036
1037 session_->sessionInfo_.isSystem_ = false;
1038 session_->SetSessionState(SessionState::STATE_FOREGROUND);
1039 result = session_->PcAppInPadNormalClose();
1040 ASSERT_EQ(result, WSError::WS_ERROR_NULLPTR);
1041
1042 sptr<SessionStageMocker> mockSessionStage = sptr<SessionStageMocker>::MakeSptr();
1043 ASSERT_NE(nullptr, mockSessionStage);
1044 session_->sessionStage_ = mockSessionStage;
1045 result = session_->PcAppInPadNormalClose();
1046 ASSERT_EQ(result, WSError::WS_OK);
1047 }
1048
1049 /**
1050 * @tc.name: GetSnapshotPixelMap
1051 * @tc.desc: GetSnapshotPixelMap Test
1052 * @tc.type: FUNC
1053 */
1054 HWTEST_F(WindowSessionTest3, GetSnapshotPixelMap, Function | SmallTest | Level2)
1055 {
1056 session_->scenePersistence_ = nullptr;
1057 EXPECT_EQ(nullptr, session_->GetSnapshotPixelMap(6.6f, 8.8f));
1058 session_->scenePersistence_ = sptr<ScenePersistence>::MakeSptr("GetSnapshotPixelMap", 2024);
1059 EXPECT_NE(nullptr, session_->scenePersistence_);
1060 session_->scenePersistence_->isSavingSnapshot_.store(true);
1061 session_->snapshot_ = nullptr;
1062 EXPECT_EQ(nullptr, session_->GetSnapshotPixelMap(6.6f, 8.8f));
1063 }
1064
1065 /**
1066 * @tc.name: ResetDirtyFlags
1067 * @tc.desc: ResetDirtyFlags Test
1068 * @tc.type: FUNC
1069 */
1070 HWTEST_F(WindowSessionTest3, ResetDirtyFlags, Function | SmallTest | Level2)
1071 {
1072 session_->isVisible_ = false;
1073 session_->dirtyFlags_ = 96;
1074 session_->ResetDirtyFlags();
1075 EXPECT_EQ(64, session_->dirtyFlags_);
1076
1077 session_->isVisible_ = true;
1078 session_->dirtyFlags_ = 16;
1079 session_->ResetDirtyFlags();
1080 EXPECT_EQ(0, session_->dirtyFlags_);
1081 }
1082
1083 /**
1084 * @tc.name: SetMainSessionUIStateDirty
1085 * @tc.desc: SetMainSessionUIStateDirty Test
1086 * @tc.type: FUNC
1087 */
1088 HWTEST_F(WindowSessionTest3, SetMainSessionUIStateDirty, Function | SmallTest | Level2)
1089 {
1090 SessionInfo infoDirty;
1091 infoDirty.abilityName_ = "SetMainSessionUIStateDirty";
1092 infoDirty.moduleName_ = "SetMainSessionUIStateDirty";
1093 infoDirty.bundleName_ = "SetMainSessionUIStateDirty";
1094 infoDirty.windowType_ = static_cast<uint32_t>(WindowType::APP_MAIN_WINDOW_END);
1095 sptr<Session> sessionDirty = sptr<Session>::MakeSptr(infoDirty);
1096 EXPECT_NE(nullptr, sessionDirty);
1097
1098 session_->parentSession_ = nullptr;
1099 EXPECT_EQ(nullptr, session_->GetParentSession());
1100 sessionDirty->SetUIStateDirty(false);
1101 session_->SetMainSessionUIStateDirty(false);
1102 EXPECT_EQ(false, sessionDirty->GetUIStateDirty());
1103
1104 session_->SetParentSession(sessionDirty);
1105 EXPECT_EQ(sessionDirty, session_->GetParentSession());
1106 session_->SetMainSessionUIStateDirty(false);
1107 EXPECT_EQ(false, sessionDirty->GetUIStateDirty());
1108
1109 infoDirty.windowType_ = static_cast<uint32_t>(WindowType::APP_MAIN_WINDOW_BASE);
1110 sptr<Session> sessionUIState = sptr<Session>::MakeSptr(infoDirty);
1111 EXPECT_NE(nullptr, sessionUIState);
1112 session_->SetParentSession(sessionUIState);
1113 session_->SetMainSessionUIStateDirty(true);
1114 EXPECT_EQ(true, sessionUIState->GetUIStateDirty());
1115 }
1116
1117 /**
1118 * @tc.name: SetStartingBeforeVisible
1119 * @tc.desc: test SetStartingBeforeVisible
1120 * @tc.type: FUNC
1121 */
1122 HWTEST_F(WindowSessionTest3, SetStartingBeforeVisible, Function | SmallTest | Level2)
1123 {
1124 ASSERT_NE(session_, nullptr);
1125 session_->SetStartingBeforeVisible(true);
1126 ASSERT_EQ(true, session_->isStartingBeforeVisible_);
1127 ASSERT_EQ(true, session_->GetStartingBeforeVisible());
1128
1129 session_->SetStartingBeforeVisible(false);
1130 ASSERT_EQ(false, session_->isStartingBeforeVisible_);
1131 ASSERT_EQ(false, session_->GetStartingBeforeVisible());
1132 }
1133
1134 /**
1135 * @tc.name: GetScreenId
1136 * @tc.desc: test func: GetScreenId
1137 * @tc.type: FUNC
1138 */
1139 HWTEST_F(WindowSessionTest3, GetScreenId, Function | SmallTest | Level2)
1140 {
1141 ASSERT_NE(session_, nullptr);
1142 session_->sessionInfo_.screenId_ = 100;
1143 ASSERT_EQ(session_->GetScreenId(), 100);
1144 }
1145
1146 /**
1147 * @tc.name: SetFreezeImmediately
1148 * @tc.desc: SetFreezeImmediately Test
1149 * @tc.type: FUNC
1150 */
1151 HWTEST_F(WindowSessionTest3, SetFreezeImmediately, Function | SmallTest | Level2)
1152 {
1153 ASSERT_NE(session_, nullptr);
1154 struct RSSurfaceNodeConfig config;
1155 session_->surfaceNode_ = RSSurfaceNode::Create(config);
1156 ASSERT_NE(session_->surfaceNode_, nullptr);
1157 ASSERT_EQ(nullptr, session_->SetFreezeImmediately(1.0f, false, 1.0f));
1158 session_->surfaceNode_->bufferAvailable_ = true;
1159 ASSERT_EQ(nullptr, session_->SetFreezeImmediately(1.0f, false, 1.0f));
1160 ASSERT_EQ(nullptr, session_->SetFreezeImmediately(1.0f, true, 1.0f));
1161 session_->surfaceNode_ = nullptr;
1162 ASSERT_EQ(nullptr, session_->SetFreezeImmediately(1.0f, false, 1.0f));
1163 }
1164
1165 /**
1166 * @tc.name: GetIsHighlighted
1167 * @tc.desc: GetIsHighlighted Test
1168 * @tc.type: FUNC
1169 */
1170 HWTEST_F(WindowSessionTest3, GetIsHighlighted, Function | SmallTest | Level2)
1171 {
1172 ASSERT_NE(session_, nullptr);
1173 bool isHighlighted = false;
1174 ASSERT_EQ(session_->GetIsHighlighted(isHighlighted), WSError::WS_OK);
1175 ASSERT_EQ(isHighlighted, false);
1176 }
1177 }
1178 } // namespace Rosen
1179 } // namespace OHOS
1180