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