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