1 /*
2 * Copyright (c) 2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <gtest/gtest.h>
17 #include <pointer_event.h>
18 #include <transaction/rs_transaction.h>
19
20 #include "display_manager.h"
21 #include "input_event.h"
22 #include "key_event.h"
23 #include "mock/mock_session_stage.h"
24 #include "mock/mock_accesstoken_kit.h"
25 #include "screen_manager.h"
26 #include "screen_session_manager_client/include/screen_session_manager_client.h"
27 #include "session/host/include/sub_session.h"
28 #include "session/host/include/main_session.h"
29 #include "session/host/include/scene_session.h"
30 #include "session/host/include/system_session.h"
31 #include <ui/rs_surface_node.h>
32 #include "wm_common.h"
33 #include "dm_common.h"
34 #include "parameters.h"
35
36 using namespace testing;
37 using namespace testing::ext;
38 namespace OHOS {
39 namespace Rosen {
40 namespace {
41 constexpr uint32_t SLEEP_TIME = 100000; // 100ms
42 std::string g_errlog;
ScreenSessionLogCallback(const LogType type,const LogLevel level,const unsigned int domain,const char * tag,const char * msg)43 void ScreenSessionLogCallback(const LogType type,
44 const LogLevel level,
45 const unsigned int domain,
46 const char* tag,
47 const char* msg)
48 {
49 g_errlog = msg;
50 }
51 } // namespace
52
53 class SceneSessionTest6 : public testing::Test {
54 public:
55 static void SetUpTestCase();
56 static void TearDownTestCase();
57 void SetUp() override;
58 void TearDown() override;
59 };
60
SetUpTestCase()61 void SceneSessionTest6::SetUpTestCase() {}
62
TearDownTestCase()63 void SceneSessionTest6::TearDownTestCase() {}
64
SetUp()65 void SceneSessionTest6::SetUp() {}
66
TearDown()67 void SceneSessionTest6::TearDown() {}
68
69 namespace {
70
71 /**
72 * @tc.name: RegisterNotifySurfaceBoundsChangeFunc
73 * @tc.desc: RegisterNotifySurfaceBoundsChangeFunc
74 * @tc.type: FUNC
75 */
76 HWTEST_F(SceneSessionTest6, RegisterNotifySurfaceBoundsChangeFunc01, TestSize.Level1)
77 {
78 SessionInfo info;
79 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
80 constexpr int sessionId = 10001;
81 sceneSession->RegisterNotifySurfaceBoundsChangeFunc(sessionId, nullptr);
82 ASSERT_EQ(nullptr, sceneSession->notifySurfaceBoundsChangeFuncMap_[sessionId]);
83
__anonbda348820302(const WSRect& rect, bool isGlobal, bool needFlush) 84 auto task = [](const WSRect& rect, bool isGlobal, bool needFlush) {};
85 sceneSession->RegisterNotifySurfaceBoundsChangeFunc(sessionId, std::move(task));
86 ASSERT_NE(nullptr, sceneSession->notifySurfaceBoundsChangeFuncMap_[sessionId]);
87
88 sceneSession->UnregisterNotifySurfaceBoundsChangeFunc(sessionId);
89 ASSERT_EQ(nullptr, sceneSession->notifySurfaceBoundsChangeFuncMap_[sessionId]);
90 }
91
92 /**
93 * @tc.name: NotifyUpdateGravity
94 * @tc.desc: NotifyUpdateGravity
95 * @tc.type: FUNC
96 */
97 HWTEST_F(SceneSessionTest6, NotifyUpdateGravity01, TestSize.Level1)
98 {
99 SessionInfo info;
100 sptr<SceneSession> subSession = sptr<SceneSession>::MakeSptr(info, nullptr);
101 int32_t subSessionId = subSession->GetPersistentId();
102
103 sptr<MainSession> mainSession = sptr<MainSession>::MakeSptr(info, nullptr);
104 ASSERT_NE(nullptr, mainSession);
105
106 constexpr int sessionId = 10001;
__anonbda348820402(const WSRect& rect, bool isGlobal, bool needFlush) 107 auto task = [](const WSRect& rect, bool isGlobal, bool needFlush) {};
108 mainSession->RegisterNotifySurfaceBoundsChangeFunc(sessionId, std::move(task));
109 mainSession->NotifyUpdateGravity();
110 ASSERT_NE(nullptr, mainSession->notifySurfaceBoundsChangeFuncMap_[sessionId]);
111
112 subSession->isFollowParentLayout_ = false;
113 mainSession->RegisterNotifySurfaceBoundsChangeFunc(subSessionId, std::move(task));
114 mainSession->NotifyUpdateGravity();
115 ASSERT_NE(nullptr, mainSession->notifySurfaceBoundsChangeFuncMap_[subSessionId]);
116
117 subSession->isFollowParentLayout_ = true;
118 mainSession->NotifyUpdateGravity();
119 ASSERT_NE(nullptr, mainSession->notifySurfaceBoundsChangeFuncMap_[subSessionId]);
120
121 sptr<MoveDragController> followController =
122 sptr<MoveDragController>::MakeSptr(subSessionId, subSession->GetWindowType());
123 ASSERT_NE(nullptr, followController);
124 struct RSSurfaceNodeConfig config;
125 std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Create(config);
126 ASSERT_NE(nullptr, surfaceNode);
127 subSession->surfaceNode_ = nullptr;
128 subSession->moveDragController_ = nullptr;
129 mainSession->NotifyUpdateGravity();
130 ASSERT_NE(nullptr, mainSession->notifySurfaceBoundsChangeFuncMap_[subSessionId]);
131
132 subSession->surfaceNode_ = surfaceNode;
133 mainSession->NotifyUpdateGravity();
134 ASSERT_NE(nullptr, mainSession->notifySurfaceBoundsChangeFuncMap_[subSessionId]);
135
136 subSession->moveDragController_ = followController;
137 mainSession->NotifyUpdateGravity();
138 ASSERT_NE(nullptr, mainSession->notifySurfaceBoundsChangeFuncMap_[subSessionId]);
139 }
140
141 /**
142 * @tc.name: GetSceneSessionById
143 * @tc.desc: GetSceneSessionById
144 * @tc.type: FUNC
145 */
146 HWTEST_F(SceneSessionTest6, GetSceneSessionById01, TestSize.Level1)
147 {
148 SessionInfo info;
149 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
150 sptr<SceneSession> findSession = sptr<SceneSession>::MakeSptr(info, nullptr);
151
152 sceneSession->specificCallback_ = nullptr;
153 sptr<SceneSession> ret = sceneSession->GetSceneSessionById(findSession->GetPersistentId());
154 ASSERT_EQ(nullptr, ret);
155
156 sptr<SceneSession::SpecificSessionCallback> callBack = sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
157 ASSERT_NE(nullptr, callBack);
158 sceneSession->specificCallback_ = callBack;
159 ret = sceneSession->GetSceneSessionById(findSession->GetPersistentId());
160 ASSERT_EQ(nullptr, ret);
161
__anonbda348820502(int32_t persistentId) 162 auto task = [&findSession](int32_t persistentId) { return findSession; };
163 callBack->onGetSceneSessionByIdCallback_ = task;
164 ret = sceneSession->GetSceneSessionById(findSession->GetPersistentId());
165 ASSERT_EQ(findSession->GetPersistentId(), ret->GetPersistentId());
166 }
167
168 /**
169 * @tc.name: SetWindowAnchorInfoChangeFunc
170 * @tc.desc: SetWindowAnchorInfoChangeFunc
171 * @tc.type: FUNC
172 */
173 HWTEST_F(SceneSessionTest6, SetWindowAnchorInfoChangeFunc01, TestSize.Level1)
174 {
175 SessionInfo info;
176 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
177
178 sceneSession->SetWindowAnchorInfoChangeFunc(nullptr);
179 EXPECT_EQ(nullptr, sceneSession->onWindowAnchorInfoChangeFunc_);
180
__anonbda348820602(const WindowAnchorInfo& windowAnchorInfo) 181 NotifyWindowAnchorInfoChangeFunc func = [](const WindowAnchorInfo& windowAnchorInfo) {};
182 sceneSession->SetWindowAnchorInfoChangeFunc(std::move(func));
183 EXPECT_NE(nullptr, sceneSession->onWindowAnchorInfoChangeFunc_);
184 }
185
186 /**
187 * @tc.name: SetWindowAnchorInfo
188 * @tc.desc: SetWindowAnchorInfo01, check the param
189 * @tc.type: FUNC
190 */
191 HWTEST_F(SceneSessionTest6, SetWindowAnchorInfo01, TestSize.Level1)
192 {
193 SessionInfo info;
194 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
195 WindowAnchorInfo windowAnchorInfo = { true, WindowAnchor::TOP_START, 0, 0 };
196
197 WSError ret = sceneSession->SetWindowAnchorInfo(windowAnchorInfo);
198 EXPECT_EQ(ret, WSError::WS_ERROR_INVALID_OPERATION);
199
200 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
201 ASSERT_NE(nullptr, property);
202 sceneSession->property_ = property;
203 property->subWindowLevel_ = 100;
204 property->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
205 ret = sceneSession->SetWindowAnchorInfo(windowAnchorInfo);
206 EXPECT_EQ(ret, WSError::WS_ERROR_INVALID_OPERATION);
207
208 property->subWindowLevel_ = 1;
209 property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
210 ret = sceneSession->SetWindowAnchorInfo(windowAnchorInfo);
211 EXPECT_EQ(ret, WSError::WS_ERROR_INVALID_OPERATION);
212
213 property->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
214 ret = sceneSession->SetWindowAnchorInfo(windowAnchorInfo);
215 EXPECT_EQ(ret, WSError::WS_ERROR_DEVICE_NOT_SUPPORT);
216
217 sceneSession->isFollowParentLayout_ = true;
218 ret = sceneSession->SetWindowAnchorInfo(windowAnchorInfo);
219 EXPECT_EQ(ret, WSError::WS_ERROR_INVALID_OPERATION);
220
221 sceneSession->isFollowParentLayout_ = false;
222 sceneSession->systemConfig_.supportFollowRelativePositionToParent_ = true;
223 ret = sceneSession->SetWindowAnchorInfo(windowAnchorInfo);
224 EXPECT_EQ(ret, WSError::WS_OK);
225 }
226
227 /**
228 * @tc.name: SetWindowAnchorInfo
229 * @tc.desc: SetWindowAnchorInfo02
230 * @tc.type: FUNC
231 */
232 HWTEST_F(SceneSessionTest6, SetWindowAnchorInfo02, TestSize.Level1)
233 {
234 SessionInfo info;
235 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
236 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
237 ASSERT_NE(nullptr, property);
238 property->subWindowLevel_ = 1;
239 property->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
240 sceneSession->property_ = property;
241 sceneSession->systemConfig_.supportFollowRelativePositionToParent_ = true;
242 // test set isAnchorEnabled_
243 sceneSession->windowAnchorInfo_.isAnchorEnabled_ = false;
244 WindowAnchorInfo windowAnchorInfo = { true, WindowAnchor::TOP_START, 0, 0 };
245 sceneSession->SetWindowAnchorInfo(windowAnchorInfo);
246 EXPECT_TRUE(sceneSession->windowAnchorInfo_.isAnchorEnabled_);
247
248 //test after set flag, call func
249 std::shared_ptr<bool> isCall = std::make_shared<bool>(false);
__anonbda348820702(const WindowAnchorInfo& windowAnchorInfo) 250 NotifyWindowAnchorInfoChangeFunc callback = [isCall](const WindowAnchorInfo& windowAnchorInfo) {
251 *isCall = true;
252 };
253 sceneSession->SetWindowAnchorInfoChangeFunc(std::move(callback));
254 EXPECT_NE(nullptr, sceneSession->onWindowAnchorInfoChangeFunc_);
255 sceneSession->SetWindowAnchorInfo(windowAnchorInfo);
256 EXPECT_TRUE(*isCall);
257 }
258
259 /**
260 * @tc.name: CalcSubWindowRectByAnchor01
261 * @tc.desc: CalcSubWindowRectByAnchor01, check the param
262 * @tc.type: FUNC
263 */
264 HWTEST_F(SceneSessionTest6, CalcSubWindowRectByAnchor01, TestSize.Level1)
265 {
266 SessionInfo info;
267 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
268 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
269 property->subWindowLevel_ = 1;
270 property->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
271 sceneSession->property_ = property;
272 sceneSession->systemConfig_.supportFollowRelativePositionToParent_ = true;
273
274 WindowAnchorInfo windowAnchorInfo = { false, WindowAnchor::TOP_START, 0, 0 };
275 WSError ret = sceneSession->SetWindowAnchorInfo(windowAnchorInfo);
276 EXPECT_EQ(ret, WSError::WS_OK);
277
278 WSRect parentRect;
279 WSRect subRect;
280 WSRect retRect;
281 sceneSession->CalcSubWindowRectByAnchor(parentRect, subRect);
282 EXPECT_EQ(subRect, retRect);
283
284 parentRect = {0, 0, 1000, 1000};
285 subRect = {0, 0, 400, 400};
286 retRect = {0, 0, 400, 400};
287 sceneSession->CalcSubWindowRectByAnchor(parentRect, subRect);
288 EXPECT_EQ(subRect, retRect);
289
290 sceneSession->windowAnchorInfo_.isAnchorEnabled_ = true;
291 sceneSession->CalcSubWindowRectByAnchor(parentRect, subRect);
292 EXPECT_EQ(subRect, retRect);
293 }
294
295 /**
296 * @tc.name: CalcSubWindowRectByAnchor02
297 * @tc.desc: CalcSubWindowRectByAnchor02
298 * @tc.type: FUNC
299 */
300 HWTEST_F(SceneSessionTest6, CalcSubWindowRectByAnchor02, TestSize.Level1)
301 {
302 SessionInfo info;
303 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
304 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
305 property->subWindowLevel_ = 1;
306 property->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
307 sceneSession->property_ = property;
308 sceneSession->systemConfig_.supportFollowRelativePositionToParent_ = true;
309
310 WindowAnchorInfo windowAnchorInfo = { true, WindowAnchor::TOP_START, 0, 0 };
311 WSError ret = sceneSession->SetWindowAnchorInfo(windowAnchorInfo);
312 EXPECT_EQ(ret, WSError::WS_OK);
313
314 WSRect parentRect = {0, 0, 1000, 1000};
315 WSRect subRect = {0, 0, 400, 400};
316 WSRect retRect;
317
318 sceneSession->CalcSubWindowRectByAnchor(parentRect, subRect);
319 retRect = {0, 0, 400, 400};
320 EXPECT_EQ(subRect, retRect);
321
322 sceneSession->windowAnchorInfo_.windowAnchor_ = WindowAnchor::TOP;
323 sceneSession->CalcSubWindowRectByAnchor(parentRect, subRect);
324 retRect = {300, 0, 400, 400};
325 EXPECT_EQ(subRect, retRect);
326
327 sceneSession->windowAnchorInfo_.windowAnchor_ = WindowAnchor::TOP_END;
328 sceneSession->CalcSubWindowRectByAnchor(parentRect, subRect);
329 retRect = {600, 0, 400, 400};
330 EXPECT_EQ(subRect, retRect);
331
332 sceneSession->windowAnchorInfo_.windowAnchor_ = WindowAnchor::START;
333 sceneSession->CalcSubWindowRectByAnchor(parentRect, subRect);
334 retRect = {0, 300, 400, 400};
335 EXPECT_EQ(subRect, retRect);
336 }
337
338 /**
339 * @tc.name: CalcSubWindowRectByAnchor03
340 * @tc.desc: CalcSubWindowRectByAnchor03
341 * @tc.type: FUNC
342 */
343 HWTEST_F(SceneSessionTest6, CalcSubWindowRectByAnchor03, TestSize.Level1)
344 {
345 SessionInfo info;
346 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
347 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
348 property->subWindowLevel_ = 1;
349 property->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
350 sceneSession->property_ = property;
351 sceneSession->systemConfig_.supportFollowRelativePositionToParent_ = true;
352
353 WindowAnchorInfo windowAnchorInfo = { true, WindowAnchor::CENTER, 0, 0 };
354 WSError ret = sceneSession->SetWindowAnchorInfo(windowAnchorInfo);
355 EXPECT_EQ(ret, WSError::WS_OK);
356
357 WSRect parentRect = {0, 0, 1000, 1000};
358 WSRect subRect = {0, 0, 400, 400};
359 WSRect retRect;
360
361 sceneSession->CalcSubWindowRectByAnchor(parentRect, subRect);
362 retRect = {300, 300, 400, 400};
363 EXPECT_EQ(subRect, retRect);
364
365 sceneSession->windowAnchorInfo_.windowAnchor_ = WindowAnchor::END;
366 sceneSession->CalcSubWindowRectByAnchor(parentRect, subRect);
367 retRect = {600, 300, 400, 400};
368 EXPECT_EQ(subRect, retRect);
369
370 sceneSession->windowAnchorInfo_.windowAnchor_ = WindowAnchor::BOTTOM_START;
371 sceneSession->CalcSubWindowRectByAnchor(parentRect, subRect);
372 retRect = {0, 600, 400, 400};
373 EXPECT_EQ(subRect, retRect);
374
375 sceneSession->windowAnchorInfo_.windowAnchor_ = WindowAnchor::BOTTOM;
376 sceneSession->CalcSubWindowRectByAnchor(parentRect, subRect);
377 retRect = {300, 600, 400, 400};
378 EXPECT_EQ(subRect, retRect);
379
380 sceneSession->windowAnchorInfo_.windowAnchor_ = WindowAnchor::BOTTOM_END;
381 sceneSession->CalcSubWindowRectByAnchor(parentRect, subRect);
382 retRect = {600, 600, 400, 400};
383 EXPECT_EQ(subRect, retRect);
384 }
385
386 /**
387 * @tc.name: SetFollowParentRectFunc
388 * @tc.desc: SetFollowParentRectFunc
389 * @tc.type: FUNC
390 */
391 HWTEST_F(SceneSessionTest6, SetFollowParentRectFunc01, TestSize.Level1)
392 {
393 SessionInfo info;
394 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
395
396 sceneSession->SetFollowParentRectFunc(nullptr);
397 ASSERT_EQ(nullptr, sceneSession->followParentRectFunc_);
398
__anonbda348820802(bool isFollow) 399 NotifyFollowParentRectFunc func = [](bool isFollow) {};
400 sceneSession->SetFollowParentRectFunc(std::move(func));
401 ASSERT_NE(nullptr, sceneSession->followParentRectFunc_);
402 }
403
404 /**
405 * @tc.name: SetFollowParentWindowLayoutEnabled
406 * @tc.desc: SetFollowParentWindowLayoutEnabled01, check the param
407 * @tc.type: FUNC
408 */
409 HWTEST_F(SceneSessionTest6, SetFollowParentWindowLayoutEnabled01, TestSize.Level1)
410 {
411 SessionInfo info;
412 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
413
414 WSError ret = sceneSession->SetFollowParentWindowLayoutEnabled(true);
415 ASSERT_EQ(ret, WSError::WS_ERROR_INVALID_OPERATION);
416
417 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
418 ASSERT_NE(nullptr, property);
419 sceneSession->property_ = property;
420 sceneSession->systemConfig_.supportFollowParentWindowLayout_ = true;
421 property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
422 ret = sceneSession->SetFollowParentWindowLayoutEnabled(true);
423 ASSERT_EQ(ret, WSError::WS_ERROR_INVALID_OPERATION);
424
425 property->subWindowLevel_ = 100;
426 property->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
427 ret = sceneSession->SetFollowParentWindowLayoutEnabled(true);
428 ASSERT_EQ(ret, WSError::WS_ERROR_INVALID_OPERATION);
429
430 property->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
431 ret = sceneSession->SetFollowParentWindowLayoutEnabled(true);
432 ASSERT_EQ(ret, WSError::WS_ERROR_INVALID_OPERATION);
433
434 property->subWindowLevel_ = 1;
435 ret = sceneSession->SetFollowParentWindowLayoutEnabled(true);
436 ASSERT_EQ(ret, WSError::WS_OK);
437
438 property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
439 ret = sceneSession->SetFollowParentWindowLayoutEnabled(true);
440 ASSERT_EQ(ret, WSError::WS_ERROR_INVALID_OPERATION);
441
442 property->subWindowLevel_ = 1;
443 property->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
444 sceneSession->systemConfig_.supportFollowParentWindowLayout_ = false;
445 ret = sceneSession->SetFollowParentWindowLayoutEnabled(true);
446 ASSERT_EQ(ret, WSError::WS_ERROR_DEVICE_NOT_SUPPORT);
447 }
448
449
450 /**
451 * @tc.name: SetFollowParentWindowLayoutEnabled
452 * @tc.desc: SetFollowParentWindowLayoutEnabled02
453 * @tc.type: FUNC
454 */
455 HWTEST_F(SceneSessionTest6, SetFollowParentWindowLayoutEnabled02, TestSize.Level1)
456 {
457 SessionInfo info;
458 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
459 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
460 ASSERT_NE(nullptr, property);
461 property->subWindowLevel_ = 1;
462 property->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
463 sceneSession->property_ = property;
464 sceneSession->systemConfig_.supportFollowParentWindowLayout_ = true;
465 // test set isFollowParentLayout_
466 sceneSession->isFollowParentLayout_ = false;
467 sceneSession->SetFollowParentWindowLayoutEnabled(true);
468 ASSERT_TRUE(sceneSession->isFollowParentLayout_);
469 // test after set flag, call func
470 bool isCall = false;
__anonbda348820902(bool isFollow) 471 NotifyFollowParentRectFunc func = [&isCall](bool isFollow) { isCall = true; };
472 sceneSession->SetFollowParentRectFunc(std::move(func));
473 ASSERT_NE(nullptr, sceneSession->followParentRectFunc_);
474 sceneSession->SetFollowParentWindowLayoutEnabled(true);
475 ASSERT_TRUE(isCall);
476 }
477
478 /**
479 * @tc.name: SetFollowParentWindowLayoutEnabled
480 * @tc.desc: SetFollowParentWindowLayoutEnabled03, test register callback
481 * @tc.type: FUNC
482 */
483 HWTEST_F(SceneSessionTest6, SetFollowParentWindowLayoutEnabled03, TestSize.Level1)
484 {
485 SessionInfo info;
486 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
487
488 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
489 property->subWindowLevel_ = 1;
490 property->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
491 sceneSession->property_ = property;
492 sceneSession->systemConfig_.supportFollowParentWindowLayout_ = true;
493
494 sptr<MainSession> parentSession = sptr<MainSession>::MakeSptr(info, nullptr);
495 ASSERT_NE(nullptr, parentSession);
496
497 sceneSession->parentSession_ = parentSession;
498 sceneSession->SetFollowParentWindowLayoutEnabled(true);
499 ASSERT_NE(nullptr, parentSession->notifySurfaceBoundsChangeFuncMap_[sceneSession->GetPersistentId()]);
500 WSRect rect;
501 parentSession->NotifySubAndDialogFollowRectChange(rect, false, false);
502
503 sceneSession->SetFollowParentWindowLayoutEnabled(false);
504 ASSERT_EQ(nullptr, parentSession->notifySurfaceBoundsChangeFuncMap_[sceneSession->GetPersistentId()]);
505 }
506
507 /**
508 * @tc.name: NotifyKeyboardAnimationCompleted
509 * @tc.desc: NotifyKeyboardAnimationCompleted
510 * @tc.type: FUNC
511 */
512 HWTEST_F(SceneSessionTest6, NotifyKeyboardAnimationCompleted, Function | SmallTest | Level1)
513 {
514 SessionInfo info;
515 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
516 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
517 sceneSession->property_ = property;
518 sceneSession->sessionStage_ = nullptr;
519 bool isShowAnimation = true;
520 WSRect beginRect = { 0, 2720, 1260, 1020 };
521 WSRect endRect = { 0, 1700, 1260, 1020 };
522 sceneSession->NotifyKeyboardAnimationCompleted(isShowAnimation, beginRect, endRect);
523 sceneSession->sessionStage_ = sptr<SessionStageMocker>::MakeSptr();
524 EXPECT_NE(nullptr, sceneSession->sessionStage_);
525
526 sceneSession->NotifyKeyboardDidShowRegistered(true);
527 sceneSession->NotifyKeyboardAnimationCompleted(isShowAnimation, beginRect, endRect);
528
529 isShowAnimation = false;
530 beginRect = { 0, 1700, 1260, 1020 };
531 endRect = { 0, 2720, 1260, 1020 };
532 sceneSession->NotifyKeyboardAnimationCompleted(isShowAnimation, beginRect, endRect);
533 sceneSession->NotifyKeyboardDidHideRegistered(true);
534 sceneSession->NotifyKeyboardAnimationCompleted(isShowAnimation, beginRect, endRect);
535 }
536
537 /**
538 * @tc.name: IsInCompatScaleStatus
539 * @tc.desc: IsInCompatScaleStatus
540 * @tc.type: FUNC
541 */
542 HWTEST_F(SceneSessionTest6, IsInCompatScaleStatus, TestSize.Level1)
543 {
544 SessionInfo info;
545 info.abilityName_ = "IsInCompatScaleStatus";
546 info.bundleName_ = "IsInCompatScaleStatus";
547 info.screenId_ = 0;
548 sptr<SceneSession> session = sptr<MainSession>::MakeSptr(info, nullptr);
549
550 EXPECT_FALSE(session->IsInCompatScaleStatus());
551 session->SetScale(1.0f, 1.0f, 0.5f, 0.5f);
552
553 sptr<CompatibleModeProperty> compatibleModeProperty = sptr<CompatibleModeProperty>::MakeSptr();
554 compatibleModeProperty->SetIsAdaptToProportionalScale(true);
555 session->property_->SetCompatibleModeProperty(compatibleModeProperty);
556 EXPECT_FALSE(session->IsInCompatScaleStatus());
557
558 compatibleModeProperty->SetIsAdaptToProportionalScale(false);
559 compatibleModeProperty->SetIsAdaptToSimulationScale(true);
560 EXPECT_FALSE(session->IsInCompatScaleStatus());
561 compatibleModeProperty->SetIsAdaptToProportionalScale(true);
562 EXPECT_FALSE(session->IsInCompatScaleStatus());
563
564 session->SetScale(2.0f, 1.0f, 0.5f, 0.5f);
565 EXPECT_TRUE(session->IsInCompatScaleStatus());
566 session->SetScale(2.0f, 0.5f, 0.5f, 0.5f);
567 EXPECT_TRUE(session->IsInCompatScaleStatus());
568 }
569
570 /**
571 * @tc.name: IsInCompatScaleMode
572 * @tc.desc: IsInCompatScaleMode
573 * @tc.type: FUNC
574 */
575 HWTEST_F(SceneSessionTest6, IsInCompatScaleMode, TestSize.Level1)
576 {
577 SessionInfo info;
578 info.abilityName_ = "IsInCompatScaleMode";
579 info.bundleName_ = "IsInCompatScaleMode";
580 info.screenId_ = 0;
581 sptr<SceneSession> session = sptr<MainSession>::MakeSptr(info, nullptr);
582 EXPECT_FALSE(session->IsInCompatScaleMode());
583
584 sptr<CompatibleModeProperty> compatibleModeProperty = sptr<CompatibleModeProperty>::MakeSptr();
585 compatibleModeProperty->SetIsAdaptToProportionalScale(true);
586 session->property_->SetCompatibleModeProperty(compatibleModeProperty);
587 EXPECT_TRUE(session->IsInCompatScaleMode());
588
589 compatibleModeProperty->SetIsAdaptToProportionalScale(false);
590 compatibleModeProperty->SetIsAdaptToSimulationScale(true);
591 EXPECT_TRUE(session->IsInCompatScaleMode());
592 compatibleModeProperty->SetIsAdaptToProportionalScale(true);
593 EXPECT_TRUE(session->IsInCompatScaleMode());
594 }
595
596 /**
597 * @tc.name: GetSystemAvoidArea
598 * @tc.desc: GetSystemAvoidArea function
599 * @tc.type: FUNC
600 */
601 HWTEST_F(SceneSessionTest6, GetSystemAvoidArea, Function | SmallTest | Level1)
602 {
603 SessionInfo info;
604 info.abilityName_ = "GetSystemAvoidArea";
605 info.bundleName_ = "GetSystemAvoidArea";
606
607 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
608 ASSERT_NE(session, nullptr);
609 ASSERT_NE(session->GetSessionProperty(), nullptr);
610 session->GetSessionProperty()->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
611 EXPECT_EQ(WindowMode::WINDOW_MODE_FLOATING, session->GetSessionProperty()->GetWindowMode());
612 info.windowType_ = static_cast<uint32_t>(WindowType::APP_MAIN_WINDOW_BASE);
613
614 SystemSessionConfig systemConfig;
615 systemConfig.windowUIType_ = WindowUIType::PHONE_WINDOW;
616 session->SetSystemConfig(systemConfig);
617 ScreenSessionManagerClient::GetInstance().screenSessionMap_.clear();
618 session->GetSessionProperty()->SetDisplayId(2025);
619 session->SetIsMidScene(false);
620 EXPECT_EQ(session->GetIsMidScene(), false);
621
622 WSRect rect;
623 AvoidArea avoidArea;
624 session->GetSystemAvoidArea(rect, avoidArea);
625 int32_t height = session->GetStatusBarHeight();
626 EXPECT_EQ(height, avoidArea.topRect_.height_);
627
__anonbda348820a02(DisplayId displayId, WSRect& barArea) 628 auto task = [](DisplayId displayId, WSRect& barArea) {
629 barArea.height_ = 100;
630 };
631 session->RegisterGetStatusBarAvoidHeightFunc(std::move(task));
632 session->GetSystemAvoidArea(rect, avoidArea);
633 EXPECT_EQ(0, avoidArea.topRect_.height_);
634 }
635
636 /**
637 * @tc.name: NotifyWindowAttachStateListenerRegistered
638 * @tc.desc: NotifyWindowAttachStateListenerRegistered about session
639 * @tc.type: FUNC
640 */
641 HWTEST_F(SceneSessionTest6, NotifyWindowAttachStateListenerRegistered_session, Function | SmallTest | Level1)
642 {
643 SessionInfo info;
644 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
645 sceneSession->NotifyWindowAttachStateListenerRegistered(true);
646 EXPECT_EQ(sceneSession->needNotifyAttachState_, true);
647 sceneSession->NotifyWindowAttachStateListenerRegistered(false);
648 EXPECT_EQ(sceneSession->needNotifyAttachState_, false);
649 }
650
651 /**
652 * @tc.name: UpdateFollowScreenChange
653 * @tc.desc: UpdateFollowScreenChange
654 * @tc.type: FUNC
655 */
656 HWTEST_F(SceneSessionTest6, UpdateFollowScreenChange, Function | SmallTest | Level1)
657 {
658 SessionInfo info;
659 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
660 ASSERT_NE(nullptr, sceneSession);
661 bool isFollowScreenChange = true;
662 sceneSession->specificCallback_ = nullptr;
663 WSError ret = sceneSession->UpdateFollowScreenChange(isFollowScreenChange);
664 EXPECT_EQ(WSError::WS_OK, ret);
665
666 sptr<SceneSession::SpecificSessionCallback> callback = sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
667 ASSERT_NE(nullptr, callback);
668 sceneSession->specificCallback_ = callback;
669 ret = sceneSession->UpdateFollowScreenChange(isFollowScreenChange);
670 EXPECT_EQ(WSError::WS_OK, ret);
671
__anonbda348820b02(bool isFollowScreenChange) 672 auto task = [] (bool isFollowScreenChange) {};
673 callback->onUpdateFollowScreenChange_ = task;
674 ret = sceneSession->UpdateFollowScreenChange(isFollowScreenChange);
675 EXPECT_EQ(WSError::WS_OK, ret);
676 }
677
678 /**
679 * @tc.name: RegisterFollowScreenChangeCallback
680 * @tc.desc: RegisterFollowScreenChangeCallback
681 * @tc.type: FUNC
682 */
683 HWTEST_F(SceneSessionTest6, RegisterFollowScreenChangeCallback, Function | SmallTest | Level1)
684 {
685 SessionInfo info;
686 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
687 ASSERT_NE(nullptr, sceneSession);
688 sceneSession->specificCallback_ = nullptr;
__anonbda348820c02(bool isFollowScreenChange) 689 auto task = [] (bool isFollowScreenChange) {};
690 sceneSession->RegisterFollowScreenChangeCallback(std::move(task));
691 EXPECT_EQ(nullptr, sceneSession->specificCallback_);
692
693 sptr<SceneSession::SpecificSessionCallback> callback = sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
694 ASSERT_NE(nullptr, callback);
695 sceneSession->specificCallback_ = callback;
696 EXPECT_EQ(nullptr, callback->onUpdateFollowScreenChange_);
697 sceneSession->RegisterFollowScreenChangeCallback(std::move(task));
698 EXPECT_NE(nullptr, callback->onUpdateFollowScreenChange_);
699 }
700
701 /**
702 * @tc.name: GetFollowScreenChange
703 * @tc.desc: GetFollowScreenChange
704 * @tc.type: FUNC
705 */
706 HWTEST_F(SceneSessionTest6, GetFollowScreenChange01, TestSize.Level1)
707 {
708 SessionInfo info;
709 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
710
711 bool isFollowScreenChange = true;
712 sceneSession->SetFollowScreenChange(isFollowScreenChange);
713 bool res = sceneSession->GetFollowScreenChange();
714 EXPECT_EQ(res, isFollowScreenChange);
715
716 isFollowScreenChange = false;
717 sceneSession->SetFollowScreenChange(isFollowScreenChange);
718 res = sceneSession->GetFollowScreenChange();
719 EXPECT_EQ(res, isFollowScreenChange);
720
721 isFollowScreenChange = true;
722 sceneSession->SetFollowScreenChange(isFollowScreenChange);
723 res = sceneSession->GetFollowScreenChange();
724 EXPECT_EQ(res, isFollowScreenChange);
725 }
726
727 /**
728 * @tc.name: HandleActionUpdateFollowScreenChange
729 * @tc.desc: test HandleActionUpdateFollowScreenChange
730 * @tc.type: FUNC
731 */
732 HWTEST_F(SceneSessionTest6, HandleActionUpdateFollowScreenChange, TestSize.Level1)
733 {
734 SessionInfo info;
735 info.abilityName_ = "HandleActionUpdateFollowScreenChange";
736 info.bundleName_ = "HandleActionUpdateFollowScreenChange";
737 info.isSystem_ = true;
738 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
739 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
740 property->SetFollowScreenChange(true);
741 WSPropertyChangeAction action = WSPropertyChangeAction::ACTION_UPDATE_FOLLOW_SCREEN_CHANGE;
742 auto res = session->HandleActionUpdateFollowScreenChange(property, action);
743 EXPECT_EQ(WMError::WM_OK, res);
744 }
745
746 /**
747 * @tc.name: NotifyKeyboardAnimationWillBegin
748 * @tc.desc: test for NotifyKeyboardAnimationWillBegin when sessionStage_ is nullptr
749 * @tc.type: FUNC
750 */
751 HWTEST_F(SceneSessionTest6, NotifyKeyboardAnimationWillBeginInvalidSessionStage, Function | SmallTest | Level1)
752 {
753 g_errlog.clear();
754 LOG_SetCallback(ScreenSessionLogCallback);
755 SessionInfo info;
756 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
757 sceneSession->property_ = sptr<WindowSessionProperty>::MakeSptr();
758 sceneSession->sessionStage_ = nullptr;
759 bool isShowAnimation = true;
760 WSRect beginRect = { 0, 2720, 1260, 1020 };
761 WSRect endRect = { 0, 1700, 1260, 1020 };
762 bool withAnimation = false;
763 const std::shared_ptr<RSTransaction>& rsTransaction = std::make_shared<RSTransaction>();
764 sceneSession->NotifyKeyboardAnimationWillBegin(isShowAnimation, beginRect, endRect, withAnimation, rsTransaction);
765 if (HiLogIsLoggable(HILOG_DOMAIN_WINDOW, g_domainContents[static_cast<uint32_t>(WmsLogTag::DEFAULT)], LOG_DEBUG)) {
766 EXPECT_TRUE(g_errlog.find("sessionStage_ is null") != std::string::npos);
767 }
768 }
769
770 /**
771 * @tc.name: NotifyKeyboardAnimationWillBegin
772 * @tc.desc: NotifyKeyboardAnimationWillBegin when willShow notification not registered
773 * @tc.type: FUNC
774 */
775 HWTEST_F(SceneSessionTest6, NotifyKeyboardAnimationWillBeginNotRegisteredWillShow, Function | SmallTest | Level1)
776 {
777 g_errlog.clear();
778 LOG_SetCallback(ScreenSessionLogCallback);
779 SessionInfo info;
780 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
781 sceneSession->property_ = sptr<WindowSessionProperty>::MakeSptr();
782 bool isShowAnimation = true;
783 WSRect beginRect = { 0, 2720, 1260, 1020 };
784 WSRect endRect = { 0, 1700, 1260, 1020 };
785 bool withAnimation = false;
786 const std::shared_ptr<RSTransaction>& rsTransaction = std::make_shared<RSTransaction>();
787 sceneSession->sessionStage_ = sptr<SessionStageMocker>::MakeSptr();
788
789 sceneSession->NotifyKeyboardWillShowRegistered(false);
790 sceneSession->NotifyKeyboardAnimationWillBegin(isShowAnimation, beginRect, endRect, withAnimation, rsTransaction);
791 EXPECT_TRUE(g_errlog.find("keyboard will show listener is not registered") != std::string::npos);
792 }
793
794 /**
795 * @tc.name: NotifyKeyboardAnimationWillBegin
796 * @tc.desc: NotifyKeyboardAnimationWillBegin when willHide notification not registered
797 * @tc.type: FUNC
798 */
799 HWTEST_F(SceneSessionTest6, NotifyKeyboardAnimationWillBeginNotRegisteredWillHide, Function | SmallTest | Level1)
800 {
801 g_errlog.clear();
802 LOG_SetCallback(ScreenSessionLogCallback);
803 SessionInfo info;
804 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
805 sceneSession->property_ = sptr<WindowSessionProperty>::MakeSptr();
806
807 WSRect beginRect = { 0, 2720, 1260, 1020 };
808 WSRect endRect = { 0, 1700, 1260, 1020 };
809 bool withAnimation = false;
810 const std::shared_ptr<RSTransaction>& rsTransaction = std::make_shared<RSTransaction>();
811 sceneSession->sessionStage_ = sptr<SessionStageMocker>::MakeSptr();
812
813 bool isShowAnimation = false;
814 sceneSession->NotifyKeyboardWillHideRegistered(false);
815 sceneSession->NotifyKeyboardAnimationWillBegin(isShowAnimation, beginRect, endRect, withAnimation, rsTransaction);
816 EXPECT_TRUE(g_errlog.find("keyboard will hide listener is not registered") != std::string::npos);
817 }
818
819 /**
820 * @tc.name: NotifyKeyboardAnimationWillBegin
821 * @tc.desc: NotifyKeyboardAnimationWillBegin when willShow notification registered
822 * @tc.type: FUNC
823 */
824 HWTEST_F(SceneSessionTest6, NotifyKeyboardAnimationWillBeginRegisteredWillShow, Function | SmallTest | Level1)
825 {
826 g_errlog.clear();
827 LOG_SetCallback(ScreenSessionLogCallback);
828 SessionInfo info;
829 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
830 sceneSession->property_ = sptr<WindowSessionProperty>::MakeSptr();
831
832 WSRect beginRect = { 0, 2720, 1260, 1020 };
833 WSRect endRect = { 0, 1700, 1260, 1020 };
834 bool withAnimation = false;
835 const std::shared_ptr<RSTransaction>& rsTransaction = std::make_shared<RSTransaction>();
836 sceneSession->sessionStage_ = sptr<SessionStageMocker>::MakeSptr();
837
838 bool isShowAnimation = true;
839 sceneSession->NotifyKeyboardWillShowRegistered(true);
840 sceneSession->NotifyKeyboardAnimationWillBegin(isShowAnimation, beginRect, endRect, withAnimation, rsTransaction);
841 EXPECT_TRUE(g_errlog.find("keyboard will show listener is not registered") == std::string::npos);
842 }
843
844 /**
845 * @tc.name: NotifyKeyboardAnimationWillBegin
846 * @tc.desc: NotifyKeyboardAnimationWillBegin when willHide notification registered
847 * @tc.type: FUNC
848 */
849 HWTEST_F(SceneSessionTest6, NotifyKeyboardAnimationWillBeginRegisteredWillHide, Function | SmallTest | Level1)
850 {
851 g_errlog.clear();
852 LOG_SetCallback(ScreenSessionLogCallback);
853 SessionInfo info;
854 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
855 sceneSession->property_ = sptr<WindowSessionProperty>::MakeSptr();
856 WSRect beginRect = { 0, 2720, 1260, 1020 };
857 WSRect endRect = { 0, 1700, 1260, 1020 };
858 bool withAnimation = false;
859 const std::shared_ptr<RSTransaction>& rsTransaction = std::make_shared<RSTransaction>();
860 sceneSession->sessionStage_ = sptr<SessionStageMocker>::MakeSptr();
861
862 bool isShowAnimation = false;
863 sceneSession->NotifyKeyboardWillHideRegistered(true);
864 sceneSession->NotifyKeyboardAnimationWillBegin(isShowAnimation, beginRect, endRect, withAnimation, rsTransaction);
865 EXPECT_TRUE(g_errlog.find("keyboard will hide listener is not registered") == std::string::npos);
866 }
867
868 /**
869 * @tc.name: NotifyKeyboardWillShowRegistered
870 * @tc.desc: NotifyKeyboardWillShowRegistered
871 * @tc.type: FUNC
872 */
873 HWTEST_F(SceneSessionTest6, NotifyKeyboardWillShowRegistered, Function | SmallTest | Level1)
874 {
875 SessionInfo info;
876 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
877 sceneSession->NotifyKeyboardWillShowRegistered(true);
878 EXPECT_EQ(true, sceneSession->GetSessionProperty()->EditSessionInfo().isKeyboardWillShowRegistered_);
879 sceneSession->NotifyKeyboardWillShowRegistered(false);
880 EXPECT_EQ(false, sceneSession->GetSessionProperty()->EditSessionInfo().isKeyboardWillShowRegistered_);
881 }
882
883 /**
884 * @tc.name: NotifyKeyboardWillHideRegistered
885 * @tc.desc: NotifyKeyboardWillHideRegistered
886 * @tc.type: FUNC
887 */
888 HWTEST_F(SceneSessionTest6, NotifyKeyboardWillHideRegistered, Function | SmallTest | Level1)
889 {
890 SessionInfo info;
891 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
892 sceneSession->NotifyKeyboardWillHideRegistered(true);
893 EXPECT_EQ(true, sceneSession->GetSessionProperty()->EditSessionInfo().isKeyboardWillHideRegistered_);
894 sceneSession->NotifyKeyboardWillHideRegistered(false);
895 EXPECT_EQ(false, sceneSession->GetSessionProperty()->EditSessionInfo().isKeyboardWillHideRegistered_);
896 }
897
898 /**
899 * @tc.name: NotifyKeyboardDidShowRegistered
900 * @tc.desc: NotifyKeyboardDidShowRegistered
901 * @tc.type: FUNC
902 */
903 HWTEST_F(SceneSessionTest6, NotifyKeyboardDidShowRegistered, Function | SmallTest | Level1)
904 {
905 SessionInfo info;
906 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
907 sceneSession->NotifyKeyboardDidShowRegistered(true);
908 EXPECT_EQ(true, sceneSession->GetSessionProperty()->EditSessionInfo().isKeyboardDidShowRegistered_);
909 sceneSession->NotifyKeyboardDidShowRegistered(false);
910 EXPECT_EQ(false, sceneSession->GetSessionProperty()->EditSessionInfo().isKeyboardDidShowRegistered_);
911 }
912
913 /**
914 * @tc.name: NotifyKeyboardDidHideRegistered
915 * @tc.desc: NotifyKeyboardDidHideRegistered
916 * @tc.type: FUNC
917 */
918 HWTEST_F(SceneSessionTest6, NotifyKeyboardDidHideRegistered, Function | SmallTest | Level1)
919 {
920 SessionInfo info;
921 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
922 sceneSession->NotifyKeyboardDidHideRegistered(true);
923 EXPECT_EQ(true, sceneSession->GetSessionProperty()->EditSessionInfo().isKeyboardDidHideRegistered_);
924 sceneSession->NotifyKeyboardDidHideRegistered(false);
925 EXPECT_EQ(false, sceneSession->GetSessionProperty()->EditSessionInfo().isKeyboardDidHideRegistered_);
926 }
927
928 /**
929 * @tc.name: CloseSpecificScene
930 * @tc.desc: test CloseSpecificScene
931 * @tc.type: FUNC
932 */
933 HWTEST_F(SceneSessionTest6, CloseSpecificScene, TestSize.Level1)
934 {
935 SessionInfo info;
936 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
937 sceneSession->sessionStage_ = nullptr;
938 auto res = sceneSession->CloseSpecificScene();
939 EXPECT_EQ(res, WSError::WS_ERROR_NULLPTR);
940 }
941
942 /**
943 * @tc.name: SetSubWindowSourceFunc
944 * @tc.desc: test SetSubWindowSourceFunc
945 * @tc.type: FUNC
946 */
947 HWTEST_F(SceneSessionTest6, SetSubWindowSourceFunc, TestSize.Level1)
948 {
949 SessionInfo info;
950 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
951 sceneSession->SetSubWindowSourceFunc(nullptr);
952 EXPECT_EQ(nullptr, sceneSession->subWindowSourceFunc_);
__anonbda348820d02(SubWindowSource source) 953 NotifySetSubWindowSourceFunc func = [](SubWindowSource source) {};
954 sceneSession->SetSubWindowSourceFunc(std::move(func));
955 EXPECT_NE(nullptr, sceneSession->subWindowSourceFunc_);
956 }
957
958 /**
959 * @tc.name: SetSubWindowSource
960 * @tc.desc: test SetSubWindowSource
961 * @tc.type: FUNC
962 */
963 HWTEST_F(SceneSessionTest6, SetSubWindowSource, TestSize.Level1)
964 {
965 SessionInfo info;
966 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
967 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
968 ASSERT_NE(nullptr, property);
969 property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
970 auto res = sceneSession->SetSubWindowSource(SubWindowSource::SUB_WINDOW_SOURCE_ARKUI);
971 EXPECT_EQ(WSError::WS_ERROR_INVALID_WINDOW, res);
972 property->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
973 sceneSession->property_ = property;
974 // test set SubWindowSource::SUB_WINDOW_SOURCE_UNKNOWN
975 sceneSession->subWindowSource_ = SubWindowSource::SUB_WINDOW_SOURCE_UNKNOWN;
976 sceneSession->SetSubWindowSource(SubWindowSource::SUB_WINDOW_SOURCE_ARKUI);
977 EXPECT_TRUE(sceneSession->subWindowSource_ == SubWindowSource::SUB_WINDOW_SOURCE_ARKUI);
978 }
979
980 /**
981 * @tc.name: AnimateTo01
982 * @tc.desc: test AnimateTo
983 * @tc.type: FUNC
984 */
985 HWTEST_F(SceneSessionTest6, AnimateTo01, TestSize.Level1)
986 {
987 SessionInfo info;
988 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
989 WindowAnimationProperty animationProperty;
990 animationProperty.targetScale = 1.5f;
991 WindowAnimationOption animationOption;
992 animationOption.curve = WindowAnimationCurve::INTERPOLATION_SPRING;
993 animationOption.duration = 500;
994
995 float resultScale = 0;
996 WindowAnimationCurve curve = WindowAnimationCurve::LINEAR;
997 auto callback = [&resultScale, &curve](const WindowAnimationProperty& animationProperty,
__anonbda348820e02(const WindowAnimationProperty& animationProperty, const WindowAnimationOption& animationOption) 998 const WindowAnimationOption& animationOption) {
999 resultScale = animationProperty.targetScale;
1000 curve = animationOption.curve;
1001 };
1002 sceneSession->AnimateTo(animationProperty, animationOption);
1003 usleep(SLEEP_TIME);
1004 ASSERT_EQ(resultScale, 0);
1005
1006 sceneSession->RegisterAnimateToCallback(callback);
1007 usleep(SLEEP_TIME);
1008 sceneSession->AnimateTo(animationProperty, animationOption);
1009 usleep(SLEEP_TIME);
1010 ASSERT_EQ(resultScale, animationProperty.targetScale);
1011 ASSERT_EQ(curve, WindowAnimationCurve::INTERPOLATION_SPRING);
1012 }
1013
1014 /**
1015 * @tc.name: RegisterUpdateAppUseControlCallback
1016 * @tc.desc: RegisterUpdateAppUseControlCallback
1017 * @tc.type: FUNC
1018 */
1019 HWTEST_F(SceneSessionTest6, RegisterUpdateAppUseControlCallback, Function | SmallTest | Level3)
1020 {
1021 ControlInfo controlInfo = {
1022 .isNeedControl = true,
1023 .isControlRecentOnly = true
1024 };
1025 SessionInfo info;
1026 info.bundleName_ = "app";
1027 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
__anonbda348820f02(ControlAppType type, bool isNeedControl, bool isControlRecentOnly) 1028 auto callback = [](ControlAppType type, bool isNeedControl, bool isControlRecentOnly) {};
1029 sceneSession->RegisterUpdateAppUseControlCallback(callback);
1030
1031 std::unordered_map<std::string, std::unordered_map<ControlAppType, ControlInfo>> allAppUseMap;
1032 sceneSession->SetGetAllAppUseControlMapFunc([&allAppUseMap]() ->
__anonbda348821002() 1033 std::unordered_map<std::string, std::unordered_map<ControlAppType, ControlInfo>>& {return allAppUseMap;});
1034 sceneSession->RegisterUpdateAppUseControlCallback(callback);
1035
1036 std::string key = "app#0";
1037 allAppUseMap[key][ControlAppType::APP_LOCK] = controlInfo;
1038 sceneSession->RegisterUpdateAppUseControlCallback(callback);
1039 ASSERT_NE(nullptr, sceneSession->onUpdateAppUseControlFunc_);
1040 }
1041
1042 /**
1043 * @tc.name: RegisterUpdateAppUseControlCallbackHasPrivacyModeControl
1044 * @tc.desc: RegisterUpdateAppUseControlCallbackHasPrivacyModeControl
1045 * @tc.type: FUNC
1046 */
1047 HWTEST_F(SceneSessionTest6, RegisterUpdateAppUseControlCallbackHasPrivacyModeControl, Function | SmallTest | Level3)
1048 {
1049 SessionInfo info;
1050 info.bundleName_ = "app";
1051 info.hasPrivacyModeControl = true;
1052 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
__anonbda348821102(ControlAppType type, bool isNeedControl, bool isControlRecentOnly) 1053 auto callback = [](ControlAppType type, bool isNeedControl, bool isControlRecentOnly) {};
1054 sceneSession->RegisterUpdateAppUseControlCallback(callback);
1055 usleep(SLEEP_TIME);
1056 EXPECT_TRUE(sceneSession->appUseControlMap_[ControlAppType::PRIVACY_WINDOW].isNeedControl);
1057 }
1058
1059 /**
1060 * @tc.name: GetScreenWidthAndHeightFromClient
1061 * @tc.desc: GetScreenWidthAndHeightFromClient
1062 * @tc.type: FUNC
1063 */
1064 HWTEST_F(SceneSessionTest6, GetScreenWidthAndHeightFromClient, Function | SmallTest | Level3)
1065 {
1066 SessionInfo info;
1067 info.bundleName_ = "GetScreenWidthAndHeightFromClient";
1068 info.abilityName_ = "GetScreenWidthAndHeightFromClient";
1069 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1070 uint32_t screenWidth = 0;
1071 uint32_t screenHeight = 0;
1072 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1073 EXPECT_EQ(sceneSession->GetScreenWidthAndHeightFromClient(property, screenWidth, screenHeight), true);
1074
1075 sceneSession->SetIsSystemKeyboard(true);
1076 EXPECT_EQ(sceneSession->IsSystemKeyboard(), true);
1077 EXPECT_EQ(sceneSession->GetScreenWidthAndHeightFromClient(property, screenWidth, screenHeight), true);
1078 }
1079
1080 /**
1081 * @tc.name: SetFrameRectForPartialZoomIn
1082 * @tc.desc: SetFrameRectForPartialZoomIn
1083 * @tc.type: FUNC
1084 */
1085 HWTEST_F(SceneSessionTest6, SetFrameRectForPartialZoomIn, Function | SmallTest | Level3)
1086 {
1087 SessionInfo info;
1088 info.bundleName_ = "SetFrameRectForPartialZoomIn";
1089 info.abilityName_ = "SetFrameRectForPartialZoomIn";
1090 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1091 Rect frameRect = { 10, 10, 10, 10 }; // 10 is valid frame rect param
1092 MockAccesstokenKit::MockIsSACalling(true);
1093 EXPECT_EQ(sceneSession->SetFrameRectForPartialZoomIn(frameRect), WSError::WS_OK);
1094
1095 MockAccesstokenKit::MockIsSACalling(false);
1096 EXPECT_EQ(sceneSession->SetFrameRectForPartialZoomIn(frameRect), WSError::WS_ERROR_INVALID_PERMISSION);
1097 }
1098
1099 /**
1100 * @tc.name: SetFrameRectForPartialZoomInInner
1101 * @tc.desc: SetFrameRectForPartialZoomInInner
1102 * @tc.type: FUNC
1103 */
1104 HWTEST_F(SceneSessionTest6, SetFrameRectForPartialZoomInInner, Function | SmallTest | Level3)
1105 {
1106 SessionInfo info;
1107 info.bundleName_ = "SetFrameRectForPartialZoomInInner";
1108 info.abilityName_ = "SetFrameRectForPartialZoomInInner";
1109 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1110
1111 Rect frameRect = { 10, 10, 10, 10 }; // 10 is valid frame rect param
1112 WSError ret = sceneSession->SetFrameRectForPartialZoomInInner(frameRect);
1113 EXPECT_EQ(ret, WSError::WS_ERROR_INVALID_WINDOW);
1114
1115 struct RSSurfaceNodeConfig config;
1116 std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Create(config);
1117 EXPECT_NE(surfaceNode, nullptr);
1118 sceneSession->surfaceNode_ = surfaceNode;
1119 ret = sceneSession->SetFrameRectForPartialZoomInInner(frameRect);
1120 EXPECT_EQ(ret, WSError::WS_OK);
1121 }
1122
1123 /**
1124 * @tc.name: SendPointerEventForHover
1125 * @tc.desc: SendPointerEventForHover
1126 * @tc.type: FUNC
1127 */
1128 HWTEST_F(SceneSessionTest6, SendPointerEventForHover, Function | SmallTest | Level3)
1129 {
1130 SessionInfo info;
1131 info.bundleName_ = "SendPointerEventForHover";
1132 info.abilityName_ = "SendPointerEventForHover";
1133 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1134 std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
1135 WSError ret = sceneSession->SendPointerEventForHover(pointerEvent);
1136 EXPECT_EQ(ret, WSError::WS_ERROR_INVALID_SESSION);
1137
1138 sceneSession->state_ = SessionState::STATE_FOREGROUND;
1139 ret = sceneSession->SendPointerEventForHover(pointerEvent);
1140 EXPECT_EQ(ret, WSError::WS_OK);
1141 }
1142
1143 /**
1144 * @tc.name: TestUpdateGlobalDisplayRectFromClient
1145 * @tc.desc: Verify UpdateGlobalDisplayRectFromClient updates rect asynchronously when necessary.
1146 * @tc.type: FUNC
1147 */
1148 HWTEST_F(SceneSessionTest6, TestUpdateGlobalDisplayRectFromClient, Function | SmallTest | Level1)
1149 {
1150 SessionInfo info;
1151 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1152
1153 // Case 1: Same rect, should early return and skip update
1154 {
1155 WSRect rect = session->GetGlobalDisplayRect();
1156 auto result = session->UpdateGlobalDisplayRectFromClient(rect, SizeChangeReason::MOVE);
1157 EXPECT_EQ(result, WSError::WS_OK);
1158 }
1159
1160 // Case 2: Different rect, update should be posted and processed
1161 {
1162 WSRect rect = session->GetGlobalDisplayRect();
1163 WSRect newRect = { rect.posX_ + 10, rect.posY_ + 20, rect.width_, rect.height_ };
1164 auto result = session->UpdateGlobalDisplayRectFromClient(newRect, SizeChangeReason::MOVE);
1165 EXPECT_EQ(result, WSError::WS_OK);
1166 }
1167 }
1168
1169 /**
1170 * @tc.name: SetWindowTransitionAnimation
1171 * @tc.desc: SetWindowTransitionAnimation
1172 * @tc.type: FUNC
1173 */
1174 HWTEST_F(SceneSessionTest6, SetWindowTransitionAnimation, Function | SmallTest | Level1)
1175 {
1176 SessionInfo info;
1177 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1178 WindowTransitionType transitionType = WindowTransitionType::DESTROY;
1179 TransitionAnimation animation;
1180 session->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1181
1182 session->systemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
1183 auto ret = session->SetWindowTransitionAnimation(transitionType, animation);
1184 ASSERT_EQ(ret, WSError::WS_ERROR_DEVICE_NOT_SUPPORT);
1185
1186 session->systemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
1187 ret = session->SetWindowTransitionAnimation(transitionType, animation);
1188 ASSERT_EQ(ret, WSError::WS_OK);
1189
1190 session->systemConfig_.windowUIType_ = WindowUIType::PAD_WINDOW;
1191 session->systemConfig_.freeMultiWindowEnable_ = false;
1192 session->systemConfig_.freeMultiWindowSupport_ = false;
1193 ret = session->SetWindowTransitionAnimation(transitionType, animation);
1194 ASSERT_EQ(ret, WSError::WS_ERROR_DEVICE_NOT_SUPPORT);
1195
1196 session->systemConfig_.freeMultiWindowEnable_ = true;
1197 session->systemConfig_.freeMultiWindowSupport_ = true;
1198 ret = session->SetWindowTransitionAnimation(transitionType, animation);
1199 ASSERT_EQ(ret, WSError::WS_OK);
1200
1201 session->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_FLOAT);
1202 ret = session->SetWindowTransitionAnimation(transitionType, animation);
1203 ASSERT_EQ(ret, WSError::WS_ERROR_INVALID_CALLING);
1204 }
1205 } // namespace
1206 } // namespace Rosen
1207 } // namespace OHOS