• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 "transaction/rs_uiextension_data.h"
17 #include "input_manager.h"
18 #include "session_manager/include/scene_session_dirty_manager.h"
19 #include <gtest/gtest.h>
20 #include <parameter.h>
21 #include <parameters.h>
22 #include "screen_session_manager_client/include/screen_session_manager_client.h"
23 #include "session/host/include/scene_session.h"
24 #include "session/host/include/sub_session.h"
25 #include "session_manager/include/scene_session_manager.h"
26 #include "transaction/rs_uiextension_data.h"
27 
28 
29 using namespace testing;
30 using namespace testing::ext;
31 
32 namespace OHOS {
33 namespace Rosen {
34 constexpr int POINTER_CHANGE_AREA_SIXTEEN = 16;
35 constexpr int POINTER_CHANGE_AREA_DEFAULT = 0;
36 constexpr int POINTER_CHANGE_AREA_FIVE = 5;
37 static int32_t g_screenRotationOffset = system::GetIntParameter<int32_t>("const.fold.screen_rotation.offset", 0);
38 class SceneSessionDirtyManagerTest : public testing::Test {
39 public:
40     static void SetUpTestCase();
41     static void TearDownTestCase();
42     void SetUp() override;
43     void TearDown() override;
44     static constexpr uint32_t WAIT_SYNC_IN_NS = 500000;
45 };
46 SceneSessionDirtyManager *manager_;
47 SceneSessionManager *ssm_;
SetUpTestCase()48 void SceneSessionDirtyManagerTest::SetUpTestCase()
49 {
50     ssm_ = &SceneSessionManager::GetInstance();
51     ssm_->sceneSessionMap_.clear();
52 }
53 
TearDownTestCase()54 void SceneSessionDirtyManagerTest::TearDownTestCase()
55 {
56     ssm_ = nullptr;
57 }
58 
SetUp()59 void SceneSessionDirtyManagerTest::SetUp()
60 {
61     manager_ = new SceneSessionDirtyManager();
62 }
63 
TearDown()64 void SceneSessionDirtyManagerTest::TearDown()
65 {
66     usleep(WAIT_SYNC_IN_NS);
67     delete manager_;
68     manager_ = nullptr;
69 }
70 namespace {
71 
72 /**
73  * @tc.name: NotifyWindowInfoChange
74  * @tc.desc: NotifyWindowInfoChange
75  * @tc.type: FUNC
76  */
77 HWTEST_F(SceneSessionDirtyManagerTest, NotifyWindowInfoChange, Function | SmallTest | Level2)
78 {
79     int ret = 0;
80     manager_->NotifyWindowInfoChange(nullptr, WindowUpdateType::WINDOW_UPDATE_ADDED, true);
81     SessionInfo info;
82     info.abilityName_ = "TestAbilityName";
83     info.bundleName_ = "TestBundleName";
84     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
85     if (sceneSession == nullptr) {
86         return;
87     }
88     manager_->NotifyWindowInfoChange(sceneSession, WindowUpdateType::WINDOW_UPDATE_ADDED, true);
89     manager_->NotifyWindowInfoChange(sceneSession, WindowUpdateType::WINDOW_UPDATE_REMOVED, true);
90     manager_->NotifyWindowInfoChange(sceneSession, WindowUpdateType::WINDOW_UPDATE_ACTIVE, true);
91     manager_->NotifyWindowInfoChange(sceneSession, WindowUpdateType::WINDOW_UPDATE_FOCUSED, true);
92     ASSERT_EQ(ret, 0);
93 }
94 
95 /**
96  * @tc.name: GetFullWindowInfoList
97  * @tc.desc: GetFullWindowInfoList
98  * @tc.type: FUNC
99  */
100 HWTEST_F(SceneSessionDirtyManagerTest, GetFullWindowInfoList, Function | SmallTest | Level2)
101 {
102     auto [windowInfoList, pixelMapList] = manager_->GetFullWindowInfoList();
103     SessionInfo info;
104     info.abilityName_ = "TestAbilityName";
105     info.bundleName_ = "TestBundleName";
106     {
107         sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
108         ASSERT_NE(sceneSession, nullptr);
109         sceneSession->UpdateVisibilityInner(true);
110         ssm_->sceneSessionMap_.insert({sceneSession->GetPersistentId(), sceneSession});
111     }
112     {
113         ssm_->sceneSessionMap_.insert({111, nullptr});
114     }
115     {
116         sptr<SceneSession> sceneSessionDialog1 = sptr<SceneSession>::MakeSptr(info, nullptr);
117         ASSERT_NE(sceneSessionDialog1, nullptr);
118         sceneSessionDialog1->UpdateVisibilityInner(true);
119         sptr<WindowSessionProperty> propertyDialog1 = sceneSessionDialog1->GetSessionProperty();
120         propertyDialog1->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
121         ssm_->sceneSessionMap_.insert({sceneSessionDialog1->GetPersistentId(), sceneSessionDialog1});
122     }
123     {
124         sptr<SceneSession> sceneSessionModal1 = sptr<SceneSession>::MakeSptr(info, nullptr);
125         ASSERT_NE(sceneSessionModal1, nullptr);
126         sceneSessionModal1->UpdateVisibilityInner(true);
127         sptr<WindowSessionProperty> propertyModal1 = sceneSessionModal1->GetSessionProperty();
128         propertyModal1->SetWindowFlags(static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_IS_MODAL));
129         ssm_->sceneSessionMap_.insert({sceneSessionModal1->GetPersistentId(), sceneSessionModal1});
130     }
131     auto [windowInfoList1, pixelMapList1] = manager_->GetFullWindowInfoList();
132     ASSERT_EQ(windowInfoList.size() + 3, windowInfoList1.size());
133 }
134 
135 /**
136  * @tc.name: IsFilterSession
137  * @tc.desc: IsFilterSession
138  * @tc.type: FUNC
139  */
140 HWTEST_F(SceneSessionDirtyManagerTest, IsFilterSession, Function | SmallTest | Level2)
141 {
142     bool ret = manager_->IsFilterSession(nullptr);
143     ASSERT_EQ(ret, true);
144     SessionInfo info;
145     info.abilityName_ = "test1";
146     info.bundleName_ = "test2";
147     info.sceneType_ = SceneType::INPUT_SCENE;
148     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
149     ASSERT_NE(sceneSession, nullptr);
150     sptr<WindowSessionProperty> property = sceneSession->GetSessionProperty();
151     sceneSession->sessionInfo_ = info;
152     ret = manager_->IsFilterSession(sceneSession);
153     ASSERT_EQ(ret, false);
154     info.isSystem_ = false;
155     sceneSession->sessionInfo_ = info;
156     sceneSession->isVisible_ = false;
157     sceneSession->isSystemActive_ = false;
158     ret = manager_->IsFilterSession(sceneSession);
159     ASSERT_EQ(ret, false);
160     info.isSystem_ = true;
161     sceneSession->sessionInfo_ = info;
162     ret = manager_->IsFilterSession(sceneSession);
163     ASSERT_EQ(ret, false);
164     sceneSession->isVisible_ = true;
165     ret = manager_->IsFilterSession(sceneSession);
166     ASSERT_EQ(ret, false);
167     sceneSession->isSystemActive_ = true;
168     ret = manager_->IsFilterSession(sceneSession);
169     ASSERT_EQ(ret, false);
170     info.isSystem_ = true;
171     sceneSession->sessionInfo_ = info;
172     sceneSession->isVisible_ = true;
173     sceneSession->SetSystemActive(true);
174     ret = manager_->IsFilterSession(sceneSession);
175     ASSERT_EQ(ret, false);
176     info.isSystem_ = false;
177     sceneSession->sessionInfo_ = info;
178     sceneSession->isVisible_ = false;
179     sceneSession->SetSystemActive(false);
180     ret = manager_->IsFilterSession(sceneSession);
181     ASSERT_EQ(ret, false);
182     sceneSession->isVisible_ = false;
183     ret = manager_->IsFilterSession(sceneSession);
184     ASSERT_EQ(ret, false);
185 }
186 
187 /**
188  * @tc.name: IsFilterSession02
189  * @tc.desc: IsFilterSession02
190  * @tc.type: FUNC
191  */
192 HWTEST_F(SceneSessionDirtyManagerTest, IsFilterSession02, Function | SmallTest | Level2)
193 {
194     bool ret = manager_->IsFilterSession(nullptr);
195     ASSERT_EQ(ret, true);
196     SessionInfo info;
197     info.abilityName_ = "test3";
198     info.bundleName_ = "test4";
199     info.sceneType_ = SceneType::WINDOW_SCENE;
200     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
201     ASSERT_NE(sceneSession, nullptr);
202     sptr<WindowSessionProperty> property = sceneSession->GetSessionProperty();
203     sceneSession->sessionInfo_ = info;
204     ret = manager_->IsFilterSession(sceneSession);
205     ASSERT_EQ(ret, true);
206     info.isSystem_ = false;
207     sceneSession->sessionInfo_ = info;
208     sceneSession->isVisible_ = false;
209     sceneSession->isSystemActive_ = false;
210     ret = manager_->IsFilterSession(sceneSession);
211     ASSERT_EQ(ret, true);
212     info.isSystem_ = true;
213     sceneSession->sessionInfo_ = info;
214     ret = manager_->IsFilterSession(sceneSession);
215     ASSERT_EQ(ret, true);
216     sceneSession->isVisible_ = true;
217     ret = manager_->IsFilterSession(sceneSession);
218     ASSERT_EQ(ret, false);
219     sceneSession->isSystemActive_ = true;
220     ret = manager_->IsFilterSession(sceneSession);
221     ASSERT_EQ(ret, false);
222     info.isSystem_ = true;
223     sceneSession->sessionInfo_ = info;
224     sceneSession->isVisible_ = true;
225     sceneSession->SetSystemActive(true);
226     ret = manager_->IsFilterSession(sceneSession);
227     ASSERT_EQ(ret, false);
228     info.isSystem_ = false;
229     sceneSession->sessionInfo_ = info;
230     sceneSession->isVisible_ = false;
231     sceneSession->SetSystemActive(false);
232     ret = manager_->IsFilterSession(sceneSession);
233     ASSERT_EQ(ret, true);
234     sceneSession->isVisible_ = false;
235     ret = manager_->IsFilterSession(sceneSession);
236     ASSERT_EQ(ret, true);
237 }
238 
239 /**
240  * @tc.name: GetWindowInfo
241  * @tc.desc: GetWindowInfo
242  * @tc.type: FUNC
243  */
244 HWTEST_F(SceneSessionDirtyManagerTest, GetWindowInfo, Function | SmallTest | Level2)
245 {
246     manager_->GetWindowInfo(nullptr, SceneSessionDirtyManager::WindowAction::WINDOW_ADD);
247     SessionInfo info;
248     info.abilityName_ = "111";
249     info.bundleName_ = "111";
250     sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
251     ASSERT_NE(session, nullptr);
252     manager_->GetWindowInfo(session, SceneSessionDirtyManager::WindowAction::WINDOW_ADD);
253     session = sptr<SceneSession>::MakeSptr(info, nullptr);
254     ASSERT_NE(session, nullptr);
255     sptr<WindowSessionProperty> windowSessionProperty = session->GetSessionProperty();
256     session->SetSessionProperty(windowSessionProperty);
257     manager_->GetWindowInfo(session, SceneSessionDirtyManager::WindowAction::WINDOW_ADD);
258     windowSessionProperty->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
259     std::pair<MMI::WindowInfo, std::shared_ptr<Media::PixelMap>> ret;
260     ret = manager_->GetWindowInfo(session, SceneSessionDirtyManager::WindowAction::WINDOW_ADD);
261     ASSERT_EQ(ret.first.id, session->GetWindowId());
262     windowSessionProperty->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
263     ret = manager_->GetWindowInfo(session, SceneSessionDirtyManager::WindowAction::WINDOW_ADD);
264     ASSERT_EQ(ret.first.windowType, static_cast<int32_t>(windowSessionProperty->GetWindowType()));
265     windowSessionProperty->SetMaximizeMode(MaximizeMode::MODE_AVOID_SYSTEM_BAR);
266     ret = manager_->GetWindowInfo(session, SceneSessionDirtyManager::WindowAction::WINDOW_ADD);
267     ASSERT_EQ(ret.first.id, session->GetWindowId());
268     info.isSetPointerAreas_ = true;
269     ret = manager_->GetWindowInfo(session, SceneSessionDirtyManager::WindowAction::WINDOW_ADD);
270     ASSERT_EQ(ret.first.id, session->GetWindowId());
271     windowSessionProperty->SetWindowFlags(static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_HANDWRITING));
272     ret = manager_->GetWindowInfo(session, SceneSessionDirtyManager::WindowAction::WINDOW_ADD);
273     ASSERT_EQ(ret.first.flags, static_cast<int32_t>(MMI::WindowInfo::FLAG_BIT_HANDWRITING));
274     windowSessionProperty->SetWindowFlags(static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_IS_MODAL));
275     ret = manager_->GetWindowInfo(session, SceneSessionDirtyManager::WindowAction::WINDOW_ADD);
276     ASSERT_EQ(ret.first.flags, 0);
277     ret = manager_->GetWindowInfo(session, SceneSessionDirtyManager::WindowAction::WINDOW_ADD);
278     ASSERT_EQ(ret.first.id, session->GetWindowId());
279 }
280 
281 /**
282  * @tc.name: CalNotRotateTransform
283  * @tc.desc: CalNotRotateTransform
284  * @tc.type: FUNC
285  */
286 HWTEST_F(SceneSessionDirtyManagerTest, CalNotRotateTransform, Function | SmallTest | Level2)
287 {
288     SessionInfo sessionInfo;
289     sessionInfo.bundleName_ = "CalNotRotateTransform";
290     sessionInfo.moduleName_ = "sessionInfo";
291     Matrix3f transform;
292     Matrix3f testTransform = transform;
293     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
294     ASSERT_NE(sceneSession, nullptr);
295     manager_->CalNotRotateTransform(nullptr, transform);
296     ASSERT_EQ(transform, testTransform);
297     auto screenId = 0;
298     sceneSession->GetSessionProperty()->SetDisplayId(screenId);
299     manager_->CalNotRotateTransform(sceneSession, transform);
300     ASSERT_EQ(transform, testTransform);
301     ScreenProperty screenProperty0;
302     screenProperty0.SetRotation(0.0f);
303     ScreenSessionConfig config;
304     sptr<ScreenSession> screenSession =
305         sptr<ScreenSession>::MakeSptr(config, ScreenSessionReason::CREATE_SESSION_FOR_CLIENT);
306     ASSERT_NE(screenSession, nullptr);
307     ScreenSessionManagerClient::GetInstance().OnUpdateFoldDisplayMode(FoldDisplayMode::UNKNOWN);
308     ScreenPropertyChangeReason reason = ScreenPropertyChangeReason::UNDEFINED;
309     ScreenSessionManagerClient::GetInstance().screenSessionMap_.emplace(screenId, screenSession);
310     testTransform.SetZero();
311     ScreenSessionManagerClient::GetInstance().OnPropertyChanged(screenId, screenProperty0, reason);
312     manager_->CalNotRotateTransform(sceneSession, transform);
313     ASSERT_EQ(transform, testTransform);
314     screenProperty0.SetRotation(90.0f);
315     ScreenSessionManagerClient::GetInstance().OnPropertyChanged(screenId, screenProperty0, reason);
316     manager_->CalNotRotateTransform(sceneSession, transform);
317     ASSERT_EQ(transform, testTransform);
318     screenProperty0.SetRotation(180.0f);
319     ScreenSessionManagerClient::GetInstance().OnPropertyChanged(screenId, screenProperty0, reason);
320     manager_->CalNotRotateTransform(sceneSession, transform);
321     ASSERT_EQ(transform, testTransform);
322     screenProperty0.SetRotation(270.0f);
323     ScreenSessionManagerClient::GetInstance().OnPropertyChanged(screenId, screenProperty0, reason);
324     manager_->CalNotRotateTransform(sceneSession, transform);
325     ASSERT_EQ(transform, testTransform);
326 }
327 
328 /**
329  * @tc.name: CalNotRotateTransform2
330  * @tc.desc: CalNotRotateTransform2
331  * @tc.type: FUNC
332  */
333 HWTEST_F(SceneSessionDirtyManagerTest, CalNotRotateTransform2, Function | SmallTest | Level2)
334 {
335     SessionInfo sessionInfo;
336     Matrix3f transform;
337     Matrix3f testTransform = transform;
338     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
339     ASSERT_NE(sceneSession, nullptr);
340     auto screenId = 0;
341     sceneSession->GetSessionProperty()->SetDisplayId(screenId);
342     ScreenProperty screenProperty0;
343     screenProperty0.SetRotation(0.0f);
344     ScreenSessionConfig config;
345     sptr<ScreenSession> screenSession =
346         sptr<ScreenSession>::MakeSptr(config, ScreenSessionReason::CREATE_SESSION_FOR_CLIENT);
347     ASSERT_NE(screenSession, nullptr);
348     ScreenSessionManagerClient::GetInstance().OnUpdateFoldDisplayMode(FoldDisplayMode::UNKNOWN);
349     ScreenPropertyChangeReason reason = ScreenPropertyChangeReason::UNDEFINED;
350     ScreenSessionManagerClient::GetInstance().screenSessionMap_.emplace(screenId, screenSession);
351     testTransform.SetZero();
352     ScreenSessionManagerClient::GetInstance().OnPropertyChanged(screenId, screenProperty0, reason);
353     auto oriProperty = sceneSession->GetSessionProperty();
354     sceneSession->property_ = nullptr;
355     manager_->CalNotRotateTransform(sceneSession, transform);
356     ASSERT_EQ(transform, testTransform);
357     sceneSession->property_ = oriProperty;
358 }
359 
360 /**
361  * @tc.name: CalTransform
362  * @tc.desc: CalTransform
363  * @tc.type: FUNC
364  */
365 HWTEST_F(SceneSessionDirtyManagerTest, CalTransform, Function | SmallTest | Level2)
366 {
367     SessionInfo sessionInfo;
368     sessionInfo.bundleName_ = "CalTransform";
369     sessionInfo.moduleName_ = "CalTransform";
370     SingleHandData testSingleHandData;
371     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
372     ASSERT_NE(sceneSession, nullptr);
373     Vector2f scale(sceneSession->GetScaleX(), sceneSession->GetScaleY());
374     Vector2f translate = sceneSession->GetSessionGlobalPosition(false);
375     Vector2f offset = sceneSession->GetSessionGlobalPosition(false);
376     Matrix3f transform;
377     Matrix3f testTransform = transform;
378     manager_->CalTransform(nullptr, transform, testSingleHandData);
379     ASSERT_EQ(transform, testTransform);
380     sessionInfo.isRotable_ = true;
381     manager_->CalTransform(sceneSession, transform, testSingleHandData);
382     ASSERT_EQ(transform, transform.Translate(translate)
383         .Scale(scale, sceneSession->GetPivotX(), sceneSession->GetPivotY()).Inverse());
384     sessionInfo.isSystem_ = true;
385     manager_->CalTransform(sceneSession, transform, testSingleHandData);
386     ASSERT_EQ(transform, transform.Translate(translate)
387         .Scale(scale, sceneSession->GetPivotX(), sceneSession->GetPivotY()).Inverse());
388     sessionInfo.isRotable_ = false;
389     manager_->CalTransform(sceneSession, transform, testSingleHandData);
390     ASSERT_EQ(transform, transform.Translate(translate)
391         .Scale(scale, sceneSession->GetPivotX(), sceneSession->GetPivotY()).Inverse());
392     sessionInfo.isRotable_ = true;
393     sessionInfo.isSystem_ = false;
394     manager_->CalTransform(sceneSession, transform, testSingleHandData);
395     ASSERT_EQ(transform, transform.Translate(translate)
396         .Scale(scale, sceneSession->GetPivotX(), sceneSession->GetPivotY()).Inverse());
397     sessionInfo.isSystem_ = true;
398     auto preScreenSessionManager = ScreenSessionManagerClient::GetInstance().screenSessionManager_;
399     ScreenSessionManagerClient::GetInstance().screenSessionManager_ = nullptr;
400     manager_->CalTransform(sceneSession, transform, testSingleHandData);
401     ASSERT_EQ(transform, transform.Translate(translate)
402         .Scale(scale, sceneSession->GetPivotX(), sceneSession->GetPivotY()).Inverse());
403     ScreenSessionManagerClient::GetInstance().screenSessionManager_ = preScreenSessionManager;
404     manager_->CalTransform(sceneSession, transform, testSingleHandData);
405     ASSERT_EQ(transform, transform.Translate(translate)
406         .Scale(scale, sceneSession->GetPivotX(), sceneSession->GetPivotY()).Inverse());
407     testSingleHandData.singleHandY = 0;
408     manager_->CalTransform(sceneSession, transform, testSingleHandData);
409     ASSERT_EQ(transform, transform.Translate(translate)
410         .Scale(scale, sceneSession->GetPivotX(), sceneSession->GetPivotY()).Inverse());
411 }
412 
413 /**
414  * @tc.name: UpdateHotAreas
415  * @tc.desc: UpdateHotAreas
416  * @tc.type: FUNC
417  */
418 HWTEST_F(SceneSessionDirtyManagerTest, UpdateHotAreas, Function | SmallTest | Level2)
419 {
420     std::vector<MMI::Rect> touchHotAreas(0);
421     std::vector<MMI::Rect> pointerHotAreas(0);
422     manager_->UpdateHotAreas(nullptr, touchHotAreas, pointerHotAreas);
423     ASSERT_EQ(touchHotAreas.size(), 0);
424     SessionInfo sessionInfo;
425     sessionInfo.bundleName_ = "UpdateHotAreas";
426     sessionInfo.moduleName_ = "UpdateHotAreas";
427     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
428     ASSERT_NE(sceneSession, nullptr);
429     std::vector<OHOS::Rosen::Rect> touchHotAreasInSceneSession(0);
430     sceneSession->GetSessionProperty()->SetTouchHotAreas(touchHotAreasInSceneSession);
431     sceneSession->persistentId_ = 1;
432     for (int i = 0; i < 2 ; i++) {
433         OHOS::Rosen::Rect area;
434         area.posX_ = i * 10;
435         area.posY_ = i * 10;
436         area.width_ = 10;
437         area.height_ = 10;
438         touchHotAreasInSceneSession.emplace_back(area);
439     }
440     sceneSession->GetSessionProperty()->SetTouchHotAreas(touchHotAreasInSceneSession);
441     touchHotAreas.clear();
442     pointerHotAreas.clear();
443     manager_->UpdateHotAreas(sceneSession, touchHotAreas, pointerHotAreas);
444     ASSERT_EQ(touchHotAreas.size(), 2);
445     for (int i = 2; i < 10 ; i++) {
446         OHOS::Rosen::Rect area;
447         area.posX_ = i * 10;
448         area.posY_ = i * 10;
449         area.width_ = 10;
450         area.height_ = 10;
451         touchHotAreasInSceneSession.emplace_back(area);
452     }
453     sceneSession->GetSessionProperty()->SetTouchHotAreas(touchHotAreasInSceneSession);
454     touchHotAreas.clear();
455     pointerHotAreas.clear();
456     manager_->UpdateHotAreas(sceneSession, touchHotAreas, pointerHotAreas);
457     ASSERT_EQ(touchHotAreas.size(), 10);
458     std::vector<OHOS::Rosen::Rect> fullSceneSession(static_cast<uint32_t>(MMI::WindowInfo::MAX_HOTAREA_COUNT));
459     sceneSession->GetSessionProperty()->SetTouchHotAreas(fullSceneSession);
460     touchHotAreas.clear();
461     pointerHotAreas.clear();
462     manager_->UpdateHotAreas(sceneSession, touchHotAreas, pointerHotAreas);
463     ASSERT_EQ(touchHotAreas.size(), 1);
464 }
465 
466 /**
467  * @tc.name: UpdateHotAreas2
468  * @tc.desc: UpdateHotAreas2
469  * @tc.type: FUNC
470  */
471 HWTEST_F(SceneSessionDirtyManagerTest, UpdateHotAreas2, Function | SmallTest | Level2)
472 {
473     std::vector<MMI::Rect> touchHotAreas(0);
474     std::vector<MMI::Rect> pointerHotAreas(0);
475     SessionInfo sessionInfo;
476     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
477     ASSERT_NE(sceneSession, nullptr);
478     std::vector<OHOS::Rosen::Rect> touchHotAreasInSceneSession(0);
479     sceneSession->GetSessionProperty()->SetTouchHotAreas(touchHotAreasInSceneSession);
480     sceneSession->GetSessionProperty()->type_ = WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT;
481     touchHotAreas.clear();
482     pointerHotAreas.clear();
483     sceneSession->GetSessionProperty()->SetDisplayId(-100);
484     manager_->UpdateHotAreas(sceneSession, touchHotAreas, pointerHotAreas);
485     ASSERT_EQ(touchHotAreas.size(), 1);
486 }
487 
488 /**
489  * @tc.name: UpdateDefaultHotAreas
490  * @tc.desc: UpdateDefaultHotAreas
491  * @tc.type: FUNC
492  */
493 HWTEST_F(SceneSessionDirtyManagerTest, UpdateDefaultHotAreas, Function | SmallTest | Level2)
494 {
495     std::vector<MMI::Rect> empty(0);
496     manager_->UpdateDefaultHotAreas(nullptr, empty, empty);
497     ASSERT_EQ(empty.size(), 0);
498     SessionInfo sessionInfo;
499     sessionInfo.bundleName_ = "UpdateDefaultHotAreas";
500     sessionInfo.moduleName_ = "UpdateDefaultHotAreas";
501     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
502     if (sceneSession == nullptr) {
503         return;
504     }
505     WSRect rect = {0, 0, 320, 240};
506     sceneSession->SetSessionRect(rect);
507     manager_->UpdateDefaultHotAreas(sceneSession, empty, empty);
508     ASSERT_NE(empty.size(), 0);
509     manager_->UpdateDefaultHotAreas(nullptr, empty, empty);
510     sceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
511     manager_->UpdateDefaultHotAreas(sceneSession, empty, empty);
512     ASSERT_NE(empty.size(), 0);
513     manager_->UpdateDefaultHotAreas(nullptr, empty, empty);
514     sceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_PIP);
515     manager_->UpdateDefaultHotAreas(sceneSession, empty, empty);
516     ASSERT_NE(empty.size(), 0);
517     manager_->UpdateDefaultHotAreas(nullptr, empty, empty);
518     sceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_SCENE_BOARD);
519     manager_->UpdateDefaultHotAreas(sceneSession, empty, empty);
520     ASSERT_NE(empty.size(), 0);
521 }
522 
523 /**
524  * @tc.name: ConvertDegreeToMMIRotation
525  * @tc.desc: ConvertDegreeToMMIRotation
526  * @tc.type: FUNC
527  */
528 HWTEST_F(SceneSessionDirtyManagerTest, ConvertDegreeToMMIRotation, Function | SmallTest | Level2)
529 {
530     MMI::Direction dirction = MMI::DIRECTION0;
531     dirction = ConvertDegreeToMMIRotation(0.0);
532     ASSERT_EQ(dirction, MMI::DIRECTION0);
533     dirction = ConvertDegreeToMMIRotation(90.0);
534     ASSERT_EQ(dirction, MMI::DIRECTION90);
535     dirction = ConvertDegreeToMMIRotation(180.0);
536     ASSERT_EQ(dirction, MMI::DIRECTION180);
537     dirction = ConvertDegreeToMMIRotation(270.0);
538     ASSERT_EQ(dirction, MMI::DIRECTION270);
539     dirction = ConvertDegreeToMMIRotation(30.0);
540     ASSERT_EQ(dirction, MMI::DIRECTION0);
541 }
542 
543 /**
544  * @tc.name: GetDialogSessionMap
545  * @tc.desc: GetDialogSessionMap
546  * @tc.type: FUNC
547  */
548 HWTEST_F(SceneSessionDirtyManagerTest, GetDialogSessionMap, Function | SmallTest | Level2)
549 {
550     std::map<int32_t, sptr<SceneSession>> sessionMap;
551     SessionInfo info;
552     info.abilityName_ = "TestAbilityName";
553     info.bundleName_ = "TestBundleName";
554     sessionMap.emplace(1, nullptr);
555     auto sessionList = manager_->GetDialogSessionMap(sessionMap);
556     ASSERT_EQ(0, sessionList.size());
557     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
558     if (!sceneSession) {
559         GTEST_LOG_(INFO) << "sceneSession is nullptr";
560         return;
561     }
562     sessionMap.emplace(2, sceneSession);
563     auto sessionList2 = manager_->GetDialogSessionMap(sessionMap);
564     ASSERT_EQ(0, sessionList2.size());
565     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
566     if (!property) {
567         GTEST_LOG_(INFO) << "property is nullptr";
568         return;
569     }
570     property->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
571     sceneSession->SetSessionProperty(property);
572     sptr<Session> session = sptr<Session>::MakeSptr(info);
573     if (!session) {
574         GTEST_LOG_(INFO) << "session is nullptr";
575         return;
576     }
577     sceneSession->SetParentSession(session);
578     auto sessionList3 = manager_->GetDialogSessionMap(sessionMap);
579     ASSERT_EQ(1, sessionList3.size());
580     sceneSession->SetForceHideState(ForceHideState::NOT_HIDDEN);
581     auto sessionList4 = manager_->GetDialogSessionMap(sessionMap);
582     ASSERT_EQ(1, sessionList4.size());
583     sceneSession->SetForceHideState(ForceHideState::HIDDEN_WHEN_FOCUSED);
584     sceneSession->SetParentSession(nullptr);
585     auto sessionList5 = manager_->GetDialogSessionMap(sessionMap);
586     ASSERT_EQ(0, sessionList5.size());
587 }
588 
589 /**
590  * @tc.name: GetDialogSessionMap02
591  * @tc.desc: GetDialogSessionMap
592  * @tc.type: FUNC
593  */
594 HWTEST_F(SceneSessionDirtyManagerTest, GetDialogSessionMap02, Function | SmallTest | Level2)
595 {
596     SessionInfo info;
597     info.abilityName_ = "TestAbilityName";
598     info.bundleName_ = "TestBundleName";
599     sptr<SubSession> sceneSession = sptr<SubSession>::MakeSptr(info, nullptr);
600     ASSERT_NE(sceneSession, nullptr);
601     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
602     ASSERT_NE(property, nullptr);
603     property->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
604     property->AddWindowFlag(WindowFlag::WINDOW_FLAG_IS_MODAL);
605     property->AddWindowFlag(WindowFlag::WINDOW_FLAG_IS_APPLICATION_MODAL);
606     sceneSession->SetSessionProperty(property);
607     sptr<Session> session = sptr<Session>::MakeSptr(info);
608     ASSERT_NE(session, nullptr);
609     sceneSession->SetParentSession(session);
610     std::map<int32_t, sptr<SceneSession>> sessionMap;
611     sessionMap.emplace(1, sceneSession);
612     auto sessionList = manager_->GetDialogSessionMap(sessionMap);
613     ASSERT_EQ(2, sessionList.size());
614 }
615 
616 /**
617  * @tc.name: UpdatePointerAreas
618  * @tc.desc: UpdatePointerAreas
619  * @tc.type: FUNC
620  */
621 HWTEST_F(SceneSessionDirtyManagerTest, UpdatePointerAreas, Function | SmallTest | Level2)
622 {
623     std::vector<int32_t> pointerChangeAreas;
624     SessionInfo info;
625     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
626     ASSERT_NE(sceneSession, nullptr);
627     auto oriProperty = sceneSession->property_;
628     sceneSession->property_ = nullptr;
629     manager_->UpdatePointerAreas(sceneSession, pointerChangeAreas);
630     ASSERT_EQ(0, pointerChangeAreas.size());
631     sceneSession->property_ = oriProperty;
632     sceneSession->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
633     sceneSession->property_->SetDragEnabled(false);
634     manager_->UpdatePointerAreas(sceneSession, pointerChangeAreas);
635     ASSERT_EQ(0, pointerChangeAreas.size());
636     sceneSession->property_->SetDragEnabled(true);
637     float vpr = 1.5f;
638     sceneSession->property_->SetDisplayId(100);
639     int32_t pointerAreaFivePx = static_cast<int32_t>(POINTER_CHANGE_AREA_FIVE * vpr);
640     int32_t pointerAreaSixteenPx = static_cast<int32_t>(POINTER_CHANGE_AREA_SIXTEEN * vpr);
641     WindowLimits limits;
642     limits.maxHeight_ = 1;
643     limits.minHeight_ = 0;
644     limits.maxWidth_ = 0;
645     limits.minWidth_ = 0;
646     sceneSession->property_->SetWindowLimits(limits);
647     manager_->UpdatePointerAreas(sceneSession, pointerChangeAreas);
648     std::vector<int32_t> compare2 = {POINTER_CHANGE_AREA_DEFAULT, pointerAreaFivePx,
649         POINTER_CHANGE_AREA_DEFAULT, POINTER_CHANGE_AREA_DEFAULT, POINTER_CHANGE_AREA_DEFAULT,
650         pointerAreaFivePx, POINTER_CHANGE_AREA_DEFAULT,  POINTER_CHANGE_AREA_DEFAULT};
651     ASSERT_EQ(compare2, pointerChangeAreas);
652     limits.maxHeight_ = 0;
653     limits.maxWidth_ = 1;
654     sceneSession->property_->SetWindowLimits(limits);
655     manager_->UpdatePointerAreas(sceneSession, pointerChangeAreas);
656     std::vector<int32_t> compare3 = {POINTER_CHANGE_AREA_DEFAULT, POINTER_CHANGE_AREA_DEFAULT,
657         POINTER_CHANGE_AREA_DEFAULT, pointerAreaFivePx, POINTER_CHANGE_AREA_DEFAULT,
658         POINTER_CHANGE_AREA_DEFAULT, POINTER_CHANGE_AREA_DEFAULT, pointerAreaFivePx};
659     ASSERT_EQ(compare3, pointerChangeAreas);
660     limits.maxHeight_ = 1;
661     sceneSession->property_->SetWindowLimits(limits);
662     sceneSession->property_->displayId_ = 0;
663     manager_->UpdatePointerAreas(sceneSession, pointerChangeAreas);
664     std::vector<int32_t> compare4 = pointerChangeAreas = {pointerAreaSixteenPx, pointerAreaFivePx,
665         pointerAreaSixteenPx, pointerAreaFivePx, pointerAreaSixteenPx,
666         pointerAreaFivePx, pointerAreaSixteenPx, pointerAreaFivePx};
667     ASSERT_EQ(compare4, pointerChangeAreas);
668     manager_->UpdatePointerAreas(nullptr, pointerChangeAreas);
669     ASSERT_EQ(compare4, pointerChangeAreas);
670 }
671 
672 /**
673  * @tc.name: UpdatePrivacyMode
674  * @tc.desc: UpdatePrivacyMode
675  * @tc.type: FUNC
676  */
677 HWTEST_F(SceneSessionDirtyManagerTest, UpdatePrivacyMode, Function | SmallTest | Level2)
678 {
679     SessionInfo info;
680     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
681     ASSERT_NE(sceneSession, nullptr);
682     MMI::WindowInfo windowinfo;
683     auto tempProperty = sceneSession->GetSessionProperty();
684     sceneSession->property_ = nullptr;
685     manager_->UpdatePrivacyMode(sceneSession, windowinfo);
686     ASSERT_EQ(windowinfo.privacyMode, MMI::SecureFlag::DEFAULT_MODE);
687     sceneSession->property_ = tempProperty;
688     sceneSession->property_->isPrivacyMode_ = true;
689     sceneSession->property_->isSystemPrivacyMode_ = false;
690     manager_->UpdatePrivacyMode(sceneSession, windowinfo);
691     ASSERT_EQ(windowinfo.privacyMode, MMI::SecureFlag::PRIVACY_MODE);
692     sceneSession->property_->isPrivacyMode_ = false;
693     sceneSession->property_->isSystemPrivacyMode_ = true;
694     manager_->UpdatePrivacyMode(sceneSession, windowinfo);
695     ASSERT_EQ(windowinfo.privacyMode, MMI::SecureFlag::PRIVACY_MODE);
696     sceneSession->property_->isPrivacyMode_ = false;
697     sceneSession->property_->isSystemPrivacyMode_ = false;
698     manager_->UpdatePrivacyMode(sceneSession, windowinfo);
699     ASSERT_EQ(windowinfo.privacyMode, MMI::SecureFlag::DEFAULT_MODE);
700     manager_->UpdatePrivacyMode(nullptr, windowinfo);
701     ASSERT_EQ(windowinfo.privacyMode, MMI::SecureFlag::DEFAULT_MODE);
702 }
703 
704 /**
705  * @tc.name: UpdateWindowFlags
706  * @tc.desc: UpdateWindowFlags
707  * @tc.type: FUNC
708  */
709 HWTEST_F(SceneSessionDirtyManagerTest, UpdateWindowFlags, Function | SmallTest | Level2)
710 {
711     SessionInfo info;
712     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
713     ASSERT_NE(sceneSession, nullptr);
714     MMI::WindowInfo windowinfo;
715     auto screenId = 0;
716     manager_->UpdateWindowFlags(screenId, sceneSession, windowinfo);
717     ASSERT_EQ(windowinfo.flags, 0);
718     ScreenProperty screenProperty0;
719     screenProperty0.SetRotation(0.0f);
720     ScreenSessionConfig config;
721     sptr<ScreenSession> screenSession =
722         sptr<ScreenSession>::MakeSptr(config, ScreenSessionReason::CREATE_SESSION_FOR_CLIENT);
723     ASSERT_NE(screenSession, nullptr);
724     screenSession->SetTouchEnabledFromJs(true);
725     ScreenSessionManagerClient::GetInstance().OnUpdateFoldDisplayMode(FoldDisplayMode::UNKNOWN);
726     ScreenPropertyChangeReason reason = ScreenPropertyChangeReason::UNDEFINED;
727     ScreenSessionManagerClient::GetInstance().screenSessionMap_.emplace(screenId, screenSession);
728     ScreenSessionManagerClient::GetInstance().OnPropertyChanged(screenId, screenProperty0, reason);
729     manager_->UpdateWindowFlags(screenId, sceneSession, windowinfo);
730     ASSERT_EQ(windowinfo.flags, 0);
731     screenSession->SetTouchEnabledFromJs(false);
732     ScreenSessionManagerClient::GetInstance().screenSessionMap_.emplace(screenId, screenSession);
733     ScreenSessionManagerClient::GetInstance().OnPropertyChanged(screenId, screenProperty0, reason);
734     manager_->UpdateWindowFlags(screenId, sceneSession, windowinfo);
735     ASSERT_EQ(windowinfo.flags, 0);
736 }
737 
738 /**
739  * @tc.name: AddModalExtensionWindowInfo
740  * @tc.desc: AddModalExtensionWindowInfo
741  * @tc.type: FUNC
742  */
743 HWTEST_F(SceneSessionDirtyManagerTest, AddModalExtensionWindowInfo, Function | SmallTest | Level2)
744 {
745     SessionInfo info;
746     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
747     ASSERT_NE(sceneSession, nullptr);
748 
749     std::vector<MMI::WindowInfo> windowInfoList;
750     MMI::WindowInfo windowInfo;
751     windowInfoList.emplace_back(windowInfo);
752     ExtensionWindowEventInfo extensionInfo = {
753         .persistentId = 12345,
754         .pid = 1234
755     };
756     manager_->AddModalExtensionWindowInfo(windowInfoList, windowInfo, nullptr, extensionInfo);
757     EXPECT_EQ(windowInfoList.size(), 1);
758 
759     sceneSession->AddNormalModalUIExtension(extensionInfo);
760     manager_->AddModalExtensionWindowInfo(windowInfoList, windowInfo, sceneSession, extensionInfo);
761     ASSERT_EQ(windowInfoList.size(), 2);
762     EXPECT_TRUE(windowInfoList[1].defaultHotAreas.empty());
763 
764     Rect windowRect {1, 1, 7, 8};
765     extensionInfo.windowRect = windowRect;
766     sceneSession->UpdateNormalModalUIExtension(extensionInfo);
767     manager_->AddModalExtensionWindowInfo(windowInfoList, windowInfo, sceneSession, extensionInfo);
768     ASSERT_EQ(windowInfoList.size(), 3);
769     EXPECT_EQ(windowInfoList[2].defaultHotAreas.size(), 1);
770 }
771 
772 /**
773  * @tc.name: GetHostComponentWindowInfo
774  * @tc.desc: GetHostComponentWindowInfo
775  * @tc.type: FUNC
776  */
777 HWTEST_F(SceneSessionDirtyManagerTest, GetHostComponentWindowInfo, Function | SmallTest | Level2)
778 {
779     MMI::WindowInfo hostWindowinfo;
780     SecSurfaceInfo secSurfaceInfo;
781     Matrix3f transform;
782     MMI::WindowInfo ret;
783     MMI::WindowInfo windowInfo;
784     ret = manager_->GetHostComponentWindowInfo(secSurfaceInfo, hostWindowinfo, transform);
785     ASSERT_EQ(ret.id, windowInfo.id);
786 
787     SecRectInfo secRectInfo;
788     secSurfaceInfo.upperNodes.emplace_back(secRectInfo);
789     secSurfaceInfo.hostPid = 1;
790     windowInfo.pid = 1;
791     ret = manager_->GetHostComponentWindowInfo(secSurfaceInfo, hostWindowinfo, transform);
792     ASSERT_EQ(ret.pid, windowInfo.pid);
793 
794     ret = manager_->GetHostComponentWindowInfo(secSurfaceInfo, hostWindowinfo, transform);
795     ASSERT_EQ(ret.defaultHotAreas.size(), 1);
796 }
797 
798 /**
799  * @tc.name: GetSecComponentWindowInfo
800  * @tc.desc: GetSecComponentWindowInfo
801  * @tc.type: FUNC
802  */
803 HWTEST_F(SceneSessionDirtyManagerTest, GetSecComponentWindowInfo, Function | SmallTest | Level2)
804 {
805     MMI::WindowInfo hostWindowinfo;
806     SecSurfaceInfo secSurfaceInfo;
807     Matrix3f transform;
808     MMI::WindowInfo ret;
809     MMI::WindowInfo windowInfo;
810     ret = manager_->GetSecComponentWindowInfo(secSurfaceInfo, hostWindowinfo, nullptr, transform);
811     ASSERT_EQ(ret.id, windowInfo.id);
812 
813     SessionInfo info;
814     info.abilityName_ = "TestAbilityName";
815     info.bundleName_ = "TestBundleName";
816     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
817     ASSERT_NE(sceneSession, nullptr);
818 
819     ret = manager_->GetSecComponentWindowInfo(secSurfaceInfo, hostWindowinfo, sceneSession, transform);
820     ASSERT_EQ(ret.id, windowInfo.id);
821 
822     secSurfaceInfo.uiExtensionNodeId = 1;
823     sceneSession->AddUIExtSurfaceNodeId(1, 1);
824     windowInfo.privacyUIFlag = true;
825     ret = manager_->GetSecComponentWindowInfo(secSurfaceInfo, hostWindowinfo, sceneSession, transform);
826     ASSERT_EQ(ret.privacyUIFlag, windowInfo.privacyUIFlag);
827 
828     windowInfo.id = 1;
829     ret = manager_->GetSecComponentWindowInfo(secSurfaceInfo, hostWindowinfo, sceneSession, transform);
830     ASSERT_EQ(ret.id, windowInfo.id);
831 }
832 
833 /**
834  * @tc.name: GetSecSurfaceWindowinfoList
835  * @tc.desc: GetSecSurfaceWindowinfoList
836  * @tc.type: FUNC
837  */
838 HWTEST_F(SceneSessionDirtyManagerTest, GetSecSurfaceWindowinfoList, Function | SmallTest | Level2)
839 {
840     MMI::WindowInfo hostWindowinfo;
841     SecSurfaceInfo secSurfaceInfo;
842     Matrix3f transform;
843     MMI::WindowInfo windowInfo;
844     auto ret = manager_->GetSecSurfaceWindowinfoList(nullptr, hostWindowinfo, transform);
845     ASSERT_EQ(ret.size(), 0);
846 
847     std::vector<SecSurfaceInfo> secSurfaceInfoList;
848     secSurfaceInfoList.emplace_back(secSurfaceInfo);
849     manager_->secSurfaceInfoMap_.emplace(1, secSurfaceInfoList);
850     ret = manager_->GetSecSurfaceWindowinfoList(nullptr, hostWindowinfo, transform);
851     ASSERT_EQ(ret.size(), 0);
852 
853     SessionInfo info;
854     info.abilityName_ = "TestAbilityName";
855     info.bundleName_ = "TestBundleName";
856     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
857     ASSERT_NE(sceneSession, nullptr);
858     struct RSSurfaceNodeConfig config;
859     std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Create(config);
860     surfaceNode->id_ = 1;
861     sceneSession->surfaceNode_ = surfaceNode;
862     ret = manager_->GetSecSurfaceWindowinfoList(sceneSession, hostWindowinfo, transform);
863     ASSERT_EQ(ret.size(), 2);
864 
865     manager_->secSurfaceInfoMap_.emplace(0, secSurfaceInfoList);
866     ret = manager_->GetSecSurfaceWindowinfoList(sceneSession, hostWindowinfo, transform);
867     ASSERT_EQ(ret.size(), 2);
868 
869     manager_->secSurfaceInfoMap_.clear();
870     manager_->secSurfaceInfoMap_.emplace(1, secSurfaceInfoList);
871     ret = manager_->GetSecSurfaceWindowinfoList(sceneSession, hostWindowinfo, transform);
872     ASSERT_EQ(ret.size(), 2);
873 
874     sceneSession->surfaceNode_ = nullptr;
875     ret = manager_->GetSecSurfaceWindowinfoList(sceneSession, hostWindowinfo, transform);
876     ASSERT_EQ(ret.size(), 0);
877 }
878 
879 /**
880  * @tc.name: UpdateSecSurfaceInfo
881  * @tc.desc: UpdateSecSurfaceInfo
882  * @tc.type: FUNC
883  */
884 HWTEST_F(SceneSessionDirtyManagerTest, UpdateSecSurfaceInfo, Function | SmallTest | Level2)
885 {
886     std::map<uint64_t, std::vector<SecSurfaceInfo>> secSurfaceInfoMap;
887     SecRectInfo secRectInfo1;
888     SecRectInfo secRectInfo2;
889     SecSurfaceInfo secSurfaceInfo1;
890     secSurfaceInfo1.upperNodes.emplace_back(secRectInfo1);
891     SecSurfaceInfo secSurfaceInfo2;
892     secSurfaceInfo2.upperNodes.emplace_back(secRectInfo2);
893     std::vector<SecSurfaceInfo> secSurfaceInfoList1;
894     std::vector<SecSurfaceInfo> secSurfaceInfoList2;
895     secSurfaceInfoList1.emplace_back(secSurfaceInfo1);
896     secSurfaceInfoList2.emplace_back(secSurfaceInfo2);
897     manager_->secSurfaceInfoMap_.emplace(1, secSurfaceInfoList1);
898     secSurfaceInfoMap.emplace(1, secSurfaceInfoList2);
899     manager_->UpdateSecSurfaceInfo(secSurfaceInfoMap);
900     ASSERT_EQ(secSurfaceInfoMap.size(), manager_->secSurfaceInfoMap_.size());
901 
902     secSurfaceInfoMap.emplace(2, secSurfaceInfoList2);
903     manager_->UpdateSecSurfaceInfo(secSurfaceInfoMap);
904     ASSERT_EQ(secSurfaceInfoMap.size(), manager_->secSurfaceInfoMap_.size());
905 
906     secSurfaceInfoMap.clear();
907     manager_->secSurfaceInfoMap_.clear();
908     secSurfaceInfoList1.clear();
909     secSurfaceInfoList2.clear();
910     secSurfaceInfo1.uiExtensionRectInfo.scale[0] = 1;
911     secSurfaceInfoList1.emplace_back(secSurfaceInfo1);
912     secSurfaceInfoList2.emplace_back(secSurfaceInfo2);
913     secSurfaceInfoMap.emplace(1, secSurfaceInfoList1);
914     manager_->secSurfaceInfoMap_.emplace(1, secSurfaceInfoList2);
915     manager_->UpdateSecSurfaceInfo(secSurfaceInfoMap);
916     ASSERT_EQ(secSurfaceInfoMap.size(), manager_->secSurfaceInfoMap_.size());
917 }
918 
919 /**
920  * @tc.name: GetLastConstrainedModalUIExtInfo
921  * @tc.desc: GetLastConstrainedModalUIExtInfo
922  * @tc.type: FUNC
923  */
924 HWTEST_F(SceneSessionDirtyManagerTest, GetLastConstrainedModalUIExtInfo, Function | SmallTest | Level2)
925 {
926     SecSurfaceInfo constrainedModalUIExtInfo;
927     bool ret = manager_->GetLastConstrainedModalUIExtInfo(nullptr, constrainedModalUIExtInfo);
928     ASSERT_EQ(ret, false);
929 
930     std::vector<SecSurfaceInfo> surfaceInfoList;
931     SecSurfaceInfo secSurfaceInfo;
932     manager_->constrainedModalUIExtInfoMap_.clear();
933     manager_->constrainedModalUIExtInfoMap_[0] = surfaceInfoList;
934     SessionInfo info;
935     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
936     ret = manager_->GetLastConstrainedModalUIExtInfo(sceneSession, constrainedModalUIExtInfo);
937     ASSERT_EQ(ret, false);
938 
939     struct RSSurfaceNodeConfig config;
940     std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Create(config);
941     surfaceNode->SetId(1);
942     sceneSession->SetSurfaceNode(surfaceNode);
943     ret = manager_->GetLastConstrainedModalUIExtInfo(sceneSession, constrainedModalUIExtInfo);
944     ASSERT_EQ(ret, false);
945 
946     sceneSession->GetSurfaceNode()->SetId(0);
947     ret = manager_->GetLastConstrainedModalUIExtInfo(sceneSession, constrainedModalUIExtInfo);
948     ASSERT_EQ(ret, false);
949 
950     manager_->constrainedModalUIExtInfoMap_[0].emplace_back(secSurfaceInfo);
951     ret = manager_->GetLastConstrainedModalUIExtInfo(sceneSession, constrainedModalUIExtInfo);
952     ASSERT_EQ(ret, true);
953     manager_->constrainedModalUIExtInfoMap_.clear();
954 }
955 
956 /**
957  * @tc.name: GetModalUIExtensionInfo
958  * @tc.desc: GetModalUIExtensionInfo
959  * @tc.type: FUNC
960  */
961 HWTEST_F(SceneSessionDirtyManagerTest, GetModalUIExtensionInfo, Function | SmallTest | Level2)
962 {
963     std::vector<MMI::WindowInfo> windowInfoList;
964     MMI::WindowInfo windowInfo;
965 
966     // normal modal UIExt
967     SessionInfo info;
968     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
969     int len = windowInfoList.size();
970     manager_->GetModalUIExtensionInfo(windowInfoList, sceneSession, windowInfo);
971     ASSERT_EQ(len, windowInfoList.size());
972 
973     ExtensionWindowEventInfo extensionInfo;
974     extensionInfo.persistentId = 12345;
975     extensionInfo.pid = 1234;
976     extensionInfo.windowRect = { 1, 2, 3, 4 };
977     sceneSession->AddNormalModalUIExtension(extensionInfo);
978     manager_->GetModalUIExtensionInfo(windowInfoList, sceneSession, windowInfo);
979     ASSERT_EQ(len + 1, windowInfoList.size());
980 
981     // constrained modal UIExt
982     struct RSSurfaceNodeConfig config;
983     std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Create(config);
984     surfaceNode->SetId(0);
985     sceneSession->SetSurfaceNode(surfaceNode);
986     std::vector<SecSurfaceInfo> surfaceInfoList;
987     SecSurfaceInfo secSurfaceInfo;
988     manager_->constrainedModalUIExtInfoMap_.clear();
989     manager_->constrainedModalUIExtInfoMap_[0] = surfaceInfoList;
990     manager_->constrainedModalUIExtInfoMap_[0].emplace_back(secSurfaceInfo);
991     manager_->GetModalUIExtensionInfo(windowInfoList, sceneSession, windowInfo);
992     ASSERT_EQ(len + 2, windowInfoList.size());
993     manager_->constrainedModalUIExtInfoMap_.clear();
994 }
995 
996 /**
997  * @tc.name: ResetFlushWindowInfoTask
998  * @tc.desc: ResetFlushWindowInfoTask
999  * @tc.type: FUNC
1000  */
1001 HWTEST_F(SceneSessionDirtyManagerTest, ResetFlushWindowInfoTask, Function | SmallTest | Level2)
1002 {
1003     auto preFlushWindowInfoCallback = manager_->flushWindowInfoCallback_;
1004     manager_->flushWindowInfoCallback_ = nullptr;
1005     manager_->ResetFlushWindowInfoTask();
1006     EXPECT_TRUE(manager_->hasPostTask_.load());
1007     manager_->flushWindowInfoCallback_ = preFlushWindowInfoCallback;
1008 }
1009 
1010 /**
1011  * @tc.name: ResetFlushWindowInfoTask1
1012  * @tc.desc: ResetFlushWindowInfoTask1
1013  * @tc.type: FUNC
1014  */
1015 HWTEST_F(SceneSessionDirtyManagerTest, ResetFlushWindowInfoTask1, Function | SmallTest | Level2)
1016 {
1017     manager_->ResetFlushWindowInfoTask();
1018     EXPECT_TRUE(manager_->hasPostTask_.load());
1019 }
1020 
1021 /**
1022  * @tc.name: DumpRect
1023  * @tc.desc: DumpRect
1024  * @tc.type: FUNC
1025  */
1026 HWTEST_F(SceneSessionDirtyManagerTest, DumpRect, Function | SmallTest | Level2)
1027 {
1028     std::vector<MMI::Rect> rects(0);
1029     for (int i = 0; i < 2 ; i++) {
1030         MMI::Rect rect = {
1031             .x = i * 10,
1032             .y = i * 10,
1033             .width = i * 10,
1034             .height = i * 10
1035         };
1036         rects.emplace_back(rect);
1037     }
1038     std::string ret = DumpRect(rects);
1039     std::string checkStr = " hot : [ 0 , 0 , 0 , 0] hot : [ 10 , 10 , 10 , 10]";
1040     ASSERT_EQ(ret, checkStr);
1041 }
1042 
1043 /**
1044  * To test UpdatePointerAreas with different drag activated settings
1045  * To expect pointerChangeAreas changes when dragActivated and dragEnable both are true
1046  *
1047  * @tc.name: CheckDragActivatedInUpdatePointerAreas
1048  * @tc.desc: CheckDragActivatedInUpdatePointerAreas
1049  * @tc.type: FUNC
1050  */
1051 HWTEST_F(SceneSessionDirtyManagerTest, CheckDragActivatedInUpdatePointerAreas, Function | SmallTest | Level2)
1052 {
1053     std::vector<int32_t> pointerChangeAreas;
1054     SessionInfo info;
1055     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1056     sceneSession->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1057 
1058     sceneSession->property_->SetDragEnabled(true);
1059     sceneSession->SetDragActivated(false);
1060     manager_->UpdatePointerAreas(sceneSession, pointerChangeAreas);
1061     ASSERT_EQ(0, pointerChangeAreas.size());
1062 
1063     sceneSession->property_->SetDragEnabled(false);
1064     sceneSession->SetDragActivated(true);
1065     manager_->UpdatePointerAreas(sceneSession, pointerChangeAreas);
1066     ASSERT_EQ(0, pointerChangeAreas.size());
1067 
1068     sceneSession->property_->SetDragEnabled(false);
1069     sceneSession->SetDragActivated(false);
1070     manager_->UpdatePointerAreas(sceneSession, pointerChangeAreas);
1071     ASSERT_EQ(0, pointerChangeAreas.size());
1072 
1073     sceneSession->property_->SetDragEnabled(true);
1074     sceneSession->SetDragActivated(true);
1075     float vpr = 1.5f;
1076     sceneSession->property_->SetDisplayId(100);
1077     int32_t pointerAreaFivePx = static_cast<int32_t>(POINTER_CHANGE_AREA_FIVE * vpr);
1078     WindowLimits limits;
1079     limits.maxHeight_ = 1;
1080     limits.minHeight_ = 0;
1081     limits.maxWidth_ = 0;
1082     limits.minWidth_ = 0;
1083     sceneSession->property_->SetWindowLimits(limits);
1084     manager_->UpdatePointerAreas(sceneSession, pointerChangeAreas);
1085     std::vector<int32_t> compare = {POINTER_CHANGE_AREA_DEFAULT, pointerAreaFivePx,
1086         POINTER_CHANGE_AREA_DEFAULT, POINTER_CHANGE_AREA_DEFAULT, POINTER_CHANGE_AREA_DEFAULT,
1087         pointerAreaFivePx, POINTER_CHANGE_AREA_DEFAULT,  POINTER_CHANGE_AREA_DEFAULT};
1088     ASSERT_EQ(compare, pointerChangeAreas);
1089 }
1090 
1091 /**
1092  * @tc.name: GetSingleHandData
1093  * @tc.desc: get session data in single hand mode
1094  * @tc.type: FUNC
1095  */
1096 HWTEST_F(SceneSessionDirtyManagerTest, GetSingleHandData, Function | SmallTest | Level2)
1097 {
1098     SingleHandData testSingleHandData;
1099     SessionInfo mainWindowInfo;
1100     mainWindowInfo.abilityName_ = "TestMainWithType";
1101     mainWindowInfo.bundleName_ = "TestMainWithType";
1102     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(mainWindowInfo, nullptr);
1103     sceneSession->property_->SetDisplayId(2000);
1104     SingleHandData res = manager_->GetSingleHandData(sceneSession);
1105     ASSERT_EQ(testSingleHandData.singleHandY, res.singleHandY);
1106     sceneSession->property_->SetDisplayId(0);
1107     res = manager_->GetSingleHandData(sceneSession);
1108     ASSERT_EQ(testSingleHandData.singleHandY, res.singleHandY);
1109 }
1110 } // namespace
1111 } // namespace Rosen
1112 } // namespace OHOS
1113