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_->onGetSceneSessionVectorByTypeAndDisplayId_ = nullptr;
200 session->GetSystemAvoidArea(rect, avoidArea);
201
202 systemConfig.uiType_ = "phone";
__anon5df351210202(WindowType type, uint64_t displayId) 203 GetSceneSessionVectorByTypeAndDisplayIdCallback 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_->onGetSceneSessionVectorByTypeAndDisplayId_ = 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";
__anon5df351210302(WindowType type, uint64_t displayId) 245 GetSceneSessionVectorByTypeAndDisplayIdCallback 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_->onGetSceneSessionVectorByTypeAndDisplayId_ = 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);
__anon5df351210402(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
__anon5df351210502(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);
__anon5df351210602(bool isLayoutFullScreen) 444 NotifyLayoutFullScreenChangeFunc func = [](bool isLayoutFullScreen) {};
445 session->onLayoutFullScreenChangeFunc_ = func;
446 EXPECT_EQ(WSError::WS_OK, session->OnLayoutFullScreenChange(true));
447 }
448
449 /**
450 * @tc.name: RegisterLayoutFullScreenChangeCallback
451 * @tc.desc: test RegisterLayoutFullScreenChangeCallback
452 * @tc.type: FUNC
453 */
454 HWTEST_F(SceneSessionTest5, RegisterLayoutFullScreenChangeCallback, Function | SmallTest | Level2)
455 {
456 SessionInfo info;
457 info.abilityName_ = "RegisterLayoutFullScreenChangeCallback";
458 info.bundleName_ = "RegisterLayoutFullScreenChangeCallback";
459 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
460 sceneSession->onLayoutFullScreenChangeFunc_ = nullptr;
__anon5df351210702(bool isLayoutFullScreen) 461 NotifyLayoutFullScreenChangeFunc func = [](bool isLayoutFullScreen) {};
462
463 sceneSession->RegisterLayoutFullScreenChangeCallback(std::move(func));
464 ASSERT_NE(sceneSession->onLayoutFullScreenChangeFunc_, nullptr);
465 }
466
467 /**
468 * @tc.name: OnDefaultDensityEnabled
469 * @tc.desc: OnDefaultDensityEnabled function
470 * @tc.type: FUNC
471 */
472 HWTEST_F(SceneSessionTest5, OnDefaultDensityEnabled, Function | SmallTest | Level2)
473 {
474 SessionInfo info;
475 info.abilityName_ = "OnDefaultDensityEnabled";
476 info.bundleName_ = "OnDefaultDensityEnabled";
477 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
478 EXPECT_NE(session, nullptr);
479 EXPECT_EQ(WSError::WS_OK, session->OnDefaultDensityEnabled(true));
480
481 session->onDefaultDensityEnabledFunc_ = nullptr;
482 EXPECT_EQ(WSError::WS_OK, session->OnDefaultDensityEnabled(true));
483
__anon5df351210802(bool isLDefaultDensityEnabled) 484 NotifyDefaultDensityEnabledFunc func = [](bool isLDefaultDensityEnabled) {};
485 session->onDefaultDensityEnabledFunc_ = func;
486 EXPECT_EQ(WSError::WS_OK, session->OnDefaultDensityEnabled(true));
487 }
488
489 /**
490 * @tc.name: UpdateSessionPropertyByAction
491 * @tc.desc: UpdateSessionPropertyByAction function01
492 * @tc.type: FUNC
493 */
494 HWTEST_F(SceneSessionTest5, UpdateSessionPropertyByAction, Function | SmallTest | Level2)
495 {
496 SessionInfo info;
497 info.abilityName_ = "UpdateSessionPropertyByAction";
498 info.bundleName_ = "UpdateSessionPropertyByAction";
499 info.windowType_ = static_cast<uint32_t>(WindowType::APP_MAIN_WINDOW_BASE);
500 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
501 EXPECT_NE(session, nullptr);
502 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
503 EXPECT_EQ(WMError::WM_ERROR_NULLPTR, session->UpdateSessionPropertyByAction
504 (nullptr, WSPropertyChangeAction::ACTION_UPDATE_PRIVACY_MODE));
505 EXPECT_EQ(WMError::WM_ERROR_INVALID_PERMISSION, session->UpdateSessionPropertyByAction
506 (property, WSPropertyChangeAction::ACTION_UPDATE_PRIVACY_MODE));
507
508 EXPECT_EQ(WMError::WM_ERROR_INVALID_PERMISSION, session->UpdateSessionPropertyByAction
509 (property, WSPropertyChangeAction::ACTION_UPDATE_PRIVACY_MODE));
510 }
511
512 /**
513 * @tc.name: SetSessionRectChangeCallback
514 * @tc.desc: SetSessionRectChangeCallback function01
515 * @tc.type: FUNC
516 */
517 HWTEST_F(SceneSessionTest5, SetSessionRectChangeCallback, Function | SmallTest | Level2)
518 {
519 SessionInfo info;
520 info.abilityName_ = "SetSessionRectChangeCallback";
521 info.bundleName_ = "SetSessionRectChangeCallback";
522 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
523 EXPECT_NE(session, nullptr);
524 WSRect rec = { 1, 1, 1, 1 };
__anon5df351210902(const WSRect& rect, const SizeChangeReason& reason) 525 NotifySessionRectChangeFunc func = [](const WSRect& rect, const SizeChangeReason& reason) {
526 return;
527 };
528 session->SetSessionRectChangeCallback(nullptr);
529 info.windowType_ = static_cast<uint32_t>(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
530 session->SetSessionRectChangeCallback(func);
531 info.windowType_ = static_cast<uint32_t>(WindowType::APP_MAIN_WINDOW_BASE);
532 session->SetSessionRectChangeCallback(func);
533 rec.width_ = 0;
534 session->SetSessionRectChangeCallback(func);
535 rec.height_ = 0;
536 session->SetSessionRectChangeCallback(func);
537 EXPECT_EQ(WindowType::APP_MAIN_WINDOW_BASE, session->GetWindowType());
538 }
539
540 /**
541 * @tc.name: SetSessionRectChangeCallback02
542 * @tc.desc: SetSessionRectChangeCallback02 function01
543 * @tc.type: FUNC
544 */
545 HWTEST_F(SceneSessionTest5, SetSessionRectChangeCallback02, Function | SmallTest | Level2)
546 {
547 SessionInfo info;
548 info.abilityName_ = "SetSessionRectChangeCallback02";
549 info.bundleName_ = "SetSessionRectChangeCallback02";
550 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
551 EXPECT_NE(session, nullptr);
552 WSRect rec = { 1, 1, 1, 1 };
__anon5df351210a02(const WSRect& rect, const SizeChangeReason& reason) 553 NotifySessionRectChangeFunc func = [](const WSRect& rect, const SizeChangeReason& reason) {
554 return;
555 };
556 session->SetSessionRectChangeCallback(nullptr);
557
558 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
559 EXPECT_NE(property, nullptr);
560 property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
561 session->SetSessionProperty(property);
562 session->SetSessionRectChangeCallback(func);
563
564 property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
565 session->SetSessionProperty(property);
566 session->SetSessionRequestRect(rec);
567 session->SetSessionRectChangeCallback(func);
568
569 rec.width_ = 0;
570 session->SetSessionRequestRect(rec);
571 session->SetSessionRectChangeCallback(func);
572
573 rec.height_ = 0;
574 session->SetSessionRequestRect(rec);
575 session->SetSessionRectChangeCallback(func);
576 EXPECT_EQ(WindowType::APP_MAIN_WINDOW_BASE, session->GetWindowType());
577 }
578
579 /**
580 * @tc.name: NotifyClientToUpdateRect
581 * @tc.desc: NotifyClientToUpdateRect function01
582 * @tc.type: FUNC
583 */
584 HWTEST_F(SceneSessionTest5, NotifyClientToUpdateRect, Function | SmallTest | Level2)
585 {
586 SessionInfo info;
587 info.abilityName_ = "NotifyClientToUpdateRect";
588 info.bundleName_ = "NotifyClientToUpdateRect";
589 info.isSystem_ = false;
590 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
591 EXPECT_NE(session, nullptr);
592 session->moveDragController_ = nullptr;
593 session->isKeyboardPanelEnabled_ = false;
594 session->reason_ = SizeChangeReason::UNDEFINED;
595 session->Session::SetSessionState(SessionState::STATE_CONNECT);
596 session->specificCallback_ = nullptr;
597 session->reason_ = SizeChangeReason::DRAG;
598 EXPECT_EQ(WSError::WS_OK, session->NotifyClientToUpdateRect("SceneSessionTest5", nullptr));
599
__anon5df351210b02(const int32_t& persistentId) 600 UpdateAvoidAreaCallback func = [](const int32_t& persistentId) {
601 return;
602 };
603 sptr<SceneSession::SpecificSessionCallback> specificCallback =
604 sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
605 specificCallback->onUpdateAvoidArea_ = func;
606 session->specificCallback_ = specificCallback;
607 session->reason_ = SizeChangeReason::RECOVER;
608 EXPECT_EQ(WSError::WS_OK, session->NotifyClientToUpdateRect("SceneSessionTest5", nullptr));
609 }
610
611 /**
612 * @tc.name: CheckAspectRatioValid
613 * @tc.desc: CheckAspectRatioValid function01
614 * @tc.type: FUNC
615 */
616 HWTEST_F(SceneSessionTest5, CheckAspectRatioValid, Function | SmallTest | Level2)
617 {
618 SessionInfo info;
619 info.abilityName_ = "CheckAspectRatioValid";
620 info.bundleName_ = "CheckAspectRatioValid";
621 info.isSystem_ = false;
622 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
623 EXPECT_NE(session, nullptr);
624 WindowLimits windowLimits;
625 ASSERT_NE(session->GetSessionProperty(), nullptr);
626 session->GetSessionProperty()->SetWindowLimits(windowLimits);
627
628 SystemSessionConfig systemConfig;
629 systemConfig.isSystemDecorEnable_ = false;
630 session->SetSystemConfig(systemConfig);
631 EXPECT_EQ(false, session->IsDecorEnable());
632
633 windowLimits.minWidth_ = 0;
634 windowLimits.minHeight_ = 0;
635 EXPECT_EQ(WSError::WS_OK, session->SetAspectRatio(0.0f));
636
637 windowLimits.minWidth_ = 1;
638 windowLimits.maxHeight_ = 0;
639 windowLimits.minHeight_ = 1;
640 windowLimits.maxWidth_ = 0;
641 EXPECT_EQ(WSError::WS_OK, session->SetAspectRatio(0.0f));
642
643 windowLimits.maxHeight_ = 1;
644 windowLimits.maxWidth_ = 1;
645 EXPECT_EQ(WSError::WS_OK, session->SetAspectRatio(1.0f));
646
647 windowLimits.maxHeight_ = 10000;
648 windowLimits.minHeight_ = -10000;
649 EXPECT_EQ(WSError::WS_OK, session->SetAspectRatio(0.0f));
650
651 windowLimits.maxHeight_ = 10000;
652 windowLimits.minHeight_ = -10000;
653 EXPECT_EQ(WSError::WS_OK, session->SetAspectRatio(0.0f));
654 }
655
656 /**
657 * @tc.name: GetSystemAvoidArea02
658 * @tc.desc: GetSystemAvoidArea02 function
659 * @tc.type: FUNC
660 */
661 HWTEST_F(SceneSessionTest5, GetSystemAvoidArea02, Function | SmallTest | Level2)
662 {
663 SessionInfo info;
664 info.abilityName_ = "GetSystemAvoidArea02";
665 info.bundleName_ = "GetSystemAvoidArea02";
666
667 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
668 EXPECT_NE(session, nullptr);
669 ASSERT_NE(session->GetSessionProperty(), nullptr);
670 session->GetSessionProperty()->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
671 info.windowType_ = static_cast<uint32_t>(WindowType::APP_MAIN_WINDOW_BASE);
672
673 SystemSessionConfig systemConfig;
674 systemConfig.uiType_ = "phone";
675 session->SetSystemConfig(systemConfig);
676 ScreenSessionManagerClient::GetInstance().screenSessionMap_.clear();
677 session->GetSessionProperty()->SetDisplayId(1664);
678 session->Session::SetFloatingScale(0.02f);
679 WSRect rect;
680 AvoidArea avoidArea;
681 session->GetSystemAvoidArea(rect, avoidArea);
682 EXPECT_EQ(0.02f, session->Session::GetFloatingScale());
683
684 session->Session::SetFloatingScale(0.5f);
685 session->property_->SetWindowMode(WindowMode::WINDOW_MODE_UNDEFINED);
686 session->GetSystemAvoidArea(rect, avoidArea);
687 session->GetSessionProperty()->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
688 rect.height_ = 2;
689 rect.width_ =1 ;
690 session->GetSystemAvoidArea(rect, avoidArea);
691 rect.height_ = 1;
692 session->GetSystemAvoidArea(rect, avoidArea);
693 }
694
695 /**
696 * @tc.name: FixRectByAspectRatio
697 * @tc.desc: FixRectByAspectRatio function01
698 * @tc.type: FUNC
699 */
700 HWTEST_F(SceneSessionTest5, FixRectByAspectRatio, Function | SmallTest | Level2)
701 {
702 SessionInfo info;
703 info.abilityName_ = "FixRectByAspectRatio";
704 info.bundleName_ = "FixRectByAspectRatio";
705 info.isSystem_ = false;
706 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
707 EXPECT_NE(session, nullptr);
708 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
709 session->SetSessionProperty(nullptr);
710 WSRect rect;
711 EXPECT_EQ(false, session->FixRectByAspectRatio(rect));
712 session->SetSessionProperty(property);
713 property->SetWindowMode(WindowMode::WINDOW_MODE_UNDEFINED);
714 EXPECT_EQ(false, session->FixRectByAspectRatio(rect));
715 property->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
716 property->SetWindowType(WindowType::APP_MAIN_WINDOW_END);
717 EXPECT_EQ(false, session->FixRectByAspectRatio(rect));
718 property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
719 EXPECT_EQ(false, session->FixRectByAspectRatio(rect));
720 }
721
722 /**
723 * @tc.name: FixRectByAspectRatio01
724 * @tc.desc: FixRectByAspectRatio function01
725 * @tc.type: FUNC
726 */
727 HWTEST_F(SceneSessionTest5, FixRectByAspectRatio01, Function | SmallTest | Level2)
728 {
729 SessionInfo info;
730 info.abilityName_ = "FixRectByAspectRatio01";
731 info.bundleName_ = "FixRectByAspectRatio01";
732 info.isSystem_ = false;
733 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
734 EXPECT_NE(session, nullptr);
735 WSRect rect;
736 session->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
737 info.windowType_ = static_cast<uint32_t>(WindowType::APP_MAIN_WINDOW_BASE);
738 session->aspectRatio_ = 0.5f;
739 EXPECT_NE(nullptr, DisplayManager::GetInstance().GetDefaultDisplay());
740
741 SystemSessionConfig systemConfig;
742 systemConfig.isSystemDecorEnable_ = true;
743 systemConfig.decorWindowModeSupportType_ = 2;
744 session->SetSystemConfig(systemConfig);
745 EXPECT_EQ(true, session->FixRectByAspectRatio(rect));
746
747 systemConfig.isSystemDecorEnable_ = false;
748 EXPECT_EQ(false, session->FixRectByAspectRatio(rect));
749
750 systemConfig.isSystemDecorEnable_ = true;
751 session->SetSessionProperty(nullptr);
752 EXPECT_EQ(false, session->FixRectByAspectRatio(rect));
753 }
754
755 /**
756 * @tc.name: OnMoveDragCallback
757 * @tc.desc: OnMoveDragCallback function01
758 * @tc.type: FUNC
759 */
760 HWTEST_F(SceneSessionTest5, OnMoveDragCallback, Function | SmallTest | Level2)
761 {
762 SessionInfo info;
763 info.abilityName_ = "OnMoveDragCallback";
764 info.bundleName_ = "OnMoveDragCallback";
765 info.isSystem_ = false;
766 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
767 EXPECT_NE(session, nullptr);
768 session->moveDragController_ = nullptr;
769 SizeChangeReason reason = { SizeChangeReason::DRAG };
770 session->OnMoveDragCallback(reason);
771 session->moveDragController_ = sptr<MoveDragController>::MakeSptr(2024);
772 session->OnMoveDragCallback(reason);
773
774 reason = SizeChangeReason::DRAG_END;
775 session->OnMoveDragCallback(reason);
776
777 reason = SizeChangeReason::DRAG_MOVE;
778 session->OnMoveDragCallback(reason);
779
780 reason = SizeChangeReason::DRAG_START;
781 session->OnMoveDragCallback(reason);
782 EXPECT_EQ(WSError::WS_OK, session->UpdateSizeChangeReason(reason));
783
784 session->moveDragController_ = sptr<MoveDragController>::MakeSptr(2024);
785 EXPECT_NE(session->moveDragController_, nullptr);
786 session->SetSessionProperty(nullptr);
787 session->OnMoveDragCallback(reason);
788 EXPECT_EQ(WSError::WS_OK, session->UpdateSizeChangeReason(reason));
789
790 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
791 ASSERT_NE(nullptr, property);
792 session->SetSessionProperty(property);
793 property->compatibleModeInPc_ = true;
794 session->OnMoveDragCallback(reason);
795 EXPECT_EQ(WSError::WS_OK, session->UpdateSizeChangeReason(reason));
796 }
797
798 /**
799 * @tc.name: SetWindowEnableDragBySystem
800 * @tc.desc: SetWindowEnableDragBySystem function
801 * @tc.type: FUNC
802 */
803 HWTEST_F(SceneSessionTest5, SetWindowEnableDragBySystem, Function | SmallTest | Level2)
804 {
805 SessionInfo info;
806 info.abilityName_ = "SetWindowEnableDrag";
807 info.bundleName_ = "SetWindowEnableDrag";
808 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
809 auto ret = session->SetWindowEnableDragBySystem(true);
810 EXPECT_EQ(WMError::WM_OK, ret);
811 }
812
813 /**
814 * To test the function call
815 *
816 * @tc.name: ActivateDragBySystem
817 * @tc.desc: ActivateDragBySystem function
818 * @tc.type: FUNC
819 */
820 HWTEST_F(SceneSessionTest5, ActivateDragBySystem, Function | SmallTest | Level2)
821 {
822 SessionInfo info;
823 info.abilityName_ = "ActivateDragBySystem";
824 info.bundleName_ = "ActivateDragBySystem";
825 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
826 auto ret = sceneSession->ActivateDragBySystem(true);
827 EXPECT_EQ(WMError::WM_OK, ret);
828 }
829
830 /**
831 * To test the drag activated settings, and validate the draggable results.
832 * Expect the results:
833 * enableDrag: true, dragActivated: true => true
834 * enableDrag: false, dragActivated: true => false
835 * enableDrag: true, dragActivated: false => false
836 * enableDrag: false, dragActivated: false => false
837 *
838 * @tc.name: CheckDragActivatedSettings
839 * @tc.desc: CheckDragActivatedSettings
840 * @tc.type: FUNC
841 */
842 HWTEST_F(SceneSessionTest5, CheckDragActivatedSettings, Function | SmallTest | Level2)
843 {
844 SessionInfo info;
845 info.abilityName_ = "CheckDragActivatedSettings";
846 info.bundleName_ = "CheckDragActivatedSettings";
847 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
848
849 sceneSession->ActivateDragBySystem(true);
850 sceneSession->GetSessionProperty()->SetDragEnabled(true);
851 ASSERT_EQ(true, sceneSession->IsDragAccessible());
852
853 sceneSession->GetSessionProperty()->SetDragEnabled(false);
854 ASSERT_EQ(false, sceneSession->IsDragAccessible());
855
856 sceneSession->ActivateDragBySystem(false);
857 sceneSession->GetSessionProperty()->SetDragEnabled(true);
858 ASSERT_EQ(false, sceneSession->IsDragAccessible());
859
860 sceneSession->GetSessionProperty()->SetDragEnabled(false);
861 ASSERT_EQ(false, sceneSession->IsDragAccessible());
862 }
863
864 /**
865 * @tc.name: UpdateWinRectForSystemBar
866 * @tc.desc: UpdateWinRectForSystemBar function01
867 * @tc.type: FUNC
868 */
869 HWTEST_F(SceneSessionTest5, UpdateWinRectForSystemBar, Function | SmallTest | Level2)
870 {
871 SessionInfo info;
872 info.abilityName_ = "UpdateWinRectForSystemBar";
873 info.bundleName_ = "UpdateWinRectForSystemBar";
874 info.isSystem_ = false;
875 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
876 EXPECT_NE(session, nullptr);
877 sptr<SceneSession::SpecificSessionCallback> specificCallback =
878 sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
879 specificCallback->onGetSceneSessionVectorByTypeAndDisplayId_ = nullptr;
880 session->specificCallback_ = specificCallback;
881 WSRect rect = { 1, 10, 3, 4 };
882 session->UpdateWinRectForSystemBar(rect);
883 GetSceneSessionVectorByTypeAndDisplayIdCallback func = [session](WindowType type, uint64_t displayId)->
884 std::vector<sptr<SceneSession>>
__anon5df351210c02(WindowType type, uint64_t displayId)885 {
886 std::vector<sptr<SceneSession>> vSession;
887 vSession.push_back(session);
888 return vSession;
889 };
890 specificCallback->onGetSceneSessionVectorByTypeAndDisplayId_ = func;
891 session->UpdateWinRectForSystemBar(rect);
892
893 session->isVisible_ = true;
894 session->winRect_ = rect;
895 session->UpdateWinRectForSystemBar(rect);
896
897 WSRect rect1 = { 1, 2, 10, 4 };
898 session->winRect_ = rect1;
899 session->UpdateWinRectForSystemBar(rect);
900 EXPECT_EQ(4, session->GetSessionRect().height_);
901
902 WSRect rect2 = { 1, 2, 10, 8 };
903 session->winRect_ = rect2;
904 session->UpdateWinRectForSystemBar(rect);
905
906 session->property_ = nullptr;
907 session->UpdateWinRectForSystemBar(rect);
908 }
909
910 /**
911 * @tc.name: UpdateNativeVisibility
912 * @tc.desc: UpdateNativeVisibility function01
913 * @tc.type: FUNC
914 */
915 HWTEST_F(SceneSessionTest5, UpdateNativeVisibility, Function | SmallTest | Level2)
916 {
917 SessionInfo info;
918 info.abilityName_ = "UpdateNativeVisibility";
919 info.bundleName_ = "UpdateNativeVisibility";
920 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
921 EXPECT_NE(session, nullptr);
922 sptr<SceneSession::SpecificSessionCallback> specificCallback =
923 sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
__anon5df351210d02(int32_t persistentId, WindowUpdateType type) 924 NotifyWindowInfoUpdateCallback dateFunc = [](int32_t persistentId, WindowUpdateType type) {
925 return;
926 };
__anon5df351210e02(const int32_t persistentId) 927 UpdateAvoidAreaCallback areaFunc = [](const int32_t persistentId) {
928 return;
929 };
930 specificCallback->onWindowInfoUpdate_ = dateFunc;
931 specificCallback->onUpdateAvoidArea_ = areaFunc;
932 session->specificCallback_ = specificCallback;
933 session->UpdateNativeVisibility(true);
934 session->SetSessionProperty(nullptr);
935 session->UpdateNativeVisibility(false);
936 EXPECT_EQ(nullptr, session->property_);
937 }
938
939 /**
940 * @tc.name: SetPrivacyMode
941 * @tc.desc: SetPrivacyMode function01
942 * @tc.type: FUNC
943 */
944 HWTEST_F(SceneSessionTest5, SetPrivacyMode, Function | SmallTest | Level2)
945 {
946 SessionInfo info;
947 info.abilityName_ = "SetPrivacyMode";
948 info.bundleName_ = "SetPrivacyMode";
949 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
950 EXPECT_NE(session, nullptr);
951 struct RSSurfaceNodeConfig config;
952 std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Create(config);
953 session->surfaceNode_ = surfaceNode;
954 ASSERT_NE(session->GetSessionProperty(), nullptr);
955 session->GetSessionProperty()->SetPrivacyMode(true);
956 EXPECT_EQ(true, session->GetSessionProperty()->GetPrivacyMode());
957 session->leashWinSurfaceNode_ = nullptr;
958 session->SetPrivacyMode(false);
959 session->leashWinSurfaceNode_ = surfaceNode;
960 session->SetPrivacyMode(true);
961 session->SetSessionProperty(nullptr);
962 session->SetPrivacyMode(true);
963
964 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
965 EXPECT_NE(property, nullptr);
966 property->SetPrivacyMode(true);
967 session->SetSessionProperty(property);
968 session->SetPrivacyMode(true);
969 }
970
971 /**
972 * @tc.name: SetSnapshotSkip
973 * @tc.desc: SetSnapshotSkip function01
974 * @tc.type: FUNC
975 */
976 HWTEST_F(SceneSessionTest5, SetSnapshotSkip, Function | SmallTest | Level2)
977 {
978 SessionInfo info;
979 info.abilityName_ = "SetSnapshotSkip";
980 info.bundleName_ = "SetSnapshotSkip";
981 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
982 EXPECT_NE(session, nullptr);
983 struct RSSurfaceNodeConfig config;
984 std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Create(config);
985 session->surfaceNode_ = surfaceNode;
986 ASSERT_NE(session->GetSessionProperty(), nullptr);
987 session->GetSessionProperty()->SetSnapshotSkip(true);
988 EXPECT_EQ(true, session->GetSessionProperty()->GetSnapshotSkip());
989 session->leashWinSurfaceNode_ = nullptr;
990 session->SetSnapshotSkip(false);
991 session->leashWinSurfaceNode_ = surfaceNode;
992 session->SetSnapshotSkip(false);
993 session->SetSnapshotSkip(true);
994 session->surfaceNode_ = nullptr;
995 EXPECT_NE(nullptr, session->GetLeashWinSurfaceNode());
996 session->SetSnapshotSkip(true);
997 session->SetSessionProperty(nullptr);
998 session->SetSnapshotSkip(true);
999 EXPECT_EQ(nullptr, session->GetSessionProperty());
1000 }
1001
1002 /**
1003 * @tc.name: UIExtSurfaceNodeIdCache
1004 * @tc.desc: UIExtSurfaceNodeIdCache
1005 * @tc.type: FUNC
1006 */
1007 HWTEST_F(SceneSessionTest5, UIExtSurfaceNodeIdCache, Function | SmallTest | Level2)
1008 {
1009 SessionInfo info;
1010 info.abilityName_ = "UIExtSurfaceNodeIdCache";
1011 info.bundleName_ = "UIExtSurfaceNodeIdCache";
1012 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1013 EXPECT_NE(session, nullptr);
1014
1015 session->AddUIExtSurfaceNodeId(1, 2);
1016 EXPECT_EQ(session->GetUIExtPersistentIdBySurfaceNodeId(1), 2);
1017
1018 session->RemoveUIExtSurfaceNodeId(2);
1019 EXPECT_EQ(session->GetUIExtPersistentIdBySurfaceNodeId(1), 0);
1020 }
1021
1022 /**
1023 * @tc.name: SetSystemSceneOcclusionAlpha
1024 * @tc.desc: SetSystemSceneOcclusionAlpha function01
1025 * @tc.type: FUNC
1026 */
1027 HWTEST_F(SceneSessionTest5, SetSystemSceneOcclusionAlpha, Function | SmallTest | Level2)
1028 {
1029 SessionInfo info;
1030 info.abilityName_ = "SetSystemSceneOcclusionAlpha";
1031 info.bundleName_ = "SetSystemSceneOcclusionAlpha";
1032 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1033 EXPECT_NE(session, nullptr);
1034 session->SetSystemSceneOcclusionAlpha(-0.325);
1035 session->SetSystemSceneOcclusionAlpha(3.14125);
1036
1037 struct RSSurfaceNodeConfig config;
1038 std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Create(config);
1039 session->surfaceNode_ = surfaceNode;
1040 session->leashWinSurfaceNode_ = nullptr;
1041 session->SetSystemSceneOcclusionAlpha(0.14125);
1042 session->leashWinSurfaceNode_ = surfaceNode;
1043 session->SetSystemSceneOcclusionAlpha(0.14125);
1044 EXPECT_NE(nullptr, session->GetLeashWinSurfaceNode());
1045 }
1046
1047 /**
1048 * @tc.name: SetSystemSceneForceUIFirst
1049 * @tc.desc: SetSystemSceneForceUIFirst function01
1050 * @tc.type: FUNC
1051 */
1052 HWTEST_F(SceneSessionTest5, SetSystemSceneForceUIFirst, Function | SmallTest | Level2)
1053 {
1054 SessionInfo info;
1055 info.abilityName_ = "SetSystemSceneForceUIFirst";
1056 info.bundleName_ = "SetSystemSceneForceUIFirst";
1057 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1058 EXPECT_NE(session, nullptr);
1059 session->SetSystemSceneForceUIFirst(true);
1060
1061 struct RSSurfaceNodeConfig config;
1062 std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Create(config);
1063 session->surfaceNode_ = surfaceNode;
1064 session->leashWinSurfaceNode_ = nullptr;
1065 session->SetSystemSceneForceUIFirst(true);
1066 session->leashWinSurfaceNode_ = surfaceNode;
1067 session->SetSystemSceneForceUIFirst(true);
1068 EXPECT_NE(nullptr, session->GetLeashWinSurfaceNode());
1069 }
1070
1071 /**
1072 * @tc.name: UpdateWindowAnimationFlag
1073 * @tc.desc: UpdateWindowAnimationFlag function01
1074 * @tc.type: FUNC
1075 */
1076 HWTEST_F(SceneSessionTest5, UpdateWindowAnimationFlag, Function | SmallTest | Level2)
1077 {
1078 SessionInfo info;
1079 info.abilityName_ = "UpdateWindowAnimationFlag";
1080 info.bundleName_ = "UpdateWindowAnimationFlag";
1081 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1082 EXPECT_NE(session, nullptr);
1083
1084 EXPECT_EQ(WSError::WS_OK, session->UpdateWindowAnimationFlag(true));
1085
1086 session->onWindowAnimationFlagChange_ = nullptr;
1087 EXPECT_EQ(WSError::WS_OK, session->UpdateWindowAnimationFlag(true));
1088
__anon5df351210f02(const bool flag) 1089 NotifyWindowAnimationFlagChangeFunc func = [](const bool flag) {
1090 return;
1091 };
1092 session->onWindowAnimationFlagChange_ = func;
1093 EXPECT_EQ(WSError::WS_OK, session->UpdateWindowAnimationFlag(true));
1094 }
1095
1096 /**
1097 * @tc.name: SetForegroundInteractiveStatus
1098 * @tc.desc: SetForegroundInteractiveStatus function01
1099 * @tc.type: FUNC
1100 */
1101 HWTEST_F(SceneSessionTest5, SetForegroundInteractiveStatus, Function | SmallTest | Level2)
1102 {
1103 SessionInfo info;
1104 info.abilityName_ = "SetForegroundInteractiveStatus";
1105 info.bundleName_ = "SetForegroundInteractiveStatus";
1106 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1107 session->SetSessionState(SessionState::STATE_FOREGROUND);
1108 EXPECT_NE(session, nullptr);
1109 session->toastSession_.clear();
1110 session->toastSession_.push_back(session);
1111 session->SetForegroundInteractiveStatus(false);
1112 session->toastSession_.clear();
1113 session->SetSessionState(SessionState::STATE_ACTIVE);
1114 session->toastSession_.push_back(session);
1115 session->SetForegroundInteractiveStatus(false);
1116 session->toastSession_.clear();
1117 session->SetSessionState(SessionState::STATE_CONNECT);
1118 session->toastSession_.push_back(session);
1119 session->SetForegroundInteractiveStatus(false);
1120 session->toastSession_.clear();
1121 session->SetSessionState(SessionState::STATE_ACTIVE);
1122 session->toastSession_.push_back(nullptr);
1123 session->SetForegroundInteractiveStatus(false);
1124 session->toastSession_.clear();
1125 }
1126
1127 /**
1128 * @tc.name: HandleUpdatePropertyByAction
1129 * @tc.desc: HandleUpdatePropertyByAction function01
1130 * @tc.type: FUNC
1131 */
1132 HWTEST_F(SceneSessionTest5, HandleUpdatePropertyByAction, Function | SmallTest | Level2)
1133 {
1134 SessionInfo info;
1135 info.abilityName_ = "HandleUpdatePropertyByAction";
1136 info.bundleName_ = "HandleUpdatePropertyByAction";
1137 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1138 WSPropertyChangeAction action = WSPropertyChangeAction::ACTION_UPDATE_RECT;
1139 auto res = session->HandleUpdatePropertyByAction(nullptr, nullptr, action);
1140 EXPECT_EQ(WMError::WM_ERROR_NULLPTR, res);
1141 res = session->HandleUpdatePropertyByAction(nullptr, session, action);
1142 EXPECT_EQ(WMError::WM_ERROR_NULLPTR, res);
1143 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1144 res = session->HandleUpdatePropertyByAction(property, session, action);
1145 EXPECT_EQ(WMError::WM_DO_NOTHING, res);
1146 action = WSPropertyChangeAction::ACTION_UPDATE_FLAGS;
1147 res = session->HandleUpdatePropertyByAction(property, session, action);
1148 EXPECT_EQ(WMError::WM_OK, res);
1149 }
1150
1151 /**
1152 * @tc.name: SetSystemWindowEnableDrag
1153 * @tc.desc: SetSystemWindowEnableDrag function01
1154 * @tc.type: FUNC
1155 */
1156 HWTEST_F(SceneSessionTest5, SetSystemWindowEnableDrag, Function | SmallTest | Level2)
1157 {
1158 SessionInfo info;
1159 info.abilityName_ = "SetSystemWindowEnableDrag";
1160 info.bundleName_ = "SetSystemWindowEnableDrag";
1161 info.windowType_ = static_cast<uint32_t>(WindowType::WINDOW_TYPE_DESKTOP);
1162 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1163 auto ret = session->SetSystemWindowEnableDrag(true);
1164 EXPECT_EQ(WMError::WM_OK, ret);
1165 }
1166
1167 /**
1168 * @tc.name: HandleActionUpdateSetBrightness
1169 * @tc.desc: HandleActionUpdateSetBrightness function01
1170 * @tc.type: FUNC
1171 */
1172 HWTEST_F(SceneSessionTest5, HandleActionUpdateSetBrightness, Function | SmallTest | Level2)
1173 {
1174 SessionInfo info;
1175 info.abilityName_ = "HandleActionUpdateSetBrightness";
1176 info.bundleName_ = "HandleActionUpdateSetBrightness";
1177 info.windowType_ = static_cast<uint32_t>(WindowType::ABOVE_APP_SYSTEM_WINDOW_BASE);
1178 info.isSystem_ = true;
1179 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1180 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1181 WSPropertyChangeAction action = WSPropertyChangeAction::ACTION_UPDATE_RECT;
1182 auto res = session->HandleActionUpdateSetBrightness(property, session, action);
1183 EXPECT_EQ(WMError::WM_OK, res);
1184
1185 info.windowType_ = static_cast<uint32_t>(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1186 sptr<SceneSession> session1 = sptr<SceneSession>::MakeSptr(info, nullptr);
1187 res = session1->HandleActionUpdateSetBrightness(property, session1, action);
1188 EXPECT_EQ(WMError::WM_ERROR_INVALID_SESSION, res);
1189
1190 info.isSystem_ = false;
1191 sptr<SceneSession> session2 = sptr<SceneSession>::MakeSptr(info, nullptr);
1192 session2->SetSessionState(SessionState::STATE_CONNECT);
1193 res = session2->HandleActionUpdateSetBrightness(property, session2, action);
1194 EXPECT_EQ(WMError::WM_OK, res);
1195
1196 sptr<SceneSession> session3 = sptr<SceneSession>::MakeSptr(info, nullptr);
1197 session3->SetSessionState(SessionState::STATE_CONNECT);
1198 property->SetBrightness(1.0);
1199 res = session3->HandleActionUpdateSetBrightness(property, session3, action);
1200 EXPECT_EQ(session3->GetBrightness(), 1.0);
1201 }
1202
1203 /**
1204 * @tc.name: HandleActionUpdateMaximizeState
1205 * @tc.desc: HandleActionUpdateMaximizeState function01
1206 * @tc.type: FUNC
1207 */
1208 HWTEST_F(SceneSessionTest5, HandleActionUpdateMaximizeState, Function | SmallTest | Level2)
1209 {
1210 SessionInfo info;
1211 info.abilityName_ = "HandleActionUpdateMaximizeState";
1212 info.bundleName_ = "HandleActionUpdateMaximizeState";
1213 info.windowType_ = static_cast<uint32_t>(WindowType::ABOVE_APP_SYSTEM_WINDOW_BASE);
1214 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1215 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1216 WSPropertyChangeAction action = WSPropertyChangeAction::ACTION_UPDATE_RECT;
1217
1218 auto res = session->HandleActionUpdateMaximizeState(property, session, action);
1219 EXPECT_EQ(WMError::WM_OK, res);
1220 res = session->HandleActionUpdateMode(property, session, action);
1221 EXPECT_EQ(WMError::WM_OK, res);
1222 res = session->HandleActionUpdateAnimationFlag(property, session, action);
1223 EXPECT_EQ(WMError::WM_OK, res);
1224
1225 session->SetSessionProperty(nullptr);
1226 res = session->HandleActionUpdateMaximizeState(property, session, action);
1227 EXPECT_EQ(WMError::WM_OK, res);
1228 res = session->HandleActionUpdateMode(property, session, action);
1229 EXPECT_EQ(WMError::WM_OK, res);
1230 res = session->HandleActionUpdateAnimationFlag(property, session, action);
1231 EXPECT_EQ(WMError::WM_OK, res);
1232 }
1233
1234 /**
1235 * @tc.name: SetUniqueDensityDpi
1236 * @tc.desc: SetUniqueDensityDpi function01
1237 * @tc.type: FUNC
1238 */
1239 HWTEST_F(SceneSessionTest5, SetUniqueDensityDpi, Function | SmallTest | Level2)
1240 {
1241 SessionInfo info;
1242 info.abilityName_ = "SetUniqueDensityDpi";
1243 info.bundleName_ = "SetUniqueDensityDpi";
1244 info.windowType_ = static_cast<uint32_t>(WindowType::ABOVE_APP_SYSTEM_WINDOW_BASE);
1245 info.isSystem_ = true;
1246 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1247 EXPECT_NE(session, nullptr);
1248 session->sessionStage_ = nullptr;
1249 EXPECT_EQ(WMError::WM_ERROR_INVALID_SESSION, session->SetUniqueDensityDpi(true, 520));
1250 session->sessionInfo_.isSystem_ = false;
1251 session->state_ = SessionState::STATE_DISCONNECT;
1252 EXPECT_EQ(WMError::WM_ERROR_INVALID_SESSION, session->SetUniqueDensityDpi(true, 520));
1253 session->state_ = SessionState::STATE_CONNECT;
1254 EXPECT_EQ(WMError::WM_ERROR_NULLPTR, session->SetUniqueDensityDpi(true, 520));
1255 EXPECT_EQ(WMError::WM_ERROR_INVALID_PARAM, session->SetUniqueDensityDpi(true, 79));
1256 EXPECT_EQ(WMError::WM_ERROR_NULLPTR, session->SetUniqueDensityDpi(false, 79));
1257
1258 session->sessionStage_ = new SessionStageMocker();
1259 EXPECT_NE(nullptr, session->sessionStage_);
1260 }
1261
1262 /**
1263 * @tc.name: HandleUpdatePropertyByAction02
1264 * @tc.desc: HandleUpdatePropertyByAction02 function01
1265 * @tc.type: FUNC
1266 */
1267 HWTEST_F(SceneSessionTest5, HandleUpdatePropertyByAction02, Function | SmallTest | Level2)
1268 {
1269 SessionInfo info;
1270 info.abilityName_ = "HandleUpdatePropertyByAction";
1271 info.bundleName_ = "HandleUpdatePropertyByAction";
1272 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1273 WSPropertyChangeAction action = WSPropertyChangeAction::ACTION_UPDATE_RECT;
1274 auto res = session->HandleUpdatePropertyByAction(nullptr, nullptr, action);
1275 EXPECT_EQ(WMError::WM_ERROR_NULLPTR, res);
1276 res = session->HandleUpdatePropertyByAction(nullptr, session, action);
1277 EXPECT_EQ(WMError::WM_ERROR_NULLPTR, res);
1278 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1279 res = session->HandleUpdatePropertyByAction(property, session, action);
1280 EXPECT_EQ(WMError::WM_DO_NOTHING, res);
1281 action = WSPropertyChangeAction::ACTION_UPDATE_FLAGS;
1282 res = session->HandleUpdatePropertyByAction(property, session, action);
1283 EXPECT_EQ(WMError::WM_OK, res);
1284 }
1285
1286 /**
1287 * @tc.name: HandleActionUpdateWindowModeSupportType
1288 * @tc.desc: HandleActionUpdateWindowModeSupportType function01
1289 * @tc.type: FUNC
1290 */
1291 HWTEST_F(SceneSessionTest5, HandleActionUpdateWindowModeSupportType, Function | SmallTest | Level2)
1292 {
1293 SessionInfo info;
1294 info.abilityName_ = "HandleActionUpdateWindowModeSupportType";
1295 info.bundleName_ = "HandleActionUpdateWindowModeSupportType";
1296 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1297 ASSERT_NE(session, nullptr);
1298 sptr<SceneSession> session2 = sptr<SceneSession>::MakeSptr(info, nullptr);
1299 ASSERT_NE(session2, nullptr);
1300 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1301 property->isSystemCalling_ = true;
1302 ASSERT_NE(session, nullptr);
1303 session->SetSessionProperty(nullptr);
1304 ASSERT_EQ(WMError::WM_OK, session->HandleActionUpdateWindowModeSupportType(property, session2,
1305 WSPropertyChangeAction::ACTION_UPDATE_RECT));
1306
1307 property->isSystemCalling_ = false;
1308 session->SetSessionProperty(property);
1309 ASSERT_EQ(WMError::WM_ERROR_NOT_SYSTEM_APP, session->HandleActionUpdateWindowModeSupportType(property, session2,
1310 WSPropertyChangeAction::ACTION_UPDATE_RECT));
1311 }
1312
1313 /**
1314 * @tc.name: UpdateUIParam
1315 * @tc.desc: UpdateUIParam function01
1316 * @tc.type: FUNC
1317 */
1318 HWTEST_F(SceneSessionTest5, UpdateUIParam, Function | SmallTest | Level2)
1319 {
1320 SessionInfo info;
1321 info.abilityName_ = "UpdateUIParam";
1322 info.bundleName_ = "UpdateUIParam";
1323 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1324 ASSERT_NE(session, nullptr);
1325 session->isFocused_ = true;
1326 session->isVisible_ = false;
1327 uint32_t res = session->UpdateUIParam();
1328 ASSERT_EQ(0, res);
1329 ASSERT_EQ(false, session->postProcessFocusState_.enabled_);
1330
1331 session->isFocused_ = true;
1332 session->isVisible_ = true;
1333 uint32_t res1 = session->UpdateUIParam();
1334 ASSERT_EQ(1, res1);
1335 ASSERT_EQ(true, session->postProcessFocusState_.enabled_);
1336 }
1337
1338 /**
1339 * @tc.name: UpdateVisibilityInner
1340 * @tc.desc: UpdateVisibilityInner function01
1341 * @tc.type: FUNC
1342 */
1343 HWTEST_F(SceneSessionTest5, UpdateVisibilityInner, Function | SmallTest | Level2)
1344 {
1345 SessionInfo info;
1346 info.abilityName_ = "UpdateVisibilityInner";
1347 info.bundleName_ = "UpdateVisibilityInner";
1348 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1349 ASSERT_NE(session, nullptr);
1350 session->isVisible_ = true;
1351 ASSERT_EQ(false, session->UpdateVisibilityInner(true));
1352 }
1353
1354 /**
1355 * @tc.name: UpdateInteractiveInner
1356 * @tc.desc: UpdateInteractiveInner function01
1357 * @tc.type: FUNC
1358 */
1359 HWTEST_F(SceneSessionTest5, UpdateInteractiveInner, Function | SmallTest | Level2)
1360 {
1361 SessionInfo info;
1362 info.abilityName_ = "UpdateInteractiveInner";
1363 info.bundleName_ = "UpdateInteractiveInner";
1364 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1365 ASSERT_NE(session, nullptr);
1366 session->foregroundInteractiveStatus_.store(true);
1367 ASSERT_EQ(false, session->UpdateInteractiveInner(true));
1368 ASSERT_EQ(true, session->UpdateInteractiveInner(false));
1369 }
1370
1371 /**
1372 * @tc.name: IsAnco
1373 * @tc.desc: IsAnco function01
1374 * @tc.type: FUNC
1375 */
1376 HWTEST_F(SceneSessionTest5, IsAnco, Function | SmallTest | Level2)
1377 {
1378 SessionInfo info;
1379 info.abilityName_ = "IsAnco";
1380 info.bundleName_ = "IsAnco";
1381 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1382 EXPECT_NE(session, nullptr);
1383 bool res = session->IsAnco();
1384 EXPECT_EQ(res, false);
1385
1386 session->collaboratorType_ = CollaboratorType::RESERVE_TYPE;
1387 res = session->IsAnco();
1388 EXPECT_EQ(res, true);
1389 }
1390
1391 /**
1392 * @tc.name: ProcessUpdatePropertyByAction
1393 * @tc.desc: ProcessUpdatePropertyByAction function01
1394 * @tc.type: FUNC
1395 */
1396 HWTEST_F(SceneSessionTest5, ProcessUpdatePropertyByAction, Function | SmallTest | Level2)
1397 {
1398 SessionInfo info;
1399 info.abilityName_ = "ProcessUpdatePropertyByAction";
1400 info.bundleName_ = "ProcessUpdatePropertyByAction";
1401 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1402 EXPECT_NE(session, nullptr);
1403
1404 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1405 EXPECT_NE(property, nullptr);
1406
1407 SessionInfo info_;
1408 info_.abilityName_ = "ProcessUpdatePropertyByAction_";
1409 info_.bundleName_ = "ProcessUpdatePropertyByAction_";
1410 sptr<SceneSession> session_ = sptr<SceneSession>::MakeSptr(info_, nullptr);
1411 EXPECT_NE(session_, nullptr);
1412
1413 session->ProcessUpdatePropertyByAction(property, session_, WSPropertyChangeAction::ACTION_UPDATE_TURN_SCREEN_ON);
1414 session->ProcessUpdatePropertyByAction(property, session_, WSPropertyChangeAction::ACTION_UPDATE_KEEP_SCREEN_ON);
1415 session->ProcessUpdatePropertyByAction(property, session_, WSPropertyChangeAction::ACTION_UPDATE_FOCUSABLE);
1416 session->ProcessUpdatePropertyByAction(property, session_, WSPropertyChangeAction::ACTION_UPDATE_TOUCHABLE);
1417 session->ProcessUpdatePropertyByAction(property, session_, WSPropertyChangeAction::ACTION_UPDATE_SET_BRIGHTNESS);
1418 session->ProcessUpdatePropertyByAction(property, session_, WSPropertyChangeAction::ACTION_UPDATE_ORIENTATION);
1419 session->ProcessUpdatePropertyByAction(property, session_, WSPropertyChangeAction::ACTION_UPDATE_PRIVACY_MODE);
1420 session->ProcessUpdatePropertyByAction(
1421 property, session_, WSPropertyChangeAction::ACTION_UPDATE_SYSTEM_PRIVACY_MODE);
1422 session->ProcessUpdatePropertyByAction(property, session_, WSPropertyChangeAction::ACTION_UPDATE_SNAPSHOT_SKIP);
1423 session->ProcessUpdatePropertyByAction(property, session_, WSPropertyChangeAction::ACTION_UPDATE_MAXIMIZE_STATE);
1424 session->ProcessUpdatePropertyByAction(property, session_, WSPropertyChangeAction::ACTION_UPDATE_OTHER_PROPS);
1425 session->ProcessUpdatePropertyByAction(property, session_, WSPropertyChangeAction::ACTION_UPDATE_STATUS_PROPS);
1426 session->ProcessUpdatePropertyByAction(
1427 property, session_, WSPropertyChangeAction::ACTION_UPDATE_NAVIGATION_INDICATOR_PROPS);
1428 session->ProcessUpdatePropertyByAction(property, session_, WSPropertyChangeAction::ACTION_UPDATE_FLAGS);
1429 session->ProcessUpdatePropertyByAction(property, session_, WSPropertyChangeAction::ACTION_UPDATE_MODE);
1430 session->ProcessUpdatePropertyByAction(property, session_, WSPropertyChangeAction::ACTION_UPDATE_ANIMATION_FLAG);
1431 session->ProcessUpdatePropertyByAction(property, session_, WSPropertyChangeAction::ACTION_UPDATE_TOUCH_HOT_AREA);
1432 session->ProcessUpdatePropertyByAction(property, session_, WSPropertyChangeAction::ACTION_UPDATE_DECOR_ENABLE);
1433 session->ProcessUpdatePropertyByAction(property, session_, WSPropertyChangeAction::ACTION_UPDATE_WINDOW_LIMITS);
1434 session->ProcessUpdatePropertyByAction(property, session_, WSPropertyChangeAction::ACTION_UPDATE_DRAGENABLED);
1435 session->ProcessUpdatePropertyByAction(property, session_, WSPropertyChangeAction::ACTION_UPDATE_RAISEENABLED);
1436 session->ProcessUpdatePropertyByAction(
1437 property, session_, WSPropertyChangeAction::ACTION_UPDATE_HIDE_NON_SYSTEM_FLOATING_WINDOWS);
1438 session->ProcessUpdatePropertyByAction(
1439 property, session_, WSPropertyChangeAction::ACTION_UPDATE_TEXTFIELD_AVOID_INFO);
1440 session->ProcessUpdatePropertyByAction(property, session_, WSPropertyChangeAction::ACTION_UPDATE_WINDOW_MASK);
1441 session->ProcessUpdatePropertyByAction(property, session_, WSPropertyChangeAction::ACTION_UPDATE_TOPMOST);
1442 session->ProcessUpdatePropertyByAction(property, session_, WSPropertyChangeAction::ACTION_UPDATE_MODE_SUPPORT_INFO);
1443 }
1444
1445 /**
1446 * @tc.name: HandleActionUpdateTurnScreenOn
1447 * @tc.desc: HandleActionUpdateTurnScreenOn function01
1448 * @tc.type: FUNC
1449 */
1450 HWTEST_F(SceneSessionTest5, HandleActionUpdateTurnScreenOn, Function | SmallTest | Level2)
1451 {
1452 SessionInfo info;
1453 info.abilityName_ = "HandleActionUpdateTurnScreenOn";
1454 info.bundleName_ = "HandleActionUpdateTurnScreenOn";
1455 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1456 EXPECT_NE(session, nullptr);
1457
1458 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1459 EXPECT_NE(property, nullptr);
1460
1461 SessionInfo info_;
1462 info_.abilityName_ = "ProcessUpdatePropertyByAction_";
1463 info_.bundleName_ = "ProcessUpdatePropertyByAction_";
1464 sptr<SceneSession> session_ = sptr<SceneSession>::MakeSptr(info_, nullptr);
1465 EXPECT_NE(session_, nullptr);
1466
1467 auto res = session->HandleActionUpdateTurnScreenOn(
1468 property, session_, WSPropertyChangeAction::ACTION_UPDATE_TURN_SCREEN_ON);
1469 EXPECT_EQ(res, WMError::WM_OK);
1470
1471 property->SetTurnScreenOn(true);
1472 res = session->HandleActionUpdateTurnScreenOn(
1473 property, session_, WSPropertyChangeAction::ACTION_UPDATE_TURN_SCREEN_ON);
1474 EXPECT_EQ(res, WMError::WM_OK);
1475 }
1476
1477 /**
1478 * @tc.name: SetNotifyVisibleChangeFunc
1479 * @tc.desc: SetNotifyVisibleChangeFunc Test
1480 * @tc.type: FUNC
1481 */
1482 HWTEST_F(SceneSessionTest5, SetNotifyVisibleChangeFunc, Function | SmallTest | Level2)
1483 {
1484 SessionInfo info;
1485 info.abilityName_ = "test";
1486 info.bundleName_ = "test";
1487 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1488 EXPECT_NE(session, nullptr);
1489
__anon5df351211002(int32_t persistentId) 1490 session->SetNotifyVisibleChangeFunc([](int32_t persistentId) {});
1491 EXPECT_NE(session->notifyVisibleChangeFunc_, nullptr);
1492 }
1493
1494 /**
1495 * @tc.name: UpdateClientRect01
1496 * @tc.desc: UpdateClientRect
1497 * @tc.type: FUNC
1498 */
1499 HWTEST_F(SceneSessionTest5, UpdateClientRect01, Function | SmallTest | Level2)
1500 {
1501 SessionInfo info;
1502 info.abilityName_ = "UpdateClientRect01";
1503 info.bundleName_ = "UpdateClientRect01";
1504 info.windowType_ = static_cast<uint32_t>(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
1505 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1506
1507 WSRect rect = { 0, 0, 0, 0 };
1508 EXPECT_EQ(session->UpdateClientRect(rect), WSError::WS_OK);
1509
1510 session->SetClientRect(rect);
1511 rect.posX_ = 100;
1512 rect.posY_ = 100;
1513 rect.width_ = 800;
1514 rect.height_ = 800;
1515 EXPECT_EQ(session->UpdateClientRect(rect), WSError::WS_OK);
1516
1517 session->SetClientRect(rect);
1518 EXPECT_EQ(session->UpdateClientRect(rect), WSError::WS_OK);
1519 }
1520
1521 /**
1522 * @tc.name: ResetSizeChangeReasonIfDirty
1523 * @tc.desc: ResetSizeChangeReasonIfDirty
1524 * @tc.type: FUNC
1525 */
1526 HWTEST_F(SceneSessionTest5, ResetSizeChangeReasonIfDirty, Function | SmallTest | Level2)
1527 {
1528 SessionInfo info;
1529 info.abilityName_ = "ResetSizeChangeReasonIfDirty";
1530 info.bundleName_ = "ResetSizeChangeReasonIfDirty";
1531 info.windowType_ = static_cast<uint32_t>(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
1532 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1533
1534 session->UpdateSizeChangeReason(SizeChangeReason::DRAG);
1535 session->ResetDirtyFlags();
1536 session->ResetSizeChangeReasonIfDirty();
1537 EXPECT_EQ(session->GetSizeChangeReason(), SizeChangeReason::DRAG);
1538
1539 session->dirtyFlags_ |= static_cast<uint32_t>(SessionUIDirtyFlag::RECT);
1540 session->ResetSizeChangeReasonIfDirty();
1541 EXPECT_EQ(session->GetSizeChangeReason(), SizeChangeReason::DRAG);
1542
1543 session->UpdateSizeChangeReason(SizeChangeReason::MOVE);
1544 session->ResetSizeChangeReasonIfDirty();
1545 EXPECT_EQ(session->GetSizeChangeReason(), SizeChangeReason::UNDEFINED);
1546 }
1547
1548 /**
1549 * @tc.name: UpdateRect01
1550 * @tc.desc: UpdateRect
1551 * @tc.type: FUNC
1552 */
1553 HWTEST_F(SceneSessionTest5, UpdateRect01, Function | SmallTest | Level2)
1554 {
1555 SessionInfo info;
1556 info.abilityName_ = "UpdateRect01";
1557 info.bundleName_ = "UpdateRect01";
1558 info.windowType_ = static_cast<uint32_t>(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
1559 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1560 EXPECT_NE(session->property_, nullptr);
1561 SizeChangeReason reason = SizeChangeReason::UNDEFINED;
1562
1563 WSRect rect = { 200, 200, 200, 200 };
1564 session->winRect_ = rect;
1565 session->SetClientRect(rect);
1566 EXPECT_EQ(session->UpdateRect(rect, reason, "SceneSessionTest5"), WSError::WS_OK);
1567
1568 rect.posX_ = 100;
1569 rect.posY_ = 100;
1570 rect.width_ = 800;
1571 rect.height_ = 800;
1572 session->winRect_ = rect;
1573 EXPECT_EQ(session->UpdateRect(rect, reason, "SceneSessionTest5"), WSError::WS_OK);
1574 }
1575
1576 /**
1577 * @tc.name: NotifyServerToUpdateRect01
1578 * @tc.desc: NotifyServerToUpdateRect01 Test
1579 * @tc.type: FUNC
1580 */
1581 HWTEST_F(SceneSessionTest5, NotifyServerToUpdateRect01, Function | SmallTest | Level2)
1582 {
1583 SessionInfo info;
1584 info.abilityName_ = "NotifyServerToUpdateRect01";
1585 info.bundleName_ = "NotifyServerToUpdateRect01";
1586 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1587 EXPECT_NE(session, nullptr);
1588
1589 session->foregroundInteractiveStatus_.store(true);
1590 EXPECT_EQ(session->GetForegroundInteractiveStatus(), true);
1591
1592 SessionUIParam uiParam;
1593 EXPECT_EQ(session->NotifyServerToUpdateRect(uiParam, SizeChangeReason::UNDEFINED), false);
1594
1595 uiParam.rect_ = { 100, 100, 200, 200 };
1596 session->SetNeedSyncSessionRect(false);
1597 EXPECT_EQ(session->NotifyServerToUpdateRect(uiParam, SizeChangeReason::UNDEFINED), false); // not sync
1598 EXPECT_NE(session->GetSessionRect(), uiParam.rect_);
1599
1600 uiParam.needSync_ = false;
1601 EXPECT_EQ(session->NotifyServerToUpdateRect(uiParam, SizeChangeReason::UNDEFINED), false); // not sync
1602 EXPECT_NE(session->GetSessionRect(), uiParam.rect_);
1603
1604 uiParam.needSync_ = true;
1605 session->SetNeedSyncSessionRect(true); // sync first
1606 EXPECT_EQ(session->NotifyServerToUpdateRect(uiParam, SizeChangeReason::UNDEFINED), true);
1607 EXPECT_EQ(session->GetSessionRect(), uiParam.rect_);
1608
1609 EXPECT_EQ(session->NotifyServerToUpdateRect(uiParam, SizeChangeReason::UNDEFINED), false); // skip same rect
1610 }
1611
1612 /**
1613 * @tc.name: MarkSystemSceneUIFirst
1614 * @tc.desc: MarkSystemSceneUIFirst function01
1615 * @tc.type: FUNC
1616 */
1617 HWTEST_F(SceneSessionTest5, MarkSystemSceneUIFirst, Function | SmallTest | Level2)
1618 {
1619 SessionInfo info;
1620 info.abilityName_ = "MarkSystemSceneUIFirst";
1621 info.bundleName_ = "MarkSystemSceneUIFirst";
1622 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1623 EXPECT_NE(session, nullptr);
1624 session->MarkSystemSceneUIFirst(true, true);
1625
1626 struct RSSurfaceNodeConfig config;
1627 std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Create(config);
1628 session->surfaceNode_ = surfaceNode;
1629 session->leashWinSurfaceNode_ = nullptr;
1630 session->MarkSystemSceneUIFirst(true, true);
1631 session->leashWinSurfaceNode_ = surfaceNode;
1632 session->MarkSystemSceneUIFirst(true, true);
1633 EXPECT_NE(nullptr, session->GetLeashWinSurfaceNode());
1634 }
1635
1636 /**
1637 * @tc.name: StartMovingWithCoordinate_01
1638 * @tc.desc: StartMovingWithCoordinate
1639 * @tc.type: FUNC
1640 */
1641 HWTEST_F(SceneSessionTest5, StartMovingWithCoordinate_01, Function | SmallTest | Level2)
1642 {
1643 const SessionInfo info;
1644 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1645 sceneSession->moveDragController_ = nullptr;
1646 WSError result = sceneSession->StartMovingWithCoordinate(100, 50, 300, 500);
1647 EXPECT_EQ(result, WSError::WS_ERROR_NULLPTR);
1648 }
1649
1650 /**
1651 * @tc.name: StartMovingWithCoordinate_02
1652 * @tc.desc: StartMovingWithCoordinate
1653 * @tc.type: FUNC
1654 */
1655 HWTEST_F(SceneSessionTest5, StartMovingWithCoordinate_02, Function | SmallTest | Level2)
1656 {
1657 const SessionInfo info;
1658 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1659 sceneSession->moveDragController_ = sptr<MoveDragController>::MakeSptr(2024);
1660 sceneSession->moveDragController_->isStartMove_ = true;
1661 WSError result = sceneSession->StartMovingWithCoordinate(100, 50, 300, 500);
1662 EXPECT_EQ(result, WSError::WS_ERROR_REPEAT_OPERATION);
1663 }
1664
1665 /**
1666 * @tc.name: StartMovingWithCoordinate_03
1667 * @tc.desc: StartMovingWithCoordinate
1668 * @tc.type: FUNC
1669 */
1670 HWTEST_F(SceneSessionTest5, StartMovingWithCoordinate_03, Function | SmallTest | Level2)
1671 {
1672 const SessionInfo info;
1673 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1674 sceneSession->moveDragController_ = sptr<MoveDragController>::MakeSptr(2024);
1675 sceneSession->moveDragController_->isStartMove_ = false;
1676 WSError result = sceneSession->StartMovingWithCoordinate(100, 50, 300, 500);
1677 EXPECT_EQ(result, WSError::WS_OK);
1678 }
1679
1680 /**
1681 * @tc.name: IsSameMainSession
1682 * @tc.desc: test IsSameMainSession
1683 * @tc.type: FUNC
1684 */
1685 HWTEST_F(SceneSessionTest5, IsSameMainSession, Function | SmallTest | Level2)
1686 {
1687 SessionInfo info1;
1688 info1.abilityName_ = "abilityName_test1";
1689 info1.bundleName_ = "bundleName_test1";
1690 SessionInfo info2;
1691 info2.abilityName_ = "abilityName_test2";
1692 info2.bundleName_ = "bundleName_test2";
1693 sptr<SceneSession> preSceneSession = sptr<SceneSession>::MakeSptr(info1, nullptr);
1694 sptr<SceneSession> currSceneSession = sptr<SceneSession>::MakeSptr(info2, nullptr);
1695 preSceneSession->persistentId_ = 1;
1696 currSceneSession->persistentId_ = 1;
1697 ASSERT_EQ(true, currSceneSession->IsSameMainSession(preSceneSession));
1698 currSceneSession->persistentId_ = 2;
1699 ASSERT_EQ(false, currSceneSession->IsSameMainSession(preSceneSession));
1700
1701 sptr<SceneSession> subSession1 = sptr<SceneSession>::MakeSptr(info1, nullptr);
1702 sptr<SceneSession> subSession2 = sptr<SceneSession>::MakeSptr(info2, nullptr);
1703 subSession1->SetParentSession(preSceneSession);
1704 subSession2->SetParentSession(currSceneSession);
1705 currSceneSession->persistentId_ = 1;
1706 subSession1->property_->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
1707 subSession2->property_->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
1708 ASSERT_EQ(true, subSession1->IsSameMainSession(subSession1));
1709 currSceneSession->persistentId_ = 2;
1710 ASSERT_EQ(false, subSession1->IsSameMainSession(subSession2));
1711 }
1712
1713 /**
1714 * @tc.name: HandleActionUpdateExclusivelyHighlighted
1715 * @tc.desc: test HandleActionUpdateExclusivelyHighlighted
1716 * @tc.type: FUNC
1717 */
1718 HWTEST_F(SceneSessionTest5, HandleActionUpdateExclusivelyHighlighted, Function | SmallTest | Level2)
1719 {
1720 SessionInfo info;
1721 info.abilityName_ = "HandleActionUpdateExclusivelyHighlighted";
1722 info.bundleName_ = "HandleActionUpdateExclusivelyHighlighted";
1723 info.isSystem_ = true;
1724 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1725 ASSERT_NE(nullptr, session);
1726 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1727 ASSERT_NE(nullptr, property);
1728 property->SetExclusivelyHighlighted(true);
1729 WSPropertyChangeAction action = WSPropertyChangeAction::ACTION_UPDATE_EXCLUSIVE_HIGHLIGHTED;
1730 auto res = session->HandleActionUpdateExclusivelyHighlighted(property, action);
1731 EXPECT_EQ(WMError::WM_OK, res);
1732 }
1733
1734 /**
1735 * @tc.name: SetHighlightChangeNotifyFunc
1736 * @tc.desc: SetHighlightChangeNotifyFunc Test
1737 * @tc.type: FUNC
1738 */
1739 HWTEST_F(SceneSessionTest5, SetHighlightChangeNotifyFunc, Function | SmallTest | Level2)
1740 {
1741 SessionInfo info;
1742 info.abilityName_ = "test";
1743 info.bundleName_ = "test";
1744 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1745 EXPECT_NE(session, nullptr);
__anon5df351211102(int32_t persistentId) 1746 session->SetHighlightChangeNotifyFunc([](int32_t persistentId) {});
1747 EXPECT_NE(session->highlightChangeFunc_, nullptr);
1748 }
1749
1750 /**
1751 * @tc.name: SetColorSpace
1752 * @tc.desc: SetColorSpace function01
1753 * @tc.type: FUNC
1754 */
1755 HWTEST_F(SceneSessionTest5, SetColorSpace, Function | SmallTest | Level2)
1756 {
1757 SessionInfo info;
1758 info.abilityName_ = "SetColorSpace";
1759 info.bundleName_ = "SetColorSpace";
1760 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1761 EXPECT_NE(session, nullptr);
1762
1763 struct RSSurfaceNodeConfig config;
1764 std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Create(config);
1765 session->SetColorSpace(ColorSpace::COLOR_SPACE_WIDE_GAMUT);
1766 EXPECT_EQ(nullptr, session->GetSurfaceNode());
1767 session->surfaceNode_ = surfaceNode;
1768 session->SetColorSpace(ColorSpace::COLOR_SPACE_WIDE_GAMUT);
1769 EXPECT_NE(nullptr, session->GetSurfaceNode());
1770 }
1771 }
1772 } // namespace Rosen
1773 } // namespace OHOS