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
18 #include "interfaces/include/ws_common.h"
19 #include "iremote_object_mocker.h"
20 #include "mock/mock_session_stage.h"
21 #include "mock/mock_window_event_channel.h"
22 #include "session_info.h"
23 #include "session_manager.h"
24 #include "session_manager/include/scene_session_manager.h"
25 #include "session/host/include/scene_session.h"
26 #include "session/host/include/main_session.h"
27 #include "window_manager_agent.h"
28 #include "zidl/window_manager_agent_interface.h"
29
30 using namespace testing;
31 using namespace testing::ext;
32
33 namespace OHOS {
34 namespace Rosen {
35
36 class SessionSpecificWindowTest : public testing::Test {
37 public:
38 static void SetUpTestCase();
39 static void TearDownTestCase();
40 void SetUp() override;
41 void TearDown() override;
42 sptr<SceneSessionManager> ssm_;
43
44 private:
45 sptr<Session> session_ = nullptr;
46 static constexpr uint32_t WAIT_SYNC_IN_NS = 500000;
47
48 sptr<SessionStageMocker> mockSessionStage_ = nullptr;
49 sptr<WindowEventChannelMocker> mockEventChannel_ = nullptr;
50 };
51
SetUpTestCase()52 void SessionSpecificWindowTest::SetUpTestCase()
53 {
54 }
55
TearDownTestCase()56 void SessionSpecificWindowTest::TearDownTestCase()
57 {
58 }
59
SetUp()60 void SessionSpecificWindowTest::SetUp()
61 {
62 SessionInfo info;
63 info.abilityName_ = "testSession1";
64 info.moduleName_ = "testSession2";
65 info.bundleName_ = "testSession3";
66 session_ = sptr<Session>::MakeSptr(info);
67 ssm_ = sptr<SceneSessionManager>::MakeSptr();
68
69 mockSessionStage_ = sptr<SessionStageMocker>::MakeSptr();
70 ASSERT_NE(mockSessionStage_, nullptr);
71
72 mockEventChannel_ = sptr<WindowEventChannelMocker>::MakeSptr(mockSessionStage_);
73 ASSERT_NE(mockEventChannel_, nullptr);
74 }
75
TearDown()76 void SessionSpecificWindowTest::TearDown()
77 {
78 session_ = nullptr;
79 usleep(WAIT_SYNC_IN_NS);
80 }
81
82 namespace {
83 /**
84 * @tc.name: BindDialogSessionTarget
85 * @tc.desc: normal function
86 * @tc.type: FUNC
87 */
88 HWTEST_F(SessionSpecificWindowTest, BindDialogSessionTarget, Function | SmallTest | Level2)
89 {
90 SessionInfo info;
91 info.abilityName_ = "BindDialogSessionTarget";
92 info.bundleName_ = "BindDialogSessionTarget";
93 sptr<Rosen::ISession> session_;
94 sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
95 sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
96 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
97 sceneSession->isActive_ = true;
98
99 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
100 property->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT);
101 property->keyboardLayoutParams_.gravity_ = WindowGravity::WINDOW_GRAVITY_BOTTOM;
102 sceneSession->SetSessionProperty(property);
103
104 sptr<SceneSession> sceneSession1 = nullptr;
105 WSError result = sceneSession->BindDialogSessionTarget(sceneSession1);
106 ASSERT_EQ(result, WSError::WS_ERROR_NULLPTR);
107
108 sptr<SceneSession> sceneSession2 = sceneSession;
109 result = sceneSession->BindDialogSessionTarget(sceneSession2);
110 ASSERT_EQ(result, WSError::WS_OK);
111 }
112
113
114 /**
115 * @tc.name: AddSubSession
116 * @tc.desc: AddSubSession Test
117 * @tc.type: FUNC
118 */
119 HWTEST_F(SessionSpecificWindowTest, AddSubSession, Function | SmallTest | Level2)
120 {
121 SessionInfo info;
122 info.abilityName_ = "NotifySessionException";
123 info.bundleName_ = "NotifySessionException";
124
125 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
126 sptr<SceneSession> subSession = nullptr;
127 bool res = session->AddSubSession(subSession);
128 ASSERT_EQ(res, false);
129
130 subSession = sptr<SceneSession>::MakeSptr(info, nullptr);
131 res = session->AddSubSession(subSession);
132 ASSERT_EQ(res, true);
133
134 res = session->AddSubSession(subSession);
135 ASSERT_EQ(res, false);
136 }
137
138 /**
139 * @tc.name: RemoveSubSession
140 * @tc.desc: RemoveSubSession Test
141 * @tc.type: FUNC
142 */
143 HWTEST_F(SessionSpecificWindowTest, RemoveSubSession, Function | SmallTest | Level2)
144 {
145 SessionInfo info;
146 info.abilityName_ = "NotifySessionException";
147 info.bundleName_ = "NotifySessionException";
148
149 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
150 bool res = session->RemoveSubSession(0);
151 ASSERT_EQ(res, false);
152
153 sptr<SceneSession> subSession = sptr<SceneSession>::MakeSptr(info, nullptr);
154 res = session->AddSubSession(subSession);
155 ASSERT_EQ(res, true);
156
157 res = session->RemoveSubSession(subSession->GetPersistentId());
158 ASSERT_EQ(res, true);
159 }
160
161 /**
162 * @tc.name: ClearSpecificSessionCbMap
163 * @tc.desc: ClearSpecificSessionCbMap
164 * @tc.type: FUNC
165 */
166 HWTEST_F(SessionSpecificWindowTest, ClearSpecificSessionCbMap, Function | SmallTest | Level2)
167 {
168 SessionInfo info;
169 info.abilityName_ = "ClearSpecificSessionCbMap";
170 info.bundleName_ = "ClearSpecificSessionCbMap";
171 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
172 auto result = false;
__anon44b6b6f90202(bool needRemove) 173 sceneSession->clearCallbackMapFunc_ = [&result](bool needRemove) {
174 result = needRemove;
175 };
176 sceneSession->ClearSpecificSessionCbMap();
177 usleep(WAIT_SYNC_IN_NS);
178 ASSERT_EQ(result, true);
179 }
180
181 /**
182 * @tc.name: ClearSpecificSessionCbMap
183 * @tc.desc: ClearSpecificSessionCbMap
184 * @tc.type: FUNC
185 */
186 HWTEST_F(SessionSpecificWindowTest, ClearSpecificSessionCbMap01, Function | SmallTest | Level2)
187 {
188 SessionInfo info;
189 info.abilityName_ = "ClearSpecificSessionCbMap01";
190 info.bundleName_ = "ClearSpecificSessionCbMap01";
191 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
192 sptr<Session> session = sptr<Session>::MakeSptr(info);
193 auto result = false;
194 sceneSession->clearCallbackMapFunc_ = nullptr;
195 sceneSession->ClearSpecificSessionCbMap();
196 usleep(WAIT_SYNC_IN_NS);
197 ASSERT_EQ(result, false);
198 ASSERT_NE(sceneSession, nullptr);
199 }
200
201 /**
202 * @tc.name: ClearSpecificSessionCbMap
203 * @tc.desc: ClearSpecificSessionCbMap
204 * @tc.type: FUNC
205 */
206 HWTEST_F(SessionSpecificWindowTest, SpecificCallback01, Function | SmallTest | Level2)
207 {
208 SessionInfo info;
209 info.abilityName_ = "ClearSpecificSessionCbMap01";
210 info.bundleName_ = "ClearSpecificSessionCbMap01";
211 info.windowType_ = static_cast<uint32_t>(WindowType::WINDOW_TYPE_FLOAT);
212 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
213
214 bool isFromClient = true;
215 sceneSession->needSnapshot_ = true;
216 sceneSession->SetSessionState(SessionState::STATE_FOREGROUND);
217 bool result = false;
218 auto specificCallback = sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
__anon44b6b6f90302(const sptr<SceneSession>& sceneSession) 219 specificCallback->onHandleSecureSessionShouldHide_ = [&result](const sptr<SceneSession>& sceneSession) {
220 result = sceneSession->needSnapshot_;
221 return WSError::WS_OK;
222 };
223 sceneSession->specificCallback_ = specificCallback;
224 sceneSession->Disconnect(isFromClient);
225 usleep(WAIT_SYNC_IN_NS);
226 ASSERT_EQ(result, false);
227 ASSERT_EQ(SessionState::STATE_DISCONNECT, sceneSession->state_);
228 }
229
230 /**
231 * @tc.name: ClearSpecificSessionCbMap
232 * @tc.desc: ClearSpecificSessionCbMap
233 * @tc.type: FUNC
234 */
235 HWTEST_F(SessionSpecificWindowTest, SpecificCallback02, Function | SmallTest | Level2)
236 {
237 SessionInfo info;
238 info.abilityName_ = "ClearSpecificSessionCbMap01";
239 info.bundleName_ = "ClearSpecificSessionCbMap01";
240 info.windowType_ = static_cast<uint32_t>(WindowType::WINDOW_TYPE_FLOAT);
241 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
242
243 bool isFromClient = false;
244 sceneSession->needSnapshot_ = true;
245 sceneSession->SetSessionState(SessionState::STATE_FOREGROUND);
246 bool result = false;
247 auto specificCallback = sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
__anon44b6b6f90402(const sptr<SceneSession>& sceneSession) 248 specificCallback->onHandleSecureSessionShouldHide_ = [&result](const sptr<SceneSession>& sceneSession) {
249 result = sceneSession->needSnapshot_;
250 return WSError::WS_OK;
251 };
252 sceneSession->specificCallback_ = specificCallback;
253 sceneSession->Disconnect(isFromClient);
254 usleep(WAIT_SYNC_IN_NS);
255 ASSERT_EQ(result, true);
256 ASSERT_EQ(SessionState::STATE_DISCONNECT, sceneSession->state_);
257 }
258
259 /**
260 * @tc.name: GetKeyboardAvoidArea
261 * @tc.desc: GetKeyboardAvoidArea01
262 * @tc.type: FUNC
263 */
264 HWTEST_F(SessionSpecificWindowTest, GetKeyboardAvoidArea01, Function | SmallTest | Level2)
265 {
266 SessionInfo info;
267 info.abilityName_ = "GetKeyboardAvoidArea";
268 info.bundleName_ = "GetKeyboardAvoidArea";
269
270 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
271 WSRect rect{ 100, 100, 100, 100 };
272 AvoidArea avoidArea;
273 GTEST_LOG_(INFO) << "1";
274 sceneSession->GetKeyboardAvoidArea(rect, avoidArea);
275 Rect result{ 0, 0, 0, 0 };
276 ASSERT_EQ(avoidArea.topRect_, result);
277 }
278
279 /**
280 * @tc.name: IsSystemSpecificSession
281 * @tc.desc: IsSystemSpecificSession
282 * @tc.type: FUNC
283 */
284 HWTEST_F(SessionSpecificWindowTest, IsSystemSpecificSession, Function | SmallTest | Level2)
285 {
286 SessionInfo info;
287 info.abilityName_ = "IsSystemSpecificSession";
288 info.bundleName_ = "IsSystemSpecificSession";
289
290 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
291 ASSERT_FALSE(sceneSession->IsSystemSpecificSession());
292 sceneSession->SetIsSystemSpecificSession(true);
293 ASSERT_TRUE(sceneSession->IsSystemSpecificSession());
294 }
295
296 /**
297 * @tc.name: SetAndIsSystemKeyboard
298 * @tc.desc: test SetIsSystemKeyboard and IsSystemKeyboard func
299 * @tc.type: FUNC
300 */
301 HWTEST_F(SessionSpecificWindowTest, SetAndIsSystemKeyboard, Function | SmallTest | Level2)
302 {
303 SessionInfo info;
304 info.abilityName_ = "SetAndIsSystemKeyboard";
305 info.bundleName_ = "SetAndIsSystemKeyboard";
306 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
307
308 ASSERT_EQ(false, session->IsSystemKeyboard());
309 session->SetIsSystemKeyboard(true);
310 ASSERT_EQ(true, session->IsSystemKeyboard());
311 }
312
313 /**
314 * @tc.name: CheckDialogOnForeground
315 * @tc.desc: check func CheckDialogOnForeground
316 * @tc.type: FUNC
317 */
318 HWTEST_F(SessionSpecificWindowTest, CheckDialogOnForeground, Function | SmallTest | Level2)
319 {
320 ASSERT_NE(session_, nullptr);
321 session_->dialogVec_.clear();
322 ASSERT_EQ(false, session_->CheckDialogOnForeground());
323 SessionInfo info;
324 info.abilityName_ = "dialogAbilityName";
325 info.moduleName_ = "dialogModuleName";
326 info.bundleName_ = "dialogBundleName";
327 sptr<Session> dialogSession = sptr<Session>::MakeSptr(info);
328 dialogSession->state_ = SessionState::STATE_INACTIVE;
329 session_->dialogVec_.push_back(dialogSession);
330 ASSERT_EQ(false, session_->CheckDialogOnForeground());
331 session_->dialogVec_.clear();
332 }
333
334 /**
335 * @tc.name: IsTopDialog
336 * @tc.desc: check func IsTopDialog
337 * @tc.type: FUNC
338 */
339 HWTEST_F(SessionSpecificWindowTest, IsTopDialog, Function | SmallTest | Level2)
340 {
341 ASSERT_NE(session_, nullptr);
342 session_->dialogVec_.clear();
343 SessionInfo info;
344 info.abilityName_ = "testSession1";
345 info.moduleName_ = "testSession2";
346 info.bundleName_ = "testSession3";
347
348 sptr<Session> dialogSession1 = sptr<Session>::MakeSptr(info);
349 dialogSession1->persistentId_ = 33;
350 dialogSession1->SetParentSession(session_);
351 dialogSession1->state_ = SessionState::STATE_ACTIVE;
352 session_->dialogVec_.push_back(dialogSession1);
353
354 sptr<Session> dialogSession2 = sptr<Session>::MakeSptr(info);
355 dialogSession2->persistentId_ = 34;
356 dialogSession2->SetParentSession(session_);
357 dialogSession2->state_ = SessionState::STATE_ACTIVE;
358 session_->dialogVec_.push_back(dialogSession2);
359
360 sptr<Session> dialogSession3 = sptr<Session>::MakeSptr(info);
361 dialogSession3->persistentId_ = 35;
362 dialogSession3->SetParentSession(session_);
363 dialogSession3->state_ = SessionState::STATE_INACTIVE;
364 session_->dialogVec_.push_back(dialogSession3);
365
366 ASSERT_EQ(false, dialogSession3->IsTopDialog());
367 ASSERT_EQ(true, dialogSession2->IsTopDialog());
368 ASSERT_EQ(false, dialogSession1->IsTopDialog());
369 session_->dialogVec_.clear();
370 }
371
372 /**
373 * @tc.name: IsTopDialog02
374 * @tc.desc: IsTopDialog Test
375 * @tc.type: FUNC
376 */
377 HWTEST_F(SessionSpecificWindowTest, IsTopDialog02, Function | SmallTest | Level2)
378 {
379 ASSERT_NE(session_, nullptr);
380 session_->SetParentSession(nullptr);
381 EXPECT_EQ(false, session_->IsTopDialog());
382
383 SessionInfo info;
384 info.abilityName_ = "testSession1";
385 info.moduleName_ = "testSession2";
386 info.bundleName_ = "testSession3";
387 sptr<Session> parentSession = sptr<Session>::MakeSptr(info);
388 parentSession->dialogVec_.clear();
389 session_->SetParentSession(parentSession);
390 auto result = session_->IsTopDialog();
391 EXPECT_EQ(result, true);
392 }
393
394 /**
395 * @tc.name: IsTopDialog03
396 * @tc.desc: IsTopDialog Test
397 * @tc.type: FUNC
398 */
399 HWTEST_F(SessionSpecificWindowTest, IsTopDialog03, Function | SmallTest | Level2)
400 {
401 ASSERT_NE(session_, nullptr);
402 session_->dialogVec_.clear();
403 SessionInfo info;
404 info.abilityName_ = "testSession1";
405 info.moduleName_ = "testSession2";
406 info.bundleName_ = "testSession3";
407 sptr<Session> dialogSession1 = sptr<Session>::MakeSptr(info);
408 sptr<Session> dialogSession2 = sptr<Session>::MakeSptr(info);
409 dialogSession1->SetParentSession(session_);
410 dialogSession2->SetParentSession(session_);
411 session_->dialogVec_.push_back(dialogSession1);
412 session_->dialogVec_.push_back(dialogSession2);
413 dialogSession1->SetSessionState(SessionState::STATE_INACTIVE);
414 dialogSession2->SetSessionState(SessionState::STATE_INACTIVE);
415 EXPECT_EQ(false, dialogSession1->IsTopDialog());
416 }
417
418 /**
419 * @tc.name: BindDialogToParentSession
420 * @tc.desc: BindDialogToParentSession Test
421 * @tc.type: FUNC
422 */
423 HWTEST_F(SessionSpecificWindowTest, BindDialogToParentSession, Function | SmallTest | Level2)
424 {
425 ASSERT_NE(session_, nullptr);
426 SessionInfo info;
427 info.abilityName_ = "testSession1";
428 info.moduleName_ = "testSession2";
429 info.bundleName_ = "testSession3";
430 sptr<Session> session = sptr<Session>::MakeSptr(info);
431 session_->BindDialogToParentSession(session);
432
433 sptr<Session> session1 = sptr<Session>::MakeSptr(info);
434 session1->persistentId_ = 33;
435 session1->SetParentSession(session_);
436 session1->state_ = SessionState::STATE_ACTIVE;
437 session_->dialogVec_.push_back(session1);
438
439 sptr<Session> session2 = sptr<Session>::MakeSptr(info);
440 session2->persistentId_ = 34;
441 session2->SetParentSession(session_);
442 session2->state_ = SessionState::STATE_ACTIVE;
443 session_->dialogVec_.push_back(session2);
444 session_->BindDialogToParentSession(session1);
445
446 ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(false));
447 }
448
449 /**
450 * @tc.name: HandlePointDownDialog
451 * @tc.desc: HandlePointDownDialog Test
452 * @tc.type: FUNC
453 */
454 HWTEST_F(SessionSpecificWindowTest, HandlePointDownDialog, Function | SmallTest | Level2)
455 {
456 ASSERT_NE(session_, nullptr);
457 SessionInfo info;
458 info.abilityName_ = "testSession1";
459 info.moduleName_ = "testSession2";
460 info.bundleName_ = "testSession3";
461 sptr<Session> dialogSession1 = sptr<Session>::MakeSptr(info);
462 sptr<Session> dialogSession2 = sptr<Session>::MakeSptr(info);
463 sptr<Session> dialogSession3 = sptr<Session>::MakeSptr(info);
464 sptr<Session> dialogSession4 = nullptr;
465 dialogSession1->SetSessionState(SessionState::STATE_FOREGROUND);
466 dialogSession2->SetSessionState(SessionState::STATE_ACTIVE);
467 dialogSession2->SetSessionState(SessionState::STATE_INACTIVE);
468 session_->dialogVec_.push_back(dialogSession1);
469 session_->dialogVec_.push_back(dialogSession2);
470 session_->dialogVec_.push_back(dialogSession3);
471 session_->dialogVec_.push_back(dialogSession4);
472 session_->HandlePointDownDialog();
473 session_->SetPendingSessionToBackgroundForDelegatorListener(nullptr);
474 EXPECT_EQ(WSError::WS_OK, session_->PendingSessionToBackgroundForDelegator(true));
475 }
476
477 /**
478 * @tc.name: RemoveDialogToParentSession
479 * @tc.desc: RemoveDialogToParentSession Test
480 * @tc.type: FUNC
481 */
482 HWTEST_F(SessionSpecificWindowTest, RemoveDialogToParentSession, Function | SmallTest | Level2)
483 {
484 ASSERT_NE(session_, nullptr);
485 SessionInfo info;
486 info.abilityName_ = "testSession1";
487 info.moduleName_ = "testSession2";
488 info.bundleName_ = "testSession3";
489 sptr<Session> session = sptr<Session>::MakeSptr(info);
490 session_->RemoveDialogToParentSession(session);
491
492 sptr<Session> session1 = sptr<Session>::MakeSptr(info);
493 session1->persistentId_ = 33;
494 session1->SetParentSession(session_);
495 session1->state_ = SessionState::STATE_ACTIVE;
496 session_->dialogVec_.push_back(session1);
497
498 sptr<Session> session2 = sptr<Session>::MakeSptr(info);
499 session2->persistentId_ = 34;
500 session2->SetParentSession(session_);
501 session2->state_ = SessionState::STATE_ACTIVE;
502 session_->dialogVec_.push_back(session2);
503 session_->RemoveDialogToParentSession(session1);
504
505 ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(false));
506 }
507
508 /**
509 * @tc.name: IsSystemSession
510 * @tc.desc: IsSystemSession
511 * @tc.type: FUNC
512 */
513 HWTEST_F(SessionSpecificWindowTest, IsSystemSession, Function | SmallTest | Level2)
514 {
515 ASSERT_NE(session_, nullptr);
516 bool res = session_->IsSystemSession();
517 ASSERT_EQ(res, false);
518 }
519
520 /**
521 * @tc.name: HandleDialogBackground
522 * @tc.desc: HandleDialogBackground Test
523 * @tc.type: FUNC
524 */
525 HWTEST_F(SessionSpecificWindowTest, HandleDialogBackground, Function | SmallTest | Level2)
526 {
527 ASSERT_NE(session_, nullptr);
528 session_->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_END);
529 session_->HandleDialogBackground();
530
531 session_->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
532 sptr<Session> session01 = nullptr;
533
534 SessionInfo info;
535 info.abilityName_ = "testSession1";
536 info.moduleName_ = "testSession2";
537 info.bundleName_ = "testSession3";
538 sptr<Session> session02 = sptr<Session>::MakeSptr(info);
539 sptr<Session> session03 = sptr<Session>::MakeSptr(info);
540
541 sptr<SessionStageMocker> mockSessionStage = sptr<SessionStageMocker>::MakeSptr();
542 EXPECT_NE(nullptr, mockSessionStage);
543 session02->sessionStage_ = mockSessionStage;
544 session03->sessionStage_ = nullptr;
545
546 session_->dialogVec_.push_back(session01);
547 session_->dialogVec_.push_back(session02);
548 session_->dialogVec_.push_back(session03);
549 session_->HandleDialogBackground();
550 session_->SetPendingSessionToBackgroundForDelegatorListener(nullptr);
551 EXPECT_EQ(WSError::WS_OK, session_->PendingSessionToBackgroundForDelegator(true));
552 }
553
554 /**
555 * @tc.name: HandleDialogForeground
556 * @tc.desc: HandleDialogForeground Test
557 * @tc.type: FUNC
558 */
559 HWTEST_F(SessionSpecificWindowTest, HandleDialogForeground, Function | SmallTest | Level2)
560 {
561 ASSERT_NE(session_, nullptr);
562 session_->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_END);
563 session_->HandleDialogForeground();
564
565 session_->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
566 sptr<Session> session01 = nullptr;
567
568 SessionInfo info;
569 info.abilityName_ = "testSession1";
570 info.moduleName_ = "testSession2";
571 info.bundleName_ = "testSession3";
572 sptr<Session> session02 = sptr<Session>::MakeSptr(info);
573 sptr<Session> session03 = sptr<Session>::MakeSptr(info);
574
575 sptr<SessionStageMocker> mockSessionStage = sptr<SessionStageMocker>::MakeSptr();
576 EXPECT_NE(nullptr, mockSessionStage);
577 session02->sessionStage_ = mockSessionStage;
578 session03->sessionStage_ = nullptr;
579
580 session_->dialogVec_.push_back(session01);
581 session_->dialogVec_.push_back(session02);
582 session_->dialogVec_.push_back(session03);
583 session_->HandleDialogForeground();
584 session_->SetPendingSessionToBackgroundForDelegatorListener(nullptr);
585 EXPECT_EQ(WSError::WS_OK, session_->PendingSessionToBackgroundForDelegator(true));
586 }
587
588 /**
589 * @tc.name: HandleSubWindowClick01
590 * @tc.desc: parentSession and property is nullptr
591 * @tc.type: FUNC
592 */
593 HWTEST_F(SessionSpecificWindowTest, HandleSubWindowClick01, Function | SmallTest | Level2)
594 {
595 ASSERT_NE(session_, nullptr);
596 auto result = session_->HandleSubWindowClick(MMI::PointerEvent::POINTER_ACTION_DOWN);
597 EXPECT_EQ(result, WSError::WS_OK);
598 }
599
600 /**
601 * @tc.name: HandleSubWindowClick03
602 * @tc.desc: parentSession->dialogVec_ is nullptr
603 * @tc.type: FUNC
604 */
605 HWTEST_F(SessionSpecificWindowTest, HandleSubWindowClick03, Function | SmallTest | Level2)
606 {
607 ASSERT_NE(session_, nullptr);
608 SessionInfo info;
609 info.abilityName_ = "testSession1";
610 info.moduleName_ = "testSession2";
611 info.bundleName_ = "testSession3";
612 sptr<Session> dialogSession = sptr<Session>::MakeSptr(info);
613 session_->SetParentSession(dialogSession);
614
615 auto result = session_->HandleSubWindowClick(MMI::PointerEvent::POINTER_ACTION_DOWN);
616 EXPECT_EQ(result, WSError::WS_OK);
617
618 result = session_->HandleSubWindowClick(MMI::PointerEvent::POINTER_ACTION_MOVE);
619 EXPECT_EQ(result, WSError::WS_OK);
620 }
621
622 /**
623 * @tc.name: HandleSubWindowClick03
624 * @tc.desc: isExecuteDelayRaise is true
625 * @tc.type: FUNC
626 */
627 HWTEST_F(SessionSpecificWindowTest, HandleSubWindowClick04, Function | SmallTest | Level2)
628 {
629 ASSERT_NE(session_, nullptr);
630 SessionInfo info;
631 info.abilityName_ = "testSession1";
632 info.moduleName_ = "testSession2";
633 info.bundleName_ = "testSession3";
634 sptr<Session> dialogSession = sptr<Session>::MakeSptr(info);
635 session_->SetParentSession(dialogSession);
636
637 bool isExecuteDelayRaise = false;
638 auto result = session_->HandleSubWindowClick(MMI::PointerEvent::POINTER_ACTION_BUTTON_DOWN, isExecuteDelayRaise);
639 EXPECT_EQ(result, WSError::WS_OK);
640 }
641 }
642 } // namespace Rosen
643 } // namespace OHOS
644