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_ = new (std::nothrow) Session(info);
94 session_->surfaceNode_ = CreateRSSurfaceNode();
95 EXPECT_NE(nullptr, session_);
96 ssm_ = new SceneSessionManager();
97 session_->SetEventHandler(ssm_->taskScheduler_->GetEventHandler(), ssm_->eventHandler_);
98 auto isScreenLockedCallback = [this]() {
99 return ssm_->IsScreenLocked();
100 };
101 session_->RegisterIsScreenLockedCallback(isScreenLockedCallback);
102
103 mockSessionStage_ = new (std::nothrow) SessionStageMocker();
104 ASSERT_NE(mockSessionStage_, nullptr);
105
106 mockEventChannel_ = new (std::nothrow) WindowEventChannelMocker(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 = new(std::nothrow) SessionStageMocker();
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 = new(std::nothrow) WindowEventChannelMocker(mockSessionStage);
171 EXPECT_NE(nullptr, mockEventChannel);
172 auto surfaceNode = CreateRSSurfaceNode();
173 SystemSessionConfig sessionConfig;
174 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
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 = new (std::nothrow) WindowSessionProperty();
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: UpdateRect01
202 * @tc.desc: update rect
203 * @tc.type: FUNC
204 * @tc.require: #I6JLSI
205 */
206 HWTEST_F(WindowSessionTest, UpdateRect01, Function | SmallTest | Level2)
207 {
208 sptr<ISession> sessionToken = nullptr;
209 sptr<SessionStageMocker> mockSessionStage = new(std::nothrow) SessionStageMocker();
210 EXPECT_NE(nullptr, mockSessionStage);
211 session_->sessionStage_ = mockSessionStage;
212 EXPECT_CALL(*(mockSessionStage), UpdateRect(_, _, _)).Times(AtLeast(1)).WillOnce(Return(WSError::WS_OK));
213
214 WSRect rect = {0, 0, 0, 0};
215 ASSERT_EQ(WSError::WS_ERROR_INVALID_SESSION, session_->UpdateRect(rect,
216 SizeChangeReason::UNDEFINED, "WindowSessionTest"));
217 sptr<WindowEventChannelMocker> mockEventChannel = new(std::nothrow) WindowEventChannelMocker(mockSessionStage);
218 EXPECT_NE(nullptr, mockEventChannel);
219 SystemSessionConfig sessionConfig;
220 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
221 ASSERT_NE(nullptr, property);
222 ASSERT_EQ(WSError::WS_OK, session_->Connect(mockSessionStage,
223 mockEventChannel, nullptr, sessionConfig, property));
224
225 rect = {0, 0, 100, 100};
226 ASSERT_EQ(WSError::WS_ERROR_INVALID_SESSION, session_->UpdateRect(rect,
227 SizeChangeReason::UNDEFINED, "WindowSessionTest"));
228 ASSERT_EQ(rect, session_->winRect_);
229
230 session_->UpdateSessionState(SessionState::STATE_ACTIVE);
231 ASSERT_EQ(WSError::WS_OK, session_->UpdateRect(rect, SizeChangeReason::UNDEFINED, "WindowSessionTest"));
232
233 session_->sessionStage_ = nullptr;
234 ASSERT_EQ(WSError::WS_OK, session_->UpdateRect(rect, SizeChangeReason::UNDEFINED, "WindowSessionTest"));
235 }
236
237 /**
238 * @tc.name: IsSessionValid01
239 * @tc.desc: check func IsSessionValid
240 * @tc.type: FUNC
241 */
242 HWTEST_F(WindowSessionTest, IsSessionValid01, Function | SmallTest | Level2)
243 {
244 session_->state_ = SessionState::STATE_DISCONNECT;
245 ASSERT_FALSE(session_->IsSessionValid());
246 session_->state_ = SessionState::STATE_CONNECT;
247 ASSERT_TRUE(session_->IsSessionValid());
248 }
249
250 /**
251 * @tc.name: ConnectInner
252 * @tc.desc: ConnectInner
253 * @tc.type: FUNC
254 */
255 HWTEST_F(WindowSessionTest, ConnectInner, Function | SmallTest | Level2)
256 {
257 SystemSessionConfig sessionConfig;
258 session_->state_ = SessionState::STATE_CONNECT;
259 session_->isTerminating_ = false;
260 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
261
262 property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
263 property->SetIsNeedUpdateWindowMode(true);
264 session_->SetScreenId(233);
265 session_->SetSessionProperty(property);
266 auto res = session_->ConnectInner(mockSessionStage_, mockEventChannel_,
267 nullptr, sessionConfig, property, nullptr, 1, 1, "");
268 ASSERT_EQ(res, WSError::WS_ERROR_INVALID_SESSION);
269
270 session_->isTerminating_ = true;
271 auto res2 = session_->ConnectInner(mockSessionStage_, mockEventChannel_,
272 nullptr, sessionConfig, property, nullptr, 1, 1, "");
273 ASSERT_EQ(res2, WSError::WS_OK);
274
275 property->SetWindowType(WindowType::APP_MAIN_WINDOW_END);
276 property->SetIsNeedUpdateWindowMode(true);
277 session_->SetScreenId(SCREEN_ID_INVALID);
278 session_->SetSessionProperty(property);
279 auto res3 = session_->ConnectInner(mockSessionStage_, mockEventChannel_,
280 nullptr, sessionConfig, property, nullptr, 1, 1, "");
281 ASSERT_EQ(res3, WSError::WS_OK);
282 }
283
284 /**
285 * @tc.name: RemoveLifeCycleTask
286 * @tc.desc: RemoveLifeCycleTask & PostLifeCycleTask
287 * @tc.type: FUNC
288 */
289 HWTEST_F(WindowSessionTest, LifeCycleTask, Function | SmallTest | Level2)
290 {
__anon7ac06df50402() 291 auto task = []() {};
292 session_->PostLifeCycleTask(task, "task1", LifeCycleTaskType::START);
293 ASSERT_EQ(session_->lifeCycleTaskQueue_.size(), 1);
294
__anon7ac06df50502() 295 auto task2 = []() {};
296 session_->PostLifeCycleTask(task2, "task2", LifeCycleTaskType::START);
297 ASSERT_EQ(session_->lifeCycleTaskQueue_.size(), 2);
298
299 LifeCycleTaskType taskType = LifeCycleTaskType{0};
300
301 session_->RemoveLifeCycleTask(taskType);
302 ASSERT_EQ(session_->lifeCycleTaskQueue_.size(), 1);
303
304 session_->RemoveLifeCycleTask(taskType);
305 ASSERT_EQ(session_->lifeCycleTaskQueue_.size(), 0);
306 }
307
308 /**
309 * @tc.name: SetSessionProperty01
310 * @tc.desc: SetSessionProperty
311 * @tc.type: FUNC
312 */
313 HWTEST_F(WindowSessionTest, SetSessionProperty01, Function | SmallTest | Level2)
314 {
315 ASSERT_EQ(session_->SetSessionProperty(nullptr), WSError::WS_OK);
316 }
317
318 /**
319 * @tc.name: SetSessionRect
320 * @tc.desc: check func SetSessionRect
321 * @tc.type: FUNC
322 */
323 HWTEST_F(WindowSessionTest, SetSessionRect, Function | SmallTest | Level2)
324 {
325 ASSERT_NE(session_, nullptr);
326 WSRect rect = { 0, 0, 320, 240}; // width: 320, height: 240
327 session_->SetSessionRect(rect);
328 ASSERT_EQ(rect, session_->winRect_);
329 }
330
331 /**
332 * @tc.name: GetSessionRect
333 * @tc.desc: check func GetSessionRect
334 * @tc.type: FUNC
335 */
336 HWTEST_F(WindowSessionTest, GetSessionRect, Function | SmallTest | Level2)
337 {
338 ASSERT_NE(session_, nullptr);
339 WSRect rect = { 0, 0, 320, 240}; // width: 320, height: 240
340 session_->SetSessionRect(rect);
341 ASSERT_EQ(rect, session_->GetSessionRect());
342 }
343
344 /**
345 * @tc.name: GetLayoutRect
346 * @tc.desc: check func GetLayoutRect
347 * @tc.type: FUNC
348 */
349 HWTEST_F(WindowSessionTest, GetLayoutRect, Function | SmallTest | Level2)
350 {
351 ASSERT_NE(session_, nullptr);
352 WSRect rect = { 0, 0, 320, 240 }; // width: 320, height: 240
353 session_->layoutRect_ = rect;
354 session_->lastLayoutRect_ = session_->layoutRect_;
355 ASSERT_EQ(rect, session_->GetLayoutRect());
356 ASSERT_EQ(rect, session_->GetLastLayoutRect());
357 }
358
359 /**
360 * @tc.name: CheckDialogOnForeground
361 * @tc.desc: check func CheckDialogOnForeground
362 * @tc.type: FUNC
363 */
364 HWTEST_F(WindowSessionTest, CheckDialogOnForeground, Function | SmallTest | Level2)
365 {
366 ASSERT_NE(session_, nullptr);
367 session_->dialogVec_.clear();
368 ASSERT_EQ(false, session_->CheckDialogOnForeground());
369 SessionInfo info;
370 info.abilityName_ = "dialogAbilityName";
371 info.moduleName_ = "dialogModuleName";
372 info.bundleName_ = "dialogBundleName";
373 sptr<Session> dialogSession = new (std::nothrow) Session(info);
374 ASSERT_NE(dialogSession, nullptr);
375 dialogSession->state_ = SessionState::STATE_INACTIVE;
376 session_->dialogVec_.push_back(dialogSession);
377 ASSERT_EQ(false, session_->CheckDialogOnForeground());
378 session_->dialogVec_.clear();
379 }
380
381 /**
382 * @tc.name: IsTopDialog
383 * @tc.desc: check func IsTopDialog
384 * @tc.type: FUNC
385 */
386 HWTEST_F(WindowSessionTest, IsTopDialog, Function | SmallTest | Level2)
387 {
388 ASSERT_NE(session_, nullptr);
389 session_->dialogVec_.clear();
390 SessionInfo info;
391 info.abilityName_ = "testSession1";
392 info.moduleName_ = "testSession2";
393 info.bundleName_ = "testSession3";
394
395 sptr<Session> dialogSession1 = new (std::nothrow) Session(info);
396 ASSERT_NE(dialogSession1, nullptr);
397 dialogSession1->persistentId_ = 33;
398 dialogSession1->SetParentSession(session_);
399 dialogSession1->state_ = SessionState::STATE_ACTIVE;
400 session_->dialogVec_.push_back(dialogSession1);
401
402 sptr<Session> dialogSession2 = new (std::nothrow) Session(info);
403 ASSERT_NE(dialogSession2, nullptr);
404 dialogSession2->persistentId_ = 34;
405 dialogSession2->SetParentSession(session_);
406 dialogSession2->state_ = SessionState::STATE_ACTIVE;
407 session_->dialogVec_.push_back(dialogSession2);
408
409 sptr<Session> dialogSession3 = new (std::nothrow) Session(info);
410 ASSERT_NE(dialogSession3, nullptr);
411 dialogSession3->persistentId_ = 35;
412 dialogSession3->SetParentSession(session_);
413 dialogSession3->state_ = SessionState::STATE_INACTIVE;
414 session_->dialogVec_.push_back(dialogSession3);
415
416 ASSERT_EQ(false, dialogSession3->IsTopDialog());
417 ASSERT_EQ(true, dialogSession2->IsTopDialog());
418 ASSERT_EQ(false, dialogSession1->IsTopDialog());
419 session_->dialogVec_.clear();
420 }
421
422 /**
423 * @tc.name: GetGlobalScaledRect
424 * @tc.desc: GetGlobalScaledRect
425 * @tc.type: FUNC
426 */
427 HWTEST_F(WindowSessionTest, GetGlobalScaledRect, Function | SmallTest | Level2)
428 {
429 SessionInfo info;
430 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
431 Rect globalScaledRect;
432 sceneSession->globalRect_ = {100, 100, 50, 40};
433 sceneSession->isScbCoreEnabled_ = true;
434 sceneSession->scaleX_ = 0.5f;
435 sceneSession->scaleY_ = 0.5f;
436 WMError ret = sceneSession->GetGlobalScaledRect(globalScaledRect);
437 ASSERT_EQ(WMError::WM_OK, ret);
438 ASSERT_EQ(100, globalScaledRect.posX_);
439 ASSERT_EQ(100, globalScaledRect.posY_);
440 ASSERT_EQ(25, globalScaledRect.width_);
441 ASSERT_EQ(20, globalScaledRect.height_);
442 }
443
444 /**
445 * @tc.name: RaiseToAppTop01
446 * @tc.desc: RaiseToAppTop
447 * @tc.type: FUNC
448 */
449 HWTEST_F(WindowSessionTest, RaiseToAppTop01, Function | SmallTest | Level2)
450 {
451 SessionInfo info;
452 info.abilityName_ = "testSession1";
453 info.bundleName_ = "testSession3";
454 sptr<SceneSession> scensession = new (std::nothrow) SceneSession(info, nullptr);
455 EXPECT_NE(scensession, nullptr);
456 auto result = scensession->RaiseToAppTop();
457 ASSERT_EQ(result, WSError::WS_OK);
458
459 sptr<SceneSession::SessionChangeCallback> scensessionchangeCallBack =
460 new (std::nothrow) SceneSession::SessionChangeCallback();
461 EXPECT_NE(scensessionchangeCallBack, nullptr);
462 scensession->RegisterSessionChangeCallback(scensessionchangeCallBack);
463 result = scensession->RaiseToAppTop();
464 ASSERT_EQ(result, WSError::WS_OK);
465
__anon7ac06df50602() 466 NotifyRaiseToTopFunc onRaiseToTop_ = []() {};
467 scensessionchangeCallBack->onRaiseToTop_ = onRaiseToTop_;
468 result = scensession->RaiseToAppTop();
469 ASSERT_EQ(result, WSError::WS_OK);
470 }
471
472 /**
473 * @tc.name: UpdateSessionRect01
474 * @tc.desc: UpdateSessionRect
475 * @tc.type: FUNC
476 */
477 HWTEST_F(WindowSessionTest, UpdateSessionRect01, Function | SmallTest | Level2)
478 {
479 SessionInfo info;
480 info.abilityName_ = "testSession1";
481 info.bundleName_ = "testSession3";
482 sptr<SceneSession> scensession = new (std::nothrow) SceneSession(info, nullptr);
483 EXPECT_NE(scensession, nullptr);
484 WSRect rect = {0, 0, 320, 240}; // width: 320, height: 240
485 auto result = scensession->UpdateSessionRect(rect, SizeChangeReason::RESIZE);
486 ASSERT_EQ(result, WSError::WS_OK);
487
488 sptr<SceneSession::SessionChangeCallback> scensessionchangeCallBack =
489 new (std::nothrow) SceneSession::SessionChangeCallback();
490 EXPECT_NE(scensessionchangeCallBack, nullptr);
491 scensession->RegisterSessionChangeCallback(scensessionchangeCallBack);
492 result = scensession->UpdateSessionRect(rect, SizeChangeReason::RESIZE);
493 ASSERT_EQ(result, WSError::WS_OK);
494 }
495
496 /**
497 * @tc.name: OnSessionEvent01
498 * @tc.desc: OnSessionEvent
499 * @tc.type: FUNC
500 */
501 HWTEST_F(WindowSessionTest, OnSessionEvent01, Function | SmallTest | Level2)
502 {
503 SessionInfo info;
504 info.abilityName_ = "testSession1";
505 info.bundleName_ = "testSession3";
506 sptr<SceneSession> scensession = new (std::nothrow) SceneSession(info, nullptr);
507 EXPECT_NE(scensession, nullptr);
508 auto result = scensession->OnSessionEvent(SessionEvent::EVENT_MINIMIZE);
509 ASSERT_EQ(result, WSError::WS_OK);
510
511 sptr<SceneSession::SessionChangeCallback> scensessionchangeCallBack =
512 new (std::nothrow) SceneSession::SessionChangeCallback();
513 EXPECT_NE(scensessionchangeCallBack, nullptr);
514 scensession->RegisterSessionChangeCallback(scensessionchangeCallBack);
515 result = scensession->OnSessionEvent(SessionEvent::EVENT_MINIMIZE);
516 ASSERT_EQ(result, WSError::WS_OK);
517
518 int resultValue = 0;
519 NotifySessionEventFunc onSessionEvent_ = [&resultValue](int32_t eventId, SessionEventParam param)
__anon7ac06df50702(int32_t eventId, SessionEventParam param) 520 { resultValue = 1; };
521 scensessionchangeCallBack->OnSessionEvent_ = onSessionEvent_;
522 result = scensession->OnSessionEvent(SessionEvent::EVENT_MINIMIZE);
523 ASSERT_EQ(result, WSError::WS_OK);
524 }
525
526 /**
527 * @tc.name: ConsumeMoveEvent01
528 * @tc.desc: ConsumeMoveEvent, abnormal scene
529 * @tc.type: FUNC
530 */
531 HWTEST_F(WindowSessionTest, ConsumeMoveEvent01, Function | SmallTest | Level2)
532 {
533 SessionInfo info;
534 info.abilityName_ = "testSession1";
535 info.bundleName_ = "testSession3";
536 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
537 sceneSession->moveDragController_ = new MoveDragController(1);
538 EXPECT_NE(sceneSession, nullptr);
539 ASSERT_TRUE(sceneSession->moveDragController_);
540 sceneSession->moveDragController_->InitMoveDragProperty();
541 WSRect originalRect = { 100, 100, 1000, 1000 };
542
543 std::shared_ptr<MMI::PointerEvent> pointerEvent = nullptr;
544 auto result = sceneSession->moveDragController_->ConsumeMoveEvent(pointerEvent, originalRect);
545 ASSERT_FALSE(result);
546
547 pointerEvent = MMI::PointerEvent::Create();
548 ASSERT_TRUE(pointerEvent);
549 pointerEvent->SetPointerId(1);
550 sceneSession->moveDragController_->moveDragProperty_.pointerId_ = 0;
551 result = sceneSession->moveDragController_->ConsumeMoveEvent(pointerEvent, originalRect);
552 ASSERT_FALSE(result);
553
554 pointerEvent->SetPointerId(0);
555 pointerEvent->SetSourceType(MMI::PointerEvent::SOURCE_TYPE_MOUSE);
556 pointerEvent->SetButtonId(MMI::PointerEvent::MOUSE_BUTTON_RIGHT);
557 result = sceneSession->moveDragController_->ConsumeMoveEvent(pointerEvent, originalRect);
558 ASSERT_FALSE(result);
559 }
560
561 /**
562 * @tc.name: ConsumeMoveEvent02
563 * @tc.desc: ConsumeMoveEvent, normal secne
564 * @tc.type: FUNC
565 */
566 HWTEST_F(WindowSessionTest, ConsumeMoveEvent02, Function | SmallTest | Level2)
567 {
568 SessionInfo info;
569 info.abilityName_ = "testSession1";
570 info.bundleName_ = "testSession3";
571 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
572 EXPECT_NE(sceneSession, nullptr);
573 sceneSession->moveDragController_ = new MoveDragController(1);
574 ASSERT_TRUE(sceneSession->moveDragController_);
575 sceneSession->moveDragController_->InitMoveDragProperty();
576 WSRect originalRect = { 100, 100, 1000, 1000 };
577 sceneSession->moveDragController_->isStartMove_ = true;
578 std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
579 ASSERT_TRUE(pointerEvent);
580 pointerEvent->SetAgentWindowId(1);
581 pointerEvent->SetPointerId(0);
582 pointerEvent->SetSourceType(MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
583 MMI::PointerEvent::PointerItem pointerItem;
584 pointerItem.SetPointerId(0);
585 pointerEvent->AddPointerItem(pointerItem);
586
587 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_MOVE);
588 pointerItem.SetDisplayX(115);
589 pointerItem.SetDisplayY(500);
590 pointerItem.SetWindowX(15);
591 pointerItem.SetWindowY(400);
592 auto result = sceneSession->moveDragController_->ConsumeMoveEvent(pointerEvent, originalRect);
593 ASSERT_EQ(result, true);
594
595 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_MOVE);
596 pointerItem.SetDisplayX(145);
597 pointerItem.SetDisplayY(550);
598 result = sceneSession->moveDragController_->ConsumeMoveEvent(pointerEvent, originalRect);
599 ASSERT_EQ(result, true);
600
601 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_MOVE);
602 pointerItem.SetDisplayX(175);
603 pointerItem.SetDisplayY(600);
604 result = sceneSession->moveDragController_->ConsumeMoveEvent(pointerEvent, originalRect);
605 ASSERT_EQ(result, true);
606
607 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_UP);
608 pointerItem.SetDisplayX(205);
609 pointerItem.SetDisplayY(650);
610 result = sceneSession->moveDragController_->ConsumeMoveEvent(pointerEvent, originalRect);
611 ASSERT_EQ(result, false);
612 }
613
614 /**
615 * @tc.name: ConsumeDragEvent01
616 * @tc.desc: ConsumeDragEvent, abnormal scene
617 * @tc.type: FUNC
618 */
619 HWTEST_F(WindowSessionTest, ConsumeDragEvent01, Function | SmallTest | Level2)
620 {
621 SessionInfo info;
622 info.abilityName_ = "testSession1";
623 info.bundleName_ = "testSession3";
624 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
625 EXPECT_NE(sceneSession, nullptr);
626 sceneSession->moveDragController_ = new MoveDragController(1);
627 ASSERT_TRUE(sceneSession->moveDragController_);
628 sceneSession->moveDragController_->InitMoveDragProperty();
629 WSRect originalRect = { 100, 100, 1000, 1000 };
630 SystemSessionConfig sessionConfig;
631
632 std::shared_ptr<MMI::PointerEvent> pointerEvent = nullptr;
633 sptr<WindowSessionProperty> property = nullptr;
634 auto result = sceneSession->moveDragController_->ConsumeDragEvent(pointerEvent, originalRect, property,
635 sessionConfig);
636 ASSERT_EQ(result, false);
637
638 pointerEvent = MMI::PointerEvent::Create();
639 ASSERT_TRUE(pointerEvent);
640 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_UP);
641 property = new WindowSessionProperty();
642 sceneSession->moveDragController_->isStartDrag_ = false;
643 result = sceneSession->moveDragController_->ConsumeDragEvent(pointerEvent, originalRect, property, sessionConfig);
644 ASSERT_EQ(result, false);
645
646 pointerEvent->SetPointerId(1);
647 sceneSession->moveDragController_->moveDragProperty_.pointerId_ = 0;
648 sceneSession->moveDragController_->isStartDrag_ = true;
649 result = sceneSession->moveDragController_->ConsumeDragEvent(pointerEvent, originalRect, property, sessionConfig);
650 ASSERT_EQ(result, false);
651
652 pointerEvent->SetPointerId(0);
653 result = sceneSession->moveDragController_->ConsumeDragEvent(pointerEvent, originalRect, property, sessionConfig);
654 ASSERT_EQ(result, false);
655 }
656
657 /**
658 * @tc.name: ConsumeDragEvent02
659 * @tc.desc: ConsumeDragEvent, normal scene
660 * @tc.type: FUNC
661 */
662 HWTEST_F(WindowSessionTest, ConsumeDragEvent02, Function | SmallTest | Level2)
663 {
664 SessionInfo info;
665 info.abilityName_ = "testSession1";
666 info.bundleName_ = "testSession3";
667 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
668 sceneSession->moveDragController_ = new MoveDragController(1);
669 ASSERT_TRUE(sceneSession->moveDragController_);
670 sceneSession->moveDragController_->InitMoveDragProperty();
671 WSRect originalRect = { 100, 100, 1000, 1000 };
672 sptr<WindowSessionProperty> property = new WindowSessionProperty();
673 property->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
674 property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
675 SystemSessionConfig sessionConfig;
676 sessionConfig.isSystemDecorEnable_ = true;
677 sessionConfig.backgroundswitch = true;
678 sessionConfig.decorWindowModeSupportType_ = WindowModeSupport::WINDOW_MODE_SUPPORT_ALL;
679 std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
680 ASSERT_TRUE(pointerEvent);
681 pointerEvent->SetAgentWindowId(1);
682 pointerEvent->SetPointerId(0);
683 pointerEvent->SetSourceType(MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
684 MMI::PointerEvent::PointerItem pointerItem;
685 pointerItem.SetPointerId(0);
686 pointerEvent->AddPointerItem(pointerItem);
687
688 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_DOWN);
689 pointerItem.SetDisplayX(100);
690 pointerItem.SetDisplayY(100);
691 pointerItem.SetWindowX(0);
692 pointerItem.SetWindowY(0);
693 auto result = sceneSession->moveDragController_->ConsumeDragEvent(pointerEvent, originalRect, property,
694 sessionConfig);
695 ASSERT_EQ(result, true);
696
697 sceneSession->moveDragController_->aspectRatio_ = 0.0f;
698 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_MOVE);
699 pointerItem.SetDisplayX(150);
700 pointerItem.SetDisplayY(150);
701 result = sceneSession->moveDragController_->ConsumeDragEvent(pointerEvent, originalRect, property, sessionConfig);
702 ASSERT_EQ(result, true);
703
704 sceneSession->moveDragController_->aspectRatio_ = 1.0f;
705 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_MOVE);
706 pointerItem.SetDisplayX(200);
707 pointerItem.SetDisplayY(200);
708 result = sceneSession->moveDragController_->ConsumeDragEvent(pointerEvent, originalRect, property, sessionConfig);
709 ASSERT_EQ(result, true);
710
711 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_UP);
712 pointerItem.SetDisplayX(250);
713 pointerItem.SetDisplayY(250);
714 result = sceneSession->moveDragController_->ConsumeDragEvent(pointerEvent, originalRect, property, sessionConfig);
715 ASSERT_EQ(result, true);
716 }
717
718 /**
719 * @tc.name: ConsumeDragEvent03
720 * @tc.desc: ConsumeDragEvent, normal scene
721 * @tc.type: FUNC
722 */
723 HWTEST_F(WindowSessionTest, ConsumeDragEvent03, Function | SmallTest | Level2)
724 {
725 SessionInfo info;
726 info.abilityName_ = "testSession1";
727 info.bundleName_ = "testSession3";
728 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
729 EXPECT_NE(sceneSession, nullptr);
730 sceneSession->moveDragController_ = new MoveDragController(1);
731 ASSERT_TRUE(sceneSession->moveDragController_);
732 sceneSession->moveDragController_->InitMoveDragProperty();
733 WSRect originalRect = { 100, 100, 1000, 1000 };
734 sptr<WindowSessionProperty> property = new WindowSessionProperty();
735 property->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
736 property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
737 SystemSessionConfig sessionConfig;
738 sessionConfig.isSystemDecorEnable_ = true;
739 sessionConfig.backgroundswitch = true;
740 sessionConfig.decorWindowModeSupportType_ = WindowModeSupport::WINDOW_MODE_SUPPORT_ALL;
741 std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
742 ASSERT_TRUE(pointerEvent);
743 pointerEvent->SetAgentWindowId(1);
744 pointerEvent->SetPointerId(0);
745 pointerEvent->SetSourceType(MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
746 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_DOWN);
747 MMI::PointerEvent::PointerItem pointerItem;
748 pointerItem.SetPointerId(0);
749 pointerEvent->AddPointerItem(pointerItem);
750
751 // LEFT_TOP
752 pointerItem.SetWindowX(0);
753 pointerItem.SetWindowY(0);
754 auto result = sceneSession->moveDragController_->ConsumeDragEvent(pointerEvent, originalRect, property,
755 sessionConfig);
756 ASSERT_EQ(result, true);
757
758 // RIGHT_TOP
759 pointerItem.SetWindowX(1000);
760 pointerItem.SetWindowY(0);
761 result = sceneSession->moveDragController_->ConsumeDragEvent(pointerEvent, originalRect, property, sessionConfig);
762 ASSERT_EQ(result, true);
763
764 // RIGHT_BOTTOM
765 pointerItem.SetWindowX(1000);
766 pointerItem.SetWindowY(1000);
767 result = sceneSession->moveDragController_->ConsumeDragEvent(pointerEvent, originalRect, property, sessionConfig);
768 ASSERT_EQ(result, true);
769
770 // LEFT_BOTTOM
771 pointerItem.SetWindowX(0);
772 pointerItem.SetWindowY(1000);
773 result = sceneSession->moveDragController_->ConsumeDragEvent(pointerEvent, originalRect, property, sessionConfig);
774 ASSERT_EQ(result, true);
775 }
776
777 /**
778 * @tc.name: ConsumeDragEvent04
779 * @tc.desc: ConsumeDragEvent, normal scene
780 * @tc.type: FUNC
781 */
782 HWTEST_F(WindowSessionTest, ConsumeDragEvent04, Function | SmallTest | Level2)
783 {
784 SessionInfo info;
785 info.abilityName_ = "testSession1";
786 info.bundleName_ = "testSession3";
787 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
788 EXPECT_NE(sceneSession, nullptr);
789 sceneSession->moveDragController_ = new MoveDragController(1);
790 ASSERT_TRUE(sceneSession->moveDragController_);
791 sceneSession->moveDragController_->InitMoveDragProperty();
792 WSRect originalRect = { 100, 100, 1000, 1000 };
793 sptr<WindowSessionProperty> property = new WindowSessionProperty();
794 property->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
795 property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
796 SystemSessionConfig sessionConfig;
797 sessionConfig.isSystemDecorEnable_ = true;
798 sessionConfig.backgroundswitch = true;
799 sessionConfig.decorWindowModeSupportType_ = WindowModeSupport::WINDOW_MODE_SUPPORT_ALL;
800 std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
801 ASSERT_TRUE(pointerEvent);
802 pointerEvent->SetAgentWindowId(1);
803 pointerEvent->SetPointerId(0);
804 pointerEvent->SetSourceType(MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
805 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_DOWN);
806 MMI::PointerEvent::PointerItem pointerItem;
807 pointerItem.SetPointerId(0);
808 pointerEvent->AddPointerItem(pointerItem);
809
810 // LEFT
811 pointerItem.SetWindowX(0);
812 pointerItem.SetWindowY(500);
813 auto result = sceneSession->moveDragController_->ConsumeDragEvent(pointerEvent, originalRect, property,
814 sessionConfig);
815 ASSERT_EQ(result, true);
816
817 // TOP
818 pointerItem.SetWindowX(500);
819 pointerItem.SetWindowY(0);
820 result = sceneSession->moveDragController_->ConsumeDragEvent(pointerEvent, originalRect, property, sessionConfig);
821 ASSERT_EQ(result, true);
822
823 // RIGHT
824 pointerItem.SetWindowX(1000);
825 pointerItem.SetWindowY(500);
826 result = sceneSession->moveDragController_->ConsumeDragEvent(pointerEvent, originalRect, property, sessionConfig);
827 ASSERT_EQ(result, true);
828
829 // BOTTOM
830 pointerItem.SetWindowX(500);
831 pointerItem.SetWindowY(1000);
832 result = sceneSession->moveDragController_->ConsumeDragEvent(pointerEvent, originalRect, property, sessionConfig);
833 ASSERT_EQ(result, true);
834 }
835
836 /**
837 * @tc.name: GetWindowId01
838 * @tc.desc: GetWindowId, normal scene
839 * @tc.type: FUNC
840 */
841 HWTEST_F(WindowSessionTest, GetWindowId, Function | SmallTest | Level2)
842 {
843 ASSERT_NE(session_, nullptr);
844 ASSERT_EQ(0, session_->GetWindowId());
845 }
846
847 /**
848 * @tc.name: GetRSVisible01
849 * @tc.desc: GetRSVisible, normal scene
850 * @tc.type: FUNC
851 */
852 HWTEST_F(WindowSessionTest, GetRSVisible, Function | SmallTest | Level2)
853 {
854 ASSERT_NE(session_, nullptr);
855 ASSERT_EQ(WSError::WS_OK, session_->SetRSVisible(false));
856 session_->state_ = SessionState::STATE_CONNECT;
857 if (!session_->GetRSVisible()) {
858 ASSERT_EQ(false, session_->GetRSVisible());
859 }
860 }
861
862 /**
863 * @tc.name: SetFocusable01
864 * @tc.desc: SetFocusable, normal scene
865 * @tc.type: FUNC
866 */
867 HWTEST_F(WindowSessionTest, SetFocusable, Function | SmallTest | Level2)
868 {
869 ASSERT_NE(session_, nullptr);
870 session_->state_ = SessionState::STATE_DISCONNECT;
871 ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(false));
872 }
873
874 /**
875 * @tc.name: GetSnapshot
876 * @tc.desc: GetSnapshot Test
877 * @tc.type: FUNC
878 */
879 HWTEST_F(WindowSessionTest, GetSnapshot, Function | SmallTest | Level2)
880 {
881 ASSERT_NE(session_, nullptr);
882 session_->state_ = SessionState::STATE_DISCONNECT;
883 std::shared_ptr<Media::PixelMap> snapshot = session_->Snapshot();
884 ASSERT_EQ(snapshot, session_->GetSnapshot());
885 }
886
887 /**
888 * @tc.name: NotifyExtensionDied
889 * @tc.desc: NotifyExtensionDied Test
890 * @tc.type: FUNC
891 */
892 HWTEST_F(WindowSessionTest, NotifyExtensionDied, Function | SmallTest | Level2)
893 {
894 ASSERT_NE(session_, nullptr);
895 session_->state_ = SessionState::STATE_DISCONNECT;
896 session_->NotifyExtensionDied();
897
898 ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(false));
899 }
900
901 /**
902 * @tc.name: NotifyExtensionTimeout
903 * @tc.desc: NotifyExtensionTimeout Test
904 * @tc.type: FUNC
905 */
906 HWTEST_F(WindowSessionTest, NotifyExtensionTimeout, Function | SmallTest | Level2)
907 {
908 ASSERT_NE(session_, nullptr);
909 session_->state_ = SessionState::STATE_DISCONNECT;
910 session_->NotifyExtensionTimeout(3);
911
912 session_->RegisterLifecycleListener(lifecycleListener_);
913 session_->NotifyExtensionTimeout(3);
914 session_->UnregisterLifecycleListener(lifecycleListener_);
915
916 ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(false));
917 }
918
919 /**
920 * @tc.name: SetAspectRatio
921 * @tc.desc: SetAspectRatio Test
922 * @tc.type: FUNC
923 */
924 HWTEST_F(WindowSessionTest, SetAspectRatio, Function | SmallTest | Level2)
925 {
926 ASSERT_NE(session_, nullptr);
927 session_->state_ = SessionState::STATE_DISCONNECT;
928 ASSERT_EQ(WSError::WS_OK, session_->SetAspectRatio(0.1f));
929 }
930
931 /**
932 * @tc.name: UpdateSessionTouchable
933 * @tc.desc: UpdateSessionTouchable Test
934 * @tc.type: FUNC
935 */
936 HWTEST_F(WindowSessionTest, UpdateSessionTouchable, Function | SmallTest | Level2)
937 {
938 ASSERT_NE(session_, nullptr);
939
940 session_->state_ = SessionState::STATE_DISCONNECT;
941 session_->UpdateSessionTouchable(false);
942
943 ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(false));
944 }
945
946 /**
947 * @tc.name: SetFocusable02
948 * @tc.desc: others
949 * @tc.type: FUNC
950 */
951 HWTEST_F(WindowSessionTest, SetFocusable02, Function | SmallTest | Level2)
952 {
953 ASSERT_NE(session_, nullptr);
954
955 session_->state_ = SessionState::STATE_FOREGROUND;
956 session_->sessionInfo_.isSystem_ = false;
957
958 ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(true));
959 }
960
961 /**
962 * @tc.name: GetFocusable01
963 * @tc.desc: property_ is not nullptr
964 * @tc.type: FUNC
965 */
966 HWTEST_F(WindowSessionTest, GetFocusable01, Function | SmallTest | Level2)
967 {
968 ASSERT_NE(session_, nullptr);
969 session_->property_ = new WindowSessionProperty();
970 ASSERT_EQ(true, session_->GetFocusable());
971 }
972
973 /**
974 * @tc.name: GetFocusable02
975 * @tc.desc: property_ is nullptr
976 * @tc.type: FUNC
977 */
978 HWTEST_F(WindowSessionTest, GetFocusable02, Function | SmallTest | Level2)
979 {
980 ASSERT_NE(session_, nullptr);
981 session_->property_ = 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 session_->property_ = nullptr;
1124 ASSERT_EQ(WSError::WS_ERROR_NULLPTR, session_->SetBrightness(0.1f));
1125 }
1126
1127 /**
1128 * @tc.name: SetBrightness02
1129 * @tc.desc: property_ is not nullptr
1130 * @tc.type: FUNC
1131 */
1132 HWTEST_F(WindowSessionTest, SetBrightness02, Function | SmallTest | Level2)
1133 {
1134 ASSERT_NE(session_, nullptr);
1135 session_->state_ = SessionState::STATE_DISCONNECT;
1136 session_->property_ = new WindowSessionProperty();
1137 ASSERT_EQ(WSError::WS_OK, session_->SetBrightness(0.1f));
1138 }
1139
1140 /**
1141 * @tc.name: UpdateHotRect
1142 * @tc.desc: UpdateHotRect Test
1143 * @tc.type: FUNC
1144 */
1145 HWTEST_F(WindowSessionTest, UpdateHotRect, Function | SmallTest | Level2)
1146 {
1147 ASSERT_NE(session_, nullptr);
1148
1149 WSRect rect;
1150 rect.posX_ = 0;
1151 rect.posY_ = 0;
1152 rect.width_ = 0;
1153 rect.height_ = 0;
1154
1155 WSRectF newRect;
1156 const float outsideBorder = 4.0f * 1.5f;
1157 const size_t outsideBorderCount = 2;
1158 newRect.posX_ = rect.posX_ - outsideBorder;
1159 newRect.posY_ = rect.posY_ - outsideBorder;
1160 newRect.width_ = rect.width_ + outsideBorder * outsideBorderCount;
1161 newRect.height_ = rect.height_ + outsideBorder * outsideBorderCount;
1162
1163 ASSERT_EQ(newRect, session_->UpdateHotRect(rect));
1164 }
1165
1166 /**
1167 * @tc.name: SetTerminateSessionListener
1168 * @tc.desc: SetTerminateSessionListener Test
1169 * @tc.type: FUNC
1170 */
1171 HWTEST_F(WindowSessionTest, SetTerminateSessionListener, Function | SmallTest | Level2)
1172 {
1173 ASSERT_NE(session_, nullptr);
1174 session_->state_ = SessionState::STATE_DISCONNECT;
1175 session_->SetTerminateSessionListener(nullptr);
1176
1177 ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(false));
1178 }
1179
1180 /**
1181 * @tc.name: SetTerminateSessionListenerTotal
1182 * @tc.desc: SetTerminateSessionListenerTotal Test
1183 * @tc.type: FUNC
1184 */
1185 HWTEST_F(WindowSessionTest, SetTerminateSessionListenerTotal, Function | SmallTest | Level2)
1186 {
1187 ASSERT_NE(session_, nullptr);
1188 session_->state_ = SessionState::STATE_DISCONNECT;
1189 session_->SetTerminateSessionListenerTotal(nullptr);
1190
1191 ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(false));
1192 }
1193
1194 /**
1195 * @tc.name: SetSessionLabel
1196 * @tc.desc: SetSessionLabel Test
1197 * @tc.type: FUNC
1198 */
1199 HWTEST_F(WindowSessionTest, SetSessionLabel, Function | SmallTest | Level2)
1200 {
1201 ASSERT_NE(session_, nullptr);
1202 session_->state_ = SessionState::STATE_DISCONNECT;
__anon7ac06df50802(const std::string& label) 1203 NofitySessionLabelUpdatedFunc func = [](const std::string& label) {};
1204 session_->updateSessionLabelFunc_ = func;
1205 ASSERT_EQ(WSError::WS_OK, session_->SetSessionLabel("SetSessionLabel Test"));
1206 }
1207
1208 /**
1209 * @tc.name: SetUpdateSessionLabelListener
1210 * @tc.desc: SetUpdateSessionLabelListener Test
1211 * @tc.type: FUNC
1212 */
1213 HWTEST_F(WindowSessionTest, SetUpdateSessionLabelListener, Function | SmallTest | Level2)
1214 {
1215 ASSERT_NE(session_, nullptr);
1216 session_->state_ = SessionState::STATE_DISCONNECT;
1217 NofitySessionLabelUpdatedFunc func = nullptr;
1218 session_->SetUpdateSessionLabelListener(func);
1219
1220 ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(false));
1221 }
1222
1223 /**
1224 * @tc.name: SetPendingSessionToForegroundListener
1225 * @tc.desc: SetPendingSessionToForegroundListener Test
1226 * @tc.type: FUNC
1227 */
1228 HWTEST_F(WindowSessionTest, SetPendingSessionToForegroundListener, Function | SmallTest | Level2)
1229 {
1230 ASSERT_NE(session_, nullptr);
1231 session_->state_ = SessionState::STATE_DISCONNECT;
1232 session_->SetPendingSessionToForegroundListener(nullptr);
1233
1234 ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(false));
1235 }
1236
1237 /**
1238 * @tc.name: NotifyScreenshot
1239 * @tc.desc: NotifyScreenshot Test
1240 * @tc.type: FUNC
1241 */
1242 HWTEST_F(WindowSessionTest, NotifyScreenshot, Function | SmallTest | Level2)
1243 {
1244 ASSERT_NE(session_, nullptr);
1245 session_->sessionStage_ = nullptr;
1246 session_->NotifyScreenshot();
1247
1248 session_->sessionStage_ = mockSessionStage_;
1249 session_->NotifyScreenshot();
1250
1251 session_->property_ = new WindowSessionProperty();
1252 ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(false));
1253 }
1254
1255 /**
1256 * @tc.name: TransferBackPressedEventForConsumed02
1257 * @tc.desc: windowEventChannel_ is not nullptr
1258 * @tc.type: FUNC
1259 */
1260 HWTEST_F(WindowSessionTest, TransferBackPressedEventForConsumed02, Function | SmallTest | Level2)
1261 {
1262 ASSERT_NE(session_, nullptr);
1263
1264 session_->windowEventChannel_ = new TestWindowEventChannel();
1265
1266 bool isConsumed = false;
1267 ASSERT_EQ(WSError::WS_OK, session_->TransferBackPressedEventForConsumed(isConsumed));
1268 }
1269
1270 /**
1271 * @tc.name: GetUIContentRemoteObj
1272 * @tc.desc: GetUIContentRemoteObj Test
1273 * @tc.type: FUNC
1274 */
1275 HWTEST_F(WindowSessionTest, GetUIContentRemoteObj, Function | SmallTest | Level2)
1276 {
1277 ASSERT_NE(session_, nullptr);
1278 sptr<SessionStageMocker> mockSessionStage = new(std::nothrow) SessionStageMocker();
1279 ASSERT_NE(mockSessionStage, nullptr);
1280 EXPECT_CALL(*(mockSessionStage), GetUIContentRemoteObj(_)).WillRepeatedly(Return(WSError::WS_OK));
1281 session_->sessionStage_ = mockSessionStage;
1282 session_->state_ = SessionState::STATE_FOREGROUND;
1283 sptr<IRemoteObject> remoteObj;
1284 ASSERT_EQ(WSError::WS_OK, session_->GetUIContentRemoteObj(remoteObj));
1285
1286 session_->state_ = SessionState::STATE_BACKGROUND;
1287 ASSERT_EQ(WSError::WS_OK, session_->GetUIContentRemoteObj(remoteObj));
1288 Mock::VerifyAndClearExpectations(&mockSessionStage);
1289
1290 session_->sessionInfo_.isSystem_ = true;
1291 ASSERT_EQ(WSError::WS_ERROR_INVALID_SESSION, session_->GetUIContentRemoteObj(remoteObj));
1292 }
1293
1294 /**
1295 * @tc.name: TransferKeyEventForConsumed02
1296 * @tc.desc: windowEventChannel_ is not nullptr, keyEvent is nullptr
1297 * @tc.type: FUNC
1298 */
1299 HWTEST_F(WindowSessionTest, TransferKeyEventForConsumed02, Function | SmallTest | Level2)
1300 {
1301 ASSERT_NE(session_, nullptr);
1302
1303 session_->windowEventChannel_ = new TestWindowEventChannel();
1304
1305 std::shared_ptr<MMI::KeyEvent> keyEvent = nullptr;
1306 bool isConsumed = false;
1307 ASSERT_EQ(WSError::WS_ERROR_NULLPTR, session_->TransferKeyEventForConsumed(keyEvent, isConsumed));
1308 }
1309
1310 /**
1311 * @tc.name: TransferKeyEventForConsumed03
1312 * @tc.desc: windowEventChannel_ is not nullptr, keyEvent is not nullptr
1313 * @tc.type: FUNC
1314 */
1315 HWTEST_F(WindowSessionTest, TransferKeyEventForConsumed03, Function | SmallTest | Level2)
1316 {
1317 ASSERT_NE(session_, nullptr);
1318
1319 session_->windowEventChannel_ = new TestWindowEventChannel();
1320
1321 std::shared_ptr<MMI::KeyEvent> keyEvent = MMI::KeyEvent::Create();
1322 bool isConsumed = false;
1323 ASSERT_EQ(WSError::WS_OK, session_->TransferKeyEventForConsumed(keyEvent, isConsumed));
1324 }
1325
1326 /**
1327 * @tc.name: TransferFocusActiveEvent02
1328 * @tc.desc: windowEventChannel_ is not nullptr
1329 * @tc.type: FUNC
1330 */
1331 HWTEST_F(WindowSessionTest, TransferFocusActiveEvent02, Function | SmallTest | Level2)
1332 {
1333 ASSERT_NE(session_, nullptr);
1334
1335 session_->windowEventChannel_ = new TestWindowEventChannel();
1336
1337 ASSERT_EQ(WSError::WS_OK, session_->TransferFocusActiveEvent(false));
1338 }
1339
1340 /**
1341 * @tc.name: TransferFocusStateEvent02
1342 * @tc.desc: windowEventChannel_ is not nullptr
1343 * @tc.type: FUNC
1344 */
1345 HWTEST_F(WindowSessionTest, TransferFocusStateEvent02, Function | SmallTest | Level2)
1346 {
1347 ASSERT_NE(session_, nullptr);
1348
1349 session_->windowEventChannel_ = new TestWindowEventChannel();
1350
1351 ASSERT_EQ(WSError::WS_OK, session_->TransferFocusStateEvent(false));
1352 }
1353
1354 /**
1355 * @tc.name: SetCompatibleModeInPc
1356 * @tc.desc: SetCompatibleModeInPc test
1357 * @tc.type: FUNC
1358 */
1359 HWTEST_F(WindowSessionTest, SetCompatibleModeInPc, Function | SmallTest | Level2)
1360 {
1361 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
1362 ASSERT_NE(nullptr, property);
1363 bool enable = true;
1364 bool isSupportDragInPcCompatibleMode = true;
1365 property->SetCompatibleModeInPc(enable);
1366 ASSERT_EQ(property->GetCompatibleModeInPc(), true);
1367 property->SetIsSupportDragInPcCompatibleMode(isSupportDragInPcCompatibleMode);;
1368 ASSERT_EQ(property->GetIsSupportDragInPcCompatibleMode(), true);
1369 }
1370
1371 /**
1372 * @tc.name: UpdateMaximizeMode
1373 * @tc.desc: UpdateMaximizeMode test
1374 * @tc.type: FUNC
1375 */
1376 HWTEST_F(WindowSessionTest, UpdateMaximizeMode, Function | SmallTest | Level2)
1377 {
1378 sptr<SessionStageMocker> mockSessionStage = new (std::nothrow) SessionStageMocker();
1379 EXPECT_NE(mockSessionStage, nullptr);
1380 session_->sessionStage_ = mockSessionStage;
1381
1382 session_->sessionInfo_.isSystem_ = false;
1383 session_->state_ = SessionState::STATE_ACTIVE;
1384 auto ret = session_->UpdateMaximizeMode(true);
1385 ASSERT_EQ(ret, WSError::WS_OK);
1386
1387 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
1388 ASSERT_NE(property, nullptr);
1389 property->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
1390 session_->SetSessionProperty(property);
1391 ret = session_->UpdateMaximizeMode(false);
1392 ASSERT_EQ(ret, WSError::WS_OK);
1393
1394 session_->SetSessionProperty(nullptr);
1395 ret = session_->UpdateMaximizeMode(false);
1396 ASSERT_EQ(ret, WSError::WS_ERROR_NULLPTR);
1397 }
1398
1399 /**
1400 * @tc.name: UpdateTitleInTargetPos
1401 * @tc.desc: UpdateTitleInTargetPos test
1402 * @tc.type: FUNC
1403 */
1404 HWTEST_F(WindowSessionTest, UpdateTitleInTargetPos, Function | SmallTest | Level2)
1405 {
1406 sptr<SessionStageMocker> mockSessionStage = new (std::nothrow) SessionStageMocker();
1407 EXPECT_NE(mockSessionStage, nullptr);
1408 session_->sessionStage_ = mockSessionStage;
1409
1410 session_->sessionInfo_.isSystem_ = false;
1411 session_->state_ = SessionState::STATE_FOREGROUND;
1412 auto ret = session_->UpdateTitleInTargetPos(true, 20);
1413 ASSERT_NE(ret, WSError::WS_ERROR_INVALID_SESSION);
1414 }
1415
1416 /**
1417 * @tc.name: SwitchFreeMultiWindow
1418 * @tc.desc: SwitchFreeMultiWindow test
1419 * @tc.type: FUNC
1420 */
1421 HWTEST_F(WindowSessionTest, SwitchFreeMultiWindow, Function | SmallTest | Level2)
1422 {
1423 sptr<SessionStageMocker> mockSessionStage = new (std::nothrow) SessionStageMocker();
1424 EXPECT_NE(mockSessionStage, nullptr);
1425 session_->sessionStage_ = mockSessionStage;
1426
1427 session_->sessionInfo_.isSystem_ = false;
1428 session_->state_ = SessionState::STATE_FOREGROUND;
1429 auto ret = session_->SwitchFreeMultiWindow(true);
1430 ASSERT_NE(ret, WSError::WS_ERROR_INVALID_SESSION);
1431
1432 session_->sessionInfo_.isSystem_ = true;
1433 ret = session_->SwitchFreeMultiWindow(true);
1434 ASSERT_EQ(ret, WSError::WS_ERROR_INVALID_SESSION);
1435 }
1436
1437 /**
1438 * @tc.name: SetTouchHotAreas
1439 * @tc.desc: SetTouchHotAreas test
1440 * @tc.type: FUNC
1441 */
1442 HWTEST_F(WindowSessionTest, SetTouchHotAreas, Function | SmallTest | Level2)
1443 {
1444 session_->SetSessionProperty(nullptr);
1445 std::vector<Rect> touchHotAreas;
1446 session_->SetTouchHotAreas(touchHotAreas);
1447 ASSERT_EQ(session_->property_, nullptr);
1448
1449 session_->property_ = new WindowSessionProperty();
1450 touchHotAreas = session_->property_->touchHotAreas_;
1451 session_->property_->SetTouchHotAreas(touchHotAreas);
1452 ASSERT_EQ(touchHotAreas, session_->property_->touchHotAreas_);
1453 }
1454
1455 /**
1456 * @tc.name: NotifyOccupiedAreaChangeInfo
1457 * @tc.desc: NotifyOccupiedAreaChangeInfo test
1458 * @tc.type: FUNC
1459 */
1460 HWTEST_F(WindowSessionTest, NotifyOccupiedAreaChangeInfo, Function | SmallTest | Level2)
1461 {
1462 sptr<SessionStageMocker> mockSessionStage = new (std::nothrow) SessionStageMocker();
1463 EXPECT_NE(mockSessionStage, nullptr);
1464 session_->sessionStage_ = mockSessionStage;
1465 session_->NotifyOccupiedAreaChangeInfo(nullptr, nullptr);
1466 EXPECT_NE(session_->sessionStage_, nullptr);
1467 }
1468
1469 /**
1470 * @tc.name: ProcessBackEvent
1471 * @tc.desc: ProcessBackEvent test
1472 * @tc.type: FUNC
1473 */
1474 HWTEST_F(WindowSessionTest, ProcessBackEvent, Function | SmallTest | Level2)
1475 {
1476 sptr<SessionStageMocker> mockSessionStage = new (std::nothrow) SessionStageMocker();
1477 EXPECT_NE(mockSessionStage, nullptr);
1478 session_->sessionStage_ = mockSessionStage;
1479
1480 session_->sessionInfo_.isSystem_ = false;
1481 session_->state_ = SessionState::STATE_FOREGROUND;
1482 auto ret = session_->ProcessBackEvent();
1483 ASSERT_NE(ret, WSError::WS_ERROR_INVALID_SESSION);
1484 }
1485
1486 /**
1487 * @tc.name: ProcessBackGetAndSetSessionRequestRectEvent
1488 * @tc.desc: GetSessionRequestRectEvent, SetSessionRequestRectEvent test
1489 * @tc.type: FUNC
1490 */
1491 HWTEST_F(WindowSessionTest, GetAndSetSessionRequestRect, Function | SmallTest | Level2)
1492 {
1493 session_->SetSessionProperty(nullptr);
1494 session_->GetSessionRequestRect();
1495 ASSERT_EQ(session_->property_, nullptr);
1496
1497 WSRect rect = {0, 0, 0, 0};
1498 session_->SetSessionRequestRect(rect);
1499 ASSERT_EQ(session_->property_, nullptr);
1500 }
1501
1502 /**
1503 * @tc.name: SetSessionRect01
1504 * @tc.desc: SetSessionRect test
1505 * @tc.type: FUNC
1506 */
1507 HWTEST_F(WindowSessionTest, SetSessionRect01, Function | SmallTest | Level2)
1508 {
1509 WSRect rect = session_->GetSessionRect();
1510 session_->SetSessionRect(rect);
1511 ASSERT_EQ(rect, session_->winRect_);
1512 }
1513 }
1514 } // namespace Rosen
1515 } // namespace OHOS
1516