1 /*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <gtest/gtest.h>
17 #include <regex>
18 #include <pointer_event.h>
19 #include <ui/rs_surface_node.h>
20
21 #include "key_event.h"
22 #include "mock/mock_session_stage.h"
23 #include "mock/mock_window_event_channel.h"
24 #include "mock/mock_pattern_detach_callback.h"
25 #include "session/host/include/extension_session.h"
26 #include "session/host/include/move_drag_controller.h"
27 #include "session/host/include/scene_session.h"
28 #include "session/host/include/session.h"
29 #include "session_manager/include/scene_session_manager.h"
30 #include "session_info.h"
31 #include "session/screen/include/screen_session.h"
32 #include "screen_session_manager_client/include/screen_session_manager_client.h"
33 #include "wm_common.h"
34 #include "window_manager_hilog.h"
35
36 using namespace testing;
37 using namespace testing::ext;
38
39 namespace OHOS {
40 namespace Rosen {
41 namespace {
42 const std::string UNDEFINED = "undefined";
43 }
44
45 class WindowSessionTest3 : public testing::Test {
46 public:
47 static void SetUpTestCase();
48 static void TearDownTestCase();
49 void SetUp() override;
50 void TearDown() override;
51
52 int32_t GetTaskCount();
53 sptr<SceneSessionManager> ssm_;
54
55 private:
56 RSSurfaceNode::SharedPtr CreateRSSurfaceNode();
57 sptr<Session> session_ = nullptr;
58 static constexpr uint32_t WAIT_SYNC_IN_NS = 500000;
59 };
60
SetUpTestCase()61 void WindowSessionTest3::SetUpTestCase()
62 {
63 }
64
TearDownTestCase()65 void WindowSessionTest3::TearDownTestCase()
66 {
67 }
68
SetUp()69 void WindowSessionTest3::SetUp()
70 {
71 SessionInfo info;
72 info.abilityName_ = "testSession1";
73 info.moduleName_ = "testSession2";
74 info.bundleName_ = "testSession3";
75 session_ = sptr<Session>::MakeSptr(info);
76 EXPECT_NE(nullptr, session_);
77 session_->surfaceNode_ = CreateRSSurfaceNode();
78 ssm_ = sptr<SceneSessionManager>::MakeSptr();
79 session_->SetEventHandler(ssm_->taskScheduler_->GetEventHandler(), ssm_->eventHandler_);
80 auto isScreenLockedCallback = [this]() {
81 return ssm_->IsScreenLocked();
82 };
83 session_->RegisterIsScreenLockedCallback(isScreenLockedCallback);
84 }
85
TearDown()86 void WindowSessionTest3::TearDown()
87 {
88 session_ = nullptr;
89 usleep(WAIT_SYNC_IN_NS);
90 }
91
CreateRSSurfaceNode()92 RSSurfaceNode::SharedPtr WindowSessionTest3::CreateRSSurfaceNode()
93 {
94 struct RSSurfaceNodeConfig rsSurfaceNodeConfig;
95 rsSurfaceNodeConfig.SurfaceNodeName = "WindowSessionTest3SurfaceNode";
96 auto surfaceNode = RSSurfaceNode::Create(rsSurfaceNodeConfig);
97 if (surfaceNode == nullptr) {
98 GTEST_LOG_(INFO) << "WindowSessionTest3::CreateRSSurfaceNode surfaceNode is nullptr";
99 }
100 return surfaceNode;
101 }
102
GetTaskCount()103 int32_t WindowSessionTest3::GetTaskCount()
104 {
105 std::string dumpInfo = session_->handler_->GetEventRunner()->GetEventQueue()->DumpCurrentQueueSize();
106 std::regex pattern("\\d+");
107 std::smatch matches;
108 int32_t taskNum = 0;
109 while (std::regex_search(dumpInfo, matches, pattern)) {
110 taskNum += std::stoi(matches.str());
111 dumpInfo = matches.suffix();
112 }
113 return taskNum;
114 }
115
116 namespace {
117 /**
118 * @tc.name: NotifyContextTransparent
119 * @tc.desc: NotifyContextTransparent Test
120 * @tc.type: FUNC
121 */
HWTEST_F(WindowSessionTest3, NotifyContextTransparent, Function | SmallTest | Level2)122 HWTEST_F(WindowSessionTest3, NotifyContextTransparent, Function | SmallTest | Level2)
123 {
124 ASSERT_NE(session_, nullptr);
125 NotifyContextTransparentFunc contextTransparentFunc = session_->contextTransparentFunc_;
126 if (contextTransparentFunc == nullptr) {
127 contextTransparentFunc = {};
128 }
129 session_->contextTransparentFunc_ = nullptr;
130 session_->NotifyContextTransparent();
131
132 session_->SetContextTransparentFunc(contextTransparentFunc);
133 session_->NotifyContextTransparent();
134 session_->SetPendingSessionToBackgroundForDelegatorListener(nullptr);
135 EXPECT_EQ(WSError::WS_OK, session_->PendingSessionToBackgroundForDelegator(true));
136 }
137
138 /**
139 * @tc.name: SetFocusable04
140 * @tc.desc: SetFocusable Test
141 * @tc.type: FUNC
142 */
HWTEST_F(WindowSessionTest3, SetFocusable04, Function | SmallTest | Level2)143 HWTEST_F(WindowSessionTest3, SetFocusable04, Function | SmallTest | Level2)
144 {
145 ASSERT_NE(session_, nullptr);
146 session_->property_ = nullptr;
147 auto result = session_->SetFocusable(false);
148 ASSERT_EQ(result, WSError::WS_ERROR_NULLPTR);
149
150 session_->isFocused_ = true;
151 session_->property_ = sptr<WindowSessionProperty>::MakeSptr();
152 EXPECT_NE(session_->property_, nullptr);
153 session_->property_->SetFocusable(false);
154
155 result = session_->SetFocusable(false);
156 EXPECT_EQ(result, WSError::WS_OK);
157 EXPECT_EQ(session_->GetFocusable(), false);
158 }
159
160 /**
161 * @tc.name: SetSystemFocusable
162 * @tc.desc: SetSystemFocusable Test
163 * @tc.type: FUNC
164 */
HWTEST_F(WindowSessionTest3, SetSystemFocusable, Function | SmallTest | Level2)165 HWTEST_F(WindowSessionTest3, SetSystemFocusable, Function | SmallTest | Level2)
166 {
167 ASSERT_NE(session_, nullptr);
168 ASSERT_EQ(session_->GetSystemFocusable(), true);
169 bool systemFocusable = false;
170 session_->SetSystemFocusable(systemFocusable);
171 ASSERT_EQ(session_->GetSystemFocusable(), systemFocusable);
172 }
173
174 /**
175 * @tc.name: SetFocusableOnShow
176 * @tc.desc: SetFocusableOnShow Test
177 * @tc.type: FUNC
178 */
HWTEST_F(WindowSessionTest3, SetFocusableOnShow, Function | SmallTest | Level2)179 HWTEST_F(WindowSessionTest3, SetFocusableOnShow, Function | SmallTest | Level2)
180 {
181 ASSERT_NE(session_, nullptr);
182 ASSERT_EQ(session_->IsFocusableOnShow(), true);
183 bool focusableOnShow = false;
184 session_->SetFocusableOnShow(focusableOnShow);
185 usleep(10000); // sleep 10ms
186 ASSERT_EQ(session_->IsFocusableOnShow(), focusableOnShow);
187 }
188
189 /**
190 * @tc.name: CheckFocusable
191 * @tc.desc: CheckFocusable Test
192 * @tc.type: FUNC
193 */
HWTEST_F(WindowSessionTest3, CheckFocusable, Function | SmallTest | Level2)194 HWTEST_F(WindowSessionTest3, CheckFocusable, Function | SmallTest | Level2)
195 {
196 ASSERT_NE(session_, nullptr);
197 session_->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
198 ASSERT_EQ(session_->CheckFocusable(), true);
199 session_->SetSystemFocusable(false);
200 ASSERT_EQ(session_->CheckFocusable(), false);
201 }
202
203 /**
204 * @tc.name: SetTouchable03
205 * @tc.desc: IsSessionValid() and touchable return true
206 * @tc.type: FUNC
207 */
HWTEST_F(WindowSessionTest3, SetTouchable03, Function | SmallTest | Level2)208 HWTEST_F(WindowSessionTest3, SetTouchable03, Function | SmallTest | Level2)
209 {
210 ASSERT_NE(session_, nullptr);
211 session_->SetSessionState(SessionState::STATE_FOREGROUND);
212 session_->sessionInfo_.isSystem_ = false;
213 EXPECT_EQ(WSError::WS_OK, session_->SetTouchable(true));
214 }
215
216 /**
217 * @tc.name: GetTouchable02
218 * @tc.desc: GetTouchable Test
219 * @tc.type: FUNC
220 */
HWTEST_F(WindowSessionTest3, GetTouchable02, Function | SmallTest | Level2)221 HWTEST_F(WindowSessionTest3, GetTouchable02, Function | SmallTest | Level2)
222 {
223 ASSERT_NE(session_, nullptr);
224 session_->property_ = sptr<WindowSessionProperty>::MakeSptr();
225 ASSERT_NE(session_->property_, nullptr);
226 EXPECT_EQ(true, session_->GetTouchable());
227
228 session_->property_ = nullptr;
229 EXPECT_EQ(true, session_->GetTouchable());
230 }
231
232 /**
233 * @tc.name: UpdateDensity02
234 * @tc.desc: UpdateDensity Test
235 * @tc.type: FUNC
236 */
HWTEST_F(WindowSessionTest3, UpdateDensity02, Function | SmallTest | Level2)237 HWTEST_F(WindowSessionTest3, UpdateDensity02, Function | SmallTest | Level2)
238 {
239 ASSERT_NE(session_, nullptr);
240 session_->SetSessionState(SessionState::STATE_FOREGROUND);
241 sptr<SessionStageMocker> mockSessionStage = sptr<SessionStageMocker>::MakeSptr();
242 EXPECT_NE(nullptr, mockSessionStage);
243 session_->sessionStage_ = mockSessionStage;
244 auto result = session_->UpdateDensity();
245 EXPECT_EQ(result, WSError::WS_OK);
246 }
247
248 /**
249 * @tc.name: UpdateOrientation
250 * @tc.desc: UpdateOrientation Test
251 * @tc.type: FUNC
252 */
HWTEST_F(WindowSessionTest3, UpdateOrientation, Function | SmallTest | Level2)253 HWTEST_F(WindowSessionTest3, UpdateOrientation, Function | SmallTest | Level2)
254 {
255 ASSERT_NE(session_, nullptr);
256 session_->sessionInfo_.isSystem_ = true;
257 auto result = session_->UpdateOrientation();
258 EXPECT_EQ(result, WSError::WS_ERROR_INVALID_SESSION);
259
260 session_->sessionInfo_.isSystem_ = false;
261 session_->SetSessionState(SessionState::STATE_FOREGROUND);
262 result = session_->UpdateOrientation();
263 EXPECT_EQ(result, WSError::WS_ERROR_NULLPTR);
264
265 sptr<SessionStageMocker> mockSessionStage = sptr<SessionStageMocker>::MakeSptr();
266 EXPECT_NE(nullptr, mockSessionStage);
267 session_->sessionStage_ = mockSessionStage;
268 result = session_->UpdateOrientation();
269 EXPECT_EQ(result, WSError::WS_OK);
270 }
271
272 /**
273 * @tc.name: HandleDialogBackground
274 * @tc.desc: HandleDialogBackground Test
275 * @tc.type: FUNC
276 */
HWTEST_F(WindowSessionTest3, HandleDialogBackground, Function | SmallTest | Level2)277 HWTEST_F(WindowSessionTest3, HandleDialogBackground, Function | SmallTest | Level2)
278 {
279 ASSERT_NE(session_, nullptr);
280 session_->property_ = sptr<WindowSessionProperty>::MakeSptr();
281 ASSERT_NE(session_->property_, nullptr);
282 session_->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_END);
283 session_->HandleDialogBackground();
284
285 session_->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
286 sptr<Session> session01 = nullptr;
287
288 SessionInfo info;
289 info.abilityName_ = "testSession1";
290 info.moduleName_ = "testSession2";
291 info.bundleName_ = "testSession3";
292 sptr<Session> session02 = sptr<Session>::MakeSptr(info);
293 sptr<Session> session03 = sptr<Session>::MakeSptr(info);
294 EXPECT_NE(session02, nullptr);
295 EXPECT_NE(session03, nullptr);
296
297 sptr<SessionStageMocker> mockSessionStage = sptr<SessionStageMocker>::MakeSptr();
298 EXPECT_NE(nullptr, mockSessionStage);
299 session02->sessionStage_ = mockSessionStage;
300 session03->sessionStage_ = nullptr;
301
302 session_->dialogVec_.push_back(session01);
303 session_->dialogVec_.push_back(session02);
304 session_->dialogVec_.push_back(session03);
305 session_->HandleDialogBackground();
306 session_->SetPendingSessionToBackgroundForDelegatorListener(nullptr);
307 EXPECT_EQ(WSError::WS_OK, session_->PendingSessionToBackgroundForDelegator(true));
308 }
309
310 /**
311 * @tc.name: HandleDialogForeground
312 * @tc.desc: HandleDialogForeground Test
313 * @tc.type: FUNC
314 */
HWTEST_F(WindowSessionTest3, HandleDialogForeground, Function | SmallTest | Level2)315 HWTEST_F(WindowSessionTest3, HandleDialogForeground, Function | SmallTest | Level2)
316 {
317 ASSERT_NE(session_, nullptr);
318 session_->property_ = sptr<WindowSessionProperty>::MakeSptr();
319 ASSERT_NE(session_->property_, nullptr);
320 session_->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_END);
321 session_->HandleDialogForeground();
322
323 session_->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
324 sptr<Session> session01 = nullptr;
325
326 SessionInfo info;
327 info.abilityName_ = "testSession1";
328 info.moduleName_ = "testSession2";
329 info.bundleName_ = "testSession3";
330 sptr<Session> session02 = sptr<Session>::MakeSptr(info);
331 sptr<Session> session03 = sptr<Session>::MakeSptr(info);
332 EXPECT_NE(session02, nullptr);
333 EXPECT_NE(session03, nullptr);
334
335 sptr<SessionStageMocker> mockSessionStage = sptr<SessionStageMocker>::MakeSptr();
336 EXPECT_NE(nullptr, mockSessionStage);
337 session02->sessionStage_ = mockSessionStage;
338 session03->sessionStage_ = nullptr;
339
340 session_->dialogVec_.push_back(session01);
341 session_->dialogVec_.push_back(session02);
342 session_->dialogVec_.push_back(session03);
343 session_->HandleDialogForeground();
344 session_->SetPendingSessionToBackgroundForDelegatorListener(nullptr);
345 EXPECT_EQ(WSError::WS_OK, session_->PendingSessionToBackgroundForDelegator(true));
346 }
347
348 /**
349 * @tc.name: SetActive
350 * @tc.desc: SetActive Test
351 * @tc.type: FUNC
352 */
HWTEST_F(WindowSessionTest3, SetActive, Function | SmallTest | Level2)353 HWTEST_F(WindowSessionTest3, SetActive, Function | SmallTest | Level2)
354 {
355 ASSERT_NE(session_, nullptr);
356 session_->SetSessionState(SessionState::STATE_CONNECT);
357 auto result = session_->SetActive(false);
358 EXPECT_EQ(result, WSError::WS_DO_NOTHING);
359 }
360
361 /**
362 * @tc.name: SetActive02
363 * @tc.desc: SetActive Test
364 * @tc.type: FUNC
365 */
HWTEST_F(WindowSessionTest3, SetActive02, Function | SmallTest | Level2)366 HWTEST_F(WindowSessionTest3, SetActive02, Function | SmallTest | Level2)
367 {
368 ASSERT_NE(session_, nullptr);
369 session_->SetSessionState(SessionState::STATE_FOREGROUND);
370 sptr<SessionStageMocker> mockSessionStage = sptr<SessionStageMocker>::MakeSptr();
371 EXPECT_NE(nullptr, mockSessionStage);
372 session_->sessionStage_ = mockSessionStage;
373 auto result = session_->SetActive(true);
374 EXPECT_EQ(result, WSError::WS_OK);
375 }
376
377 /**
378 * @tc.name: SetActive03
379 * @tc.desc: SetActive Test
380 * @tc.type: FUNC
381 */
HWTEST_F(WindowSessionTest3, SetActive03, Function | SmallTest | Level2)382 HWTEST_F(WindowSessionTest3, SetActive03, Function | SmallTest | Level2)
383 {
384 ASSERT_NE(session_, nullptr);
385 sptr<SessionStageMocker> mockSessionStage = sptr<SessionStageMocker>::MakeSptr();
386 EXPECT_NE(nullptr, mockSessionStage);
387 session_->sessionStage_ = mockSessionStage;
388
389 session_->SetSessionState(SessionState::STATE_CONNECT);
390 auto result = session_->SetActive(true);
391 EXPECT_EQ(result, WSError::WS_OK);
392
393 session_->isActive_ = true;
394 result = session_->SetActive(false);
395 EXPECT_EQ(result, WSError::WS_OK);
396
397 session_->SetSessionState(SessionState::STATE_ACTIVE);
398 session_->isActive_ = true;
399 result = session_->SetActive(false);
400 EXPECT_EQ(result, WSError::WS_OK);
401 }
402
403 /**
404 * @tc.name: IsTopDialog02
405 * @tc.desc: IsTopDialog Test
406 * @tc.type: FUNC
407 */
HWTEST_F(WindowSessionTest3, IsTopDialog02, Function | SmallTest | Level2)408 HWTEST_F(WindowSessionTest3, IsTopDialog02, Function | SmallTest | Level2)
409 {
410 ASSERT_NE(session_, nullptr);
411 session_->SetParentSession(nullptr);
412 EXPECT_EQ(false, session_->IsTopDialog());
413
414 SessionInfo info;
415 info.abilityName_ = "testSession1";
416 info.moduleName_ = "testSession2";
417 info.bundleName_ = "testSession3";
418 sptr<Session> parentSession = sptr<Session>::MakeSptr(info);
419 ASSERT_NE(parentSession, nullptr);
420 parentSession->dialogVec_.clear();
421 session_->SetParentSession(parentSession);
422 auto result = session_->IsTopDialog();
423 EXPECT_EQ(result, true);
424 }
425
426 /**
427 * @tc.name: IsTopDialog03
428 * @tc.desc: IsTopDialog Test
429 * @tc.type: FUNC
430 */
HWTEST_F(WindowSessionTest3, IsTopDialog03, Function | SmallTest | Level2)431 HWTEST_F(WindowSessionTest3, IsTopDialog03, Function | SmallTest | Level2)
432 {
433 ASSERT_NE(session_, nullptr);
434 session_->dialogVec_.clear();
435 SessionInfo info;
436 info.abilityName_ = "testSession1";
437 info.moduleName_ = "testSession2";
438 info.bundleName_ = "testSession3";
439 sptr<Session> dialogSession1 = sptr<Session>::MakeSptr(info);
440 sptr<Session> dialogSession2 = sptr<Session>::MakeSptr(info);
441 ASSERT_NE(dialogSession1, nullptr);
442 ASSERT_NE(dialogSession2, nullptr);
443 dialogSession1->SetParentSession(session_);
444 dialogSession2->SetParentSession(session_);
445 session_->dialogVec_.push_back(dialogSession1);
446 session_->dialogVec_.push_back(dialogSession2);
447 dialogSession1->SetSessionState(SessionState::STATE_INACTIVE);
448 dialogSession2->SetSessionState(SessionState::STATE_INACTIVE);
449 EXPECT_EQ(false, dialogSession1->IsTopDialog());
450 }
451
452 /**
453 * @tc.name: PresentFocusIfPointDown
454 * @tc.desc: PresentFocusIfPointDown Test
455 * @tc.type: FUNC
456 */
HWTEST_F(WindowSessionTest3, PresentFocusIfPointDown, Function | SmallTest | Level2)457 HWTEST_F(WindowSessionTest3, PresentFocusIfPointDown, Function | SmallTest | Level2)
458 {
459 ASSERT_NE(session_, nullptr);
460 session_->isFocused_ = true;
461 session_->PresentFocusIfPointDown();
462
463 session_->isFocused_ = false;
464 session_->property_ = sptr<WindowSessionProperty>::MakeSptr();
465 EXPECT_NE(session_->property_, nullptr);
466 session_->property_->SetFocusable(false);
467 session_->PresentFocusIfPointDown();
468 session_->SetPendingSessionToBackgroundForDelegatorListener(nullptr);
469 EXPECT_EQ(WSError::WS_OK, session_->PendingSessionToBackgroundForDelegator(true));
470 }
471
472 /**
473 * @tc.name: HandlePointDownDialog
474 * @tc.desc: HandlePointDownDialog Test
475 * @tc.type: FUNC
476 */
HWTEST_F(WindowSessionTest3, HandlePointDownDialog, Function | SmallTest | Level2)477 HWTEST_F(WindowSessionTest3, HandlePointDownDialog, Function | SmallTest | Level2)
478 {
479 ASSERT_NE(session_, nullptr);
480 SessionInfo info;
481 info.abilityName_ = "testSession1";
482 info.moduleName_ = "testSession2";
483 info.bundleName_ = "testSession3";
484 sptr<Session> dialogSession1 = sptr<Session>::MakeSptr(info);
485 sptr<Session> dialogSession2 = sptr<Session>::MakeSptr(info);
486 sptr<Session> dialogSession3 = sptr<Session>::MakeSptr(info);
487 sptr<Session> dialogSession4 = nullptr;
488 ASSERT_NE(dialogSession1, nullptr);
489 ASSERT_NE(dialogSession2, nullptr);
490 ASSERT_NE(dialogSession3, nullptr);
491 dialogSession1->SetSessionState(SessionState::STATE_FOREGROUND);
492 dialogSession2->SetSessionState(SessionState::STATE_ACTIVE);
493 dialogSession2->SetSessionState(SessionState::STATE_INACTIVE);
494 session_->dialogVec_.push_back(dialogSession1);
495 session_->dialogVec_.push_back(dialogSession2);
496 session_->dialogVec_.push_back(dialogSession3);
497 session_->dialogVec_.push_back(dialogSession4);
498 session_->HandlePointDownDialog();
499 session_->SetPendingSessionToBackgroundForDelegatorListener(nullptr);
500 EXPECT_EQ(WSError::WS_OK, session_->PendingSessionToBackgroundForDelegator(true));
501 }
502
503 /**
504 * @tc.name: HandleSubWindowClick01
505 * @tc.desc: parentSession and property is nullptr
506 * @tc.type: FUNC
507 */
HWTEST_F(WindowSessionTest3, HandleSubWindowClick01, Function | SmallTest | Level2)508 HWTEST_F(WindowSessionTest3, HandleSubWindowClick01, Function | SmallTest | Level2)
509 {
510 ASSERT_NE(session_, nullptr);
511 auto result = session_->HandleSubWindowClick(MMI::PointerEvent::POINTER_ACTION_DOWN);
512 EXPECT_EQ(result, WSError::WS_OK);
513 }
514
515 /**
516 * @tc.name: HandleSubWindowClick03
517 * @tc.desc: parentSession->dialogVec_ is nullptr
518 * @tc.type: FUNC
519 */
HWTEST_F(WindowSessionTest3, HandleSubWindowClick03, Function | SmallTest | Level2)520 HWTEST_F(WindowSessionTest3, HandleSubWindowClick03, Function | SmallTest | Level2)
521 {
522 ASSERT_NE(session_, nullptr);
523 SessionInfo info;
524 info.abilityName_ = "testSession1";
525 info.moduleName_ = "testSession2";
526 info.bundleName_ = "testSession3";
527 sptr<Session> dialogSession = sptr<Session>::MakeSptr(info);
528 ASSERT_NE(dialogSession, nullptr);
529 session_->SetParentSession(dialogSession);
530
531 session_->property_ = sptr<WindowSessionProperty>::MakeSptr();
532 ASSERT_NE(session_->property_, nullptr);
533
534 auto result = session_->HandleSubWindowClick(MMI::PointerEvent::POINTER_ACTION_DOWN);
535 EXPECT_EQ(result, WSError::WS_OK);
536
537 result = session_->HandleSubWindowClick(MMI::PointerEvent::POINTER_ACTION_MOVE);
538 EXPECT_EQ(result, WSError::WS_OK);
539 }
540
541 /**
542 * @tc.name: TransferPointerEvent06
543 * @tc.desc: TransferPointerEvent Test
544 * @tc.type: FUNC
545 */
HWTEST_F(WindowSessionTest3, TransferPointerEvent06, Function | SmallTest | Level2)546 HWTEST_F(WindowSessionTest3, TransferPointerEvent06, Function | SmallTest | Level2)
547 {
548 ASSERT_NE(session_, nullptr);
549 session_->SetSessionState(SessionState::STATE_CONNECT);
550 std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
551 ASSERT_NE(pointerEvent, nullptr);
552
553 SessionInfo info;
554 info.abilityName_ = "testSession1";
555 info.moduleName_ = "testSession2";
556 info.bundleName_ = "testSession3";
557 sptr<Session> dialogSession = sptr<Session>::MakeSptr(info);
558 ASSERT_NE(dialogSession, nullptr);
559 dialogSession->SetSessionState(SessionState::STATE_ACTIVE);
560 session_->dialogVec_.push_back(dialogSession);
561 pointerEvent->pointerAction_ = MMI::PointerEvent::POINTER_ACTION_DOWN;
562
563 auto result = session_->TransferPointerEvent(pointerEvent);
564 EXPECT_EQ(result, WSError::WS_ERROR_INVALID_PERMISSION);
565 }
566
567 /**
568 * @tc.name: TransferPointerEvent07
569 * @tc.desc: TransferPointerEvent Test
570 * @tc.type: FUNC
571 */
HWTEST_F(WindowSessionTest3, TransferPointerEvent07, Function | SmallTest | Level2)572 HWTEST_F(WindowSessionTest3, TransferPointerEvent07, Function | SmallTest | Level2)
573 {
574 ASSERT_NE(session_, nullptr);
575 session_->SetSessionState(SessionState::STATE_CONNECT);
576 std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
577 ASSERT_NE(pointerEvent, nullptr);
578 session_->property_ = sptr<WindowSessionProperty>::MakeSptr();
579 ASSERT_NE(session_->property_, nullptr);
580 session_->property_->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
581 auto result = session_->TransferPointerEvent(pointerEvent);
582 EXPECT_EQ(result, WSError::WS_ERROR_NULLPTR);
583 }
584
585 /**
586 * @tc.name: TransferPointerEvent08
587 * @tc.desc: TransferPointerEvent Test
588 * @tc.type: FUNC
589 */
HWTEST_F(WindowSessionTest3, TransferPointerEvent08, Function | SmallTest | Level2)590 HWTEST_F(WindowSessionTest3, TransferPointerEvent08, Function | SmallTest | Level2)
591 {
592 ASSERT_NE(session_, nullptr);
593 session_->SetSessionState(SessionState::STATE_CONNECT);
594 std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
595 ASSERT_NE(pointerEvent, nullptr);
596
597 session_->property_ = sptr<WindowSessionProperty>::MakeSptr();
598 ASSERT_NE(session_->property_, nullptr);
599
600 session_->property_->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
601 SessionInfo info;
602 info.abilityName_ = "testSession1";
603 info.moduleName_ = "testSession2";
604 info.bundleName_ = "testSession3";
605 sptr<Session> dialogSession = sptr<Session>::MakeSptr(info);
606 ASSERT_NE(dialogSession, nullptr);
607
608 session_->SetParentSession(dialogSession);
609 auto result = session_->TransferPointerEvent(pointerEvent);
610 EXPECT_EQ(result, WSError::WS_ERROR_NULLPTR);
611 }
612
613 /**
614 * @tc.name: TransferPointerEvent09
615 * @tc.desc: TransferPointerEvent Test
616 * @tc.type: FUNC
617 */
HWTEST_F(WindowSessionTest3, TransferPointerEvent09, Function | SmallTest | Level2)618 HWTEST_F(WindowSessionTest3, TransferPointerEvent09, Function | SmallTest | Level2)
619 {
620 ASSERT_NE(session_, nullptr);
621 session_->SetSessionState(SessionState::STATE_FOREGROUND);
622 std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
623 ASSERT_NE(pointerEvent, nullptr);
624
625 session_->property_ = sptr<WindowSessionProperty>::MakeSptr();
626 ASSERT_NE(session_->property_, nullptr);
627
628 session_->property_->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
629 SessionInfo info;
630 info.abilityName_ = "testSession1";
631 info.moduleName_ = "testSession2";
632 info.bundleName_ = "testSession3";
633 sptr<Session> dialogSession = sptr<Session>::MakeSptr(info);
634 ASSERT_NE(dialogSession, nullptr);
635
636 session_->SetParentSession(dialogSession);
637 dialogSession->dialogVec_.push_back(session_);
638 pointerEvent->pointerAction_ = MMI::PointerEvent::POINTER_ACTION_MOVE;
639 auto result = session_->TransferPointerEvent(pointerEvent);
640 EXPECT_EQ(result, WSError::WS_ERROR_NULLPTR);
641 }
642
643 /**
644 * @tc.name: TransferPointerEvent10
645 * @tc.desc: TransferPointerEvent Test
646 * @tc.type: FUNC
647 */
HWTEST_F(WindowSessionTest3, TransferPointerEvent10, Function | SmallTest | Level2)648 HWTEST_F(WindowSessionTest3, TransferPointerEvent10, Function | SmallTest | Level2)
649 {
650 ASSERT_NE(session_, nullptr);
651 session_->SetSessionState(SessionState::STATE_FOREGROUND);
652 std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
653 ASSERT_NE(pointerEvent, nullptr);
654 pointerEvent->pointerAction_ = MMI::PointerEvent::POINTER_ACTION_DOWN;
655
656 session_->property_ = sptr<WindowSessionProperty>::MakeSptr();
657 ASSERT_NE(session_->property_, nullptr);
658 session_->property_->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
659
660 SessionInfo info;
661 info.abilityName_ = "testSession1";
662 info.moduleName_ = "testSession2";
663 info.bundleName_ = "testSession3";
664 sptr<Session> dialogSession = sptr<Session>::MakeSptr(info);
665 sptr<Session> dialogSession2 = sptr<Session>::MakeSptr(info);
666 sptr<Session> dialogSession3 = sptr<Session>::MakeSptr(info);
667 ASSERT_NE(dialogSession, nullptr);
668 ASSERT_NE(dialogSession2, nullptr);
669 ASSERT_NE(dialogSession3, nullptr);
670 dialogSession2->SetSessionState(SessionState::STATE_FOREGROUND);
671 dialogSession3->SetSessionState(SessionState::STATE_ACTIVE);
672 dialogSession2->persistentId_ = 9;
673 session_->SetParentSession(dialogSession);
674 dialogSession->dialogVec_.push_back(dialogSession2);
675 dialogSession->dialogVec_.push_back(dialogSession3);
676 auto result = session_->TransferPointerEvent(pointerEvent);
677 EXPECT_EQ(result, WSError::WS_ERROR_NULLPTR);
678 }
679
680 /**
681 * @tc.name: TransferPointerEvent11
682 * @tc.desc: TransferPointerEvent Test
683 * @tc.type: FUNC
684 */
HWTEST_F(WindowSessionTest3, TransferPointerEvent11, Function | SmallTest | Level2)685 HWTEST_F(WindowSessionTest3, TransferPointerEvent11, Function | SmallTest | Level2)
686 {
687 ASSERT_NE(session_, nullptr);
688 session_->SetSessionState(SessionState::STATE_FOREGROUND);
689 std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
690 ASSERT_NE(pointerEvent, nullptr);
691
692 session_->property_ = sptr<WindowSessionProperty>::MakeSptr();
693 ASSERT_NE(session_->property_, nullptr);
694 session_->property_->SetWindowType(WindowType::APP_WINDOW_BASE);
695
696 session_->windowEventChannel_ = nullptr;
697 auto result = session_->TransferPointerEvent(pointerEvent);
698 EXPECT_EQ(result, WSError::WS_ERROR_NULLPTR);
699 }
700
701 /**
702 * @tc.name: TransferFocusStateEvent03
703 * @tc.desc: TransferFocusStateEvent Test
704 * @tc.type: FUNC
705 */
HWTEST_F(WindowSessionTest3, TransferFocusStateEvent03, Function | SmallTest | Level2)706 HWTEST_F(WindowSessionTest3, TransferFocusStateEvent03, Function | SmallTest | Level2)
707 {
708 ASSERT_NE(session_, nullptr);
709 session_->windowEventChannel_ = nullptr;
710 session_->sessionInfo_.isSystem_ = true;
711 EXPECT_EQ(session_->TransferFocusStateEvent(true), WSError::WS_ERROR_NULLPTR);
712 }
713
714 /**
715 * @tc.name: Snapshot
716 * @tc.desc: Snapshot Test
717 * @tc.type: FUNC
718 */
HWTEST_F(WindowSessionTest3, Snapshot, Function | SmallTest | Level2)719 HWTEST_F(WindowSessionTest3, Snapshot, Function | SmallTest | Level2)
720 {
721 ASSERT_NE(session_, nullptr);
722 int32_t persistentId = 1424;
723 std::string bundleName = "testBundleName";
724 session_->scenePersistence_ = sptr<ScenePersistence>::MakeSptr(bundleName, persistentId);
725 ASSERT_NE(session_->scenePersistence_, nullptr);
726 struct RSSurfaceNodeConfig config;
727 session_->surfaceNode_ = RSSurfaceNode::Create(config);
728 ASSERT_NE(session_->surfaceNode_, nullptr);
729 EXPECT_EQ(nullptr, session_->Snapshot(false, 0.0f));
730
731 session_->bufferAvailable_ = true;
732 EXPECT_EQ(nullptr, session_->Snapshot(false, 0.0f));
733
734 session_->surfaceNode_->bufferAvailable_ = true;
735 EXPECT_EQ(nullptr, session_->Snapshot(false, 0.0f));
736
737 session_->surfaceNode_ = nullptr;
738 EXPECT_EQ(nullptr, session_->Snapshot(false, 0.0f));
739 }
740
741 /**
742 * @tc.name: SetBufferAvailableChangeListener
743 * @tc.desc: SetBufferAvailableChangeListener Test
744 * @tc.type: FUNC
745 */
HWTEST_F(WindowSessionTest3, SetBufferAvailableChangeListener, Function | SmallTest | Level2)746 HWTEST_F(WindowSessionTest3, SetBufferAvailableChangeListener, Function | SmallTest | Level2)
747 {
748 ASSERT_NE(session_, nullptr);
749 session_->SetSessionState(SessionState::STATE_CONNECT);
750 session_->SetSessionStateChangeNotifyManagerListener(nullptr);
751
752 session_->bufferAvailable_ = true;
753 session_->SetBufferAvailableChangeListener(nullptr);
754
755 int resultValue = 0;
756 NotifyBufferAvailableChangeFunc func = [&resultValue](const bool isAvailable) {
757 resultValue = 1;
758 };
759 session_->SetBufferAvailableChangeListener(func);
760 EXPECT_EQ(resultValue, 1);
761 }
762
763 /**
764 * @tc.name: SetLeashWindowSurfaceNodeChangedListener
765 * @tc.desc: SetLeashWindowSurfaceNodeChangedListener Test
766 * @tc.type: FUNC
767 */
HWTEST_F(WindowSessionTest3, SetLeashWindowSurfaceNodeChangedListener, Function | SmallTest | Level2)768 HWTEST_F(WindowSessionTest3, SetLeashWindowSurfaceNodeChangedListener, Function | SmallTest | Level2)
769 {
770 ASSERT_NE(session_, nullptr);
771 int resultValue = 0;
772 NotifyLeashWindowSurfaceNodeChangedFunc func = [&resultValue]() {
773 resultValue = 1;
774 };
775 session_->SetLeashWindowSurfaceNodeChangedListener(func);
776 session_->SetLeashWinSurfaceNode(nullptr);
777 EXPECT_EQ(resultValue, 1);
778 session_->SetLeashWindowSurfaceNodeChangedListener(nullptr);
779 }
780
781 /**
782 * @tc.name: NotifySessionFocusableChange
783 * @tc.desc: NotifySessionFocusableChange Test
784 * @tc.type: FUNC
785 */
HWTEST_F(WindowSessionTest3, NotifySessionFocusableChange, Function | SmallTest | Level2)786 HWTEST_F(WindowSessionTest3, NotifySessionFocusableChange, Function | SmallTest | Level2)
787 {
788 ASSERT_NE(session_, nullptr);
789 int resultValue = 0;
790 NotifySessionFocusableChangeFunc func = [&resultValue](const bool isFocusable) {
791 resultValue = 1;
792 };
793 session_->SetSessionFocusableChangeListener(func);
794 session_->NotifySessionFocusableChange(true);
795
796 session_->sessionFocusableChangeFunc_ = nullptr;
797 session_->NotifySessionFocusableChange(true);
798 EXPECT_EQ(resultValue, 1);
799 }
800
801 /**
802 * @tc.name: GetStateFromManager
803 * @tc.desc: GetStateFromManager Test
804 * @tc.type: FUNC
805 */
HWTEST_F(WindowSessionTest3, GetStateFromManager, Function | SmallTest | Level2)806 HWTEST_F(WindowSessionTest3, GetStateFromManager, Function | SmallTest | Level2)
807 {
808 ManagerState key = ManagerState{0};
809 GetStateFromManagerFunc func = [](const ManagerState key) {
810 return true;
811 };
812 session_->getStateFromManagerFunc_ = func;
813 session_->GetStateFromManager(key);
814
815 session_->getStateFromManagerFunc_ = nullptr;
816 ASSERT_EQ(false, session_->GetStateFromManager(key));
817
818 // 覆盖default分支
819 key = ManagerState{-1};
820 ASSERT_EQ(false, session_->GetStateFromManager(key));
821 }
822
823 /**
824 * @tc.name: NotifyUIRequestFocus
825 * @tc.desc: NotifyUIRequestFocus Test
826 * @tc.type: FUNC
827 */
HWTEST_F(WindowSessionTest3, NotifyUIRequestFocus, Function | SmallTest | Level2)828 HWTEST_F(WindowSessionTest3, NotifyUIRequestFocus, Function | SmallTest | Level2)
829 {
830 session_->requestFocusFunc_ = []() {};
831 session_->NotifyUIRequestFocus();
832
833 ASSERT_NE(session_, nullptr);
834 }
835
836 /**
837 * @tc.name: SetCompatibleModeInPc
838 * @tc.desc: SetCompatibleModeInPc Test
839 * @tc.type: FUNC
840 */
HWTEST_F(WindowSessionTest3, SetCompatibleModeInPc, Function | SmallTest | Level2)841 HWTEST_F(WindowSessionTest3, SetCompatibleModeInPc, Function | SmallTest | Level2)
842 {
843 session_->property_ = nullptr;
844 auto enable = true;
845 auto isSupportDragInPcCompatibleMode = true;
846 ASSERT_EQ(WSError::WS_ERROR_NULLPTR, session_->SetCompatibleModeInPc(enable, isSupportDragInPcCompatibleMode));
847
848 session_->property_ = sptr<WindowSessionProperty>::MakeSptr();
849 ASSERT_EQ(WSError::WS_OK, session_->SetCompatibleModeInPc(enable, isSupportDragInPcCompatibleMode));
850
851 enable = false;
852 ASSERT_EQ(WSError::WS_OK, session_->SetCompatibleModeInPc(enable, isSupportDragInPcCompatibleMode));
853 }
854
855 /**
856 * @tc.name: CompatibleFullScreen Recover&Minimize&Close
857 * @tc.desc: CompatibleFullScreen Recover&Minimize&Close Test
858 * @tc.type: FUNC
859 */
HWTEST_F(WindowSessionTest3, CompatibleFullScreen, Function | SmallTest | Level2)860 HWTEST_F(WindowSessionTest3, CompatibleFullScreen, Function | SmallTest | Level2)
861 {
862 sptr<SessionStageMocker> mockSessionStage = sptr<SessionStageMocker>::MakeSptr();
863 EXPECT_NE(nullptr, mockSessionStage);
864 session_->sessionStage_ = mockSessionStage;
865
866 session_->sessionInfo_.isSystem_ = false;
867 session_->state_ = SessionState::STATE_CONNECT;
868 session_->CompatibleFullScreenRecover();
869 session_->CompatibleFullScreenMinimize();
870 session_->CompatibleFullScreenClose();
871 session_->state_ = SessionState::STATE_DISCONNECT;
872
873 session_->sessionInfo_.isSystem_ = true;
874 ASSERT_EQ(WSError::WS_ERROR_INVALID_SESSION, session_->CompatibleFullScreenRecover());
875 ASSERT_EQ(WSError::WS_ERROR_INVALID_SESSION, session_->CompatibleFullScreenMinimize());
876 ASSERT_EQ(WSError::WS_ERROR_INVALID_SESSION, session_->CompatibleFullScreenClose());
877 }
878
879 /**
880 * @tc.name: NotifySessionTouchableChange
881 * @tc.desc: NotifySessionTouchableChange Test
882 * @tc.type: FUNC
883 */
HWTEST_F(WindowSessionTest3, NotifySessionTouchableChange, Function | SmallTest | Level2)884 HWTEST_F(WindowSessionTest3, NotifySessionTouchableChange, Function | SmallTest | Level2)
885 {
886 ASSERT_NE(session_, nullptr);
887 int resultValue = 0;
888 NotifySessionTouchableChangeFunc func = [&resultValue](const bool touchable) {
889 resultValue = 1;
890 };
891 session_->SetSessionTouchableChangeListener(func);
892 session_->NotifySessionTouchableChange(true);
893 EXPECT_EQ(resultValue, 1);
894 }
895
896 /**
897 * @tc.name: NotifyClick
898 * @tc.desc: NotifyClick Test
899 * @tc.type: FUNC
900 */
HWTEST_F(WindowSessionTest3, NotifyClick, Function | SmallTest | Level2)901 HWTEST_F(WindowSessionTest3, NotifyClick, Function | SmallTest | Level2)
902 {
903 ASSERT_NE(session_, nullptr);
904 int resultValue = 0;
905 bool hasRequestFocus = true;
906 NotifyClickFunc func = [&resultValue, &hasRequestFocus](bool requestFocus) {
907 resultValue = 1;
908 hasRequestFocus = requestFocus;
909 };
910 session_->SetClickListener(func);
911 session_->NotifyClick(false);
912 EXPECT_EQ(resultValue, 1);
913 EXPECT_EQ(hasRequestFocus, false);
914 }
915
916 /**
917 * @tc.name: NotifyRequestFocusStatusNotifyManager
918 * @tc.desc: NotifyRequestFocusStatusNotifyManager Test
919 * @tc.type: FUNC
920 */
HWTEST_F(WindowSessionTest3, NotifyRequestFocusStatusNotifyManager, Function | SmallTest | Level2)921 HWTEST_F(WindowSessionTest3, NotifyRequestFocusStatusNotifyManager, Function | SmallTest | Level2)
922 {
923 ASSERT_NE(session_, nullptr);
924 int resultValue = 0;
925 NotifyRequestFocusStatusNotifyManagerFunc func = [&resultValue](int32_t persistentId,
926 const bool isFocused, const bool byForeground, FocusChangeReason reason) {
927 resultValue = 1;
928 };
929 session_->SetRequestFocusStatusNotifyManagerListener(func);
930 FocusChangeReason reason = FocusChangeReason::SCB_SESSION_REQUEST;
931 session_->NotifyRequestFocusStatusNotifyManager(true, false, reason);
932 EXPECT_EQ(resultValue, 1);
933 }
934
935 /**
936 * @tc.name: PresentFoucusIfNeed
937 * @tc.desc: PresentFoucusIfNeed Test
938 * @tc.type: FUNC
939 */
HWTEST_F(WindowSessionTest3, PresentFoucusIfNeed, Function | SmallTest | Level2)940 HWTEST_F(WindowSessionTest3, PresentFoucusIfNeed, Function | SmallTest | Level2)
941 {
942 ASSERT_NE(session_, nullptr);
943 int32_t pointerAction = MMI::PointerEvent::POINTER_ACTION_DOWN;
944 session_->PresentFoucusIfNeed(pointerAction);
945 pointerAction = MMI::PointerEvent::POINTER_ACTION_BUTTON_DOWN;
946 session_->PresentFoucusIfNeed(pointerAction);
947 session_->property_->focusable_ = false;
948 session_->PresentFoucusIfNeed(pointerAction);
949 session_->isFocused_ = true;
950 session_->PresentFoucusIfNeed(pointerAction);
951 EXPECT_EQ(true, session_->CheckPointerEventDispatch(nullptr));
952 }
953
954 /**
955 * @tc.name: UpdateFocus03
956 * @tc.desc: UpdateFocus Test
957 * @tc.type: FUNC
958 */
HWTEST_F(WindowSessionTest3, UpdateFocus03, Function | SmallTest | Level2)959 HWTEST_F(WindowSessionTest3, UpdateFocus03, Function | SmallTest | Level2)
960 {
961 ASSERT_NE(session_, nullptr);
962 session_->isFocused_ = true;
963 EXPECT_EQ(WSError::WS_OK, session_->UpdateFocus(false));
964 }
965
966 /**
967 * @tc.name: NotifyFocusStatus
968 * @tc.desc: NotifyFocusStatus Test
969 * @tc.type: FUNC
970 */
HWTEST_F(WindowSessionTest3, NotifyFocusStatus, Function | SmallTest | Level2)971 HWTEST_F(WindowSessionTest3, NotifyFocusStatus, Function | SmallTest | Level2)
972 {
973 ASSERT_NE(session_, nullptr);
974 session_->state_ = SessionState::STATE_CONNECT;
975 sptr<SessionStageMocker> mockSessionStage = sptr<SessionStageMocker>::MakeSptr();
976 EXPECT_NE(nullptr, mockSessionStage);
977 session_->sessionStage_ = mockSessionStage;
978 EXPECT_EQ(WSError::WS_OK, session_->NotifyFocusStatus(true));
979 session_->sessionStage_ = nullptr;
980 EXPECT_EQ(WSError::WS_ERROR_NULLPTR, session_->NotifyFocusStatus(true));
981 }
982
983 /**
984 * @tc.name: RequestFocus
985 * @tc.desc: RequestFocus Test
986 * @tc.type: FUNC
987 */
HWTEST_F(WindowSessionTest3, RequestFocus, Function | SmallTest | Level2)988 HWTEST_F(WindowSessionTest3, RequestFocus, Function | SmallTest | Level2)
989 {
990 ASSERT_NE(session_, nullptr);
991 session_->state_ = SessionState::STATE_FOREGROUND;
992 session_->sessionInfo_.isSystem_ = false;
993 EXPECT_EQ(WSError::WS_OK, session_->RequestFocus(true));
994 EXPECT_EQ(WSError::WS_OK, session_->RequestFocus(false));
995 }
996
997 /**
998 * @tc.name: UpdateWindowMode
999 * @tc.desc: UpdateWindowMode Test
1000 * @tc.type: FUNC
1001 */
HWTEST_F(WindowSessionTest3, UpdateWindowMode, Function | SmallTest | Level2)1002 HWTEST_F(WindowSessionTest3, UpdateWindowMode, Function | SmallTest | Level2)
1003 {
1004 ASSERT_NE(session_, nullptr);
1005 sptr<SessionStageMocker> mockSessionStage = sptr<SessionStageMocker>::MakeSptr();
1006 EXPECT_NE(nullptr, mockSessionStage);
1007 session_->sessionStage_ = mockSessionStage;
1008
1009 session_->state_ = SessionState::STATE_END;
1010 auto result = session_->UpdateWindowMode(WindowMode::WINDOW_MODE_UNDEFINED);
1011 EXPECT_EQ(result, WSError::WS_ERROR_INVALID_SESSION);
1012
1013 session_->state_ = SessionState::STATE_DISCONNECT;
1014 result = session_->UpdateWindowMode(WindowMode::WINDOW_MODE_UNDEFINED);
1015 EXPECT_EQ(session_->property_->windowMode_, WindowMode::WINDOW_MODE_UNDEFINED);
1016 EXPECT_EQ(session_->property_->isNeedUpdateWindowMode_, true);
1017 EXPECT_EQ(result, WSError::WS_OK);
1018
1019 session_->state_ = SessionState::STATE_CONNECT;
1020 result = session_->UpdateWindowMode(WindowMode::WINDOW_MODE_SPLIT_SECONDARY);
1021 EXPECT_EQ(session_->property_->windowMode_, WindowMode::WINDOW_MODE_SPLIT_SECONDARY);
1022 EXPECT_EQ(session_->property_->maximizeMode_, MaximizeMode::MODE_RECOVER);
1023 EXPECT_EQ(result, WSError::WS_OK);
1024
1025 session_->state_ = SessionState::STATE_CONNECT;
1026 result = session_->UpdateWindowMode(WindowMode::WINDOW_MODE_SPLIT_PRIMARY);
1027 EXPECT_EQ(result, WSError::WS_OK);
1028
1029 session_->state_ = SessionState::STATE_CONNECT;
1030 result = session_->UpdateWindowMode(WindowMode::WINDOW_MODE_UNDEFINED);
1031 EXPECT_EQ(result, WSError::WS_OK);
1032
1033 session_->sessionStage_ = nullptr;
1034 result = session_->UpdateWindowMode(WindowMode::WINDOW_MODE_UNDEFINED);
1035 EXPECT_EQ(result, WSError::WS_ERROR_NULLPTR);
1036 }
1037
1038 /**
1039 * @tc.name: RectSizeCheckProcess
1040 * @tc.desc: RectSizeCheckProcess Test
1041 * @tc.type: FUNC
1042 */
HWTEST_F(WindowSessionTest3, RectSizeCheckProcess, Function | SmallTest | Level2)1043 HWTEST_F(WindowSessionTest3, RectSizeCheckProcess, Function | SmallTest | Level2)
1044 {
1045 ASSERT_NE(session_, nullptr);
1046 session_->RectSizeCheckProcess(1, 0, 2, 0, 0);
1047 session_->RectSizeCheckProcess(1, 0, 1, 0, 0);
1048 session_->RectSizeCheckProcess(0, 1, 0, 2, 0);
1049 session_->RectSizeCheckProcess(0, 1, 0, 0, 0);
1050 EXPECT_EQ(true, session_->CheckPointerEventDispatch(nullptr));
1051 }
1052
1053 /**
1054 * @tc.name: RectCheckProcess
1055 * @tc.desc: RectCheckProcess Test
1056 * @tc.type: FUNC
1057 */
HWTEST_F(WindowSessionTest3, RectCheckProcess, Function | SmallTest | Level2)1058 HWTEST_F(WindowSessionTest3, RectCheckProcess, Function | SmallTest | Level2)
1059 {
1060 ASSERT_NE(session_, nullptr);
1061 session_->isVisible_ = true;
1062 session_->property_ = nullptr;
1063 session_->RectCheckProcess();
1064
1065 session_->state_ = SessionState::STATE_FOREGROUND;
1066 session_->property_ = nullptr;
1067 session_->RectCheckProcess();
1068 EXPECT_EQ(true, session_->CheckPointerEventDispatch(nullptr));
1069 }
1070
1071 /**
1072 * @tc.name: RectCheckProcess01
1073 * @tc.desc: RectCheckProcess01 Test
1074 * @tc.type: FUNC
1075 */
HWTEST_F(WindowSessionTest3, RectCheckProcess01, Function | SmallTest | Level2)1076 HWTEST_F(WindowSessionTest3, RectCheckProcess01, Function | SmallTest | Level2)
1077 {
1078 ASSERT_NE(session_, nullptr);
1079 session_->state_ = SessionState::STATE_INACTIVE;
1080 session_->isVisible_ = false;
1081 session_->property_ = nullptr;
1082 session_->RectCheckProcess();
1083
1084 session_->state_ = SessionState::STATE_ACTIVE;
1085 session_->isVisible_ = true;
1086 session_->property_ = sptr<WindowSessionProperty>::MakeSptr();
1087 session_->RectCheckProcess();
1088
1089 session_->property_->displayId_ = 0;
1090 sptr<ScreenSession> screenSession = new ScreenSession(0, ScreenProperty(), 0);
1091 ASSERT_NE(screenSession, nullptr);
1092 ScreenProperty screenProperty = screenSession->GetScreenProperty();
1093 ASSERT_NE(&screenProperty, nullptr);
1094 screenSession->screenId_ = 0;
1095 screenSession->SetVirtualPixelRatio(0.0f);
1096 ScreenSessionManagerClient::GetInstance().screenSessionMap_.insert(std::make_pair(0, screenSession));
1097 session_->RectCheckProcess();
1098
1099 ScreenSessionManagerClient::GetInstance().screenSessionMap_.clear();
1100 screenSession->SetVirtualPixelRatio(1.0f);
1101 ScreenSessionManagerClient::GetInstance().screenSessionMap_.insert(std::make_pair(0, screenSession));
1102 session_->RectCheckProcess();
1103
1104 WSRect rect = {0, 0, 0, 0};
1105 session_->winRect_ = rect;
1106 session_->RectCheckProcess();
1107
1108 session_->winRect_.height_ = 200;
1109 session_->RectCheckProcess();
1110
1111 session_->aspectRatio_ = 0.0f;
1112 session_->RectCheckProcess();
1113
1114 session_->aspectRatio_ = 0.5f;
1115 session_->RectCheckProcess();
1116
1117 session_->winRect_.width_ = 200;
1118 session_->RectCheckProcess();
1119
1120 session_->aspectRatio_ = 1.0f;
1121 session_->RectCheckProcess();
1122
1123 ScreenSessionManagerClient::GetInstance().screenSessionMap_.clear();
1124 }
1125
1126 /**
1127 * @tc.name: SetAcquireRotateAnimationConfigFunc
1128 * @tc.desc: SetAcquireRotateAnimationConfigFunc Test
1129 * @tc.type: FUNC
1130 */
HWTEST_F(WindowSessionTest3, SetAcquireRotateAnimationConfigFunc, Function | SmallTest | Level2)1131 HWTEST_F(WindowSessionTest3, SetAcquireRotateAnimationConfigFunc, Function | SmallTest | Level2)
1132 {
1133 ASSERT_NE(session_, nullptr);
1134 session_->SetAcquireRotateAnimationConfigFunc(nullptr);
1135 ASSERT_EQ(session_->acquireRotateAnimationConfigFunc_, nullptr);
1136 int32_t duration = session_->GetRotateAnimationDuration();
1137 ASSERT_EQ(duration, ROTATE_ANIMATION_DURATION);
1138
1139 AcquireRotateAnimationConfigFunc func = [](RotateAnimationConfig& config) {
1140 config.duration_ = 800;
1141 };
1142 session_->SetAcquireRotateAnimationConfigFunc(func);
1143 ASSERT_NE(session_->acquireRotateAnimationConfigFunc_, nullptr);
1144 duration = session_->GetRotateAnimationDuration();
1145 ASSERT_EQ(duration, 800);
1146 }
1147
1148 /**
1149 * @tc.name: SetIsPcAppInPad
1150 * @tc.desc: SetIsPcAppInPad Test
1151 * @tc.type: FUNC
1152 */
HWTEST_F(WindowSessionTest3, SetIsPcAppInPad, Function | SmallTest | Level2)1153 HWTEST_F(WindowSessionTest3, SetIsPcAppInPad, Function | SmallTest | Level2)
1154 {
1155 ASSERT_NE(session_, nullptr);
1156 bool isPcAppInPad = false;
1157 session_->property_ = sptr<WindowSessionProperty>::MakeSptr();
1158 auto result = session_->SetIsPcAppInPad(isPcAppInPad);
1159 EXPECT_EQ(result, WSError::WS_OK);
1160
1161 session_->property_ = nullptr;
1162 EXPECT_EQ(WSError::WS_ERROR_NULLPTR, session_->SetIsPcAppInPad(isPcAppInPad));
1163 }
1164
1165 /**
1166 * @tc.name: SetBufferAvailable
1167 * @tc.desc: SetBufferAvailable Test
1168 * @tc.type: FUNC
1169 */
HWTEST_F(WindowSessionTest3, SetBufferAvailable, Function | SmallTest | Level2)1170 HWTEST_F(WindowSessionTest3, SetBufferAvailable, Function | SmallTest | Level2)
1171 {
1172 int resultValue = 0;
1173 NotifyBufferAvailableChangeFunc func = [&resultValue](const bool isAvailable) {
1174 resultValue = 1;
1175 };
1176 session_->SetBufferAvailableChangeListener(func);
1177 session_->SetBufferAvailable(true);
1178 ASSERT_EQ(session_->bufferAvailable_, true);
1179 }
1180
1181 /**
1182 * @tc.name: NotifySessionInfoChange
1183 * @tc.desc: NotifySessionInfoChange Test
1184 * @tc.type: FUNC
1185 */
HWTEST_F(WindowSessionTest3, NotifySessionInfoChange, Function | SmallTest | Level2)1186 HWTEST_F(WindowSessionTest3, NotifySessionInfoChange, Function | SmallTest | Level2)
1187 {
1188 int resultValue = 0;
1189 NotifyBufferAvailableChangeFunc func = [&resultValue](const bool isAvailable) {
1190 resultValue = 1;
1191 };
1192 session_->SetSessionInfoChangeNotifyManagerListener(func);
1193 session_->NotifySessionInfoChange();
1194 ASSERT_EQ(resultValue, 1);
1195 }
1196
1197 /**
1198 * @tc.name: SetCompatibleModeEnableInPad
1199 * @tc.desc: SetCompatibleModeEnableInPad Test
1200 * @tc.type: FUNC
1201 */
HWTEST_F(WindowSessionTest3, SetCompatibleModeEnableInPad, Function | SmallTest | Level2)1202 HWTEST_F(WindowSessionTest3, SetCompatibleModeEnableInPad, Function | SmallTest | Level2)
1203 {
1204 ASSERT_NE(session_, nullptr);
1205 session_->state_ = SessionState::STATE_FOREGROUND;
1206 sptr<SessionStageMocker> mockSessionStage = sptr<SessionStageMocker>::MakeSptr();
1207 EXPECT_NE(nullptr, mockSessionStage);
1208 session_->sessionStage_ = mockSessionStage;
1209 session_->property_ = nullptr;
1210 bool enable = true;
1211 ASSERT_EQ(WSError::WS_ERROR_NULLPTR, session_->SetCompatibleModeEnableInPad(enable));
1212
1213 session_->property_ = sptr<WindowSessionProperty>::MakeSptr();
1214 ASSERT_EQ(WSError::WS_OK, session_->SetCompatibleModeEnableInPad(enable));
1215
1216 enable = false;
1217 ASSERT_EQ(WSError::WS_OK, session_->SetCompatibleModeEnableInPad(enable));
1218 }
1219
1220 /**
1221 * @tc.name: RectSizeCheckProcess01
1222 * @tc.desc: RectSizeCheckProcess Test
1223 * @tc.type: FUNC
1224 */
HWTEST_F(WindowSessionTest3, RectSizeCheckProcess01, Function | SmallTest | Level2)1225 HWTEST_F(WindowSessionTest3, RectSizeCheckProcess01, Function | SmallTest | Level2)
1226 {
1227 session_->SetSessionProperty(nullptr);
1228 session_->RectSizeCheckProcess(1, 1, 2, 2, 0);
1229 ASSERT_EQ(session_->property_, nullptr);
1230 }
1231
1232 /**
1233 * @tc.name: GetSurfaceNodeForMoveDrag
1234 * @tc.desc: GetSurfaceNodeForMoveDrag Test
1235 * @tc.type: FUNC
1236 */
HWTEST_F(WindowSessionTest3, GetSurfaceNodeForMoveDrag, Function | SmallTest | Level2)1237 HWTEST_F(WindowSessionTest3, GetSurfaceNodeForMoveDrag, Function | SmallTest | Level2)
1238 {
1239 ASSERT_NE(session_, nullptr);
1240 session_->leashWinSurfaceNode_ = nullptr;
1241 session_->surfaceNode_ = nullptr;
1242 std::shared_ptr<RSSurfaceNode> res = session_->GetSurfaceNodeForMoveDrag();
1243 ASSERT_EQ(res, nullptr);
1244 }
1245
1246 /**
1247 * @tc.name: GetSnapshotPixelMap
1248 * @tc.desc: GetSnapshotPixelMap Test
1249 * @tc.type: FUNC
1250 */
HWTEST_F(WindowSessionTest3, GetSnapshotPixelMap, Function | SmallTest | Level2)1251 HWTEST_F(WindowSessionTest3, GetSnapshotPixelMap, Function | SmallTest | Level2)
1252 {
1253 session_->scenePersistence_ = nullptr;
1254 EXPECT_EQ(nullptr, session_->GetSnapshotPixelMap(6.6f, 8.8f));
1255 session_->scenePersistence_ = sptr<ScenePersistence>::MakeSptr("GetSnapshotPixelMap", 2024);
1256 EXPECT_NE(nullptr, session_->scenePersistence_);
1257 session_->scenePersistence_->isSavingSnapshot_.store(true);
1258 session_->snapshot_ = nullptr;
1259 EXPECT_EQ(nullptr, session_->GetSnapshotPixelMap(6.6f, 8.8f));
1260 }
1261
1262 /**
1263 * @tc.name: ResetDirtyFlags
1264 * @tc.desc: ResetDirtyFlags Test
1265 * @tc.type: FUNC
1266 */
HWTEST_F(WindowSessionTest3, ResetDirtyFlags, Function | SmallTest | Level2)1267 HWTEST_F(WindowSessionTest3, ResetDirtyFlags, Function | SmallTest | Level2)
1268 {
1269 session_->isVisible_ = false;
1270 session_->dirtyFlags_ = 64;
1271 session_->ResetDirtyFlags();
1272 EXPECT_EQ(64, session_->dirtyFlags_);
1273
1274 session_->isVisible_ = true;
1275 session_->dirtyFlags_ = 16;
1276 session_->ResetDirtyFlags();
1277 EXPECT_EQ(0, session_->dirtyFlags_);
1278 }
1279
1280 /**
1281 * @tc.name: SetMainSessionUIStateDirty
1282 * @tc.desc: SetMainSessionUIStateDirty Test
1283 * @tc.type: FUNC
1284 */
HWTEST_F(WindowSessionTest3, SetMainSessionUIStateDirty, Function | SmallTest | Level2)1285 HWTEST_F(WindowSessionTest3, SetMainSessionUIStateDirty, Function | SmallTest | Level2)
1286 {
1287 SessionInfo infoDirty;
1288 infoDirty.abilityName_ = "SetMainSessionUIStateDirty";
1289 infoDirty.moduleName_ = "SetMainSessionUIStateDirty";
1290 infoDirty.bundleName_ = "SetMainSessionUIStateDirty";
1291 infoDirty.windowType_ = static_cast<uint32_t>(WindowType::APP_MAIN_WINDOW_END);
1292 sptr<Session> sessionDirty = sptr<Session>::MakeSptr(infoDirty);
1293 EXPECT_NE(nullptr, sessionDirty);
1294
1295 session_->parentSession_ = nullptr;
1296 EXPECT_EQ(nullptr, session_->GetParentSession());
1297 sessionDirty->SetUIStateDirty(false);
1298 session_->SetMainSessionUIStateDirty(false);
1299 EXPECT_EQ(false, sessionDirty->GetUIStateDirty());
1300
1301 session_->SetParentSession(sessionDirty);
1302 EXPECT_EQ(sessionDirty, session_->GetParentSession());
1303 session_->SetMainSessionUIStateDirty(false);
1304 EXPECT_EQ(false, sessionDirty->GetUIStateDirty());
1305
1306 infoDirty.windowType_ = static_cast<uint32_t>(WindowType::APP_MAIN_WINDOW_BASE);
1307 sptr<Session> sessionUIState = sptr<Session>::MakeSptr(infoDirty);
1308 EXPECT_NE(nullptr, sessionUIState);
1309 session_->SetParentSession(sessionUIState);
1310 session_->SetMainSessionUIStateDirty(true);
1311 EXPECT_EQ(true, sessionUIState->GetUIStateDirty());
1312 }
1313
1314 /**
1315 * @tc.name: CompatibleFullScreenRecover
1316 * @tc.desc: CompatibleFullScreenRecover Test
1317 * @tc.type: FUNC
1318 */
HWTEST_F(WindowSessionTest3, CompatibleFullScreenRecover, Function | SmallTest | Level2)1319 HWTEST_F(WindowSessionTest3, CompatibleFullScreenRecover, Function | SmallTest | Level2)
1320 {
1321 ASSERT_NE(session_, nullptr);
1322 sptr<SessionStageMocker> mockSessionStage = sptr<SessionStageMocker>::MakeSptr();
1323 ASSERT_NE(nullptr, mockSessionStage);
1324 session_->sessionStage_ = mockSessionStage;
1325 session_->sessionInfo_.isSystem_ = true;
1326 auto result = session_->CompatibleFullScreenRecover();
1327 ASSERT_EQ(result, WSError::WS_ERROR_INVALID_SESSION);
1328
1329 session_->sessionInfo_.isSystem_ = false;
1330 session_->SetSessionState(SessionState::STATE_FOREGROUND);
1331 result = session_->CompatibleFullScreenRecover();
1332 ASSERT_EQ(result, WSError::WS_OK);
1333 }
1334
1335 /**
1336 * @tc.name: CompatibleFullScreenMinimize
1337 * @tc.desc: CompatibleFullScreenMinimize Test
1338 * @tc.type: FUNC
1339 */
HWTEST_F(WindowSessionTest3, CompatibleFullScreenMinimize, Function | SmallTest | Level2)1340 HWTEST_F(WindowSessionTest3, CompatibleFullScreenMinimize, Function | SmallTest | Level2)
1341 {
1342 ASSERT_NE(session_, nullptr);
1343 sptr<SessionStageMocker> mockSessionStage = sptr<SessionStageMocker>::MakeSptr();
1344 ASSERT_NE(nullptr, mockSessionStage);
1345 session_->sessionStage_ = mockSessionStage;
1346 session_->sessionInfo_.isSystem_ = true;
1347 auto result = session_->CompatibleFullScreenMinimize();
1348 ASSERT_EQ(result, WSError::WS_ERROR_INVALID_SESSION);
1349
1350 session_->sessionInfo_.isSystem_ = false;
1351 session_->SetSessionState(SessionState::STATE_FOREGROUND);
1352 result = session_->CompatibleFullScreenMinimize();
1353 ASSERT_EQ(result, WSError::WS_OK);
1354 }
1355
1356 /**
1357 * @tc.name: CompatibleFullScreenClose
1358 * @tc.desc: CompatibleFullScreenClose Test
1359 * @tc.type: FUNC
1360 */
HWTEST_F(WindowSessionTest3, CompatibleFullScreenClose, Function | SmallTest | Level2)1361 HWTEST_F(WindowSessionTest3, CompatibleFullScreenClose, Function | SmallTest | Level2)
1362 {
1363 ASSERT_NE(session_, nullptr);
1364 sptr<SessionStageMocker> mockSessionStage = sptr<SessionStageMocker>::MakeSptr();
1365 ASSERT_NE(nullptr, mockSessionStage);
1366 session_->sessionStage_ = mockSessionStage;
1367 session_->sessionInfo_.isSystem_ = true;
1368 auto result = session_->CompatibleFullScreenClose();
1369 ASSERT_EQ(result, WSError::WS_ERROR_INVALID_SESSION);
1370
1371 session_->sessionInfo_.isSystem_ = false;
1372 session_->SetSessionState(SessionState::STATE_FOREGROUND);
1373 result = session_->CompatibleFullScreenClose();
1374 ASSERT_EQ(result, WSError::WS_OK);
1375 }
1376 }
1377 } // namespace Rosen
1378 } // namespace OHOS
1379