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 #include "transaction/rs_uiextension_data.h"
16 #include "input_manager.h"
17 #include "session_manager/include/scene_session_dirty_manager.h"
18 #include <gtest/gtest.h>
19 #include <parameter.h>
20 #include <parameters.h>
21 #include "screen_session_manager/include/screen_session_manager_client.h"
22 #include "session/host/include/scene_session.h"
23 #include "session/host/include/sub_session.h"
24 #include "session_manager/include/scene_session_manager.h"
25 #include "transaction/rs_uiextension_data.h"
26 
27 
28 using namespace testing;
29 using namespace testing::ext;
30 
31 namespace OHOS {
32 namespace Rosen {
33 constexpr int POINTER_CHANGE_AREA_SIXTEEN = 16;
34 constexpr int POINTER_CHANGE_AREA_DEFAULT = 0;
35 constexpr int POINTER_CHANGE_AREA_FIVE = 5;
36 static int32_t g_screenRotationOffset = system::GetIntParameter<int32_t>("const.fold.screen_rotation.offset", 0);
37 class SceneSessionDirtyManagerTest : public testing::Test {
38 public:
39     static void SetUpTestCase();
40     static void TearDownTestCase();
41     void SetUp() override;
42     void TearDown() override;
43     static constexpr uint32_t WAIT_SYNC_IN_NS = 500000;
44 };
45 SceneSessionDirtyManager *manager_;
46 SceneSessionManager *ssm_;
SetUpTestCase()47 void SceneSessionDirtyManagerTest::SetUpTestCase()
48 {
49     ssm_ = &SceneSessionManager::GetInstance();
50     ssm_->sceneSessionMap_.clear();
51 }
52 
TearDownTestCase()53 void SceneSessionDirtyManagerTest::TearDownTestCase()
54 {
55     ssm_ = nullptr;
56 }
57 
SetUp()58 void SceneSessionDirtyManagerTest::SetUp()
59 {
60     manager_ = new SceneSessionDirtyManager();
61 }
62 
TearDown()63 void SceneSessionDirtyManagerTest::TearDown()
64 {
65     usleep(WAIT_SYNC_IN_NS);
66     delete manager_;
67     manager_ = nullptr;
68 }
69 namespace {
70 
71 /**
72  * @tc.name: NotifyWindowInfoChange
73  * @tc.desc: NotifyWindowInfoChange
74  * @tc.type: FUNC
75  */
76 HWTEST_F(SceneSessionDirtyManagerTest, NotifyWindowInfoChange, Function | SmallTest | Level2)
77 {
78     int ret = 0;
79     manager_->NotifyWindowInfoChange(nullptr, WindowUpdateType::WINDOW_UPDATE_ADDED, true);
80     SessionInfo info;
81     info.abilityName_ = "TestAbilityName";
82     info.bundleName_ = "TestBundleName";
83     sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
84     if (sceneSession == nullptr) {
85         return;
86     }
87     manager_->NotifyWindowInfoChange(sceneSession, WindowUpdateType::WINDOW_UPDATE_ADDED, true);
88     manager_->NotifyWindowInfoChange(sceneSession, WindowUpdateType::WINDOW_UPDATE_REMOVED, true);
89     manager_->NotifyWindowInfoChange(sceneSession, WindowUpdateType::WINDOW_UPDATE_ACTIVE, true);
90     manager_->NotifyWindowInfoChange(sceneSession, WindowUpdateType::WINDOW_UPDATE_FOCUSED, true);
91     ASSERT_EQ(ret, 0);
92 }
93 
94 /**
95  * @tc.name: GetFullWindowInfoList
96  * @tc.desc: GetFullWindowInfoList
97  * @tc.type: FUNC
98  */
99 HWTEST_F(SceneSessionDirtyManagerTest, GetFullWindowInfoList, Function | SmallTest | Level2)
100 {
101     int ret = 0;
102     SessionInfo info;
103     info.abilityName_ = "TestAbilityName";
104     info.bundleName_ = "TestBundleName";
105     {
106         sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
107         if (sceneSession == nullptr) {
108             return;
109         }
110         ssm_->sceneSessionMap_.insert({sceneSession->GetPersistentId(), sceneSession});
111     }
112     {
113         ssm_->sceneSessionMap_.insert({111, nullptr});
114     }
115     {
116         sptr<SceneSession> sceneSessionDialog1 = new (std::nothrow) SceneSession(info, nullptr);
117         if (sceneSessionDialog1 == nullptr) {
118             return;
119         }
120         sptr<WindowSessionProperty> propertyDialog1 = sceneSessionDialog1->GetSessionProperty();
121         propertyDialog1->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
122         ssm_->sceneSessionMap_.insert({sceneSessionDialog1->GetPersistentId(), sceneSessionDialog1});
123     }
124     {
125         sptr<SceneSession> sceneSessionModal1 = new (std::nothrow) SceneSession(info, nullptr);
126         if (sceneSessionModal1 == nullptr) {
127             return;
128         }
129         sptr<WindowSessionProperty> propertyModal1 = sceneSessionModal1->GetSessionProperty();
130         propertyModal1->SetWindowFlags(static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_IS_MODAL));
131         ssm_->sceneSessionMap_.insert({sceneSessionModal1->GetPersistentId(), sceneSessionModal1});
132     }
133     manager_->GetFullWindowInfoList();
134     ASSERT_EQ(ret, 0);
135 }
136 
137 /**
138  * @tc.name: IsFilterSession
139  * @tc.desc: IsFilterSession
140  * @tc.type: FUNC
141  */
142 HWTEST_F(SceneSessionDirtyManagerTest, IsFilterSession, Function | SmallTest | Level2)
143 {
144     int ret = 0;
145     manager_->IsFilterSession(nullptr);
146     SessionInfo info;
147     info.abilityName_ = "test1";
148     info.bundleName_ = "test2";
149     info.sceneType_ = SceneType::INPUT_SCENE;
150     sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
151     if (sceneSession == nullptr) {
152         return;
153     }
154     sptr<WindowSessionProperty> property = sceneSession->GetSessionProperty();
155     info.sceneType_ = SceneType::INPUT_SCENE;
156     manager_->IsFilterSession(sceneSession);
157     info.sceneType_ = SceneType::WINDOW_SCENE;
158     info.isSystem_ = false;
159     sceneSession->isVisible_ = false;
160     sceneSession->isSystemActive_ = false;
161     manager_->IsFilterSession(sceneSession);
162     info.isSystem_ = true;
163     manager_->IsFilterSession(sceneSession);
164     sceneSession->isVisible_ = true;
165     manager_->IsFilterSession(sceneSession);
166     sceneSession->isSystemActive_ = true;
167     manager_->IsFilterSession(sceneSession);
168     info.isSystem_ = true;
169     sceneSession->isVisible_ = true;
170     sceneSession->SetSystemActive(true);
171     manager_->IsFilterSession(sceneSession);
172     info.isSystem_ = false;
173     sceneSession->isVisible_ = false;
174     sceneSession->SetSystemActive(false);
175     manager_->IsFilterSession(sceneSession);
176     sceneSession->isVisible_ = false;
177     manager_->IsFilterSession(sceneSession);
178     ASSERT_EQ(ret, 0);
179 }
180 
181 /**
182  * @tc.name: GetWindowInfo
183  * @tc.desc: GetWindowInfo
184  * @tc.type: FUNC
185  */
186 HWTEST_F(SceneSessionDirtyManagerTest, GetWindowInfo, Function | SmallTest | Level2)
187 {
188     int ret = 0;
189     manager_->GetWindowInfo(nullptr, SceneSessionDirtyManager::WindowAction::WINDOW_ADD);
190     SessionInfo info;
191     info.abilityName_ = "111";
192     info.bundleName_ = "111";
193     sptr<SceneSession> session = new (std::nothrow) SceneSession(info, nullptr);
194     if (session == nullptr) {
195         return;
196     }
197     manager_->GetWindowInfo(session, SceneSessionDirtyManager::WindowAction::WINDOW_ADD);
198     session = new (std::nothrow) SceneSession(info, nullptr);
199     if (session == nullptr) {
200         return;
201     }
202     sptr<WindowSessionProperty> windowSessionProperty = session->GetSessionProperty();
203     manager_->GetWindowInfo(session, SceneSessionDirtyManager::WindowAction::WINDOW_ADD);
204     windowSessionProperty->SetWindowMode(Rosen::WindowMode::WINDOW_MODE_FLOATING);
205     manager_->GetWindowInfo(session, SceneSessionDirtyManager::WindowAction::WINDOW_ADD);
206     windowSessionProperty->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
207     manager_->GetWindowInfo(session, SceneSessionDirtyManager::WindowAction::WINDOW_ADD);
208     windowSessionProperty->SetMaximizeMode(Rosen::MaximizeMode::MODE_AVOID_SYSTEM_BAR);
209     manager_->GetWindowInfo(session, SceneSessionDirtyManager::WindowAction::WINDOW_ADD);
210     info.isSetPointerAreas_ = true;
211     manager_->GetWindowInfo(session, SceneSessionDirtyManager::WindowAction::WINDOW_ADD);
212     windowSessionProperty->SetWindowFlags(static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_HANDWRITING));
213     manager_->GetWindowInfo(session, SceneSessionDirtyManager::WindowAction::WINDOW_ADD);
214     windowSessionProperty->SetWindowFlags(static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_IS_MODAL));
215     manager_->GetWindowInfo(session, SceneSessionDirtyManager::WindowAction::WINDOW_ADD);
216     session->SetSessionProperty(nullptr);
217     manager_->GetWindowInfo(session, SceneSessionDirtyManager::WindowAction::WINDOW_ADD);
218     ASSERT_EQ(ret, 0);
219 }
220 
221 /**
222  * @tc.name: CalNotRotateTransform
223  * @tc.desc: CalNotRotateTransform
224  * @tc.type: FUNC
225  */
226 HWTEST_F(SceneSessionDirtyManagerTest, CalNotRotateTransform, Function | SmallTest | Level2)
227 {
228     int ret = 0;
229     SessionInfo sessionInfo;
230     sessionInfo.bundleName_ = "CalNotRotateTransform";
231     sessionInfo.moduleName_ = "sessionInfo";
232     Matrix3f transform;
233     sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(sessionInfo, nullptr);
234     ASSERT_NE(sceneSession, nullptr);
235     manager_->CalNotRotateTransform(nullptr, transform);
236     auto screenId = 0;
237     sceneSession->GetSessionProperty()->SetDisplayId(screenId);
238     manager_->CalNotRotateTransform(sceneSession, transform);
239     ScreenProperty screenProperty0;
240     screenProperty0.SetRotation(0.0f);
241     ScreenSessionConfig config;
242     sptr<ScreenSession> screenSession = new ScreenSession(config, ScreenSessionReason::CREATE_SESSION_FOR_CLIENT);
243     ASSERT_NE(screenSession, nullptr);
244     Rosen::ScreenSessionManagerClient::GetInstance().OnUpdateFoldDisplayMode(FoldDisplayMode::UNKNOWN);
245     ScreenPropertyChangeReason reason = ScreenPropertyChangeReason::UNDEFINED;
246     Rosen::ScreenSessionManagerClient::GetInstance().screenSessionMap_.emplace(screenId, screenSession);
247     Rosen::ScreenSessionManagerClient::GetInstance().OnPropertyChanged(screenId, screenProperty0, reason);
248     manager_->CalNotRotateTransform(sceneSession, transform);
249 
250     screenProperty0.SetRotation(90.0f);
251     Rosen::ScreenSessionManagerClient::GetInstance().OnPropertyChanged(screenId, screenProperty0, reason);
252     manager_->CalNotRotateTransform(sceneSession, transform);
253 
254     screenProperty0.SetRotation(180.0f);
255     Rosen::ScreenSessionManagerClient::GetInstance().OnPropertyChanged(screenId, screenProperty0, reason);
256     manager_->CalNotRotateTransform(sceneSession, transform);
257 
258     screenProperty0.SetRotation(270.0f);
259     Rosen::ScreenSessionManagerClient::GetInstance().OnPropertyChanged(screenId, screenProperty0, reason);
260     manager_->CalNotRotateTransform(sceneSession, transform);
261     ASSERT_EQ(ret, 0);
262 
263     sptr<SceneSession> sceneSessionWithNullProperty = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
264     sceneSessionWithNullProperty->SetSessionProperty(nullptr);
265     manager_->CalNotRotateTransform(sceneSessionWithNullProperty, transform);
266     ASSERT_EQ(ret, 0);
267 }
268 
269 /**
270  * @tc.name: CalTransform
271  * @tc.desc: CalTransform
272  * @tc.type: FUNC
273  */
274 HWTEST_F(SceneSessionDirtyManagerTest, CalTransform, Function | SmallTest | Level2)
275 {
276     int ret = 0;
277     SessionInfo sessionInfo;
278     sessionInfo.bundleName_ = "CalTransform";
279     sessionInfo.moduleName_ = "CalTransform";
280     sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(sessionInfo, nullptr);
281     if (sceneSession == nullptr) {
282         return;
283     }
284     Matrix3f transform;
285     manager_->CalTransform(nullptr, transform);
286     sessionInfo.isRotable_ = true;
287     manager_->CalTransform(sceneSession, transform);
288     sessionInfo.isSystem_ = true;
289     manager_->CalTransform(sceneSession, transform);
290     sessionInfo.isRotable_ = false;
291     manager_->CalTransform(sceneSession, transform);
292     sessionInfo.isRotable_ = true;
293     sessionInfo.isSystem_ = false;
294     manager_->CalTransform(sceneSession, transform);
295     sessionInfo.isSystem_ = true;
296     auto preScreenSessionManager = Rosen::ScreenSessionManagerClient::GetInstance().screenSessionManager_;
297     Rosen::ScreenSessionManagerClient::GetInstance().screenSessionManager_ = nullptr;
298     manager_->CalTransform(sceneSession, transform);
299     Rosen::ScreenSessionManagerClient::GetInstance().screenSessionManager_ = preScreenSessionManager;
300     manager_->CalTransform(sceneSession, transform);
301     ASSERT_EQ(ret, 0);
302 }
303 
304 /**
305  * @tc.name: UpdateHotAreas
306  * @tc.desc: UpdateHotAreas
307  * @tc.type: FUNC
308  */
309 HWTEST_F(SceneSessionDirtyManagerTest, UpdateHotAreas, Function | SmallTest | Level2)
310 {
311     int ret = 0;
312     std::vector<MMI::Rect> empty(0);
313     manager_->UpdateHotAreas(nullptr, empty, empty);
314     SessionInfo sessionInfo;
315     sessionInfo.bundleName_ = "UpdateHotAreas";
316     sessionInfo.moduleName_ = "UpdateHotAreas";
317     sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(sessionInfo, nullptr);
318     if (sceneSession == nullptr) {
319         return;
320     }
321     std::vector<MMI::Rect> touchHotAreas(0);
322     std::vector<MMI::Rect> pointerHotAreas(0);
323     std::vector<OHOS::Rosen::Rect> touchHotAreasInSceneSession(0);
324     sceneSession->GetSessionProperty()->SetTouchHotAreas(touchHotAreasInSceneSession);
325     sceneSession->persistentId_ = 1;
326     for (int i = 0; i < 2 ; i++) {
327         OHOS::Rosen::Rect area;
328         area.posX_ = i * 10;
329         area.posY_ = i * 10;
330         area.width_ = 10;
331         area.height_ = 10;
332         touchHotAreasInSceneSession.emplace_back(area);
333     }
334     sceneSession->GetSessionProperty()->SetTouchHotAreas(touchHotAreasInSceneSession);
335     manager_->UpdateHotAreas(sceneSession, touchHotAreas, pointerHotAreas);
336     for (int i = 2; i < 10 ; i++) {
337         OHOS::Rosen::Rect area;
338         area.posX_ = i * 10;
339         area.posY_ = i * 10;
340         area.width_ = 10;
341         area.height_ = 10;
342         touchHotAreasInSceneSession.emplace_back(area);
343     }
344     sceneSession->GetSessionProperty()->SetTouchHotAreas(touchHotAreasInSceneSession);
345     manager_->UpdateHotAreas(sceneSession, touchHotAreas, pointerHotAreas);
346     std::vector<OHOS::Rosen::Rect> fullSceneSession(static_cast<uint32_t>(MMI::WindowInfo::MAX_HOTAREA_COUNT));
347     sceneSession->GetSessionProperty()->SetTouchHotAreas(fullSceneSession);
348     manager_->UpdateHotAreas(sceneSession, touchHotAreas, pointerHotAreas);
349     ASSERT_EQ(ret, 0);
350 }
351 
352 /**
353  * @tc.name: UpdateDefaultHotAreas
354  * @tc.desc: UpdateDefaultHotAreas
355  * @tc.type: FUNC
356  */
357 HWTEST_F(SceneSessionDirtyManagerTest, UpdateDefaultHotAreas, Function | SmallTest | Level2)
358 {
359     int ret = 0;
360     std::vector<MMI::Rect> empty(0);
361     manager_->UpdateDefaultHotAreas(nullptr, empty, empty);
362     SessionInfo sessionInfo;
363     sessionInfo.bundleName_ = "UpdateDefaultHotAreas";
364     sessionInfo.moduleName_ = "UpdateDefaultHotAreas";
365     sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(sessionInfo, nullptr);
366     if (sceneSession == nullptr) {
367         return;
368     }
369     WSRect rect = {0, 0, 320, 240};
370     sceneSession->SetSessionRect(rect);
371     manager_->UpdateDefaultHotAreas(sceneSession, empty, empty);
372     sceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
373     manager_->UpdateDefaultHotAreas(sceneSession, empty, empty);
374     sceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_PIP);
375     manager_->UpdateDefaultHotAreas(sceneSession, empty, empty);
376     sceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_SCENE_BOARD);
377     manager_->UpdateDefaultHotAreas(sceneSession, empty, empty);
378     sceneSession->SetSessionProperty(nullptr);
379     manager_->UpdateDefaultHotAreas(sceneSession, empty, empty);
380     ASSERT_EQ(ret, 0);
381 }
382 
383 /**
384  * @tc.name: ConvertDegreeToMMIRotation
385  * @tc.desc: ConvertDegreeToMMIRotation
386  * @tc.type: FUNC
387  */
388 HWTEST_F(SceneSessionDirtyManagerTest, ConvertDegreeToMMIRotation, Function | SmallTest | Level2)
389 {
390     MMI::Direction dirction = MMI::DIRECTION0;
391     dirction = ConvertDegreeToMMIRotation(0.0, MMI::DisplayMode::UNKNOWN);
392     ASSERT_EQ(dirction, MMI::DIRECTION0);
393     dirction = ConvertDegreeToMMIRotation(90.0, MMI::DisplayMode::UNKNOWN);
394     ASSERT_EQ(dirction, MMI::DIRECTION90);
395     dirction = ConvertDegreeToMMIRotation(180.0, MMI::DisplayMode::UNKNOWN);
396     ASSERT_EQ(dirction, MMI::DIRECTION180);
397     dirction = ConvertDegreeToMMIRotation(270.0, MMI::DisplayMode::UNKNOWN);
398     ASSERT_EQ(dirction, MMI::DIRECTION270);
399     if (g_screenRotationOffset != 0) {
400         dirction = ConvertDegreeToMMIRotation(0.0, MMI::DisplayMode::FULL);
401         ASSERT_EQ(dirction, MMI::DIRECTION90);
402         dirction = ConvertDegreeToMMIRotation(90.0, MMI::DisplayMode::FULL);
403         ASSERT_EQ(dirction, MMI::DIRECTION180);
404         dirction = ConvertDegreeToMMIRotation(180.0, MMI::DisplayMode::FULL);
405         ASSERT_EQ(dirction, MMI::DIRECTION270);
406         dirction = ConvertDegreeToMMIRotation(270.0, MMI::DisplayMode::FULL);
407         ASSERT_EQ(dirction, MMI::DIRECTION0);
408         dirction = ConvertDegreeToMMIRotation(30.0, MMI::DisplayMode::FULL);
409         ASSERT_EQ(dirction, MMI::DIRECTION90);
410     }
411     dirction = ConvertDegreeToMMIRotation(30.0, MMI::DisplayMode::UNKNOWN);
412     ASSERT_EQ(dirction, MMI::DIRECTION0);
413 }
414 
415 /**
416  * @tc.name: GetDialogSessionMap
417  * @tc.desc: GetDialogSessionMap
418  * @tc.type: FUNC
419  */
420 HWTEST_F(SceneSessionDirtyManagerTest, GetDialogSessionMap, Function | SmallTest | Level2)
421 {
422     std::map<int32_t, sptr<SceneSession>> sessionMap;
423     SessionInfo info;
424     info.abilityName_ = "TestAbilityName";
425     info.bundleName_ = "TestBundleName";
426     sessionMap.emplace(1, nullptr);
427     auto sessionList = manager_->GetDialogSessionMap(sessionMap);
428     ASSERT_EQ(0, sessionList.size());
429     sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
430     if (!sceneSession) {
431         GTEST_LOG_(INFO) << "sceneSession is nullptr";
432         return;
433     }
434     sessionMap.emplace(2, sceneSession);
435     auto sessionList2 = manager_->GetDialogSessionMap(sessionMap);
436     ASSERT_EQ(0, sessionList2.size());
437     sptr<WindowSessionProperty> property = new WindowSessionProperty();
438     if (!property) {
439         GTEST_LOG_(INFO) << "property is nullptr";
440         return;
441     }
442     property->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
443     sceneSession->SetSessionProperty(property);
444     sptr<Session> session = new (std::nothrow) Session(info);
445     if (!session) {
446         GTEST_LOG_(INFO) << "session is nullptr";
447         return;
448     }
449     sceneSession->SetParentSession(session);
450     auto sessionList3 = manager_->GetDialogSessionMap(sessionMap);
451     ASSERT_EQ(1, sessionList3.size());
452     sceneSession->SetForceHideState(ForceHideState::NOT_HIDDEN);
453     auto sessionList4 = manager_->GetDialogSessionMap(sessionMap);
454     ASSERT_EQ(1, sessionList4.size());
455     sceneSession->SetForceHideState(ForceHideState::HIDDEN_WHEN_FOCUSED);
456     sceneSession->SetSessionProperty(nullptr);
457     sceneSession->SetParentSession(nullptr);
458     auto sessionList5 = manager_->GetDialogSessionMap(sessionMap);
459     ASSERT_EQ(0, sessionList5.size());
460 }
461 
462 /**
463  * @tc.name: GetDialogSessionMap02
464  * @tc.desc: GetDialogSessionMap
465  * @tc.type: FUNC
466  */
467 HWTEST_F(SceneSessionDirtyManagerTest, GetDialogSessionMap02, Function | SmallTest | Level2)
468 {
469     SessionInfo info;
470     info.abilityName_ = "TestAbilityName";
471     info.bundleName_ = "TestBundleName";
472     sptr<SubSession> sceneSession = sptr<SubSession>::MakeSptr(info, nullptr);
473     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
474     property->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
475     property->AddWindowFlag(WindowFlag::WINDOW_FLAG_IS_MODAL);
476     property->AddWindowFlag(WindowFlag::WINDOW_FLAG_IS_APPLICATION_MODAL);
477     sceneSession->SetSessionProperty(property);
478     sptr<Session> session = sptr<Session>::MakeSptr(info);
479     sceneSession->SetParentSession(session);
480     std::map<int32_t, sptr<SceneSession>> sessionMap;
481     sessionMap.emplace(1, sceneSession);
482     auto sessionList = manager_->GetDialogSessionMap(sessionMap);
483     ASSERT_EQ(2, sessionList.size());
484 }
485 
486 /**
487  * @tc.name: UpdatePointerAreas
488  * @tc.desc: UpdatePointerAreas
489  * @tc.type: FUNC
490  */
491 HWTEST_F(SceneSessionDirtyManagerTest, UpdatePointerAreas, Function | SmallTest | Level2)
492 {
493     std::vector<int32_t> pointerChangeAreas;
494     SessionInfo info;
495     sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
496     sptr<WindowSessionProperty> property = new WindowSessionProperty();
497     if (!sceneSession || !property) {
498         return;
499     }
500     property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
501     property->SetDragEnabled(false);
502     sceneSession->SetSessionProperty(property);
503     manager_->UpdatePointerAreas(sceneSession, pointerChangeAreas);
504     ASSERT_EQ(0, pointerChangeAreas.size());
505     property->SetDragEnabled(true);
506     float vpr = 1.5f;
507     property->SetDisplayId(100);
508     int32_t pointerAreaFivePx = static_cast<int32_t>(POINTER_CHANGE_AREA_FIVE * vpr);
509     int32_t pointerAreaSixteenPx = static_cast<int32_t>(POINTER_CHANGE_AREA_SIXTEEN * vpr);
510     WindowLimits limits;
511     limits.maxHeight_ = 1;
512     limits.minHeight_ = 0;
513     limits.maxWidth_ = 0;
514     limits.minWidth_ = 0;
515     property->SetWindowLimits(limits);
516     manager_->UpdatePointerAreas(sceneSession, pointerChangeAreas);
517     std::vector<int32_t> compare2 = {POINTER_CHANGE_AREA_DEFAULT, pointerAreaFivePx,
518         POINTER_CHANGE_AREA_DEFAULT, POINTER_CHANGE_AREA_DEFAULT, POINTER_CHANGE_AREA_DEFAULT,
519         pointerAreaFivePx, POINTER_CHANGE_AREA_DEFAULT,  POINTER_CHANGE_AREA_DEFAULT};
520     ASSERT_EQ(compare2, pointerChangeAreas);
521     limits.maxHeight_ = 0;
522     limits.maxWidth_ = 1;
523     property->SetWindowLimits(limits);
524     manager_->UpdatePointerAreas(sceneSession, pointerChangeAreas);
525     std::vector<int32_t> compare3 = {POINTER_CHANGE_AREA_DEFAULT, POINTER_CHANGE_AREA_DEFAULT,
526         POINTER_CHANGE_AREA_DEFAULT, pointerAreaFivePx, POINTER_CHANGE_AREA_DEFAULT,
527         POINTER_CHANGE_AREA_DEFAULT, POINTER_CHANGE_AREA_DEFAULT, pointerAreaFivePx};
528     ASSERT_EQ(compare3, pointerChangeAreas);
529     limits.maxHeight_ = 1;
530     property->SetWindowLimits(limits);
531     manager_->UpdatePointerAreas(sceneSession, pointerChangeAreas);
532     std::vector<int32_t> compare4 = pointerChangeAreas = {pointerAreaSixteenPx, pointerAreaFivePx,
533         pointerAreaSixteenPx, pointerAreaFivePx, pointerAreaSixteenPx,
534         pointerAreaFivePx, pointerAreaSixteenPx, pointerAreaFivePx};
535     ASSERT_EQ(compare4, pointerChangeAreas);
536     manager_->UpdatePointerAreas(nullptr, pointerChangeAreas);
537     sceneSession->SetSessionProperty(nullptr);
538     manager_->UpdatePointerAreas(nullptr, pointerChangeAreas);
539 }
540 
541 /**
542  * @tc.name: UpdatePrivacyMode
543  * @tc.desc: UpdatePrivacyMode
544  * @tc.type: FUNC
545  */
546 HWTEST_F(SceneSessionDirtyManagerTest, UpdatePrivacyMode, Function | SmallTest | Level2)
547 {
548     SessionInfo info;
549     sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
550     ASSERT_NE(sceneSession, nullptr);
551     MMI::WindowInfo windowinfo;
552     auto tempProperty = sceneSession->GetSessionProperty();
553     sceneSession->property_ = nullptr;
554     manager_->UpdatePrivacyMode(sceneSession, windowinfo);
555 
556     sceneSession->property_ = tempProperty;
557     sceneSession->property_->isPrivacyMode_ = true;
558     sceneSession->property_->isSystemPrivacyMode_ = false;
559     manager_->UpdatePrivacyMode(sceneSession, windowinfo);
560 
561     sceneSession->property_->isPrivacyMode_ = false;
562     sceneSession->property_->isSystemPrivacyMode_ = true;
563     manager_->UpdatePrivacyMode(sceneSession, windowinfo);
564 
565     sceneSession->property_->isPrivacyMode_ = false;
566     sceneSession->property_->isSystemPrivacyMode_ = false;
567     manager_->UpdatePrivacyMode(sceneSession, windowinfo);
568 
569     manager_->UpdatePrivacyMode(nullptr, windowinfo);
570 }
571 
572 /**
573  * @tc.name: UpdateWindowFlags
574  * @tc.desc: UpdateWindowFlags
575  * @tc.type: FUNC
576  */
577 HWTEST_F(SceneSessionDirtyManagerTest, UpdateWindowFlags, Function | SmallTest | Level2)
578 {
579     SessionInfo info;
580     sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
581     ASSERT_NE(sceneSession, nullptr);
582     MMI::WindowInfo windowinfo;
583     auto screenId = 0;
584     manager_->UpdateWindowFlags(screenId, sceneSession, windowinfo);
585 
586     ScreenProperty screenProperty0;
587     screenProperty0.SetRotation(0.0f);
588     ScreenSessionConfig config;
589     sptr<ScreenSession> screenSession = new ScreenSession(config, ScreenSessionReason::CREATE_SESSION_FOR_CLIENT);
590     ASSERT_NE(screenSession, nullptr);
591     screenSession->SetTouchEnabledFromJs(true);
592     Rosen::ScreenSessionManagerClient::GetInstance().OnUpdateFoldDisplayMode(FoldDisplayMode::UNKNOWN);
593     ScreenPropertyChangeReason reason = ScreenPropertyChangeReason::UNDEFINED;
594     Rosen::ScreenSessionManagerClient::GetInstance().screenSessionMap_.emplace(screenId, screenSession);
595     Rosen::ScreenSessionManagerClient::GetInstance().OnPropertyChanged(screenId, screenProperty0, reason);
596     manager_->UpdateWindowFlags(screenId, sceneSession, windowinfo);
597 
598     screenSession->SetTouchEnabledFromJs(false);
599     Rosen::ScreenSessionManagerClient::GetInstance().screenSessionMap_.emplace(screenId, screenSession);
600     Rosen::ScreenSessionManagerClient::GetInstance().OnPropertyChanged(screenId, screenProperty0, reason);
601     manager_->UpdateWindowFlags(screenId, sceneSession, windowinfo);
602 }
603 
604 /**
605  * @tc.name: AddModalExtensionWindowInfo
606  * @tc.desc: AddModalExtensionWindowInfo
607  * @tc.type: FUNC
608  */
609 HWTEST_F(SceneSessionDirtyManagerTest, AddModalExtensionWindowInfo, Function | SmallTest | Level2)
610 {
611     SessionInfo info;
612     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
613     ASSERT_NE(sceneSession, nullptr);
614 
615     std::vector<MMI::WindowInfo> windowInfoList;
616     MMI::WindowInfo windowInfo;
617     windowInfoList.emplace_back(windowInfo);
618     ExtensionWindowEventInfo extensionInfo = {
619         .persistentId = 12345,
620         .pid = 1234
621     };
622     manager_->AddModalExtensionWindowInfo(windowInfoList, windowInfo, nullptr, extensionInfo);
623     EXPECT_EQ(windowInfoList.size(), 1);
624 
625     sceneSession->AddModalUIExtension(extensionInfo);
626     manager_->AddModalExtensionWindowInfo(windowInfoList, windowInfo, sceneSession, extensionInfo);
627     ASSERT_EQ(windowInfoList.size(), 2);
628     EXPECT_TRUE(windowInfoList[1].defaultHotAreas.empty());
629 
630     Rect windowRect {1, 1, 7, 8};
631     extensionInfo.windowRect = windowRect;
632     sceneSession->UpdateModalUIExtension(extensionInfo);
633     manager_->AddModalExtensionWindowInfo(windowInfoList, windowInfo, sceneSession, extensionInfo);
634     ASSERT_EQ(windowInfoList.size(), 3);
635     EXPECT_EQ(windowInfoList[2].defaultHotAreas.size(), 1);
636 }
637 
638 /**
639  * @tc.name: GetHostComponentWindowInfo
640  * @tc.desc: GetHostComponentWindowInfo
641  * @tc.type: FUNC
642  */
643 HWTEST_F(SceneSessionDirtyManagerTest, GetHostComponentWindowInfo, Function | SmallTest | Level2)
644 {
645     MMI::WindowInfo hostWindowinfo;
646     SecSurfaceInfo secSurfaceInfo;
647     Matrix3f transform;
648     MMI::WindowInfo ret;
649     MMI::WindowInfo windowInfo;
650     ret = manager_->GetHostComponentWindowInfo(secSurfaceInfo, hostWindowinfo, transform);
651     ASSERT_EQ(ret.id, windowInfo.id);
652 
653     SecRectInfo secRectInfo;
654     secSurfaceInfo.upperNodes.emplace_back(secRectInfo);
655     secSurfaceInfo.hostPid = 1;
656     windowInfo.pid = 1;
657     ret = manager_->GetHostComponentWindowInfo(secSurfaceInfo, hostWindowinfo, transform);
658     ASSERT_EQ(ret.pid, windowInfo.pid);
659 
660     ret = manager_->GetHostComponentWindowInfo(secSurfaceInfo, hostWindowinfo, transform);
661     ASSERT_EQ(ret.defaultHotAreas.size(), 1);
662 }
663 
664 /**
665  * @tc.name: GetSecComponentWindowInfo
666  * @tc.desc: GetSecComponentWindowInfo
667  * @tc.type: FUNC
668  */
669 HWTEST_F(SceneSessionDirtyManagerTest, GetSecComponentWindowInfo, Function | SmallTest | Level2)
670 {
671     MMI::WindowInfo hostWindowinfo;
672     SecSurfaceInfo secSurfaceInfo;
673     Matrix3f transform;
674     MMI::WindowInfo ret;
675     MMI::WindowInfo windowInfo;
676     ret = manager_->GetSecComponentWindowInfo(secSurfaceInfo, hostWindowinfo, nullptr, transform);
677     ASSERT_EQ(ret.id, windowInfo.id);
678 
679     SessionInfo info;
680     info.abilityName_ = "TestAbilityName";
681     info.bundleName_ = "TestBundleName";
682     sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
683     ASSERT_NE(sceneSession, nullptr);
684 
685     ret = manager_->GetSecComponentWindowInfo(secSurfaceInfo, hostWindowinfo, sceneSession, transform);
686     ASSERT_EQ(ret.id, windowInfo.id);
687 
688     secSurfaceInfo.uiExtensionNodeId = 1;
689     sceneSession->AddUIExtSurfaceNodeId(1, 1);
690     windowInfo.privacyUIFlag = true;
691     ret = manager_->GetSecComponentWindowInfo(secSurfaceInfo, hostWindowinfo, sceneSession, transform);
692     ASSERT_EQ(ret.privacyUIFlag, windowInfo.privacyUIFlag);
693 
694     windowInfo.id = 1;
695     ret = manager_->GetSecComponentWindowInfo(secSurfaceInfo, hostWindowinfo, sceneSession, transform);
696     ASSERT_EQ(ret.id, windowInfo.id);
697 }
698 
699 /**
700  * @tc.name: GetSecSurfaceWindowinfoList
701  * @tc.desc: GetSecSurfaceWindowinfoList
702  * @tc.type: FUNC
703  */
704 HWTEST_F(SceneSessionDirtyManagerTest, GetSecSurfaceWindowinfoList, Function | SmallTest | Level2)
705 {
706     MMI::WindowInfo hostWindowinfo;
707     SecSurfaceInfo secSurfaceInfo;
708     Matrix3f transform;
709     MMI::WindowInfo windowInfo;
710     auto ret = manager_->GetSecSurfaceWindowinfoList(nullptr, hostWindowinfo, transform);
711     ASSERT_EQ(ret.size(), 0);
712 
713     std::vector<SecSurfaceInfo> secSurfaceInfoList;
714     secSurfaceInfoList.emplace_back(secSurfaceInfo);
715     manager_->secSurfaceInfoMap_.emplace(1, secSurfaceInfoList);
716     ret = manager_->GetSecSurfaceWindowinfoList(nullptr, hostWindowinfo, transform);
717     ASSERT_EQ(ret.size(), 0);
718 
719     SessionInfo info;
720     info.abilityName_ = "TestAbilityName";
721     info.bundleName_ = "TestBundleName";
722     sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
723     ASSERT_NE(sceneSession, nullptr);
724     struct RSSurfaceNodeConfig config;
725     std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Create(config);
726     surfaceNode->id_ = 1;
727     sceneSession->surfaceNode_ = surfaceNode;
728     ret = manager_->GetSecSurfaceWindowinfoList(sceneSession, hostWindowinfo, transform);
729     ASSERT_EQ(ret.size(), 2);
730 
731     manager_->secSurfaceInfoMap_.emplace(0, secSurfaceInfoList);
732     ret = manager_->GetSecSurfaceWindowinfoList(sceneSession, hostWindowinfo, transform);
733     ASSERT_EQ(ret.size(), 2);
734 
735     manager_->secSurfaceInfoMap_.clear();
736     manager_->secSurfaceInfoMap_.emplace(1, secSurfaceInfoList);
737     ret = manager_->GetSecSurfaceWindowinfoList(sceneSession, hostWindowinfo, transform);
738     ASSERT_EQ(ret.size(), 2);
739 
740     sceneSession->surfaceNode_ = nullptr;
741     ret = manager_->GetSecSurfaceWindowinfoList(sceneSession, hostWindowinfo, transform);
742     ASSERT_EQ(ret.size(), 0);
743 }
744 
745 /**
746  * @tc.name: UpdateSecSurfaceInfo
747  * @tc.desc: UpdateSecSurfaceInfo
748  * @tc.type: FUNC
749  */
750 HWTEST_F(SceneSessionDirtyManagerTest, UpdateSecSurfaceInfo, Function | SmallTest | Level2)
751 {
752     std::map<uint64_t, std::vector<SecSurfaceInfo>> secSurfaceInfoMap;
753     SecRectInfo secRectInfo1;
754     SecRectInfo secRectInfo2;
755     SecSurfaceInfo secSurfaceInfo1;
756     secSurfaceInfo1.upperNodes.emplace_back(secRectInfo1);
757     SecSurfaceInfo secSurfaceInfo2;
758     secSurfaceInfo2.upperNodes.emplace_back(secRectInfo2);
759     std::vector<SecSurfaceInfo> secSurfaceInfoList1;
760     std::vector<SecSurfaceInfo> secSurfaceInfoList2;
761     secSurfaceInfoList1.emplace_back(secSurfaceInfo1);
762     secSurfaceInfoList2.emplace_back(secSurfaceInfo2);
763     manager_->secSurfaceInfoMap_.emplace(1, secSurfaceInfoList1);
764     secSurfaceInfoMap.emplace(1, secSurfaceInfoList2);
765     manager_->UpdateSecSurfaceInfo(secSurfaceInfoMap);
766     ASSERT_EQ(secSurfaceInfoMap.size(), manager_->secSurfaceInfoMap_.size());
767 
768     secSurfaceInfoMap.emplace(2, secSurfaceInfoList2);
769     manager_->UpdateSecSurfaceInfo(secSurfaceInfoMap);
770     ASSERT_EQ(secSurfaceInfoMap.size(), manager_->secSurfaceInfoMap_.size());
771 
772     secSurfaceInfoMap.clear();
773     manager_->secSurfaceInfoMap_.clear();
774     secSurfaceInfoList1.clear();
775     secSurfaceInfoList2.clear();
776     secSurfaceInfo1.uiExtensionRectInfo.scale[0] = 1;
777     secSurfaceInfoList1.emplace_back(secSurfaceInfo1);
778     secSurfaceInfoList2.emplace_back(secSurfaceInfo2);
779     secSurfaceInfoMap.emplace(1, secSurfaceInfoList1);
780     manager_->secSurfaceInfoMap_.emplace(1, secSurfaceInfoList2);
781     manager_->UpdateSecSurfaceInfo(secSurfaceInfoMap);
782     ASSERT_EQ(secSurfaceInfoMap.size(), manager_->secSurfaceInfoMap_.size());
783 }
784 
785 /**
786  * @tc.name: ResetFlushWindowInfoTask
787  * @tc.desc: ResetFlushWindowInfoTask
788  * @tc.type: FUNC
789  */
790 HWTEST_F(SceneSessionDirtyManagerTest, ResetFlushWindowInfoTask, Function | SmallTest | Level2)
791 {
792     int ret = 0;
793     auto preFlushWindowInfoCallback = manager_->flushWindowInfoCallback_;
794     manager_->flushWindowInfoCallback_ = nullptr;
795     manager_->ResetFlushWindowInfoTask();
796     manager_->flushWindowInfoCallback_ = preFlushWindowInfoCallback;
797     ASSERT_EQ(ret, 0);
798 }
799 
800 /**
801  * @tc.name: DumpRect
802  * @tc.desc: DumpRect
803  * @tc.type: FUNC
804  */
805 HWTEST_F(SceneSessionDirtyManagerTest, DumpRect, Function | SmallTest | Level2)
806 {
807     int ret = 0;
808     std::vector<MMI::Rect> rects(0);
809     for (int i = 0; i < 2 ; i++) {
810         MMI::Rect rect = {
811             .x = i * 10,
812             .y = i * 10,
813             .width = i * 10,
814             .height = i * 10
815         };
816         rects.emplace_back(rect);
817     }
818     DumpRect(rects);
819     ASSERT_EQ(ret, 0);
820 }
821 
822 } // namespace
823 } // namespace Rosen
824 } // namespace OHOS
825