1 /*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <gtest/gtest.h>
17 #include <pointer_event.h>
18 #include "proxy/include/window_info.h"
19
20 #include "common/include/session_permission.h"
21 #include "display_manager.h"
22 #include "input_event.h"
23 #include "key_event.h"
24
25 #include "mock/mock_session_stage.h"
26 #include "mock/mock_scene_session.h"
27 #include "pointer_event.h"
28
29 #include "screen_manager.h"
30 #include "session/host/include/sub_session.h"
31 #include "session/host/include/main_session.h"
32 #include "session/host/include/scene_session.h"
33 #include "session/host/include/system_session.h"
34 #include "session/screen/include/screen_session.h"
35 #include "screen_session_manager_client/include/screen_session_manager_client.h"
36 #include "wm_common.h"
37 #include "window_helper.h"
38 #include "ui/rs_surface_node.h"
39 #include "transaction/rs_transaction.h"
40
41 using namespace testing;
42 using namespace testing::ext;
43 namespace OHOS {
44 namespace Rosen {
45 namespace {
46 std::string g_errLog;
MyLogCallback(const LogType type,const LogLevel level,const unsigned int domain,const char * tag,const char * msg)47 void MyLogCallback(const LogType type, const LogLevel level, const unsigned int domain, const char *tag,
48 const char *msg)
49 {
50 g_errLog = msg;
51 }
52 }
53 class GetKeyboardGravitySceneSession : public SceneSession {
54 public:
GetKeyboardGravitySceneSession(const SessionInfo & info,const sptr<SpecificSessionCallback> & specificCallback)55 GetKeyboardGravitySceneSession(const SessionInfo& info, const sptr<SpecificSessionCallback>& specificCallback)
56 : SceneSession(info, specificCallback)
57 {
58 }
59
GetKeyboardGravity() const60 SessionGravity GetKeyboardGravity() const override
61 {
62 return SessionGravity::SESSION_GRAVITY_FLOAT;
63 }
64 };
65
66 class SceneSessionTest5 : public testing::Test {
67 public:
68 static void SetUpTestCase();
69 static void TearDownTestCase();
70 void SetUp() override;
71 void TearDown() override;
72 };
73
SetUpTestCase()74 void SceneSessionTest5::SetUpTestCase() {}
75
TearDownTestCase()76 void SceneSessionTest5::TearDownTestCase() {}
77
SetUp()78 void SceneSessionTest5::SetUp() {}
79
TearDown()80 void SceneSessionTest5::TearDown() {}
81
82 namespace {
83
84 /**
85 * @tc.name: GetSystemAvoidArea
86 * @tc.desc: GetSystemAvoidArea function
87 * @tc.type: FUNC
88 */
89 HWTEST_F(SceneSessionTest5, GetSystemAvoidArea, TestSize.Level1)
90 {
91 SessionInfo info;
92 info.abilityName_ = "GetSystemAvoidArea";
93 info.bundleName_ = "GetSystemAvoidArea";
94
95 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
96 EXPECT_NE(session, nullptr);
97 WSRect rect;
98 AvoidArea avoidArea;
99 session->property_->SetWindowFlags(0);
100 session->property_->SetWindowMode(WindowMode::WINDOW_MODE_UNDEFINED);
101 session->isDisplayStatusBarTemporarily_.store(true);
102 session->GetSystemAvoidArea(rect, avoidArea);
103 ASSERT_NE(session->GetSessionProperty(), nullptr);
104 EXPECT_EQ(WindowMode::WINDOW_MODE_UNDEFINED, session->GetSessionProperty()->GetWindowMode());
105
106 session->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
107 info.windowType_ = static_cast<uint32_t>(WindowType::APP_MAIN_WINDOW_END);
108 session->isDisplayStatusBarTemporarily_.store(false);
109 session->GetSystemAvoidArea(rect, avoidArea);
110
111 info.windowType_ = static_cast<uint32_t>(WindowType::APP_MAIN_WINDOW_BASE);
112 SystemSessionConfig systemConfig;
113 systemConfig.windowUIType_ = WindowUIType::PC_WINDOW;
114 session->SetSystemConfig(systemConfig);
115 sptr<SceneSession::SpecificSessionCallback> specificCallback =
116 sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
117 session->specificCallback_ = specificCallback;
118 session->specificCallback_->onGetSceneSessionVectorByTypeAndDisplayId_ = nullptr;
119 session->GetSystemAvoidArea(rect, avoidArea);
120
121 systemConfig.windowUIType_ = WindowUIType::PHONE_WINDOW;
__anonbd9130010302(WindowType type, uint64_t displayId) 122 GetSceneSessionVectorByTypeAndDisplayIdCallback func = [&session](WindowType type, uint64_t displayId) {
123 std::vector<sptr<SceneSession>> vSession;
124 vSession.push_back(session);
125 return vSession;
126 };
127 session->property_->SetDisplayId(2024);
128 sptr<ScreenSession> screenSession = sptr<ScreenSession>::MakeSptr();
129 ScreenSessionManagerClient::GetInstance().screenSessionMap_.clear();
130 ScreenSessionManagerClient::GetInstance().screenSessionMap_.insert(std::make_pair(2024, screenSession));
131 session->specificCallback_->onGetSceneSessionVectorByTypeAndDisplayId_ = func;
132 session->GetSystemAvoidArea(rect, avoidArea);
133 ScreenSessionManagerClient::GetInstance().screenSessionMap_.clear();
134 }
135
136 /**
137 * @tc.name: HookAvoidAreaInCompatibleMode
138 * @tc.desc: HookAvoidAreaInCompatibleMode function
139 * @tc.type: FUNC
140 */
141 HWTEST_F(SceneSessionTest5, HookAvoidAreaInCompatibleMode, TestSize.Level1)
142 {
143 SessionInfo info;
144 info.abilityName_ = "HookAvoidAreaInCompatibleMode";
145 info.bundleName_ = "HookAvoidAreaInCompatibleMode";
146
147 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
148 EXPECT_NE(session, nullptr);
149 WSRect rect = { 800, 100, 1000, 1000 };
150 AvoidArea avoidArea;
151 avoidArea.topRect_ = { -1, -1, -1, -1 };
152 avoidArea.bottomRect_ = { -1, -1, -1, -1 };
153 Rect invalidRect = { -1, -1, -1, -1 };
154 // hook Func only support compatibleMode
155 sptr<CompatibleModeProperty> compatibleModeProperty = sptr<CompatibleModeProperty>::MakeSptr();
156 compatibleModeProperty->SetIsAdaptToImmersive(false);
157 session->property_->SetCompatibleModeProperty(compatibleModeProperty);
158 session->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
159 session->HookAvoidAreaInCompatibleMode(rect, AvoidAreaType::TYPE_SYSTEM, avoidArea);
160 EXPECT_TRUE(avoidArea.topRect_ == invalidRect);
161 compatibleModeProperty->SetIsAdaptToImmersive(true);
162 session->property_->SetCompatibleModeProperty(compatibleModeProperty);
163 session->property_->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
164 session->HookAvoidAreaInCompatibleMode(rect, AvoidAreaType::TYPE_SYSTEM, avoidArea);
165 EXPECT_TRUE(avoidArea.topRect_ == invalidRect);
166
167 // test top system avoidArea
168 session->property_->GetCompatibleModeProperty()->SetIsAdaptToImmersive(true);
169 session->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
170 session->HookAvoidAreaInCompatibleMode(rect, AvoidAreaType::TYPE_SYSTEM, avoidArea);
171 auto vpr = 3.5f;
172 Rect targetRect = { 0, 0, rect.width_, 40 * vpr };
173 EXPECT_TRUE(avoidArea.topRect_ == targetRect);
174
175 // test buttom aiBar avoidArea
176 session->HookAvoidAreaInCompatibleMode(rect, AvoidAreaType::TYPE_NAVIGATION_INDICATOR, avoidArea);
177 targetRect = { 0, rect.height_ - 28 * vpr, rect.width_, 28 * vpr };
178 EXPECT_TRUE(avoidArea.bottomRect_ == targetRect);
179 }
180
181 /**
182 * @tc.name: GetSystemAvoidArea01
183 * @tc.desc: GetSystemAvoidArea01 function
184 * @tc.type: FUNC
185 */
186 HWTEST_F(SceneSessionTest5, GetSystemAvoidArea01, TestSize.Level1)
187 {
188 SessionInfo info;
189 info.abilityName_ = "GetSystemAvoidArea01";
190 info.bundleName_ = "GetSystemAvoidArea01";
191
192 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
193 EXPECT_NE(session, nullptr);
194 WSRect rect;
195 AvoidArea avoidArea;
196 session->property_->SetWindowFlags(0);
197
198 session->isDisplayStatusBarTemporarily_.store(false);
199
200 info.windowType_ = static_cast<uint32_t>(WindowType::APP_MAIN_WINDOW_BASE);
201 SystemSessionConfig systemConfig;
202
203 session->SetSystemConfig(systemConfig);
204 sptr<SceneSession::SpecificSessionCallback> specificCallback =
205 sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
206 session->specificCallback_ = specificCallback;
207
208 systemConfig.windowUIType_ = WindowUIType::PHONE_WINDOW;
__anonbd9130010402(WindowType type, uint64_t displayId) 209 GetSceneSessionVectorByTypeAndDisplayIdCallback func = [&session](WindowType type, uint64_t displayId) {
210 std::vector<sptr<SceneSession>> vSession;
211 vSession.push_back(session);
212 return vSession;
213 };
214 session->property_->SetDisplayId(2024);
215 sptr<ScreenSession> screenSession = sptr<ScreenSession>::MakeSptr();
216 ScreenSessionManagerClient::GetInstance().screenSessionMap_.clear();
217 ScreenSessionManagerClient::GetInstance().screenSessionMap_.insert(std::make_pair(2024, screenSession));
218 session->specificCallback_->onGetSceneSessionVectorByTypeAndDisplayId_ = func;
219 ScreenSessionManagerClient::GetInstance().screenSessionMap_.clear();
220
221 session->property_->SetDisplayId(1024);
222 session->Session::SetFloatingScale(0.0f);
223
224 session->Session::SetFloatingScale(0.5f);
225 EXPECT_EQ(0.5f, session->Session::GetFloatingScale());
226 session->property_->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_PRIMARY);
227 session->GetSystemAvoidArea(rect, avoidArea);
228 session->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
229 session->GetSystemAvoidArea(rect, avoidArea);
230 rect.height_ = 3;
231 rect.width_ = 4;
232 session->GetSystemAvoidArea(rect, avoidArea);
233
234 session->isVisible_ = true;
235 session->property_->SetWindowMode(WindowMode::WINDOW_MODE_UNDEFINED);
236 session->GetSystemAvoidArea(rect, avoidArea);
237 }
238
239 /**
240 * @tc.name: NotifyOutsideDownEvent
241 * @tc.desc: NotifyOutsideDownEvent function
242 * @tc.type: FUNC
243 */
244 HWTEST_F(SceneSessionTest5, NotifyOutsideDownEvent, TestSize.Level1)
245 {
246 SessionInfo info;
247 info.abilityName_ = "NotifyOutsideDownEvent";
248 info.bundleName_ = "NotifyOutsideDownEvent";
249 info.windowInputType_ = static_cast<uint32_t>(MMI::WindowInputType::NORMAL);
250
251 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
252 EXPECT_NE(session, nullptr);
253 std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
254 pointerEvent->SetPointerAction(2);
255 pointerEvent->RemoveAllPointerItems();
256 session->NotifyOutsideDownEvent(pointerEvent);
257 pointerEvent->SetPointerAction(8);
258 MMI::PointerEvent::PointerItem pointerItem;
259 pointerItem.SetPointerId(2024);
260 pointerEvent->AddPointerItem(pointerItem);
261 pointerEvent->SetPointerId(2024);
262 session->NotifyOutsideDownEvent(pointerEvent);
263 sptr<SceneSession::SpecificSessionCallback> specificCallback =
264 sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
265 session->specificCallback_ = specificCallback;
266 session->specificCallback_->onOutsideDownEvent_ = nullptr;
267 session->NotifyOutsideDownEvent(pointerEvent);
__anonbd9130010502(int32_t x, int32_t y) 268 OnOutsideDownEvent func = [](int32_t x, int32_t y) { return; };
269 session->specificCallback_->onOutsideDownEvent_ = func;
270 session->NotifyOutsideDownEvent(pointerEvent);
271 auto res = pointerEvent->GetPointerItem(2024, pointerItem);
272 EXPECT_EQ(true, res);
273
274 pointerEvent->SetPointerAction(5);
275 session->NotifyOutsideDownEvent(pointerEvent);
276 pointerEvent->RemoveAllPointerItems();
277
278 info.windowInputType_ = static_cast<uint32_t>(MMI::WindowInputType::TRANSMIT_ALL);
279 sptr<SceneSession> session1 = sptr<SceneSession>::MakeSptr(info, nullptr);
280 session1->NotifyOutsideDownEvent(pointerEvent);
281 }
282
283 /**
284 * @tc.name: TransferPointerEventInnerTest
285 * @tc.desc: TransferPointerEventInner function
286 * @tc.type: FUNC
287 */
288 HWTEST_F(SceneSessionTest5, TransferPointerEventInner, TestSize.Level1)
289 {
290 SessionInfo info;
291 info.abilityName_ = "TransferPointerEventInner";
292 info.bundleName_ = "TransferPointerEventInner";
293
294 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
295 EXPECT_NE(session, nullptr);
296 std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
297
298 info.isSystem_ = false;
299 pointerEvent->SetPointerAction(9);
300
301 sptr<SceneSession::SpecificSessionCallback> specificCallback =
302 sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
303 session->specificCallback_ = specificCallback;
304 session->specificCallback_->onSessionTouchOutside_ = nullptr;
305 EXPECT_EQ(WSError::WS_ERROR_INVALID_SESSION, session->TransferPointerEventInner(pointerEvent, false));
306
__anonbd9130010602(int32_t persistentId, DisplayId displayId) 307 NotifySessionTouchOutsideCallback func = [](int32_t persistentId, DisplayId displayId) { return; };
308 session->specificCallback_->onSessionTouchOutside_ = func;
309 EXPECT_EQ(WSError::WS_ERROR_INVALID_SESSION, session->TransferPointerEventInner(pointerEvent, false));
310 pointerEvent->SetPointerAction(2);
311 EXPECT_EQ(WSError::WS_ERROR_INVALID_SESSION, session->TransferPointerEventInner(pointerEvent, false));
312 }
313
314 /**
315 * @tc.name: TransferPointerEventInnerTest001
316 * @tc.desc: TransferPointerEventInner function
317 * @tc.type: FUNC
318 */
319 HWTEST_F(SceneSessionTest5, TransferPointerEventInnerTest001, TestSize.Level1)
320 {
321 SessionInfo info;
322 info.abilityName_ = "TransferPointerEventInnerTest001";
323 info.bundleName_ = "TransferPointerEventInnerTest001";
324 info.windowType_ = static_cast<uint32_t>(WindowType::APP_MAIN_WINDOW_BASE);
325 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
326 EXPECT_NE(session, nullptr);
327 std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
328 session->property_->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_PRIMARY);
329 session->property_->SetMaximizeMode(MaximizeMode::MODE_RECOVER);
330 session->ClearDialogVector();
331 session->moveDragController_ = sptr<MoveDragController>::MakeSptr(2024, session->GetWindowType());
332 SystemSessionConfig systemConfig;
333 systemConfig.isSystemDecorEnable_ = false;
334 systemConfig.decorWindowModeSupportType_ = 2;
335 session->SetSystemConfig(systemConfig);
336 EXPECT_EQ(WSError::WS_ERROR_INVALID_SESSION, session->TransferPointerEventInner(pointerEvent, false));
337
338 session->BindDialogToParentSession(session);
339 session->SetSessionState(SessionState::STATE_ACTIVE);
340 pointerEvent->SetPointerAction(5);
341 session->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
342 session->property_->SetDragEnabled(false);
343 systemConfig.isSystemDecorEnable_ = true;
344
345 session->moveDragController_->isStartDrag_ = false;
346 EXPECT_EQ(WSError::WS_ERROR_NULLPTR, session->TransferPointerEventInner(pointerEvent, false));
347
348 pointerEvent->SetPointerAction(2);
349 EXPECT_EQ(WSError::WS_OK, session->TransferPointerEventInner(pointerEvent, false));
350
351 session->property_->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
352 session->property_->SetDecorEnable(false);
353 EXPECT_EQ(WSError::WS_OK, session->TransferPointerEventInner(pointerEvent, false));
354
355 pointerEvent->SetPointerAction(5);
356 session->property_->SetDragEnabled(true);
357 systemConfig.windowUIType_ = WindowUIType::PHONE_WINDOW;
358 systemConfig.freeMultiWindowSupport_ = false;
359 session->moveDragController_->isStartDrag_ = true;
360 EXPECT_EQ(WSError::WS_ERROR_NULLPTR, session->TransferPointerEventInner(pointerEvent, false));
361
362 systemConfig.windowUIType_ = WindowUIType::PC_WINDOW;
363 EXPECT_EQ(WSError::WS_ERROR_NULLPTR, session->TransferPointerEventInner(pointerEvent, false));
364 session->ClearDialogVector();
365 }
366
367 /**
368 * @tc.name: SetSurfaceBounds01
369 * @tc.desc: SetSurfaceBounds function
370 * @tc.type: FUNC
371 */
372 HWTEST_F(SceneSessionTest5, SetSurfaceBounds01, TestSize.Level1)
373 {
374 SessionInfo info;
375 info.abilityName_ = "SetSurfaceBounds01";
376 info.bundleName_ = "SetSurfaceBounds01";
377 info.windowType_ = static_cast<uint32_t>(WindowType::WINDOW_TYPE_FLOAT);
378 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
379 struct RSSurfaceNodeConfig config;
380 std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Create(config);
381 session->surfaceNode_ = nullptr;
382 WSRect preRect = { 20, 20, 800, 800 };
383 WSRect rect = { 30, 30, 900, 900 };
384 session->SetSessionRect(preRect);
385 session->SetSurfaceBounds(rect, false);
386
387 session->surfaceNode_ = surfaceNode;
388 session->SetSurfaceBounds(rect, false);
389 EXPECT_EQ(preRect, session->GetSessionRect());
390 }
391
392 /**
393 * @tc.name: OnLayoutFullScreenChange
394 * @tc.desc: OnLayoutFullScreenChange function
395 * @tc.type: FUNC
396 */
397 HWTEST_F(SceneSessionTest5, OnLayoutFullScreenChange, TestSize.Level1)
398 {
399 SessionInfo info;
400 info.abilityName_ = "OnLayoutFullScreenChange";
401 info.bundleName_ = "OnLayoutFullScreenChange";
402 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
403 EXPECT_NE(session, nullptr);
__anonbd9130010702(bool isLayoutFullScreen) 404 NotifyLayoutFullScreenChangeFunc func = [](bool isLayoutFullScreen) {};
405 session->onLayoutFullScreenChangeFunc_ = func;
406 EXPECT_EQ(WSError::WS_OK, session->OnLayoutFullScreenChange(true));
407 }
408
409 /**
410 * @tc.name: RegisterLayoutFullScreenChangeCallback
411 * @tc.desc: test RegisterLayoutFullScreenChangeCallback
412 * @tc.type: FUNC
413 */
414 HWTEST_F(SceneSessionTest5, RegisterLayoutFullScreenChangeCallback, TestSize.Level1)
415 {
416 SessionInfo info;
417 info.abilityName_ = "RegisterLayoutFullScreenChangeCallback";
418 info.bundleName_ = "RegisterLayoutFullScreenChangeCallback";
419 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
420 sceneSession->onLayoutFullScreenChangeFunc_ = nullptr;
__anonbd9130010802(bool isLayoutFullScreen) 421 NotifyLayoutFullScreenChangeFunc func = [](bool isLayoutFullScreen) {};
422
423 sceneSession->RegisterLayoutFullScreenChangeCallback(std::move(func));
424 ASSERT_NE(sceneSession->onLayoutFullScreenChangeFunc_, nullptr);
425 }
426
427 /**
428 * @tc.name: OnDefaultDensityEnabled
429 * @tc.desc: OnDefaultDensityEnabled function
430 * @tc.type: FUNC
431 */
432 HWTEST_F(SceneSessionTest5, OnDefaultDensityEnabled, TestSize.Level1)
433 {
434 SessionInfo info;
435 info.abilityName_ = "OnDefaultDensityEnabled";
436 info.bundleName_ = "OnDefaultDensityEnabled";
437 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
438 EXPECT_NE(session, nullptr);
439 EXPECT_EQ(WSError::WS_OK, session->OnDefaultDensityEnabled(true));
440
441 session->onDefaultDensityEnabledFunc_ = nullptr;
442 EXPECT_EQ(WSError::WS_OK, session->OnDefaultDensityEnabled(true));
443
__anonbd9130010902(bool isLDefaultDensityEnabled) 444 NotifyDefaultDensityEnabledFunc func = [](bool isLDefaultDensityEnabled) {};
445 session->onDefaultDensityEnabledFunc_ = func;
446 EXPECT_EQ(WSError::WS_OK, session->OnDefaultDensityEnabled(true));
447 }
448
449 /**
450 * @tc.name: UpdateSessionPropertyByAction
451 * @tc.desc: UpdateSessionPropertyByAction function01
452 * @tc.type: FUNC
453 */
454 HWTEST_F(SceneSessionTest5, UpdateSessionPropertyByAction, TestSize.Level1)
455 {
456 SessionInfo info;
457 info.abilityName_ = "UpdateSessionPropertyByAction";
458 info.bundleName_ = "UpdateSessionPropertyByAction";
459 info.windowType_ = static_cast<uint32_t>(WindowType::APP_MAIN_WINDOW_BASE);
460 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
461 EXPECT_NE(session, nullptr);
462 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
463 EXPECT_EQ(WMError::WM_ERROR_NULLPTR,
464 session->UpdateSessionPropertyByAction(nullptr, WSPropertyChangeAction::ACTION_UPDATE_PRIVACY_MODE));
465 EXPECT_EQ(WMError::WM_ERROR_INVALID_PERMISSION,
466 session->UpdateSessionPropertyByAction(property, WSPropertyChangeAction::ACTION_UPDATE_PRIVACY_MODE));
467 }
468
469 /**
470 * @tc.name: SetSessionRectChangeCallback
471 * @tc.desc: SetSessionRectChangeCallback function01
472 * @tc.type: FUNC
473 */
474 HWTEST_F(SceneSessionTest5, SetSessionRectChangeCallback, TestSize.Level1)
475 {
476 SessionInfo info;
477 info.abilityName_ = "SetSessionRectChangeCallback";
478 info.bundleName_ = "SetSessionRectChangeCallback";
479 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
480 EXPECT_NE(session, nullptr);
481 WSRect rec = { 1, 1, 1, 1 };
482 NotifySessionRectChangeFunc func = [](const WSRect& rect,
483 SizeChangeReason reason,
484 DisplayId displayId,
__anonbd9130010a02(const WSRect& rect, SizeChangeReason reason, DisplayId displayId, const RectAnimationConfig& rectAnimationConfig) 485 const RectAnimationConfig& rectAnimationConfig) { return; };
486 session->SetSessionRectChangeCallback(nullptr);
487 info.windowType_ = static_cast<uint32_t>(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
488 session->SetSessionRectChangeCallback(func);
489 info.windowType_ = static_cast<uint32_t>(WindowType::APP_MAIN_WINDOW_BASE);
490 session->SetSessionRectChangeCallback(func);
491 rec.width_ = 0;
492 session->SetSessionRectChangeCallback(func);
493 rec.height_ = 0;
494 session->SetSessionRectChangeCallback(func);
495 EXPECT_EQ(WindowType::APP_MAIN_WINDOW_BASE, session->GetWindowType());
496 }
497
498 /**
499 * @tc.name: SetSessionRectChangeCallback02
500 * @tc.desc: SetSessionRectChangeCallback02 function01
501 * @tc.type: FUNC
502 */
503 HWTEST_F(SceneSessionTest5, SetSessionRectChangeCallback02, TestSize.Level1)
504 {
505 SessionInfo info;
506 info.abilityName_ = "SetSessionRectChangeCallback02";
507 info.bundleName_ = "SetSessionRectChangeCallback02";
508 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
509 EXPECT_NE(session, nullptr);
510 WSRect rec = { 1, 1, 1, 1 };
511 NotifySessionRectChangeFunc func = [](const WSRect& rect,
512 SizeChangeReason reason,
513 DisplayId displayId,
__anonbd9130010b02(const WSRect& rect, SizeChangeReason reason, DisplayId displayId, const RectAnimationConfig& rectAnimationConfig) 514 const RectAnimationConfig& rectAnimationConfig) { return; };
515 session->SetSessionRectChangeCallback(nullptr);
516
517 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
518 EXPECT_NE(property, nullptr);
519 property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
520 session->SetSessionProperty(property);
521 session->SetSessionRectChangeCallback(func);
522
523 property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
524 session->SetSessionProperty(property);
525 session->SetSessionRequestRect(rec);
526 session->SetSessionRectChangeCallback(func);
527
528 rec.width_ = 0;
529 session->SetSessionRequestRect(rec);
530 session->SetSessionRectChangeCallback(func);
531
532 rec.height_ = 0;
533 session->SetSessionRequestRect(rec);
534 session->SetSessionRectChangeCallback(func);
535 EXPECT_EQ(WindowType::APP_MAIN_WINDOW_BASE, session->GetWindowType());
536 }
537
538 /**
539 * @tc.name: SetSessionRectChangeCallback03
540 * @tc.desc: SetSessionRectChangeCallback
541 * @tc.type: FUNC
542 */
543 HWTEST_F(SceneSessionTest5, SetSessionRectChangeCallback03, TestSize.Level1)
544 {
545 SessionInfo info;
546 info.abilityName_ = "SetSessionRectChangeCallback03";
547 info.bundleName_ = "SetSessionRectChangeCallback03";
548 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
549 property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
550 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
551 session->SetSessionProperty(property);
552 WSRect rec = { 1, 1, 1, 1 };
553 NotifySessionRectChangeFunc func = [](const WSRect& rect,
554 const SizeChangeReason reason,
555 DisplayId displayId,
__anonbd9130010c02(const WSRect& rect, const SizeChangeReason reason, DisplayId displayId, const RectAnimationConfig& rectAnimationConfig) 556 const RectAnimationConfig& rectAnimationConfig) { return; };
557 session->SetSessionRequestRect(rec);
558 session->SetSessionRectChangeCallback(nullptr);
559
560 rec.width_ = 0;
561 session->SetSessionRequestRect(rec);
562 session->SetSessionRectChangeCallback(nullptr);
563
564 rec.height_ = 0;
565 rec.width_ = 1;
566 session->SetSessionRequestRect(rec);
567 session->SetSessionRectChangeCallback(nullptr);
568
569 rec.height_ = 0;
570 rec.width_ = 0;
571 session->SetSessionRequestRect(rec);
572 session->SetSessionRectChangeCallback(nullptr);
573 EXPECT_EQ(WindowType::APP_MAIN_WINDOW_BASE, session->GetWindowType());
574 }
575
576 /**
577 * @tc.name: GetSystemAvoidArea02
578 * @tc.desc: GetSystemAvoidArea02 function
579 * @tc.type: FUNC
580 */
581 HWTEST_F(SceneSessionTest5, GetSystemAvoidArea02, TestSize.Level1)
582 {
583 SessionInfo info;
584 info.abilityName_ = "GetSystemAvoidArea02";
585 info.bundleName_ = "GetSystemAvoidArea02";
586
587 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
588 EXPECT_NE(session, nullptr);
589 ASSERT_NE(session->GetSessionProperty(), nullptr);
590 session->GetSessionProperty()->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
591 info.windowType_ = static_cast<uint32_t>(WindowType::APP_MAIN_WINDOW_BASE);
592
593 SystemSessionConfig systemConfig;
594 systemConfig.windowUIType_ = WindowUIType::PHONE_WINDOW;
595 session->SetSystemConfig(systemConfig);
596 ScreenSessionManagerClient::GetInstance().screenSessionMap_.clear();
597 session->GetSessionProperty()->SetDisplayId(1664);
598 session->Session::SetFloatingScale(0.02f);
599 WSRect rect;
600 AvoidArea avoidArea;
601 session->GetSystemAvoidArea(rect, avoidArea);
602 EXPECT_EQ(0.02f, session->Session::GetFloatingScale());
603
604 session->Session::SetFloatingScale(0.5f);
605 session->property_->SetWindowMode(WindowMode::WINDOW_MODE_UNDEFINED);
606 session->GetSystemAvoidArea(rect, avoidArea);
607 session->GetSessionProperty()->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
608 rect.height_ = 2;
609 rect.width_ = 1;
610 session->GetSystemAvoidArea(rect, avoidArea);
611 rect.height_ = 1;
612 session->GetSystemAvoidArea(rect, avoidArea);
613 }
614
615 /**
616 * @tc.name: OnMoveDragCallback
617 * @tc.desc: OnMoveDragCallback function01
618 * @tc.type: FUNC
619 */
620 HWTEST_F(SceneSessionTest5, OnMoveDragCallback, TestSize.Level1)
621 {
622 SessionInfo info;
623 info.abilityName_ = "OnMoveDragCallback";
624 info.bundleName_ = "OnMoveDragCallback";
625 info.isSystem_ = false;
626 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
__anonbd9130010d02(const std::shared_ptr<VsyncCallback>& callback) 627 session->SetRequestNextVsyncFunc([](const std::shared_ptr<VsyncCallback>& callback) {});
628 EXPECT_NE(nullptr, session->requestNextVsyncFunc_);
629 session->moveDragController_ = nullptr;
630 SizeChangeReason reason = { SizeChangeReason::DRAG };
631 session->OnMoveDragCallback(reason);
632 session->moveDragController_ = sptr<MoveDragController>::MakeSptr(2024, session->GetWindowType());
633 session->OnMoveDragCallback(reason);
634
635 reason = SizeChangeReason::DRAG_END;
636 session->OnMoveDragCallback(reason);
637
638 reason = SizeChangeReason::DRAG_MOVE;
639 session->OnMoveDragCallback(reason);
640
641 reason = SizeChangeReason::DRAG_START;
642 session->OnMoveDragCallback(reason);
643 EXPECT_EQ(WSError::WS_OK, session->UpdateSizeChangeReason(reason));
644
645 session->moveDragController_ = sptr<MoveDragController>::MakeSptr(2024, session->GetWindowType());
646 EXPECT_NE(session->moveDragController_, nullptr);
647 }
648
649 /**
650 * @tc.name: OnMoveDragCallback02
651 * @tc.desc: OnMoveDragCallback for DragResizeWhenEndFilter
652 * @tc.type: FUNC
653 */
654 HWTEST_F(SceneSessionTest5, OnMoveDragCallback02, Function | SmallTest | Level2)
655 {
656 SessionInfo info;
657 info.abilityName_ = "DragResizeWhenEnd";
658 info.bundleName_ = "DragResizeWhenEnd";
659 info.windowType_ = static_cast<uint32_t>(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
660 info.isSystem_ = false;
661 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
662 EXPECT_NE(nullptr, session);
663 session->moveDragController_ = sptr<MoveDragController>::MakeSptr(2024, session->GetWindowType());
664 EXPECT_NE(nullptr, session->moveDragController_);
665 SizeChangeReason reason = { SizeChangeReason::DRAG };
666 session->OnMoveDragCallback(reason);
667 session->systemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
668 session->dragResizeTypeDuringDrag_ = DragResizeType::RESIZE_WHEN_DRAG_END;
669 session->moveDragController_->isStartDrag_ = true;
670 EXPECT_EQ(session->DragResizeWhenEndFilter(reason), true);
671 session->OnMoveDragCallback(reason);
672 }
673
674 /**
675 * @tc.name: DragResizeWhenEndFilter
676 * @tc.desc: DragResizeWhenEndFilter function01
677 * @tc.type: FUNC
678 */
679 HWTEST_F(SceneSessionTest5, DragResizeWhenEndFilter, Function | SmallTest | Level2)
680 {
681 SessionInfo info;
682 info.abilityName_ = "DragResizeWhenEnd";
683 info.bundleName_ = "DragResizeWhenEnd";
684 info.windowType_ = static_cast<uint32_t>(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
685 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
686 EXPECT_NE(nullptr, session);
687 auto oriProperty = session->GetSessionProperty();
688 EXPECT_NE(nullptr, oriProperty);
689 auto moveDragController = sptr<MoveDragController>::MakeSptr(2024, session->GetWindowType());
690 EXPECT_NE(nullptr, moveDragController);
691 SizeChangeReason reason = { SizeChangeReason::DRAG };
692 // null
693 session->moveDragController_ = nullptr;
694 EXPECT_EQ(session->DragResizeWhenEndFilter(reason), true);
695 session->moveDragController_ = moveDragController;
696 session->property_ = nullptr;
697 EXPECT_EQ(session->DragResizeWhenEndFilter(reason), true);
698 session->property_ = oriProperty;
699 // invalid
700 EXPECT_EQ(session->DragResizeWhenEndFilter(SizeChangeReason::DRAG_START), false);
701 session->moveDragController_->isStartDrag_ = false;
702 EXPECT_EQ(session->DragResizeWhenEndFilter(reason), false);
703 session->moveDragController_->isStartDrag_ = true;
704 EXPECT_EQ(session->DragResizeWhenEndFilter(reason), false);
705 session->systemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
706 session->systemConfig_.freeMultiWindowSupport_ = true;
707 session->systemConfig_.freeMultiWindowEnable_ = false;
708 session->dragResizeTypeDuringDrag_ = DragResizeType::RESIZE_WHEN_DRAG_END;
709 EXPECT_EQ(session->DragResizeWhenEndFilter(reason), false);
710 session->systemConfig_.freeMultiWindowEnable_ = true;
711 EXPECT_EQ(session->DragResizeWhenEndFilter(reason), true);
712 session->systemConfig_.freeMultiWindowEnable_ = false;
713 session->systemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
714 EXPECT_EQ(session->DragResizeWhenEndFilter(reason), true);
715 EXPECT_EQ(session->DragResizeWhenEndFilter(SizeChangeReason::DRAG_END), true);
716 session->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
717 EXPECT_EQ(session->DragResizeWhenEndFilter(reason), false);
718 }
719
720 /**
721 * @tc.name: HandleSessionDragEvent
722 * @tc.desc: HandleSessionDragEvent function01
723 * @tc.type: FUNC
724 */
725 HWTEST_F(SceneSessionTest5, HandleSessionDragEvent, TestSize.Level1)
726 {
727 SessionInfo info;
728 info.abilityName_ = "HandleSessionDragEvent";
729 info.bundleName_ = "HandleSessionDragEvent";
730 info.windowType_ = static_cast<uint32_t>(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
731 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
732 EXPECT_NE(session, nullptr);
733
734 session->appDragResizeType_ = DragResizeType::RESIZE_TYPE_UNDEFINED;
735 session->moveDragController_ = nullptr;
736 session->HandleSessionDragEvent(SessionEvent::EVENT_END_MOVE);
737 EXPECT_EQ(session->GetDragResizeTypeDuringDrag(), DragResizeType::RESIZE_TYPE_UNDEFINED);
738
739 auto oriProperty = session->GetSessionProperty();
740 session->property_ = oriProperty;
741 auto moveDragController = sptr<MoveDragController>::MakeSptr(2024, session->GetWindowType());
742 session->moveDragController_ = moveDragController;
743 SessionEvent event = { SessionEvent::EVENT_DRAG };
744
745 sptr<CompatibleModeProperty> compatibleModeProperty = sptr<CompatibleModeProperty>::MakeSptr();
746 ASSERT_NE(compatibleModeProperty, nullptr);
747
748 session->moveDragController_->isStartDrag_ = false;
749 compatibleModeProperty->SetIsAdaptToDragScale(false);
750 session->property_->SetCompatibleModeProperty(compatibleModeProperty);
751 session->HandleSessionDragEvent(event);
752
753 compatibleModeProperty->SetIsAdaptToDragScale(true);
754 session->property_->SetCompatibleModeProperty(compatibleModeProperty);
755 session->HandleSessionDragEvent(event);
756
757 event = { SessionEvent::EVENT_DRAG_START };
758 session->moveDragController_->isStartDrag_ = true;
759
760 compatibleModeProperty->SetIsAdaptToDragScale(false);
761 session->property_->SetCompatibleModeProperty(compatibleModeProperty);
762 session->HandleSessionDragEvent(event);
763 EXPECT_EQ(session->GetDragResizeTypeDuringDrag(), session->GetAppDragResizeType());
764
765 compatibleModeProperty->SetIsAdaptToDragScale(true);
766 session->property_->SetCompatibleModeProperty(compatibleModeProperty);
767 session->HandleSessionDragEvent(event);
768
769 session->HandleSessionDragEvent(SessionEvent::EVENT_END_MOVE);
770 EXPECT_EQ(session->GetDragResizeTypeDuringDrag(), DragResizeType::RESIZE_TYPE_UNDEFINED);
771
772 session->HandleSessionDragEvent(SessionEvent::EVENT_MAXIMIZE);
773 EXPECT_EQ(session->GetDragResizeTypeDuringDrag(), DragResizeType::RESIZE_TYPE_UNDEFINED);
774 }
775
776 /**
777 * @tc.name: IsCompatibleModeDirtyDragScaleWindow
778 * @tc.desc: IsCompatibleModeDirtyDragScaleWindow function01
779 * @tc.type: FUNC
780 */
781 HWTEST_F(SceneSessionTest5, IsCompatibleModeDirtyDragScaleWindow, Function | SmallTest | Level2)
782 {
783 SessionInfo info;
784 info.abilityName_ = "IsCompatibleModeDirtyDragScaleWindow";
785 info.bundleName_ = "IsCompatibleModeDirtyDragScaleWindow";
786 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
787 EXPECT_NE(session, nullptr);
788 session->compatibleDragScaleFlags_ = false;
789 EXPECT_EQ(session->IsCompatibleModeDirtyDragScaleWindow(), false);
790 session->compatibleDragScaleFlags_ = true;
791 EXPECT_EQ(session->IsCompatibleModeDirtyDragScaleWindow(), true);
792 }
793
794 /**
795 * @tc.name: ResetCompatibleModeDragScaleFlags
796 * @tc.desc: ResetCompatibleModeDragScaleFlags function01
797 * @tc.type: FUNC
798 */
799 HWTEST_F(SceneSessionTest5, ResetCompatibleModeDragScaleFlags, Function | SmallTest | Level2)
800 {
801 SessionInfo info;
802 info.abilityName_ = "ResetCompatibleModeDragScaleFlags";
803 info.bundleName_ = "ResetCompatibleModeDragScaleFlags";
804 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
805 EXPECT_NE(session, nullptr);
806 session->ResetCompatibleModeDragScaleFlags();
807 EXPECT_EQ(session->IsCompatibleModeDirtyDragScaleWindow(), false);
808 }
809
810 /**
811 * @tc.name: UpdateKeyFrameCloneNode
812 * @tc.desc: UpdateKeyFrameCloneNode function01
813 * @tc.type: FUNC
814 */
815 HWTEST_F(SceneSessionTest5, UpdateKeyFrameCloneNode, Function | SmallTest | Level2)
816 {
817 SessionInfo info;
818 info.abilityName_ = "keyframe";
819 info.bundleName_ = "keyframe";
820 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
821 EXPECT_NE(session, nullptr);
822 auto sessionStage = sptr<SessionStageMocker>::MakeSptr();
823 EXPECT_NE(nullptr, sessionStage);
824 auto rsCanvasNode = RSCanvasNode::Create();
825 EXPECT_NE(nullptr, rsCanvasNode);
826 std::shared_ptr<RSCanvasNode> rsCanvasNodeNull = nullptr;
827 auto rsTransaction = std::make_shared<RSTransaction>();
828 EXPECT_NE(nullptr, rsTransaction);
829 std::shared_ptr<RSTransaction> rsTransactionNull = nullptr;
830
831 session->keyFrameCloneNode_ = rsCanvasNode;
832 EXPECT_EQ(session->UpdateKeyFrameCloneNode(rsCanvasNode, rsTransaction), WSError::WS_OK);
833 session->keyFrameCloneNode_ = nullptr;
834 EXPECT_EQ(session->UpdateKeyFrameCloneNode(rsCanvasNodeNull, rsTransaction), WSError::WS_ERROR_NULLPTR);
835 EXPECT_EQ(session->UpdateKeyFrameCloneNode(rsCanvasNode, rsTransaction), WSError::WS_ERROR_NULLPTR);
836 session->sessionStage_ = sessionStage;
837 EXPECT_EQ(session->UpdateKeyFrameCloneNode(rsCanvasNode, rsTransactionNull), WSError::WS_OK);
838 EXPECT_EQ(session->UpdateKeyFrameCloneNode(rsCanvasNode, rsTransaction), WSError::WS_OK);
839 }
840
841 /**
842 * @tc.name: UpdateKeyFrameState
843 * @tc.desc: UpdateKeyFrameState function01
844 * @tc.type: FUNC
845 */
846 HWTEST_F(SceneSessionTest5, UpdateKeyFrameState, Function | SmallTest | Level2)
847 {
848 SessionInfo info;
849 info.abilityName_ = "keyframe";
850 info.bundleName_ = "keyframe";
851 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
852 EXPECT_NE(session, nullptr);
853 auto moveDragController = sptr<MoveDragController>::MakeSptr(2024, session->GetWindowType());
854 EXPECT_NE(nullptr, moveDragController);
855 auto sessionStage = sptr<SessionStageMocker>::MakeSptr();
856 EXPECT_NE(nullptr, sessionStage);
857 auto rsCanvasNode = RSCanvasNode::Create();
858 EXPECT_NE(nullptr, rsCanvasNode);
859 auto rsTransaction = std::make_shared<RSTransaction>();
860 EXPECT_NE(nullptr, rsTransaction);
861
862 session->moveDragController_ = nullptr;
863 session->sessionStage_ = nullptr;
864 SizeChangeReason reason = { SizeChangeReason::DRAG_START };
865 WSRect rect;
866 KeyFramePolicy keyFramePolicy;
867 keyFramePolicy.dragResizeType_ = DragResizeType::RESIZE_KEY_FRAME;
868 session->UpdateKeyFrameState(reason, rect);
869 EXPECT_EQ(session->keyFramePolicy_.running_, false);
870 session->moveDragController_ = moveDragController;
871 session->UpdateKeyFrameState(reason, rect);
872 EXPECT_EQ(session->keyFramePolicy_.running_, false);
873 session->sessionStage_ = sessionStage;
874 session->UpdateKeyFrameState(reason, rect);
875 EXPECT_EQ(session->keyFramePolicy_.running_, false);
876 session->moveDragController_->isStartDrag_ = true;
877 session->UpdateKeyFrameState(reason, rect);
878 session->SetKeyFramePolicy(keyFramePolicy);
879 session->UpdateKeyFrameState(reason, rect);
880 EXPECT_EQ(session->keyFramePolicy_.running_, true);
881 session->SetAppDragResizeType(DragResizeType::RESIZE_WHEN_DRAG_END);
882 session->UpdateKeyFrameState(reason, rect);
883 EXPECT_EQ(session->keyFramePolicy_.running_, false);
884 session->SetAppDragResizeType(DragResizeType::RESIZE_TYPE_UNDEFINED);
885 session->UpdateKeyFrameState(reason, rect);
886 EXPECT_EQ(session->keyFramePolicy_.running_, true);
887 session->keyFrameCloneNode_ = rsCanvasNode;
888 reason = SizeChangeReason::DRAG;
889 session->UpdateKeyFrameState(reason, rect);
890 EXPECT_EQ(session->lastKeyFrameDragRect_, rect);
891 reason = SizeChangeReason::DRAG_END;
892 session->UpdateKeyFrameState(reason, rect);
893 EXPECT_EQ(session->keyFramePolicy_.running_, false);
894 }
895
896 /**
897 * @tc.name: RequestKeyFrameNextVsync
898 * @tc.desc: RequestKeyFrameNextVsync function01
899 * @tc.type: FUNC
900 */
901 HWTEST_F(SceneSessionTest5, RequestKeyFrameNextVsync, Function | SmallTest | Level2)
902 {
903 SessionInfo info;
904 info.abilityName_ = "keyframe";
905 info.bundleName_ = "keyframe";
906 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
907 EXPECT_NE(session, nullptr);
908 uint64_t requestStamp = 0;
909 uint64_t count = 0;
910
911 session->RequestKeyFrameNextVsync(requestStamp, count);
912 session->keyFramePolicy_.running_ = true;
913 session->RequestKeyFrameNextVsync(requestStamp, count);
__anonbd9130010e02(const std::shared_ptr<VsyncCallback>& callback) 914 session->SetRequestNextVsyncFunc([](const std::shared_ptr<VsyncCallback>& callback) {});
915 EXPECT_NE(nullptr, session->requestNextVsyncFunc_);
916 session->RequestKeyFrameNextVsync(requestStamp, count);
917 session->keyFrameVsyncRequestStamp_ = requestStamp;
918 session->RequestKeyFrameNextVsync(requestStamp, count);
919 }
920
921 /**
922 * @tc.name: OnKeyFrameNextVsync
923 * @tc.desc: OnKeyFrameNextVsync function01
924 * @tc.type: FUNC
925 */
926 HWTEST_F(SceneSessionTest5, OnKeyFrameNextVsync, Function | SmallTest | Level2)
927 {
928 SessionInfo info;
929 info.abilityName_ = "keyframe";
930 info.bundleName_ = "keyframe";
931 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
932 EXPECT_NE(session, nullptr);
933 uint64_t count = 0;
934 session->lastKeyFrameDragStamp_ = 0;
935 session->keyFrameDragPauseNoticed_ = true;
936 session->keyFrameAnimating_ = true;
937 session->OnKeyFrameNextVsync(count);
938 EXPECT_EQ(session->keyFrameDragPauseNoticed_, true);
939 session->keyFrameDragPauseNoticed_ = false;
940 session->OnKeyFrameNextVsync(count);
941 EXPECT_EQ(session->keyFrameDragPauseNoticed_, false);
942 session->keyFrameAnimating_ = false;
943 session->OnKeyFrameNextVsync(count);
944 EXPECT_EQ(session->keyFrameDragPauseNoticed_, true);
945 session->lastKeyFrameDragStamp_ = 0;
946 session->keyFrameDragPauseNoticed_ = false;
947 session->keyFrameAnimating_ = false;
948 session->OnKeyFrameNextVsync(count);
949 EXPECT_EQ(session->keyFrameDragPauseNoticed_, true);
950 session->keyFrameDragPauseNoticed_ = false;
951 session->keyFrameAnimating_ = false;
952 uint64_t nowTimeStamp =
953 std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch())
954 .count();
955 session->lastKeyFrameDragStamp_ = nowTimeStamp;
956 session->OnKeyFrameNextVsync(count);
957 EXPECT_EQ(session->keyFrameDragPauseNoticed_, false);
958 }
959
960 /**
961 * @tc.name: KeyFrameNotifyFilter
962 * @tc.desc: KeyFrameNotifyFilter function01
963 * @tc.type: FUNC
964 */
965 HWTEST_F(SceneSessionTest5, KeyFrameNotifyFilter, Function | SmallTest | Level2)
966 {
967 SessionInfo info;
968 info.abilityName_ = "keyframe";
969 info.bundleName_ = "keyframe";
970 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
971 EXPECT_NE(session, nullptr);
972
973 SizeChangeReason reason = { SizeChangeReason::DRAG };
974 WSRect rect = { 0, 0, 10, 10 };
975 WSRect rectNew = { 100, 100, 100, 100 };
976 session->lastKeyFrameRect_ = rect;
977 session->lastKeyFrameStamp_ = 0;
978 // no running
979 EXPECT_EQ(session->KeyFrameNotifyFilter(rectNew, reason), false);
980 session->keyFramePolicy_.running_ = true;
981 // other reason
982 EXPECT_EQ(session->KeyFrameNotifyFilter(rectNew, SizeChangeReason::DRAG_START), true);
983 EXPECT_EQ(session->KeyFrameNotifyFilter(rectNew, SizeChangeReason::DRAG_END), false);
984 session->keyFrameAnimating_ = true;
985 EXPECT_EQ(session->KeyFrameNotifyFilter(rectNew, reason), true);
986 // for same rect
987 session->keyFrameAnimating_ = false;
988 session->lastKeyFrameRect_ = rect;
989 session->lastKeyFrameStamp_ = 0;
990 EXPECT_EQ(session->KeyFrameNotifyFilter(rect, reason), true);
991 session->keyFrameAnimating_ = false;
992 session->lastKeyFrameRect_ = rect;
993 session->lastKeyFrameStamp_ = 0;
994 EXPECT_EQ(session->KeyFrameNotifyFilter(rectNew, reason), false);
995 // not meet time condition
996 session->keyFrameAnimating_ = false;
997 session->lastKeyFrameRect_ = rect;
998 EXPECT_EQ(session->KeyFrameNotifyFilter(rectNew, reason), true);
999 // for distance condition
1000 WSRect moveToRect = {
1001 0, 0, static_cast<int>(session->keyFramePolicy_.distance_), static_cast<int>(session->keyFramePolicy_.distance_)
1002 };
1003 session->keyFrameAnimating_ = false;
1004 EXPECT_EQ(session->KeyFrameNotifyFilter(moveToRect, reason), false);
1005 session->keyFramePolicy_.distance_ = 0;
1006 session->lastKeyFrameRect_ = rect;
1007 session->keyFrameAnimating_ = false;
1008 EXPECT_EQ(session->KeyFrameNotifyFilter(moveToRect, reason), true);
1009 }
1010
1011 /**
1012 * @tc.name: KeyFrameRectAlmostSame
1013 * @tc.desc: KeyFrameRectAlmostSame function01
1014 * @tc.type: FUNC
1015 */
1016 HWTEST_F(SceneSessionTest5, KeyFrameRectAlmostSame, Function | SmallTest | Level2)
1017 {
1018 SessionInfo info;
1019 info.abilityName_ = "keyframe";
1020 info.bundleName_ = "keyframe";
1021 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1022 EXPECT_NE(session, nullptr);
1023 WSRect rect = { 10, 10, 10, 10 };
1024 const int32_t DIFF_TEST = 13;
1025 EXPECT_EQ(session->KeyFrameRectAlmostSame(rect, { DIFF_TEST + 1, 10, 10, 10 }), false);
1026 EXPECT_EQ(session->KeyFrameRectAlmostSame(rect, { 10, DIFF_TEST + 1, 10, 10 }), false);
1027 EXPECT_EQ(session->KeyFrameRectAlmostSame(rect, { 10, 10, DIFF_TEST + 1, 10 }), false);
1028 EXPECT_EQ(session->KeyFrameRectAlmostSame(rect, { 10, 10, 10, DIFF_TEST + 1 }), false);
1029 EXPECT_EQ(session->KeyFrameRectAlmostSame(rect, { DIFF_TEST, DIFF_TEST, DIFF_TEST, DIFF_TEST }), true);
1030 }
1031
1032 /**
1033 * @tc.name: KeyFrameAnimateEnd
1034 * @tc.desc: KeyFrameAnimateEnd function01
1035 * @tc.type: FUNC
1036 */
1037 HWTEST_F(SceneSessionTest5, KeyFrameAnimateEnd, Function | SmallTest | Level2)
1038 {
1039 SessionInfo info;
1040 info.abilityName_ = "keyframe";
1041 info.bundleName_ = "keyframe";
1042 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1043 EXPECT_NE(session, nullptr);
1044 EXPECT_EQ(session->KeyFrameAnimateEnd(), WSError::WS_OK);
1045 }
1046
1047 /**
1048 * @tc.name: UpdateWinRectForSystemBar
1049 * @tc.desc: UpdateWinRectForSystemBar function01
1050 * @tc.type: FUNC
1051 */
1052 HWTEST_F(SceneSessionTest5, UpdateWinRectForSystemBar, TestSize.Level1)
1053 {
1054 SessionInfo info;
1055 info.abilityName_ = "UpdateWinRectForSystemBar";
1056 info.bundleName_ = "UpdateWinRectForSystemBar";
1057 info.isSystem_ = false;
1058 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1059 EXPECT_NE(session, nullptr);
1060 sptr<SceneSession::SpecificSessionCallback> specificCallback =
1061 sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
1062 specificCallback->onGetSceneSessionVectorByTypeAndDisplayId_ = nullptr;
1063 session->specificCallback_ = specificCallback;
1064 WSRect rect = { 1, 10, 3, 4 };
1065 session->UpdateWinRectForSystemBar(rect);
1066 GetSceneSessionVectorByTypeAndDisplayIdCallback func =
__anonbd9130010f02(WindowType type, uint64_t displayId) 1067 [session](WindowType type, uint64_t displayId) -> std::vector<sptr<SceneSession>> {
1068 std::vector<sptr<SceneSession>> vSession;
1069 vSession.push_back(session);
1070 return vSession;
1071 };
1072 specificCallback->onGetSceneSessionVectorByTypeAndDisplayId_ = func;
1073 session->UpdateWinRectForSystemBar(rect);
1074
1075 session->isVisible_ = true;
1076 session->GetLayoutController()->SetSessionRect(rect);
1077 session->UpdateWinRectForSystemBar(rect);
1078
1079 WSRect rect1 = { 1, 2, 10, 4 };
1080 session->GetLayoutController()->SetSessionRect(rect1);
1081 session->UpdateWinRectForSystemBar(rect);
1082 EXPECT_EQ(4, session->GetSessionRect().height_);
1083
1084 WSRect rect2 = { 1, 2, 10, 8 };
1085 session->GetLayoutController()->SetSessionRect(rect2);
1086 session->UpdateWinRectForSystemBar(rect);
1087 }
1088
1089 /**
1090 * @tc.name: UpdateNativeVisibility
1091 * @tc.desc: UpdateNativeVisibility function01
1092 * @tc.type: FUNC
1093 */
1094 HWTEST_F(SceneSessionTest5, UpdateNativeVisibility, TestSize.Level1)
1095 {
1096 SessionInfo info;
1097 info.abilityName_ = "UpdateNativeVisibility";
1098 info.bundleName_ = "UpdateNativeVisibility";
1099 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1100 EXPECT_NE(session, nullptr);
1101 sptr<SceneSession::SpecificSessionCallback> specificCallback =
1102 sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
__anonbd9130011002(int32_t persistentId, WindowUpdateType type) 1103 NotifyWindowInfoUpdateCallback dateFunc = [](int32_t persistentId, WindowUpdateType type) { return; };
__anonbd9130011102(const int32_t persistentId) 1104 UpdateAvoidAreaCallback areaFunc = [](const int32_t persistentId) { return; };
1105 specificCallback->onWindowInfoUpdate_ = dateFunc;
1106 specificCallback->onUpdateAvoidArea_ = areaFunc;
1107 session->specificCallback_ = specificCallback;
1108 session->UpdateNativeVisibility(true);
1109 session->UpdateNativeVisibility(false);
1110 }
1111
1112 /**
1113 * @tc.name: SetPrivacyMode
1114 * @tc.desc: SetPrivacyMode function01
1115 * @tc.type: FUNC
1116 */
1117 HWTEST_F(SceneSessionTest5, SetPrivacyMode, TestSize.Level1)
1118 {
1119 SessionInfo info;
1120 info.abilityName_ = "SetPrivacyMode";
1121 info.bundleName_ = "SetPrivacyMode";
1122 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1123 EXPECT_NE(session, nullptr);
1124 struct RSSurfaceNodeConfig config;
1125 std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Create(config);
1126 session->surfaceNode_ = surfaceNode;
1127 ASSERT_NE(session->GetSessionProperty(), nullptr);
1128 session->GetSessionProperty()->SetPrivacyMode(true);
1129 EXPECT_EQ(true, session->GetSessionProperty()->GetPrivacyMode());
1130 session->leashWinSurfaceNode_ = nullptr;
1131 session->SetPrivacyMode(false);
1132 session->leashWinSurfaceNode_ = surfaceNode;
1133 session->SetPrivacyMode(true);
1134
1135 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1136 EXPECT_NE(property, nullptr);
1137 property->SetPrivacyMode(true);
1138 session->SetSessionProperty(property);
1139 session->SetPrivacyMode(true);
1140 }
1141
1142 /**
1143 * @tc.name: SetSnapshotSkip
1144 * @tc.desc: SetSnapshotSkip function01
1145 * @tc.type: FUNC
1146 */
1147 HWTEST_F(SceneSessionTest5, SetSnapshotSkip, TestSize.Level1)
1148 {
1149 SessionInfo info;
1150 info.abilityName_ = "SetSnapshotSkip";
1151 info.bundleName_ = "SetSnapshotSkip";
1152 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1153 EXPECT_NE(session, nullptr);
1154 struct RSSurfaceNodeConfig config;
1155 std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Create(config);
1156 session->surfaceNode_ = surfaceNode;
1157 ASSERT_NE(session->GetSessionProperty(), nullptr);
1158 session->GetSessionProperty()->SetSnapshotSkip(true);
1159 EXPECT_EQ(true, session->GetSessionProperty()->GetSnapshotSkip());
1160 session->leashWinSurfaceNode_ = nullptr;
1161 session->SetSnapshotSkip(false);
1162 session->leashWinSurfaceNode_ = surfaceNode;
1163 session->SetSnapshotSkip(false);
1164 session->SetSnapshotSkip(true);
1165 session->surfaceNode_ = nullptr;
1166 EXPECT_NE(nullptr, session->GetLeashWinSurfaceNode());
1167 session->SetSnapshotSkip(true);
1168 }
1169
1170 /**
1171 * @tc.name: SetWatermarkEnabled
1172 * @tc.desc: SetWatermarkEnabled function01
1173 * @tc.type: FUNC
1174 */
1175 HWTEST_F(SceneSessionTest5, SetWatermarkEnabled, TestSize.Level1)
1176 {
1177 SessionInfo info;
1178 info.abilityName_ = "SetWatermarkEnabled";
1179 info.bundleName_ = "SetWatermarkEnabled";
1180 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1181 EXPECT_NE(session, nullptr);
1182
1183 std::string watermarkName = "watermarkNameTest";
1184 session->SetWatermarkEnabled(watermarkName, true);
1185
1186 struct RSSurfaceNodeConfig config;
1187 std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Create(config);
1188 session->surfaceNode_ = surfaceNode;
1189 session->SetWatermarkEnabled(watermarkName, true);
1190 }
1191
1192 /**
1193 * @tc.name: UIExtSurfaceNodeIdCache
1194 * @tc.desc: UIExtSurfaceNodeIdCache
1195 * @tc.type: FUNC
1196 */
1197 HWTEST_F(SceneSessionTest5, UIExtSurfaceNodeIdCache, TestSize.Level1)
1198 {
1199 SessionInfo info;
1200 info.abilityName_ = "UIExtSurfaceNodeIdCache";
1201 info.bundleName_ = "UIExtSurfaceNodeIdCache";
1202 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1203 EXPECT_NE(session, nullptr);
1204
1205 session->AddUIExtSurfaceNodeId(1, 2);
1206 EXPECT_EQ(session->GetUIExtPersistentIdBySurfaceNodeId(1), 2);
1207
1208 session->RemoveUIExtSurfaceNodeId(2);
1209 EXPECT_EQ(session->GetUIExtPersistentIdBySurfaceNodeId(1), 0);
1210 }
1211
1212 /**
1213 * @tc.name: SetSystemSceneOcclusionAlpha
1214 * @tc.desc: SetSystemSceneOcclusionAlpha function01
1215 * @tc.type: FUNC
1216 */
1217 HWTEST_F(SceneSessionTest5, SetSystemSceneOcclusionAlpha, TestSize.Level1)
1218 {
1219 SessionInfo info;
1220 info.abilityName_ = "SetSystemSceneOcclusionAlpha";
1221 info.bundleName_ = "SetSystemSceneOcclusionAlpha";
1222 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1223 EXPECT_NE(session, nullptr);
1224 session->SetSystemSceneOcclusionAlpha(-0.325);
1225 session->SetSystemSceneOcclusionAlpha(3.14125);
1226
1227 struct RSSurfaceNodeConfig config;
1228 std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Create(config);
1229 session->surfaceNode_ = surfaceNode;
1230 session->leashWinSurfaceNode_ = nullptr;
1231 session->SetSystemSceneOcclusionAlpha(0.14125);
1232 session->leashWinSurfaceNode_ = surfaceNode;
1233 session->SetSystemSceneOcclusionAlpha(0.14125);
1234 EXPECT_NE(nullptr, session->GetLeashWinSurfaceNode());
1235 }
1236
1237 /**
1238 * @tc.name: ResetOcclusionAlpha
1239 * @tc.desc: ResetOcclusionAlpha function01
1240 * @tc.type: FUNC
1241 */
1242 HWTEST_F(SceneSessionTest5, ResetOcclusionAlpha, TestSize.Level1)
1243 {
1244 SessionInfo info;
1245 info.abilityName_ = "ResetOcclusionAlpha";
1246 info.bundleName_ = "ResetOcclusionAlpha";
1247 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1248 EXPECT_NE(session, nullptr);
1249
1250 struct RSSurfaceNodeConfig config;
1251 std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Create(config);
1252 session->surfaceNode_ = surfaceNode;
1253 session->leashWinSurfaceNode_ = nullptr;
1254 session->ResetOcclusionAlpha();
1255 EXPECT_EQ(nullptr, session->GetLeashWinSurfaceNode());
1256 session->leashWinSurfaceNode_ = surfaceNode;
1257 session->ResetOcclusionAlpha();
1258 EXPECT_NE(nullptr, session->GetLeashWinSurfaceNode());
1259 }
1260
1261 /**
1262 * @tc.name: SetSystemSceneForceUIFirst
1263 * @tc.desc: SetSystemSceneForceUIFirst function01
1264 * @tc.type: FUNC
1265 */
1266 HWTEST_F(SceneSessionTest5, SetSystemSceneForceUIFirst, TestSize.Level1)
1267 {
1268 SessionInfo info;
1269 info.abilityName_ = "SetSystemSceneForceUIFirst";
1270 info.bundleName_ = "SetSystemSceneForceUIFirst";
1271 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1272 EXPECT_NE(session, nullptr);
1273 session->SetSystemSceneForceUIFirst(true);
1274
1275 struct RSSurfaceNodeConfig config;
1276 std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Create(config);
1277 session->surfaceNode_ = surfaceNode;
1278 session->leashWinSurfaceNode_ = nullptr;
1279 session->SetSystemSceneForceUIFirst(true);
1280 session->leashWinSurfaceNode_ = surfaceNode;
1281 session->SetSystemSceneForceUIFirst(true);
1282 EXPECT_NE(nullptr, session->GetLeashWinSurfaceNode());
1283 }
1284
1285 /**
1286 * @tc.name: UpdateWindowAnimationFlag
1287 * @tc.desc: UpdateWindowAnimationFlag function01
1288 * @tc.type: FUNC
1289 */
1290 HWTEST_F(SceneSessionTest5, UpdateWindowAnimationFlag, TestSize.Level1)
1291 {
1292 SessionInfo info;
1293 info.abilityName_ = "UpdateWindowAnimationFlag";
1294 info.bundleName_ = "UpdateWindowAnimationFlag";
1295 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1296 EXPECT_NE(session, nullptr);
1297
1298 EXPECT_EQ(WSError::WS_OK, session->UpdateWindowAnimationFlag(true));
1299
1300 session->onWindowAnimationFlagChange_ = nullptr;
1301 EXPECT_EQ(WSError::WS_OK, session->UpdateWindowAnimationFlag(true));
1302
__anonbd9130011202(const bool flag) 1303 NotifyWindowAnimationFlagChangeFunc func = [](const bool flag) { return; };
1304 session->onWindowAnimationFlagChange_ = func;
1305 EXPECT_EQ(WSError::WS_OK, session->UpdateWindowAnimationFlag(true));
1306 }
1307
1308 /**
1309 * @tc.name: SetForegroundInteractiveStatus
1310 * @tc.desc: SetForegroundInteractiveStatus function01
1311 * @tc.type: FUNC
1312 */
1313 HWTEST_F(SceneSessionTest5, SetForegroundInteractiveStatus, TestSize.Level1)
1314 {
1315 SessionInfo info;
1316 info.abilityName_ = "SetForegroundInteractiveStatus";
1317 info.bundleName_ = "SetForegroundInteractiveStatus";
1318 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1319 session->SetSessionState(SessionState::STATE_FOREGROUND);
1320 EXPECT_NE(session, nullptr);
1321 session->toastSession_.clear();
1322 session->toastSession_.push_back(session);
1323 session->SetForegroundInteractiveStatus(false);
1324 session->toastSession_.clear();
1325 session->SetSessionState(SessionState::STATE_ACTIVE);
1326 session->toastSession_.push_back(session);
1327 session->SetForegroundInteractiveStatus(false);
1328 session->toastSession_.clear();
1329 session->SetSessionState(SessionState::STATE_CONNECT);
1330 session->toastSession_.push_back(session);
1331 session->SetForegroundInteractiveStatus(false);
1332 session->toastSession_.clear();
1333 session->SetSessionState(SessionState::STATE_ACTIVE);
1334 session->toastSession_.push_back(nullptr);
1335 session->SetForegroundInteractiveStatus(false);
1336 session->toastSession_.clear();
1337 }
1338
1339 /**
1340 * @tc.name: HandleUpdatePropertyByAction
1341 * @tc.desc: HandleUpdatePropertyByAction function01
1342 * @tc.type: FUNC
1343 */
1344 HWTEST_F(SceneSessionTest5, HandleUpdatePropertyByAction, TestSize.Level1)
1345 {
1346 SessionInfo info;
1347 info.abilityName_ = "HandleUpdatePropertyByAction";
1348 info.bundleName_ = "HandleUpdatePropertyByAction";
1349 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1350 ASSERT_NE(nullptr, session);
1351 WSPropertyChangeAction action = WSPropertyChangeAction::ACTION_UPDATE_RECT;
1352 auto res = session->HandleUpdatePropertyByAction(nullptr, action);
1353 EXPECT_EQ(WMError::WM_ERROR_NULLPTR, res);
1354 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1355 ASSERT_NE(nullptr, property);
1356 res = session->HandleUpdatePropertyByAction(property, action);
1357 EXPECT_EQ(WMError::WM_DO_NOTHING, res);
1358 action = WSPropertyChangeAction::ACTION_UPDATE_FLAGS;
1359 res = session->HandleUpdatePropertyByAction(property, action);
1360 EXPECT_EQ(WMError::WM_OK, res);
1361 auto prop = session->GetSessionProperty();
1362 EXPECT_EQ(prop->GetSystemBarProperty(), property->GetSystemBarProperty());
1363 }
1364
1365 /**
1366 * @tc.name: SetSystemWindowEnableDrag
1367 * @tc.desc: SetSystemWindowEnableDrag function01
1368 * @tc.type: FUNC
1369 */
1370 HWTEST_F(SceneSessionTest5, SetSystemWindowEnableDrag, TestSize.Level1)
1371 {
1372 SessionInfo info;
1373 info.abilityName_ = "SetSystemWindowEnableDrag";
1374 info.bundleName_ = "SetSystemWindowEnableDrag";
1375 info.windowType_ = static_cast<uint32_t>(WindowType::WINDOW_TYPE_DESKTOP);
1376 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1377 auto ret = session->SetWindowEnableDragBySystem(true);
1378 EXPECT_EQ(WMError::WM_OK, ret);
1379 }
1380
1381 /**
1382 * @tc.name: SetWindowEnableDragBySystem
1383 * @tc.desc: SetWindowEnableDragBySystem function
1384 * @tc.type: FUNC
1385 */
1386 HWTEST_F(SceneSessionTest5, SetWindowEnableDragBySystem, TestSize.Level1)
1387 {
1388 SessionInfo info;
1389 info.abilityName_ = "SetWindowEnableDrag";
1390 info.bundleName_ = "SetWindowEnableDrag";
1391 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1392 auto ret = session->SetWindowEnableDragBySystem(true);
1393 EXPECT_EQ(WMError::WM_OK, ret);
1394 }
1395
1396 /**
1397 * @tc.name: HandleActionUpdateSetBrightness01
1398 * @tc.desc: HandleActionUpdateSetBrightness function01
1399 * @tc.type: FUNC
1400 */
1401 HWTEST_F(SceneSessionTest5, HandleActionUpdateSetBrightness01, TestSize.Level1)
1402 {
1403 SessionInfo info;
1404 info.abilityName_ = "HandleActionUpdateSetBrightness";
1405 info.bundleName_ = "HandleActionUpdateSetBrightness";
1406 info.windowType_ = static_cast<uint32_t>(WindowType::ABOVE_APP_SYSTEM_WINDOW_BASE);
1407 info.isSystem_ = true;
1408 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1409 ASSERT_NE(nullptr, session);
1410 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1411 ASSERT_NE(nullptr, property);
1412 WSPropertyChangeAction action = WSPropertyChangeAction::ACTION_UPDATE_RECT;
1413 auto res = session->HandleActionUpdateSetBrightness(property, action);
1414 EXPECT_EQ(WMError::WM_OK, res);
1415
1416 info.windowType_ = static_cast<uint32_t>(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1417 sptr<SceneSession> session1 = sptr<SceneSession>::MakeSptr(info, nullptr);
1418 res = session1->HandleActionUpdateSetBrightness(property, action);
1419 EXPECT_EQ(WMError::WM_ERROR_INVALID_SESSION, res);
1420
1421 info.isSystem_ = false;
1422 sptr<SceneSession> session2 = sptr<SceneSession>::MakeSptr(info, nullptr);
1423 session2->SetSessionState(SessionState::STATE_CONNECT);
1424 res = session2->HandleActionUpdateSetBrightness(property, action);
1425 EXPECT_EQ(WMError::WM_OK, res);
1426
1427 sptr<SceneSession> session3 = sptr<SceneSession>::MakeSptr(info, nullptr);
1428 session3->SetSessionState(SessionState::STATE_CONNECT);
1429 float brightness = 1.0;
1430 property->SetBrightness(brightness);
1431 EXPECT_EQ(brightness, property->GetBrightness());
1432 EXPECT_EQ(WSError::WS_OK, session3->SetBrightness(brightness));
1433 res = session3->HandleActionUpdateSetBrightness(property, action);
1434 EXPECT_EQ(WMError::WM_OK, res);
1435 EXPECT_EQ(brightness, session3->GetBrightness());
1436
1437 sptr<SceneSession> session4 = sptr<SceneSession>::MakeSptr(info, nullptr);
1438 session4->SetSessionState(SessionState::STATE_CONNECT);
1439 brightness = 0.8;
1440 property->SetBrightness(brightness);
1441 EXPECT_EQ(brightness, property->GetBrightness());
1442 res = session4->HandleActionUpdateSetBrightness(property, action);
1443 EXPECT_EQ(WMError::WM_OK, res);
1444 EXPECT_EQ(brightness, session4->GetBrightness());
1445 brightness = 1.0;
1446 EXPECT_EQ(WSError::WS_OK, session4->SetBrightness(brightness));
1447 EXPECT_EQ(brightness, session4->GetBrightness());
1448 }
1449
1450 /**
1451 * @tc.name: HandleActionUpdateSetBrightness02
1452 * @tc.desc: WINDOW_TYPE_WALLET_SWIPE_CARD
1453 * @tc.type: FUNC
1454 */
1455 HWTEST_F(SceneSessionTest5, HandleActionUpdateSetBrightness02, TestSize.Level1)
1456 {
1457 SessionInfo info;
1458 info.abilityName_ = "HandleActionUpdateSetBrightness";
1459 info.bundleName_ = "HandleActionUpdateSetBrightness";
1460 info.windowType_ = static_cast<uint32_t>(WindowType::WINDOW_TYPE_WALLET_SWIPE_CARD);
1461 info.isSystem_ = false;
1462 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1463 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1464 session->SetSessionState(SessionState::STATE_CONNECT);
1465 WSPropertyChangeAction action = WSPropertyChangeAction::ACTION_UPDATE_SET_BRIGHTNESS;
1466 auto res = session->HandleActionUpdateSetBrightness(property, action);
1467 EXPECT_EQ(WMError::WM_OK, res);
1468 }
1469
1470 /**
1471 * @tc.name: HandleActionUpdateMaximizeState
1472 * @tc.desc: HandleActionUpdateMaximizeState function01
1473 * @tc.type: FUNC
1474 */
1475 HWTEST_F(SceneSessionTest5, HandleActionUpdateMaximizeState, TestSize.Level1)
1476 {
1477 SessionInfo info;
1478 info.abilityName_ = "HandleActionUpdateMaximizeState";
1479 info.bundleName_ = "HandleActionUpdateMaximizeState";
1480 info.windowType_ = static_cast<uint32_t>(WindowType::ABOVE_APP_SYSTEM_WINDOW_BASE);
1481 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1482 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1483 WSPropertyChangeAction action = WSPropertyChangeAction::ACTION_UPDATE_RECT;
1484
1485 auto res = session->HandleActionUpdateMaximizeState(property, action);
1486 EXPECT_EQ(WMError::WM_OK, res);
1487 res = session->HandleActionUpdateMode(property, action);
1488 EXPECT_EQ(WMError::WM_OK, res);
1489 res = session->HandleActionUpdateAnimationFlag(property, action);
1490 EXPECT_EQ(WMError::WM_OK, res);
1491 }
1492
1493 /**
1494 * @tc.name: SetUniqueDensityDpi
1495 * @tc.desc: SetUniqueDensityDpi function01
1496 * @tc.type: FUNC
1497 */
1498 HWTEST_F(SceneSessionTest5, SetUniqueDensityDpi, TestSize.Level1)
1499 {
1500 SessionInfo info;
1501 info.abilityName_ = "SetUniqueDensityDpi";
1502 info.bundleName_ = "SetUniqueDensityDpi";
1503 info.windowType_ = static_cast<uint32_t>(WindowType::ABOVE_APP_SYSTEM_WINDOW_BASE);
1504 info.isSystem_ = true;
1505 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1506 EXPECT_NE(session, nullptr);
1507 session->sessionStage_ = nullptr;
1508 EXPECT_EQ(WMError::WM_ERROR_INVALID_SESSION, session->SetUniqueDensityDpi(true, 520));
1509 session->sessionInfo_.isSystem_ = false;
1510 session->state_ = SessionState::STATE_DISCONNECT;
1511 EXPECT_EQ(WMError::WM_ERROR_INVALID_SESSION, session->SetUniqueDensityDpi(true, 520));
1512 session->state_ = SessionState::STATE_CONNECT;
1513 EXPECT_EQ(WMError::WM_ERROR_NULLPTR, session->SetUniqueDensityDpi(true, 520));
1514 EXPECT_EQ(WMError::WM_ERROR_INVALID_PARAM, session->SetUniqueDensityDpi(true, 79));
1515 EXPECT_EQ(WMError::WM_ERROR_NULLPTR, session->SetUniqueDensityDpi(false, 79));
1516
1517 session->sessionStage_ = sptr<SessionStageMocker>::MakeSptr();
1518 EXPECT_NE(nullptr, session->sessionStage_);
1519 }
1520
1521 /**
1522 * @tc.name: HandleActionUpdateWindowModeSupportType
1523 * @tc.desc: HandleActionUpdateWindowModeSupportType function01
1524 * @tc.type: FUNC
1525 */
1526 HWTEST_F(SceneSessionTest5, HandleActionUpdateWindowModeSupportType, TestSize.Level1)
1527 {
1528 SessionInfo info;
1529 info.abilityName_ = "HandleActionUpdateWindowModeSupportType";
1530 info.bundleName_ = "HandleActionUpdateWindowModeSupportType";
1531 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1532 ASSERT_NE(session, nullptr);
1533 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1534
1535 property->isSystemCalling_ = false;
1536 session->SetSessionProperty(property);
1537 ASSERT_EQ(WMError::WM_ERROR_NOT_SYSTEM_APP,
1538 session->HandleActionUpdateWindowModeSupportType(property, WSPropertyChangeAction::ACTION_UPDATE_RECT));
1539 }
1540
1541 /**
1542 * @tc.name: UpdateUIParam
1543 * @tc.desc: UpdateUIParam function01
1544 * @tc.type: FUNC
1545 */
1546 HWTEST_F(SceneSessionTest5, UpdateUIParam, TestSize.Level1)
1547 {
1548 SessionInfo info;
1549 info.abilityName_ = "UpdateUIParam";
1550 info.bundleName_ = "UpdateUIParam";
1551 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1552 ASSERT_NE(session, nullptr);
1553 session->isFocused_ = true;
1554 session->isVisible_ = false;
1555 uint32_t res = session->UpdateUIParam();
1556 ASSERT_EQ(0, res);
1557 ASSERT_EQ(false, session->postProcessFocusState_.enabled_);
1558
1559 session->isFocused_ = true;
1560 session->isVisible_ = true;
1561 uint32_t res1 = session->UpdateUIParam();
1562 ASSERT_EQ(1, res1);
1563 ASSERT_EQ(true, session->postProcessFocusState_.enabled_);
1564 }
1565
1566 /**
1567 * @tc.name: UpdateVisibilityInner
1568 * @tc.desc: UpdateVisibilityInner function01
1569 * @tc.type: FUNC
1570 */
1571 HWTEST_F(SceneSessionTest5, UpdateVisibilityInner, TestSize.Level1)
1572 {
1573 SessionInfo info;
1574 info.abilityName_ = "UpdateVisibilityInner";
1575 info.bundleName_ = "UpdateVisibilityInner";
1576 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1577 ASSERT_NE(session, nullptr);
1578 session->isVisible_ = true;
1579 ASSERT_EQ(false, session->UpdateVisibilityInner(true));
1580 }
1581
1582 /**
1583 * @tc.name: UpdateInteractiveInner
1584 * @tc.desc: UpdateInteractiveInner function01
1585 * @tc.type: FUNC
1586 */
1587 HWTEST_F(SceneSessionTest5, UpdateInteractiveInner, TestSize.Level1)
1588 {
1589 SessionInfo info;
1590 info.abilityName_ = "UpdateInteractiveInner";
1591 info.bundleName_ = "UpdateInteractiveInner";
1592 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1593 ASSERT_NE(session, nullptr);
1594 session->foregroundInteractiveStatus_.store(true);
1595 ASSERT_EQ(false, session->UpdateInteractiveInner(true));
1596 ASSERT_EQ(true, session->UpdateInteractiveInner(false));
1597 }
1598
1599 /**
1600 * @tc.name: IsAnco
1601 * @tc.desc: IsAnco function01
1602 * @tc.type: FUNC
1603 */
1604 HWTEST_F(SceneSessionTest5, IsAnco, TestSize.Level1)
1605 {
1606 SessionInfo info;
1607 info.abilityName_ = "IsAnco";
1608 info.bundleName_ = "IsAnco";
1609 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1610 EXPECT_NE(session, nullptr);
1611 bool res = session->IsAnco();
1612 EXPECT_EQ(res, false);
1613
1614 session->collaboratorType_ = CollaboratorType::RESERVE_TYPE;
1615 res = session->IsAnco();
1616 EXPECT_EQ(res, true);
1617 }
1618
1619 /**
1620 * @tc.name: ProcessUpdatePropertyByAction
1621 * @tc.desc: ProcessUpdatePropertyByAction function01
1622 * @tc.type: FUNC
1623 */
1624 HWTEST_F(SceneSessionTest5, ProcessUpdatePropertyByAction, TestSize.Level1)
1625 {
1626 SessionInfo info;
1627 info.abilityName_ = "ProcessUpdatePropertyByAction";
1628 info.bundleName_ = "ProcessUpdatePropertyByAction";
1629 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1630 EXPECT_NE(session, nullptr);
1631
1632 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1633 EXPECT_NE(property, nullptr);
1634
1635 session->ProcessUpdatePropertyByAction(property, WSPropertyChangeAction::ACTION_UPDATE_KEEP_SCREEN_ON);
1636 session->ProcessUpdatePropertyByAction(property, WSPropertyChangeAction::ACTION_UPDATE_FOCUSABLE);
1637 session->ProcessUpdatePropertyByAction(property, WSPropertyChangeAction::ACTION_UPDATE_TOUCHABLE);
1638 session->ProcessUpdatePropertyByAction(property, WSPropertyChangeAction::ACTION_UPDATE_SET_BRIGHTNESS);
1639 session->ProcessUpdatePropertyByAction(property, WSPropertyChangeAction::ACTION_UPDATE_ORIENTATION);
1640 session->ProcessUpdatePropertyByAction(property, WSPropertyChangeAction::ACTION_UPDATE_PRIVACY_MODE);
1641 session->ProcessUpdatePropertyByAction(property, WSPropertyChangeAction::ACTION_UPDATE_SYSTEM_PRIVACY_MODE);
1642 session->ProcessUpdatePropertyByAction(property, WSPropertyChangeAction::ACTION_UPDATE_SNAPSHOT_SKIP);
1643 session->ProcessUpdatePropertyByAction(property, WSPropertyChangeAction::ACTION_UPDATE_MAXIMIZE_STATE);
1644 session->ProcessUpdatePropertyByAction(property, WSPropertyChangeAction::ACTION_UPDATE_OTHER_PROPS);
1645 session->ProcessUpdatePropertyByAction(property, WSPropertyChangeAction::ACTION_UPDATE_STATUS_PROPS);
1646 session->ProcessUpdatePropertyByAction(property, WSPropertyChangeAction::ACTION_UPDATE_NAVIGATION_INDICATOR_PROPS);
1647 session->ProcessUpdatePropertyByAction(property, WSPropertyChangeAction::ACTION_UPDATE_FLAGS);
1648 session->ProcessUpdatePropertyByAction(property, WSPropertyChangeAction::ACTION_UPDATE_MODE);
1649 session->ProcessUpdatePropertyByAction(property, WSPropertyChangeAction::ACTION_UPDATE_ANIMATION_FLAG);
1650 session->ProcessUpdatePropertyByAction(property, WSPropertyChangeAction::ACTION_UPDATE_TOUCH_HOT_AREA);
1651 session->ProcessUpdatePropertyByAction(property, WSPropertyChangeAction::ACTION_UPDATE_DECOR_ENABLE);
1652 session->ProcessUpdatePropertyByAction(property, WSPropertyChangeAction::ACTION_UPDATE_WINDOW_LIMITS);
1653 session->ProcessUpdatePropertyByAction(property, WSPropertyChangeAction::ACTION_UPDATE_DRAGENABLED);
1654 session->ProcessUpdatePropertyByAction(property, WSPropertyChangeAction::ACTION_UPDATE_RAISEENABLED);
1655 session->ProcessUpdatePropertyByAction(property,
1656 WSPropertyChangeAction::ACTION_UPDATE_HIDE_NON_SYSTEM_FLOATING_WINDOWS);
1657 session->ProcessUpdatePropertyByAction(property, WSPropertyChangeAction::ACTION_UPDATE_TEXTFIELD_AVOID_INFO);
1658 session->ProcessUpdatePropertyByAction(property, WSPropertyChangeAction::ACTION_UPDATE_WINDOW_MASK);
1659 session->ProcessUpdatePropertyByAction(property, WSPropertyChangeAction::ACTION_UPDATE_TOPMOST);
1660 session->ProcessUpdatePropertyByAction(property, WSPropertyChangeAction::ACTION_UPDATE_MODE_SUPPORT_INFO);
1661 }
1662
1663 /**
1664 * @tc.name: HandleActionUpdateTurnScreenOn
1665 * @tc.desc: HandleActionUpdateTurnScreenOn function01
1666 * @tc.type: FUNC
1667 */
1668 HWTEST_F(SceneSessionTest5, HandleActionUpdateTurnScreenOn, TestSize.Level0)
1669 {
1670 SessionInfo info;
1671 info.abilityName_ = "HandleActionUpdateTurnScreenOn";
1672 info.bundleName_ = "HandleActionUpdateTurnScreenOn";
1673 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1674 EXPECT_NE(session, nullptr);
1675
1676 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1677 EXPECT_NE(property, nullptr);
1678
1679 auto res = session->HandleActionUpdateTurnScreenOn(property, WSPropertyChangeAction::ACTION_UPDATE_TURN_SCREEN_ON);
1680 EXPECT_EQ(res, WMError::WM_OK);
1681
1682 property->SetTurnScreenOn(true);
1683 res = session->HandleActionUpdateTurnScreenOn(property, WSPropertyChangeAction::ACTION_UPDATE_TURN_SCREEN_ON);
1684 EXPECT_EQ(res, WMError::WM_OK);
1685 }
1686
1687 /**
1688 * @tc.name: HandleActionUpdatePrivacyMode1
1689 * @tc.desc: HandleActionUpdatePrivacyMode1
1690 * @tc.type: FUNC
1691 */
1692 HWTEST_F(SceneSessionTest5, HandleActionUpdatePrivacyMode1, TestSize.Level0)
1693 {
1694 SessionInfo info;
1695 info.abilityName_ = "HandleActionUpdatePrivacyMode1";
1696 info.bundleName_ = "HandleActionUpdatePrivacyMode1";
1697 info.windowType_ = static_cast<uint32_t>(WindowType::APP_MAIN_WINDOW_BASE);
1698 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1699 EXPECT_NE(session, nullptr);
1700 EXPECT_NE(session->property_, nullptr);
1701 struct RSSurfaceNodeConfig config;
1702 std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Create(config);
1703 session->surfaceNode_ = surfaceNode;
1704 session->property_->SetPrivacyMode(false);
1705 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1706 property->SetPrivacyMode(true);
1707 auto res = session->HandleActionUpdatePrivacyMode(property, WSPropertyChangeAction::ACTION_UPDATE_PRIVACY_MODE);
1708 EXPECT_EQ(WMError::WM_OK, res);
1709 EXPECT_EQ(true, session->property_->GetPrivacyMode());
1710 }
1711
1712 /**
1713 * @tc.name: HandleActionUpdatePrivacyMode2
1714 * @tc.desc: HandleActionUpdatePrivacyMode2
1715 * @tc.type: FUNC
1716 */
1717 HWTEST_F(SceneSessionTest5, HandleActionUpdatePrivacyMode2, TestSize.Level1)
1718 {
1719 SessionInfo info;
1720 info.abilityName_ = "HandleActionUpdatePrivacyMode2";
1721 info.bundleName_ = "HandleActionUpdatePrivacyMode2";
1722 info.windowType_ = static_cast<uint32_t>(WindowType::APP_MAIN_WINDOW_BASE);
1723 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1724 EXPECT_NE(session, nullptr);
1725 EXPECT_NE(session->property_, nullptr);
1726 struct RSSurfaceNodeConfig config;
1727 std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Create(config);
1728 session->surfaceNode_ = surfaceNode;
1729 session->property_->SetPrivacyMode(true);
1730 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1731 property->SetPrivacyMode(false);
1732 auto res = session->HandleActionUpdatePrivacyMode(property, WSPropertyChangeAction::ACTION_UPDATE_PRIVACY_MODE);
1733 EXPECT_EQ(WMError::WM_OK, res);
1734 EXPECT_EQ(false, session->property_->GetPrivacyMode());
1735 }
1736
1737 /**
1738 * @tc.name: UpdateClientRect01
1739 * @tc.desc: UpdateClientRect
1740 * @tc.type: FUNC
1741 */
1742 HWTEST_F(SceneSessionTest5, UpdateClientRect01, TestSize.Level1)
1743 {
1744 SessionInfo info;
1745 info.abilityName_ = "UpdateClientRect01";
1746 info.bundleName_ = "UpdateClientRect01";
1747 info.windowType_ = static_cast<uint32_t>(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
1748 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1749
1750 WSRect rect = { 0, 0, 0, 0 };
1751 EXPECT_EQ(session->UpdateClientRect(rect), WSError::WS_OK);
1752
1753 session->SetClientRect(rect);
1754 rect.posX_ = 100;
1755 rect.posY_ = 100;
1756 rect.width_ = 800;
1757 rect.height_ = 800;
1758 EXPECT_EQ(session->UpdateClientRect(rect), WSError::WS_OK);
1759
1760 session->SetClientRect(rect);
1761 EXPECT_EQ(session->UpdateClientRect(rect), WSError::WS_OK);
1762 }
1763
1764 /**
1765 * @tc.name: ResetSizeChangeReasonIfDirty
1766 * @tc.desc: ResetSizeChangeReasonIfDirty
1767 * @tc.type: FUNC
1768 */
1769 HWTEST_F(SceneSessionTest5, ResetSizeChangeReasonIfDirty, TestSize.Level1)
1770 {
1771 SessionInfo info;
1772 info.abilityName_ = "ResetSizeChangeReasonIfDirty";
1773 info.bundleName_ = "ResetSizeChangeReasonIfDirty";
1774 info.windowType_ = static_cast<uint32_t>(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
1775 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1776
1777 session->UpdateSizeChangeReason(SizeChangeReason::DRAG);
1778 session->ResetDirtyFlags();
1779 session->ResetSizeChangeReasonIfDirty();
1780 EXPECT_EQ(session->GetSizeChangeReason(), SizeChangeReason::DRAG);
1781
1782 session->dirtyFlags_ |= static_cast<uint32_t>(SessionUIDirtyFlag::RECT);
1783 session->ResetSizeChangeReasonIfDirty();
1784 EXPECT_EQ(session->GetSizeChangeReason(), SizeChangeReason::DRAG);
1785
1786 session->UpdateSizeChangeReason(SizeChangeReason::MOVE);
1787 session->ResetSizeChangeReasonIfDirty();
1788 EXPECT_EQ(session->GetSizeChangeReason(), SizeChangeReason::UNDEFINED);
1789 }
1790
1791 /**
1792 * @tc.name: HandleMoveDragSurfaceNode
1793 * @tc.desc: HandleMoveDragSurfaceNode Test
1794 * @tc.type: FUNC
1795 */
1796 HWTEST_F(SceneSessionTest5, HandleMoveDragSurfaceNode, TestSize.Level1)
1797 {
1798 SessionInfo info;
1799 info.abilityName_ = "HandleMoveDragSurfaceNode";
1800 info.bundleName_ = "HandleMoveDragSurfaceNode";
1801 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1802 EXPECT_NE(session, nullptr);
1803
1804 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1805 EXPECT_NE(property, nullptr);
1806
1807 session->moveDragController_ = sptr<MoveDragController>::MakeSptr(2024, session->GetWindowType());
1808 EXPECT_NE(session->moveDragController_, nullptr);
1809
1810 session->HandleMoveDragSurfaceNode(SizeChangeReason::DRAG_START);
1811 session->HandleMoveDragSurfaceNode(SizeChangeReason::DRAG);
1812 session->HandleMoveDragSurfaceNode(SizeChangeReason::DRAG_MOVE);
1813 session->HandleMoveDragSurfaceNode(SizeChangeReason::DRAG_END);
1814 }
1815
1816 /**
1817 * @tc.name: HandleMoveDragSurfaceBounds
1818 * @tc.desc: HandleMoveDragSurfaceBounds Test
1819 * @tc.type: FUNC
1820 */
1821 HWTEST_F(SceneSessionTest5, HandleMoveDragSurfaceBounds, TestSize.Level1)
1822 {
1823 SessionInfo info;
1824 info.abilityName_ = "HandleMoveDragSurfaceBounds";
1825 info.bundleName_ = "HandleMoveDragSurfaceBounds";
1826 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1827 session->moveDragController_ = sptr<MoveDragController>::MakeSptr(1000, session->GetWindowType());
1828 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1829
1830 WSRect preRect = { 0, 0, 50, 50 };
1831 WSRect rect = { 0, 0, 100, 100 };
1832 WSRect globalRect = { 0, 0, 100, 100 };
1833
__anonbd9130011302(const std::shared_ptr<VsyncCallback>& callback) 1834 session->SetRequestNextVsyncFunc([](const std::shared_ptr<VsyncCallback>& callback) {
1835 callback->onCallback(1, 1);
1836 });
1837 ASSERT_NE(nullptr, session->requestNextVsyncFunc_);
1838 session->SetSessionRect(preRect);
1839 EXPECT_EQ(preRect, session->GetSessionRect());
1840 session->keyFramePolicy_.running_ = true;
1841 session->HandleMoveDragSurfaceBounds(rect, globalRect, SizeChangeReason::DRAG_MOVE);
1842 EXPECT_EQ(preRect, session->GetSessionRect());
1843 session->HandleMoveDragSurfaceBounds(rect, globalRect, SizeChangeReason::DRAG);
1844 EXPECT_EQ(rect, session->GetSessionRect());
1845
1846 session->keyFramePolicy_.running_ = false;
1847 session->HandleMoveDragSurfaceBounds(rect, globalRect, SizeChangeReason::DRAG_END);
1848 session->HandleMoveDragSurfaceBounds(rect, globalRect, SizeChangeReason::DRAG);
1849 EXPECT_EQ(rect, session->GetSessionRect());
1850 }
1851
1852 /**
1853 * @tc.name: HandleMoveDragSurfaceBounds02
1854 * @tc.desc: HandleMoveDragSurfaceBounds for interrupted
1855 * @tc.type: FUNC
1856 */
1857 HWTEST_F(SceneSessionTest5, HandleMoveDragSurfaceBounds02, TestSize.Level1)
1858 {
1859 SessionInfo info;
1860 info.abilityName_ = "HandleMoveDragSurfaceBounds02";
1861 info.bundleName_ = "HandleMoveDragSurfaceBounds02";
1862 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1863 session->moveDragController_ = sptr<MoveDragController>::MakeSptr(1000, session->GetWindowType());
1864 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1865 WSRect preRect = { 0, 0, 50, 50 };
1866 WSRect rect = { 0, 0, 100, 100 };
1867 WSRect globalRect = { 0, 0, 100, 100 };
__anonbd9130011402(const std::shared_ptr<VsyncCallback>& callback) 1868 session->SetRequestNextVsyncFunc([](const std::shared_ptr<VsyncCallback>& callback) {
1869 callback->onCallback(1, 1);
1870 });
1871 ASSERT_NE(nullptr, session->requestNextVsyncFunc_);
1872 session->SetSessionRect(preRect);
1873 EXPECT_EQ(preRect, session->GetSessionRect());
1874 session->keyFramePolicy_.running_ = false;
1875 session->moveDragController_->SetStartDragFlag(false);
1876 session->HandleMoveDragSurfaceBounds(rect, globalRect, SizeChangeReason::DRAG_END);
1877 session->HandleMoveDragSurfaceBounds(rect, globalRect, SizeChangeReason::DRAG);
1878 EXPECT_EQ(rect, session->GetSessionRect());
1879 EXPECT_EQ(false, session->moveDragController_->GetStartDragFlag());
1880
1881 session->moveDragController_->SetStartDragFlag(true);
1882 session->HandleMoveDragSurfaceBounds(rect, globalRect, SizeChangeReason::DRAG);
1883 EXPECT_EQ(rect, session->GetSessionRect());
1884 session->HandleMoveDragSurfaceBounds(rect, globalRect, SizeChangeReason::DRAG_END);
1885 EXPECT_EQ(true, session->moveDragController_->GetStartDragFlag());
1886 }
1887
1888 /**
1889 * @tc.name: OnNextVsyncReceivedWhenDrag
1890 * @tc.desc: OnNextVsyncReceivedWhenDrag
1891 * @tc.type: FUNC
1892 */
1893 HWTEST_F(SceneSessionTest5, OnNextVsyncReceivedWhenDrag, TestSize.Level1)
1894 {
1895 SessionInfo info;
1896 info.abilityName_ = "OnNextVsyncReceivedWhenDrag";
1897 info.bundleName_ = "OnNextVsyncReceivedWhenDrag";
1898 LOG_SetCallback(MyLogCallback);
1899 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1900 session->moveDragController_ = nullptr;
1901 WSRect globalRect = { 0, 0, 100, 100 };
1902 bool isGlobal = true;
1903 bool needFlush = true;
1904 bool needSetBoundsNextVsync = true;
1905 session->UpdateRectForDrag(globalRect);
1906 session->OnNextVsyncReceivedWhenDrag(globalRect, isGlobal, needFlush, needSetBoundsNextVsync);
1907 EXPECT_TRUE(g_errLog.find("session moveDragController is null") != std::string::npos);
1908 }
1909
1910 /**
1911 * @tc.name: SetNotifyVisibleChangeFunc
1912 * @tc.desc: SetNotifyVisibleChangeFunc Test
1913 * @tc.type: FUNC
1914 */
1915 HWTEST_F(SceneSessionTest5, SetNotifyVisibleChangeFunc, TestSize.Level1)
1916 {
1917 SessionInfo info;
1918 info.abilityName_ = "test";
1919 info.bundleName_ = "test";
1920 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1921 EXPECT_NE(session, nullptr);
1922
__anonbd9130011502(int32_t persistentId) 1923 session->SetNotifyVisibleChangeFunc([](int32_t persistentId) {});
1924 EXPECT_NE(session->notifyVisibleChangeFunc_, nullptr);
1925 }
1926
1927 /**
1928 * @tc.name: SetRequestNextVsyncFunc
1929 * @tc.desc: SetRequestNextVsyncFunc01 Test
1930 * @tc.type: FUNC
1931 */
1932 HWTEST_F(SceneSessionTest5, SetRequestNextVsyncFunc01, TestSize.Level1)
1933 {
1934 SessionInfo info;
1935 info.abilityName_ = "test1";
1936 info.bundleName_ = "test1";
1937 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1938
1939 session->SetRequestNextVsyncFunc(nullptr);
1940 ASSERT_EQ(nullptr, session->requestNextVsyncFunc_);
1941
__anonbd9130011602(const std::shared_ptr<VsyncCallback>& callback) 1942 session->SetRequestNextVsyncFunc([](const std::shared_ptr<VsyncCallback>& callback) {
1943 SessionInfo info1;
1944 info1.abilityName_ = "test2";
1945 info1.bundleName_ = "test2";
1946 });
1947 ASSERT_NE(nullptr, session->requestNextVsyncFunc_);
1948 }
1949
1950 /**
1951 * @tc.name: NotifyServerToUpdateRect01
1952 * @tc.desc: NotifyServerToUpdateRect01 Test
1953 * @tc.type: FUNC
1954 */
1955 HWTEST_F(SceneSessionTest5, NotifyServerToUpdateRect01, TestSize.Level1)
1956 {
1957 SessionInfo info;
1958 info.abilityName_ = "NotifyServerToUpdateRect01";
1959 info.bundleName_ = "NotifyServerToUpdateRect01";
1960 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1961 EXPECT_NE(session, nullptr);
1962
1963 session->foregroundInteractiveStatus_.store(true);
1964 EXPECT_EQ(session->GetForegroundInteractiveStatus(), true);
1965
1966 SessionUIParam uiParam;
1967 EXPECT_EQ(session->NotifyServerToUpdateRect(uiParam, SizeChangeReason::UNDEFINED), false);
1968
1969 uiParam.rect_ = { 100, 100, 200, 200 };
1970 session->SetNeedSyncSessionRect(false);
1971 EXPECT_EQ(session->NotifyServerToUpdateRect(uiParam, SizeChangeReason::UNDEFINED), false); // not sync
1972 EXPECT_NE(session->GetSessionRect(), uiParam.rect_);
1973
1974 uiParam.needSync_ = false;
1975 EXPECT_EQ(session->NotifyServerToUpdateRect(uiParam, SizeChangeReason::UNDEFINED), false); // not sync
1976 EXPECT_NE(session->GetSessionRect(), uiParam.rect_);
1977
1978 uiParam.needSync_ = true;
1979 session->SetNeedSyncSessionRect(true); // sync first
1980 EXPECT_EQ(session->NotifyServerToUpdateRect(uiParam, SizeChangeReason::UNDEFINED), true);
1981 EXPECT_EQ(session->GetSessionRect(), uiParam.rect_);
1982
1983 session->SetClientRect(session->GetSessionRect());
1984 EXPECT_EQ(session->NotifyServerToUpdateRect(uiParam, SizeChangeReason::UNDEFINED), false); // skip same rect
1985 }
1986
1987 /**
1988 * @tc.name: MoveUnderInteriaAndNotifyRectChange
1989 * @tc.desc: test func: MoveUnderInteriaAndNotifyRectChange
1990 * @tc.type: FUNC
1991 */
1992 HWTEST_F(SceneSessionTest5, MoveUnderInteriaAndNotifyRectChange, TestSize.Level1)
1993 {
1994 SessionInfo info;
1995 info.abilityName_ = "MoveUnderInteriaAndNotifyRectChange";
1996 info.bundleName_ = "MoveUnderInteriaAndNotifyRectChange";
1997 info.screenId_ = 0;
1998 sptr<MainSession> mainSession = sptr<MainSession>::MakeSptr(info, nullptr);
1999 ASSERT_NE(mainSession->pcFoldScreenController_, nullptr);
2000 auto controller = mainSession->pcFoldScreenController_;
2001 WSRect rect = { 0, 0, 100, 100 };
2002 EXPECT_FALSE(mainSession->MoveUnderInteriaAndNotifyRectChange(rect, SizeChangeReason::DRAG_END));
2003 PcFoldScreenManager::GetInstance().UpdateFoldScreenStatus(
2004 0, SuperFoldStatus::HALF_FOLDED, { 0, 0, 2472, 1648 }, { 0, 1648, 2472, 1648 }, { 0, 1624, 2472, 1648 });
2005 PcFoldScreenManager::GetInstance().vpr_ = 1.7f;
2006
2007 WSRect rect0 = { 100, 100, 400, 400 };
2008 WSRect rect1 = { 100, 500, 400, 400 };
2009
2010 // throw
2011 controller->RecordStartMoveRect(rect0, false);
2012 controller->RecordMoveRects(rect0);
2013 usleep(10000);
2014 rect = rect1;
2015 controller->RecordMoveRects(rect);
2016 EXPECT_TRUE(mainSession->MoveUnderInteriaAndNotifyRectChange(rect, SizeChangeReason::DRAG_END));
2017
2018 // throw full screen
2019 usleep(100000);
2020 controller->RecordStartMoveRect(rect0, true);
2021 controller->RecordMoveRects(rect0);
2022 usleep(10000);
2023 rect = rect1;
2024 controller->RecordMoveRects(rect);
2025 EXPECT_TRUE(mainSession->MoveUnderInteriaAndNotifyRectChange(rect, SizeChangeReason::DRAG_END));
2026 }
2027
2028 /**
2029 * @tc.name: WindowScaleTransfer01
2030 * @tc.desc: WindowScaleTransfer01
2031 * @tc.type: FUNC
2032 */
2033 HWTEST_F(SceneSessionTest5, WindowScaleTransfer01, TestSize.Level1)
2034 {
2035 SessionInfo info;
2036 info.abilityName_ = "WindowScaleTransfer01";
2037 info.bundleName_ = "WindowScaleTransfer01";
2038 info.screenId_ = 0;
2039 sptr<MainSession> mainSession = sptr<MainSession>::MakeSptr(info, nullptr);
2040 WSRect rect = { 100, 100, 400, 400 };
2041 WSRect resultRect = { 200, 200, 200, 200 };
2042 float scaleX = 0.5f;
2043 float scaleY = 0.5f;
2044 mainSession->GetLayoutController()->SetSessionRect(rect);
2045 mainSession->SetScale(scaleX, scaleY, 0.5f, 0.5f);
2046 mainSession->WindowScaleTransfer(mainSession->GetLayoutController()->winRect_, scaleX, scaleY);
2047 EXPECT_EQ(mainSession->GetSessionRect(), resultRect);
2048 }
2049
2050 /**
2051 * @tc.name: WindowScaleTransfer02
2052 * @tc.desc: WindowScaleTransfer02
2053 * @tc.type: FUNC
2054 */
2055 HWTEST_F(SceneSessionTest5, WindowScaleTransfer02, TestSize.Level1)
2056 {
2057 SessionInfo info;
2058 info.abilityName_ = "WindowScaleTransfer02";
2059 info.bundleName_ = "WindowScaleTransfer02";
2060 info.screenId_ = 0;
2061 sptr<MainSession> mainSession = sptr<MainSession>::MakeSptr(info, nullptr);
2062 WSRect rect = { 200, 200, 200, 200 };
2063 WSRect resultRect = { 100, 100, 400, 400 };
2064 float scaleX = 2.0f;
2065 float scaleY = 2.0f;
2066 mainSession->GetLayoutController()->SetSessionRect(rect);
2067 mainSession->SetScale(scaleX, scaleY, 0.5f, 0.5f);
2068 mainSession->WindowScaleTransfer(mainSession->GetLayoutController()->winRect_, scaleX, scaleY);
2069 EXPECT_EQ(mainSession->GetSessionRect(), resultRect);
2070 }
2071
2072 /**
2073 * @tc.name: IsCompatibilityModeScale01
2074 * @tc.desc: IsCompatibilityModeScale01
2075 * @tc.type: FUNC
2076 */
2077 HWTEST_F(SceneSessionTest5, IsCompatibilityModeScale01, TestSize.Level1)
2078 {
2079 SessionInfo info;
2080 info.abilityName_ = "IsCompatibilityModeScale01";
2081 info.bundleName_ = "IsCompatibilityModeScale01";
2082 info.screenId_ = 0;
2083 sptr<MainSession> mainSession = sptr<MainSession>::MakeSptr(info, nullptr);
2084 auto property = mainSession->GetSessionProperty();
2085 float scaleX = 2.0f;
2086 float scaleY = 2.0f;
2087 sptr<CompatibleModeProperty> compatibleModeProperty = sptr<CompatibleModeProperty>::MakeSptr();
2088 compatibleModeProperty->SetIsAdaptToProportionalScale(true);
2089 mainSession->property_->SetCompatibleModeProperty(compatibleModeProperty);
2090 bool res = mainSession->IsCompatibilityModeScale(scaleX, scaleY);
2091 EXPECT_EQ(res, true);
2092 compatibleModeProperty->SetIsAdaptToProportionalScale(false);
2093 mainSession->property_->SetCompatibleModeProperty(compatibleModeProperty);
2094 res = mainSession->IsCompatibilityModeScale(scaleX, scaleY);
2095 EXPECT_EQ(res, false);
2096 }
2097
2098 /**
2099 * @tc.name: IsCompatibilityModeScale02
2100 * @tc.desc: IsCompatibilityModeScale02
2101 * @tc.type: FUNC
2102 */
2103 HWTEST_F(SceneSessionTest5, IsCompatibilityModeScale02, TestSize.Level1)
2104 {
2105 SessionInfo info;
2106 info.abilityName_ = "IsCompatibilityModeScale02";
2107 info.bundleName_ = "IsCompatibilityModeScale02";
2108 info.screenId_ = 0;
2109 sptr<MainSession> mainSession = sptr<MainSession>::MakeSptr(info, nullptr);
2110 auto property = mainSession->GetSessionProperty();
2111 float scaleX = 1.0f;
2112 float scaleY = 1.0f;
2113 sptr<CompatibleModeProperty> compatibleModeProperty = sptr<CompatibleModeProperty>::MakeSptr();
2114 compatibleModeProperty->SetIsAdaptToProportionalScale(true);
2115 mainSession->property_->SetCompatibleModeProperty(compatibleModeProperty);
2116 bool res = mainSession->IsCompatibilityModeScale(scaleX, scaleY);
2117 EXPECT_EQ(res, false);
2118 compatibleModeProperty->SetIsAdaptToProportionalScale(false);
2119 mainSession->property_->SetCompatibleModeProperty(compatibleModeProperty);
2120 res = mainSession->IsCompatibilityModeScale(scaleX, scaleY);
2121 EXPECT_EQ(res, false);
2122 }
2123
2124 /**
2125 * @tc.name: HookStartMoveRect
2126 * @tc.desc: HookStartMoveRect
2127 * @tc.type: FUNC
2128 */
2129 HWTEST_F(SceneSessionTest5, HookStartMoveRect, TestSize.Level1)
2130 {
2131 SessionInfo info;
2132 info.abilityName_ = "HookStartMoveRect";
2133 info.bundleName_ = "HookStartMoveRect";
2134 info.screenId_ = 0;
2135 sptr<MainSession> mainSession = sptr<MainSession>::MakeSptr(info, nullptr);
2136 WSRect preRect = { 100, 100, 400, 400 };
2137 WSRect resultRect = { 200, 200, 200, 200 };
2138 float scaleX = 0.5f;
2139 float scaleY = 0.5f;
2140 mainSession->SetScale(scaleX, scaleY, 0.5f, 0.5f);
2141 mainSession->SetSessionRect(preRect);
2142 EXPECT_EQ(preRect, mainSession->GetSessionRect());
2143 auto property = mainSession->GetSessionProperty();
2144 sptr<CompatibleModeProperty> compatibleModeProperty = sptr<CompatibleModeProperty>::MakeSptr();
2145 compatibleModeProperty->SetIsAdaptToProportionalScale(false);
2146 mainSession->property_->SetCompatibleModeProperty(compatibleModeProperty);
2147 WSRect currRect;
2148 mainSession->HookStartMoveRect(currRect, mainSession->GetSessionRect());
2149 EXPECT_EQ(preRect, currRect);
2150 compatibleModeProperty->SetIsAdaptToProportionalScale(true);
2151 mainSession->property_->SetCompatibleModeProperty(compatibleModeProperty);
2152 mainSession->HookStartMoveRect(currRect, mainSession->GetSessionRect());
2153 EXPECT_EQ(resultRect, currRect);
2154 }
2155
2156 /**
2157 * @tc.name: CompatibilityModeWindowScaleTransfer
2158 * @tc.desc: CompatibilityModeWindowScaleTransfer
2159 * @tc.type: FUNC
2160 */
2161 HWTEST_F(SceneSessionTest5, CompatibilityModeWindowScaleTransfer, TestSize.Level1)
2162 {
2163 SessionInfo info;
2164 info.abilityName_ = "CompatibilityModeWindowScaleTransfer";
2165 info.bundleName_ = "CompatibilityModeWindowScaleTransfer";
2166 info.screenId_ = 0;
2167 sptr<MainSession> mainSession = sptr<MainSession>::MakeSptr(info, nullptr);
2168 WSRect preRect = { 100, 100, 400, 400 };
2169 WSRect noChangeRect = { 100, 100, 400, 400 };
2170 WSRect resultRect = { 200, 200, 200, 200 };
2171 float scaleX = 0.5f;
2172 float scaleY = 0.5f;
2173 bool isScale = true;
2174 mainSession->SetScale(scaleX, scaleY, 0.5f, 0.5f);
2175 sptr<CompatibleModeProperty> compatibleModeProperty = sptr<CompatibleModeProperty>::MakeSptr();
2176 compatibleModeProperty->SetIsAdaptToProportionalScale(false);
2177 mainSession->property_->SetCompatibleModeProperty(compatibleModeProperty);
2178 mainSession->CompatibilityModeWindowScaleTransfer(preRect, isScale);
2179 EXPECT_EQ(noChangeRect, preRect);
2180 compatibleModeProperty->SetIsAdaptToProportionalScale(true);
2181 mainSession->property_->SetCompatibleModeProperty(compatibleModeProperty);
2182 mainSession->CompatibilityModeWindowScaleTransfer(preRect, isScale);
2183 EXPECT_EQ(resultRect, preRect);
2184 isScale = false;
2185 mainSession->CompatibilityModeWindowScaleTransfer(preRect, isScale);
2186 EXPECT_EQ(noChangeRect, preRect);
2187 }
2188
2189 /**
2190 * @tc.name: ThrowSlipDirectly
2191 * @tc.desc: ThrowSlipDirectly
2192 * @tc.type: FUNC
2193 */
2194 HWTEST_F(SceneSessionTest5, ThrowSlipDirectly, TestSize.Level1)
2195 {
2196 SessionInfo info;
2197 info.abilityName_ = "ThrowSlipDirectly";
2198 info.bundleName_ = "ThrowSlipDirectly";
2199 info.screenId_ = 0;
2200 sptr<MainSession> mainSession = sptr<MainSession>::MakeSptr(info, nullptr);
2201 WSRect rect = { 100, 100, 400, 400 };
2202 mainSession->GetLayoutController()->SetSessionRect(rect);
2203 mainSession->ThrowSlipDirectly(ThrowSlipMode::THREE_FINGERS_SWIPE, WSRectF{ 0.0f, 0.0f, 0.0f, 0.0f });
2204 EXPECT_EQ(mainSession->GetSessionRect(), rect);
2205 }
2206
2207 /**
2208 * @tc.name: MarkSystemSceneUIFirst
2209 * @tc.desc: MarkSystemSceneUIFirst function01
2210 * @tc.type: FUNC
2211 */
2212 HWTEST_F(SceneSessionTest5, MarkSystemSceneUIFirst, TestSize.Level1)
2213 {
2214 SessionInfo info;
2215 info.abilityName_ = "MarkSystemSceneUIFirst";
2216 info.bundleName_ = "MarkSystemSceneUIFirst";
2217 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
2218 EXPECT_NE(session, nullptr);
2219 session->MarkSystemSceneUIFirst(true, true);
2220
2221 struct RSSurfaceNodeConfig config;
2222 std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Create(config);
2223 session->surfaceNode_ = surfaceNode;
2224 session->leashWinSurfaceNode_ = nullptr;
2225 session->MarkSystemSceneUIFirst(true, true);
2226 session->leashWinSurfaceNode_ = surfaceNode;
2227 session->MarkSystemSceneUIFirst(true, true);
2228 EXPECT_NE(nullptr, session->GetLeashWinSurfaceNode());
2229 }
2230
2231 /**
2232 * @tc.name: IsMissionHighlighted
2233 * @tc.desc: IsMissionHighlighted
2234 * @tc.type: FUNC
2235 */
2236 HWTEST_F(SceneSessionTest5, IsMissionHighlighted, TestSize.Level1)
2237 {
2238 SessionInfo info;
2239 info.abilityName_ = "IsMissionHighlighted";
2240 info.bundleName_ = "IsMissionHighlighted";
2241 sptr<MainSession> mainSession = sptr<MainSession>::MakeSptr(info, nullptr);
2242 mainSession->isFocused_ = true;
2243 EXPECT_TRUE(mainSession->IsMissionHighlighted());
2244 mainSession->isFocused_ = false;
2245
2246 SessionInfo subInfo;
2247 subInfo.abilityName_ = "IsMissionHighlightedSub";
2248 subInfo.bundleName_ = "IsMissionHighlightedSub";
2249 sptr<SceneSession> subSession = sptr<SceneSession>::MakeSptr(subInfo, nullptr);
2250 mainSession->subSession_.push_back(subSession);
2251 subSession->isFocused_ = true;
2252 EXPECT_TRUE(mainSession->IsMissionHighlighted());
2253 subSession->isFocused_ = false;
2254 EXPECT_FALSE(mainSession->IsMissionHighlighted());
2255 }
2256
2257 /**
2258 * @tc.name: SetSessionDisplayIdChangeCallback
2259 * @tc.desc: SetSessionDisplayIdChangeCallback
2260 * @tc.type: FUNC
2261 */
2262 HWTEST_F(SceneSessionTest5, SetSessionDisplayIdChangeCallback, TestSize.Level1)
2263 {
2264 const SessionInfo info;
2265 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
__anonbd9130011702(uint64_t displayId) 2266 sceneSession->SetSessionDisplayIdChangeCallback([](uint64_t displayId) { return; });
2267 ASSERT_NE(sceneSession->sessionDisplayIdChangeFunc_, nullptr);
2268 }
2269
2270 /**
2271 * @tc.name: NotifySessionDisplayIdChange
2272 * @tc.desc: NotifySessionDisplayIdChange
2273 * @tc.type: FUNC
2274 */
2275 HWTEST_F(SceneSessionTest5, NotifySessionDisplayIdChange, TestSize.Level1)
2276 {
2277 const SessionInfo info;
2278 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
2279 uint64_t checkDisplayId = 345;
2280 uint64_t moveDisplayId = 456;
__anonbd9130011802(uint64_t displayId) 2281 sceneSession->sessionDisplayIdChangeFunc_ = [&checkDisplayId](uint64_t displayId) { checkDisplayId = displayId; };
2282 sceneSession->NotifySessionDisplayIdChange(moveDisplayId);
2283 ASSERT_EQ(moveDisplayId, checkDisplayId);
2284 }
2285
2286 /**
2287 * @tc.name: CheckAndMoveDisplayIdRecursively
2288 * @tc.desc: CheckAndMoveDisplayIdRecursively
2289 * @tc.type: FUNC
2290 */
2291 HWTEST_F(SceneSessionTest5, CheckAndMoveDisplayIdRecursively, TestSize.Level1)
2292 {
2293 const SessionInfo info;
2294 sptr<SceneSessionMocker> sceneSession = sptr<SceneSessionMocker>::MakeSptr(info, nullptr);
2295 uint64_t displayId = 234;
2296 sptr<SceneSessionMocker> subSession = sptr<SceneSessionMocker>::MakeSptr(info, nullptr);
2297 sceneSession->subSession_.push_back(subSession);
2298 EXPECT_CALL(*sceneSession, CheckAndMoveDisplayIdRecursively(displayId))
__anonbd9130011902(uint64_t displayId) 2299 .WillRepeatedly([weakThis = wptr(sceneSession)](uint64_t displayId) {
2300 auto session = weakThis.promote();
2301 if (session) {
2302 return weakThis->SceneSession::CheckAndMoveDisplayIdRecursively(displayId);
2303 } else {
2304 GTEST_LOG_(INFO) << "SceneSessionMocker:NULL";
2305 return;
2306 }
2307 });
2308 sceneSession->property_->SetDisplayId(displayId);
2309 sceneSession->shouldFollowParentWhenShow_ = true;
2310 EXPECT_CALL(*sceneSession, SetScreenId(displayId)).Times(0);
2311 sceneSession->CheckAndMoveDisplayIdRecursively(displayId);
2312 sceneSession->property_->SetDisplayId(123);
2313 sceneSession->shouldFollowParentWhenShow_ = false;
2314 EXPECT_CALL(*sceneSession, SetScreenId(displayId)).Times(0);
2315 sceneSession->CheckAndMoveDisplayIdRecursively(displayId);
2316 sceneSession->property_->SetDisplayId(123);
2317 sceneSession->shouldFollowParentWhenShow_ = true;
2318 EXPECT_CALL(*sceneSession, SetScreenId(displayId)).Times(1);
2319 EXPECT_CALL(*subSession, CheckAndMoveDisplayIdRecursively(displayId)).Times(1);
2320 sceneSession->CheckAndMoveDisplayIdRecursively(displayId);
2321 ASSERT_EQ(sceneSession->property_->GetDisplayId(), displayId);
2322 }
2323
2324 /**
2325 * @tc.name: SetShouldFollowParentWhenShow
2326 * @tc.desc: SetShouldFollowParentWhenShow
2327 * @tc.type: FUNC
2328 */
2329 HWTEST_F(SceneSessionTest5, SetShouldFollowParentWhenShow, TestSize.Level1)
2330 {
2331 const SessionInfo info;
2332 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
2333 sceneSession->SetShouldFollowParentWhenShow(false);
2334 ASSERT_EQ(sceneSession->shouldFollowParentWhenShow_, false);
2335 }
2336
2337 HWTEST_F(SceneSessionTest5, CheckSubSessionShouldFollowParent, TestSize.Level1)
2338 {
2339 const SessionInfo info;
2340 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
2341 sptr<SceneSession> subSession = sptr<SceneSession>::MakeSptr(info, nullptr);
2342 sceneSession->subSession_.push_back(subSession);
2343 subSession->state_ = SessionState::STATE_ACTIVE;
2344 uint64_t displayIdBase = 123;
2345 uint64_t displayIdDiff = 345;
2346 subSession->property_->SetDisplayId(displayIdBase);
2347 sceneSession->CheckSubSessionShouldFollowParent(displayIdBase);
2348 sceneSession->CheckSubSessionShouldFollowParent(displayIdBase);
2349 EXPECT_EQ(subSession->shouldFollowParentWhenShow_, true);
2350 sceneSession->CheckSubSessionShouldFollowParent(displayIdDiff);
2351 EXPECT_EQ(subSession->shouldFollowParentWhenShow_, false);
2352 }
2353
2354 /**
2355 * @tc.name: ActivateKeyboardAvoidArea01
2356 * @tc.desc: test ActivateKeyboardAvoidArea
2357 * @tc.type: FUNC
2358 */
2359 HWTEST_F(SceneSessionTest5, ActivateKeyboardAvoidArea01, TestSize.Level1)
2360 {
2361 SessionInfo info;
2362 info.bundleName_ = "ActivateKeyboardAvoidArea01";
2363 info.abilityName_ = "ActivateKeyboardAvoidArea01";
2364 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
2365 ASSERT_EQ(true, sceneSession->IsKeyboardAvoidAreaActive());
2366 sceneSession->ActivateKeyboardAvoidArea(false, true);
2367 ASSERT_EQ(false, sceneSession->IsKeyboardAvoidAreaActive());
2368 sceneSession->ActivateKeyboardAvoidArea(false, false);
2369 ASSERT_EQ(false, sceneSession->IsKeyboardAvoidAreaActive());
2370 sceneSession->ActivateKeyboardAvoidArea(true, true);
2371 ASSERT_EQ(true, sceneSession->IsKeyboardAvoidAreaActive());
2372 sceneSession->ActivateKeyboardAvoidArea(true, false);
2373 ASSERT_EQ(true, sceneSession->IsKeyboardAvoidAreaActive());
2374 }
2375
2376 /**
2377 * @tc.name: IsSameMainSession
2378 * @tc.desc: test IsSameMainSession
2379 * @tc.type: FUNC
2380 */
2381 HWTEST_F(SceneSessionTest5, IsSameMainSession, TestSize.Level1)
2382 {
2383 SessionInfo info1;
2384 info1.abilityName_ = "abilityName_test1";
2385 info1.bundleName_ = "bundleName_test1";
2386 SessionInfo info2;
2387 info2.abilityName_ = "abilityName_test2";
2388 info2.bundleName_ = "bundleName_test2";
2389 sptr<SceneSession> preSceneSession = sptr<SceneSession>::MakeSptr(info1, nullptr);
2390 sptr<SceneSession> currSceneSession = sptr<SceneSession>::MakeSptr(info2, nullptr);
2391 preSceneSession->persistentId_ = 1;
2392 currSceneSession->persistentId_ = 1;
2393 ASSERT_EQ(true, currSceneSession->IsSameMainSession(preSceneSession));
2394 currSceneSession->persistentId_ = 2;
2395 ASSERT_EQ(false, currSceneSession->IsSameMainSession(preSceneSession));
2396
2397 sptr<SceneSession> subSession1 = sptr<SceneSession>::MakeSptr(info1, nullptr);
2398 sptr<SceneSession> subSession2 = sptr<SceneSession>::MakeSptr(info2, nullptr);
2399 subSession1->SetParentSession(preSceneSession);
2400 subSession2->SetParentSession(currSceneSession);
2401 currSceneSession->persistentId_ = 1;
2402 subSession1->property_->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
2403 subSession2->property_->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
2404 ASSERT_EQ(true, subSession1->IsSameMainSession(subSession1));
2405 currSceneSession->persistentId_ = 2;
2406 ASSERT_EQ(false, subSession1->IsSameMainSession(subSession2));
2407 }
2408
2409 /**
2410 * @tc.name: HandleActionUpdateExclusivelyHighlighted
2411 * @tc.desc: test HandleActionUpdateExclusivelyHighlighted
2412 * @tc.type: FUNC
2413 */
2414 HWTEST_F(SceneSessionTest5, HandleActionUpdateExclusivelyHighlighted, TestSize.Level1)
2415 {
2416 SessionInfo info;
2417 info.abilityName_ = "HandleActionUpdateExclusivelyHighlighted";
2418 info.bundleName_ = "HandleActionUpdateExclusivelyHighlighted";
2419 info.isSystem_ = true;
2420 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
2421 ASSERT_NE(nullptr, session);
2422 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
2423 ASSERT_NE(nullptr, property);
2424 property->SetExclusivelyHighlighted(true);
2425 WSPropertyChangeAction action = WSPropertyChangeAction::ACTION_UPDATE_EXCLUSIVE_HIGHLIGHTED;
2426 auto res = session->HandleActionUpdateExclusivelyHighlighted(property, action);
2427 EXPECT_EQ(WMError::WM_OK, res);
2428 }
2429
2430 /**
2431 * @tc.name: SetHighlightChangeNotifyFunc
2432 * @tc.desc: SetHighlightChangeNotifyFunc Test
2433 * @tc.type: FUNC
2434 */
2435 HWTEST_F(SceneSessionTest5, SetHighlightChangeNotifyFunc, TestSize.Level1)
2436 {
2437 SessionInfo info;
2438 info.abilityName_ = "test";
2439 info.bundleName_ = "test";
2440 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
2441 EXPECT_NE(session, nullptr);
__anonbd9130011a02(int32_t persistentId) 2442 session->SetHighlightChangeNotifyFunc([](int32_t persistentId) {});
2443 EXPECT_NE(session->highlightChangeFunc_, nullptr);
2444 }
2445
2446 /**
2447 * @tc.name: StartMovingWithCoordinate_01
2448 * @tc.desc: StartMovingWithCoordinate
2449 * @tc.type: FUNC
2450 */
2451 HWTEST_F(SceneSessionTest5, StartMovingWithCoordinate_01, TestSize.Level1)
2452 {
2453 const SessionInfo info;
2454 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
2455 sceneSession->moveDragController_ = nullptr;
2456 WSError result = sceneSession->StartMovingWithCoordinate(100, 50, 300, 500, 0);
2457 EXPECT_EQ(result, WSError::WS_ERROR_NULLPTR);
2458 }
2459
2460 /**
2461 * @tc.name: StartMovingWithCoordinate_02
2462 * @tc.desc: StartMovingWithCoordinate
2463 * @tc.type: FUNC
2464 */
2465 HWTEST_F(SceneSessionTest5, StartMovingWithCoordinate_02, TestSize.Level1)
2466 {
2467 const SessionInfo info;
2468 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
2469 sceneSession->moveDragController_ = sptr<MoveDragController>::MakeSptr(2024, sceneSession->GetWindowType());
2470 sceneSession->moveDragController_->isStartMove_ = true;
2471 WSError result = sceneSession->StartMovingWithCoordinate(100, 50, 300, 500, 0);
2472 EXPECT_EQ(result, WSError::WS_ERROR_REPEAT_OPERATION);
2473 }
2474
2475 /**
2476 * @tc.name: StartMovingWithCoordinate_03
2477 * @tc.desc: StartMovingWithCoordinate
2478 * @tc.type: FUNC
2479 */
2480 HWTEST_F(SceneSessionTest5, StartMovingWithCoordinate_03, TestSize.Level1)
2481 {
2482 const SessionInfo info;
2483 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
2484 sceneSession->moveDragController_ = sptr<MoveDragController>::MakeSptr(2024, sceneSession->GetWindowType());
2485 sceneSession->moveDragController_->isStartMove_ = false;
2486 WSError result = sceneSession->StartMovingWithCoordinate(100, 50, 300, 500, 0);
2487 EXPECT_EQ(result, WSError::WS_OK);
2488 }
2489
2490 /**
2491 * @tc.name: StartMovingWithCoordinate_04
2492 * @tc.desc: StartMovingWithCoordinate
2493 * @tc.type: FUNC
2494 */
2495 HWTEST_F(SceneSessionTest5, StartMovingWithCoordinate_04, TestSize.Level1)
2496 {
2497 const SessionInfo info;
2498 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
2499 sceneSession->moveDragController_ = sptr<MoveDragController>::MakeSptr(2024, sceneSession->GetWindowType());
2500 sceneSession->moveDragController_->isStartMove_ = false;
2501 WSError result = sceneSession->StartMovingWithCoordinate(100, 50, 300, 500, 999);
2502 EXPECT_EQ(result, WSError::WS_OK);
2503 }
2504
2505 /**
2506 * @tc.name: SetColorSpace
2507 * @tc.desc: SetColorSpace function01
2508 * @tc.type: FUNC
2509 */
2510 HWTEST_F(SceneSessionTest5, SetColorSpace, TestSize.Level1)
2511 {
2512 SessionInfo info;
2513 info.abilityName_ = "SetColorSpace";
2514 info.bundleName_ = "SetColorSpace";
2515 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
2516 EXPECT_NE(session, nullptr);
2517
2518 struct RSSurfaceNodeConfig config;
2519 std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Create(config);
2520 session->SetColorSpace(ColorSpace::COLOR_SPACE_WIDE_GAMUT);
2521 EXPECT_EQ(nullptr, session->GetSurfaceNode());
2522 session->surfaceNode_ = surfaceNode;
2523 session->SetColorSpace(ColorSpace::COLOR_SPACE_WIDE_GAMUT);
2524 EXPECT_NE(nullptr, session->GetSurfaceNode());
2525 }
2526
2527 /**
2528 * @tc.name: UpdateCrossAxisOfLayout
2529 * @tc.desc: UpdateCrossAxisOfLayout
2530 * @tc.type: FUNC
2531 */
2532 HWTEST_F(SceneSessionTest5, UpdateCrossAxisOfLayout, TestSize.Level1)
2533 {
2534 const SessionInfo info;
2535 sptr<SceneSessionMocker> sceneSession = sptr<SceneSessionMocker>::MakeSptr(info, nullptr);
2536 WSRect rect;
2537 EXPECT_CALL(*sceneSession, UpdateCrossAxis()).Times(1);
2538 sceneSession->SceneSession::UpdateCrossAxisOfLayout(rect);
2539 }
2540
2541 /**
2542 * @tc.name: UpdateCrossAxis
2543 * @tc.desc: UpdateCrossAxis
2544 * @tc.type: FUNC
2545 */
2546 HWTEST_F(SceneSessionTest5, UpdateCrossAxis, TestSize.Level1)
2547 {
2548 const SessionInfo info;
2549 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
2550 auto sessionStageMocker = sptr<SessionStageMocker>::MakeSptr();
2551 sceneSession->sessionStage_ = sessionStageMocker;
2552 // always have ovelap with axis
2553 sceneSession->isCrossAxisOfLayout_ = true;
2554 // not fold screen
2555 PcFoldScreenManager::GetInstance().displayId_ = SCREEN_ID_INVALID;
2556 EXPECT_CALL(*sessionStageMocker, NotifyWindowCrossAxisChange(_)).Times(0);
2557 sceneSession->UpdateCrossAxis();
2558 // fold screen, but fold status unknown
2559 PcFoldScreenManager::GetInstance().displayId_ = 0;
2560 sceneSession->GetSessionProperty()->displayId_ = 0;
2561 PcFoldScreenManager::GetInstance().screenFoldStatus_ = SuperFoldStatus::UNKNOWN;
2562 sceneSession->crossAxisState_ = 100;
2563 EXPECT_CALL(*sessionStageMocker, NotifyWindowCrossAxisChange(CrossAxisState::STATE_INVALID)).Times(1);
2564 sceneSession->UpdateCrossAxis();
2565 // state: half folded
2566 sceneSession->crossAxisState_ = 100;
2567 PcFoldScreenManager::GetInstance().screenFoldStatus_ = SuperFoldStatus::HALF_FOLDED;
2568 EXPECT_CALL(*sessionStageMocker, NotifyWindowCrossAxisChange(CrossAxisState::STATE_CROSS)).Times(1);
2569 sceneSession->UpdateCrossAxis();
2570 // state: other
2571 sceneSession->crossAxisState_ = 100;
2572 PcFoldScreenManager::GetInstance().screenFoldStatus_ = SuperFoldStatus::EXPANDED;
2573 EXPECT_CALL(*sessionStageMocker, NotifyWindowCrossAxisChange(CrossAxisState::STATE_NO_CROSS)).Times(1);
2574 sceneSession->UpdateCrossAxis();
2575 // sessionStage is nullptr
2576 sceneSession->crossAxisState_ = 100;
2577 sceneSession->sessionStage_ = nullptr;
2578 EXPECT_CALL(*sessionStageMocker, NotifyWindowCrossAxisChange(_)).Times(0);
2579 sceneSession->UpdateCrossAxis();
2580 }
2581
2582 /**
2583 * @tc.name: GetCrossAxisState
2584 * @tc.desc: GetCrossAxisState
2585 * @tc.type: FUNC
2586 */
2587 HWTEST_F(SceneSessionTest5, GetCrossAxisState, TestSize.Level1)
2588 {
2589 const SessionInfo info;
2590 sptr<SceneSessionMocker> sceneSession = sptr<SceneSessionMocker>::MakeSptr(info, nullptr);
2591 sceneSession->crossAxisState_ = 1;
2592 CrossAxisState state = CrossAxisState::STATE_INVALID;
2593 sceneSession->GetCrossAxisState(state);
2594 EXPECT_EQ(state, CrossAxisState::STATE_CROSS);
2595 }
2596
2597 /**
2598 * @tc.name: GetWaterfallMode
2599 * @tc.desc: GetWaterfallMode
2600 * @tc.type: FUNC
2601 */
2602 HWTEST_F(SceneSessionTest5, GetWaterfallMode, TestSize.Level1)
2603 {
2604 SessionInfo info;
2605 info.abilityName_ = "GetWaterfallMode";
2606 info.bundleName_ = "GetWaterfallMode";
2607 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
2608 EXPECT_NE(session, nullptr);
2609 bool isWaterfallMode = true;
2610 session->GetWaterfallMode(isWaterfallMode);
2611 EXPECT_EQ(isWaterfallMode, false);
2612 }
2613
2614 /**
2615 * @tc.name: UpdateDensity
2616 * @tc.desc: UpdateDensity Test
2617 * @tc.type: FUNC
2618 */
2619 HWTEST_F(SceneSessionTest5, UpdateDensity, TestSize.Level1)
2620 {
2621 SessionInfo info;
2622 info.abilityName_ = "updateDensity";
2623 info.bundleName_ = "updateDensity";
2624 info.windowType_ = static_cast<uint32_t>(WindowType::APP_MAIN_WINDOW_END);
2625 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
2626 ASSERT_NE(nullptr, session);
2627 SystemSessionConfig systemConfig;
2628 systemConfig.windowUIType_ = WindowUIType::PC_WINDOW;
2629 session->SetSystemConfig(systemConfig);
2630 session->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
2631 session->property_->SetLastLimitsVpr(1.9f);
2632 session->property_->SetDisplayId(0);
2633
2634 WSRect rect = { 10, 10, 800, 600 };
2635 session->GetLayoutController()->SetSessionRect(rect);
2636 DMRect availableArea = { 0, 0, 1000, 800 };
2637 ScreenProperty screenProperty;
2638 screenProperty.SetAvailableArea(availableArea);
2639 ScreenSessionConfig config = {
2640 .screenId = 0,
2641 .rsId = 0,
2642 .name = "updateDensity",
2643 .property = screenProperty,
2644 };
2645 sptr<ScreenSession> screenSession = sptr<ScreenSession>::MakeSptr();
2646 ASSERT_NE(nullptr, screenSession);
2647
2648 session->UpdateDensity();
2649 WSRect resultRect = { 10, 10, 800, 600 };
2650 EXPECT_EQ(session->GetSessionRect(), resultRect);
2651 }
2652
2653 /**
2654 * @tc.name: NotifyRotationChange
2655 * @tc.desc: NotifyRotationChange
2656 * @tc.type: FUNC
2657 */
2658 HWTEST_F(SceneSessionTest5, NotifyRotationChange, Function | SmallTest | Level2)
2659 {
2660 const SessionInfo info;
2661 sptr<SceneSessionMocker> session = sptr<SceneSessionMocker>::MakeSptr(info, nullptr);
2662 session->sessionStage_ = nullptr;
2663 session->isRotationChangeCallbackRegistered = false;
2664 RotationChangeInfo rotationInfo = { RotationChangeType::WINDOW_WILL_ROTATE, 0, 0, { 0, 0, 2720, 1270 } };
2665 RotationChangeResult res = session->NotifyRotationChange(rotationInfo);
2666 EXPECT_EQ(res.windowRect_.width_, 0);
2667
2668 session->isRotationChangeCallbackRegistered = true;
2669 res = session->NotifyRotationChange(rotationInfo);
2670 EXPECT_EQ(res.windowRect_.width_, 0);
2671
2672 sptr<SessionStageMocker> sessionStageMocker = sptr<SessionStageMocker>::MakeSptr();
2673 ASSERT_NE(sessionStageMocker, nullptr);
2674 session->sessionStage_ = sessionStageMocker;
2675 res = session->NotifyRotationChange(rotationInfo);
2676 EXPECT_EQ(res.windowRect_.width_, 0);
2677 }
2678
2679 /**
2680 * @tc.name: NotifyRotationChange_IsRestrictNotify_SystemWindow
2681 * @tc.desc: NotifyRotationChange_IsRestrictNotify_SystemWindow
2682 * @tc.type: FUNC
2683 */
2684 HWTEST_F(SceneSessionTest5, NotifyRotationChange_IsRestrictNotify_SystemWindow, Function | SmallTest | Level2)
2685 {
2686 sptr<SessionStageMocker> sessionStageMocker = sptr<SessionStageMocker>::MakeSptr();
2687 ASSERT_NE(sessionStageMocker, nullptr);
2688 RotationChangeInfo rotationInfo = { RotationChangeType::WINDOW_WILL_ROTATE, 0, 0, { 0, 0, 2720, 1270 } };
2689 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
2690
2691 SessionInfo info;
2692 property->SetWindowType(WindowType::WINDOW_TYPE_DESKTOP);
2693 sptr<SceneSessionMocker> session = sptr<SceneSessionMocker>::MakeSptr(info, nullptr);
2694 session->isRotationChangeCallbackRegistered = true;
2695 session->sessionStage_ = sessionStageMocker;
2696 bool isRestrictNotify = false;
2697 property->isSystemCalling_ = true;
2698 session->SetSessionProperty(property);
2699 RotationChangeResult res = session->NotifyRotationChange(rotationInfo, isRestrictNotify);
2700 EXPECT_EQ(res.windowRect_.width_, 0);
2701
2702 property->isSystemCalling_ = false;
2703 session->SetSessionProperty(property);
2704 res = session->NotifyRotationChange(rotationInfo, isRestrictNotify);
2705 EXPECT_EQ(res.windowRect_.width_, 0);
2706
2707 isRestrictNotify = true;
2708 property->isSystemCalling_ = true;
2709 session->SetSessionProperty(property);
2710 res = session->NotifyRotationChange(rotationInfo, isRestrictNotify);
2711 EXPECT_EQ(res.windowRect_.width_, 0);
2712
2713 property->isSystemCalling_ = false;
2714 session->SetSessionProperty(property);
2715 res = session->NotifyRotationChange(rotationInfo, isRestrictNotify);
2716 EXPECT_EQ(res.windowRect_.width_, 0);
2717 }
2718
2719 /**
2720 * @tc.name: NotifyRotationChange_IsRestrictNotify_NotSystemWindow
2721 * @tc.desc: NotifyRotationChange_IsRestrictNotify_NotSystemWindow
2722 * @tc.type: FUNC
2723 */
2724 HWTEST_F(SceneSessionTest5, NotifyRotationChange_IsRestrictNotify_NotSystemWindow, Function | SmallTest | Level2)
2725 {
2726 sptr<SessionStageMocker> sessionStageMocker = sptr<SessionStageMocker>::MakeSptr();
2727 ASSERT_NE(sessionStageMocker, nullptr);
2728 RotationChangeInfo rotationInfo = { RotationChangeType::WINDOW_WILL_ROTATE, 0, 0, { 0, 0, 2720, 1270 } };
2729 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
2730
2731 SessionInfo info;
2732 property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
2733 sptr<SceneSessionMocker> session = sptr<SceneSessionMocker>::MakeSptr(info, nullptr);
2734 session->isRotationChangeCallbackRegistered = true;
2735 session->sessionStage_ = sessionStageMocker;
2736 bool isRestrictNotify = false;
2737 property->isSystemCalling_ = true;
2738 session->SetSessionProperty(property);
2739 RotationChangeResult res = session->NotifyRotationChange(rotationInfo, isRestrictNotify);
2740 EXPECT_EQ(res.windowRect_.width_, 0);
2741
2742 property->isSystemCalling_ = false;
2743 session->SetSessionProperty(property);
2744 res = session->NotifyRotationChange(rotationInfo, isRestrictNotify);
2745 EXPECT_EQ(res.windowRect_.width_, 0);
2746
2747 isRestrictNotify = true;
2748 property->isSystemCalling_ = true;
2749 session->SetSessionProperty(property);
2750 res = session->NotifyRotationChange(rotationInfo, isRestrictNotify);
2751 EXPECT_EQ(res.windowRect_.width_, 0);
2752
2753 property->isSystemCalling_ = false;
2754 session->SetSessionProperty(property);
2755 res = session->NotifyRotationChange(rotationInfo, isRestrictNotify);
2756 EXPECT_EQ(res.windowRect_.width_, 0);
2757 }
2758
2759 /**
2760 * @tc.name: SetSessionGetTargetOrientationConfigInfoCallback
2761 * @tc.desc: SetSessionGetTargetOrientationConfigInfoCallback
2762 * @tc.type: FUNC
2763 */
2764 HWTEST_F(SceneSessionTest5, SetSessionGetTargetOrientationConfigInfoCallback, Function | SmallTest | Level2)
2765 {
2766 SessionInfo info;
2767 info.abilityName_ = "SetSessionGetTargetOrientationConfigInfoCallback";
2768 info.bundleName_ = "SetSessionGetTargetOrientationConfigInfoCallback";
2769
2770 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
2771 EXPECT_NE(sceneSession, nullptr);
2772
__anonbd9130011b02(uint32_t targetOrientation) 2773 sceneSession->SetSessionGetTargetOrientationConfigInfoCallback([](uint32_t targetOrientation) { return; });
2774 EXPECT_NE(sceneSession->sessionGetTargetOrientationConfigInfoFunc_, nullptr);
2775 }
2776
2777 /**
2778 * @tc.name: GetTargetOrientationConfigInfo
2779 * @tc.desc: GetTargetOrientationConfigInfo
2780 * @tc.type: FUNC
2781 */
2782 HWTEST_F(SceneSessionTest5, GetTargetOrientationConfigInfo, Function | SmallTest | Level2)
2783 {
2784 SessionInfo info;
2785 info.abilityName_ = "GetTargetOrientationConfigInfo";
2786 info.bundleName_ = "GetTargetOrientationConfigInfo";
2787
2788 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
2789 EXPECT_NE(sceneSession, nullptr);
2790
2791 Orientation orientation = Orientation::USER_ROTATION_PORTRAIT;
2792 std::map<Rosen::WindowType, Rosen::SystemBarProperty> properties;
__anonbd9130011c02(uint32_t targetOrientation) 2793 NotifySessionGetTargetOrientationConfigInfoFunc func = [](uint32_t targetOrientation) {};
2794 sceneSession->sessionGetTargetOrientationConfigInfoFunc_ = func;
2795 sceneSession->GetTargetOrientationConfigInfo(orientation, properties);
2796 EXPECT_NE(sceneSession->sessionGetTargetOrientationConfigInfoFunc_, nullptr);
2797 }
2798
2799 /**
2800 * @tc.name: NotifyRotationProperty
2801 * @tc.desc: NotifyRotationProperty
2802 * @tc.type: FUNC
2803 */
2804 HWTEST_F(SceneSessionTest5, NotifyRotationProperty, Function | SmallTest | Level2)
2805 {
2806 SessionInfo info;
2807 info.abilityName_ = "NotifyRotationProperty";
2808 info.bundleName_ = "NotifyRotationProperty";
2809
2810 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
2811 EXPECT_NE(sceneSession, nullptr);
2812
2813 WSError result = sceneSession->NotifyRotationProperty(0, 0, 0);
2814 EXPECT_EQ(result, WSError::WS_OK);
2815 WSError result1 = sceneSession->NotifyRotationProperty(0, 0, 1);
2816 EXPECT_EQ(result1, WSError::WS_OK);
2817 WSError result2 = sceneSession->NotifyRotationProperty(0, 1, 1);
2818 EXPECT_EQ(result2, WSError::WS_OK);
2819 WSError result3 = sceneSession->NotifyRotationProperty(90, 1, 1);
2820 EXPECT_EQ(result3, WSError::WS_OK);
2821 }
2822
2823 /**
2824 * @tc.name: GetSystemBarPropertyForRotation
2825 * @tc.desc: GetSystemBarPropertyForRotation
2826 * @tc.type: FUNC
2827 */
2828 HWTEST_F(SceneSessionTest5, GetSystemBarPropertyForRotation, Function | SmallTest | Level2)
2829 {
2830 SessionInfo info;
2831 info.abilityName_ = "GetSystemBarPropertyForRotation";
2832 info.bundleName_ = "GetSystemBarPropertyForRotation";
2833
2834 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
2835 EXPECT_NE(sceneSession, nullptr);
2836
2837 std::map<Rosen::WindowType, Rosen::SystemBarProperty> properties;
2838 sceneSession->SetSystemBarPropertyForRotation(properties);
2839 EXPECT_EQ(sceneSession->GetSystemBarPropertyForRotation(), properties);
2840 }
2841 } // namespace
2842 } // namespace Rosen
2843 } // namespace OHOS