1 /*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <gtest/gtest.h>
17 #include <regex>
18 #include <pointer_event.h>
19 #include <ui/rs_surface_node.h>
20
21 #include "mock/mock_session_stage.h"
22 #include "mock/mock_window_event_channel.h"
23 #include "mock/mock_pattern_detach_callback.h"
24 #include "session/host/include/extension_session.h"
25 #include "session/host/include/move_drag_controller.h"
26 #include "session/host/include/scene_session.h"
27 #include "session_manager/include/scene_session_manager.h"
28 #include "session/host/include/pc_fold_screen_manager.h"
29 #include "session/host/include/session.h"
30 #include "session_info.h"
31 #include "key_event.h"
32 #include "wm_common.h"
33 #include "window_event_channel_base.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 WindowSessionTest : public testing::Test {
46 public:
47 static void SetUpTestCase();
48 static void TearDownTestCase();
49 void SetUp() override;
50 void TearDown() override;
51 int32_t GetTaskCount();
52 sptr<SceneSessionManager> ssm_;
53
54 private:
55 RSSurfaceNode::SharedPtr CreateRSSurfaceNode();
56 sptr<Session> session_ = nullptr;
57 static constexpr uint32_t WAIT_SYNC_IN_NS = 500000;
58
59 class TLifecycleListener : public ILifecycleListener {
60 public:
~TLifecycleListener()61 virtual ~TLifecycleListener() {}
OnActivation()62 void OnActivation() override {}
OnConnect()63 void OnConnect() override {}
OnForeground()64 void OnForeground() override {}
OnBackground()65 void OnBackground() override {}
OnDisconnect()66 void OnDisconnect() override {}
OnExtensionDied()67 void OnExtensionDied() override {}
OnExtensionTimeout(int32_t errorCode)68 void OnExtensionTimeout(int32_t errorCode) override {}
OnAccessibilityEvent(const Accessibility::AccessibilityEventInfo & info,int64_t uiExtensionIdLevel)69 void OnAccessibilityEvent(const Accessibility::AccessibilityEventInfo& info,
70 int64_t uiExtensionIdLevel) override
71 {
72 }
OnDrawingCompleted()73 void OnDrawingCompleted() override {}
OnAppRemoveStartingWindow()74 void OnAppRemoveStartingWindow() override {}
75 };
76 std::shared_ptr<TLifecycleListener> lifecycleListener_ = std::make_shared<TLifecycleListener>();
77
78 sptr<SessionStageMocker> mockSessionStage_ = nullptr;
79 sptr<WindowEventChannelMocker> mockEventChannel_ = nullptr;
80 };
81
SetUpTestCase()82 void WindowSessionTest::SetUpTestCase() {}
83
TearDownTestCase()84 void WindowSessionTest::TearDownTestCase() {}
85
SetUp()86 void WindowSessionTest::SetUp()
87 {
88 SessionInfo info;
89 info.abilityName_ = "testSession1";
90 info.moduleName_ = "testSession2";
91 info.bundleName_ = "testSession3";
92 session_ = sptr<Session>::MakeSptr(info);
93 session_->surfaceNode_ = CreateRSSurfaceNode();
94 EXPECT_NE(nullptr, session_);
95 ssm_ = sptr<SceneSessionManager>::MakeSptr();
96 session_->SetEventHandler(ssm_->taskScheduler_->GetEventHandler(), ssm_->eventHandler_);
97 auto isScreenLockedCallback = [this]() { return ssm_->IsScreenLocked(); };
98 session_->RegisterIsScreenLockedCallback(isScreenLockedCallback);
99
100 mockSessionStage_ = sptr<SessionStageMocker>::MakeSptr();
101 ASSERT_NE(mockSessionStage_, nullptr);
102
103 mockEventChannel_ = sptr<WindowEventChannelMocker>::MakeSptr(mockSessionStage_);
104 ASSERT_NE(mockEventChannel_, nullptr);
105 }
106
TearDown()107 void WindowSessionTest::TearDown()
108 {
109 session_ = nullptr;
110 usleep(WAIT_SYNC_IN_NS);
111 }
112
CreateRSSurfaceNode()113 RSSurfaceNode::SharedPtr WindowSessionTest::CreateRSSurfaceNode()
114 {
115 struct RSSurfaceNodeConfig rsSurfaceNodeConfig;
116 rsSurfaceNodeConfig.SurfaceNodeName = "WindowSessionTestSurfaceNode";
117 auto surfaceNode = RSSurfaceNode::Create(rsSurfaceNodeConfig);
118 if (surfaceNode == nullptr) {
119 GTEST_LOG_(INFO) << "WindowSessionTest::CreateRSSurfaceNode surfaceNode is nullptr";
120 }
121 return surfaceNode;
122 }
123
GetTaskCount()124 int32_t WindowSessionTest::GetTaskCount()
125 {
126 std::string dumpInfo = session_->handler_->GetEventRunner()->GetEventQueue()->DumpCurrentQueueSize();
127 std::regex pattern("\\d+");
128 std::smatch matches;
129 int32_t taskNum = 0;
130 while (std::regex_search(dumpInfo, matches, pattern)) {
131 taskNum += std::stoi(matches.str());
132 dumpInfo = matches.suffix();
133 }
134 return taskNum;
135 }
136
137 namespace {
138 /**
139 * @tc.name: SetForceTouchable
140 * @tc.desc: SetForceTouchable
141 * @tc.type: FUNC
142 */
143 HWTEST_F(WindowSessionTest, SetForceTouchable, TestSize.Level1)
144 {
145 ASSERT_NE(session_, nullptr);
146 bool touchable = false;
147 session_->SetForceTouchable(touchable);
148 ASSERT_EQ(session_->forceTouchable_, touchable);
149 }
150
151 /**
152 * @tc.name: SetActive01
153 * @tc.desc: set session active
154 * @tc.type: FUNC
155 * @tc.require: #I6JLSI
156 */
157 HWTEST_F(WindowSessionTest, SetActive01, TestSize.Level1)
158 {
159 sptr<ISession> sessionToken = nullptr;
160 sptr<SessionStageMocker> mockSessionStage = sptr<SessionStageMocker>::MakeSptr();
161 EXPECT_NE(nullptr, mockSessionStage);
162 EXPECT_CALL(*(mockSessionStage), SetActive(_)).WillOnce(Return(WSError::WS_OK));
163 EXPECT_CALL(*(mockSessionStage), UpdateRect(_, _, _, _)).Times(0).WillOnce(Return(WSError::WS_OK));
164 session_->sessionStage_ = mockSessionStage;
165 ASSERT_EQ(WSError::WS_ERROR_INVALID_SESSION, session_->SetActive(true));
166
167 sptr<WindowEventChannelMocker> mockEventChannel = sptr<WindowEventChannelMocker>::MakeSptr(mockSessionStage);
168 EXPECT_NE(nullptr, mockEventChannel);
169 auto surfaceNode = CreateRSSurfaceNode();
170 SystemSessionConfig sessionConfig;
171 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
172 ASSERT_NE(nullptr, property);
173 ASSERT_EQ(WSError::WS_OK,
174 session_->Connect(mockSessionStage, mockEventChannel, surfaceNode, sessionConfig, property));
175 ASSERT_EQ(WSError::WS_ERROR_INVALID_SESSION, session_->SetActive(true));
176 ASSERT_EQ(false, session_->isActive_);
177
178 session_->UpdateSessionState(SessionState::STATE_FOREGROUND);
179 ASSERT_EQ(WSError::WS_OK, session_->SetActive(true));
180 ASSERT_EQ(true, session_->isActive_);
181 }
182
183 /**
184 * @tc.name: SetCompatibleModeProperty
185 * @tc.desc: SetCompatibleModeProperty
186 * @tc.type: FUNC
187 */
188 HWTEST_F(WindowSessionTest, SetCompatibleModeProperty, TestSize.Level1)
189 {
190 sptr<CompatibleModeProperty> compatibleModeProperty = sptr<CompatibleModeProperty>::MakeSptr();
191 ASSERT_EQ(WSError::WS_OK, session_->SetCompatibleModeProperty(compatibleModeProperty));
192 }
193
194 /**
195 * @tc.name: UpdateClientDisplayId01
196 * @tc.desc: UpdateClientDisplayId
197 * @tc.type: FUNC
198 */
199 HWTEST_F(WindowSessionTest, UpdateClientDisplayId01, TestSize.Level1)
200 {
201 ASSERT_NE(session_, nullptr);
202 session_->sessionStage_ = nullptr;
203 session_->clientDisplayId_ = 0;
204 DisplayId updatedDisplayId = 0;
205 EXPECT_EQ(session_->UpdateClientDisplayId(updatedDisplayId), WSError::WS_ERROR_NULLPTR);
206 EXPECT_EQ(updatedDisplayId, session_->clientDisplayId_);
207 updatedDisplayId = 10;
208 EXPECT_EQ(session_->UpdateClientDisplayId(updatedDisplayId), WSError::WS_ERROR_NULLPTR);
209 EXPECT_NE(updatedDisplayId, session_->clientDisplayId_);
210 }
211
212 /**
213 * @tc.name: UpdateClientDisplayId02
214 * @tc.desc: UpdateClientDisplayId
215 * @tc.type: FUNC
216 */
217 HWTEST_F(WindowSessionTest, UpdateClientDisplayId02, TestSize.Level1)
218 {
219 ASSERT_NE(session_, nullptr);
220 ASSERT_NE(mockSessionStage_, nullptr);
221 session_->sessionStage_ = mockSessionStage_;
222 session_->SetPropertyDirtyFlags(0);
223 session_->clientDisplayId_ = 0;
224 DisplayId updatedDisplayId = 0;
225 EXPECT_EQ(session_->UpdateClientDisplayId(updatedDisplayId), WSError::WS_OK);
226 EXPECT_EQ(session_->GetPropertyDirtyFlags(), 0);
227 EXPECT_EQ(updatedDisplayId, session_->clientDisplayId_);
228 updatedDisplayId = 100;
229 EXPECT_EQ(session_->UpdateClientDisplayId(updatedDisplayId), WSError::WS_OK);
230 EXPECT_EQ(session_->GetPropertyDirtyFlags(), static_cast<uint32_t>(SessionPropertyFlag::DISPLAY_ID));
231 EXPECT_EQ(updatedDisplayId, session_->clientDisplayId_);
232 }
233
234 /**
235 * @tc.name: UpdateClientRectPosYAndDisplayId01
236 * @tc.desc: UpdateClientRectPosYAndDisplayId
237 * @tc.type: FUNC
238 */
239 HWTEST_F(WindowSessionTest, UpdateClientRectPosYAndDisplayId01, TestSize.Level1)
240 {
241 ASSERT_NE(session_, nullptr);
242 session_->sessionInfo_.screenId_ = 0;
243 EXPECT_EQ(session_->GetScreenId(), 0);
244 session_->GetSessionProperty()->SetIsSystemKeyboard(false);
245 PcFoldScreenManager::GetInstance().UpdateFoldScreenStatus(
246 0, SuperFoldStatus::EXPANDED, { 0, 0, 2472, 1648 }, { 0, 1648, 2472, 1648 }, { 0, 1624, 2472, 1648 });
247 WSRect rect = { 0, 0, 0, 0 };
248 session_->UpdateClientRectPosYAndDisplayId(rect);
249 EXPECT_EQ(rect.posY_, 0);
250 PcFoldScreenManager::GetInstance().UpdateFoldScreenStatus(
251 0, SuperFoldStatus::KEYBOARD, { 0, 0, 2472, 1648 }, { 0, 1648, 2472, 1648 }, { 0, 1624, 2472, 1648 });
252 rect = { 0, 100, 0, 0 };
253 session_->UpdateClientRectPosYAndDisplayId(rect);
254 EXPECT_EQ(rect.posY_, 100);
255
256 PcFoldScreenManager::GetInstance().UpdateFoldScreenStatus(
257 0, SuperFoldStatus::HALF_FOLDED, { 0, 0, 2472, 1648 }, { 0, 1648, 2472, 1648 }, { 0, 1649, 2472, 40 });
258 const auto& [defaultDisplayRect, virtualDisplayRect, foldCreaseRect] =
259 PcFoldScreenManager::GetInstance().GetDisplayRects();
260 rect = { 0, 1000, 100, 100 };
261 session_->UpdateClientRectPosYAndDisplayId(rect);
262 EXPECT_EQ(rect.posY_, 1000);
263 rect = { 0, 2000, 100, 100 };
264 auto rect2 = rect;
265 session_->UpdateClientRectPosYAndDisplayId(rect);
266 EXPECT_EQ(rect.posY_, rect2.posY_ - defaultDisplayRect.height_ - foldCreaseRect.height_);
267 }
268
269 /**
270 * @tc.name: IsSessionValid01
271 * @tc.desc: check func IsSessionValid
272 * @tc.type: FUNC
273 */
274 HWTEST_F(WindowSessionTest, IsSessionValid01, TestSize.Level1)
275 {
276 session_->state_ = SessionState::STATE_DISCONNECT;
277 ASSERT_FALSE(session_->IsSessionValid());
278 session_->state_ = SessionState::STATE_CONNECT;
279 ASSERT_TRUE(session_->IsSessionValid());
280 }
281
282 /**
283 * @tc.name: ConnectInner
284 * @tc.desc: ConnectInner
285 * @tc.type: FUNC
286 */
287 HWTEST_F(WindowSessionTest, ConnectInner, TestSize.Level1)
288 {
289 SystemSessionConfig sessionConfig;
290 session_->state_ = SessionState::STATE_CONNECT;
291 session_->isTerminating_ = false;
292 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
293
294 property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
295 property->SetIsNeedUpdateWindowMode(true);
296 session_->SetScreenId(233);
297 session_->SetSessionProperty(property);
298 auto res = session_->ConnectInner(
299 mockSessionStage_, mockEventChannel_, nullptr, sessionConfig, property, nullptr, 1, 1, "");
300 ASSERT_EQ(res, WSError::WS_ERROR_INVALID_SESSION);
301
302 session_->isTerminating_ = true;
303 auto res2 = session_->ConnectInner(
304 mockSessionStage_, mockEventChannel_, nullptr, sessionConfig, property, nullptr, 1, 1, "");
305 ASSERT_EQ(res2, WSError::WS_OK);
306
307 property->SetWindowType(WindowType::APP_MAIN_WINDOW_END);
308 property->SetIsNeedUpdateWindowMode(true);
309 session_->SetScreenId(SCREEN_ID_INVALID);
310 session_->SetSessionProperty(property);
311 auto res3 = session_->ConnectInner(
312 mockSessionStage_, mockEventChannel_, nullptr, sessionConfig, property, nullptr, 1, 1, "");
313 ASSERT_EQ(res3, WSError::WS_OK);
314 ASSERT_EQ(false, session_->GetSessionProperty()->GetIsNeedUpdateWindowMode());
315 }
316
317 /**
318 * @tc.name: RemoveLifeCycleTask
319 * @tc.desc: RemoveLifeCycleTask & PostLifeCycleTask
320 * @tc.type: FUNC
321 */
322 HWTEST_F(WindowSessionTest, LifeCycleTask, TestSize.Level1)
323 {
__anonbffd99df0402() 324 auto task = []() {};
325 session_->PostLifeCycleTask(task, "task1", LifeCycleTaskType::START);
326 ASSERT_EQ(session_->lifeCycleTaskQueue_.size(), 1);
327
__anonbffd99df0502() 328 auto task2 = []() {};
329 session_->PostLifeCycleTask(task2, "task2", LifeCycleTaskType::START);
330 ASSERT_EQ(session_->lifeCycleTaskQueue_.size(), 2);
331
332 LifeCycleTaskType taskType = LifeCycleTaskType{ 0 };
333
334 session_->RemoveLifeCycleTask(taskType);
335 ASSERT_EQ(session_->lifeCycleTaskQueue_.size(), 1);
336
337 session_->RemoveLifeCycleTask(taskType);
338 ASSERT_EQ(session_->lifeCycleTaskQueue_.size(), 0);
339 }
340
341 /**
342 * @tc.name: SetSessionProperty01
343 * @tc.desc: SetSessionProperty
344 * @tc.type: FUNC
345 */
346 HWTEST_F(WindowSessionTest, SetSessionProperty01, TestSize.Level1)
347 {
348 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
349 property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
350 property->SetIsNeedUpdateWindowMode(true);
351 session_->SetScreenId(233);
352 session_->SetSessionProperty(property);
353 ASSERT_EQ(session_->SetSessionProperty(property), WSError::WS_OK);
354 }
355
356 /**
357 * @tc.name: SetSessionRect
358 * @tc.desc: check func SetSessionRect
359 * @tc.type: FUNC
360 */
361 HWTEST_F(WindowSessionTest, SetSessionRect, TestSize.Level1)
362 {
363 ASSERT_NE(session_, nullptr);
364 WSRect rect = { 0, 0, 320, 240 }; // width: 320, height: 240
365 session_->SetSessionRect(rect);
366 ASSERT_EQ(rect, session_->GetSessionRect());
367 }
368
369 /**
370 * @tc.name: GetSessionRect
371 * @tc.desc: check func GetSessionRect
372 * @tc.type: FUNC
373 */
374 HWTEST_F(WindowSessionTest, GetSessionRect, TestSize.Level1)
375 {
376 ASSERT_NE(session_, nullptr);
377 WSRect rect = { 0, 0, 320, 240 }; // width: 320, height: 240
378 session_->SetSessionRect(rect);
379 ASSERT_EQ(rect, session_->GetSessionRect());
380 }
381
382 /**
383 * @tc.name: GetLayoutRect
384 * @tc.desc: check func GetLayoutRect
385 * @tc.type: FUNC
386 */
387 HWTEST_F(WindowSessionTest, GetLayoutRect, TestSize.Level1)
388 {
389 ASSERT_NE(session_, nullptr);
390 WSRect rect = { 0, 0, 320, 240 }; // width: 320, height: 240
391 session_->layoutRect_ = rect;
392 session_->lastLayoutRect_ = session_->layoutRect_;
393 ASSERT_EQ(rect, session_->GetLayoutRect());
394 ASSERT_EQ(rect, session_->GetLastLayoutRect());
395 }
396
397 /**
398 * @tc.name: GetGlobalScaledRect
399 * @tc.desc: GetGlobalScaledRect
400 * @tc.type: FUNC
401 */
402 HWTEST_F(WindowSessionTest, GetGlobalScaledRect, TestSize.Level1)
403 {
404 SessionInfo info;
405 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
406 Rect globalScaledRect;
407 sceneSession->SetSessionGlobalRect({ 100, 100, 50, 40 });
408 sceneSession->isScbCoreEnabled_ = true;
409 sceneSession->SetScale(0.5f, 0.5f, sceneSession->GetPivotX(), sceneSession->GetPivotY());
410 WMError ret = sceneSession->GetGlobalScaledRect(globalScaledRect);
411 ASSERT_EQ(WMError::WM_OK, ret);
412 ASSERT_EQ(100, globalScaledRect.posX_);
413 ASSERT_EQ(100, globalScaledRect.posY_);
414 ASSERT_EQ(25, globalScaledRect.width_);
415 ASSERT_EQ(20, globalScaledRect.height_);
416 }
417
418 /**
419 * @tc.name: RaiseToAppTop01
420 * @tc.desc: RaiseToAppTop
421 * @tc.type: FUNC
422 */
423 HWTEST_F(WindowSessionTest, RaiseToAppTop01, TestSize.Level1)
424 {
425 SessionInfo info;
426 info.abilityName_ = "testSession1";
427 info.bundleName_ = "testSession3";
428 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
429 auto result = sceneSession->RaiseToAppTop();
430 ASSERT_EQ(result, WSError::WS_OK);
431
432 sptr<SceneSession> parentSession = sptr<SceneSession>::MakeSptr(info, nullptr);
433 sceneSession->SetParentSession(parentSession);
434 result = sceneSession->RaiseToAppTop();
435 ASSERT_EQ(result, WSError::WS_OK);
436 ASSERT_FALSE(parentSession->GetUIStateDirty());
437
438 parentSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
__anonbffd99df0602() 439 NotifyRaiseToTopFunc onRaiseToTop = []() {};
440 sceneSession->onRaiseToTop_ = onRaiseToTop;
441 result = sceneSession->RaiseToAppTop();
442 ASSERT_EQ(result, WSError::WS_OK);
443 ASSERT_TRUE(parentSession->GetUIStateDirty());
444 parentSession->SetUIStateDirty(false);
445
446 parentSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
447 result = sceneSession->RaiseToAppTop();
448 ASSERT_EQ(result, WSError::WS_OK);
449 ASSERT_FALSE(parentSession->GetUIStateDirty());
450 }
451
452 /**
453 * @tc.name: OnSessionEvent01
454 * @tc.desc: OnSessionEvent
455 * @tc.type: FUNC
456 */
457 HWTEST_F(WindowSessionTest, OnSessionEvent01, TestSize.Level1)
458 {
459 SessionInfo info;
460 info.abilityName_ = "testSession1";
461 info.bundleName_ = "testSession3";
462 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
463 EXPECT_NE(sceneSession, nullptr);
464 auto result = sceneSession->OnSessionEvent(SessionEvent::EVENT_MINIMIZE);
465 ASSERT_EQ(result, WSError::WS_OK);
466
467 result = sceneSession->OnSessionEvent(SessionEvent::EVENT_MINIMIZE);
468 ASSERT_EQ(result, WSError::WS_OK);
469
470 int resultValue = 0;
__anonbffd99df0702(int32_t eventId, SessionEventParam param) 471 NotifySessionEventFunc onSessionEvent_ = [&resultValue](int32_t eventId, SessionEventParam param) {
472 resultValue = 1;
473 };
474 sceneSession->onSessionEvent_ = onSessionEvent_;
475 result = sceneSession->OnSessionEvent(SessionEvent::EVENT_MINIMIZE);
476 ASSERT_EQ(result, WSError::WS_OK);
477 }
478
479 /**
480 * @tc.name: OnSessionEvent02
481 * @tc.desc: OnSessionEvent drag
482 * @tc.type: FUNC
483 */
484 HWTEST_F(WindowSessionTest, OnSessionEvent02, TestSize.Level1)
485 {
486 SessionInfo info;
487 info.abilityName_ = "testSession1";
488 info.bundleName_ = "testSession3";
489 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
490 EXPECT_NE(sceneSession, nullptr);
491 sceneSession->moveDragController_ = sptr<MoveDragController>::MakeSptr(1, WindowType::WINDOW_TYPE_FLOAT);
492 ASSERT_TRUE(sceneSession->moveDragController_);
493 sceneSession->moveDragController_->InitMoveDragProperty();
494 WSRect targetRect = { 100, 100, 1000, 1000 };
495 sceneSession->moveDragController_->moveDragProperty_.targetRect_ = targetRect;
496 auto result = sceneSession->OnSessionEvent(SessionEvent::EVENT_DRAG);
497 ASSERT_EQ(result, WSError::WS_OK);
498 }
499
500 /**
501 * @tc.name: ConsumeMoveEvent02
502 * @tc.desc: ConsumeMoveEvent, normal secne
503 * @tc.type: FUNC
504 */
505 HWTEST_F(WindowSessionTest, ConsumeMoveEvent02, TestSize.Level1)
506 {
507 SessionInfo info;
508 info.abilityName_ = "testSession1";
509 info.bundleName_ = "testSession3";
510 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
511 EXPECT_NE(sceneSession, nullptr);
512 sceneSession->moveDragController_ = sptr<MoveDragController>::MakeSptr(1, WindowType::WINDOW_TYPE_FLOAT);
513 ASSERT_TRUE(sceneSession->moveDragController_);
514 sceneSession->moveDragController_->InitMoveDragProperty();
515 WSRect originalRect = { 100, 100, 1000, 1000 };
516 sceneSession->moveDragController_->isStartMove_ = true;
517 std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
518 ASSERT_TRUE(pointerEvent);
519 pointerEvent->SetAgentWindowId(1);
520 pointerEvent->SetPointerId(0);
521 pointerEvent->SetSourceType(MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
522 MMI::PointerEvent::PointerItem pointerItem;
523 pointerItem.SetPointerId(0);
524 pointerItem.SetOriginPointerId(0);
525 pointerEvent->AddPointerItem(pointerItem);
526
527 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_MOVE);
528 pointerItem.SetDisplayX(115);
529 pointerItem.SetDisplayY(500);
530 pointerItem.SetWindowX(15);
531 pointerItem.SetWindowY(400);
532 auto result = sceneSession->moveDragController_->ConsumeMoveEvent(pointerEvent, originalRect);
533 ASSERT_EQ(result, true);
534
535 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_MOVE);
536 pointerItem.SetDisplayX(145);
537 pointerItem.SetDisplayY(550);
538 result = sceneSession->moveDragController_->ConsumeMoveEvent(pointerEvent, originalRect);
539 ASSERT_EQ(result, true);
540
541 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_MOVE);
542 pointerItem.SetDisplayX(175);
543 pointerItem.SetDisplayY(600);
544 result = sceneSession->moveDragController_->ConsumeMoveEvent(pointerEvent, originalRect);
545 ASSERT_EQ(result, true);
546
547 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_UP);
548 pointerItem.SetDisplayX(205);
549 pointerItem.SetDisplayY(650);
550 result = sceneSession->moveDragController_->ConsumeMoveEvent(pointerEvent, originalRect);
551 ASSERT_EQ(result, true);
552 }
553
554 /**
555 * @tc.name: ConsumeDragEvent01
556 * @tc.desc: ConsumeDragEvent, abnormal scene
557 * @tc.type: FUNC
558 */
559 HWTEST_F(WindowSessionTest, ConsumeDragEvent01, TestSize.Level1)
560 {
561 SessionInfo info;
562 info.abilityName_ = "testSession1";
563 info.bundleName_ = "testSession3";
564 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
565 EXPECT_NE(sceneSession, nullptr);
566 sceneSession->moveDragController_ = sptr<MoveDragController>::MakeSptr(1, WindowType::WINDOW_TYPE_FLOAT);
567 ASSERT_TRUE(sceneSession->moveDragController_);
568 sceneSession->moveDragController_->InitMoveDragProperty();
569 WSRect originalRect = { 100, 100, 1000, 1000 };
570 SystemSessionConfig sessionConfig;
571
572 std::shared_ptr<MMI::PointerEvent> pointerEvent = nullptr;
573 sptr<WindowSessionProperty> property = nullptr;
574 auto result =
575 sceneSession->moveDragController_->ConsumeDragEvent(pointerEvent, originalRect, property, sessionConfig);
576 ASSERT_EQ(result, false);
577
578 pointerEvent = MMI::PointerEvent::Create();
579 ASSERT_TRUE(pointerEvent);
580 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_UP);
581 property = sptr<WindowSessionProperty>::MakeSptr();
582 sceneSession->moveDragController_->isStartDrag_ = false;
583 result = sceneSession->moveDragController_->ConsumeDragEvent(pointerEvent, originalRect, property, sessionConfig);
584 ASSERT_EQ(result, false);
585
586 pointerEvent->SetPointerId(1);
587 sceneSession->moveDragController_->moveDragProperty_.pointerId_ = 0;
588 sceneSession->moveDragController_->isStartDrag_ = true;
589 result = sceneSession->moveDragController_->ConsumeDragEvent(pointerEvent, originalRect, property, sessionConfig);
590 ASSERT_EQ(result, false);
591
592 pointerEvent->SetPointerId(0);
593 result = sceneSession->moveDragController_->ConsumeDragEvent(pointerEvent, originalRect, property, sessionConfig);
594 ASSERT_EQ(result, false);
595 }
596
597 /**
598 * @tc.name: ConsumeDragEvent02
599 * @tc.desc: ConsumeDragEvent, normal scene
600 * @tc.type: FUNC
601 */
602 HWTEST_F(WindowSessionTest, ConsumeDragEvent02, TestSize.Level1)
603 {
604 SessionInfo info;
605 info.abilityName_ = "testSession1";
606 info.bundleName_ = "testSession3";
607 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
608 sceneSession->moveDragController_ = sptr<MoveDragController>::MakeSptr(1, WindowType::WINDOW_TYPE_FLOAT);
609 ASSERT_TRUE(sceneSession->moveDragController_);
610 sceneSession->moveDragController_->InitMoveDragProperty();
611 WSRect originalRect = { 100, 100, 1000, 1000 };
612 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
613 property->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
614 property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
615 SystemSessionConfig sessionConfig;
616 sessionConfig.isSystemDecorEnable_ = true;
617 sessionConfig.backgroundswitch = true;
618 sessionConfig.decorWindowModeSupportType_ = WindowModeSupport::WINDOW_MODE_SUPPORT_ALL;
619 std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
620 pointerEvent->SetAgentWindowId(1);
621 pointerEvent->SetPointerId(0);
622 pointerEvent->SetSourceType(MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
623 MMI::PointerEvent::PointerItem pointerItem;
624 pointerItem.SetPointerId(0);
625 pointerItem.SetOriginPointerId(0);
626 pointerEvent->AddPointerItem(pointerItem);
627 sceneSession->moveDragController_->moveDragProperty_.pointerId_ = pointerItem.GetOriginPointerId();
628 sceneSession->moveDragController_->moveDragProperty_.pointerType_ = pointerEvent->GetSourceType();
629
630 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_DOWN);
631 pointerItem.SetDisplayX(100);
632 pointerItem.SetDisplayY(100);
633 pointerItem.SetWindowX(0);
634 pointerItem.SetWindowY(0);
635 auto result =
636 sceneSession->moveDragController_->ConsumeDragEvent(pointerEvent, originalRect, property, sessionConfig);
637 ASSERT_EQ(result, true);
638
639 sceneSession->moveDragController_->aspectRatio_ = 0.0f;
640 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_MOVE);
641 pointerItem.SetDisplayX(150);
642 pointerItem.SetDisplayY(150);
643 result = sceneSession->moveDragController_->ConsumeDragEvent(pointerEvent, originalRect, property, sessionConfig);
644 ASSERT_EQ(result, true);
645
646 sceneSession->moveDragController_->aspectRatio_ = 1.0f;
647 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_MOVE);
648 pointerItem.SetDisplayX(200);
649 pointerItem.SetDisplayY(200);
650 result = sceneSession->moveDragController_->ConsumeDragEvent(pointerEvent, originalRect, property, sessionConfig);
651 ASSERT_EQ(result, true);
652
653 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_UP);
654 pointerItem.SetDisplayX(250);
655 pointerItem.SetDisplayY(250);
656 result = sceneSession->moveDragController_->ConsumeDragEvent(pointerEvent, originalRect, property, sessionConfig);
657 ASSERT_EQ(result, true);
658 }
659
660 /**
661 * @tc.name: ConsumeDragEvent03
662 * @tc.desc: ConsumeDragEvent, normal scene
663 * @tc.type: FUNC
664 */
665 HWTEST_F(WindowSessionTest, ConsumeDragEvent03, TestSize.Level1)
666 {
667 SessionInfo info;
668 info.abilityName_ = "testSession1";
669 info.bundleName_ = "testSession3";
670 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
671 EXPECT_NE(sceneSession, nullptr);
672 sceneSession->moveDragController_ = sptr<MoveDragController>::MakeSptr(1, WindowType::WINDOW_TYPE_FLOAT);
673 ASSERT_TRUE(sceneSession->moveDragController_);
674 sceneSession->moveDragController_->InitMoveDragProperty();
675 WSRect originalRect = { 100, 100, 1000, 1000 };
676 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
677 property->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
678 property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
679 SystemSessionConfig sessionConfig;
680 sessionConfig.isSystemDecorEnable_ = true;
681 sessionConfig.backgroundswitch = true;
682 sessionConfig.decorWindowModeSupportType_ = WindowModeSupport::WINDOW_MODE_SUPPORT_ALL;
683 std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
684 pointerEvent->SetAgentWindowId(1);
685 pointerEvent->SetPointerId(0);
686 pointerEvent->SetSourceType(MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
687 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_DOWN);
688 MMI::PointerEvent::PointerItem pointerItem;
689 pointerItem.SetPointerId(0);
690 pointerItem.SetOriginPointerId(0);
691 pointerEvent->AddPointerItem(pointerItem);
692 sceneSession->moveDragController_->moveDragProperty_.pointerId_ = pointerItem.GetOriginPointerId();
693 sceneSession->moveDragController_->moveDragProperty_.pointerType_ = pointerEvent->GetSourceType();
694
695 // LEFT_TOP
696 pointerItem.SetWindowX(0);
697 pointerItem.SetWindowY(0);
698 auto result =
699 sceneSession->moveDragController_->ConsumeDragEvent(pointerEvent, originalRect, property, sessionConfig);
700 ASSERT_EQ(result, true);
701
702 // RIGHT_TOP
703 pointerItem.SetWindowX(1000);
704 pointerItem.SetWindowY(0);
705 result = sceneSession->moveDragController_->ConsumeDragEvent(pointerEvent, originalRect, property, sessionConfig);
706 ASSERT_EQ(result, true);
707
708 // RIGHT_BOTTOM
709 pointerItem.SetWindowX(1000);
710 pointerItem.SetWindowY(1000);
711 result = sceneSession->moveDragController_->ConsumeDragEvent(pointerEvent, originalRect, property, sessionConfig);
712 ASSERT_EQ(result, true);
713
714 // LEFT_BOTTOM
715 pointerItem.SetWindowX(0);
716 pointerItem.SetWindowY(1000);
717 result = sceneSession->moveDragController_->ConsumeDragEvent(pointerEvent, originalRect, property, sessionConfig);
718 ASSERT_EQ(result, true);
719 }
720
721 /**
722 * @tc.name: ConsumeDragEvent04
723 * @tc.desc: ConsumeDragEvent, normal scene
724 * @tc.type: FUNC
725 */
726 HWTEST_F(WindowSessionTest, ConsumeDragEvent04, TestSize.Level1)
727 {
728 SessionInfo info;
729 info.abilityName_ = "testSession1";
730 info.bundleName_ = "testSession3";
731 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
732 EXPECT_NE(sceneSession, nullptr);
733 sceneSession->moveDragController_ = sptr<MoveDragController>::MakeSptr(1, WindowType::WINDOW_TYPE_FLOAT);
734 ASSERT_TRUE(sceneSession->moveDragController_);
735 sceneSession->moveDragController_->InitMoveDragProperty();
736 WSRect originalRect = { 100, 100, 1000, 1000 };
737 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
738 property->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
739 property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
740 SystemSessionConfig sessionConfig;
741 sessionConfig.isSystemDecorEnable_ = true;
742 sessionConfig.backgroundswitch = true;
743 sessionConfig.decorWindowModeSupportType_ = WindowModeSupport::WINDOW_MODE_SUPPORT_ALL;
744 std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
745 pointerEvent->SetAgentWindowId(1);
746 pointerEvent->SetPointerId(0);
747 pointerEvent->SetSourceType(MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
748 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_DOWN);
749 MMI::PointerEvent::PointerItem pointerItem;
750 pointerItem.SetPointerId(0);
751 pointerItem.SetOriginPointerId(0);
752 pointerEvent->AddPointerItem(pointerItem);
753 sceneSession->moveDragController_->moveDragProperty_.pointerId_ = pointerItem.GetOriginPointerId();
754 sceneSession->moveDragController_->moveDragProperty_.pointerType_ = pointerEvent->GetSourceType();
755
756 // LEFT
757 pointerItem.SetWindowX(0);
758 pointerItem.SetWindowY(500);
759 auto result =
760 sceneSession->moveDragController_->ConsumeDragEvent(pointerEvent, originalRect, property, sessionConfig);
761 ASSERT_EQ(result, true);
762
763 // TOP
764 pointerItem.SetWindowX(500);
765 pointerItem.SetWindowY(0);
766 result = sceneSession->moveDragController_->ConsumeDragEvent(pointerEvent, originalRect, property, sessionConfig);
767 ASSERT_EQ(result, true);
768
769 // RIGHT
770 pointerItem.SetWindowX(1000);
771 pointerItem.SetWindowY(500);
772 result = sceneSession->moveDragController_->ConsumeDragEvent(pointerEvent, originalRect, property, sessionConfig);
773 ASSERT_EQ(result, true);
774
775 // BOTTOM
776 pointerItem.SetWindowX(500);
777 pointerItem.SetWindowY(1000);
778 result = sceneSession->moveDragController_->ConsumeDragEvent(pointerEvent, originalRect, property, sessionConfig);
779 ASSERT_EQ(result, true);
780 }
781
782 /**
783 * @tc.name: GetWindowId01
784 * @tc.desc: GetWindowId, normal scene
785 * @tc.type: FUNC
786 */
787 HWTEST_F(WindowSessionTest, GetWindowId, TestSize.Level1)
788 {
789 ASSERT_NE(session_, nullptr);
790 ASSERT_EQ(0, session_->GetWindowId());
791 }
792
793 /**
794 * @tc.name: GetRSVisible01
795 * @tc.desc: GetRSVisible, normal scene
796 * @tc.type: FUNC
797 */
798 HWTEST_F(WindowSessionTest, GetRSVisible, TestSize.Level1)
799 {
800 ASSERT_NE(session_, nullptr);
801 ASSERT_EQ(WSError::WS_OK, session_->SetRSVisible(false));
802 session_->state_ = SessionState::STATE_CONNECT;
803 if (!session_->GetRSVisible()) {
804 ASSERT_EQ(false, session_->GetRSVisible());
805 }
806 }
807
808 /**
809 * @tc.name: SetFocusable01
810 * @tc.desc: SetFocusable, normal scene
811 * @tc.type: FUNC
812 */
813 HWTEST_F(WindowSessionTest, SetFocusable, TestSize.Level1)
814 {
815 ASSERT_NE(session_, nullptr);
816 session_->state_ = SessionState::STATE_DISCONNECT;
817 ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(false));
818 ASSERT_EQ(session_->GetFocusable(), false);
819 }
820
821 /**
822 * @tc.name: Snapshot
823 * @tc.desc: Snapshot Test
824 * @tc.type: FUNC
825 */
826 HWTEST_F(WindowSessionTest, Snapshot, TestSize.Level1)
827 {
828 ASSERT_NE(session_, nullptr);
829 int32_t persistentId = 1999;
830 std::string bundleName = "test";
831 session_->scenePersistence_ = sptr<ScenePersistence>::MakeSptr(bundleName, persistentId);
832 ASSERT_NE(session_->scenePersistence_, nullptr);
833 struct RSSurfaceNodeConfig config;
834 session_->surfaceNode_ = RSSurfaceNode::Create(config);
835 ASSERT_NE(session_->surfaceNode_, nullptr);
836 EXPECT_EQ(nullptr, session_->Snapshot(false, 0.0f));
837
838 session_->bufferAvailable_ = true;
839 EXPECT_EQ(nullptr, session_->Snapshot(false, 0.0f));
840
841 session_->surfaceNode_->bufferAvailable_ = true;
842 EXPECT_EQ(nullptr, session_->Snapshot(false, 0.0f));
843
844 session_->surfaceNode_ = nullptr;
845 EXPECT_EQ(nullptr, session_->Snapshot(false, 0.0f));
846 }
847
848 /**
849 * @tc.name: GetSnapshot
850 * @tc.desc: GetSnapshot Test
851 * @tc.type: FUNC
852 */
853 HWTEST_F(WindowSessionTest, GetSnapshot, TestSize.Level1)
854 {
855 ASSERT_NE(session_, nullptr);
856 session_->state_ = SessionState::STATE_DISCONNECT;
857 std::shared_ptr<Media::PixelMap> snapshot = session_->Snapshot();
858 ASSERT_EQ(snapshot, session_->GetSnapshot());
859 }
860
861 /**
862 * @tc.name: NotifyAddSnapshot
863 * @tc.desc: NotifyAddSnapshot Test
864 * @tc.type: FUNC
865 */
866 HWTEST_F(WindowSessionTest, NotifyAddSnapshot, TestSize.Level1)
867 {
868 ASSERT_NE(session_, nullptr);
869 session_->state_ = SessionState::STATE_DISCONNECT;
870 session_->NotifyAddSnapshot();
871 ASSERT_EQ(session_->GetSnapshot(), nullptr);
872 }
873
874 /**
875 * @tc.name: NotifyRemoveSnapshot
876 * @tc.desc: NotifyRemoveSnapshot Test
877 * @tc.type: FUNC
878 */
879 HWTEST_F(WindowSessionTest, NotifyRemoveSnapshot, TestSize.Level1)
880 {
881 ASSERT_NE(session_, nullptr);
882 session_->scenePersistence_ = sptr<ScenePersistence>::MakeSptr("bundleName", 1);
883 session_->state_ = SessionState::STATE_DISCONNECT;
884 session_->NotifyRemoveSnapshot();
885 ASSERT_EQ(session_->GetScenePersistence()->HasSnapshot(), false);
886 }
887
888 /**
889 * @tc.name: NotifyExtensionDied
890 * @tc.desc: NotifyExtensionDied Test
891 * @tc.type: FUNC
892 */
893 HWTEST_F(WindowSessionTest, NotifyExtensionDied, TestSize.Level1)
894 {
895 ASSERT_NE(session_, nullptr);
896 session_->state_ = SessionState::STATE_DISCONNECT;
897 session_->NotifyExtensionDied();
898
899 ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(false));
900 }
901
902 /**
903 * @tc.name: NotifyExtensionTimeout
904 * @tc.desc: NotifyExtensionTimeout Test
905 * @tc.type: FUNC
906 */
907 HWTEST_F(WindowSessionTest, NotifyExtensionTimeout, TestSize.Level1)
908 {
909 ASSERT_NE(session_, nullptr);
910 session_->state_ = SessionState::STATE_DISCONNECT;
911 session_->NotifyExtensionTimeout(3);
912
913 session_->RegisterLifecycleListener(lifecycleListener_);
914 session_->NotifyExtensionTimeout(3);
915 session_->UnregisterLifecycleListener(lifecycleListener_);
916
917 ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(false));
918 }
919
920 /**
921 * @tc.name: SetAspectRatio
922 * @tc.desc: SetAspectRatio Test
923 * @tc.type: FUNC
924 */
925 HWTEST_F(WindowSessionTest, SetAspectRatio, TestSize.Level1)
926 {
927 ASSERT_NE(session_, nullptr);
928 session_->state_ = SessionState::STATE_DISCONNECT;
929 const float ratio = 0.1f;
930 ASSERT_EQ(WSError::WS_OK, session_->SetAspectRatio(ratio));
931 ASSERT_EQ(ratio, session_->GetAspectRatio());
932 }
933
934 /**
935 * @tc.name: UpdateSessionTouchable
936 * @tc.desc: UpdateSessionTouchable Test
937 * @tc.type: FUNC
938 */
939 HWTEST_F(WindowSessionTest, UpdateSessionTouchable, TestSize.Level1)
940 {
941 ASSERT_NE(session_, nullptr);
942
943 session_->state_ = SessionState::STATE_DISCONNECT;
944 session_->UpdateSessionTouchable(false);
945
946 ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(false));
947 }
948
949 /**
950 * @tc.name: SetFocusable02
951 * @tc.desc: others
952 * @tc.type: FUNC
953 */
954 HWTEST_F(WindowSessionTest, SetFocusable02, TestSize.Level1)
955 {
956 ASSERT_NE(session_, nullptr);
957
958 session_->state_ = SessionState::STATE_FOREGROUND;
959 session_->sessionInfo_.isSystem_ = false;
960
961 ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(true));
962 ASSERT_EQ(session_->GetFocusable(), true);
963 }
964
965 /**
966 * @tc.name: GetFocusable01
967 * @tc.desc: property_ is not nullptr
968 * @tc.type: FUNC
969 */
970 HWTEST_F(WindowSessionTest, GetFocusable01, TestSize.Level1)
971 {
972 ASSERT_NE(session_, nullptr);
973 ASSERT_EQ(true, session_->GetFocusable());
974 }
975
976 /**
977 * @tc.name: SetNeedNotify
978 * @tc.desc: SetNeedNotify Test
979 * @tc.type: FUNC
980 */
981 HWTEST_F(WindowSessionTest, SetNeedNotify, TestSize.Level1)
982 {
983 ASSERT_NE(session_, nullptr);
984 session_->state_ = SessionState::STATE_DISCONNECT;
985 session_->SetNeedNotify(false);
986
987 ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(false));
988 }
989
990 /**
991 * @tc.name: NeedNotify
992 * @tc.desc: NeedNotify Test
993 * @tc.type: FUNC
994 */
995 HWTEST_F(WindowSessionTest, NeedNotify, TestSize.Level1)
996 {
997 ASSERT_NE(session_, nullptr);
998 session_->state_ = SessionState::STATE_DISCONNECT;
999 session_->SetNeedNotify(true);
1000 ASSERT_EQ(true, session_->NeedNotify());
1001 }
1002
1003 /**
1004 * @tc.name: SetFocusedOnShow
1005 * @tc.desc: SetFocusedOnShow Test
1006 * @tc.type: FUNC
1007 */
1008 HWTEST_F(WindowSessionTest, SetFocusedOnShow, TestSize.Level1)
1009 {
1010 ASSERT_NE(session_, nullptr);
1011 session_->SetFocusedOnShow(false);
1012 auto focusedOnShow = session_->IsFocusedOnShow();
1013 ASSERT_EQ(focusedOnShow, false);
1014 session_->SetFocusedOnShow(true);
1015 focusedOnShow = session_->IsFocusedOnShow();
1016 ASSERT_EQ(focusedOnShow, true);
1017 }
1018
1019 /**
1020 * @tc.name: SetTouchable01
1021 * @tc.desc: IsSessionValid() return false
1022 * @tc.type: FUNC
1023 */
1024 HWTEST_F(WindowSessionTest, SetTouchable01, TestSize.Level1)
1025 {
1026 ASSERT_NE(session_, nullptr);
1027 session_->state_ = SessionState::STATE_DISCONNECT;
1028 session_->sessionInfo_.isSystem_ = true;
1029 ASSERT_EQ(WSError::WS_ERROR_INVALID_SESSION, session_->SetTouchable(false));
1030 }
1031
1032 /**
1033 * @tc.name: SetTouchable02
1034 * @tc.desc: IsSessionValid() return true
1035 * @tc.type: FUNC
1036 */
1037 HWTEST_F(WindowSessionTest, SetTouchable02, TestSize.Level1)
1038 {
1039 ASSERT_NE(session_, nullptr);
1040 session_->state_ = SessionState::STATE_FOREGROUND;
1041 session_->sessionInfo_.isSystem_ = false;
1042 ASSERT_EQ(WSError::WS_OK, session_->SetTouchable(false));
1043 }
1044
1045 /**
1046 * @tc.name: SetSessionInfoLockedState01
1047 * @tc.desc: IsSessionValid() return false
1048 * @tc.type: FUNC
1049 */
1050 HWTEST_F(WindowSessionTest, SetSessionInfoLockedState01, TestSize.Level1)
1051 {
1052 ASSERT_NE(session_, nullptr);
1053 session_->SetSessionInfoLockedState(false);
1054 ASSERT_EQ(false, session_->sessionInfo_.lockedState);
1055 }
1056
1057 /**
1058 * @tc.name: SetSessionInfoLockedState02
1059 * @tc.desc: IsSessionValid() return true
1060 * @tc.type: FUNC
1061 */
1062 HWTEST_F(WindowSessionTest, SetSessionInfoLockedState02, TestSize.Level1)
1063 {
1064 ASSERT_NE(session_, nullptr);
1065 session_->SetSessionInfoLockedState(true);
1066 ASSERT_EQ(true, session_->sessionInfo_.lockedState);
1067 }
1068
1069 /**
1070 * @tc.name: GetCallingPid
1071 * @tc.desc: GetCallingPid Test
1072 * @tc.type: FUNC
1073 */
1074 HWTEST_F(WindowSessionTest, GetCallingPid, TestSize.Level1)
1075 {
1076 ASSERT_NE(session_, nullptr);
1077 session_->SetCallingPid(111);
1078 ASSERT_EQ(111, session_->GetCallingPid());
1079 }
1080
1081 /**
1082 * @tc.name: GetCallingUid
1083 * @tc.desc: GetCallingUid Test
1084 * @tc.type: FUNC
1085 */
1086 HWTEST_F(WindowSessionTest, GetCallingUid, TestSize.Level1)
1087 {
1088 ASSERT_NE(session_, nullptr);
1089 session_->SetCallingUid(111);
1090 ASSERT_EQ(111, session_->GetCallingUid());
1091 }
1092
1093 /**
1094 * @tc.name: GetAbilityToken
1095 * @tc.desc: GetAbilityToken Test
1096 * @tc.type: FUNC
1097 */
1098 HWTEST_F(WindowSessionTest, GetAbilityToken, TestSize.Level1)
1099 {
1100 ASSERT_NE(session_, nullptr);
1101 session_->SetAbilityToken(nullptr);
1102 ASSERT_EQ(nullptr, session_->GetAbilityToken());
1103 }
1104
1105 /**
1106 * @tc.name: SetBrightness01
1107 * @tc.desc: property_ is nullptr
1108 * @tc.type: FUNC
1109 */
1110 HWTEST_F(WindowSessionTest, SetBrightness01, TestSize.Level1)
1111 {
1112 ASSERT_NE(session_, nullptr);
1113 session_->state_ = SessionState::STATE_DISCONNECT;
1114 ASSERT_EQ(WSError::WS_OK, session_->SetBrightness(0.1f));
1115 }
1116
1117 /**
1118 * @tc.name: SetBrightness02
1119 * @tc.desc: property_ is not nullptr
1120 * @tc.type: FUNC
1121 */
1122 HWTEST_F(WindowSessionTest, SetBrightness02, TestSize.Level1)
1123 {
1124 ASSERT_NE(session_, nullptr);
1125 session_->state_ = SessionState::STATE_DISCONNECT;
1126 ASSERT_EQ(WSError::WS_OK, session_->SetBrightness(0.1f));
1127 }
1128
1129 /**
1130 * @tc.name: UpdateHotRect
1131 * @tc.desc: UpdateHotRect Test
1132 * @tc.type: FUNC
1133 */
1134 HWTEST_F(WindowSessionTest, UpdateHotRect, TestSize.Level1)
1135 {
1136 ASSERT_NE(session_, nullptr);
1137
1138 WSRect rect;
1139 rect.posX_ = 0;
1140 rect.posY_ = 0;
1141 rect.width_ = 0;
1142 rect.height_ = 0;
1143
1144 WSRectF newRect;
1145 const float outsideBorder = 4.0f * 1.5f;
1146 const size_t outsideBorderCount = 2;
1147 newRect.posX_ = rect.posX_ - outsideBorder;
1148 newRect.posY_ = rect.posY_ - outsideBorder;
1149 newRect.width_ = rect.width_ + outsideBorder * outsideBorderCount;
1150 newRect.height_ = rect.height_ + outsideBorder * outsideBorderCount;
1151
1152 ASSERT_EQ(newRect, session_->UpdateHotRect(rect));
1153 }
1154
1155 /**
1156 * @tc.name: SetTerminateSessionListener
1157 * @tc.desc: SetTerminateSessionListener Test
1158 * @tc.type: FUNC
1159 */
1160 HWTEST_F(WindowSessionTest, SetTerminateSessionListener, TestSize.Level1)
1161 {
1162 ASSERT_NE(session_, nullptr);
1163 session_->state_ = SessionState::STATE_DISCONNECT;
1164 session_->SetTerminateSessionListener(nullptr);
1165
1166 ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(false));
1167 }
1168
1169 /**
1170 * @tc.name: SetTerminateSessionListenerTotal
1171 * @tc.desc: SetTerminateSessionListenerTotal Test
1172 * @tc.type: FUNC
1173 */
1174 HWTEST_F(WindowSessionTest, SetTerminateSessionListenerTotal, TestSize.Level1)
1175 {
1176 ASSERT_NE(session_, nullptr);
1177 session_->state_ = SessionState::STATE_DISCONNECT;
1178 session_->SetTerminateSessionListenerTotal(nullptr);
1179
1180 ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(false));
1181 }
1182
1183 /**
1184 * @tc.name: SetSessionLabel
1185 * @tc.desc: SetSessionLabel Test
1186 * @tc.type: FUNC
1187 */
1188 HWTEST_F(WindowSessionTest, SetSessionLabel, TestSize.Level1)
1189 {
1190 ASSERT_NE(session_, nullptr);
1191 session_->state_ = SessionState::STATE_DISCONNECT;
__anonbffd99df0802(const std::string& label) 1192 NofitySessionLabelUpdatedFunc func = [](const std::string& label) {};
1193 session_->updateSessionLabelFunc_ = func;
1194 ASSERT_EQ(WSError::WS_OK, session_->SetSessionLabel("SetSessionLabel Test"));
1195 }
1196
1197 /**
1198 * @tc.name: SetUpdateSessionLabelListener
1199 * @tc.desc: SetUpdateSessionLabelListener Test
1200 * @tc.type: FUNC
1201 */
1202 HWTEST_F(WindowSessionTest, SetUpdateSessionLabelListener, TestSize.Level1)
1203 {
1204 ASSERT_NE(session_, nullptr);
1205 session_->state_ = SessionState::STATE_DISCONNECT;
1206 NofitySessionLabelUpdatedFunc func = nullptr;
1207 session_->SetUpdateSessionLabelListener(func);
1208
1209 ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(false));
1210 }
1211
1212 /**
1213 * @tc.name: SetPendingSessionToForegroundListener
1214 * @tc.desc: SetPendingSessionToForegroundListener Test
1215 * @tc.type: FUNC
1216 */
1217 HWTEST_F(WindowSessionTest, SetPendingSessionToForegroundListener, TestSize.Level1)
1218 {
1219 ASSERT_NE(session_, nullptr);
1220 session_->state_ = SessionState::STATE_DISCONNECT;
1221 session_->SetPendingSessionToForegroundListener(nullptr);
1222
1223 ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(false));
1224 }
1225
1226 /**
1227 * @tc.name: NotifyScreenshot
1228 * @tc.desc: NotifyScreenshot Test
1229 * @tc.type: FUNC
1230 */
1231 HWTEST_F(WindowSessionTest, NotifyScreenshot, TestSize.Level1)
1232 {
1233 ASSERT_NE(session_, nullptr);
1234 session_->sessionStage_ = nullptr;
1235 session_->NotifyScreenshot();
1236
1237 session_->sessionStage_ = mockSessionStage_;
1238 session_->NotifyScreenshot();
1239
1240 ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(false));
1241 }
1242
1243 /**
1244 * @tc.name: NotifyScreenshotAppEvent
1245 * @tc.desc: NotifyScreenshotAppEvent Test
1246 * @tc.type: FUNC
1247 */
1248 HWTEST_F(WindowSessionTest, NotifyScreenshotAppEvent, TestSize.Level1)
1249 {
1250 ASSERT_NE(session_, nullptr);
1251 ScreenshotEventType type = ScreenshotEventType::SCROLL_SHOT_START;
1252 session_->sessionStage_ = nullptr;
1253 auto ret = session_->NotifyScreenshotAppEvent(type);
1254 EXPECT_EQ(ret, WSError::WS_ERROR_NULLPTR);
1255
1256 session_->sessionStage_ = mockSessionStage_;
1257 ret = session_->NotifyScreenshotAppEvent(type);
1258 EXPECT_EQ(ret, WSError::WS_OK);
1259 }
1260
1261 /**
1262 * @tc.name: TransferBackPressedEventForConsumed02
1263 * @tc.desc: windowEventChannel_ is not nullptr
1264 * @tc.type: FUNC
1265 */
1266 HWTEST_F(WindowSessionTest, TransferBackPressedEventForConsumed02, TestSize.Level1)
1267 {
1268 ASSERT_NE(session_, nullptr);
1269
1270 session_->windowEventChannel_ = sptr<TestWindowEventChannel>::MakeSptr();
1271
1272 bool isConsumed = false;
1273 ASSERT_EQ(WSError::WS_OK, session_->TransferBackPressedEventForConsumed(isConsumed));
1274 }
1275
1276 /**
1277 * @tc.name: TransferFocusActiveEvent02
1278 * @tc.desc: windowEventChannel_ is not nullptr
1279 * @tc.type: FUNC
1280 */
1281 HWTEST_F(WindowSessionTest, TransferFocusActiveEvent02, TestSize.Level1)
1282 {
1283 ASSERT_NE(session_, nullptr);
1284
1285 session_->windowEventChannel_ = sptr<TestWindowEventChannel>::MakeSptr();
1286
1287 ASSERT_EQ(WSError::WS_OK, session_->TransferFocusActiveEvent(false));
1288 }
1289
1290 /**
1291 * @tc.name: TransferFocusStateEvent02
1292 * @tc.desc: windowEventChannel_ is not nullptr
1293 * @tc.type: FUNC
1294 */
1295 HWTEST_F(WindowSessionTest, TransferFocusStateEvent02, TestSize.Level1)
1296 {
1297 ASSERT_NE(session_, nullptr);
1298
1299 session_->windowEventChannel_ = sptr<TestWindowEventChannel>::MakeSptr();
1300
1301 ASSERT_EQ(WSError::WS_OK, session_->TransferFocusStateEvent(false));
1302 }
1303
1304 /**
1305 * @tc.name: CreateDetectStateTask001
1306 * @tc.desc: Create detection task when there are no pre_existing tasks.
1307 * @tc.type: FUNC
1308 */
1309 HWTEST_F(WindowSessionTest, CreateDetectStateTask001, TestSize.Level1)
1310 {
1311 session_->systemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
1312 std::string taskName = "wms:WindowStateDetect" + std::to_string(session_->persistentId_);
1313 DetectTaskInfo detectTaskInfo;
1314 detectTaskInfo.taskState = DetectTaskState::NO_TASK;
1315 int32_t beforeTaskNum = GetTaskCount();
1316 session_->SetDetectTaskInfo(detectTaskInfo);
1317 session_->CreateDetectStateTask(false, WindowMode::WINDOW_MODE_FULLSCREEN);
1318
1319 ASSERT_EQ(beforeTaskNum + 1, GetTaskCount());
1320 ASSERT_EQ(DetectTaskState::DETACH_TASK, session_->GetDetectTaskInfo().taskState);
1321 session_->handler_->RemoveTask(taskName);
1322
1323 session_->showRecent_ = true;
1324 session_->CreateDetectStateTask(false, WindowMode::WINDOW_MODE_FULLSCREEN);
1325 }
1326
1327 /**
1328 * @tc.name: CreateDetectStateTask002
1329 * @tc.desc: Detect state when window mode changed.
1330 * @tc.type: FUNC
1331 */
1332 HWTEST_F(WindowSessionTest, CreateDetectStateTask002, TestSize.Level1)
1333 {
1334 session_->systemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
1335 std::string taskName = "wms:WindowStateDetect" + std::to_string(session_->persistentId_);
__anonbffd99df0902() 1336 auto task = []() {};
1337 int64_t delayTime = 3000;
1338 session_->handler_->PostTask(task, taskName, delayTime);
1339 int32_t beforeTaskNum = GetTaskCount();
1340
1341 DetectTaskInfo detectTaskInfo;
1342 detectTaskInfo.taskState = DetectTaskState::DETACH_TASK;
1343 detectTaskInfo.taskWindowMode = WindowMode::WINDOW_MODE_FULLSCREEN;
1344 session_->SetDetectTaskInfo(detectTaskInfo);
1345 session_->CreateDetectStateTask(true, WindowMode::WINDOW_MODE_SPLIT_SECONDARY);
1346
1347 ASSERT_EQ(beforeTaskNum - 1, GetTaskCount());
1348 ASSERT_EQ(DetectTaskState::NO_TASK, session_->GetDetectTaskInfo().taskState);
1349 ASSERT_EQ(WindowMode::WINDOW_MODE_UNDEFINED, session_->GetDetectTaskInfo().taskWindowMode);
1350 session_->handler_->RemoveTask(taskName);
1351
1352 session_->showRecent_ = true;
1353 session_->CreateDetectStateTask(false, WindowMode::WINDOW_MODE_SPLIT_SECONDARY);
1354 }
1355
1356 /**
1357 * @tc.name: CreateDetectStateTask003
1358 * @tc.desc: Detect sup and down tree tasks fo the same type.
1359 * @tc.type: FUNC
1360 */
1361 HWTEST_F(WindowSessionTest, CreateDetectStateTask003, TestSize.Level1)
1362 {
1363 session_->systemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
1364 std::string taskName = "wms:WindowStateDetect" + std::to_string(session_->persistentId_);
1365 DetectTaskInfo detectTaskInfo;
1366 detectTaskInfo.taskState = DetectTaskState::DETACH_TASK;
1367 detectTaskInfo.taskWindowMode = WindowMode::WINDOW_MODE_FULLSCREEN;
1368 int32_t beforeTaskNum = GetTaskCount();
1369 session_->SetDetectTaskInfo(detectTaskInfo);
1370 session_->CreateDetectStateTask(false, WindowMode::WINDOW_MODE_SPLIT_SECONDARY);
1371
1372 ASSERT_EQ(beforeTaskNum + 1, GetTaskCount());
1373 ASSERT_EQ(DetectTaskState::DETACH_TASK, session_->GetDetectTaskInfo().taskState);
1374 session_->handler_->RemoveTask(taskName);
1375
1376 session_->showRecent_ = true;
1377 session_->CreateDetectStateTask(false, WindowMode::WINDOW_MODE_SPLIT_SECONDARY);
1378 }
1379
1380 /**
1381 * @tc.name: CreateDetectStateTask004
1382 * @tc.desc: Detection tasks under the same window mode.
1383 * @tc.type: FUNC
1384 */
1385 HWTEST_F(WindowSessionTest, CreateDetectStateTask004, TestSize.Level1)
1386 {
1387 session_->systemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
1388 std::string taskName = "wms:WindowStateDetect" + std::to_string(session_->persistentId_);
1389 DetectTaskInfo detectTaskInfo;
1390 int32_t beforeTaskNum = GetTaskCount();
1391 detectTaskInfo.taskState = DetectTaskState::DETACH_TASK;
1392 detectTaskInfo.taskWindowMode = WindowMode::WINDOW_MODE_FULLSCREEN;
1393 session_->SetDetectTaskInfo(detectTaskInfo);
1394 session_->CreateDetectStateTask(true, WindowMode::WINDOW_MODE_FULLSCREEN);
1395
1396 ASSERT_EQ(beforeTaskNum + 1, GetTaskCount());
1397 ASSERT_EQ(DetectTaskState::ATTACH_TASK, session_->GetDetectTaskInfo().taskState);
1398 session_->handler_->RemoveTask(taskName);
1399
1400 session_->showRecent_ = true;
1401 session_->CreateDetectStateTask(false, WindowMode::WINDOW_MODE_FULLSCREEN);
1402 }
1403
1404 /**
1405 * @tc.name: GetUIContentRemoteObj
1406 * @tc.desc: GetUIContentRemoteObj Test
1407 * @tc.type: FUNC
1408 */
1409 HWTEST_F(WindowSessionTest, GetUIContentRemoteObj, TestSize.Level1)
1410 {
1411 ASSERT_NE(session_, nullptr);
1412 sptr<SessionStageMocker> mockSessionStage = sptr<SessionStageMocker>::MakeSptr();
1413 ASSERT_NE(mockSessionStage, nullptr);
1414 EXPECT_CALL(*(mockSessionStage), GetUIContentRemoteObj(_)).WillRepeatedly(Return(WSError::WS_OK));
1415 session_->sessionStage_ = mockSessionStage;
1416 session_->state_ = SessionState::STATE_FOREGROUND;
1417 sptr<IRemoteObject> remoteObj;
1418 ASSERT_EQ(WSError::WS_OK, session_->GetUIContentRemoteObj(remoteObj));
1419
1420 session_->state_ = SessionState::STATE_BACKGROUND;
1421 ASSERT_EQ(WSError::WS_OK, session_->GetUIContentRemoteObj(remoteObj));
1422 Mock::VerifyAndClearExpectations(&mockSessionStage);
1423
1424 session_->sessionInfo_.isSystem_ = true;
1425 ASSERT_EQ(WSError::WS_ERROR_INVALID_SESSION, session_->GetUIContentRemoteObj(remoteObj));
1426 }
1427
1428 /**
1429 * @tc.name: TransferKeyEventForConsumed02
1430 * @tc.desc: windowEventChannel_ is not nullptr, keyEvent is nullptr
1431 * @tc.type: FUNC
1432 */
1433 HWTEST_F(WindowSessionTest, TransferKeyEventForConsumed02, TestSize.Level1)
1434 {
1435 ASSERT_NE(session_, nullptr);
1436
1437 session_->windowEventChannel_ = sptr<TestWindowEventChannel>::MakeSptr();
1438
1439 std::shared_ptr<MMI::KeyEvent> keyEvent = nullptr;
1440 bool isConsumed = false;
1441 ASSERT_EQ(WSError::WS_ERROR_NULLPTR, session_->TransferKeyEventForConsumed(keyEvent, isConsumed));
1442 }
1443
1444 /**
1445 * @tc.name: TransferKeyEventForConsumed03
1446 * @tc.desc: windowEventChannel_ is not nullptr, keyEvent is not nullptr
1447 * @tc.type: FUNC
1448 */
1449 HWTEST_F(WindowSessionTest, TransferKeyEventForConsumed03, TestSize.Level1)
1450 {
1451 ASSERT_NE(session_, nullptr);
1452
1453 session_->windowEventChannel_ = sptr<TestWindowEventChannel>::MakeSptr();
1454
1455 std::shared_ptr<MMI::KeyEvent> keyEvent = MMI::KeyEvent::Create();
1456 bool isConsumed = false;
1457 ASSERT_EQ(WSError::WS_OK, session_->TransferKeyEventForConsumed(keyEvent, isConsumed));
1458 }
1459
1460 /**
1461 * @tc.name: UpdateMaximizeMode
1462 * @tc.desc: UpdateMaximizeMode test
1463 * @tc.type: FUNC
1464 */
1465 HWTEST_F(WindowSessionTest, UpdateMaximizeMode, TestSize.Level1)
1466 {
1467 sptr<SessionStageMocker> mockSessionStage = sptr<SessionStageMocker>::MakeSptr();
1468 EXPECT_NE(mockSessionStage, nullptr);
1469 session_->sessionStage_ = mockSessionStage;
1470
1471 session_->sessionInfo_.isSystem_ = false;
1472 session_->state_ = SessionState::STATE_ACTIVE;
1473 auto ret = session_->UpdateMaximizeMode(true);
1474 ASSERT_EQ(ret, WSError::WS_OK);
1475
1476 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1477 ASSERT_NE(property, nullptr);
1478 property->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
1479 session_->SetSessionProperty(property);
1480 ret = session_->UpdateMaximizeMode(false);
1481 ASSERT_EQ(ret, WSError::WS_OK);
1482 }
1483
1484 /**
1485 * @tc.name: UpdateTitleInTargetPos
1486 * @tc.desc: UpdateTitleInTargetPos test
1487 * @tc.type: FUNC
1488 */
1489 HWTEST_F(WindowSessionTest, UpdateTitleInTargetPos, TestSize.Level1)
1490 {
1491 sptr<SessionStageMocker> mockSessionStage = sptr<SessionStageMocker>::MakeSptr();
1492 EXPECT_NE(mockSessionStage, nullptr);
1493 session_->sessionStage_ = mockSessionStage;
1494
1495 session_->sessionInfo_.isSystem_ = false;
1496 session_->state_ = SessionState::STATE_FOREGROUND;
1497 auto ret = session_->UpdateTitleInTargetPos(true, 20);
1498 ASSERT_NE(ret, WSError::WS_ERROR_INVALID_SESSION);
1499 }
1500
1501 /**
1502 * @tc.name: SwitchFreeMultiWindow
1503 * @tc.desc: SwitchFreeMultiWindow test
1504 * @tc.type: FUNC
1505 */
1506 HWTEST_F(WindowSessionTest, SwitchFreeMultiWindow, TestSize.Level1)
1507 {
1508 sptr<SessionStageMocker> mockSessionStage = sptr<SessionStageMocker>::MakeSptr();
1509 EXPECT_NE(mockSessionStage, nullptr);
1510 session_->sessionStage_ = mockSessionStage;
1511
1512 session_->sessionInfo_.isSystem_ = false;
1513 session_->state_ = SessionState::STATE_FOREGROUND;
1514 SystemSessionConfig sessionConfig;
1515 sessionConfig.freeMultiWindowEnable_ = true;
1516 sessionConfig.defaultWindowMode_ = WindowMode::WINDOW_MODE_FLOATING;
1517 auto ret = session_->SwitchFreeMultiWindow(sessionConfig);
1518 ASSERT_NE(ret, WSError::WS_ERROR_INVALID_SESSION);
1519
1520 session_->sessionInfo_.isSystem_ = true;
1521 ret = session_->SwitchFreeMultiWindow(sessionConfig);
1522 ASSERT_EQ(ret, WSError::WS_ERROR_INVALID_SESSION);
1523 }
1524
1525 /**
1526 * @tc.name: ExtractSupportWindowModeFromMetaData
1527 * @tc.desc: ExtractSupportWindowModeFromMetaData
1528 * @tc.type: FUNC
1529 */
1530 HWTEST_F(WindowSessionTest, ExtractSupportWindowModeFromMetaData, TestSize.Level1)
1531 {
1532 sptr<SessionStageMocker> mockSessionStage = sptr<SessionStageMocker>::MakeSptr();
1533 EXPECT_NE(mockSessionStage, nullptr);
1534 session_->sessionStage_ = mockSessionStage;
1535
1536 session_->sessionInfo_.isSystem_ = false;
1537 session_->state_ = SessionState::STATE_FOREGROUND;
1538 SystemSessionConfig sessionConfig;
1539 sessionConfig.freeMultiWindowEnable_ = true;
1540 sessionConfig.defaultWindowMode_ = WindowMode::WINDOW_MODE_FLOATING;
1541
1542 session_->systemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
1543 AppExecFwk::AbilityInfo abilityInfo;
1544 std::vector<AppExecFwk::SupportWindowMode> res = {};
1545 std::vector<AppExecFwk::SupportWindowMode> updateWindowModes =
1546 session_->ExtractSupportWindowModeFromMetaData(
1547 std::make_shared<OHOS::AppExecFwk::AbilityInfo>(abilityInfo));
1548 ASSERT_EQ(updateWindowModes, res);
1549
1550 session_->systemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
1551 session_->systemConfig_.freeMultiWindowEnable_ = false;
1552 updateWindowModes =
1553 session_->ExtractSupportWindowModeFromMetaData(
1554 std::make_shared<OHOS::AppExecFwk::AbilityInfo>(abilityInfo));
1555 ASSERT_EQ(updateWindowModes, res);
1556 }
1557
1558 /**
1559 * @tc.name: ParseWindowModeFromMetaData
1560 * @tc.desc: ParseWindowModeFromMetaData
1561 * @tc.type: FUNC
1562 */
1563 HWTEST_F(WindowSessionTest, ParseWindowModeFromMetaData, TestSize.Level1)
1564 {
1565 sptr<SessionStageMocker> mockSessionStage = sptr<SessionStageMocker>::MakeSptr();
1566 EXPECT_NE(mockSessionStage, nullptr);
1567 session_->sessionStage_ = mockSessionStage;
1568
1569 session_->sessionInfo_.isSystem_ = false;
1570 session_->state_ = SessionState::STATE_FOREGROUND;
1571 SystemSessionConfig sessionConfig;
1572 sessionConfig.freeMultiWindowEnable_ = true;
1573 sessionConfig.defaultWindowMode_ = WindowMode::WINDOW_MODE_FLOATING;
1574
1575 std::vector<AppExecFwk::SupportWindowMode> updateWindowModes =
1576 {AppExecFwk::SupportWindowMode::FULLSCREEN};
1577 ASSERT_NE(updateWindowModes, session_->ParseWindowModeFromMetaData("split"));
1578 ASSERT_EQ(updateWindowModes, session_->ParseWindowModeFromMetaData("fullscreen, "));
1579 }
1580
1581 /**
1582 * @tc.name: InitSessionPropertyWhenConnect
1583 * @tc.desc: InitSessionPropertyWhenConnect test
1584 * @tc.type: FUNC
1585 */
1586 HWTEST_F(WindowSessionTest, InitSessionPropertyWhenConnect, TestSize.Level1)
1587 {
1588 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1589 ASSERT_NE(nullptr, property);
1590 property->isSystemCalling_ = false;
1591 session_->systemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
1592 session_->InitSessionPropertyWhenConnect(property);
1593 ASSERT_EQ(true, property->dragEnabled_);
1594
1595 session_->systemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
1596 session_->InitSessionPropertyWhenConnect(property);
1597 ASSERT_EQ(false, property->dragEnabled_);
1598 }
1599
1600 /**
1601 * @tc.name: SetTouchHotAreas
1602 * @tc.desc: SetTouchHotAreas test
1603 * @tc.type: FUNC
1604 */
1605 HWTEST_F(WindowSessionTest, SetTouchHotAreas, TestSize.Level1)
1606 {
1607 std::vector<Rect> touchHotAreas = session_->property_->touchHotAreas_;
1608 session_->property_->SetTouchHotAreas(touchHotAreas);
1609 ASSERT_EQ(touchHotAreas, session_->property_->touchHotAreas_);
1610 }
1611
1612 /**
1613 * @tc.name: NotifyOccupiedAreaChangeInfo
1614 * @tc.desc: NotifyOccupiedAreaChangeInfo test
1615 * @tc.type: FUNC
1616 */
1617 HWTEST_F(WindowSessionTest, NotifyOccupiedAreaChangeInfo, TestSize.Level1)
1618 {
1619 sptr<SessionStageMocker> mockSessionStage = sptr<SessionStageMocker>::MakeSptr();
1620 EXPECT_NE(mockSessionStage, nullptr);
1621 session_->sessionStage_ = mockSessionStage;
1622 session_->NotifyOccupiedAreaChangeInfo(nullptr, nullptr);
1623 EXPECT_NE(session_->sessionStage_, nullptr);
1624 }
1625
1626 /**
1627 * @tc.name: ProcessBackEvent
1628 * @tc.desc: ProcessBackEvent test
1629 * @tc.type: FUNC
1630 */
1631 HWTEST_F(WindowSessionTest, ProcessBackEvent, TestSize.Level1)
1632 {
1633 sptr<SessionStageMocker> mockSessionStage = sptr<SessionStageMocker>::MakeSptr();
1634 EXPECT_NE(mockSessionStage, nullptr);
1635 session_->sessionStage_ = mockSessionStage;
1636
1637 session_->sessionInfo_.isSystem_ = false;
1638 session_->state_ = SessionState::STATE_FOREGROUND;
1639 auto ret = session_->ProcessBackEvent();
1640 ASSERT_NE(ret, WSError::WS_ERROR_INVALID_SESSION);
1641 }
1642
1643 /**
1644 * @tc.name: ProcessBackGetAndSetSessionRequestRectEvent
1645 * @tc.desc: GetSessionRequestRectEvent, SetSessionRequestRectEvent test
1646 * @tc.type: FUNC
1647 */
1648 HWTEST_F(WindowSessionTest, GetAndSetSessionRequestRect, TestSize.Level1)
1649 {
1650 WSRect rect = { 0, 0, 0, 0 };
1651 session_->SetSessionRequestRect(rect);
1652 ASSERT_EQ(session_->GetSessionRequestRect(), rect);
1653 }
1654
1655 /**
1656 * @tc.name: SetSessionRect01
1657 * @tc.desc: SetSessionRect test
1658 * @tc.type: FUNC
1659 */
1660 HWTEST_F(WindowSessionTest, SetSessionRect01, TestSize.Level1)
1661 {
1662 WSRect rect = session_->GetSessionRect();
1663 session_->SetSessionRect(rect);
1664 ASSERT_EQ(rect, session_->GetSessionRect());
1665 }
1666
1667 /**
1668 * @tc.name: UpdateClientRectPosYAndDisplayId02
1669 * @tc.desc: UpdateClientRectPosYAndDisplayId
1670 * @tc.type: FUNC
1671 */
1672 HWTEST_F(WindowSessionTest, UpdateClientRectPosYAndDisplayId02, TestSize.Level1)
1673 {
1674 ASSERT_NE(session_, nullptr);
1675 session_->sessionInfo_.screenId_ = 0;
1676 EXPECT_EQ(session_->GetScreenId(), 0);
1677 session_->GetSessionProperty()->SetIsSystemKeyboard(false);
1678 PcFoldScreenManager::GetInstance().UpdateFoldScreenStatus(
1679 0, SuperFoldStatus::UNKNOWN, { 0, 0, 2472, 1648 }, { 0, 1648, 2472, 1648 }, { 0, 1624, 2472, 1648 });
1680 WSRect rect = { 0, 0, 0, 0 };
1681 session_->UpdateClientRectPosYAndDisplayId(rect);
1682 EXPECT_EQ(rect.posY_, 0);
1683 PcFoldScreenManager::GetInstance().UpdateFoldScreenStatus(
1684 0, SuperFoldStatus::FOLDED, { 0, 0, 2472, 1648 }, { 0, 1648, 2472, 1648 }, { 0, 1624, 2472, 1648 });
1685 rect = { 0, 100, 0, 0 };
1686 session_->UpdateClientRectPosYAndDisplayId(rect);
1687 EXPECT_EQ(rect.posY_, 100);
1688 }
1689
1690 /**
1691 * @tc.name: UpdateClientRectPosYAndDisplayId03
1692 * @tc.desc: UpdateClientRectPosYAndDisplayId
1693 * @tc.type: FUNC
1694 */
1695 HWTEST_F(WindowSessionTest, UpdateClientRectPosYAndDisplayId03, TestSize.Level1)
1696 {
1697 ASSERT_NE(session_, nullptr);
1698 session_->sessionInfo_.screenId_ = 0;
1699 EXPECT_EQ(session_->GetScreenId(), 0);
1700 session_->GetSessionProperty()->SetIsSystemKeyboard(true);
1701 PcFoldScreenManager::GetInstance().UpdateFoldScreenStatus(
1702 0, SuperFoldStatus::HALF_FOLDED, { 0, 0, 2472, 1648 }, { 0, 1648, 2472, 1648 }, { 0, 1649, 2472, 40 });
1703 WSRect rect = { 0, 1000, 100, 100 };
1704 session_->UpdateClientRectPosYAndDisplayId(rect);
1705 EXPECT_EQ(rect.posY_, 1000);
1706 }
1707
1708 /**
1709 * @tc.name: SetExclusivelyHighlighted
1710 * @tc.desc: SetExclusivelyHighlighted Test
1711 * @tc.type: FUNC
1712 */
1713 HWTEST_F(WindowSessionTest, SetExclusivelyHighlighted, TestSize.Level1)
1714 {
1715 ASSERT_NE(session_, nullptr);
1716 session_->SetExclusivelyHighlighted(false);
1717 bool isExclusivelyHighlighted = session_->GetSessionProperty()->GetExclusivelyHighlighted();
1718 ASSERT_EQ(isExclusivelyHighlighted, false);
1719 session_->SetExclusivelyHighlighted(true);
1720 isExclusivelyHighlighted = session_->GetSessionProperty()->GetExclusivelyHighlighted();
1721 ASSERT_EQ(isExclusivelyHighlighted, true);
1722 }
1723
1724 /**
1725 * @tc.name: UpdateHighlightStatus
1726 * @tc.desc: UpdateHighlightStatus Test
1727 * @tc.type: FUNC
1728 */
1729 HWTEST_F(WindowSessionTest, UpdateHighlightStatus, TestSize.Level1)
1730 {
1731 ASSERT_NE(session_, nullptr);
1732 EXPECT_EQ(session_->UpdateHighlightStatus(false, false), WSError::WS_DO_NOTHING);
1733
1734 EXPECT_EQ(session_->UpdateHighlightStatus(true, false), WSError::WS_OK);
1735 session_->isHighlighted_ = false;
1736 EXPECT_EQ(session_->UpdateHighlightStatus(true, true), WSError::WS_OK);
1737 }
1738
1739 /**
1740 * @tc.name: NotifyHighlightChange
1741 * @tc.desc: NotifyHighlightChange Test
1742 * @tc.type: FUNC
1743 */
1744 HWTEST_F(WindowSessionTest, NotifyHighlightChange, TestSize.Level1)
1745 {
1746 ASSERT_NE(session_, nullptr);
1747 session_->sessionInfo_.isSystem_ = true;
1748 EXPECT_EQ(session_->NotifyHighlightChange(true), WSError::WS_ERROR_INVALID_SESSION);
1749 session_->sessionInfo_.isSystem_ = false;
1750 EXPECT_EQ(session_->NotifyHighlightChange(true), WSError::WS_ERROR_NULLPTR);
1751 session_->sessionStage_ = mockSessionStage_;
1752 session_->state_ = SessionState::STATE_CONNECT;
1753 EXPECT_EQ(session_->NotifyHighlightChange(true), WSError::WS_OK);
1754 session_->sessionStage_ = nullptr;
1755 EXPECT_EQ(session_->NotifyHighlightChange(true), WSError::WS_ERROR_NULLPTR);
1756 }
1757
1758 /**
1759 * @tc.name: TransformRelativeRectToGlobalRect
1760 * @tc.desc: TransformRelativeRectToGlobalRect Test
1761 * @tc.type: FUNC
1762 */
1763 HWTEST_F(WindowSessionTest, TransformRelativeRectToGlobalRect, TestSize.Level1)
1764 {
1765 SessionInfo sessionInfo;
1766 sessionInfo.isSystem_ = false;
1767 sessionInfo.bundleName_ = "bundleName";
1768 sessionInfo.abilityName_ = "abilityName";
1769 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1770 PcFoldScreenManager::GetInstance().UpdateFoldScreenStatus(
1771 0, SuperFoldStatus::HALF_FOLDED, { 0, 0, 2472, 1648 }, { 0, 1648, 2472, 1648 }, { 0, 1624, 2472, 1648 });
1772 WSRect rect{ 0, 100, 100, 100 };
1773 sceneSession->SetSessionGlobalRect({ 0, 0, 2472, 1648 });
1774 sceneSession->GetLayoutController()->SetSessionRect({ 0, 0, 2472, 1648 });
1775 sceneSession->TransformRelativeRectToGlobalRect(rect);
1776 EXPECT_EQ(rect.posY_, 100);
1777 sceneSession->SetSessionGlobalRect({ 0, 9999, 2472, 1648 });
1778 sceneSession->GetLayoutController()->SetSessionRect({ 0, 9999, 2472, 1648 });
1779 sceneSession->TransformRelativeRectToGlobalRect(rect);
1780 EXPECT_NE(rect.posY_, 100);
1781 }
1782 } // namespace
1783 } // namespace Rosen
1784 } // namespace OHOS
1785