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