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