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
19 #include "common/include/session_permission.h"
20 #include "display_manager.h"
21 #include "input_event.h"
22 #include "key_event.h"
23
24 #include "mock/mock_session_stage.h"
25 #include "pointer_event.h"
26
27 #include "screen_manager.h"
28 #include "session/host/include/sub_session.h"
29 #include "session/host/include/main_session.h"
30 #include "session/host/include/scene_session.h"
31 #include "session/host/include/system_session.h"
32 #include "session/screen/include/screen_session.h"
33 #include "screen_session_manager/include/screen_session_manager_client.h"
34 #include "wm_common.h"
35 #include "window_helper.h"
36 #include "ui/rs_surface_node.h"
37
38 using namespace testing;
39 using namespace testing::ext;
40 namespace OHOS {
41 namespace Rosen {
42
43 class GetKeyboardGravitySceneSession : public SceneSession {
44 public:
GetKeyboardGravitySceneSession(const SessionInfo & info,const sptr<SpecificSessionCallback> & specificCallback)45 GetKeyboardGravitySceneSession(const SessionInfo& info, const sptr<SpecificSessionCallback>& specificCallback)
46 : SceneSession(info, specificCallback)
47 {
48 }
49
GetKeyboardGravity() const50 SessionGravity GetKeyboardGravity() const override
51 {
52 return SessionGravity::SESSION_GRAVITY_FLOAT;
53 }
54 };
55
56 class SceneSessionTest5 : public testing::Test {
57 public:
58 static void SetUpTestCase();
59 static void TearDownTestCase();
60 void SetUp() override;
61 void TearDown() override;
62 };
63
SetUpTestCase()64 void SceneSessionTest5::SetUpTestCase()
65 {
66 }
67
TearDownTestCase()68 void SceneSessionTest5::TearDownTestCase()
69 {
70 }
71
SetUp()72 void SceneSessionTest5::SetUp()
73 {
74 }
75
TearDown()76 void SceneSessionTest5::TearDown()
77 {
78 }
79
80 namespace {
81
82 /**
83 * @tc.name: FixKeyboardPositionByKeyboardPanel
84 * @tc.desc: FixKeyboardPositionByKeyboardPanel function
85 * @tc.type: FUNC
86 */
87 HWTEST_F(SceneSessionTest5, FixKeyboardPositionByKeyboardPanel, Function | SmallTest | Level2)
88 {
89 SessionInfo info;
90 info.abilityName_ = "FixKeyboardPositionByKeyboardPanel";
91 info.bundleName_ = "FixKeyboardPositionByKeyboardPanel";
92
93 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
94 EXPECT_NE(session, nullptr);
95
96 sptr<SceneSession> panelSession = nullptr;
97 sptr<SceneSession> keyboardSession = nullptr;
98 session->FixKeyboardPositionByKeyboardPanel(panelSession, keyboardSession);
99 panelSession = session;
100 session->FixKeyboardPositionByKeyboardPanel(panelSession, keyboardSession);
101 keyboardSession = sptr<SceneSession>::MakeSptr(info, nullptr);
102 session->FixKeyboardPositionByKeyboardPanel(panelSession, keyboardSession);
103
104 keyboardSession = session;
105 session->property_ = nullptr;
106 session->FixKeyboardPositionByKeyboardPanel(panelSession, keyboardSession);
107
108 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
109 session->SetSessionProperty(property);
110 session->FixKeyboardPositionByKeyboardPanel(panelSession, keyboardSession);
111 EXPECT_EQ(property, session->GetSessionProperty());
112 }
113
114 /**
115 * @tc.name: NotifyClientToUpdateRectTask
116 * @tc.desc: NotifyClientToUpdateRectTask function
117 * @tc.type: FUNC
118 */
119 HWTEST_F(SceneSessionTest5, NotifyClientToUpdateRectTask, Function | SmallTest | Level2)
120 {
121 SessionInfo info;
122 info.abilityName_ = "NotifyClientToUpdateRectTask";
123 info.bundleName_ = "NotifyClientToUpdateRectTask";
124 info.isSystem_ = true;
125
126 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
127 EXPECT_NE(session, nullptr);
128
129 session->moveDragController_ = nullptr;
130 session->isKeyboardPanelEnabled_ = false;
131
132 session->Session::UpdateSizeChangeReason(SizeChangeReason::UNDEFINED);
133 EXPECT_EQ(WSError::WS_ERROR_INVALID_SESSION, session->NotifyClientToUpdateRectTask("SceneSessionTest5", nullptr));
134 session->Session::UpdateSizeChangeReason(SizeChangeReason::MOVE);
135 EXPECT_EQ(WSError::WS_ERROR_INVALID_SESSION, session->NotifyClientToUpdateRectTask("SceneSessionTest5", nullptr));
136 session->Session::UpdateSizeChangeReason(SizeChangeReason::DRAG_MOVE);
137 EXPECT_EQ(WSError::WS_ERROR_INVALID_SESSION, session->NotifyClientToUpdateRectTask("SceneSessionTest5", nullptr));
138 session->Session::UpdateSizeChangeReason(SizeChangeReason::RESIZE);
139 EXPECT_EQ(WSError::WS_ERROR_INVALID_SESSION, session->NotifyClientToUpdateRectTask("SceneSessionTest5", nullptr));
140 session->Session::UpdateSizeChangeReason(SizeChangeReason::RECOVER);
141 EXPECT_EQ(session->reason_, SizeChangeReason::RECOVER);
142 EXPECT_EQ(WSError::WS_ERROR_INVALID_SESSION, session->NotifyClientToUpdateRectTask("SceneSessionTest5", nullptr));
143
144 session->moveDragController_ = sptr<MoveDragController>::MakeSptr(2024);
145 session->moveDragController_->isStartDrag_ = true;
146 session->moveDragController_->isStartMove_ = true;
147 session->Session::UpdateSizeChangeReason(SizeChangeReason::MOVE);
148 session->isKeyboardPanelEnabled_ = true;
149 info.windowType_ = static_cast<uint32_t>(WindowType::ABOVE_APP_SYSTEM_WINDOW_BASE);
150 EXPECT_EQ(WSError::WS_ERROR_INVALID_SESSION, session->NotifyClientToUpdateRectTask("SceneSessionTest5", nullptr));
151 info.windowType_ = static_cast<uint32_t>(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT);
152 EXPECT_EQ(WSError::WS_ERROR_INVALID_SESSION, session->NotifyClientToUpdateRectTask("SceneSessionTest5", nullptr));
153
154 session->Session::UpdateSizeChangeReason(SizeChangeReason::UNDEFINED);
155 EXPECT_EQ(WSError::WS_ERROR_REPEAT_OPERATION, session->NotifyClientToUpdateRectTask("SceneSessionTest5", nullptr));
156
157 session->Session::UpdateSizeChangeReason(SizeChangeReason::MOVE);
158 info.windowType_ = static_cast<uint32_t>(WindowType::WINDOW_TYPE_KEYBOARD_PANEL);
159 EXPECT_EQ(WSError::WS_ERROR_INVALID_SESSION, session->NotifyClientToUpdateRectTask("SceneSessionTest5", nullptr));
160 session->Session::UpdateSizeChangeReason(SizeChangeReason::DRAG_MOVE);
161 info.windowType_ = static_cast<uint32_t>(WindowType::WINDOW_TYPE_KEYBOARD_PANEL);
162 EXPECT_EQ(WSError::WS_ERROR_INVALID_SESSION, session->NotifyClientToUpdateRectTask("SceneSessionTest5", nullptr));
163 }
164
165 /**
166 * @tc.name: GetSystemAvoidArea
167 * @tc.desc: GetSystemAvoidArea function
168 * @tc.type: FUNC
169 */
170 HWTEST_F(SceneSessionTest5, GetSystemAvoidArea, Function | SmallTest | Level2)
171 {
172 SessionInfo info;
173 info.abilityName_ = "GetSystemAvoidArea";
174 info.bundleName_ = "GetSystemAvoidArea";
175
176 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
177 EXPECT_NE(session, nullptr);
178 WSRect rect;
179 AvoidArea avoidArea;
180 session->property_->SetWindowFlags(0);
181 session->property_->SetWindowMode(WindowMode::WINDOW_MODE_UNDEFINED);
182 session->isDisplayStatusBarTemporarily_.store(true);
183 session->GetSystemAvoidArea(rect, avoidArea);
184 ASSERT_NE(session->GetSessionProperty(), nullptr);
185 EXPECT_EQ(WindowMode::WINDOW_MODE_UNDEFINED, session->GetSessionProperty()->GetWindowMode());
186
187 session->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
188 info.windowType_ = static_cast<uint32_t>(WindowType::APP_MAIN_WINDOW_END);
189 session->isDisplayStatusBarTemporarily_.store(false);
190 session->GetSystemAvoidArea(rect, avoidArea);
191
192 info.windowType_ = static_cast<uint32_t>(WindowType::APP_MAIN_WINDOW_BASE);
193 SystemSessionConfig systemConfig;
194 systemConfig.uiType_ = "PC";
195 session->SetSystemConfig(systemConfig);
196 sptr<SceneSession::SpecificSessionCallback> specificCallback =
197 sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
198 session->specificCallback_ = specificCallback;
199 session->specificCallback_->onGetSceneSessionVectorByType_ = nullptr;
200 session->GetSystemAvoidArea(rect, avoidArea);
201
202 systemConfig.uiType_ = "phone";
__anon5c05cf570202(WindowType type, uint64_t displayId) 203 GetSceneSessionVectorByTypeCallback func = [&session](WindowType type, uint64_t displayId) {
204 std::vector<sptr<SceneSession>> vSession;
205 vSession.push_back(session);
206 return vSession;
207 };
208 session->property_->SetDisplayId(2024);
209 sptr<ScreenSession> screenSession = sptr<ScreenSession>::MakeSptr();
210 ScreenSessionManagerClient::GetInstance().screenSessionMap_.clear();
211 ScreenSessionManagerClient::GetInstance().screenSessionMap_.insert(std::make_pair(2024, screenSession));
212 session->specificCallback_->onGetSceneSessionVectorByType_ = func;
213 session->GetSystemAvoidArea(rect, avoidArea);
214 ScreenSessionManagerClient::GetInstance().screenSessionMap_.clear();
215 }
216
217 /**
218 * @tc.name: GetSystemAvoidArea01
219 * @tc.desc: GetSystemAvoidArea01 function
220 * @tc.type: FUNC
221 */
222 HWTEST_F(SceneSessionTest5, GetSystemAvoidArea01, Function | SmallTest | Level2)
223 {
224 SessionInfo info;
225 info.abilityName_ = "GetSystemAvoidArea01";
226 info.bundleName_ = "GetSystemAvoidArea01";
227
228 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
229 EXPECT_NE(session, nullptr);
230 WSRect rect;
231 AvoidArea avoidArea;
232 session->property_->SetWindowFlags(0);
233
234 session->isDisplayStatusBarTemporarily_.store(false);
235
236 info.windowType_ = static_cast<uint32_t>(WindowType::APP_MAIN_WINDOW_BASE);
237 SystemSessionConfig systemConfig;
238
239 session->SetSystemConfig(systemConfig);
240 sptr<SceneSession::SpecificSessionCallback> specificCallback =
241 sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
242 session->specificCallback_ = specificCallback;
243
244 systemConfig.uiType_ = "phone";
__anon5c05cf570302(WindowType type, uint64_t displayId) 245 GetSceneSessionVectorByTypeCallback func = [&session](WindowType type, uint64_t displayId) {
246 std::vector<sptr<SceneSession>> vSession;
247 vSession.push_back(session);
248 return vSession;
249 };
250 session->property_->SetDisplayId(2024);
251 sptr<ScreenSession> screenSession = sptr<ScreenSession>::MakeSptr();
252 ScreenSessionManagerClient::GetInstance().screenSessionMap_.clear();
253 ScreenSessionManagerClient::GetInstance().screenSessionMap_.insert(std::make_pair(2024, screenSession));
254 session->specificCallback_->onGetSceneSessionVectorByType_ = func;
255 ScreenSessionManagerClient::GetInstance().screenSessionMap_.clear();
256
257 session->property_->SetDisplayId(1024);
258 session->Session::SetFloatingScale(0.0f);
259
260 session->Session::SetFloatingScale(0.5f);
261 EXPECT_EQ(0.5f, session->Session::GetFloatingScale());
262 session->property_->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_PRIMARY);
263 session->GetSystemAvoidArea(rect, avoidArea);
264 session->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
265 session->GetSystemAvoidArea(rect, avoidArea);
266 rect.height_ = 3;
267 rect.width_ =4;
268 session->GetSystemAvoidArea(rect, avoidArea);
269
270 session->isVisible_ = true;
271 session->property_->SetWindowMode(WindowMode::WINDOW_MODE_UNDEFINED);
272 session->GetSystemAvoidArea(rect, avoidArea);
273 }
274
275 /**
276 * @tc.name: NotifyOutsideDownEvent
277 * @tc.desc: NotifyOutsideDownEvent function
278 * @tc.type: FUNC
279 */
280 HWTEST_F(SceneSessionTest5, NotifyOutsideDownEvent, Function | SmallTest | Level2)
281 {
282 SessionInfo info;
283 info.abilityName_ = "NotifyOutsideDownEvent";
284 info.bundleName_ = "NotifyOutsideDownEvent";
285
286 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
287 EXPECT_NE(session, nullptr);
288 std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
289 pointerEvent->SetPointerAction(2);
290 pointerEvent->RemoveAllPointerItems();
291 session->NotifyOutsideDownEvent(pointerEvent);
292 pointerEvent->SetPointerAction(8);
293 MMI::PointerEvent::PointerItem pointerItem;
294 pointerItem.SetPointerId(2024);
295 pointerEvent->AddPointerItem(pointerItem);
296 pointerEvent->SetPointerId(2024);
297 session->NotifyOutsideDownEvent(pointerEvent);
298 sptr<SceneSession::SpecificSessionCallback> specificCallback =
299 sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
300 session->specificCallback_ = specificCallback;
301 session->specificCallback_->onOutsideDownEvent_ = nullptr;
302 session->NotifyOutsideDownEvent(pointerEvent);
__anon5c05cf570402(int32_t x, int32_t y) 303 OnOutsideDownEvent func = [](int32_t x, int32_t y) {
304 return;
305 };
306 session->specificCallback_->onOutsideDownEvent_ = func;
307 session->NotifyOutsideDownEvent(pointerEvent);
308 auto res = pointerEvent->GetPointerItem(2024, pointerItem);
309 EXPECT_EQ(true, res);
310
311 pointerEvent->SetPointerAction(5);
312 session->NotifyOutsideDownEvent(pointerEvent);
313 pointerEvent->RemoveAllPointerItems();
314 }
315
316 /**
317 * @tc.name: TransferPointerEvent
318 * @tc.desc: TransferPointerEvent function
319 * @tc.type: FUNC
320 */
321 HWTEST_F(SceneSessionTest5, TransferPointerEvent, Function | SmallTest | Level2)
322 {
323 SessionInfo info;
324 info.abilityName_ = "TransferPointerEvent";
325 info.bundleName_ = "TransferPointerEvent";
326
327 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
328 EXPECT_NE(session, nullptr);
329 std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();;
330
331 SceneSession::enterSession_ = wptr<SceneSession>(session);
332 info.isSystem_ = false;
333 session->property_ = nullptr;
334 EXPECT_EQ(WSError::WS_ERROR_INVALID_SESSION, session->TransferPointerEvent(pointerEvent, false));
335
336 info.isSystem_ = false;
337 pointerEvent->SetPointerAction(9);
338
339 sptr<SceneSession::SpecificSessionCallback> specificCallback =
340 sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
341 session->specificCallback_ = specificCallback;
342 session->specificCallback_->onSessionTouchOutside_ = nullptr;
343 EXPECT_EQ(WSError::WS_ERROR_INVALID_SESSION, session->TransferPointerEvent(pointerEvent, false));
344
__anon5c05cf570502(int32_t persistentId) 345 NotifySessionTouchOutsideCallback func = [](int32_t persistentId) {
346 return;
347 };
348 session->specificCallback_->onSessionTouchOutside_ = func;
349 EXPECT_EQ(WSError::WS_ERROR_INVALID_SESSION, session->TransferPointerEvent(pointerEvent, false));
350 pointerEvent->SetPointerAction(2);
351 EXPECT_EQ(WSError::WS_ERROR_INVALID_SESSION, session->TransferPointerEvent(pointerEvent, false));
352 }
353
354 /**
355 * @tc.name: TransferPointerEvent01
356 * @tc.desc: TransferPointerEvent01 function
357 * @tc.type: FUNC
358 */
359 HWTEST_F(SceneSessionTest5, TransferPointerEvent01, Function | SmallTest | Level2)
360 {
361 SessionInfo info;
362 info.abilityName_ = "TransferPointerEvent01";
363 info.bundleName_ = "TransferPointerEvent01";
364 info.windowType_ = static_cast<uint32_t>(WindowType::APP_MAIN_WINDOW_BASE);
365 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
366 EXPECT_NE(session, nullptr);
367 std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();;
368 session->property_->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_PRIMARY);
369 session->property_->SetMaximizeMode(MaximizeMode::MODE_RECOVER);
370 session->ClearDialogVector();
371 session->moveDragController_ = sptr<MoveDragController>::MakeSptr(2024);
372 SystemSessionConfig systemConfig;
373 systemConfig.isSystemDecorEnable_ = false;
374 systemConfig.decorWindowModeSupportType_ = 2;
375 session->SetSystemConfig(systemConfig);
376 EXPECT_EQ(WSError::WS_ERROR_INVALID_SESSION, session->TransferPointerEvent(pointerEvent, false));
377
378 session->BindDialogToParentSession(session);
379 session->SetSessionState(SessionState::STATE_ACTIVE);
380 pointerEvent->SetPointerAction(5);
381 session->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
382 session->property_->SetDragEnabled(false);
383 systemConfig.isSystemDecorEnable_ = true;
384
385 session->moveDragController_->isStartDrag_ = false;
386 EXPECT_EQ(WSError::WS_ERROR_NULLPTR, session->TransferPointerEvent(pointerEvent, false));
387
388 pointerEvent->SetPointerAction(2);
389 EXPECT_EQ(WSError::WS_OK, session->TransferPointerEvent(pointerEvent, false));
390
391 session->property_->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
392 session->property_->SetDecorEnable(false);
393 EXPECT_EQ(WSError::WS_OK, session->TransferPointerEvent(pointerEvent, false));
394
395 pointerEvent->SetPointerAction(5);
396 session->property_->SetDragEnabled(true);
397 systemConfig.uiType_ = "phone";
398 systemConfig.freeMultiWindowSupport_ = false;
399 session->moveDragController_->isStartDrag_ = true;
400 EXPECT_EQ(WSError::WS_ERROR_NULLPTR, session->TransferPointerEvent(pointerEvent, false));
401
402 systemConfig.uiType_ = "pc";
403 EXPECT_EQ(WSError::WS_ERROR_NULLPTR, session->TransferPointerEvent(pointerEvent, false));
404 session->ClearDialogVector();
405 }
406
407 /**
408 * @tc.name: SetSurfaceBounds01
409 * @tc.desc: SetSurfaceBounds function
410 * @tc.type: FUNC
411 */
412 HWTEST_F(SceneSessionTest5, SetSurfaceBounds01, Function | SmallTest | Level2)
413 {
414 SessionInfo info;
415 info.abilityName_ = "SetSurfaceBounds01";
416 info.bundleName_ = "SetSurfaceBounds01";
417 info.windowType_ = static_cast<uint32_t>(WindowType::WINDOW_TYPE_FLOAT);
418 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
419 struct RSSurfaceNodeConfig config;
420 std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Create(config);
421 session->surfaceNode_ = nullptr;
422 WSRect preRect = { 20, 20, 800, 800 };
423 WSRect rect = { 30, 30, 900, 900 };
424 session->SetSessionRect(preRect);
425 session->SetSurfaceBounds(rect);
426
427 session->surfaceNode_ = surfaceNode;
428 session->SetSurfaceBounds(rect);
429 EXPECT_EQ(preRect, session->GetSessionRect());
430 }
431
432 /**
433 * @tc.name: OnLayoutFullScreenChange
434 * @tc.desc: OnLayoutFullScreenChange function
435 * @tc.type: FUNC
436 */
437 HWTEST_F(SceneSessionTest5, OnLayoutFullScreenChange, Function | SmallTest | Level2)
438 {
439 SessionInfo info;
440 info.abilityName_ = "OnLayoutFullScreenChange";
441 info.bundleName_ = "OnLayoutFullScreenChange";
442 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
443 EXPECT_NE(session, nullptr);
444 EXPECT_EQ(WSError::WS_OK, session->OnLayoutFullScreenChange(true));
445
446 sptr<SceneSession::SessionChangeCallback> sessionChangeCallback =
447 sptr<SceneSession::SessionChangeCallback>::MakeSptr();
448 session->RegisterSessionChangeCallback(sessionChangeCallback);
449 sessionChangeCallback->onLayoutFullScreenChangeFunc_ = nullptr;
450 EXPECT_EQ(WSError::WS_OK, session->OnLayoutFullScreenChange(true));
451
__anon5c05cf570602(bool isLayoutFullScreen) 452 NotifyLayoutFullScreenChangeFunc func = [](bool isLayoutFullScreen) {
453 return;
454 };
455 sessionChangeCallback->onLayoutFullScreenChangeFunc_ = func;
456 EXPECT_EQ(WSError::WS_OK, session->OnLayoutFullScreenChange(true));
457 }
458
459 /**
460 * @tc.name: OnDefaultDensityEnabled
461 * @tc.desc: OnDefaultDensityEnabled function
462 * @tc.type: FUNC
463 */
464 HWTEST_F(SceneSessionTest5, OnDefaultDensityEnabled, Function | SmallTest | Level2)
465 {
466 SessionInfo info;
467 info.abilityName_ = "OnDefaultDensityEnabled";
468 info.bundleName_ = "OnDefaultDensityEnabled";
469 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
470 EXPECT_NE(session, nullptr);
471 EXPECT_EQ(WSError::WS_OK, session->OnDefaultDensityEnabled(true));
472
473 session->onDefaultDensityEnabledFunc_ = nullptr;
474 EXPECT_EQ(WSError::WS_OK, session->OnDefaultDensityEnabled(true));
475
__anon5c05cf570702(bool isLDefaultDensityEnabled) 476 NotifyDefaultDensityEnabledFunc func = [](bool isLDefaultDensityEnabled) {};
477 session->onDefaultDensityEnabledFunc_ = func;
478 EXPECT_EQ(WSError::WS_OK, session->OnDefaultDensityEnabled(true));
479 }
480
481 /**
482 * @tc.name: UpdateSessionPropertyByAction
483 * @tc.desc: UpdateSessionPropertyByAction function01
484 * @tc.type: FUNC
485 */
486 HWTEST_F(SceneSessionTest5, UpdateSessionPropertyByAction, Function | SmallTest | Level2)
487 {
488 SessionInfo info;
489 info.abilityName_ = "UpdateSessionPropertyByAction";
490 info.bundleName_ = "UpdateSessionPropertyByAction";
491 info.windowType_ = static_cast<uint32_t>(WindowType::APP_MAIN_WINDOW_BASE);
492 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
493 EXPECT_NE(session, nullptr);
494 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
495 EXPECT_EQ(WMError::WM_ERROR_NULLPTR, session->UpdateSessionPropertyByAction
496 (nullptr, WSPropertyChangeAction::ACTION_UPDATE_PRIVACY_MODE));
497 EXPECT_EQ(WMError::WM_ERROR_INVALID_PERMISSION, session->UpdateSessionPropertyByAction
498 (property, WSPropertyChangeAction::ACTION_UPDATE_PRIVACY_MODE));
499
500 EXPECT_EQ(WMError::WM_ERROR_INVALID_PERMISSION, session->UpdateSessionPropertyByAction
501 (property, WSPropertyChangeAction::ACTION_UPDATE_PRIVACY_MODE));
502 }
503
504 /**
505 * @tc.name: SetSessionRectChangeCallback
506 * @tc.desc: SetSessionRectChangeCallback function01
507 * @tc.type: FUNC
508 */
509 HWTEST_F(SceneSessionTest5, SetSessionRectChangeCallback, Function | SmallTest | Level2)
510 {
511 SessionInfo info;
512 info.abilityName_ = "SetSessionRectChangeCallback";
513 info.bundleName_ = "SetSessionRectChangeCallback";
514 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
515 EXPECT_NE(session, nullptr);
516 WSRect rec = { 1, 1, 1, 1 };
__anon5c05cf570802(const WSRect& rect, const SizeChangeReason& reason) 517 NotifySessionRectChangeFunc func = [](const WSRect& rect, const SizeChangeReason& reason) {
518 return;
519 };
520 session->SetSessionRectChangeCallback(nullptr);
521 info.windowType_ = static_cast<uint32_t>(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
522 session->SetSessionRectChangeCallback(func);
523 info.windowType_ = static_cast<uint32_t>(WindowType::APP_MAIN_WINDOW_BASE);
524 session->SetSessionRectChangeCallback(func);
525 rec.width_ = 0;
526 session->SetSessionRectChangeCallback(func);
527 rec.height_ = 0;
528 session->SetSessionRectChangeCallback(func);
529 EXPECT_EQ(WindowType::APP_MAIN_WINDOW_BASE, session->GetWindowType());
530 }
531
532 /**
533 * @tc.name: SetSessionRectChangeCallback02
534 * @tc.desc: SetSessionRectChangeCallback02 function01
535 * @tc.type: FUNC
536 */
537 HWTEST_F(SceneSessionTest5, SetSessionRectChangeCallback02, Function | SmallTest | Level2)
538 {
539 SessionInfo info;
540 info.abilityName_ = "SetSessionRectChangeCallback02";
541 info.bundleName_ = "SetSessionRectChangeCallback02";
542 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
543 EXPECT_NE(session, nullptr);
544 WSRect rec = { 1, 1, 1, 1 };
__anon5c05cf570902(const WSRect& rect, const SizeChangeReason& reason) 545 NotifySessionRectChangeFunc func = [](const WSRect& rect, const SizeChangeReason& reason) {
546 return;
547 };
548 session->SetSessionRectChangeCallback(nullptr);
549
550 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
551 EXPECT_NE(property, nullptr);
552 property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
553 session->SetSessionProperty(property);
554 session->SetSessionRectChangeCallback(func);
555
556 property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
557 session->SetSessionProperty(property);
558 session->SetSessionRequestRect(rec);
559 session->SetSessionRectChangeCallback(func);
560
561 rec.width_ = 0;
562 session->SetSessionRequestRect(rec);
563 session->SetSessionRectChangeCallback(func);
564
565 rec.height_ = 0;
566 session->SetSessionRequestRect(rec);
567 session->SetSessionRectChangeCallback(func);
568 EXPECT_EQ(WindowType::APP_MAIN_WINDOW_BASE, session->GetWindowType());
569 }
570
571 /**
572 * @tc.name: NotifyClientToUpdateRect
573 * @tc.desc: NotifyClientToUpdateRect function01
574 * @tc.type: FUNC
575 */
576 HWTEST_F(SceneSessionTest5, NotifyClientToUpdateRect, Function | SmallTest | Level2)
577 {
578 SessionInfo info;
579 info.abilityName_ = "NotifyClientToUpdateRect";
580 info.bundleName_ = "NotifyClientToUpdateRect";
581 info.isSystem_ = false;
582 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
583 EXPECT_NE(session, nullptr);
584 session->moveDragController_ = nullptr;
585 session->isKeyboardPanelEnabled_ = false;
586 session->reason_ = SizeChangeReason::UNDEFINED;
587 session->Session::SetSessionState(SessionState::STATE_CONNECT);
588 session->specificCallback_ = nullptr;
589 session->reason_ = SizeChangeReason::DRAG;
590 EXPECT_EQ(WSError::WS_OK, session->NotifyClientToUpdateRect("SceneSessionTest5", nullptr));
591
__anon5c05cf570a02(const int32_t& persistentId) 592 UpdateAvoidAreaCallback func = [](const int32_t& persistentId) {
593 return;
594 };
595 sptr<SceneSession::SpecificSessionCallback> specificCallback =
596 sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
597 specificCallback->onUpdateAvoidArea_ = func;
598 session->specificCallback_ = specificCallback;
599 session->reason_ = SizeChangeReason::RECOVER;
600 EXPECT_EQ(WSError::WS_OK, session->NotifyClientToUpdateRect("SceneSessionTest5", nullptr));
601 }
602
603 /**
604 * @tc.name: CheckAspectRatioValid
605 * @tc.desc: CheckAspectRatioValid function01
606 * @tc.type: FUNC
607 */
608 HWTEST_F(SceneSessionTest5, CheckAspectRatioValid, Function | SmallTest | Level2)
609 {
610 SessionInfo info;
611 info.abilityName_ = "CheckAspectRatioValid";
612 info.bundleName_ = "CheckAspectRatioValid";
613 info.isSystem_ = false;
614 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
615 EXPECT_NE(session, nullptr);
616 WindowLimits windowLimits;
617 ASSERT_NE(session->GetSessionProperty(), nullptr);
618 session->GetSessionProperty()->SetWindowLimits(windowLimits);
619
620 SystemSessionConfig systemConfig;
621 systemConfig.isSystemDecorEnable_ = false;
622 session->SetSystemConfig(systemConfig);
623 EXPECT_EQ(false, session->IsDecorEnable());
624
625 windowLimits.minWidth_ = 0;
626 windowLimits.minHeight_ = 0;
627 EXPECT_EQ(WSError::WS_OK, session->SetAspectRatio(0.0f));
628
629 windowLimits.minWidth_ = 1;
630 windowLimits.maxHeight_ = 0;
631 windowLimits.minHeight_ = 1;
632 windowLimits.maxWidth_ = 0;
633 EXPECT_EQ(WSError::WS_OK, session->SetAspectRatio(0.0f));
634
635 windowLimits.maxHeight_ = 1;
636 windowLimits.maxWidth_ = 1;
637 EXPECT_EQ(WSError::WS_OK, session->SetAspectRatio(1.0f));
638
639 windowLimits.maxHeight_ = 10000;
640 windowLimits.minHeight_ = -10000;
641 EXPECT_EQ(WSError::WS_OK, session->SetAspectRatio(0.0f));
642
643 windowLimits.maxHeight_ = 10000;
644 windowLimits.minHeight_ = -10000;
645 EXPECT_EQ(WSError::WS_OK, session->SetAspectRatio(0.0f));
646 }
647
648 /**
649 * @tc.name: GetSystemAvoidArea02
650 * @tc.desc: GetSystemAvoidArea02 function
651 * @tc.type: FUNC
652 */
653 HWTEST_F(SceneSessionTest5, GetSystemAvoidArea02, Function | SmallTest | Level2)
654 {
655 SessionInfo info;
656 info.abilityName_ = "GetSystemAvoidArea02";
657 info.bundleName_ = "GetSystemAvoidArea02";
658
659 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
660 EXPECT_NE(session, nullptr);
661 ASSERT_NE(session->GetSessionProperty(), nullptr);
662 session->GetSessionProperty()->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
663 info.windowType_ = static_cast<uint32_t>(WindowType::APP_MAIN_WINDOW_BASE);
664
665 SystemSessionConfig systemConfig;
666 systemConfig.uiType_ = "phone";
667 session->SetSystemConfig(systemConfig);
668 ScreenSessionManagerClient::GetInstance().screenSessionMap_.clear();
669 session->GetSessionProperty()->SetDisplayId(1664);
670 session->Session::SetFloatingScale(0.02f);
671 WSRect rect;
672 AvoidArea avoidArea;
673 session->GetSystemAvoidArea(rect, avoidArea);
674 EXPECT_EQ(0.02f, session->Session::GetFloatingScale());
675
676 session->Session::SetFloatingScale(0.5f);
677 session->property_->SetWindowMode(WindowMode::WINDOW_MODE_UNDEFINED);
678 session->GetSystemAvoidArea(rect, avoidArea);
679 session->GetSessionProperty()->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
680 rect.height_ = 2;
681 rect.width_ =1 ;
682 session->GetSystemAvoidArea(rect, avoidArea);
683 rect.height_ = 1;
684 session->GetSystemAvoidArea(rect, avoidArea);
685 }
686
687 /**
688 * @tc.name: FixRectByAspectRatio
689 * @tc.desc: FixRectByAspectRatio function01
690 * @tc.type: FUNC
691 */
692 HWTEST_F(SceneSessionTest5, FixRectByAspectRatio, Function | SmallTest | Level2)
693 {
694 SessionInfo info;
695 info.abilityName_ = "FixRectByAspectRatio";
696 info.bundleName_ = "FixRectByAspectRatio";
697 info.isSystem_ = false;
698 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
699 EXPECT_NE(session, nullptr);
700 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
701 session->SetSessionProperty(nullptr);
702 WSRect rect;
703 EXPECT_EQ(false, session->FixRectByAspectRatio(rect));
704 session->SetSessionProperty(property);
705 property->SetWindowMode(WindowMode::WINDOW_MODE_UNDEFINED);
706 EXPECT_EQ(false, session->FixRectByAspectRatio(rect));
707 property->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
708 property->SetWindowType(WindowType::APP_MAIN_WINDOW_END);
709 EXPECT_EQ(false, session->FixRectByAspectRatio(rect));
710 property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
711 EXPECT_EQ(false, session->FixRectByAspectRatio(rect));
712 }
713
714 /**
715 * @tc.name: FixRectByAspectRatio01
716 * @tc.desc: FixRectByAspectRatio function01
717 * @tc.type: FUNC
718 */
719 HWTEST_F(SceneSessionTest5, FixRectByAspectRatio01, Function | SmallTest | Level2)
720 {
721 SessionInfo info;
722 info.abilityName_ = "FixRectByAspectRatio01";
723 info.bundleName_ = "FixRectByAspectRatio01";
724 info.isSystem_ = false;
725 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
726 EXPECT_NE(session, nullptr);
727 WSRect rect;
728 session->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
729 info.windowType_ = static_cast<uint32_t>(WindowType::APP_MAIN_WINDOW_BASE);
730 session->aspectRatio_ = 0.5f;
731 EXPECT_NE(nullptr, DisplayManager::GetInstance().GetDefaultDisplay());
732
733 SystemSessionConfig systemConfig;
734 systemConfig.isSystemDecorEnable_ = true;
735 systemConfig.decorWindowModeSupportType_ = 2;
736 session->SetSystemConfig(systemConfig);
737 EXPECT_EQ(true, session->FixRectByAspectRatio(rect));
738
739 systemConfig.isSystemDecorEnable_ = false;
740 EXPECT_EQ(false, session->FixRectByAspectRatio(rect));
741
742 systemConfig.isSystemDecorEnable_ = true;
743 session->SetSessionProperty(nullptr);
744 EXPECT_EQ(false, session->FixRectByAspectRatio(rect));
745 }
746
747 /**
748 * @tc.name: OnMoveDragCallback
749 * @tc.desc: OnMoveDragCallback function01
750 * @tc.type: FUNC
751 */
752 HWTEST_F(SceneSessionTest5, OnMoveDragCallback, Function | SmallTest | Level2)
753 {
754 SessionInfo info;
755 info.abilityName_ = "OnMoveDragCallback";
756 info.bundleName_ = "OnMoveDragCallback";
757 info.isSystem_ = false;
758 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
759 EXPECT_NE(session, nullptr);
760 session->moveDragController_ = nullptr;
761 SizeChangeReason reason = { SizeChangeReason::DRAG };
762 session->OnMoveDragCallback(reason);
763 session->moveDragController_ = sptr<MoveDragController>::MakeSptr(2024);
764 session->OnMoveDragCallback(reason);
765
766 reason = SizeChangeReason::DRAG_END;
767 session->OnMoveDragCallback(reason);
768
769 reason = SizeChangeReason::DRAG_MOVE;
770 session->OnMoveDragCallback(reason);
771
772 reason = SizeChangeReason::DRAG_START;
773 session->OnMoveDragCallback(reason);
774 EXPECT_EQ(WSError::WS_OK, session->UpdateSizeChangeReason(reason));
775
776 session->moveDragController_ = sptr<MoveDragController>::MakeSptr(2024);
777 EXPECT_NE(session->moveDragController_, nullptr);
778 session->SetSessionProperty(nullptr);
779 session->OnMoveDragCallback(reason);
780 EXPECT_EQ(WSError::WS_OK, session->UpdateSizeChangeReason(reason));
781
782 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
783 ASSERT_NE(nullptr, property);
784 session->SetSessionProperty(property);
785 property->compatibleModeInPc_ = true;
786 session->OnMoveDragCallback(reason);
787 EXPECT_EQ(WSError::WS_OK, session->UpdateSizeChangeReason(reason));
788 }
789
790 /**
791 * @tc.name: SetWindowEnableDragBySystem
792 * @tc.desc: SetWindowEnableDragBySystem function
793 * @tc.type: FUNC
794 */
795 HWTEST_F(SceneSessionTest5, SetWindowEnableDragBySystem, Function | SmallTest | Level2)
796 {
797 SessionInfo info;
798 info.abilityName_ = "SetWindowEnableDrag";
799 info.bundleName_ = "SetWindowEnableDrag";
800 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
801 auto ret = session->SetWindowEnableDragBySystem(true);
802 EXPECT_EQ(WMError::WM_OK, ret);
803 }
804
805 /**
806 * @tc.name: UpdateWinRectForSystemBar
807 * @tc.desc: UpdateWinRectForSystemBar function01
808 * @tc.type: FUNC
809 */
810 HWTEST_F(SceneSessionTest5, UpdateWinRectForSystemBar, Function | SmallTest | Level2)
811 {
812 SessionInfo info;
813 info.abilityName_ = "UpdateWinRectForSystemBar";
814 info.bundleName_ = "UpdateWinRectForSystemBar";
815 info.isSystem_ = false;
816 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
817 EXPECT_NE(session, nullptr);
818 sptr<SceneSession::SpecificSessionCallback> specificCallback =
819 sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
820 specificCallback->onGetSceneSessionVectorByType_ = nullptr;
821 session->specificCallback_ = specificCallback;
822 WSRect rect = { 1, 10, 3, 4 };
823 session->UpdateWinRectForSystemBar(rect);
824 GetSceneSessionVectorByTypeCallback func = [session](WindowType type, uint64_t displayId)->
825 std::vector<sptr<SceneSession>>
__anon5c05cf570b02(WindowType type, uint64_t displayId)826 {
827 std::vector<sptr<SceneSession>> vSession;
828 vSession.push_back(session);
829 return vSession;
830 };
831 specificCallback->onGetSceneSessionVectorByType_ = func;
832 session->UpdateWinRectForSystemBar(rect);
833
834 session->isVisible_ = true;
835 session->winRect_ = rect;
836 session->UpdateWinRectForSystemBar(rect);
837
838 WSRect rect1 = { 1, 2, 10, 4 };
839 session->winRect_ = rect1;
840 session->UpdateWinRectForSystemBar(rect);
841 EXPECT_EQ(4, session->GetSessionRect().height_);
842
843 WSRect rect2 = { 1, 2, 10, 8 };
844 session->winRect_ = rect2;
845 session->UpdateWinRectForSystemBar(rect);
846
847 session->property_ = nullptr;
848 session->UpdateWinRectForSystemBar(rect);
849 }
850
851 /**
852 * @tc.name: UpdateNativeVisibility
853 * @tc.desc: UpdateNativeVisibility function01
854 * @tc.type: FUNC
855 */
856 HWTEST_F(SceneSessionTest5, UpdateNativeVisibility, Function | SmallTest | Level2)
857 {
858 SessionInfo info;
859 info.abilityName_ = "UpdateNativeVisibility";
860 info.bundleName_ = "UpdateNativeVisibility";
861 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
862 EXPECT_NE(session, nullptr);
863 sptr<SceneSession::SpecificSessionCallback> specificCallback =
864 sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
__anon5c05cf570c02(int32_t persistentId, WindowUpdateType type) 865 NotifyWindowInfoUpdateCallback dateFunc = [](int32_t persistentId, WindowUpdateType type) {
866 return;
867 };
__anon5c05cf570d02(const int32_t persistentId) 868 UpdateAvoidAreaCallback areaFunc = [](const int32_t persistentId) {
869 return;
870 };
871 specificCallback->onWindowInfoUpdate_ = dateFunc;
872 specificCallback->onUpdateAvoidArea_ = areaFunc;
873 session->specificCallback_ = specificCallback;
874 session->UpdateNativeVisibility(true);
875 session->SetSessionProperty(nullptr);
876 session->UpdateNativeVisibility(false);
877 EXPECT_EQ(nullptr, session->property_);
878 }
879
880 /**
881 * @tc.name: SetPrivacyMode
882 * @tc.desc: SetPrivacyMode function01
883 * @tc.type: FUNC
884 */
885 HWTEST_F(SceneSessionTest5, SetPrivacyMode, Function | SmallTest | Level2)
886 {
887 SessionInfo info;
888 info.abilityName_ = "SetPrivacyMode";
889 info.bundleName_ = "SetPrivacyMode";
890 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
891 EXPECT_NE(session, nullptr);
892 struct RSSurfaceNodeConfig config;
893 std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Create(config);
894 session->surfaceNode_ = surfaceNode;
895 ASSERT_NE(session->GetSessionProperty(), nullptr);
896 session->GetSessionProperty()->SetPrivacyMode(true);
897 EXPECT_EQ(true, session->GetSessionProperty()->GetPrivacyMode());
898 session->leashWinSurfaceNode_ = nullptr;
899 session->SetPrivacyMode(false);
900 session->leashWinSurfaceNode_ = surfaceNode;
901 session->SetPrivacyMode(true);
902 session->SetSessionProperty(nullptr);
903 session->SetPrivacyMode(true);
904
905 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
906 EXPECT_NE(property, nullptr);
907 property->SetPrivacyMode(true);
908 session->SetSessionProperty(property);
909 session->SetPrivacyMode(true);
910 }
911
912 /**
913 * @tc.name: SetSnapshotSkip
914 * @tc.desc: SetSnapshotSkip function01
915 * @tc.type: FUNC
916 */
917 HWTEST_F(SceneSessionTest5, SetSnapshotSkip, Function | SmallTest | Level2)
918 {
919 SessionInfo info;
920 info.abilityName_ = "SetSnapshotSkip";
921 info.bundleName_ = "SetSnapshotSkip";
922 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
923 EXPECT_NE(session, nullptr);
924 struct RSSurfaceNodeConfig config;
925 std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Create(config);
926 session->surfaceNode_ = surfaceNode;
927 ASSERT_NE(session->GetSessionProperty(), nullptr);
928 session->GetSessionProperty()->SetSnapshotSkip(true);
929 EXPECT_EQ(true, session->GetSessionProperty()->GetSnapshotSkip());
930 session->leashWinSurfaceNode_ = nullptr;
931 session->SetSnapshotSkip(false);
932 session->leashWinSurfaceNode_ = surfaceNode;
933 session->SetSnapshotSkip(false);
934 session->SetSnapshotSkip(true);
935 session->surfaceNode_ = nullptr;
936 EXPECT_NE(nullptr, session->GetLeashWinSurfaceNode());
937 session->SetSnapshotSkip(true);
938 session->SetSessionProperty(nullptr);
939 session->SetSnapshotSkip(true);
940 EXPECT_EQ(nullptr, session->GetSessionProperty());
941 }
942
943 /**
944 * @tc.name: UIExtSurfaceNodeIdCache
945 * @tc.desc: UIExtSurfaceNodeIdCache
946 * @tc.type: FUNC
947 */
948 HWTEST_F(SceneSessionTest5, UIExtSurfaceNodeIdCache, Function | SmallTest | Level2)
949 {
950 SessionInfo info;
951 info.abilityName_ = "UIExtSurfaceNodeIdCache";
952 info.bundleName_ = "UIExtSurfaceNodeIdCache";
953 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
954 EXPECT_NE(session, nullptr);
955
956 session->AddUIExtSurfaceNodeId(1, 2);
957 EXPECT_EQ(session->GetUIExtPersistentIdBySurfaceNodeId(1), 2);
958
959 session->RemoveUIExtSurfaceNodeId(2);
960 EXPECT_EQ(session->GetUIExtPersistentIdBySurfaceNodeId(1), 0);
961 }
962
963 /**
964 * @tc.name: SetSystemSceneOcclusionAlpha
965 * @tc.desc: SetSystemSceneOcclusionAlpha function01
966 * @tc.type: FUNC
967 */
968 HWTEST_F(SceneSessionTest5, SetSystemSceneOcclusionAlpha, Function | SmallTest | Level2)
969 {
970 SessionInfo info;
971 info.abilityName_ = "SetSystemSceneOcclusionAlpha";
972 info.bundleName_ = "SetSystemSceneOcclusionAlpha";
973 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
974 EXPECT_NE(session, nullptr);
975 session->SetSystemSceneOcclusionAlpha(-0.325);
976 session->SetSystemSceneOcclusionAlpha(3.14125);
977
978 struct RSSurfaceNodeConfig config;
979 std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Create(config);
980 session->surfaceNode_ = surfaceNode;
981 session->leashWinSurfaceNode_ = nullptr;
982 session->SetSystemSceneOcclusionAlpha(0.14125);
983 session->leashWinSurfaceNode_ = surfaceNode;
984 session->SetSystemSceneOcclusionAlpha(0.14125);
985 EXPECT_NE(nullptr, session->GetLeashWinSurfaceNode());
986 }
987
988 /**
989 * @tc.name: SetSystemSceneForceUIFirst
990 * @tc.desc: SetSystemSceneForceUIFirst function01
991 * @tc.type: FUNC
992 */
993 HWTEST_F(SceneSessionTest5, SetSystemSceneForceUIFirst, Function | SmallTest | Level2)
994 {
995 SessionInfo info;
996 info.abilityName_ = "SetSystemSceneForceUIFirst";
997 info.bundleName_ = "SetSystemSceneForceUIFirst";
998 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
999 EXPECT_NE(session, nullptr);
1000 session->SetSystemSceneForceUIFirst(true);
1001
1002 struct RSSurfaceNodeConfig config;
1003 std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Create(config);
1004 session->surfaceNode_ = surfaceNode;
1005 session->leashWinSurfaceNode_ = nullptr;
1006 session->SetSystemSceneForceUIFirst(true);
1007 session->leashWinSurfaceNode_ = surfaceNode;
1008 session->SetSystemSceneForceUIFirst(true);
1009 EXPECT_NE(nullptr, session->GetLeashWinSurfaceNode());
1010 }
1011
1012 /**
1013 * @tc.name: UpdateWindowAnimationFlag
1014 * @tc.desc: UpdateWindowAnimationFlag function01
1015 * @tc.type: FUNC
1016 */
1017 HWTEST_F(SceneSessionTest5, UpdateWindowAnimationFlag, Function | SmallTest | Level2)
1018 {
1019 SessionInfo info;
1020 info.abilityName_ = "UpdateWindowAnimationFlag";
1021 info.bundleName_ = "UpdateWindowAnimationFlag";
1022 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1023 EXPECT_NE(session, nullptr);
1024
1025 EXPECT_EQ(WSError::WS_OK, session->UpdateWindowAnimationFlag(true));
1026
1027 session->onWindowAnimationFlagChange_ = nullptr;
1028 EXPECT_EQ(WSError::WS_OK, session->UpdateWindowAnimationFlag(true));
1029
__anon5c05cf570e02(const bool flag) 1030 NotifyWindowAnimationFlagChangeFunc func = [](const bool flag) {
1031 return;
1032 };
1033 session->onWindowAnimationFlagChange_ = func;
1034 EXPECT_EQ(WSError::WS_OK, session->UpdateWindowAnimationFlag(true));
1035 }
1036
1037 /**
1038 * @tc.name: SetForegroundInteractiveStatus
1039 * @tc.desc: SetForegroundInteractiveStatus function01
1040 * @tc.type: FUNC
1041 */
1042 HWTEST_F(SceneSessionTest5, SetForegroundInteractiveStatus, Function | SmallTest | Level2)
1043 {
1044 SessionInfo info;
1045 info.abilityName_ = "SetForegroundInteractiveStatus";
1046 info.bundleName_ = "SetForegroundInteractiveStatus";
1047 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1048 session->SetSessionState(SessionState::STATE_FOREGROUND);
1049 EXPECT_NE(session, nullptr);
1050 session->toastSession_.clear();
1051 session->toastSession_.push_back(session);
1052 session->SetForegroundInteractiveStatus(false);
1053 session->toastSession_.clear();
1054 session->SetSessionState(SessionState::STATE_ACTIVE);
1055 session->toastSession_.push_back(session);
1056 session->SetForegroundInteractiveStatus(false);
1057 session->toastSession_.clear();
1058 session->SetSessionState(SessionState::STATE_CONNECT);
1059 session->toastSession_.push_back(session);
1060 session->SetForegroundInteractiveStatus(false);
1061 session->toastSession_.clear();
1062 session->SetSessionState(SessionState::STATE_ACTIVE);
1063 session->toastSession_.push_back(nullptr);
1064 session->SetForegroundInteractiveStatus(false);
1065 session->toastSession_.clear();
1066 }
1067
1068 /**
1069 * @tc.name: HandleUpdatePropertyByAction
1070 * @tc.desc: HandleUpdatePropertyByAction function01
1071 * @tc.type: FUNC
1072 */
1073 HWTEST_F(SceneSessionTest5, HandleUpdatePropertyByAction, Function | SmallTest | Level2)
1074 {
1075 SessionInfo info;
1076 info.abilityName_ = "HandleUpdatePropertyByAction";
1077 info.bundleName_ = "HandleUpdatePropertyByAction";
1078 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1079 WSPropertyChangeAction action = WSPropertyChangeAction::ACTION_UPDATE_RECT;
1080 auto res = session->HandleUpdatePropertyByAction(nullptr, nullptr, action);
1081 EXPECT_EQ(WMError::WM_ERROR_NULLPTR, res);
1082 res = session->HandleUpdatePropertyByAction(nullptr, session, action);
1083 EXPECT_EQ(WMError::WM_ERROR_NULLPTR, res);
1084 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1085 res = session->HandleUpdatePropertyByAction(property, session, action);
1086 EXPECT_EQ(WMError::WM_DO_NOTHING, res);
1087 action = WSPropertyChangeAction::ACTION_UPDATE_FLAGS;
1088 res = session->HandleUpdatePropertyByAction(property, session, action);
1089 EXPECT_EQ(WMError::WM_OK, res);
1090 }
1091
1092 /**
1093 * @tc.name: SetSystemWindowEnableDrag
1094 * @tc.desc: SetSystemWindowEnableDrag function01
1095 * @tc.type: FUNC
1096 */
1097 HWTEST_F(SceneSessionTest5, SetSystemWindowEnableDrag, Function | SmallTest | Level2)
1098 {
1099 SessionInfo info;
1100 info.abilityName_ = "SetSystemWindowEnableDrag";
1101 info.bundleName_ = "SetSystemWindowEnableDrag";
1102 info.windowType_ = static_cast<uint32_t>(WindowType::WINDOW_TYPE_DESKTOP);
1103 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1104 auto ret = session->SetSystemWindowEnableDrag(true);
1105 EXPECT_EQ(WMError::WM_OK, ret);
1106 }
1107
1108 /**
1109 * @tc.name: HandleActionUpdateSetBrightness
1110 * @tc.desc: HandleActionUpdateSetBrightness function01
1111 * @tc.type: FUNC
1112 */
1113 HWTEST_F(SceneSessionTest5, HandleActionUpdateSetBrightness, Function | SmallTest | Level2)
1114 {
1115 SessionInfo info;
1116 info.abilityName_ = "HandleActionUpdateSetBrightness";
1117 info.bundleName_ = "HandleActionUpdateSetBrightness";
1118 info.windowType_ = static_cast<uint32_t>(WindowType::ABOVE_APP_SYSTEM_WINDOW_BASE);
1119 info.isSystem_ = true;
1120 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1121 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1122 WSPropertyChangeAction action = WSPropertyChangeAction::ACTION_UPDATE_RECT;
1123 auto res = session->HandleActionUpdateSetBrightness(property, session, action);
1124 EXPECT_EQ(WMError::WM_OK, res);
1125
1126 info.windowType_ = static_cast<uint32_t>(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1127 sptr<SceneSession> session1 = sptr<SceneSession>::MakeSptr(info, nullptr);
1128 res = session1->HandleActionUpdateSetBrightness(property, session1, action);
1129 EXPECT_EQ(WMError::WM_ERROR_INVALID_SESSION, res);
1130
1131 info.isSystem_ = false;
1132 sptr<SceneSession> session2 = sptr<SceneSession>::MakeSptr(info, nullptr);
1133 session2->SetSessionState(SessionState::STATE_CONNECT);
1134 res = session2->HandleActionUpdateSetBrightness(property, session2, action);
1135 EXPECT_EQ(WMError::WM_OK, res);
1136
1137 sptr<SceneSession> session3 = sptr<SceneSession>::MakeSptr(info, nullptr);
1138 session3->SetSessionState(SessionState::STATE_CONNECT);
1139 property->SetBrightness(1.0);
1140 res = session3->HandleActionUpdateSetBrightness(property, session3, action);
1141 EXPECT_EQ(session3->GetBrightness(), 1.0);
1142 }
1143
1144 /**
1145 * @tc.name: HandleActionUpdateMaximizeState
1146 * @tc.desc: HandleActionUpdateMaximizeState function01
1147 * @tc.type: FUNC
1148 */
1149 HWTEST_F(SceneSessionTest5, HandleActionUpdateMaximizeState, Function | SmallTest | Level2)
1150 {
1151 SessionInfo info;
1152 info.abilityName_ = "HandleActionUpdateMaximizeState";
1153 info.bundleName_ = "HandleActionUpdateMaximizeState";
1154 info.windowType_ = static_cast<uint32_t>(WindowType::ABOVE_APP_SYSTEM_WINDOW_BASE);
1155 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1156 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1157 WSPropertyChangeAction action = WSPropertyChangeAction::ACTION_UPDATE_RECT;
1158
1159 auto res = session->HandleActionUpdateMaximizeState(property, session, action);
1160 EXPECT_EQ(WMError::WM_OK, res);
1161 res = session->HandleActionUpdateMode(property, session, action);
1162 EXPECT_EQ(WMError::WM_OK, res);
1163 res = session->HandleActionUpdateAnimationFlag(property, session, action);
1164 EXPECT_EQ(WMError::WM_OK, res);
1165
1166 session->SetSessionProperty(nullptr);
1167 res = session->HandleActionUpdateMaximizeState(property, session, action);
1168 EXPECT_EQ(WMError::WM_OK, res);
1169 res = session->HandleActionUpdateMode(property, session, action);
1170 EXPECT_EQ(WMError::WM_OK, res);
1171 res = session->HandleActionUpdateAnimationFlag(property, session, action);
1172 EXPECT_EQ(WMError::WM_OK, res);
1173 }
1174
1175 /**
1176 * @tc.name: SetUniqueDensityDpi
1177 * @tc.desc: SetUniqueDensityDpi function01
1178 * @tc.type: FUNC
1179 */
1180 HWTEST_F(SceneSessionTest5, SetUniqueDensityDpi, Function | SmallTest | Level2)
1181 {
1182 SessionInfo info;
1183 info.abilityName_ = "SetUniqueDensityDpi";
1184 info.bundleName_ = "SetUniqueDensityDpi";
1185 info.windowType_ = static_cast<uint32_t>(WindowType::ABOVE_APP_SYSTEM_WINDOW_BASE);
1186 info.isSystem_ = true;
1187 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1188 EXPECT_NE(session, nullptr);
1189 session->sessionStage_ = nullptr;
1190 EXPECT_EQ(WMError::WM_ERROR_INVALID_SESSION, session->SetUniqueDensityDpi(true, 520));
1191 session->sessionInfo_.isSystem_ = false;
1192 session->state_ = SessionState::STATE_DISCONNECT;
1193 EXPECT_EQ(WMError::WM_ERROR_INVALID_SESSION, session->SetUniqueDensityDpi(true, 520));
1194 session->state_ = SessionState::STATE_CONNECT;
1195 EXPECT_EQ(WMError::WM_ERROR_NULLPTR, session->SetUniqueDensityDpi(true, 520));
1196 EXPECT_EQ(WMError::WM_ERROR_INVALID_PARAM, session->SetUniqueDensityDpi(true, 79));
1197 EXPECT_EQ(WMError::WM_ERROR_NULLPTR, session->SetUniqueDensityDpi(false, 79));
1198
1199 session->sessionStage_ = new SessionStageMocker();
1200 EXPECT_NE(nullptr, session->sessionStage_);
1201 }
1202
1203 /**
1204 * @tc.name: HandleUpdatePropertyByAction02
1205 * @tc.desc: HandleUpdatePropertyByAction02 function01
1206 * @tc.type: FUNC
1207 */
1208 HWTEST_F(SceneSessionTest5, HandleUpdatePropertyByAction02, Function | SmallTest | Level2)
1209 {
1210 SessionInfo info;
1211 info.abilityName_ = "HandleUpdatePropertyByAction";
1212 info.bundleName_ = "HandleUpdatePropertyByAction";
1213 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1214 WSPropertyChangeAction action = WSPropertyChangeAction::ACTION_UPDATE_RECT;
1215 auto res = session->HandleUpdatePropertyByAction(nullptr, nullptr, action);
1216 EXPECT_EQ(WMError::WM_ERROR_NULLPTR, res);
1217 res = session->HandleUpdatePropertyByAction(nullptr, session, action);
1218 EXPECT_EQ(WMError::WM_ERROR_NULLPTR, res);
1219 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1220 res = session->HandleUpdatePropertyByAction(property, session, action);
1221 EXPECT_EQ(WMError::WM_DO_NOTHING, res);
1222 action = WSPropertyChangeAction::ACTION_UPDATE_FLAGS;
1223 res = session->HandleUpdatePropertyByAction(property, session, action);
1224 EXPECT_EQ(WMError::WM_OK, res);
1225 }
1226
1227 /**
1228 * @tc.name: HandleActionUpdateWindowModeSupportType
1229 * @tc.desc: HandleActionUpdateWindowModeSupportType function01
1230 * @tc.type: FUNC
1231 */
1232 HWTEST_F(SceneSessionTest5, HandleActionUpdateWindowModeSupportType, Function | SmallTest | Level2)
1233 {
1234 SessionInfo info;
1235 info.abilityName_ = "HandleActionUpdateWindowModeSupportType";
1236 info.bundleName_ = "HandleActionUpdateWindowModeSupportType";
1237 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1238 ASSERT_NE(session, nullptr);
1239 sptr<SceneSession> session2 = sptr<SceneSession>::MakeSptr(info, nullptr);
1240 ASSERT_NE(session2, nullptr);
1241 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1242 property->isSystemCalling_ = true;
1243 ASSERT_NE(session, nullptr);
1244 session->SetSessionProperty(nullptr);
1245 ASSERT_EQ(WMError::WM_OK, session->HandleActionUpdateWindowModeSupportType(property, session2,
1246 WSPropertyChangeAction::ACTION_UPDATE_RECT));
1247
1248 property->isSystemCalling_ = false;
1249 session->SetSessionProperty(property);
1250 ASSERT_EQ(WMError::WM_ERROR_NOT_SYSTEM_APP, session->HandleActionUpdateWindowModeSupportType(property, session2,
1251 WSPropertyChangeAction::ACTION_UPDATE_RECT));
1252 }
1253
1254 /**
1255 * @tc.name: UpdateUIParam
1256 * @tc.desc: UpdateUIParam function01
1257 * @tc.type: FUNC
1258 */
1259 HWTEST_F(SceneSessionTest5, UpdateUIParam, Function | SmallTest | Level2)
1260 {
1261 SessionInfo info;
1262 info.abilityName_ = "UpdateUIParam";
1263 info.bundleName_ = "UpdateUIParam";
1264 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1265 ASSERT_NE(session, nullptr);
1266 session->isFocused_ = true;
1267 session->isVisible_ = false;
1268 uint32_t res = session->UpdateUIParam();
1269 ASSERT_EQ(0, res);
1270 ASSERT_EQ(false, session->postProcessFocusState_.enabled_);
1271
1272 session->isFocused_ = true;
1273 session->isVisible_ = true;
1274 uint32_t res1 = session->UpdateUIParam();
1275 ASSERT_EQ(1, res1);
1276 ASSERT_EQ(true, session->postProcessFocusState_.enabled_);
1277 }
1278
1279 /**
1280 * @tc.name: UpdateVisibilityInner
1281 * @tc.desc: UpdateVisibilityInner function01
1282 * @tc.type: FUNC
1283 */
1284 HWTEST_F(SceneSessionTest5, UpdateVisibilityInner, Function | SmallTest | Level2)
1285 {
1286 SessionInfo info;
1287 info.abilityName_ = "UpdateVisibilityInner";
1288 info.bundleName_ = "UpdateVisibilityInner";
1289 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1290 ASSERT_NE(session, nullptr);
1291 session->isVisible_ = true;
1292 ASSERT_EQ(false, session->UpdateVisibilityInner(true));
1293 }
1294
1295 /**
1296 * @tc.name: UpdateInteractiveInner
1297 * @tc.desc: UpdateInteractiveInner function01
1298 * @tc.type: FUNC
1299 */
1300 HWTEST_F(SceneSessionTest5, UpdateInteractiveInner, Function | SmallTest | Level2)
1301 {
1302 SessionInfo info;
1303 info.abilityName_ = "UpdateInteractiveInner";
1304 info.bundleName_ = "UpdateInteractiveInner";
1305 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1306 ASSERT_NE(session, nullptr);
1307 session->foregroundInteractiveStatus_.store(true);
1308 ASSERT_EQ(false, session->UpdateInteractiveInner(true));
1309 ASSERT_EQ(true, session->UpdateInteractiveInner(false));
1310 }
1311
1312 /**
1313 * @tc.name: IsAnco
1314 * @tc.desc: IsAnco function01
1315 * @tc.type: FUNC
1316 */
1317 HWTEST_F(SceneSessionTest5, IsAnco, Function | SmallTest | Level2)
1318 {
1319 SessionInfo info;
1320 info.abilityName_ = "IsAnco";
1321 info.bundleName_ = "IsAnco";
1322 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1323 EXPECT_NE(session, nullptr);
1324 bool res = session->IsAnco();
1325 EXPECT_EQ(res, false);
1326
1327 session->collaboratorType_ = CollaboratorType::RESERVE_TYPE;
1328 res = session->IsAnco();
1329 EXPECT_EQ(res, true);
1330 }
1331
1332 /**
1333 * @tc.name: ProcessUpdatePropertyByAction
1334 * @tc.desc: ProcessUpdatePropertyByAction function01
1335 * @tc.type: FUNC
1336 */
1337 HWTEST_F(SceneSessionTest5, ProcessUpdatePropertyByAction, Function | SmallTest | Level2)
1338 {
1339 SessionInfo info;
1340 info.abilityName_ = "ProcessUpdatePropertyByAction";
1341 info.bundleName_ = "ProcessUpdatePropertyByAction";
1342 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1343 EXPECT_NE(session, nullptr);
1344
1345 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1346 EXPECT_NE(property, nullptr);
1347
1348 SessionInfo info_;
1349 info_.abilityName_ = "ProcessUpdatePropertyByAction_";
1350 info_.bundleName_ = "ProcessUpdatePropertyByAction_";
1351 sptr<SceneSession> session_ = sptr<SceneSession>::MakeSptr(info_, nullptr);
1352 EXPECT_NE(session_, nullptr);
1353
1354 session->ProcessUpdatePropertyByAction(property, session_, WSPropertyChangeAction::ACTION_UPDATE_TURN_SCREEN_ON);
1355 session->ProcessUpdatePropertyByAction(property, session_, WSPropertyChangeAction::ACTION_UPDATE_KEEP_SCREEN_ON);
1356 session->ProcessUpdatePropertyByAction(property, session_, WSPropertyChangeAction::ACTION_UPDATE_FOCUSABLE);
1357 session->ProcessUpdatePropertyByAction(property, session_, WSPropertyChangeAction::ACTION_UPDATE_TOUCHABLE);
1358 session->ProcessUpdatePropertyByAction(property, session_, WSPropertyChangeAction::ACTION_UPDATE_SET_BRIGHTNESS);
1359 session->ProcessUpdatePropertyByAction(property, session_, WSPropertyChangeAction::ACTION_UPDATE_ORIENTATION);
1360 session->ProcessUpdatePropertyByAction(property, session_, WSPropertyChangeAction::ACTION_UPDATE_PRIVACY_MODE);
1361 session->ProcessUpdatePropertyByAction(
1362 property, session_, WSPropertyChangeAction::ACTION_UPDATE_SYSTEM_PRIVACY_MODE);
1363 session->ProcessUpdatePropertyByAction(property, session_, WSPropertyChangeAction::ACTION_UPDATE_SNAPSHOT_SKIP);
1364 session->ProcessUpdatePropertyByAction(property, session_, WSPropertyChangeAction::ACTION_UPDATE_MAXIMIZE_STATE);
1365 session->ProcessUpdatePropertyByAction(property, session_, WSPropertyChangeAction::ACTION_UPDATE_OTHER_PROPS);
1366 session->ProcessUpdatePropertyByAction(property, session_, WSPropertyChangeAction::ACTION_UPDATE_STATUS_PROPS);
1367 session->ProcessUpdatePropertyByAction(
1368 property, session_, WSPropertyChangeAction::ACTION_UPDATE_NAVIGATION_INDICATOR_PROPS);
1369 session->ProcessUpdatePropertyByAction(property, session_, WSPropertyChangeAction::ACTION_UPDATE_FLAGS);
1370 session->ProcessUpdatePropertyByAction(property, session_, WSPropertyChangeAction::ACTION_UPDATE_MODE);
1371 session->ProcessUpdatePropertyByAction(property, session_, WSPropertyChangeAction::ACTION_UPDATE_ANIMATION_FLAG);
1372 session->ProcessUpdatePropertyByAction(property, session_, WSPropertyChangeAction::ACTION_UPDATE_TOUCH_HOT_AREA);
1373 session->ProcessUpdatePropertyByAction(property, session_, WSPropertyChangeAction::ACTION_UPDATE_DECOR_ENABLE);
1374 session->ProcessUpdatePropertyByAction(property, session_, WSPropertyChangeAction::ACTION_UPDATE_WINDOW_LIMITS);
1375 session->ProcessUpdatePropertyByAction(property, session_, WSPropertyChangeAction::ACTION_UPDATE_DRAGENABLED);
1376 session->ProcessUpdatePropertyByAction(property, session_, WSPropertyChangeAction::ACTION_UPDATE_RAISEENABLED);
1377 session->ProcessUpdatePropertyByAction(
1378 property, session_, WSPropertyChangeAction::ACTION_UPDATE_HIDE_NON_SYSTEM_FLOATING_WINDOWS);
1379 session->ProcessUpdatePropertyByAction(
1380 property, session_, WSPropertyChangeAction::ACTION_UPDATE_TEXTFIELD_AVOID_INFO);
1381 session->ProcessUpdatePropertyByAction(property, session_, WSPropertyChangeAction::ACTION_UPDATE_WINDOW_MASK);
1382 session->ProcessUpdatePropertyByAction(property, session_, WSPropertyChangeAction::ACTION_UPDATE_TOPMOST);
1383 session->ProcessUpdatePropertyByAction(property, session_, WSPropertyChangeAction::ACTION_UPDATE_MODE_SUPPORT_INFO);
1384 }
1385
1386 /**
1387 * @tc.name: HandleActionUpdateTurnScreenOn
1388 * @tc.desc: HandleActionUpdateTurnScreenOn function01
1389 * @tc.type: FUNC
1390 */
1391 HWTEST_F(SceneSessionTest5, HandleActionUpdateTurnScreenOn, Function | SmallTest | Level2)
1392 {
1393 SessionInfo info;
1394 info.abilityName_ = "HandleActionUpdateTurnScreenOn";
1395 info.bundleName_ = "HandleActionUpdateTurnScreenOn";
1396 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1397 EXPECT_NE(session, nullptr);
1398
1399 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1400 EXPECT_NE(property, nullptr);
1401
1402 SessionInfo info_;
1403 info_.abilityName_ = "ProcessUpdatePropertyByAction_";
1404 info_.bundleName_ = "ProcessUpdatePropertyByAction_";
1405 sptr<SceneSession> session_ = sptr<SceneSession>::MakeSptr(info_, nullptr);
1406 EXPECT_NE(session_, nullptr);
1407
1408 auto res = session->HandleActionUpdateTurnScreenOn(
1409 property, session_, WSPropertyChangeAction::ACTION_UPDATE_TURN_SCREEN_ON);
1410 EXPECT_EQ(res, WMError::WM_OK);
1411
1412 property->SetTurnScreenOn(true);
1413 res = session->HandleActionUpdateTurnScreenOn(
1414 property, session_, WSPropertyChangeAction::ACTION_UPDATE_TURN_SCREEN_ON);
1415 EXPECT_EQ(res, WMError::WM_OK);
1416 }
1417
1418 /**
1419 * @tc.name: SetNotifyVisibleChangeFunc
1420 * @tc.desc: SetNotifyVisibleChangeFunc Test
1421 * @tc.type: FUNC
1422 */
1423 HWTEST_F(SceneSessionTest5, SetNotifyVisibleChangeFunc, Function | SmallTest | Level2)
1424 {
1425 SessionInfo info;
1426 info.abilityName_ = "test";
1427 info.bundleName_ = "test";
1428 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1429 EXPECT_NE(session, nullptr);
1430
__anon5c05cf570f02(int32_t persistentId) 1431 session->SetNotifyVisibleChangeFunc([](int32_t persistentId) {});
1432 EXPECT_NE(session->notifyVisibleChangeFunc_, nullptr);
1433 }
1434
1435 /**
1436 * @tc.name: UpdateClientRect01
1437 * @tc.desc: UpdateClientRect
1438 * @tc.type: FUNC
1439 */
1440 HWTEST_F(SceneSessionTest5, UpdateClientRect01, Function | SmallTest | Level2)
1441 {
1442 SessionInfo info;
1443 info.abilityName_ = "UpdateClientRect01";
1444 info.bundleName_ = "UpdateClientRect01";
1445 info.windowType_ = static_cast<uint32_t>(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
1446 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1447
1448 WSRect rect = { 0, 0, 0, 0 };
1449 EXPECT_EQ(session->UpdateClientRect(rect), WSError::WS_OK);
1450
1451 session->SetClientRect(rect);
1452 rect.posX_ = 100;
1453 rect.posY_ = 100;
1454 rect.width_ = 800;
1455 rect.height_ = 800;
1456 EXPECT_EQ(session->UpdateClientRect(rect), WSError::WS_OK);
1457
1458 session->SetClientRect(rect);
1459 EXPECT_EQ(session->UpdateClientRect(rect), WSError::WS_OK);
1460 }
1461
1462 /**
1463 * @tc.name: ResetSizeChangeReasonIfDirty
1464 * @tc.desc: ResetSizeChangeReasonIfDirty
1465 * @tc.type: FUNC
1466 */
1467 HWTEST_F(SceneSessionTest5, ResetSizeChangeReasonIfDirty, Function | SmallTest | Level2)
1468 {
1469 SessionInfo info;
1470 info.abilityName_ = "ResetSizeChangeReasonIfDirty";
1471 info.bundleName_ = "ResetSizeChangeReasonIfDirty";
1472 info.windowType_ = static_cast<uint32_t>(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
1473 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1474
1475 session->UpdateSizeChangeReason(SizeChangeReason::DRAG);
1476 session->ResetDirtyFlags();
1477 session->ResetSizeChangeReasonIfDirty();
1478 EXPECT_EQ(session->GetSizeChangeReason(), SizeChangeReason::DRAG);
1479
1480 session->dirtyFlags_ |= static_cast<uint32_t>(SessionUIDirtyFlag::RECT);
1481 session->ResetSizeChangeReasonIfDirty();
1482 EXPECT_EQ(session->GetSizeChangeReason(), SizeChangeReason::DRAG);
1483
1484 session->UpdateSizeChangeReason(SizeChangeReason::MOVE);
1485 session->ResetSizeChangeReasonIfDirty();
1486 EXPECT_EQ(session->GetSizeChangeReason(), SizeChangeReason::UNDEFINED);
1487 }
1488
1489 /**
1490 * @tc.name: UpdateRect01
1491 * @tc.desc: UpdateRect
1492 * @tc.type: FUNC
1493 */
1494 HWTEST_F(SceneSessionTest5, UpdateRect01, Function | SmallTest | Level2)
1495 {
1496 SessionInfo info;
1497 info.abilityName_ = "UpdateRect01";
1498 info.bundleName_ = "UpdateRect01";
1499 info.windowType_ = static_cast<uint32_t>(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
1500 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1501 EXPECT_NE(session->property_, nullptr);
1502 SizeChangeReason reason = SizeChangeReason::UNDEFINED;
1503
1504 WSRect rect = { 200, 200, 200, 200 };
1505 session->winRect_ = rect;
1506 session->SetClientRect(rect);
1507 EXPECT_EQ(session->UpdateRect(rect, reason, "SceneSessionTest5"), WSError::WS_OK);
1508
1509 rect.posX_ = 100;
1510 rect.posY_ = 100;
1511 rect.width_ = 800;
1512 rect.height_ = 800;
1513 session->winRect_ = rect;
1514 EXPECT_EQ(session->UpdateRect(rect, reason, "SceneSessionTest5"), WSError::WS_OK);
1515 }
1516
1517 /**
1518 * @tc.name: NotifyServerToUpdateRect01
1519 * @tc.desc: NotifyServerToUpdateRect01 Test
1520 * @tc.type: FUNC
1521 */
1522 HWTEST_F(SceneSessionTest5, NotifyServerToUpdateRect01, Function | SmallTest | Level2)
1523 {
1524 SessionInfo info;
1525 info.abilityName_ = "NotifyServerToUpdateRect01";
1526 info.bundleName_ = "NotifyServerToUpdateRect01";
1527 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1528 EXPECT_NE(session, nullptr);
1529
1530 session->foregroundInteractiveStatus_.store(true);
1531 EXPECT_EQ(session->GetForegroundInteractiveStatus(), true);
1532
1533 SessionUIParam uiParam;
1534 EXPECT_EQ(session->NotifyServerToUpdateRect(uiParam, SizeChangeReason::UNDEFINED), false);
1535
1536 uiParam.rect_ = { 100, 100, 200, 200 };
1537 session->SetNeedSyncSessionRect(false);
1538 EXPECT_EQ(session->NotifyServerToUpdateRect(uiParam, SizeChangeReason::UNDEFINED), false); // not sync
1539 EXPECT_NE(session->GetSessionRect(), uiParam.rect_);
1540
1541 uiParam.needSync_ = false;
1542 EXPECT_EQ(session->NotifyServerToUpdateRect(uiParam, SizeChangeReason::UNDEFINED), false); // not sync
1543 EXPECT_NE(session->GetSessionRect(), uiParam.rect_);
1544
1545 uiParam.needSync_ = true;
1546 session->SetNeedSyncSessionRect(true); // sync first
1547 EXPECT_EQ(session->NotifyServerToUpdateRect(uiParam, SizeChangeReason::UNDEFINED), true);
1548 EXPECT_EQ(session->GetSessionRect(), uiParam.rect_);
1549
1550 EXPECT_EQ(session->NotifyServerToUpdateRect(uiParam, SizeChangeReason::UNDEFINED), false); // skip same rect
1551 }
1552
1553 /**
1554 * @tc.name: MarkSystemSceneUIFirst
1555 * @tc.desc: MarkSystemSceneUIFirst function01
1556 * @tc.type: FUNC
1557 */
1558 HWTEST_F(SceneSessionTest5, MarkSystemSceneUIFirst, Function | SmallTest | Level2)
1559 {
1560 SessionInfo info;
1561 info.abilityName_ = "MarkSystemSceneUIFirst";
1562 info.bundleName_ = "MarkSystemSceneUIFirst";
1563 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1564 EXPECT_NE(session, nullptr);
1565 session->MarkSystemSceneUIFirst(true, true);
1566
1567 struct RSSurfaceNodeConfig config;
1568 std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Create(config);
1569 session->surfaceNode_ = surfaceNode;
1570 session->leashWinSurfaceNode_ = nullptr;
1571 session->MarkSystemSceneUIFirst(true, true);
1572 session->leashWinSurfaceNode_ = surfaceNode;
1573 session->MarkSystemSceneUIFirst(true, true);
1574 EXPECT_NE(nullptr, session->GetLeashWinSurfaceNode());
1575 }
1576 }
1577 }
1578 }