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 "window_helper.h"
17 #include "display_manager.h"
18 #include "pointer_event.h"
19 #include "proxy/include/window_info.h"
20
21 #include <gtest/gtest.h>
22 #include "key_event.h"
23 #include "session/host/include/scene_session.h"
24 #include "session/host/include/sub_session.h"
25 #include "session/host/include/system_session.h"
26 #include "session/host/include/main_session.h"
27 #include "wm_common.h"
28 #include "mock/mock_session_stage.h"
29 #include "input_event.h"
30 #include <pointer_event.h>
31 #include "ui/rs_surface_node.h"
32
33 using namespace testing;
34 using namespace testing::ext;
35 namespace OHOS {
36 namespace Rosen {
37 class SceneSessionTest2 : public testing::Test {
38 public:
39 static void SetUpTestCase();
40 static void TearDownTestCase();
41 void SetUp() override;
42 void TearDown() override;
43 };
44
SetUpTestCase()45 void SceneSessionTest2::SetUpTestCase() {}
46
TearDownTestCase()47 void SceneSessionTest2::TearDownTestCase() {}
48
SetUp()49 void SceneSessionTest2::SetUp() {}
50
TearDown()51 void SceneSessionTest2::TearDown() {}
52
53 namespace {
54 /**
55 * @tc.name: RaiseAboveTarget
56 * @tc.desc: normal function
57 * @tc.type: FUNC
58 */
59 HWTEST_F(SceneSessionTest2, RaiseAboveTarget, TestSize.Level1)
60 {
61 SessionInfo info;
62 info.abilityName_ = "RaiseAboveTarget";
63 info.bundleName_ = "RaiseAboveTarget";
64 sptr<Rosen::ISession> session_;
65 sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
66 sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
67 EXPECT_NE(specificCallback_, nullptr);
68 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
69 EXPECT_NE(sceneSession, nullptr);
70 sceneSession->isActive_ = true;
71
72 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
73 property->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT);
74 property->keyboardLayoutParams_.gravity_ = WindowGravity::WINDOW_GRAVITY_BOTTOM;
75
76 sceneSession->SetSessionProperty(property);
77 WSError result = sceneSession->RaiseAboveTarget(0);
78 ASSERT_EQ(result, WSError::WS_OK);
79
80 sptr<SceneSession> tempSession = sptr<SceneSession>::MakeSptr(info, nullptr);
81 int32_t persistentId = 1;
82 tempSession->persistentId_ = persistentId;
83 int32_t callingPid = 2;
84 tempSession->callingPid_ = callingPid;
85 sceneSession->subSession_.push_back(tempSession);
86 int32_t subWindowId = 1;
87 result = sceneSession->RaiseAboveTarget(subWindowId);
88 ASSERT_EQ(result, WSError::WS_ERROR_INVALID_CALLING);
89
90 sceneSession->onRaiseAboveTarget_ = nullptr;
91 result = sceneSession->RaiseAboveTarget(0);
92 ASSERT_EQ(result, WSError::WS_OK);
93 }
94
95 /**
96 * @tc.name: RaiseMainWindowAboveTarget
97 * @tc.desc: normal function
98 * @tc.type: FUNC
99 */
100 HWTEST_F(SceneSessionTest2, RaiseMainWindowAboveTarget, TestSize.Level1)
101 {
102 SessionInfo info;
103 info.abilityName_ = "RaiseMainWindowAboveTarget";
104 info.bundleName_ = "RaiseMainWindowAboveTarget";
105 sptr<Rosen::ISession> session_;
106 sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
107 sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
108 EXPECT_NE(specificCallback_, nullptr);
109
110 sptr<SceneSession> sourceSession = sptr<SceneSession>::MakeSptr(info, nullptr);
111 EXPECT_NE(sourceSession, nullptr);
112
113 sourceSession->isActive_ = true;
114 sourceSession->callingPid_ = 1;
115 sourceSession->zOrder_ = 2001;
116 sptr<WindowSessionProperty> property1 = sptr<WindowSessionProperty>::MakeSptr();
117 property1->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
118 property1->SetDisplayId(0);
119 sourceSession->SetSessionProperty(property1);
120
121 auto result = sourceSession->RaiseMainWindowAboveTarget(0);
122 EXPECT_EQ(result, WSError::WS_ERROR_NULLPTR);
123
124 sptr<SceneSession> targetSession = sptr<SceneSession>::MakeSptr(info, nullptr);
125 EXPECT_NE(targetSession, nullptr);
126
127 targetSession->isActive_ = true;
128 targetSession->callingPid_ = 2;
129 targetSession->zOrder_ = 102;
130 sptr<WindowSessionProperty> property2 = sptr<WindowSessionProperty>::MakeSptr();
131 property2->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
132 property2->SetDisplayId(1);
133 targetSession->SetSessionProperty(property2);
134
135 sptr<SceneSession::SpecificSessionCallback> callBack =
136 sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
137 EXPECT_NE(nullptr, callBack);
138 sourceSession->specificCallback_ = callBack;
__anonbd5ae67e0202(int32_t persistentId) 139 auto task = [&targetSession](int32_t persistentId) { return targetSession; };
140 callBack->onGetSceneSessionByIdCallback_ = task;
141 result = sourceSession->RaiseMainWindowAboveTarget(0);
142 EXPECT_EQ(result, WSError::WS_ERROR_INVALID_CALLING);
143
144 targetSession->callingPid_ = 1;
145 result = sourceSession->RaiseMainWindowAboveTarget(0);
146 EXPECT_EQ(result, WSError::WS_ERROR_INVALID_CALLING);
147
148 property2->SetDisplayId(0);
149 targetSession->SetSessionProperty(property2);
150 result = sourceSession->RaiseMainWindowAboveTarget(0);
151 EXPECT_EQ(result, WSError::WS_ERROR_INVALID_CALLING);
152 }
153
154 /**
155 * @tc.name: NotifyPropertyWhenConnect1
156 * @tc.desc: NotifyPropertyWhenConnect1
157 * @tc.type: FUNC
158 */
159 HWTEST_F(SceneSessionTest2, NotifyPropertyWhenConnect1, TestSize.Level1)
160 {
161 SessionInfo info;
162 info.abilityName_ = "ability";
163 info.bundleName_ = "bundle";
164 info.moduleName_ = "module";
165 info.windowType_ = 1;
166 sptr<Rosen::ISession> session_;
167 sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
168 sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
169 EXPECT_NE(specificCallback_, nullptr);
170 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
171 EXPECT_NE(sceneSession, nullptr);
172 int ret = 1;
173 std::string key = info.bundleName_ + info.moduleName_ + info.abilityName_;
174 sceneSession = sptr<SceneSession>::MakeSptr(info, specificCallback_);
175 sceneSession->NotifyPropertyWhenConnect();
176
177 sptr<WindowSessionProperty> property = nullptr;
178 sceneSession->NotifyPropertyWhenConnect();
179 ASSERT_EQ(ret, 1);
180 }
181
182 /**
183 * @tc.name: GetSystemAvoidArea
184 * @tc.desc: normal function
185 * @tc.type: FUNC
186 */
187 HWTEST_F(SceneSessionTest2, GetSystemAvoidArea, TestSize.Level1)
188 {
189 SessionInfo info;
190 info.abilityName_ = "GetSystemAvoidArea";
191 info.bundleName_ = "GetSystemAvoidArea";
192 sptr<Rosen::ISession> session_;
193 sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
194 sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
195 EXPECT_NE(specificCallback_, nullptr);
196 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
197 EXPECT_NE(sceneSession, nullptr);
198 sceneSession->isActive_ = true;
199
200 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
201 property->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT);
202 int32_t p = 10;
203 property->SetWindowFlags(static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_NEED_AVOID));
204
205 sceneSession->SetSessionProperty(property);
206 WSRect rect({ 1, 1, 1, 1 });
207 AvoidArea avoidArea;
208 sceneSession->GetSystemAvoidArea(rect, avoidArea);
209 ASSERT_EQ(p, 10);
210 }
211
212 /**
213 * @tc.name: TransferPointerEvent
214 * @tc.desc: TransferPointerEvent
215 * @tc.type: FUNC
216 */
217 HWTEST_F(SceneSessionTest2, TransferPointerEvent01, TestSize.Level1)
218 {
219 SessionInfo info;
220 info.abilityName_ = "Background01";
221 info.bundleName_ = "IsFloatingWindowAppType";
222 info.windowType_ = 1;
223 sptr<Rosen::ISession> session_;
224 sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
225 sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
226 EXPECT_NE(specificCallback_, nullptr);
227 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, specificCallback_);
228 EXPECT_NE(sceneSession, nullptr);
229 std::shared_ptr<MMI::PointerEvent> pointerEvent = nullptr;
230 ASSERT_EQ(sceneSession->TransferPointerEvent(pointerEvent), WSError::WS_OK);
231
232 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
233 property->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
234 property->SetMaximizeMode(MaximizeMode::MODE_FULL_FILL);
235 property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
236 property->SetPersistentId(11);
237 sceneSession->property_ = property;
238
239 std::shared_ptr<MMI::PointerEvent> pointerEvent_ = MMI::PointerEvent::Create();
240 pointerEvent_->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_ENTER_WINDOW);
241 ASSERT_EQ(sceneSession->TransferPointerEvent(pointerEvent_), WSError::WS_OK);
242
243 sceneSession->sessionInfo_.isSystem_ = true;
244 pointerEvent_->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_BUTTON_DOWN);
245 ASSERT_EQ(sceneSession->TransferPointerEvent(pointerEvent_), WSError::WS_OK);
246
247 pointerEvent_->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_ENTER_WINDOW);
248 ASSERT_EQ(sceneSession->TransferPointerEvent(pointerEvent_), WSError::WS_OK);
249
250 sceneSession->sessionInfo_.isSystem_ = false;
251 pointerEvent_->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_BUTTON_DOWN);
252 ASSERT_EQ(sceneSession->TransferPointerEvent(pointerEvent_), WSError::WS_OK);
253
254 pointerEvent_->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_ENTER_WINDOW);
255 ASSERT_EQ(sceneSession->TransferPointerEvent(pointerEvent_), WSError::WS_OK);
256 }
257
258 /**
259 * @tc.name: TransferPointerEvent
260 * @tc.desc: TransferPointerEvent
261 * @tc.type: FUNC
262 */
263 HWTEST_F(SceneSessionTest2, TransferPointerEvent02, TestSize.Level1)
264 {
265 SessionInfo info;
266 info.abilityName_ = "Background01";
267 info.bundleName_ = "IsSubWindowAppType";
268 info.windowType_ = 1;
269 sptr<Rosen::ISession> session_;
270 sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
271 sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
272 EXPECT_NE(specificCallback_, nullptr);
273 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, specificCallback_);
274 EXPECT_NE(sceneSession, nullptr);
275 std::shared_ptr<MMI::PointerEvent> pointerEvent = nullptr;
276 ASSERT_EQ(sceneSession->TransferPointerEvent(pointerEvent), WSError::WS_OK);
277
278 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
279 property->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
280 property->SetMaximizeMode(MaximizeMode::MODE_FULL_FILL);
281 property->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
282 property->SetPersistentId(11);
283 sceneSession->property_ = property;
284
285 std::shared_ptr<MMI::PointerEvent> pointerEvent_ = MMI::PointerEvent::Create();
286 pointerEvent_->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_DOWN);
287 ASSERT_EQ(sceneSession->TransferPointerEvent(pointerEvent_), WSError::WS_OK);
288 }
289
290 /**
291 * @tc.name: RequestSessionBack
292 * @tc.desc: normal function
293 * @tc.type: FUNC
294 */
295 HWTEST_F(SceneSessionTest2, RequestSessionBack, TestSize.Level1)
296 {
297 SessionInfo info;
298 info.abilityName_ = "RequestSessionBack";
299 info.bundleName_ = "RequestSessionBack";
300 sptr<Rosen::ISession> session_;
301 sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
302 sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
303 EXPECT_NE(specificCallback_, nullptr);
304 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
305 EXPECT_NE(sceneSession, nullptr);
306 sceneSession->isActive_ = true;
307
308 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
309 property->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT);
310 property->keyboardLayoutParams_.gravity_ = WindowGravity::WINDOW_GRAVITY_BOTTOM;
311 sceneSession->SetSessionProperty(property);
312
313 WSError result = sceneSession->RequestSessionBack(true);
314 ASSERT_EQ(result, WSError::WS_OK);
315
316 struct RSSurfaceNodeConfig config;
317 std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Create(config);
318 EXPECT_NE(nullptr, surfaceNode);
319 sceneSession->SetLeashWinSurfaceNode(surfaceNode);
320 result = sceneSession->RequestSessionBack(true);
321 ASSERT_EQ(result, WSError::WS_OK);
322 }
323
324 /**
325 * @tc.name: SetParentPersistentId
326 * @tc.desc: normal function
327 * @tc.type: FUNC
328 */
329 HWTEST_F(SceneSessionTest2, SetParentPersistentId, TestSize.Level1)
330 {
331 SessionInfo info;
332 info.abilityName_ = "SetParentPersistentId";
333 info.bundleName_ = "SetParentPersistentId";
334 sptr<Rosen::ISession> session_;
335 sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
336 sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
337 EXPECT_NE(specificCallback_, nullptr);
338 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
339 EXPECT_NE(sceneSession, nullptr);
340 sceneSession->isActive_ = true;
341
342 sceneSession->SetParentPersistentId(0);
343 int32_t result = sceneSession->GetParentPersistentId();
344 ASSERT_EQ(result, 0);
345
346 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
347 property->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT);
348
349 sceneSession->SetSessionProperty(property);
350 sceneSession->SetParentPersistentId(0);
351 result = sceneSession->GetParentPersistentId();
352 ASSERT_EQ(result, 0);
353 }
354
355 /**
356 * @tc.name: GetMainSessionId
357 * @tc.desc: GetMainSessionId Test
358 * @tc.type: FUNC
359 */
360 HWTEST_F(SceneSessionTest2, GetMainSessionId, TestSize.Level1)
361 {
362 SessionInfo info;
363 info.abilityName_ = "GetMainSessionId";
364 info.moduleName_ = "GetMainSessionId";
365 info.bundleName_ = "GetMainSessionId";
366
367 sptr<Session> session = sptr<Session>::MakeSptr(info);
368 EXPECT_NE(session, nullptr);
369 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
370 EXPECT_NE(property, nullptr);
371 property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
372 property->SetPersistentId(0);
373 session->SetSessionProperty(property);
374
375 sptr<Session> subSession = sptr<Session>::MakeSptr(info);
376 EXPECT_NE(subSession, nullptr);
377 subSession->SetParentSession(session);
378 sptr<WindowSessionProperty> subProperty = sptr<WindowSessionProperty>::MakeSptr();
379 EXPECT_NE(subProperty, nullptr);
380 subProperty->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
381 subProperty->SetPersistentId(1);
382 subSession->SetSessionProperty(subProperty);
383
384 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
385 EXPECT_NE(sceneSession, nullptr);
386 sceneSession->SetParentSession(subSession);
387 sptr<WindowSessionProperty> sceneProperty = sptr<WindowSessionProperty>::MakeSptr();
388 EXPECT_NE(sceneProperty, nullptr);
389 sceneProperty->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
390 sceneProperty->SetPersistentId(2);
391 sceneSession->SetSessionProperty(sceneProperty);
392 auto result = sceneSession->GetMainSessionId();
393 ASSERT_EQ(result, 0);
394 }
395
396 /**
397 * @tc.name: UpdateSizeChangeReason01
398 * @tc.desc: UpdateSizeChangeReason01
399 * @tc.type: FUNC
400 */
401 HWTEST_F(SceneSessionTest2, UpdateSizeChangeReason01, TestSize.Level1)
402 {
403 SessionInfo info;
404 info.abilityName_ = "UpdateSizeChangeReason01";
405 info.bundleName_ = "UpdateSizeChangeReason01";
406 info.windowType_ = 1;
407 sptr<Rosen::ISession> session_;
408 sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
409 sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
410 EXPECT_NE(specificCallback_, nullptr);
411 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
412 EXPECT_NE(sceneSession, nullptr);
413 sptr<SessionStageMocker> mockSessionStage = sptr<SessionStageMocker>::MakeSptr();
414 ASSERT_NE(mockSessionStage, nullptr);
415 sceneSession->dirtyFlags_ |= static_cast<uint32_t>(SessionUIDirtyFlag::RECT);
416 sceneSession->sessionStage_ = mockSessionStage;
417 sceneSession->UpdateSizeChangeReason(SizeChangeReason::ROTATION);
418 ASSERT_EQ(sceneSession->GetSizeChangeReason(), SizeChangeReason::ROTATION);
419 ASSERT_EQ(WSError::WS_OK, sceneSession->UpdateSizeChangeReason(SizeChangeReason::UNDEFINED));
420 }
421
422 /**
423 * @tc.name: UpdatePiPRect01
424 * @tc.desc: UpdatePiPRect
425 * @tc.type: FUNC
426 */
427 HWTEST_F(SceneSessionTest2, UpdatePiPRect, TestSize.Level1)
428 {
429 SessionInfo info;
430 info.abilityName_ = "UpdatePiPRect01";
431 info.bundleName_ = "UpdatePiPRect";
432 sptr<Rosen::ISession> session_;
433 sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
434 sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
435 EXPECT_NE(specificCallback_, nullptr);
436 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
437 EXPECT_NE(sceneSession, nullptr);
438 sceneSession->isActive_ = true;
439
440 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
441 property->SetWindowType(WindowType::WINDOW_TYPE_PIP);
442 sceneSession->SetSessionProperty(property);
443
444 Rect rect = { 0, 0, 800, 600 };
445 SizeChangeReason reason = SizeChangeReason::PIP_START;
446 WSError result = sceneSession->UpdatePiPRect(rect, reason);
447 ASSERT_EQ(result, WSError::WS_OK);
448
449 property->SetWindowType(WindowType::WINDOW_TYPE_FLOAT);
450 sceneSession->SetSessionProperty(property);
451 result = sceneSession->UpdatePiPRect(rect, reason);
452 ASSERT_EQ(result, WSError::WS_DO_NOTHING);
453
454 property->SetWindowType(WindowType::WINDOW_TYPE_PIP);
455 sceneSession->SetSessionProperty(property);
456 sceneSession->isTerminating_ = true;
457 result = sceneSession->UpdatePiPRect(rect, reason);
458 ASSERT_EQ(result, WSError::WS_OK);
459
460 sceneSession->isTerminating_ = false;
461 result = sceneSession->UpdatePiPRect(rect, reason);
462 ASSERT_EQ(result, WSError::WS_OK);
463 }
464
465 /**
466 * @tc.name: UpdatePiPControlStatus
467 * @tc.desc: UpdatePiPControlStatus
468 * @tc.type: FUNC
469 */
470 HWTEST_F(SceneSessionTest2, UpdatePiPControlStatus, TestSize.Level1)
471 {
472 SessionInfo info;
473 info.abilityName_ = "UpdatePiPControlStatus";
474 info.bundleName_ = "UpdatePiPControlStatus";
475 auto sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
476 EXPECT_NE(sceneSession, nullptr);
477 sceneSession->isActive_ = true;
478
479 auto property = sptr<WindowSessionProperty>::MakeSptr();
480 EXPECT_NE(property, nullptr);
481 property->SetWindowType(WindowType::WINDOW_TYPE_PIP);
482 sceneSession->SetSessionProperty(property);
483
484 auto controlType = WsPiPControlType::VIDEO_PLAY_PAUSE;
485 auto status = WsPiPControlStatus::PLAY;
486 WSError result = sceneSession->UpdatePiPControlStatus(controlType, status);
487 ASSERT_EQ(result, WSError::WS_OK);
488
489 property->SetWindowType(WindowType::WINDOW_TYPE_FLOAT);
490 sceneSession->SetSessionProperty(property);
491 result = sceneSession->UpdatePiPControlStatus(controlType, status);
492 ASSERT_EQ(result, WSError::WS_DO_NOTHING);
493 }
494
495 /**
496 * @tc.name: SetScale
497 * @tc.desc: SetScale
498 * @tc.type: FUNC
499 */
500 HWTEST_F(SceneSessionTest2, SetScale, TestSize.Level1)
501 {
502 SessionInfo info;
503 info.abilityName_ = "SetScale";
504 info.bundleName_ = "SetScale";
505 sptr<Rosen::ISession> session_;
506 sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
507 sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
508 EXPECT_NE(specificCallback_, nullptr);
509 int resultValue = 0;
510 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
511 EXPECT_NE(sceneSession, nullptr);
512 sceneSession->SetScale(1.0f, 1.0f, 0.0f, 0.0f);
513 ASSERT_EQ(0, resultValue);
514 }
515
516 /**
517 * @tc.name: SetIsDisplayStatusBarTemporarily
518 * @tc.desc: SetIsDisplayStatusBarTemporarily
519 * @tc.type: FUNC
520 */
521 HWTEST_F(SceneSessionTest2, SetIsDisplayStatusBarTemporarily, TestSize.Level1)
522 {
523 SessionInfo info;
524 info.abilityName_ = "SetIsDisplayStatusBarTemporarily";
525 info.bundleName_ = "SetIsDisplayStatusBarTemporarily";
526 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
527 EXPECT_NE(sceneSession, nullptr);
528 sceneSession->SetIsDisplayStatusBarTemporarily(true);
529 ASSERT_EQ(true, sceneSession->GetIsDisplayStatusBarTemporarily());
530 sceneSession->SetIsDisplayStatusBarTemporarily(false);
531 ASSERT_EQ(false, sceneSession->GetIsDisplayStatusBarTemporarily());
532 }
533
534 /**
535 * @tc.name: UpdateAvoidArea
536 * @tc.desc: UpdateAvoidArea
537 * @tc.type: FUNC
538 */
539 HWTEST_F(SceneSessionTest2, UpdateAvoidArea, TestSize.Level1)
540 {
541 SessionInfo info;
542 info.abilityName_ = "UpdateAvoidArea";
543 info.bundleName_ = "UpdateAvoidArea";
544 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
545 sceneSession->sessionStage_ = nullptr;
546 WSError result = sceneSession->UpdateAvoidArea(nullptr, AvoidAreaType::TYPE_SYSTEM);
547 EXPECT_EQ(WSError::WS_ERROR_NULLPTR, result);
548
549 sceneSession->sessionStage_ = sptr<SessionStageMocker>::MakeSptr();
550 EXPECT_NE(nullptr, sceneSession->sessionStage_);
551 result = sceneSession->UpdateAvoidArea(nullptr, AvoidAreaType::TYPE_SYSTEM);
552 EXPECT_EQ(WSError::WS_OK, result);
553 sceneSession->foregroundInteractiveStatus_.store(false);
554 result = sceneSession->UpdateAvoidArea(nullptr, AvoidAreaType::TYPE_SYSTEM);
555 EXPECT_EQ(WSError::WS_DO_NOTHING, result);
556 }
557
558 /**
559 * @tc.name: ChangeSessionVisibilityWithStatusBar
560 * @tc.desc: normal function
561 * @tc.type: FUNC
562 */
563 HWTEST_F(SceneSessionTest2, ChangeSessionVisibilityWithStatusBar, TestSize.Level1)
564 {
565 SessionInfo info;
566 info.abilityName_ = "ChangeSessionVisibilityWithStatusBar";
567 info.bundleName_ = "ChangeSessionVisibilityWithStatusBar";
568
569 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
570 EXPECT_NE(sceneSession, nullptr);
571 sceneSession->isActive_ = true;
572
573 sptr<AAFwk::SessionInfo> info1 = nullptr;
574 WSError result = sceneSession->ChangeSessionVisibilityWithStatusBar(info1, false);
575 ASSERT_EQ(result, WSError::WS_ERROR_INVALID_PERMISSION);
576
577 sptr<AAFwk::SessionInfo> abilitySessionInfo = sptr<AAFwk::SessionInfo>::MakeSptr();
578 result = sceneSession->ChangeSessionVisibilityWithStatusBar(abilitySessionInfo, false);
579 ASSERT_EQ(result, WSError::WS_ERROR_INVALID_PERMISSION);
580 }
581
582 /**
583 * @tc.name: SetShouldHideNonSecureWindows
584 * @tc.desc: SetShouldHideNonSecureWindows
585 * @tc.type: FUNC
586 */
587 HWTEST_F(SceneSessionTest2, SetShouldHideNonSecureWindows, TestSize.Level1)
588 {
589 SessionInfo info;
590 info.abilityName_ = "SetShouldHideNonSecureWindows";
591 info.bundleName_ = "SetShouldHideNonSecureWindows";
592
593 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
594 EXPECT_NE(sceneSession, nullptr);
595
596 EXPECT_FALSE(sceneSession->shouldHideNonSecureWindows_.load());
597 sceneSession->SetShouldHideNonSecureWindows(true);
598 EXPECT_TRUE(sceneSession->shouldHideNonSecureWindows_.load());
599 }
600
601 /**
602 * @tc.name: UpdateExtWindowFlags
603 * @tc.desc: update uiextension window flags
604 * @tc.type: FUNC
605 */
606 HWTEST_F(SceneSessionTest2, UpdateExtWindowFlags, TestSize.Level1)
607 {
608 SessionInfo info;
609 info.abilityName_ = "UpdateExtWindowFlags";
610 info.bundleName_ = "UpdateExtWindowFlags";
611
612 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
613 EXPECT_NE(sceneSession, nullptr);
614
615 EXPECT_TRUE(sceneSession->extWindowFlagsMap_.empty());
616 int32_t persistentId = 12345;
617 ExtensionWindowFlags flags(7);
618 ExtensionWindowFlags actions(7);
619 sceneSession->UpdateExtWindowFlags(persistentId, flags, actions);
620 EXPECT_EQ(sceneSession->extWindowFlagsMap_.size(), 1);
621 EXPECT_EQ(sceneSession->extWindowFlagsMap_.begin()->first, persistentId);
622 EXPECT_EQ(sceneSession->extWindowFlagsMap_.begin()->second.bitData, 7);
623 flags.bitData = 0;
624 actions.bitData = 3;
625 sceneSession->UpdateExtWindowFlags(persistentId, flags, actions);
626 EXPECT_EQ(sceneSession->extWindowFlagsMap_.size(), 1);
627 EXPECT_EQ(sceneSession->extWindowFlagsMap_.begin()->first, persistentId);
628 EXPECT_EQ(sceneSession->extWindowFlagsMap_.begin()->second.bitData, 4);
629 actions.bitData = 4;
630 sceneSession->UpdateExtWindowFlags(persistentId, flags, actions);
631 EXPECT_TRUE(sceneSession->extWindowFlagsMap_.empty());
632 }
633
634 /**
635 * @tc.name: GetCombinedExtWindowFlags
636 * @tc.desc: get combined uiextension window flags
637 * @tc.type: FUNC
638 */
639 HWTEST_F(SceneSessionTest2, GetCombinedExtWindowFlags, TestSize.Level1)
640 {
641 SessionInfo info;
642 info.abilityName_ = "GetCombinedExtWindowFlags";
643 info.bundleName_ = "GetCombinedExtWindowFlags";
644
645 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
646 EXPECT_NE(sceneSession, nullptr);
647
648 auto combinedExtWindowFlags = sceneSession->GetCombinedExtWindowFlags();
649 EXPECT_EQ(combinedExtWindowFlags.bitData, 0);
650 sceneSession->UpdateExtWindowFlags(1234, ExtensionWindowFlags(3), ExtensionWindowFlags(3));
651 sceneSession->UpdateExtWindowFlags(5678, ExtensionWindowFlags(4), ExtensionWindowFlags(4));
652
653 sceneSession->state_ = SessionState::STATE_FOREGROUND;
654 combinedExtWindowFlags = sceneSession->GetCombinedExtWindowFlags();
655 EXPECT_EQ(combinedExtWindowFlags.bitData, 7);
656
657 sceneSession->state_ = SessionState::STATE_BACKGROUND;
658 combinedExtWindowFlags = sceneSession->GetCombinedExtWindowFlags();
659 EXPECT_EQ(combinedExtWindowFlags.bitData, 6);
660 }
661
662 /**
663 * @tc.name: RemoveExtWindowFlags
664 * @tc.desc: remove uiextension window flags
665 * @tc.type: FUNC
666 */
667 HWTEST_F(SceneSessionTest2, RemoveExtWindowFlags, TestSize.Level1)
668 {
669 SessionInfo info;
670 info.abilityName_ = "RemoveExtWindowFlags";
671 info.bundleName_ = "RemoveExtWindowFlags";
672
673 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
674 EXPECT_NE(sceneSession, nullptr);
675
676 EXPECT_TRUE(sceneSession->extWindowFlagsMap_.empty());
677 sceneSession->UpdateExtWindowFlags(1234, ExtensionWindowFlags(3), ExtensionWindowFlags(3));
678 EXPECT_EQ(sceneSession->extWindowFlagsMap_.size(), 1);
679 sceneSession->RemoveExtWindowFlags(1234);
680 EXPECT_TRUE(sceneSession->extWindowFlagsMap_.empty());
681 }
682
683 /**
684 * @tc.name: ClearExtWindowFlags
685 * @tc.desc: clear uiextension window flags
686 * @tc.type: FUNC
687 */
688 HWTEST_F(SceneSessionTest2, ClearExtWindowFlags, TestSize.Level1)
689 {
690 SessionInfo info;
691 info.abilityName_ = "ClearExtWindowFlags";
692 info.bundleName_ = "ClearExtWindowFlags";
693
694 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
695 EXPECT_NE(sceneSession, nullptr);
696
697 EXPECT_TRUE(sceneSession->extWindowFlagsMap_.empty());
698 sceneSession->UpdateExtWindowFlags(1234, ExtensionWindowFlags(3), ExtensionWindowFlags(3));
699 sceneSession->UpdateExtWindowFlags(5678, ExtensionWindowFlags(4), ExtensionWindowFlags(4));
700 EXPECT_EQ(sceneSession->extWindowFlagsMap_.size(), 2);
701 sceneSession->ClearExtWindowFlags();
702 EXPECT_TRUE(sceneSession->extWindowFlagsMap_.empty());
703 }
704
705 /**
706 * @tc.name: CalculateCombinedExtWindowFlags
707 * @tc.desc: calculate combined uiextension window flags
708 * @tc.type: FUNC
709 */
710 HWTEST_F(SceneSessionTest2, CalculateCombinedExtWindowFlags, TestSize.Level1)
711 {
712 SessionInfo info;
713 info.abilityName_ = "CalculateCombinedExtWindowFlags";
714 info.bundleName_ = "CalculateCombinedExtWindowFlags";
715
716 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
717 EXPECT_NE(sceneSession, nullptr);
718
719 EXPECT_EQ(sceneSession->combinedExtWindowFlags_.bitData, 0);
720 sceneSession->UpdateExtWindowFlags(1234, ExtensionWindowFlags(3), ExtensionWindowFlags(3));
721 sceneSession->UpdateExtWindowFlags(5678, ExtensionWindowFlags(4), ExtensionWindowFlags(4));
722 sceneSession->CalculateCombinedExtWindowFlags();
723 EXPECT_EQ(sceneSession->combinedExtWindowFlags_.bitData, 7);
724 }
725
726 /**
727 * @tc.name: SaveUpdatedIcon
728 * @tc.desc: SaveUpdatedIcon
729 * @tc.type: FUNC
730 */
731 HWTEST_F(SceneSessionTest2, SaveUpdatedIcon, TestSize.Level1)
732 {
733 SessionInfo info;
734 info.abilityName_ = "SaveUpdatedIcon";
735 info.bundleName_ = "SaveUpdatedIcon";
736 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
737
738 sceneSession->scenePersistence_ = sptr<ScenePersistence>::MakeSptr("OpenHarmony", 1);
739 EXPECT_NE(nullptr, sceneSession->scenePersistence_);
740 sceneSession->SaveUpdatedIcon(nullptr);
741 }
742
743 /**
744 * @tc.name: NotifyTouchOutside
745 * @tc.desc: NotifyTouchOutside
746 * @tc.type: FUNC
747 */
748 HWTEST_F(SceneSessionTest2, NotifyTouchOutside, TestSize.Level1)
749 {
750 SessionInfo info;
751 info.abilityName_ = "NotifyTouchOutside";
752 info.bundleName_ = "NotifyTouchOutside";
753 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
754
755 sceneSession->sessionStage_ = sptr<SessionStageMocker>::MakeSptr();
756 EXPECT_NE(nullptr, sceneSession->sessionStage_);
757 sceneSession->NotifyTouchOutside();
758
__anonbd5ae67e0302() 759 auto func = [sceneSession]() { sceneSession->SaveUpdatedIcon(nullptr); };
760 sceneSession->onTouchOutside_ = func;
761 EXPECT_NE(nullptr, &func);
762 sceneSession->sessionStage_ = nullptr;
763 sceneSession->NotifyTouchOutside();
764
765 sceneSession->onTouchOutside_ = nullptr;
766 sceneSession->sessionStage_ = nullptr;
767 sceneSession->NotifyTouchOutside();
768 }
769
770 /**
771 * @tc.name: CheckTouchOutsideCallbackRegistered
772 * @tc.desc: CheckTouchOutsideCallbackRegistered
773 * @tc.type: FUNC
774 */
775 HWTEST_F(SceneSessionTest2, CheckTouchOutsideCallbackRegistered, TestSize.Level1)
776 {
777 SessionInfo info;
778 info.abilityName_ = "CheckTouchOutsideCallbackRegistered";
779 info.bundleName_ = "CheckTouchOutsideCallbackRegistered";
780 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
781
__anonbd5ae67e0402() 782 auto func = [sceneSession]() { sceneSession->NotifyWindowVisibility(); };
783 sceneSession->onTouchOutside_ = func;
784 bool result = sceneSession->CheckTouchOutsideCallbackRegistered();
785 EXPECT_EQ(true, result);
786
787 sceneSession->onTouchOutside_ = nullptr;
788 result = sceneSession->CheckTouchOutsideCallbackRegistered();
789 EXPECT_EQ(false, result);
790 }
791
792 /**
793 * @tc.name: RegisterTouchOutsideCallback
794 * @tc.desc: test RegisterTouchOutsideCallback
795 * @tc.type: FUNC
796 */
797 HWTEST_F(SceneSessionTest2, RegisterTouchOutsideCallback, TestSize.Level1)
798 {
799 SessionInfo info;
800 info.abilityName_ = "RegisterTouchOutsideCallback";
801 info.bundleName_ = "RegisterTouchOutsideCallback";
802 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
803 sceneSession->onTouchOutside_ = nullptr;
__anonbd5ae67e0502() 804 NotifyTouchOutsideFunc func = []() {};
805 sceneSession->RegisterTouchOutsideCallback(std::move(func));
806
807 ASSERT_NE(sceneSession->onTouchOutside_, nullptr);
808 }
809
810 /**
811 * @tc.name: UpdateRotationAvoidArea
812 * @tc.desc: UpdateRotationAvoidArea
813 * @tc.type: FUNC
814 */
815 HWTEST_F(SceneSessionTest2, UpdateRotationAvoidArea, TestSize.Level1)
816 {
817 SessionInfo info;
818 info.abilityName_ = "UpdateRotationAvoidArea";
819 info.bundleName_ = "UpdateRotationAvoidArea";
820 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
821 sceneSession->specificCallback_ = sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
822 EXPECT_NE(nullptr, sceneSession->specificCallback_);
__anonbd5ae67e0602(const int32_t& persistentId) 823 auto func = [sceneSession](const int32_t& persistentId) {
824 sceneSession->SetParentPersistentId(persistentId);
825 sceneSession->GetParentPersistentId();
826 };
827 sceneSession->specificCallback_->onUpdateAvoidArea_ = func;
828 sptr<Session> session;
829 session = sptr<Session>::MakeSptr(info);
830 int result = session->GetPersistentId();
831 EXPECT_EQ(0, result);
832 sceneSession->UpdateRotationAvoidArea();
833
834 sceneSession->specificCallback_ = nullptr;
835 sceneSession->UpdateRotationAvoidArea();
836 }
837
838 /**
839 * @tc.name: NotifyForceHideChange
840 * @tc.desc: NotifyForceHideChange
841 * @tc.type: FUNC
842 */
843 HWTEST_F(SceneSessionTest2, NotifyForceHideChange, TestSize.Level1)
844 {
845 SessionInfo info;
846 info.abilityName_ = "NotifyForceHideChange";
847 info.bundleName_ = "NotifyForceHideChange";
848 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
849 sceneSession->NotifyForceHideChange(true);
850
851 sptr<Session> session = sptr<Session>::MakeSptr(info);
__anonbd5ae67e0702(bool hide) 852 auto func = [sceneSession](bool hide) { sceneSession->SetPrivacyMode(hide); };
853 sceneSession->onForceHideChangeFunc_ = func;
854 EXPECT_NE(nullptr, &func);
855 sceneSession->NotifyForceHideChange(true);
856 }
857
858 /**
859 * @tc.name: SendPointerEventToUI
860 * @tc.desc: SendPointerEventToUI
861 * @tc.type: FUNC
862 */
863 HWTEST_F(SceneSessionTest2, SendPointerEventToUI, TestSize.Level1)
864 {
865 SessionInfo info;
866 info.abilityName_ = "SendPointerEventToUI";
867 info.bundleName_ = "SendPointerEventToUI";
868 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
869 EXPECT_NE(nullptr, sceneSession);
__anonbd5ae67e0802(std::shared_ptr<MMI::PointerEvent> pointerEvent) 870 auto pointerEventFunc = [sceneSession](std::shared_ptr<MMI::PointerEvent> pointerEvent) {
871 sceneSession->NotifyOutsideDownEvent(pointerEvent);
872 };
873 sceneSession->systemSessionPointerEventFunc_ = pointerEventFunc;
874 std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
875 sceneSession->SendPointerEventToUI(pointerEvent);
876 EXPECT_NE(nullptr, pointerEvent);
877 }
878
879 /**
880 * @tc.name: SetFloatingScale
881 * @tc.desc: SetFloatingScale
882 * @tc.type: FUNC
883 */
884 HWTEST_F(SceneSessionTest2, SetFloatingScale, TestSize.Level1)
885 {
886 SessionInfo info;
887 info.abilityName_ = "SetFloatingScale";
888 info.bundleName_ = "SetFloatingScale";
889 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
890 sceneSession->specificCallback_ = sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
__anonbd5ae67e0902(int32_t persistentId, WindowUpdateType type) 891 auto windowInfoUpdateFun = [sceneSession](int32_t persistentId, WindowUpdateType type) {
892 if (WindowUpdateType::WINDOW_UPDATE_PROPERTY == type) {
893 sceneSession->SetCollaboratorType(persistentId);
894 return;
895 } else {
896 persistentId++;
897 sceneSession->SetParentPersistentId(persistentId);
898 return;
899 }
900 };
__anonbd5ae67e0a02(const int32_t& persistentId) 901 auto updateAvoidAreaFun = [sceneSession](const int32_t& persistentId) {
902 bool result = sceneSession->RemoveSubSession(persistentId);
903 sceneSession->SetWindowAnimationFlag(result);
904 };
905 sceneSession->specificCallback_->onWindowInfoUpdate_ = windowInfoUpdateFun;
906 sceneSession->specificCallback_->onUpdateAvoidArea_ = updateAvoidAreaFun;
907 sceneSession->SetFloatingScale(3.14f);
908 EXPECT_EQ(3.14f, sceneSession->floatingScale_);
909
910 sceneSession->floatingScale_ = 3.0f;
911 sceneSession->SetFloatingScale(3.0f);
912 EXPECT_EQ(3.0f, sceneSession->floatingScale_);
913 }
914
915 /**
916 * @tc.name: ProcessPointDownSession
917 * @tc.desc: ProcessPointDownSession
918 * @tc.type: FUNC
919 */
920 HWTEST_F(SceneSessionTest2, ProcessPointDownSession, TestSize.Level1)
921 {
922 SessionInfo info;
923 info.abilityName_ = "ProcessPointDownSession";
924 info.bundleName_ = "ProcessPointDownSession";
925 info.windowInputType_ = static_cast<uint32_t>(MMI::WindowInputType::NORMAL);
926 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
927 sceneSession->specificCallback_ = sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
928 EXPECT_NE(nullptr, sceneSession->specificCallback_);
__anonbd5ae67e0b02(int32_t persistentId, DisplayId displayId) 929 auto sessionTouchOutsideFun = [sceneSession](int32_t persistentId, DisplayId displayId) {
930 sceneSession->SetCollaboratorType(persistentId);
931 };
__anonbd5ae67e0c02(int32_t x, int32_t y) 932 auto outsideDownEventFun = [sceneSession](int32_t x, int32_t y) {
933 int z = x + y;
934 sceneSession->SetCollaboratorType(z);
935 };
936 sceneSession->specificCallback_->onSessionTouchOutside_ = sessionTouchOutsideFun;
937 sceneSession->specificCallback_->onOutsideDownEvent_ = outsideDownEventFun;
938 EXPECT_EQ(WSError::WS_OK, sceneSession->ProcessPointDownSession(3, 4));
939
940 sceneSession->specificCallback_->onSessionTouchOutside_ = nullptr;
941 EXPECT_EQ(WSError::WS_OK, sceneSession->ProcessPointDownSession(3, 4));
942
943 sceneSession->sessionInfo_.bundleName_ = "SCBGestureBack";
944 sceneSession->specificCallback_->onOutsideDownEvent_ = nullptr;
945 EXPECT_EQ(WSError::WS_OK, sceneSession->ProcessPointDownSession(3, 4));
946
947 info.windowInputType_ = static_cast<uint32_t>(MMI::WindowInputType::TRANSMIT_ALL);
948 sptr<SceneSession> sceneSession1 = sptr<SceneSession>::MakeSptr(info, nullptr);
949 sceneSession1->specificCallback_ = sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
950 EXPECT_NE(nullptr, sceneSession1->specificCallback_);
951 sceneSession1->specificCallback_->onOutsideDownEvent_ = nullptr;
952 EXPECT_EQ(WSError::WS_ERROR_INVALID_TYPE, sceneSession1->ProcessPointDownSession(3, 4));
953 }
954
955 /**
956 * @tc.name: SetSessionInfoWindowInputType
957 * @tc.desc: SetSessionInfoWindowInputType
958 * @tc.type: FUNC
959 */
960 HWTEST_F(SceneSessionTest2, SetSessionInfoWindowInputType, TestSize.Level1)
961 {
962 SessionInfo info;
963 info.abilityName_ = "SetSessionInfoWindowInputType";
964 info.bundleName_ = "SetSessionInfoWindowInputType";
965 info.windowInputType_ = static_cast<uint32_t>(MMI::WindowInputType::NORMAL);
966 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
967 sceneSession->isActive_ = true;
968 sceneSession->SetSessionInfoWindowInputType(static_cast<uint32_t>(MMI::WindowInputType::TRANSMIT_AXIS_MOVE));
969
970 SessionInfo sessionInfo = sceneSession->GetSessionInfo();
971 ASSERT_EQ(sessionInfo.windowInputType_, static_cast<uint32_t>(MMI::WindowInputType::TRANSMIT_AXIS_MOVE));
972
973 sceneSession->SetSessionInfoWindowInputType(static_cast<uint32_t>(MMI::WindowInputType::TRANSMIT_ALL));
974 sessionInfo = sceneSession->GetSessionInfo();
975 ASSERT_EQ(sessionInfo.windowInputType_, static_cast<uint32_t>(MMI::WindowInputType::TRANSMIT_ALL));
976 }
977
978 /**
979 * @tc.name: SetSelfToken
980 * @tc.desc: SetSelfToken
981 * @tc.type: FUNC
982 */
983 HWTEST_F(SceneSessionTest2, SetSelfToken, TestSize.Level1)
984 {
985 SessionInfo info;
986 info.abilityName_ = "SetSelfToken";
987 info.bundleName_ = "SetSelfToken";
988 sptr<SceneSession> sceneSession;
989 sptr<SceneSession::SpecificSessionCallback> specificSession =
990 sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
991 sceneSession = sptr<SceneSession>::MakeSptr(info, specificSession);
992 EXPECT_NE(nullptr, sceneSession);
993 sceneSession->SetSessionState(SessionState::STATE_DISCONNECT);
994 sceneSession->UpdateSessionState(SessionState::STATE_CONNECT);
995 sceneSession->UpdateSessionState(SessionState::STATE_ACTIVE);
996 sceneSession->isVisible_ = true;
997 EXPECT_EQ(true, sceneSession->IsVisibleForAccessibility());
998 sceneSession->SetSystemTouchable(false);
999 EXPECT_EQ(false, sceneSession->IsVisibleForAccessibility());
1000 sceneSession->SetForegroundInteractiveStatus(true);
1001 sceneSession->NotifyAccessibilityVisibilityChange();
__anonbd5ae67e0d02(int32_t persistentId, WindowUpdateType type) 1002 auto windowInfoUpdateFun = [sceneSession](int32_t persistentId, WindowUpdateType type) {
1003 if (WindowUpdateType::WINDOW_UPDATE_PROPERTY == type) {
1004 sceneSession->SetCollaboratorType(persistentId);
1005 return;
1006 } else {
1007 persistentId++;
1008 sceneSession->SetParentPersistentId(persistentId);
1009 return;
1010 }
1011 };
1012 sceneSession->specificCallback_->onWindowInfoUpdate_ = windowInfoUpdateFun;
1013 sceneSession->NotifyAccessibilityVisibilityChange();
1014 EXPECT_NE(nullptr, sceneSession->specificCallback_);
1015 }
1016
1017 /**
1018 * @tc.name: SetLastSafeRect
1019 * @tc.desc: SetLastSafeRect
1020 * @tc.type: FUNC
1021 */
1022 HWTEST_F(SceneSessionTest2, SetLastSafeRect, TestSize.Level1)
1023 {
1024 SessionInfo info;
1025 info.abilityName_ = "SetLastSafeRect";
1026 info.bundleName_ = "SetLastSafeRect";
1027 sptr<SceneSession> sceneSession;
1028 sptr<SceneSession::SpecificSessionCallback> specificSession =
1029 sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
1030 sceneSession = sptr<SceneSession>::MakeSptr(info, specificSession);
1031 WSRect rect = { 3, 4, 5, 6 };
1032 sceneSession->SetLastSafeRect(rect);
1033 WSRect result = sceneSession->GetLastSafeRect();
1034 EXPECT_EQ(3, result.posX_);
1035 EXPECT_EQ(4, result.posY_);
1036 EXPECT_EQ(5, result.width_);
1037 EXPECT_EQ(6, result.height_);
1038 }
1039
1040 /**
1041 * @tc.name: GetSessionTargetRectByDisplayId
1042 * @tc.desc: GetSessionTargetRectByDisplayId
1043 * @tc.type: FUNC
1044 */
1045 HWTEST_F(SceneSessionTest2, GetSessionTargetRectByDisplayId, TestSize.Level1)
1046 {
1047 SessionInfo info;
1048 info.abilityName_ = "GetSubSession";
1049 info.bundleName_ = "GetSessionTargetRectByDisplayId";
1050 sptr<SceneSession> sceneSession;
1051 sptr<SceneSession::SpecificSessionCallback> specificSession =
1052 sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
1053 sceneSession = sptr<SceneSession>::MakeSptr(info, specificSession);
1054 bool res = sceneSession->AddSubSession(sceneSession);
1055 EXPECT_EQ(true, res);
1056 EXPECT_EQ(sceneSession, (sceneSession->GetSubSession())[0]);
1057 sceneSession->moveDragController_ = sptr<MoveDragController>::MakeSptr(1024, WindowType::WINDOW_TYPE_FLOAT);
1058 WSRect rectResult = sceneSession->GetSessionTargetRectByDisplayId(0);
1059 EXPECT_EQ(0, rectResult.posX_);
1060 EXPECT_EQ(0, rectResult.width_);
__anonbd5ae67e0e02(DisplayId displayId, int32_t type, SizeChangeReason reason) 1061 auto dragHotAreaFunc = [sceneSession](DisplayId displayId, int32_t type, SizeChangeReason reason) {
1062 if (SizeChangeReason::END == reason) {
1063 GTEST_LOG_(INFO) << "type = " << type;
1064 }
1065 return;
1066 };
1067 sceneSession->SetWindowDragHotAreaListener(dragHotAreaFunc);
1068 EXPECT_NE(nullptr, sceneSession->moveDragController_);
1069 sceneSession->moveDragController_ = nullptr;
1070 rectResult = sceneSession->GetSessionTargetRectByDisplayId(0);
1071 sceneSession->SetWindowDragHotAreaListener(dragHotAreaFunc);
1072 ASSERT_EQ(0, rectResult.width_);
1073 }
1074
1075 /**
1076 * @tc.name: SetPipActionEvent
1077 * @tc.desc: SetPipActionEvent
1078 * @tc.type: FUNC
1079 */
1080 HWTEST_F(SceneSessionTest2, SetPipActionEvent, TestSize.Level1)
1081 {
1082 SessionInfo info;
1083 info.abilityName_ = "SetPipActionEvent";
1084 info.bundleName_ = "SetPipActionEvent";
1085 auto sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1086 EXPECT_NE(sceneSession, nullptr);
1087
1088 WSError res = sceneSession->SetPipActionEvent("close", 0);
1089 ASSERT_EQ(res, WSError::WS_ERROR_NULLPTR);
1090 auto mockSessionStage = sptr<SessionStageMocker>::MakeSptr();
1091 sceneSession->sessionStage_ = mockSessionStage;
1092 res = sceneSession->SetPipActionEvent("close", 0);
1093 ASSERT_EQ(res, WSError::WS_OK);
1094 }
1095
1096 /**
1097 * @tc.name: SetPiPControlEvent
1098 * @tc.desc: SetPiPControlEvent
1099 * @tc.type: FUNC
1100 */
1101 HWTEST_F(SceneSessionTest2, SetPiPControlEvent, TestSize.Level1)
1102 {
1103 SessionInfo info;
1104 info.abilityName_ = "SetPiPControlEvent";
1105 info.bundleName_ = "SetPiPControlEvent";
1106 auto sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1107 EXPECT_NE(sceneSession, nullptr);
1108
1109 auto property = sptr<WindowSessionProperty>::MakeSptr();
1110 EXPECT_NE(property, nullptr);
1111 property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1112 sceneSession->SetSessionProperty(property);
1113 auto controlType = WsPiPControlType::VIDEO_PLAY_PAUSE;
1114 auto status = WsPiPControlStatus::PLAY;
1115 WSError res = sceneSession->SetPiPControlEvent(controlType, status);
1116 ASSERT_EQ(res, WSError::WS_ERROR_INVALID_TYPE);
1117
1118 auto sessionStage = sptr<SessionStageMocker>::MakeSptr();
1119 ASSERT_NE(sessionStage, nullptr);
1120
1121 property->SetWindowType(WindowType::WINDOW_TYPE_PIP);
1122 property->SetWindowMode(WindowMode::WINDOW_MODE_PIP);
1123 sceneSession->SetSessionProperty(property);
1124 res = sceneSession->SetPiPControlEvent(controlType, status);
1125 ASSERT_EQ(res, WSError::WS_ERROR_NULLPTR);
1126 }
1127
1128 /**
1129 * @tc.name: SetForceHideState
1130 * @tc.desc: SetForceHideState
1131 * @tc.type: FUNC
1132 */
1133 HWTEST_F(SceneSessionTest2, SetForceHideState, TestSize.Level1)
1134 {
1135 SessionInfo info;
1136 info.abilityName_ = "SetForceHideState";
1137 info.bundleName_ = "SetForceHideState";
1138 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1139 EXPECT_NE(sceneSession, nullptr);
1140
1141 sceneSession->SetForceHideState(ForceHideState::NOT_HIDDEN);
1142 bool hide = sceneSession->GetForceHideState();
1143 ASSERT_EQ(hide, ForceHideState::NOT_HIDDEN);
1144 sceneSession->SetForceHideState(ForceHideState::HIDDEN_WHEN_FOCUSED);
1145 hide = sceneSession->GetForceHideState();
1146 ASSERT_EQ(hide, ForceHideState::HIDDEN_WHEN_FOCUSED);
1147 }
1148
1149 /**
1150 * @tc.name: OnSessionEvent01
1151 * @tc.desc: OnSessionEvent
1152 * @tc.type: FUNC
1153 */
1154 HWTEST_F(SceneSessionTest2, OnSessionEvent01, TestSize.Level1)
1155 {
1156 SessionInfo info;
1157 info.abilityName_ = "OnSessionEvent01";
1158 info.bundleName_ = "OnSessionEvent01";
1159
1160 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1161 EXPECT_NE(sceneSession, nullptr);
1162
1163 sceneSession->leashWinSurfaceNode_ = nullptr;
1164 SessionEvent event = SessionEvent::EVENT_START_MOVE;
1165 sceneSession->moveDragController_ = sptr<MoveDragController>::MakeSptr(1, WindowType::WINDOW_TYPE_FLOAT);
1166 sceneSession->OnSessionEvent(event);
1167
1168 sceneSession->moveDragController_->isStartDrag_ = true;
1169 auto result = sceneSession->OnSessionEvent(event);
1170 ASSERT_EQ(result, WSError::WS_OK);
1171 event = SessionEvent::EVENT_DRAG_START;
1172 ASSERT_EQ(sceneSession->OnSessionEvent(event), WSError::WS_OK);
1173 }
1174
1175 /**
1176 * @tc.name: SetSessionRectChangeCallback
1177 * @tc.desc: SetSessionRectChangeCallback
1178 * @tc.type: FUNC
1179 */
1180 HWTEST_F(SceneSessionTest2, SetSessionRectChangeCallback, TestSize.Level1)
1181 {
1182 SessionInfo info;
1183 info.abilityName_ = "SetSessionRectChangeCallback";
1184 info.bundleName_ = "SetSessionRectChangeCallback";
1185
1186 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1187 EXPECT_NE(sceneSession, nullptr);
1188
1189 NotifySessionRectChangeFunc func;
1190 sceneSession->SetSessionRectChangeCallback(func);
1191
1192 sceneSession->RaiseToAppTop();
1193 sceneSession = nullptr;
1194 GTEST_LOG_(INFO) << "2";
1195 sceneSession->BindDialogSessionTarget(sceneSession);
1196
1197 Session ssession(info);
1198 ssession.property_ = nullptr;
1199 }
1200
1201 /**
1202 * @tc.name: SetSessionPiPControlStatusChangeCallback
1203 * @tc.desc: SetSessionPiPControlStatusChangeCallback
1204 * @tc.type: FUNC
1205 */
1206 HWTEST_F(SceneSessionTest2, SetSessionPiPControlStatusChangeCallback, TestSize.Level1)
1207 {
1208 SessionInfo info;
1209 info.abilityName_ = "SetSessionPiPControlStatusChangeCallback";
1210 info.bundleName_ = "SetSessionPiPControlStatusChangeCallback";
1211 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1212 EXPECT_NE(sceneSession, nullptr);
1213 NotifySessionPiPControlStatusChangeFunc func;
1214 sceneSession->SetSessionPiPControlStatusChangeCallback(func);
1215 }
1216
1217 /**
1218 * @tc.name: SetAutoStartPiPStatusChangeCallback
1219 * @tc.desc: SetAutoStartPiPStatusChangeCallback
1220 * @tc.type: FUNC
1221 */
1222 HWTEST_F(SceneSessionTest2, SetAutoStartPiPStatusChangeCallback, TestSize.Level1)
1223 {
1224 SessionInfo info;
1225 info.abilityName_ = "SetAutoStartPiPStatusChangeCallback";
1226 info.bundleName_ = "SetAutoStartPiPStatusChangeCallback";
1227 auto sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1228 EXPECT_NE(sceneSession, nullptr);
1229 NotifyAutoStartPiPStatusChangeFunc func;
1230 sceneSession->SetAutoStartPiPStatusChangeCallback(func);
1231 }
1232
1233 /**
1234 * @tc.name: RaiseAppMainWindowToTop
1235 * @tc.desc: RaiseAppMainWindowToTop
1236 * @tc.type: FUNC
1237 */
1238 HWTEST_F(SceneSessionTest2, RaiseAppMainWindowToTop, TestSize.Level1)
1239 {
1240 SessionInfo info;
1241 info.abilityName_ = "RaiseAppMainWindowToTop";
1242 info.bundleName_ = "RaiseAppMainWindowToTop";
1243
1244 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1245 EXPECT_NE(sceneSession, nullptr);
1246
1247 WSError result = sceneSession->RaiseAppMainWindowToTop();
1248 EXPECT_EQ(WSError::WS_OK, result);
1249 bool status = true;
1250 sceneSession->OnNeedAvoid(status);
1251
1252 bool showWhenLocked = true;
1253 sceneSession->OnShowWhenLocked(showWhenLocked);
1254 sceneSession->NotifyPropertyWhenConnect();
1255
1256 sceneSession->focusedOnShow_ = false;
1257 result = sceneSession->RaiseAppMainWindowToTop();
1258 EXPECT_EQ(WSError::WS_OK, result);
1259 }
1260
1261 /**
1262 * @tc.name: GetCutoutAvoidArea
1263 * @tc.desc: GetCutoutAvoidArea
1264 * @tc.type: FUNC
1265 */
1266 HWTEST_F(SceneSessionTest2, GetCutoutAvoidArea01, TestSize.Level1)
1267 {
1268 SessionInfo info;
1269 info.abilityName_ = "GetCutoutAvoidArea";
1270 info.bundleName_ = "GetCutoutAvoidArea";
1271
1272 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1273 EXPECT_NE(sceneSession, nullptr);
1274
1275 WSRect rect;
1276 AvoidArea avoidArea;
1277 DisplayManager displayManager;
1278 Session ssession(info);
1279 auto display = DisplayManager::GetInstance().GetDisplayById(ssession.GetSessionProperty()->GetDisplayId());
1280 sceneSession->GetCutoutAvoidArea(rect, avoidArea);
1281 }
1282
1283 /**
1284 * @tc.name: GetAINavigationBarArea
1285 * @tc.desc: GetAINavigationBarArea
1286 * @tc.type: FUNC
1287 */
1288 HWTEST_F(SceneSessionTest2, GetAINavigationBarArea, TestSize.Level1)
1289 {
1290 SessionInfo info;
1291 info.abilityName_ = "GetAINavigationBarArea";
1292 info.bundleName_ = "GetAINavigationBarArea";
1293
1294 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1295 EXPECT_NE(sceneSession, nullptr);
1296
1297 WSRect rect;
1298 AvoidArea avoidArea;
1299 sceneSession->GetAINavigationBarArea(rect, avoidArea);
1300
1301 sceneSession->SetIsDisplayStatusBarTemporarily(true);
1302 sceneSession->GetAINavigationBarArea(rect, avoidArea);
1303 ASSERT_EQ(sceneSession->GetIsDisplayStatusBarTemporarily(), true);
1304
1305 auto property = sptr<WindowSessionProperty>::MakeSptr();
1306 EXPECT_NE(property, nullptr);
1307 property->SetWindowMode(WindowMode::WINDOW_MODE_PIP);
1308 sceneSession->property_ = property;
1309 sceneSession->GetAINavigationBarArea(rect, avoidArea);
1310
1311 property->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
1312 sceneSession->SetSessionProperty(property);
1313 sceneSession->specificCallback_ = sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
1314 ASSERT_NE(nullptr, sceneSession->specificCallback_);
__anonbd5ae67e0f02(uint64_t displayId) 1315 sceneSession->specificCallback_->onGetAINavigationBarArea_ = [](uint64_t displayId) {
1316 WSRect rect = { 1, 1, 1, 1 };
1317 return rect;
1318 };
1319 sceneSession->GetAINavigationBarArea(rect, avoidArea);
1320 }
1321
1322 /**
1323 * @tc.name: TransferPointerEvent
1324 * @tc.desc: TransferPointerEvent
1325 * @tc.type: FUNC
1326 */
1327 HWTEST_F(SceneSessionTest2, TransferPointerEvent03, TestSize.Level1)
1328 {
1329 SessionInfo info;
1330 info.abilityName_ = "TransferPointerEvent";
1331 info.bundleName_ = "TransferPointerEvent";
1332
1333 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1334 EXPECT_NE(sceneSession, nullptr);
1335
1336 std::shared_ptr<MMI::PointerEvent> pointerEvent = nullptr;
1337 sceneSession->specificCallback_ = sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
1338
1339 sceneSession->TransferPointerEvent(pointerEvent);
1340
1341 WindowLimits limits;
1342 WSRect rect;
1343 float ratio = 0.0;
1344 bool isDecor = true;
1345 float vpr = 0.0;
1346 sceneSession->GetLayoutController()->AdjustRectByLimits(limits, ratio, isDecor, vpr, rect);
1347 sceneSession->SetPipActionEvent("pointerEvent", 0);
1348
1349 auto property = sptr<WindowSessionProperty>::MakeSptr();
1350 EXPECT_NE(property, nullptr);
1351 property->SetWindowType(WindowType::WINDOW_TYPE_FLOAT);
1352 sceneSession->SetSessionProperty(property);
1353 ASSERT_EQ(WSError::WS_ERROR_NULLPTR, sceneSession->SetPipActionEvent("pointerEvent", 0));
1354
1355 sceneSession->sessionStage_ = sptr<SessionStageMocker>::MakeSptr();
1356 property->SetWindowType(WindowType::WINDOW_TYPE_PIP);
1357 property->SetWindowMode(WindowMode::WINDOW_MODE_PIP);
1358 sceneSession->SetSessionProperty(property);
1359 sceneSession->GetLayoutController()->AdjustRectByLimits(limits, ratio, false, vpr, rect);
1360 ASSERT_EQ(WSError::WS_OK, sceneSession->SetPipActionEvent("pointerEvent", 0));
1361 }
1362
1363 /**
1364 * @tc.name: OnMoveDragCallback
1365 * @tc.desc: OnMoveDragCallback
1366 * @tc.type: FUNC
1367 */
1368 HWTEST_F(SceneSessionTest2, OnMoveDragCallback, TestSize.Level1)
1369 {
1370 SessionInfo info;
1371 info.abilityName_ = "OnMoveDragCallback";
1372 info.bundleName_ = "OnMoveDragCallback";
1373
1374 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1375 EXPECT_NE(sceneSession, nullptr);
1376
1377 Session session(info);
1378 WSRect rect;
1379 sceneSession->UpdateWinRectForSystemBar(rect);
1380 sceneSession->SetSurfaceBounds(rect, false);
1381 sceneSession->GetWindowNameAllType();
1382 session.scenePersistence_ = sptr<ScenePersistence>::MakeSptr("aa", 0);
1383 sceneSession->GetUpdatedIconPath();
1384
1385 bool visible = true;
1386 sceneSession->UpdateNativeVisibility(visible);
1387
1388 sceneSession->scenePersistence_ = sptr<ScenePersistence>::MakeSptr(info.bundleName_, 0);
1389 EXPECT_NE(sceneSession->scenePersistence_, nullptr);
1390 sceneSession->GetUpdatedIconPath();
1391 }
1392
1393 /**
1394 * @tc.name: OnMoveDragCallback
1395 * @tc.desc: OnMoveDragCallback
1396 * @tc.type: FUNC
1397 */
1398 HWTEST_F(SceneSessionTest2, OnMoveDragCallback01, TestSize.Level1)
1399 {
1400 SessionInfo info;
1401 info.abilityName_ = "OnMoveDragCallback01";
1402 info.bundleName_ = "OnMoveDragCallback01";
1403
1404 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1405 EXPECT_NE(sceneSession, nullptr);
1406
1407 double alpha = 0.5;
1408 Session session(info);
1409
1410 sceneSession->SetSystemSceneOcclusionAlpha(alpha);
1411 sceneSession->IsNeedDefaultAnimation();
1412 bool isPlaying = true;
1413 sceneSession->NotifyIsCustomAnimationPlaying(isPlaying);
1414
1415 sptr<AAFwk::SessionInfo> abilitySessionInfo = nullptr;
1416 bool visible = true;
1417 sceneSession->ChangeSessionVisibilityWithStatusBar(abilitySessionInfo, visible);
1418 }
1419
1420 /**
1421 * @tc.name: OnMoveDragCallback
1422 * @tc.desc: OnMoveDragCallback
1423 * @tc.type: FUNC
1424 */
1425 HWTEST_F(SceneSessionTest2, OnMoveDragCallback02, TestSize.Level1)
1426 {
1427 SessionInfo info;
1428 info.abilityName_ = "OnMoveDragCallback02";
1429 info.bundleName_ = "OnMoveDragCallback02";
1430
1431 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1432 EXPECT_NE(sceneSession, nullptr);
1433 sptr<SceneSession> ssession = nullptr;
1434 sceneSession->HandleCastScreenConnection(info, ssession);
1435
1436 Session session(info);
1437 sptr<AAFwk::SessionInfo> abilitySessionInfo = nullptr;
1438 ExceptionInfo exceptionInfo;
__anonbd5ae67e1002(const SessionInfo& info, const ExceptionInfo& exceInfo, bool startFail) 1439 NotifySessionExceptionFunc func = [](const SessionInfo& info, const ExceptionInfo& exceInfo, bool startFail) {};
1440 session.sessionExceptionFunc_ = func;
__anonbd5ae67e1102(const SessionInfo& info, const ExceptionInfo& exceInfo, bool startFail) 1441 NotifySessionExceptionFunc func1 = [](const SessionInfo& info, const ExceptionInfo& exceInfo, bool startFail) {};
1442 session.jsSceneSessionExceptionFunc_ = func1;
1443 sceneSession->NotifySessionException(abilitySessionInfo, exceptionInfo);
1444
1445 sceneSession->NotifyPiPWindowPrepareClose();
1446
1447 bool isLandscapeMultiWindow = true;
1448 sceneSession->SetLandscapeMultiWindow(isLandscapeMultiWindow);
1449
1450 std::shared_ptr<MMI::KeyEvent> keyEvent = std::make_shared<MMI::KeyEvent>(MMI::KeyEvent::KEYCODE_BACK);
1451 bool isPreImeEvent = true;
1452 sceneSession->SendKeyEventToUI(keyEvent, isPreImeEvent);
1453 sceneSession->IsDirtyWindow();
1454 sceneSession->moveDragController_ = sptr<MoveDragController>::MakeSptr(0, WindowType::WINDOW_TYPE_FLOAT);
1455 sceneSession->NotifyUILostFocus();
1456 }
1457
1458 /**
1459 * @tc.name: IsStartMoving
1460 * @tc.desc: IsStartMoving
1461 * @tc.type: FUNC
1462 */
1463 HWTEST_F(SceneSessionTest2, IsStartMoving, TestSize.Level1)
1464 {
1465 SessionInfo info;
1466 info.abilityName_ = "IsStartMoving";
1467 info.bundleName_ = "IsStartMoving";
1468
1469 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1470 EXPECT_NE(sceneSession, nullptr);
1471
1472 sceneSession->IsStartMoving();
1473 bool startMoving = true;
1474 sceneSession->SetIsStartMoving(startMoving);
1475 DisplayId from = 0;
1476 DisplayId to = 0;
1477 sceneSession->NotifyDisplayMove(from, to);
1478 sceneSession->ClearExtWindowFlags();
1479 bool isRegister = true;
1480 sceneSession->UpdateRectChangeListenerRegistered(isRegister);
1481
1482 sceneSession->sessionStage_ = sptr<SessionStageMocker>::MakeSptr();
1483 EXPECT_NE(nullptr, sceneSession->sessionStage_);
1484 sceneSession->NotifyDisplayMove(from, to);
1485 }
1486
1487 /**
1488 * @tc.name: SetTemporarilyShowWhenLocked
1489 * @tc.desc: SetTemporarilyShowWhenLocked
1490 * @tc.type: FUNC
1491 */
1492 HWTEST_F(SceneSessionTest2, SetTemporarilyShowWhenLocked, TestSize.Level1)
1493 {
1494 SessionInfo info;
1495 info.abilityName_ = "SetTemporarilyShowWhenLocked";
1496 info.bundleName_ = "SetTemporarilyShowWhenLocked";
1497 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1498 EXPECT_NE(sceneSession, nullptr);
1499 bool isTemporarilyShowWhenLocked = sceneSession->IsTemporarilyShowWhenLocked();
1500 ASSERT_EQ(isTemporarilyShowWhenLocked, false);
1501 sceneSession->SetTemporarilyShowWhenLocked(true);
1502 isTemporarilyShowWhenLocked = sceneSession->IsTemporarilyShowWhenLocked();
1503 ASSERT_EQ(isTemporarilyShowWhenLocked, true);
1504 sceneSession->SetTemporarilyShowWhenLocked(false);
1505 isTemporarilyShowWhenLocked = sceneSession->IsTemporarilyShowWhenLocked();
1506 ASSERT_EQ(isTemporarilyShowWhenLocked, false);
1507
1508 sceneSession->isTemporarilyShowWhenLocked_.store(true);
1509 sceneSession->SetTemporarilyShowWhenLocked(true);
1510 ASSERT_EQ(sceneSession->IsTemporarilyShowWhenLocked(), true);
1511 }
1512
1513 /**
1514 * @tc.name: GetShowWhenLockedFlagValue
1515 * @tc.desc: GetShowWhenLockedFlagValue
1516 * @tc.type: FUNC
1517 */
1518 HWTEST_F(SceneSessionTest2, GetShowWhenLockedFlagValue, TestSize.Level1)
1519 {
1520 SessionInfo info;
1521 info.abilityName_ = "GetShowWhenLockedFlagValue";
1522 info.bundleName_ = "GetShowWhenLockedFlagValue";
1523 info.windowType_ = 1;
1524 sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
1525 sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
1526 EXPECT_NE(specificCallback_, nullptr);
1527 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, specificCallback_);
1528 EXPECT_NE(sceneSession, nullptr);
1529 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1530 EXPECT_NE(property, nullptr);
1531 property->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
1532 property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1533 ASSERT_EQ(sceneSession->GetShowWhenLockedFlagValue(), false);
1534 sceneSession->property_ = property;
1535 property->SetWindowFlags(4);
1536 ASSERT_EQ(sceneSession->GetShowWhenLockedFlagValue(), true);
1537 }
1538
1539 /**
1540 * @tc.name: SetClientIdentityToken
1541 * @tc.desc: SetClientIdentityToken
1542 * @tc.type: FUNC
1543 */
1544 HWTEST_F(SceneSessionTest2, SetClientIdentityToken, TestSize.Level1)
1545 {
1546 SessionInfo info;
1547 info.abilityName_ = "SetClientIdentityToken";
1548 info.bundleName_ = "SetClientIdentityToken";
1549 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1550 EXPECT_NE(sceneSession, nullptr);
1551 std::string token = "testToken";
1552 sceneSession->SetClientIdentityToken(token);
1553 ASSERT_EQ(sceneSession->GetClientIdentityToken(), token);
1554 }
1555
1556 /**
1557 * @tc.name: SetSkipDraw
1558 * @tc.desc: SetSkipDraw
1559 * @tc.type: FUNC
1560 */
1561 HWTEST_F(SceneSessionTest2, SetSkipDraw, TestSize.Level1)
1562 {
1563 SessionInfo info;
1564 info.abilityName_ = "SetSkipDraw";
1565 info.bundleName_ = "SetSkipDraw";
1566 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1567 EXPECT_NE(sceneSession, nullptr);
1568 sceneSession->SetSkipDraw(true);
1569 sceneSession->SetSkipDraw(false);
1570 }
1571
1572 /**
1573 * @tc.name: GetWindowDragHotAreaType
1574 * @tc.desc: GetWindowDragHotAreaType
1575 * @tc.type: FUNC
1576 */
1577 HWTEST_F(SceneSessionTest2, GetWindowDragHotAreaType, TestSize.Level1)
1578 {
1579 SessionInfo info;
1580 info.abilityName_ = "HotAreaType";
1581 info.bundleName_ = "HotAreaType";
1582 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1583 EXPECT_NE(sceneSession, nullptr);
1584 WSRect rect = { 0, 0, 10, 10 };
1585 sceneSession->AddOrUpdateWindowDragHotArea(0, 1, rect);
1586 sceneSession->AddOrUpdateWindowDragHotArea(0, 1, rect);
1587 auto type = sceneSession->GetWindowDragHotAreaType(0, 1, 2, 2);
1588 ASSERT_EQ(type, 1);
1589 }
1590
1591 /**
1592 * @tc.name: RegisterSubModalTypeChangeCallback
1593 * @tc.desc: RegisterSubModalTypeChangeCallback
1594 * @tc.type: FUNC
1595 */
1596 HWTEST_F(SceneSessionTest2, RegisterSubModalTypeChangeCallback, TestSize.Level1)
1597 {
1598 SessionInfo info;
1599 info.abilityName_ = "RegisterSubModalTypeChangeCallback";
1600 info.bundleName_ = "RegisterSubModalTypeChangeCallback";
1601 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1602 EXPECT_NE(sceneSession, nullptr);
__anonbd5ae67e1202(SubWindowModalType subWindowModalType) 1603 sceneSession->RegisterSubModalTypeChangeCallback([](SubWindowModalType subWindowModalType) { return; });
1604 EXPECT_NE(sceneSession->onSubModalTypeChange_, nullptr);
1605 }
1606
1607 /**
1608 * @tc.name: NotifySubModalTypeChange
1609 * @tc.desc: NotifySubModalTypeChange
1610 * @tc.type: FUNC
1611 */
1612 HWTEST_F(SceneSessionTest2, NotifySubModalTypeChange, TestSize.Level1)
1613 {
1614 SessionInfo info;
1615 info.abilityName_ = "NotifySubModalTypeChange";
1616 info.bundleName_ = "NotifySubModalTypeChange";
1617 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1618 EXPECT_NE(sceneSession, nullptr);
__anonbd5ae67e1302(SubWindowModalType subWindowModalType) 1619 sceneSession->RegisterSubModalTypeChangeCallback([](SubWindowModalType subWindowModalType) { return; });
1620 EXPECT_NE(sceneSession->onSubModalTypeChange_, nullptr);
1621 EXPECT_EQ(sceneSession->NotifySubModalTypeChange(SubWindowModalType::TYPE_WINDOW_MODALITY), WSError::WS_OK);
1622 }
1623
1624 /**
1625 * @tc.name: RegisterMainModalTypeChangeCallback
1626 * @tc.desc: RegisterMainModalTypeChangeCallback
1627 * @tc.type: FUNC
1628 */
1629 HWTEST_F(SceneSessionTest2, RegisterMainModalTypeChangeCallback, TestSize.Level1)
1630 {
1631 SessionInfo info;
1632 info.abilityName_ = "RegisterMainModalTypeChangeCallback";
1633 info.bundleName_ = "RegisterMainModalTypeChangeCallback";
1634 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1635 EXPECT_NE(sceneSession, nullptr);
__anonbd5ae67e1402(bool isModal) 1636 sceneSession->RegisterMainModalTypeChangeCallback([](bool isModal) { return; });
1637 EXPECT_NE(sceneSession->onMainModalTypeChange_, nullptr);
1638 }
1639
1640 /**
1641 * @tc.name: GetSubWindowModalType
1642 * @tc.desc: GetSubWindowModalType
1643 * @tc.type: FUNC
1644 */
1645 HWTEST_F(SceneSessionTest2, GetSubWindowModalType, TestSize.Level1)
1646 {
1647 SessionInfo info;
1648 info.abilityName_ = "ModalType";
1649 info.bundleName_ = "ModalType";
1650 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1651 EXPECT_NE(sceneSession, nullptr);
1652
1653 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1654 EXPECT_NE(property, nullptr);
1655 property->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
1656 sceneSession->SetSessionProperty(property);
1657 auto result = sceneSession->GetSubWindowModalType();
1658 ASSERT_EQ(result, SubWindowModalType::TYPE_DIALOG);
1659 }
1660
1661 /**
1662 * @tc.name: SetWindowAnimationFlag
1663 * @tc.desc: SetWindowAnimationFlag
1664 * @tc.type: FUNC
1665 */
1666 HWTEST_F(SceneSessionTest2, SetWindowAnimationFlag, TestSize.Level1)
1667 {
1668 SessionInfo info;
1669 info.abilityName_ = "SetWindowAnimationFlag";
1670 info.bundleName_ = "SetWindowAnimationFlag";
1671 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1672 EXPECT_NE(sceneSession, nullptr);
1673
__anonbd5ae67e1502(bool isNeedDefaultAnimationFlag) 1674 sceneSession->onWindowAnimationFlagChange_ = [](bool isNeedDefaultAnimationFlag) {};
1675 sceneSession->SetWindowAnimationFlag(true);
1676 ASSERT_EQ(true, sceneSession->needDefaultAnimationFlag_);
1677 }
1678
1679 /**
1680 * @tc.name: IsFullScreenMovable
1681 * @tc.desc: IsFullScreenMovable
1682 * @tc.type: FUNC
1683 */
1684 HWTEST_F(SceneSessionTest2, IsFullScreenMovable, TestSize.Level1)
1685 {
1686 SessionInfo info;
1687 info.abilityName_ = "IsFullScreenMovable";
1688 info.bundleName_ = "IsFullScreenMovable";
1689 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1690 EXPECT_NE(sceneSession, nullptr);
1691 auto result = sceneSession->IsFullScreenMovable();
1692 ASSERT_EQ(true, result);
1693 }
1694
1695 /**
1696 * @tc.name: SetTitleAndDockHoverShowChangeCallback
1697 * @tc.desc: SetTitleAndDockHoverShowChangeCallback
1698 * @tc.type: FUNC
1699 */
1700 HWTEST_F(SceneSessionTest2, SetTitleAndDockHoverShowChangeCallback, TestSize.Level1)
1701 {
1702 SessionInfo info;
1703 info.abilityName_ = "SetTitleAndDockHoverShowChangeCallback";
1704 info.bundleName_ = "SetTitleAndDockHoverShowChangeCallback";
1705 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
__anonbd5ae67e1602(bool isTitleHoverShown, bool isDockHoverShown) 1706 sceneSession->SetTitleAndDockHoverShowChangeCallback([](bool isTitleHoverShown, bool isDockHoverShown) { return; });
1707 EXPECT_NE(sceneSession->onTitleAndDockHoverShowChangeFunc_, nullptr);
1708 }
1709
1710 /**
1711 * @tc.name: HandleMoveDragEvent
1712 * @tc.desc: HandleMoveDragEvent function01
1713 * @tc.type: FUNC
1714 */
1715 HWTEST_F(SceneSessionTest2, HandleMoveDragEvent, TestSize.Level1)
1716 {
1717 SessionInfo info;
1718 info.abilityName_ = "HandleMoveDragEvent";
1719 info.bundleName_ = "HandleMoveDragEvent";
1720 info.windowType_ = static_cast<uint32_t>(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1721 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1722 SizeChangeReason reason = { SizeChangeReason::DRAG };
1723 session->HandleMoveDragEvent(reason);
1724 SessionEvent event = { SessionEvent::EVENT_DRAG };
1725 EXPECT_EQ(WSError::WS_OK, session->OnSessionEvent(event));
1726
1727 auto moveDragController = sptr<MoveDragController>::MakeSptr(2024, session->GetWindowType());
1728 session->moveDragController_ = moveDragController;
1729 session->moveDragController_->isStartDrag_ = true;
1730 session->systemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
1731 session->systemConfig_.freeMultiWindowSupport_ = true;
1732 session->systemConfig_.freeMultiWindowEnable_ = true;
1733 session->dragResizeTypeDuringDrag_ = DragResizeType::RESIZE_SCALE;
1734 session->compatibleDragScaleFlags_ = true;
1735
1736 session->SetRequestNextVsyncFunc(nullptr);
1737 ASSERT_EQ(nullptr, session->requestNextVsyncFunc_);
1738 session->HandleMoveDragEvent(reason);
1739
__anonbd5ae67e1702(const std::shared_ptr<VsyncCallback>& callback) 1740 session->SetRequestNextVsyncFunc([](const std::shared_ptr<VsyncCallback>& callback) {
1741 SessionInfo info1;
1742 info1.abilityName_ = "HandleMoveDragEventRequestNextVsync";
1743 info1.bundleName_ = "HandleMoveDragEventRequestNextVsync";
1744 });
1745 ASSERT_NE(nullptr, session->requestNextVsyncFunc_);
1746 session->HandleMoveDragEvent(reason);
1747 EXPECT_EQ(WSError::WS_OK, session->OnSessionEvent(event));
1748 }
1749
1750 /**
1751 * @tc.name: IsDragResizeScale
1752 * @tc.desc: IsDragResizeScale function01
1753 * @tc.type: FUNC
1754 */
1755 HWTEST_F(SceneSessionTest2, IsDragResizeScale, Function | SmallTest | Level2)
1756 {
1757 SessionInfo info;
1758 info.abilityName_ = "IsDragResizeScale";
1759 info.bundleName_ = "IsDragResizeScale";
1760 info.windowType_ = static_cast<uint32_t>(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1761 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1762 EXPECT_NE(session, nullptr);
1763 auto oriProperty = session->GetSessionProperty();
1764 session->property_ = nullptr;
1765 SizeChangeReason reason = { SizeChangeReason::DRAG_START };
1766 EXPECT_EQ(session->IsDragResizeScale(reason), false);
1767
1768 reason = { SizeChangeReason::DRAG_END };
1769 EXPECT_EQ(session->IsDragResizeScale(reason), false);
1770
1771 session->property_ = oriProperty;
1772 reason = { SizeChangeReason::DRAG };
1773 auto moveDragController = sptr<MoveDragController>::MakeSptr(2024, session->GetWindowType());
1774 session->moveDragController_ = moveDragController;
1775
1776 session->systemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
1777 session->systemConfig_.freeMultiWindowSupport_ = true;
1778 session->systemConfig_.freeMultiWindowEnable_ = true;
1779 session->dragResizeTypeDuringDrag_ = DragResizeType::RESIZE_SCALE;
1780 session->moveDragController_->isStartDrag_ = true;
1781 session->compatibleDragScaleFlags_ = true;
1782 EXPECT_EQ(session->IsDragResizeScale(reason), true);
1783 }
1784 } // namespace
1785 } // namespace Rosen
1786 } // namespace OHOS