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 "iremote_object_mocker.h"
22 #include "key_event.h"
23 #include "mock/mock_session.h"
24 #include "mock/mock_session_stage.h"
25 #include "mock/mock_window_event_channel.h"
26 #include "mock/mock_pattern_detach_callback.h"
27 #include "session/host/include/extension_session.h"
28 #include "session/host/include/move_drag_controller.h"
29 #include "session/host/include/scene_session.h"
30 #include "session_manager/include/scene_session_manager.h"
31 #include "session/host/include/session.h"
32 #include "session_info.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 constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowSessionTest4" };
44 } // namespace
45 namespace {
46 std::string g_logMsg;
SessionTest4LogCallBack(const LogType type,const LogLevel level,const unsigned int domain,const char * tag,const char * msg)47 void SessionTest4LogCallBack(const LogType type,
48 const LogLevel level,
49 const unsigned int domain,
50 const char* tag,
51 const char* msg)
52 {
53 g_logMsg = msg;
54 }
55 } // namespace
56 class WindowSessionTest4 : public testing::Test {
57 public:
58 static void SetUpTestCase();
59 static void TearDownTestCase();
60 void SetUp() override;
61 void TearDown() override;
62 int32_t GetTaskCount();
63 sptr<SceneSessionManager> ssm_;
64
65 private:
66 RSSurfaceNode::SharedPtr CreateRSSurfaceNode();
67 sptr<Session> session_ = nullptr;
68 static constexpr uint32_t waitSyncInNs_ = 500000;
69 };
70
SetUpTestCase()71 void WindowSessionTest4::SetUpTestCase() {}
72
TearDownTestCase()73 void WindowSessionTest4::TearDownTestCase() {}
74
SetUp()75 void WindowSessionTest4::SetUp()
76 {
77 SessionInfo info;
78 info.abilityName_ = "testSession1";
79 info.moduleName_ = "testSession2";
80 info.bundleName_ = "testSession4";
81 session_ = sptr<Session>::MakeSptr(info);
82 session_->surfaceNode_ = CreateRSSurfaceNode();
83 EXPECT_NE(nullptr, session_);
84 ssm_ = sptr<SceneSessionManager>::MakeSptr();
85 session_->SetEventHandler(ssm_->taskScheduler_->GetEventHandler(), ssm_->eventHandler_);
86 auto isScreenLockedCallback = [this]() { return ssm_->IsScreenLocked(); };
87 session_->RegisterIsScreenLockedCallback(isScreenLockedCallback);
88 }
89
TearDown()90 void WindowSessionTest4::TearDown()
91 {
92 session_ = nullptr;
93 usleep(waitSyncInNs_);
94 }
95
CreateRSSurfaceNode()96 RSSurfaceNode::SharedPtr WindowSessionTest4::CreateRSSurfaceNode()
97 {
98 struct RSSurfaceNodeConfig rsSurfaceNodeConfig;
99 rsSurfaceNodeConfig.SurfaceNodeName = "WindowSessionTest4SurfaceNode";
100 auto surfaceNode = RSSurfaceNode::Create(rsSurfaceNodeConfig);
101 if (surfaceNode == nullptr) {
102 GTEST_LOG_(INFO) << "WindowSessionTest4::CreateRSSurfaceNode surfaceNode is nullptr";
103 }
104 return surfaceNode;
105 }
106
GetTaskCount()107 int32_t WindowSessionTest4::GetTaskCount()
108 {
109 std::string dumpInfo = session_->handler_->GetEventRunner()->GetEventQueue()->DumpCurrentQueueSize();
110 std::regex pattern("\\d+");
111 std::smatch matches;
112 int32_t taskNum = 0;
113 while (std::regex_search(dumpInfo, matches, pattern)) {
114 taskNum += std::stoi(matches.str());
115 dumpInfo = matches.suffix();
116 }
117 return taskNum;
118 }
119
120 namespace {
121 /**
122 * @tc.name: SetShowRecent001
123 * @tc.desc: Exist detect task when in recent.
124 * @tc.type: FUNC
125 */
126 HWTEST_F(WindowSessionTest4, SetShowRecent001, TestSize.Level1)
127 {
128 std::string taskName = "wms:WindowStateDetect" + std::to_string(session_->persistentId_);
__anonc00021d30502() 129 auto task = []() {};
130 int64_t delayTime = 3000;
131 session_->handler_->PostTask(task, taskName, delayTime);
132 int32_t beforeTaskNum = GetTaskCount();
133
134 session_->SetShowRecent(true);
135 ASSERT_EQ(beforeTaskNum, GetTaskCount());
136 session_->handler_->RemoveTask(taskName);
137 }
138
139 /**
140 * @tc.name: SetShowRecent002
141 * @tc.desc: SetShowRecent:showRecent is false, showRecent_ is false.
142 * @tc.type: FUNC
143 */
144 HWTEST_F(WindowSessionTest4, SetShowRecent002, TestSize.Level1)
145 {
146 std::string taskName = "wms:WindowStateDetect" + std::to_string(session_->persistentId_);
__anonc00021d30602() 147 auto task = []() {};
148 int64_t delayTime = 3000;
149 session_->handler_->PostTask(task, taskName, delayTime);
150 session_->showRecent_ = false;
151 int32_t beforeTaskNum = GetTaskCount();
152
153 session_->SetShowRecent(false);
154 ASSERT_EQ(beforeTaskNum, GetTaskCount());
155 session_->handler_->RemoveTask(taskName);
156 }
157
158 /**
159 * @tc.name: SetShowRecent003
160 * @tc.desc: SetShowRecent:showRecent is false, showRecent_ is true, detach task.
161 * @tc.type: FUNC
162 */
163 HWTEST_F(WindowSessionTest4, SetShowRecent003, TestSize.Level1)
164 {
165 std::string taskName = "wms:WindowStateDetect" + std::to_string(session_->persistentId_);
__anonc00021d30702() 166 auto task = []() {};
167 int64_t delayTime = 3000;
168 session_->handler_->PostTask(task, taskName, delayTime);
169 session_->showRecent_ = true;
170 session_->isAttach_ = false;
171 int32_t beforeTaskNum = GetTaskCount();
172
173 session_->SetShowRecent(false);
174 ASSERT_EQ(beforeTaskNum, GetTaskCount());
175 session_->handler_->RemoveTask(taskName);
176 }
177
178 /**
179 * @tc.name: SetShowRecent004
180 * @tc.desc: SetShowRecent
181 * @tc.type: FUNC
182 */
183 HWTEST_F(WindowSessionTest4, SetShowRecent004, TestSize.Level1)
184 {
185 session_->systemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
186 ssm_->SetScreenLocked(false);
187 sleep(1);
188
189 session_->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
190
191 bool showRecent = false;
192 session_->showRecent_ = true;
193 session_->SetAttachState(true);
194 session_->SetShowRecent(showRecent);
195 ASSERT_EQ(session_->GetShowRecent(), showRecent);
196 }
197
198 /**
199 * @tc.name: CreateDetectStateTask001
200 * @tc.desc: Create detection task when there are no pre_existing tasks.
201 * @tc.type: FUNC
202 */
203 HWTEST_F(WindowSessionTest4, CreateDetectStateTask001, TestSize.Level1)
204 {
205 session_->systemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
206 std::string taskName = "wms:WindowStateDetect" + std::to_string(session_->persistentId_);
207 DetectTaskInfo detectTaskInfo;
208 detectTaskInfo.taskState = DetectTaskState::NO_TASK;
209 int32_t beforeTaskNum = GetTaskCount();
210 session_->SetDetectTaskInfo(detectTaskInfo);
211 session_->CreateDetectStateTask(false, WindowMode::WINDOW_MODE_FULLSCREEN);
212
213 ASSERT_EQ(beforeTaskNum + 1, GetTaskCount());
214 ASSERT_EQ(DetectTaskState::DETACH_TASK, session_->GetDetectTaskInfo().taskState);
215 session_->handler_->RemoveTask(taskName);
216
217 session_->showRecent_ = true;
218 session_->CreateDetectStateTask(false, WindowMode::WINDOW_MODE_FULLSCREEN);
219 }
220
221 /**
222 * @tc.name: CreateDetectStateTask002
223 * @tc.desc: Detect state when window mode changed.
224 * @tc.type: FUNC
225 */
226 HWTEST_F(WindowSessionTest4, CreateDetectStateTask002, TestSize.Level1)
227 {
228 session_->systemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
229 std::string taskName = "wms:WindowStateDetect" + std::to_string(session_->persistentId_);
__anonc00021d30802() 230 auto task = []() {};
231 int64_t delayTime = 3000;
232 session_->handler_->PostTask(task, taskName, delayTime);
233 int32_t beforeTaskNum = GetTaskCount();
234
235 DetectTaskInfo detectTaskInfo;
236 detectTaskInfo.taskState = DetectTaskState::DETACH_TASK;
237 detectTaskInfo.taskWindowMode = WindowMode::WINDOW_MODE_FULLSCREEN;
238 session_->SetDetectTaskInfo(detectTaskInfo);
239 session_->CreateDetectStateTask(true, WindowMode::WINDOW_MODE_SPLIT_SECONDARY);
240
241 ASSERT_EQ(beforeTaskNum - 1, GetTaskCount());
242 ASSERT_EQ(DetectTaskState::NO_TASK, session_->GetDetectTaskInfo().taskState);
243 ASSERT_EQ(WindowMode::WINDOW_MODE_UNDEFINED, session_->GetDetectTaskInfo().taskWindowMode);
244 session_->handler_->RemoveTask(taskName);
245
246 session_->showRecent_ = true;
247 session_->CreateDetectStateTask(false, WindowMode::WINDOW_MODE_SPLIT_SECONDARY);
248 }
249
250 /**
251 * @tc.name: CreateDetectStateTask003
252 * @tc.desc: Detect sup and down tree tasks for the same type.
253 * @tc.type: FUNC
254 */
255 HWTEST_F(WindowSessionTest4, CreateDetectStateTask003, TestSize.Level1)
256 {
257 session_->systemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
258 std::string taskName = "wms:WindowStateDetect" + std::to_string(session_->persistentId_);
259 DetectTaskInfo detectTaskInfo;
260 detectTaskInfo.taskState = DetectTaskState::DETACH_TASK;
261 detectTaskInfo.taskWindowMode = WindowMode::WINDOW_MODE_FULLSCREEN;
262 session_->SetDetectTaskInfo(detectTaskInfo);
263 session_->CreateDetectStateTask(true, WindowMode::WINDOW_MODE_SPLIT_SECONDARY);
264 ASSERT_EQ(DetectTaskState::NO_TASK, session_->GetDetectTaskInfo().taskState);
265 session_->handler_->RemoveTask(taskName);
266
267 session_->showRecent_ = true;
268 session_->CreateDetectStateTask(false, WindowMode::WINDOW_MODE_SPLIT_SECONDARY);
269 }
270
271 /**
272 * @tc.name: CreateDetectStateTask004
273 * @tc.desc: Detection tasks under the same window mode.
274 * @tc.type: FUNC
275 */
276 HWTEST_F(WindowSessionTest4, CreateDetectStateTask004, TestSize.Level1)
277 {
278 session_->systemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
279 std::string taskName = "wms:WindowStateDetect" + std::to_string(session_->persistentId_);
280 DetectTaskInfo detectTaskInfo;
281 int32_t beforeTaskNum = GetTaskCount();
282 detectTaskInfo.taskState = DetectTaskState::DETACH_TASK;
283 detectTaskInfo.taskWindowMode = WindowMode::WINDOW_MODE_FULLSCREEN;
284 session_->SetDetectTaskInfo(detectTaskInfo);
285 session_->CreateDetectStateTask(true, WindowMode::WINDOW_MODE_FULLSCREEN);
286
287 ASSERT_EQ(beforeTaskNum + 1, GetTaskCount());
288 ASSERT_EQ(DetectTaskState::ATTACH_TASK, session_->GetDetectTaskInfo().taskState);
289 session_->handler_->RemoveTask(taskName);
290
291 session_->showRecent_ = true;
292 session_->CreateDetectStateTask(false, WindowMode::WINDOW_MODE_FULLSCREEN);
293 }
294
295 /**
296 * @tc.name: GetAttachState001
297 * @tc.desc: GetAttachState001
298 * @tc.type: FUNC
299 */
300 HWTEST_F(WindowSessionTest4, GetAttachState001, TestSize.Level1)
301 {
302 std::string taskName = "wms:WindowStateDetect" + std::to_string(session_->persistentId_);
303 session_->SetAttachState(false);
304 bool isAttach = session_->GetAttachState();
305 ASSERT_EQ(false, isAttach);
306 session_->handler_->RemoveTask(taskName);
307 }
308
309 /**
310 * @tc.name: ResetSessionConnectState
311 * @tc.desc: ResetSessionConnectState
312 * @tc.type: FUNC
313 */
314 HWTEST_F(WindowSessionTest4, ResetSessionConnectState, TestSize.Level1)
315 {
316 ASSERT_NE(session_, nullptr);
317 session_->ResetSessionConnectState();
318 ASSERT_EQ(session_->state_, SessionState::STATE_DISCONNECT);
319 ASSERT_EQ(session_->GetCallingPid(), -1);
320 }
321
322 /**
323 * @tc.name: ResetIsActive
324 * @tc.desc: ResetIsActive
325 * @tc.type: FUNC
326 */
327 HWTEST_F(WindowSessionTest4, ResetIsActive, TestSize.Level1)
328 {
329 ASSERT_NE(session_, nullptr);
330 session_->ResetIsActive();
331 ASSERT_EQ(session_->isActive_, false);
332 }
333
334 /**
335 * @tc.name: PostExportTask02
336 * @tc.desc: PostExportTask
337 * @tc.type: FUNC
338 */
339 HWTEST_F(WindowSessionTest4, PostExportTask02, TestSize.Level1)
340 {
341 ASSERT_NE(session_, nullptr);
342 std::string name = "sessionExportTask";
__anonc00021d30902() 343 auto task = []() {};
344 int64_t delayTime = 0;
345
346 session_->PostExportTask(task, name, delayTime);
347 auto result = session_->GetBufferAvailable();
348 ASSERT_EQ(result, false);
349
350 sptr<SceneSessionManager> sceneSessionManager = sptr<SceneSessionManager>::MakeSptr();
351 session_->SetEventHandler(sceneSessionManager->taskScheduler_->GetEventHandler(),
352 sceneSessionManager->eventHandler_);
353 session_->PostExportTask(task, name, delayTime);
354 auto result2 = session_->GetBufferAvailable();
355 ASSERT_EQ(result2, false);
356 }
357
358 /**
359 * @tc.name: SetLeashWinSurfaceNode02
360 * @tc.desc: SetLeashWinSurfaceNode
361 * @tc.type: FUNC
362 */
363 HWTEST_F(WindowSessionTest4, SetLeashWinSurfaceNode02, TestSize.Level1)
364 {
365 ASSERT_NE(session_, nullptr);
366 session_->leashWinSurfaceNode_ = WindowSessionTest4::CreateRSSurfaceNode();
367 session_->SetLeashWinSurfaceNode(nullptr);
368
369 session_->leashWinSurfaceNode_ = nullptr;
370 session_->SetLeashWinSurfaceNode(nullptr);
371 auto result = session_->GetBufferAvailable();
372 ASSERT_EQ(result, false);
373 }
374
375 /**
376 * @tc.name: GetCloseAbilityWantAndClean
377 * @tc.desc: GetCloseAbilityWantAndClean
378 * @tc.type: FUNC
379 */
380 HWTEST_F(WindowSessionTest4, GetCloseAbilityWantAndClean, TestSize.Level1)
381 {
382 ASSERT_NE(session_, nullptr);
383 AAFwk::Want outWant;
384 session_->sessionInfo_.closeAbilityWant = std::make_shared<AAFwk::Want>();
385 session_->GetCloseAbilityWantAndClean(outWant);
386
387 session_->sessionInfo_.closeAbilityWant = nullptr;
388 session_->GetCloseAbilityWantAndClean(outWant);
389 auto result = session_->GetBufferAvailable();
390 ASSERT_EQ(result, false);
391 }
392
393 /**
394 * @tc.name: SetScreenId02
395 * @tc.desc: SetScreenId Test
396 * @tc.type: FUNC
397 */
398 HWTEST_F(WindowSessionTest4, SetScreenId02, TestSize.Level1)
399 {
400 ASSERT_NE(session_, nullptr);
401 uint64_t screenId = 0;
402 session_->sessionStage_ = sptr<SessionStageMocker>::MakeSptr();
403 session_->SetScreenId(screenId);
404 ASSERT_EQ(0, session_->sessionInfo_.screenId_);
405 }
406
407 /**
408 * @tc.name: SetSessionState
409 * @tc.desc: SetSessionState
410 * @tc.type: FUNC
411 */
412 HWTEST_F(WindowSessionTest4, SetSessionState, TestSize.Level1)
413 {
414 ASSERT_NE(session_, nullptr);
415
416 SessionState state03 = SessionState::STATE_CONNECT;
417 session_->SetSessionState(state03);
418 ASSERT_EQ(state03, session_->state_);
419 }
420
421 /**
422 * @tc.name: SetFocusable03
423 * @tc.desc: SetFocusable
424 * @tc.type: FUNC
425 */
426 HWTEST_F(WindowSessionTest4, SetFocusable03, TestSize.Level1)
427 {
428 ASSERT_NE(session_, nullptr);
429 session_->isFocused_ = true;
430 session_->property_->focusable_ = false;
431 bool isFocusable = true;
432
433 auto result = session_->SetFocusable(isFocusable);
434 ASSERT_EQ(result, WSError::WS_OK);
435 ASSERT_EQ(session_->GetFocusable(), true);
436 }
437
438 /**
439 * @tc.name: GetFocused
440 * @tc.desc: GetFocused Test
441 * @tc.type: FUNC
442 */
443 HWTEST_F(WindowSessionTest4, GetFocused, TestSize.Level1)
444 {
445 ASSERT_NE(session_, nullptr);
446 bool result = session_->GetFocused();
447 ASSERT_EQ(result, false);
448
449 session_->isFocused_ = true;
450 bool result2 = session_->GetFocused();
451 ASSERT_EQ(result2, true);
452 }
453
454 /**
455 * @tc.name: UpdatePointerArea
456 * @tc.desc: UpdatePointerArea Test
457 * @tc.type: FUNC
458 */
459 HWTEST_F(WindowSessionTest4, UpdatePointerArea, TestSize.Level1)
460 {
461 ASSERT_NE(session_, nullptr);
462 WSRect rect = { 0, 0, 0, 0 };
463 session_->preRect_ = rect;
464 session_->UpdatePointerArea(rect);
465 ASSERT_EQ(session_->GetFocused(), false);
466 }
467
468 /**
469 * @tc.name: UpdateSizeChangeReason02
470 * @tc.desc: UpdateSizeChangeReason Test
471 * @tc.type: FUNC
472 */
473 HWTEST_F(WindowSessionTest4, UpdateSizeChangeReason02, TestSize.Level1)
474 {
475 ASSERT_NE(session_, nullptr);
476 SizeChangeReason reason = SizeChangeReason::UNDEFINED;
477 WSError result = session_->UpdateSizeChangeReason(reason);
478 ASSERT_EQ(result, WSError::WS_DO_NOTHING);
479 }
480
481 /**
482 * @tc.name: UpdateDensity
483 * @tc.desc: UpdateDensity Test
484 * @tc.type: FUNC
485 */
486 HWTEST_F(WindowSessionTest4, UpdateDensity, TestSize.Level1)
487 {
488 ASSERT_NE(session_, nullptr);
489
490 session_->state_ = SessionState::STATE_DISCONNECT;
491 ASSERT_FALSE(session_->IsSessionValid());
492 WSError result = session_->UpdateDensity();
493 ASSERT_EQ(result, WSError::WS_ERROR_INVALID_SESSION);
494
495 session_->state_ = SessionState::STATE_CONNECT;
496 ASSERT_TRUE(session_->IsSessionValid());
497 session_->sessionStage_ = nullptr;
498 WSError result02 = session_->UpdateDensity();
499 ASSERT_EQ(result02, WSError::WS_ERROR_NULLPTR);
500 }
501
502 /**
503 * @tc.name: UpdateSizeChangeReason
504 * @tc.desc: UpdateSizeChangeReason UpdateDensity
505 * @tc.type: FUNC
506 */
507 HWTEST_F(WindowSessionTest4, UpdateSizeChangeReason, TestSize.Level1)
508 {
509 SizeChangeReason reason = SizeChangeReason{ 1 };
510 ASSERT_EQ(session_->UpdateSizeChangeReason(reason), WSError::WS_OK);
511 }
512
513 /**
514 * @tc.name: SetPendingSessionActivationEventListener
515 * @tc.desc: SetPendingSessionActivationEventListener
516 * @tc.type: FUNC
517 */
518 HWTEST_F(WindowSessionTest4, SetPendingSessionActivationEventListener, TestSize.Level1)
519 {
520 int resultValue = 0;
__anonc00021d30a02(const SessionInfo& info) 521 session_->SetPendingSessionActivationEventListener([&resultValue](const SessionInfo& info) { resultValue = 1; });
522 usleep(waitSyncInNs_);
__anonc00021d30b02(const SessionInfo& info) 523 session_->SetTerminateSessionListener([&resultValue](const SessionInfo& info) { resultValue = 2; });
524 usleep(waitSyncInNs_);
525 LifeCycleTaskType taskType = LifeCycleTaskType{ 0 };
526 session_->RemoveLifeCycleTask(taskType);
527 ASSERT_EQ(resultValue, 0);
528 }
529
530 /**
531 * @tc.name: SetSessionIcon
532 * @tc.desc: SetSessionIcon UpdateDensity
533 * @tc.type: FUNC
534 */
535 HWTEST_F(WindowSessionTest4, SetSessionIcon, TestSize.Level1)
536 {
537 std::shared_ptr<Media::PixelMap> icon;
538 session_->SetSessionIcon(icon);
539 ASSERT_EQ(session_->Clear(), WSError::WS_OK);
540 session_->SetSessionSnapshotListener(nullptr);
__anonc00021d30c02(const SessionInfo& info) 541 NotifyPendingSessionActivationFunc func = [](const SessionInfo& info) {};
542 session_->pendingSessionActivationFunc_ = func;
543 ASSERT_EQ(session_->PendingSessionToForeground(), WSError::WS_OK);
544
545 session_->scenePersistence_ = sptr<ScenePersistence>::MakeSptr("SetSessionIcon", 1);
546 session_->updateSessionIconFunc_ = nullptr;
547 ASSERT_EQ(WSError::WS_OK, session_->SetSessionIcon(icon));
548
__anonc00021d30d02(const std::string& iconPath) 549 NofitySessionIconUpdatedFunc func2 = [](const std::string& iconPath) {};
550 session_->updateSessionIconFunc_ = func2;
551 ASSERT_EQ(WSError::WS_OK, session_->SetSessionIcon(icon));
552
553 NotifyTerminateSessionFuncNew func3 =
__anonc00021d30e02(const SessionInfo& info, bool needStartCaller, bool isFromBroker, bool isForceClean) 554 [](const SessionInfo& info, bool needStartCaller, bool isFromBroker, bool isForceClean) {};
555 session_->terminateSessionFuncNew_ = func3;
556 ASSERT_EQ(WSError::WS_OK, session_->Clear());
557 }
558
559 /**
560 * @tc.name: SetSessionExceptionListener
561 * @tc.desc: SetSessionExceptionListener
562 * @tc.type: FUNC
563 */
564 HWTEST_F(WindowSessionTest4, SetSessionExceptionListener, TestSize.Level1)
565 {
566 session_->SetSessionExceptionListener(nullptr, true);
567 session_->SetSessionExceptionListener(
__anonc00021d30f02(const SessionInfo& info, const ExceptionInfo& exceptionInfo, bool startFail) 568 [](const SessionInfo& info, const ExceptionInfo& exceptionInfo, bool startFail) {}, true);
569 usleep(waitSyncInNs_);
570 ASSERT_NE(nullptr, session_->jsSceneSessionExceptionFunc_);
571 }
572
573 /**
574 * @tc.name: SetRaiseToAppTopForPointDownFunc
575 * @tc.desc: SetRaiseToAppTopForPointDownFunc Test
576 * @tc.type: FUNC
577 */
578 HWTEST_F(WindowSessionTest4, SetRaiseToAppTopForPointDownFunc, TestSize.Level1)
579 {
580 ASSERT_NE(session_, nullptr);
581 session_->SetRaiseToAppTopForPointDownFunc(nullptr);
582
__anonc00021d31002() 583 NotifyRaiseToTopForPointDownFunc func = []() {};
584 session_->raiseToTopForPointDownFunc_ = func;
585 session_->RaiseToAppTopForPointDown();
586 session_->HandlePointDownDialog();
587 session_->ClearDialogVector();
588
589 session_->SetBufferAvailableChangeListener(nullptr);
590 session_->UnregisterSessionChangeListeners();
591 session_->SetSessionStateChangeNotifyManagerListener(nullptr);
592 session_->SetSessionInfoChangeNotifyManagerListener(nullptr);
593 session_->NotifyFocusStatus(true);
594
595 session_->SetRequestFocusStatusNotifyManagerListener(nullptr);
596 session_->SetNotifyUIRequestFocusFunc(nullptr);
597 session_->SetNotifyUILostFocusFunc(nullptr);
598 session_->UnregisterSessionChangeListeners();
599
__anonc00021d31102(const SessionInfo& info, bool shouldBackToCaller) 600 NotifyPendingSessionToBackgroundForDelegatorFunc func2 = [](const SessionInfo& info, bool shouldBackToCaller) {};
601 session_->pendingSessionToBackgroundForDelegatorFunc_ = func2;
602 ASSERT_EQ(WSError::WS_OK, session_->PendingSessionToBackgroundForDelegator(true));
603 }
604
605 /**
606 * @tc.name: NotifyCloseExistPipWindow
607 * @tc.desc: check func NotifyCloseExistPipWindow
608 * @tc.type: FUNC
609 */
610 HWTEST_F(WindowSessionTest4, NotifyCloseExistPipWindow, TestSize.Level1)
611 {
612 sptr<SessionStageMocker> mockSessionStage = sptr<SessionStageMocker>::MakeSptr();
613 ASSERT_NE(mockSessionStage, nullptr);
614 ManagerState key = ManagerState{ 0 };
615 session_->GetStateFromManager(key);
616 session_->NotifyUILostFocus();
617
__anonc00021d31202() 618 session_->lostFocusFunc_ = []() {};
619 session_->NotifyUILostFocus();
620
621 session_->SetSystemSceneBlockingFocus(true);
622 session_->GetBlockingFocus();
623 session_->sessionStage_ = mockSessionStage;
624 EXPECT_CALL(*(mockSessionStage), NotifyCloseExistPipWindow()).Times(1).WillOnce(Return(WSError::WS_OK));
625 ASSERT_EQ(WSError::WS_OK, session_->NotifyCloseExistPipWindow());
626 session_->sessionStage_ = nullptr;
627 ASSERT_EQ(WSError::WS_ERROR_NULLPTR, session_->NotifyCloseExistPipWindow());
628 }
629
630 /**
631 * @tc.name: SetUseStartingWindowAboveLocked
632 * @tc.desc: SetUseStartingWindowAboveLocked Test
633 * @tc.type: FUNC
634 */
635 HWTEST_F(WindowSessionTest4, SetUseStartingWindowAboveLocked, TestSize.Level1)
636 {
637 ASSERT_NE(session_, nullptr);
638 session_->useStartingWindowAboveLocked_ = false;
639 ASSERT_EQ(session_->useStartingWindowAboveLocked_, false);
640 session_->SetUseStartingWindowAboveLocked(true);
641 ASSERT_EQ(session_->UseStartingWindowAboveLocked(), true);
642 }
643
644 /**
645 * @tc.name: SetSystemConfig
646 * @tc.desc: SetSystemConfig Test
647 * @tc.type: FUNC
648 */
649 HWTEST_F(WindowSessionTest4, SetSystemConfig, TestSize.Level1)
650 {
651 ASSERT_NE(session_, nullptr);
652 SystemSessionConfig systemConfig;
653 session_->SetSystemConfig(systemConfig);
654 float snapshotScale = 0.5;
655 session_->SetSnapshotScale(snapshotScale);
656 session_->ProcessBackEvent();
657 session_->NotifyOccupiedAreaChangeInfo(nullptr);
658 session_->UpdateMaximizeMode(true);
659 ASSERT_EQ(session_->GetZOrder(), 0);
660
661 session_->SetUINodeId(0);
662 session_->GetUINodeId();
663 session_->SetShowRecent(true);
664 session_->GetShowRecent();
665 session_->SetBufferAvailable(true);
666
667 session_->SetNeedSnapshot(true);
668 session_->SetFloatingScale(0.5);
669 ASSERT_EQ(session_->GetFloatingScale(), 0.5f);
670 session_->SetScale(50, 100, 50, 100);
671 session_->GetScaleX();
672 session_->GetScaleY();
673 session_->GetPivotX();
674 session_->GetPivotY();
675 session_->SetSCBKeepKeyboard(true);
676 session_->GetSCBKeepKeyboardFlag();
677 ASSERT_EQ(WSError::WS_OK, session_->MarkProcessed(11));
678 }
679
680 /**
681 * @tc.name: SetOffset
682 * @tc.desc: SetOffset Test
683 * @tc.type: FUNC
684 */
685 HWTEST_F(WindowSessionTest4, SetOffset, TestSize.Level1)
686 {
687 ASSERT_NE(session_, nullptr);
688 session_->SetOffset(50, 100);
689 session_->GetOffsetX();
690 session_->GetOffsetY();
691 WSRectF bounds;
692 session_->SetBounds(bounds);
693 session_->GetBounds();
694 session_->UpdateTitleInTargetPos(true, 100);
695 session_->SetNotifySystemSessionPointerEventFunc(nullptr);
696 session_->SetNotifySystemSessionKeyEventFunc(nullptr);
697 ASSERT_EQ(session_->GetBufferAvailable(), false);
698 }
699
700 /**
701 * @tc.name: SetBackPressedListenser
702 * @tc.desc: SetBackPressedListenser Test
703 type: FUNC
704 */
705 HWTEST_F(WindowSessionTest4, SetBackPressedListenser, TestSize.Level1)
706 {
707 ASSERT_NE(session_, nullptr);
708 int32_t result = 0;
__anonc00021d31302(const bool needMoveToBackground) 709 session_->SetBackPressedListenser([&result](const bool needMoveToBackground) { result = 1; });
710 usleep(waitSyncInNs_);
711 session_->backPressedFunc_(true);
712 ASSERT_EQ(result, 1);
713 }
714
715 /**
716 * @tc.name: SetUpdateSessionIconListener
717 * @tc.desc: SetUpdateSessionIconListener Test
718 * @tc.type: FUNC
719 */
720 HWTEST_F(WindowSessionTest4, SetUpdateSessionIconListener, TestSize.Level1)
721 {
722 ASSERT_NE(session_, nullptr);
723 WLOGFI("SetUpdateSessionIconListener begin!");
724
725 session_->SetUpdateSessionIconListener(session_->updateSessionIconFunc_);
726
727 WLOGFI("SetUpdateSessionIconListener end!");
728 }
729
730 /**
731 * @tc.name: NotifyContextTransparent
732 * @tc.desc: NotifyContextTransparent Test
733 * @tc.type: FUNC
734 */
735 HWTEST_F(WindowSessionTest4, NotifyContextTransparent, TestSize.Level1)
736 {
737 WLOGFI("NotifyContextTransparent begin!");
738 ASSERT_NE(session_, nullptr);
739
740 NotifyContextTransparentFunc contextTransparentFunc = session_->contextTransparentFunc_;
741 if (contextTransparentFunc == nullptr) {
__anonc00021d31402() 742 contextTransparentFunc = []() {};
743 }
744 session_->contextTransparentFunc_ = nullptr;
745 session_->NotifyContextTransparent();
746
747 session_->SetContextTransparentFunc(contextTransparentFunc);
748 session_->NotifyContextTransparent();
749
750 WLOGFI("NotifyContextTransparent end!");
751 }
752
753 /**
754 * @tc.name: NotifySessionInfoLockedStateChange
755 * @tc.desc: NotifySessionInfoLockedStateChange Test
756 * @tc.type: FUNC
757 */
758 HWTEST_F(WindowSessionTest4, NotifySessionInfoLockedStateChange, TestSize.Level1)
759 {
760 WLOGFI("NotifySessionInfoLockedStateChange begin!");
761 ASSERT_NE(session_, nullptr);
762
763 NotifySessionInfoLockedStateChangeFunc sessionInfoLockedStateChangeFunc =
764 session_->sessionInfoLockedStateChangeFunc_;
765 if (sessionInfoLockedStateChangeFunc == nullptr) {
__anonc00021d31502(const bool lockedState) 766 sessionInfoLockedStateChangeFunc = [](const bool lockedState) {};
767 }
768 session_->sessionInfoLockedStateChangeFunc_ = nullptr;
769 session_->NotifySessionInfoLockedStateChange(true);
770
771 session_->SetSessionInfoLockedStateChangeListener(sessionInfoLockedStateChangeFunc);
772 session_->NotifySessionInfoLockedStateChange(true);
773
774 WLOGFI("NotifySessionInfoLockedStateChange end!");
775 }
776
777 /**
778 * @tc.name: GetMainSession
779 * @tc.desc: GetMainSession Test
780 * @tc.type: FUNC
781 */
782 HWTEST_F(WindowSessionTest4, GetMainSession, TestSize.Level1)
783 {
784 ASSERT_NE(session_, nullptr);
785 SessionInfo info;
786 info.abilityName_ = "getMainSession";
787 info.moduleName_ = "getMainSession";
788 info.bundleName_ = "getMainSession";
789 sptr<Session> session = sptr<Session>::MakeSptr(info);
790 ASSERT_NE(session, nullptr);
791 session_->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
792 EXPECT_EQ(session, session->GetMainSession());
793
794 sptr<Session> subSession = sptr<Session>::MakeSptr(info);
795 ASSERT_NE(subSession, nullptr);
796 subSession->SetParentSession(session);
797 subSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
798 EXPECT_EQ(session, subSession->GetMainSession());
799
800 sptr<Session> subSubSession = sptr<Session>::MakeSptr(info);
801 ASSERT_NE(subSubSession, nullptr);
802 subSubSession->SetParentSession(subSession);
803 subSubSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
804 EXPECT_EQ(session, subSubSession->GetMainSession());
805 }
806
807 /**
808 * @tc.name: GetMainOrFloatSession
809 * @tc.desc: GetMainOrFloatSession Test
810 * @tc.type: FUNC
811 */
812 HWTEST_F(WindowSessionTest4, GetMainOrFloatSession, TestSize.Level1)
813 {
814 ASSERT_NE(session_, nullptr);
815 SessionInfo info;
816 info.abilityName_ = "GetMainOrFloatSession";
817 info.moduleName_ = "GetMainOrFloatSession";
818 info.bundleName_ = "GetMainOrFloatSession";
819 sptr<Session> session = sptr<Session>::MakeSptr(info);
820 session_->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
821 EXPECT_EQ(session, session->GetMainOrFloatSession());
822
823 sptr<Session> floatSession = sptr<Session>::MakeSptr(info);
824 floatSession->SetParentSession(session);
825 floatSession->property_->SetWindowType(WindowType::WINDOW_TYPE_FLOAT);
826 EXPECT_EQ(floatSession, floatSession->GetMainOrFloatSession());
827
828 sptr<Session> subSession = sptr<Session>::MakeSptr(info);
829 subSession->SetParentSession(floatSession);
830 subSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
831 EXPECT_EQ(floatSession, subSession->GetMainOrFloatSession());
832 }
833
834 /**
835 * @tc.name: IsAncestorsSession
836 * @tc.desc: IsAncestorsSession Test
837 * @tc.type: FUNC
838 */
839 HWTEST_F(WindowSessionTest4, IsAncestorsSession, TestSize.Level1)
840 {
841 SessionInfo info;
842 info.abilityName_ = "IsAncestorsSession";
843 info.moduleName_ = "IsAncestorsSession";
844 info.bundleName_ = "IsAncestorsSession";
845 sptr<Session> session = sptr<Session>::MakeSptr(info);
846 session->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
847 session->property_->SetPersistentId(1);
848
849 sptr<Session> subSession = sptr<Session>::MakeSptr(info);
850 subSession->SetParentSession(session);
851 subSession->property_->SetPersistentId(2);
852 subSession->property_->SetParentPersistentId(1);
853 subSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
854 EXPECT_EQ(true, subSession->IsAncestorsSession(1));
855
856 sptr<Session> subSubSession = sptr<Session>::MakeSptr(info);
857 subSubSession->SetParentSession(subSession);
858 subSubSession->property_->SetPersistentId(3);
859 subSubSession->property_->SetParentPersistentId(2);
860 subSubSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
861 EXPECT_EQ(true, subSubSession->IsAncestorsSession(1));
862 EXPECT_EQ(true, subSubSession->IsAncestorsSession(2));
863 EXPECT_EQ(false, subSubSession->IsAncestorsSession(3));
864 }
865
866 /**
867 * @tc.name: IsSupportDetectWindow
868 * @tc.desc: IsSupportDetectWindow Test
869 * @tc.type: FUNC
870 */
871 HWTEST_F(WindowSessionTest4, IsSupportDetectWindow, TestSize.Level1)
872 {
873 session_->systemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
874 ssm_->SetScreenLocked(true);
875 sleep(1);
876 bool ret = session_->IsSupportDetectWindow(true);
877 ASSERT_EQ(ret, false);
878
879 ssm_->SetScreenLocked(false);
880 sleep(1);
881 session_->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_END);
882 ret = session_->IsSupportDetectWindow(true);
883 ASSERT_EQ(ret, false);
884
885 ssm_->SetScreenLocked(false);
886 sleep(1);
887 session_->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
888 session_->systemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
889 ret = session_->IsSupportDetectWindow(false);
890 ASSERT_EQ(ret, false);
891 }
892
893 /**
894 * @tc.name: ShouldCreateDetectTask
895 * @tc.desc: ShouldCreateDetectTask Test
896 * @tc.type: FUNC
897 */
898 HWTEST_F(WindowSessionTest4, ShouldCreateDetectTask, TestSize.Level1)
899 {
900 DetectTaskInfo detectTaskInfo;
901 detectTaskInfo.taskState = DetectTaskState::ATTACH_TASK;
902 detectTaskInfo.taskWindowMode = WindowMode::WINDOW_MODE_FULLSCREEN;
903 session_->SetDetectTaskInfo(detectTaskInfo);
904 bool ret = session_->ShouldCreateDetectTask(true, WindowMode::WINDOW_MODE_UNDEFINED);
905 ASSERT_EQ(ret, true);
906 detectTaskInfo.taskState = DetectTaskState::DETACH_TASK;
907 session_->SetDetectTaskInfo(detectTaskInfo);
908 ret = session_->ShouldCreateDetectTask(false, WindowMode::WINDOW_MODE_UNDEFINED);
909 ASSERT_EQ(ret, true);
910 ret = session_->ShouldCreateDetectTask(true, WindowMode::WINDOW_MODE_UNDEFINED);
911 ASSERT_EQ(ret, false);
912 }
913
914 /**
915 * @tc.name: ShouldCreateDetectTaskInRecent
916 * @tc.desc: ShouldCreateDetectTaskInRecent Test
917 * @tc.type: FUNC
918 */
919 HWTEST_F(WindowSessionTest4, ShouldCreateDetectTaskInRecent, TestSize.Level1)
920 {
921 bool ret = session_->ShouldCreateDetectTaskInRecent(true, true, true);
922 ASSERT_EQ(ret, false);
923 ret = session_->ShouldCreateDetectTaskInRecent(false, true, true);
924 ASSERT_EQ(ret, true);
925 ret = session_->ShouldCreateDetectTaskInRecent(false, true, false);
926 ASSERT_EQ(ret, false);
927 ret = session_->ShouldCreateDetectTaskInRecent(false, false, false);
928 ASSERT_EQ(ret, false);
929 }
930
931 /**
932 * @tc.name: CreateWindowStateDetectTask
933 * @tc.desc: CreateWindowStateDetectTask Test
934 * @tc.type: FUNC
935 */
936 HWTEST_F(WindowSessionTest4, CreateWindowStateDetectTask, TestSize.Level1)
937 {
__anonc00021d31602() 938 auto isScreenLockedCallback = [this]() { return ssm_->IsScreenLocked(); };
939 session_->RegisterIsScreenLockedCallback(isScreenLockedCallback);
940 session_->SetSessionState(SessionState::STATE_CONNECT);
941 bool isAttach = true;
942 session_->CreateWindowStateDetectTask(isAttach, WindowMode::WINDOW_MODE_UNDEFINED);
943 ASSERT_EQ(isAttach, true);
944
945 session_->handler_ = nullptr;
946 session_->CreateWindowStateDetectTask(false, WindowMode::WINDOW_MODE_UNDEFINED);
947 ASSERT_EQ(session_->handler_, nullptr);
948 }
949
950 /**
951 * @tc.name: SetOffset01
952 * @tc.desc: SetOffset Test
953 * @tc.type: FUNC
954 */
955 HWTEST_F(WindowSessionTest4, SetOffset01, TestSize.Level1)
956 {
957 ASSERT_NE(session_, nullptr);
958 session_->SetOffset(0, 0);
959 ASSERT_EQ(session_->GetOffsetX(), 0);
960 }
961
962 /**
963 * @tc.name: GetIsMidScene
964 * @tc.desc: GetIsMidScene Test
965 * @tc.type: FUNC
966 */
967 HWTEST_F(WindowSessionTest4, GetIsMidScene, TestSize.Level1)
968 {
969 ASSERT_NE(session_, nullptr);
970 bool isMidScene = false;
971 auto result = session_->GetIsMidScene(isMidScene);
972 ASSERT_EQ(result, WSError::WS_OK);
973 ASSERT_EQ(isMidScene, false);
974 }
975
976 /**
977 * @tc.name: GetWindowUIInfoForWindowInfo01
978 * @tc.desc: GetWindowUIInfoForWindowInfo Test
979 * @tc.type: FUNC
980 */
981 HWTEST_F(WindowSessionTest4, GetWindowUIInfoForWindowInfo01, TestSize.Level1)
982 {
983 SessionInfo sessionInfo;
984 sessionInfo.isSystem_ = false;
985 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
986 sceneSession->SetVisibilityState(WINDOW_VISIBILITY_STATE_TOTALLY_OCCUSION);
987 WSRect rect = { 0, 0, 100, 100 };
988 sceneSession->SetSessionRect(rect);
989 sceneSession->SetSessionGlobalRect(rect);
990 sceneSession->SetSessionState(SessionState::STATE_FOREGROUND);
991 sceneSession->GetSessionProperty()->SetDisplayId(0);
992
993 WindowUIInfo windowUIInfo = sceneSession->GetWindowUIInfoForWindowInfo();
994 ASSERT_EQ(windowUIInfo.visibilityState, sceneSession->GetVisibilityState());
995 }
996
997 /**
998 * @tc.name: GetWindowDisplayInfoForWindowInfo01
999 * @tc.desc: GetWindowDisplayInfoForWindowInfo Test
1000 * @tc.type: FUNC
1001 */
1002 HWTEST_F(WindowSessionTest4, GetWindowDisplayInfoForWindowInfo01, TestSize.Level1)
1003 {
1004 SessionInfo sessionInfo;
1005 sessionInfo.isSystem_ = false;
1006 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1007 sceneSession->SetVisibilityState(WINDOW_VISIBILITY_STATE_TOTALLY_OCCUSION);
1008 WSRect rect = { 5, 0, 100, 100 };
1009 sceneSession->SetSessionRect(rect);
1010 sceneSession->SetSessionGlobalRect(rect);
1011 sceneSession->SetSessionState(SessionState::STATE_FOREGROUND);
1012 constexpr DisplayId SECOND_DISPLAY_ID = 11;
1013 sceneSession->GetSessionProperty()->SetDisplayId(SECOND_DISPLAY_ID);
1014
1015 WindowDisplayInfo windowDisplayInfo = sceneSession->GetWindowDisplayInfoForWindowInfo();
1016 ASSERT_EQ(windowDisplayInfo.displayId, sceneSession->GetSessionProperty()->GetDisplayId());
1017 }
1018
1019 /**
1020 * @tc.name: GetWindowLayoutInfoForWindowInfo01
1021 * @tc.desc: GetWindowLayoutInfoForWindowInfo Test
1022 * @tc.type: FUNC
1023 */
1024 HWTEST_F(WindowSessionTest4, GetWindowLayoutInfoForWindowInfo01, TestSize.Level1)
1025 {
1026 SessionInfo sessionInfo;
1027 sessionInfo.isSystem_ = false;
1028 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1029 sceneSession->SetVisibilityState(WINDOW_VISIBILITY_STATE_TOTALLY_OCCUSION);
1030 WSRect rect = { 5, 0, 100, 100 };
1031 sceneSession->SetSessionRect(rect);
1032 sceneSession->SetSessionGlobalRect(rect);
1033 sceneSession->SetSessionState(SessionState::STATE_FOREGROUND);
1034 sceneSession->GetSessionProperty()->SetDisplayId(0);
1035 sceneSession->SetZOrder(100);
1036
1037 WindowLayoutInfo windowLayoutInfo = sceneSession->GetWindowLayoutInfoForWindowInfo();
1038 ASSERT_EQ(windowLayoutInfo.rect.posX_, 5);
1039 ASSERT_EQ(windowLayoutInfo.rect.posY_, 0);
1040 ASSERT_EQ(windowLayoutInfo.rect.width_, 100);
1041 ASSERT_EQ(windowLayoutInfo.rect.height_, 100);
1042 ASSERT_EQ(windowLayoutInfo.zOrder, 100);
1043 }
1044
1045 /**
1046 * @tc.name: GetWindowMetaInfoForWindowInfo01
1047 * @tc.desc: GetWindowMetaInfoForWindowInfo Test
1048 * @tc.type: FUNC
1049 */
1050 HWTEST_F(WindowSessionTest4, GetWindowMetaInfoForWindowInfo01, TestSize.Level1)
1051 {
1052 SessionInfo sessionInfo;
1053 sessionInfo.isSystem_ = false;
1054 sessionInfo.bundleName_ = "bundleName";
1055 sessionInfo.abilityName_ = "abilityName";
1056 sessionInfo.windowType_ = static_cast<uint32_t>(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1057 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1058 sceneSession->GetSessionProperty()->SetWindowName("sceneSession");
1059 sceneSession->SetVisibilityState(WINDOW_VISIBILITY_STATE_TOTALLY_OCCUSION);
1060 WSRect rect = { 5, 0, 100, 100 };
1061 sceneSession->SetSessionRect(rect);
1062 sceneSession->SetSessionGlobalRect(rect);
1063 sceneSession->SetSessionState(SessionState::STATE_FOREGROUND);
1064 sceneSession->GetSessionProperty()->SetDisplayId(0);
1065 sceneSession->callingPid_ = 123;
1066 sceneSession->UpdateWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
1067 sceneSession->isMidScene_ = true;
1068 sceneSession->isFocused_ = true;
1069 SessionInfo sessionInfo1;
1070 sessionInfo1.isSystem_ = true;
1071 sessionInfo1.abilityName_ = "abilityName1";
1072 sptr<SceneSession> sceneSession1 = sptr<SceneSession>::MakeSptr(sessionInfo1, nullptr);
1073 sceneSession1->SetVisibilityState(WINDOW_VISIBILITY_STATE_TOTALLY_OCCUSION);
1074 rect = { 200, 0, 100, 100 };
1075 sceneSession1->SetSessionRect(rect);
1076 sceneSession1->SetSessionGlobalRect(rect);
1077 sceneSession1->SetSessionState(SessionState::STATE_FOREGROUND);
1078 sceneSession1->GetSessionProperty()->SetDisplayId(0);
1079 sceneSession1->SetParentSession(sceneSession);
1080 sceneSession1->property_->SetPrivacyMode(true);
1081 sceneSession1->surfaceNode_ = nullptr;
1082 sceneSession1->leashWinSurfaceNode_ = nullptr;
1083
1084 WindowMetaInfo windowMetaInfo = sceneSession->GetWindowMetaInfoForWindowInfo();
1085 ASSERT_EQ(windowMetaInfo.windowId, sceneSession->GetWindowId());
1086 ASSERT_EQ(windowMetaInfo.windowName, sceneSession->GetSessionProperty()->GetWindowName());
1087 ASSERT_EQ(windowMetaInfo.bundleName, sceneSession->GetSessionInfo().bundleName_);
1088 ASSERT_EQ(windowMetaInfo.abilityName, sceneSession->GetSessionInfo().abilityName_);
1089 ASSERT_EQ(windowMetaInfo.pid, sceneSession->GetCallingPid());
1090 ASSERT_EQ(windowMetaInfo.windowType, WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1091 ASSERT_EQ(windowMetaInfo.windowMode, WindowMode::WINDOW_MODE_FULLSCREEN);
1092 ASSERT_EQ(windowMetaInfo.isMidScene, true);
1093 ASSERT_EQ(windowMetaInfo.isFocused, true);
1094 WindowMetaInfo windowMetaInfo1 = sceneSession1->GetWindowMetaInfoForWindowInfo();
1095 ASSERT_EQ(windowMetaInfo1.windowName, sceneSession1->GetSessionInfo().abilityName_);
1096 ASSERT_EQ(windowMetaInfo1.parentWindowId, sceneSession->GetWindowId());
1097 ASSERT_EQ(windowMetaInfo1.surfaceNodeId, 0);
1098 ASSERT_EQ(windowMetaInfo1.leashWinSurfaceNodeId, 0);
1099 ASSERT_EQ(windowMetaInfo1.isPrivacyMode, true);
1100 }
1101
1102 /**
1103 * @tc.name: GetWantSafely01
1104 * @tc.desc: GetWantSafely Test
1105 * @tc.type: FUNC
1106 */
1107 HWTEST_F(WindowSessionTest4, GetWantSafely01, TestSize.Level1)
1108 {
1109 SessionInfo sessionInfo;
1110 ASSERT_EQ(nullptr, sessionInfo.want);
1111 EXPECT_EQ(sessionInfo.GetWantSafely().GetBundle(), "");
1112 }
1113
1114 /**
1115 * @tc.name: SetWantSafely01
1116 * @tc.desc: SetWantSafely Test
1117 * @tc.type: FUNC
1118 */
1119 HWTEST_F(WindowSessionTest4, SetWantSafely01, TestSize.Level1)
1120 {
1121 SessionInfo sessionInfo;
1122 AAFwk::Want wantObj;
1123 wantObj.SetBundle("SetWantSafelyTest");
1124 sessionInfo.SetWantSafely(wantObj);
1125 ASSERT_NE(nullptr, sessionInfo.want);
1126 EXPECT_EQ(sessionInfo.GetWantSafely().GetBundle(), "SetWantSafelyTest");
1127 }
1128
1129 /**
1130 * @tc.name: IsNeedReportTimeout
1131 * @tc.desc: Case of non-specific window
1132 * @tc.type: FUNC
1133 */
1134 HWTEST_F(WindowSessionTest4, IsNeedReportTimeout_NonSpecific_Window, TestSize.Level1)
1135 {
1136 SessionInfo sessionInfo;
1137 sessionInfo.abilityName_ = "IsNeedReportTimeout_NonSpecific_Window";
1138 sessionInfo.bundleName_ = "IsNeedReportTimeout_NonSpecific_Window";
1139
1140 sptr<Session> session = sptr<Session>::MakeSptr(sessionInfo);
1141 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1142 property->isSystemCalling_ = true;
1143 property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1144 EXPECT_EQ(WindowType::APP_MAIN_WINDOW_BASE, property->GetWindowType());
1145
1146 session->SetSessionProperty(property);
1147 EXPECT_EQ(WindowType::APP_MAIN_WINDOW_BASE, session->GetWindowType());
1148 EXPECT_EQ(false, session->IsNeedReportTimeout());
1149
1150 property->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT);
1151 EXPECT_EQ(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT, property->GetWindowType());
1152
1153 session->SetSessionProperty(property);
1154 EXPECT_EQ(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT, session->GetWindowType());
1155 EXPECT_EQ(false, session->IsNeedReportTimeout());
1156 }
1157
1158 /**
1159 * @tc.name: IsNeedReportTimeout
1160 * @tc.desc: Case of specific window
1161 * @tc.type: FUNC
1162 */
1163 HWTEST_F(WindowSessionTest4, IsNeedReportTimeout_specific_window, TestSize.Level1)
1164 {
1165 SessionInfo sessionInfo;
1166 sessionInfo.abilityName_ = "IsNeedReportTimeout_specific_window";
1167 sessionInfo.bundleName_ = "IsNeedReportTimeout_specific_window";
1168
1169 sptr<Session> session = sptr<Session>::MakeSptr(sessionInfo);
1170 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1171 property->isSystemCalling_ = true;
1172 property->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
1173 EXPECT_EQ(WindowType::WINDOW_TYPE_APP_SUB_WINDOW, property->GetWindowType());
1174
1175 session->SetSessionProperty(property);
1176 EXPECT_EQ(WindowType::WINDOW_TYPE_APP_SUB_WINDOW, session->GetWindowType());
1177 EXPECT_EQ(true, session->IsNeedReportTimeout());
1178 }
1179
1180 /**
1181 * @tc.name: PostSpecificSessionLifeCycleTimeoutTask
1182 * @tc.desc: Test Case about non specific window
1183 * @tc.type: FUNC
1184 */
1185 HWTEST_F(WindowSessionTest4, ReportWindowTimeout_NonSpecificWindow, TestSize.Level1)
1186 {
1187 LOG_SetCallback(SessionTest4LogCallBack);
1188 g_logMsg.clear();
1189 SessionInfo sessionInfo;
1190 sessionInfo.abilityName_ = "ReportWindowTimeout_NonSpecificWindow";
1191 sessionInfo.bundleName_ = "ReportWindowTimeout_NonSpecificWindow";
1192
1193 sptr<Session> session = sptr<Session>::MakeSptr(sessionInfo);
1194 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1195 property->isSystemCalling_ = true;
1196 property->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT);
1197 session->SetSessionProperty(property);
1198 EXPECT_EQ(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT, property->GetWindowType());
1199 EXPECT_EQ(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT, session->GetWindowType());
1200 session->PostSpecificSessionLifeCycleTimeoutTask(ATTACH_EVENT_NAME);
1201 EXPECT_EQ(false, session->IsNeedReportTimeout());
1202 }
1203
1204 /**
1205 * @tc.name: PostSpecificSessionLifeCycleTimeoutTask
1206 * @tc.desc: Test Case about non specific window
1207 * @tc.type: FUNC
1208 */
1209 HWTEST_F(WindowSessionTest4, ReportWindowTimeout_SpecificWindow, TestSize.Level1)
1210 {
1211 LOG_SetCallback(SessionTest4LogCallBack);
1212 g_logMsg.clear();
1213 SessionInfo sessionInfo;
1214 sessionInfo.abilityName_ = "ReportWindowTimeout_SpecificWindow";
1215 sessionInfo.bundleName_ = "ReportWindowTimeout_SpecificWindow";
1216
1217 sptr<Session> session = sptr<Session>::MakeSptr(sessionInfo);
1218 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1219 property->isSystemCalling_ = true;
1220 property->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
1221 session->SetSessionProperty(property);
1222 EXPECT_EQ(WindowType::WINDOW_TYPE_APP_SUB_WINDOW, property->GetWindowType());
1223 EXPECT_EQ(WindowType::WINDOW_TYPE_APP_SUB_WINDOW, session->GetWindowType());
1224 session->PostSpecificSessionLifeCycleTimeoutTask(ATTACH_EVENT_NAME);
1225 EXPECT_TRUE(g_logMsg.find("not specific window") == std::string::npos);
1226 }
1227
1228 /**
1229 * @tc.name: PostSpecificSessionLifeCycleTimeoutTask
1230 * @tc.desc: Test Case about handler is not nullptr
1231 * @tc.type: FUNC
1232 */
1233 HWTEST_F(WindowSessionTest4, ReportWindowTimeout_Handler_NOT_NULL, TestSize.Level1)
1234 {
1235 LOG_SetCallback(SessionTest4LogCallBack);
1236 g_logMsg.clear();
1237 SessionInfo sessionInfo;
1238 sessionInfo.abilityName_ = "ReportWindowTimeout_Handler_NOT_NULL";
1239 sessionInfo.bundleName_ = "ReportWindowTimeout_Handler_NOT_NULL";
1240
1241 sptr<Session> session = sptr<Session>::MakeSptr(sessionInfo);
1242 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1243 property->isSystemCalling_ = true;
1244 property->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
1245 session->SetSessionProperty(property);
1246 EXPECT_EQ(WindowType::WINDOW_TYPE_APP_SUB_WINDOW, property->GetWindowType());
1247 EXPECT_EQ(WindowType::WINDOW_TYPE_APP_SUB_WINDOW, session->GetWindowType());
1248 session->PostSpecificSessionLifeCycleTimeoutTask(ATTACH_EVENT_NAME);
1249
1250 sptr<SceneSessionManager> sceneSessionManager = sptr<SceneSessionManager>::MakeSptr();
1251 session_->SetEventHandler(sceneSessionManager->taskScheduler_->GetEventHandler(),
1252 sceneSessionManager->eventHandler_);
1253 EXPECT_TRUE(g_logMsg.find("not specific window") == std::string::npos);
1254 EXPECT_TRUE(g_logMsg.find("handler is null") == std::string::npos);
1255 }
1256
1257 /**
1258 * @tc.name: PostSpecificSessionLifeCycleTimeoutTask
1259 * @tc.desc: Test Case about window animation duration
1260 * @tc.type: FUNC
1261 */
1262 HWTEST_F(WindowSessionTest4, ReportWindowTimeout_WindowAnimationDuration, TestSize.Level1)
1263 {
1264 LOG_SetCallback(SessionTest4LogCallBack);
1265 g_logMsg.clear();
1266 SessionInfo sessionInfo;
1267 sessionInfo.abilityName_ = "ReportWindowTimeout_WindowAnimationDuration";
1268 sessionInfo.bundleName_ = "ReportWindowTimeout_WindowAnimationDuration";
1269
1270 sptr<Session> session = sptr<Session>::MakeSptr(sessionInfo);
1271 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1272 property->isSystemCalling_ = true;
1273 property->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
1274 session->SetSessionProperty(property);
1275 EXPECT_EQ(WindowType::WINDOW_TYPE_APP_SUB_WINDOW, property->GetWindowType());
1276 EXPECT_EQ(WindowType::WINDOW_TYPE_APP_SUB_WINDOW, session->GetWindowType());
1277 session->PostSpecificSessionLifeCycleTimeoutTask(ATTACH_EVENT_NAME);
1278 sptr<SceneSessionManager> sceneSessionManager = sptr<SceneSessionManager>::MakeSptr();
1279 session_->SetEventHandler(sceneSessionManager->taskScheduler_->GetEventHandler(),
1280 sceneSessionManager->eventHandler_);
1281 EXPECT_TRUE(g_logMsg.find("handler is null") == std::string::npos);
1282
1283 session->SetWindowAnimationDuration(true);
1284 EXPECT_EQ(true, session->IsNeedReportTimeout());
1285
1286 session->SetWindowAnimationDuration(false);
1287 EXPECT_TRUE(g_logMsg.find("window configured animation") == std::string::npos);
1288 }
1289
1290 /**
1291 * @tc.name: NotifyAppForceLandscapeConfigUpdated
1292 * @tc.desc: check func NotifyAppForceLandscapeConfigUpdated
1293 * @tc.type: FUNC
1294 */
1295 HWTEST_F(WindowSessionTest4, NotifyAppForceLandscapeConfigUpdated, TestSize.Level1)
1296 {
1297 ASSERT_NE(session_, nullptr);
1298 session_->state_ = SessionState::STATE_CONNECT;
1299 sptr<SessionStageMocker> mockSessionStage = sptr<SessionStageMocker>::MakeSptr();
1300 ASSERT_NE(nullptr, mockSessionStage);
1301 session_->sessionStage_ = mockSessionStage;
1302 EXPECT_EQ(WSError::WS_OK, session_->NotifyAppForceLandscapeConfigUpdated());
1303 session_->sessionStage_ = nullptr;
1304 EXPECT_EQ(WSError::WS_ERROR_NULLPTR, session_->NotifyAppForceLandscapeConfigUpdated());
1305 }
1306
1307 /**
1308 * @tc.name: SetLifeCycleTaskRunning
1309 * @tc.desc: check func SetLifeCycleTaskRunning
1310 * @tc.type: FUNC
1311 */
1312 HWTEST_F(WindowSessionTest4, SetLifeCycleTaskRunning, TestSize.Level1)
1313 {
1314 ASSERT_NE(session_, nullptr);
__anonc00021d31702()1315 auto task = [](){};
1316 std::string name = "testTask";
1317 sptr<Session::SessionLifeCycleTask> lifeCycleTask =
1318 sptr<Session::SessionLifeCycleTask>::MakeSptr(std::move(task), name, LifeCycleTaskType::STOP);
1319
1320 bool ret = session_->SetLifeCycleTaskRunning(lifeCycleTask);
1321
1322 EXPECT_TRUE(lifeCycleTask->running);
1323 EXPECT_TRUE(ret);
1324
1325 ret = session_->SetLifeCycleTaskRunning(lifeCycleTask);
1326 EXPECT_FALSE(ret);
1327
1328 sptr<Session::SessionLifeCycleTask> lifeCycleNullTask = nullptr;
1329 ret = session_->SetLifeCycleTaskRunning(lifeCycleNullTask);
1330 EXPECT_FALSE(ret);
1331 }
1332
1333 /**
1334 * @tc.name: SetHidingStartingWindow
1335 * @tc.desc: check func SetHidingStartingWindow
1336 * @tc.type: FUNC
1337 */
1338 HWTEST_F(WindowSessionTest4, SetHidingStartingWindow, TestSize.Level1)
1339 {
1340 ASSERT_NE(session_, nullptr);
1341
1342 session_->SetLeashWinSurfaceNode(nullptr);
1343 auto ret = session_->SetHidingStartingWindow(false);
1344 EXPECT_EQ(ret, WSError::WS_ERROR_NULLPTR);
1345 EXPECT_TRUE(session_->GetHidingStartingWindow() == false);
1346
1347 struct RSSurfaceNodeConfig config;
1348 std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Create(config);
1349 session_->SetLeashWinSurfaceNode(surfaceNode);
1350 ret = session_->SetHidingStartingWindow(true);
1351 EXPECT_TRUE(session_->GetHidingStartingWindow());
1352 EXPECT_EQ(ret, WSError::WS_OK);
1353 }
1354
1355 /**
1356 * @tc.name: SetAndGetGlobalDisplayRect
1357 * @tc.desc: Verify that setting and getting global display rect works as expected
1358 * @tc.type: FUNC
1359 */
1360 HWTEST_F(WindowSessionTest4, SetAndGetGlobalDisplayRect, TestSize.Level1)
1361 {
1362 WSRect rect = { 10, 20, 200, 100 };
1363 session_->SetGlobalDisplayRect(rect);
1364 WSRect result = session_->GetGlobalDisplayRect();
1365 EXPECT_EQ(result, rect);
1366 }
1367
1368 /**
1369 * @tc.name: TestUpdateGlobalDisplayRect
1370 * @tc.desc: Verify that updating global display rect works as expected
1371 * @tc.type: FUNC
1372 */
1373 HWTEST_F(WindowSessionTest4, TestUpdateGlobalDisplayRect, TestSize.Level1)
1374 {
1375 WSRect rect = { 10, 20, 200, 100 };
1376 session_->SetGlobalDisplayRect(rect);
1377 session_->globalDisplayRectSizeChangeReason_ = SizeChangeReason::RESIZE;
1378
1379 auto ret = session_->UpdateGlobalDisplayRect(rect, SizeChangeReason::RESIZE);
1380 EXPECT_EQ(ret, WSError::WS_DO_NOTHING);
1381 EXPECT_EQ(session_->GetGlobalDisplayRect(), rect);
1382 EXPECT_EQ(session_->globalDisplayRectSizeChangeReason_, SizeChangeReason::RESIZE);
1383
1384 ret = session_->UpdateGlobalDisplayRect(rect, SizeChangeReason::MOVE);
1385 EXPECT_EQ(ret, WSError::WS_OK);
1386 EXPECT_EQ(session_->GetGlobalDisplayRect(), rect);
1387 EXPECT_EQ(session_->globalDisplayRectSizeChangeReason_, SizeChangeReason::MOVE);
1388
1389 WSRect updated = { 30, 40, 200, 100 };
1390 ret = session_->UpdateGlobalDisplayRect(updated, SizeChangeReason::MOVE);
1391 EXPECT_EQ(ret, WSError::WS_OK);
1392 EXPECT_EQ(session_->GetGlobalDisplayRect(), updated);
1393 EXPECT_EQ(session_->globalDisplayRectSizeChangeReason_, SizeChangeReason::MOVE);
1394
1395 updated = { 0, 0, 200, 100 };
1396 ret = session_->UpdateGlobalDisplayRect(updated, SizeChangeReason::DRAG);
1397 EXPECT_EQ(ret, WSError::WS_OK);
1398 EXPECT_EQ(session_->GetGlobalDisplayRect(), updated);
1399 EXPECT_EQ(session_->globalDisplayRectSizeChangeReason_, SizeChangeReason::DRAG);
1400 }
1401
1402 /**
1403 * @tc.name: TestNotifyClientToUpdateGlobalDisplayRect
1404 * @tc.desc: Verify that notifying client to update global display rect works as expected
1405 * @tc.type: FUNC
1406 */
1407 HWTEST_F(WindowSessionTest4, TestNotifyClientToUpdateGlobalDisplayRect, TestSize.Level1)
1408 {
1409 WSRect rect = { 10, 20, 200, 100 };
1410 auto originalState = session_->state_.load();
1411 auto originalSessionStage = session_->sessionStage_;
1412
1413 session_->sessionStage_ = nullptr;
1414 auto result = session_->NotifyClientToUpdateGlobalDisplayRect(rect, SizeChangeReason::UNDEFINED);
1415 EXPECT_EQ(result, WSError::WS_DO_NOTHING);
1416
1417 auto mockSessionStage = sptr<SessionStageMocker>::MakeSptr();
1418 session_->sessionStage_ = mockSessionStage;
1419 session_->state_ = SessionState::STATE_BACKGROUND;
1420 result = session_->NotifyClientToUpdateGlobalDisplayRect(rect, SizeChangeReason::UNDEFINED);
1421 EXPECT_EQ(result, WSError::WS_DO_NOTHING);
1422
1423 session_->state_ = SessionState::STATE_FOREGROUND;
1424 EXPECT_CALL(*mockSessionStage, UpdateGlobalDisplayRectFromServer(rect, SizeChangeReason::UNDEFINED))
1425 .WillOnce(Return(WSError::WS_OK));
1426 result = session_->NotifyClientToUpdateGlobalDisplayRect(rect, SizeChangeReason::UNDEFINED);
1427 EXPECT_EQ(result, WSError::WS_OK);
1428 session_->state_ = originalState;
1429 session_->sessionStage_ = originalSessionStage;
1430 }
1431
1432 /**
1433 * @tc.name: TestGetSessionScreenRelativeRect_001
1434 * @tc.desc: get relative rect when reason is not drag move
1435 * @tc.type: FUNC
1436 */
1437 HWTEST_F(WindowSessionTest4, TestGetSessionScreenRelativeRect_001, TestSize.Level1)
1438 {
1439 session_->UpdateSizeChangeReason(SizeChangeReason::RESIZE);
1440 WSRect expectedRect = { 0, 0, 100, 100};
1441 session_->SetSessionRect(expectedRect);
1442
1443 WSRect result = session_->GetSessionScreenRelativeRect();
1444 EXPECT_EQ(result, expectedRect);
1445 }
1446
1447 class LayoutControllerMocker : public LayoutController {
1448 public:
LayoutControllerMocker(const sptr<WindowSessionProperty> & property)1449 explicit LayoutControllerMocker(const sptr<WindowSessionProperty>& property) : LayoutController(property) {};
~LayoutControllerMocker()1450 ~LayoutControllerMocker() {};
1451 MOCK_METHOD2(ConvertGlobalRectToRelative, WSRect(const WSRect& globalRect, DisplayId targetDisplayId));
1452 };
1453
1454 /**
1455 * @tc.name: TestGetSessionScreenRelativeRect_001
1456 * @tc.desc: get relative rect when reason is not drag move
1457 * @tc.type: FUNC
1458 */
1459 HWTEST_F(WindowSessionTest4, TestGetSessionScreenRelativeRect_002, TestSize.Level1)
1460 {
1461 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1462 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
1463 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1464 sptr<LayoutControllerMocker> layoutController = sptr<LayoutControllerMocker>::MakeSptr(property);
1465
1466 session->SetMockLayoutController(layoutController);
1467 session_->UpdateSizeChangeReason(SizeChangeReason::DRAG_MOVE);
1468 WSRect expectedRect = { 0, 0, 50, 50};
1469 WSRect winRect = { 0, 0, 50, 50};
1470 session->SetSessionRect(winRect);
1471
1472 EXPECT_CALL(*layoutController, ConvertGlobalRectToRelative(_, _)).Times(1).WillOnce(Return(expectedRect));
1473 WSRect result = session_->GetSessionScreenRelativeRect();
1474 EXPECT_EQ(result, expectedRect);
1475 }
1476
1477 /**
1478 * @tc.name: HasParentSessionWithToken
1479 * @tc.desc: get relative rect when reason is not drag move
1480 * @tc.type: FUNC
1481 */
1482 HWTEST_F(WindowSessionTest4, HasParentSessionWithToken, TestSize.Level1)
1483 {
1484 SessionInfo info;
1485 info.abilityName_ = "HasParentSessionWithToken";
1486 info.bundleName_ = "HasParentSessionWithToken";
1487 sptr<Session> session = sptr<Session>::MakeSptr(info);
1488
1489 sptr<IRemoteObject> token = sptr<MockIRemoteObject>::MakeSptr();
1490 bool ret = session->HasParentSessionWithToken(token);
1491 EXPECT_EQ(ret, false);
1492
1493 SessionInfo parentSessionInfo;
1494 parentSessionInfo.abilityName_ = "parentSession";
1495 parentSessionInfo.bundleName_ = "parentSession";
1496 sptr<Session> parentSession = sptr<Session>::MakeSptr(parentSessionInfo);
1497 session->SetParentSession(parentSession);
1498
1499 ret = session->HasParentSessionWithToken(token);
1500 EXPECT_EQ(ret, false);
1501
1502 parentSession->SetAbilityToken(token);
1503 ret = session->HasParentSessionWithToken(token);
1504 EXPECT_EQ(ret, true);
1505 }
1506 } // namespace
1507 } // namespace Rosen
1508 } // namespace OHOS
1509