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