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 "scene_input_manager.h"
17 #include <gtest/gtest.h>
18 #include "session_manager/include/scene_session_manager.h"
19 #include "screen_session_manager/include/screen_session_manager_client.h"
20 
21 using namespace testing;
22 using namespace testing::ext;
23 
24 namespace OHOS {
25 namespace Rosen {
26 constexpr int MAX_WINDOWINFO_NUM = 15;
27 class SceneInputManagerTest : public testing::Test {
28 public:
29     static void SetUpTestCase();
30     static void TearDownTestCase();
31     void SetUp() override;
32     void TearDown() override;
33     static sptr<SceneSessionManager> ssm_;
34 private:
35     static constexpr uint32_t WAIT_SYNC_IN_NS = 500000;
36 };
37 
38 sptr<SceneSessionManager> SceneInputManagerTest::ssm_ = nullptr;
39 
SetUpTestCase()40 void SceneInputManagerTest::SetUpTestCase()
41 {
42     ssm_ = &SceneSessionManager::GetInstance();
43 }
44 
TearDownTestCase()45 void SceneInputManagerTest::TearDownTestCase()
46 {
47     ssm_ = nullptr;
48 }
49 
SetUp()50 void SceneInputManagerTest::SetUp()
51 {
52 }
53 
TearDown()54 void SceneInputManagerTest::TearDown()
55 {
56     usleep(WAIT_SYNC_IN_NS);
57 }
58 
59 namespace {
CheckNeedUpdateTest()60 void CheckNeedUpdateTest()
61 {
62     SceneInputManager::GetInstance().SetUserBackground(true);
63     SceneInputManager::GetInstance().FlushDisplayInfoToMMI();
64     SceneInputManager::GetInstance().lastFocusId_ = -1;
65     SceneInputManager::GetInstance().FlushDisplayInfoToMMI();
66 
67     SceneInputManager::GetInstance().lastWindowInfoList_.clear();
68     SceneInputManager::GetInstance().FlushDisplayInfoToMMI();
69     SceneInputManager::GetInstance().lastDisplayInfos_.clear();
70     SceneInputManager::GetInstance().FlushDisplayInfoToMMI();
71     SceneInputManager::GetInstance().lastWindowInfoList_.clear();
72     SceneInputManager::GetInstance().lastDisplayInfos_.clear();
73     SceneInputManager::GetInstance().FlushDisplayInfoToMMI();
74 
75     if (SceneInputManager::GetInstance().lastDisplayInfos_.size() != 0) {
76         MMI::DisplayInfo displayInfo;
77         SceneInputManager::GetInstance().lastDisplayInfos_[0] = displayInfo;
78         SceneInputManager::GetInstance().FlushDisplayInfoToMMI();
79     }
80 
81     if (SceneInputManager::GetInstance().lastWindowInfoList_.size() != 0) {
82         MMI::WindowInfo windowInfo;
83         SceneInputManager::GetInstance().lastWindowInfoList_[0] = windowInfo;
84         SceneInputManager::GetInstance().FlushDisplayInfoToMMI();
85     }
86 }
87 
88 
WindowInfoListZeroTest(sptr<SceneSessionManager> ssm_)89 void WindowInfoListZeroTest(sptr<SceneSessionManager> ssm_)
90 {
91     const auto sceneSessionMap = ssm_->GetSceneSessionMap();
92     for (auto sceneSession : sceneSessionMap) {
93         ssm_->DestroyDialogWithMainWindow(sceneSession.second);
94     }
95     SceneInputManager::GetInstance().FlushDisplayInfoToMMI();
96 
97     for (auto sceneSession : sceneSessionMap) {
98         sptr<WindowSessionProperty> windowSessionProperty = new WindowSessionProperty();
99         windowSessionProperty->SetWindowType(sceneSession.second->GetWindowType());
100         ssm_->RequestSceneSession(sceneSession.second->GetSessionInfo(), windowSessionProperty);
101     }
102     SceneInputManager::GetInstance().FlushDisplayInfoToMMI();
103 }
104 
MaxWindowInfoTest(sptr<SceneSessionManager> ssm_)105 void MaxWindowInfoTest(sptr<SceneSessionManager> ssm_)
106 {
107     std::vector<sptr<SceneSession>> sessionList;
108     int maxWindowInfoNum = 20;
109     int32_t idStart = 1000;
110     for (int i = 0; i < maxWindowInfoNum; i++) {
111         SessionInfo info;
112         info.abilityName_ = "test" + std::to_string(i);
113         info.bundleName_ = "test" + std::to_string(i);
114         info.appIndex_ = idStart + i;
115         sptr<WindowSessionProperty> windowSessionProperty = new WindowSessionProperty();
116         ASSERT_NE(windowSessionProperty, nullptr);
117         windowSessionProperty->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
118         auto sceneSession = ssm_->RequestSceneSession(info, windowSessionProperty);
119         if (sceneSession != nullptr) {
120             sessionList.push_back(sceneSession);
121         }
122     }
123     SceneInputManager::GetInstance().FlushDisplayInfoToMMI();
124 
125     for (auto session : sessionList) {
126         ssm_->DestroyDialogWithMainWindow(session);
127     }
128     SceneInputManager::GetInstance().FlushDisplayInfoToMMI();
129 }
130 
131 /**
132  * @tc.name: FlushDisplayInfoToMMI
133  * @tc.desc: check func FlushDisplayInfoToMMI
134  * @tc.type: FUNC
135  */
136 HWTEST_F(SceneInputManagerTest, FlushDisplayInfoToMMI, Function | SmallTest | Level1)
137 {
138     GTEST_LOG_(INFO) << "SceneInputManagerTest: FlushDisplayInfoToMMI start";
139     int ret = 0;
140     // sceneSessionDirty_ = nullptr
141     SceneInputManager::GetInstance().isUserBackground_ = false;
142     auto oldDirty = SceneInputManager::GetInstance().sceneSessionDirty_;
143     SceneInputManager::GetInstance().sceneSessionDirty_ = nullptr;
144     SceneInputManager::GetInstance().FlushDisplayInfoToMMI();
145     SceneInputManager::GetInstance().sceneSessionDirty_ = oldDirty;
146 
147     // NotNeedUpdate
148     SceneInputManager::GetInstance().FlushDisplayInfoToMMI(true);
149     SceneInputManager::GetInstance().FlushDisplayInfoToMMI();
150 
151     auto preEventHandler = SceneInputManager::GetInstance().eventHandler_;
152     SceneInputManager::GetInstance().eventHandler_ = nullptr;
153     SceneInputManager::GetInstance().FlushEmptyInfoToMMI();
154     SceneInputManager::GetInstance().eventHandler_ = preEventHandler;
155 
156     CheckNeedUpdateTest();
157     WindowInfoListZeroTest(ssm_);
158     MaxWindowInfoTest(ssm_);
159 
160     ASSERT_EQ(ret, 0);
161     GTEST_LOG_(INFO) << "SceneInputManagerTest: FlushDisplayInfoToMMI end";
162 }
163 
164 /**
165 * @tc.name: NotifyWindowInfoChange
166 * @tc.desc: check func NotifyWindowInfoChange
167 * @tc.type: FUNC
168 */
169 HWTEST_F(SceneInputManagerTest, NotifyWindowInfoChange, Function | SmallTest | Level1)
170 {
171     GTEST_LOG_(INFO) << "SceneInputManagerTest: NotifyWindowInfoChange start";
172     SessionInfo info;
173     info.abilityName_ = "NotifyWindowInfoChange";
174     info.bundleName_ = "NotifyWindowInfoChange";
175     info.appIndex_ = 10;
176     sptr<SceneSession::SpecificSessionCallback> specificCallback_
177             = new (std::nothrow) SceneSession::SpecificSessionCallback();
178     EXPECT_NE(specificCallback_, nullptr);
179     sptr<SceneSession> sceneSession = new SceneSession(info, specificCallback_);
180 
181     // sceneSessionDirty_ = nullptr
182     auto oldDirty = SceneInputManager::GetInstance().sceneSessionDirty_;
183     SceneInputManager::GetInstance().sceneSessionDirty_ = nullptr;
184     SceneInputManager::GetInstance()
185     .NotifyWindowInfoChange(sceneSession, WindowUpdateType::WINDOW_UPDATE_ADDED);
186     SceneInputManager::GetInstance().sceneSessionDirty_ = oldDirty;
187 
188     SceneInputManager::GetInstance()
189     .NotifyWindowInfoChange(sceneSession, WindowUpdateType::WINDOW_UPDATE_ADDED);
190     SceneInputManager::GetInstance().FlushDisplayInfoToMMI();
191     GTEST_LOG_(INFO) << "SceneInputManagerTest: NotifyWindowInfoChange end";
192 }
193 
194 /**
195 * @tc.name: NotifyWindowInfoChangeFromSession
196 * @tc.desc: check func NotifyWindowInfoChangeFromSession
197 * @tc.type: FUNC
198 */
199 HWTEST_F(SceneInputManagerTest, NotifyWindowInfoChangeFromSession, Function | SmallTest | Level1)
200 {
201     GTEST_LOG_(INFO) << "SceneInputManagerTest: NotifyWindowInfoChangeFromSession start";
202     SessionInfo info;
203     info.abilityName_ = "NotifyWindowInfoChangeFromSession";
204     info.bundleName_ = "NotifyWindowInfoChangeFromSession";
205     info.appIndex_ = 100;
206     sptr<SceneSession::SpecificSessionCallback> specificCallback_
207             = new (std::nothrow) SceneSession::SpecificSessionCallback();
208     EXPECT_NE(specificCallback_, nullptr);
209     sptr<SceneSession> sceneSession = new SceneSession(info, specificCallback_);
210 
211     // sceneSessionDirty_ = nullptr
212     auto oldDirty = SceneInputManager::GetInstance().sceneSessionDirty_;
213     SceneInputManager::GetInstance().sceneSessionDirty_ = nullptr;
214     SceneInputManager::GetInstance().NotifyWindowInfoChangeFromSession(sceneSession);
215     SceneInputManager::GetInstance().sceneSessionDirty_ = oldDirty;
216 
217     SceneInputManager::GetInstance().NotifyWindowInfoChangeFromSession(sceneSession);
218     SceneInputManager::GetInstance().FlushDisplayInfoToMMI();
219     GTEST_LOG_(INFO) << "SceneInputManagerTest: NotifyWindowInfoChangeFromSession end";
220 }
221 
222 /**
223 * @tc.name: NotifyMMIWindowPidChange
224 * @tc.desc: check func NotifyMMIWindowPidChange
225 * @tc.type: FUNC
226 */
227 HWTEST_F(SceneInputManagerTest, NotifyMMIWindowPidChange, Function | SmallTest | Level1)
228 {
229     GTEST_LOG_(INFO) << "SceneInputManagerTest: NotifyMMIWindowPidChange start";
230     SessionInfo info;
231     info.abilityName_ = "NotifyMMIWindowPidChange";
232     info.bundleName_ = "NotifyMMIWindowPidChange";
233     info.appIndex_ = 1000;
234     sptr<SceneSession::SpecificSessionCallback> specificCallback_
235             = new (std::nothrow) SceneSession::SpecificSessionCallback();
236     EXPECT_NE(specificCallback_, nullptr);
237     sptr<SceneSession> sceneSession = new SceneSession(info, specificCallback_);
238 
239     // sceneSessionDirty_ = nullptr
240     auto oldDirty = SceneInputManager::GetInstance().sceneSessionDirty_;
241     SceneInputManager::GetInstance().sceneSessionDirty_ = nullptr;
242     SceneInputManager::GetInstance().NotifyMMIWindowPidChange(sceneSession, true);
243     SceneInputManager::GetInstance().sceneSessionDirty_ = oldDirty;
244 
245     SceneInputManager::GetInstance().NotifyMMIWindowPidChange(sceneSession, true);
246     EXPECT_TRUE(sceneSession->IsStartMoving());
247     SceneInputManager::GetInstance().NotifyMMIWindowPidChange(sceneSession, false);
248     EXPECT_FALSE(sceneSession->IsStartMoving());
249     SceneInputManager::GetInstance().NotifyMMIWindowPidChange(nullptr, false);
250     EXPECT_FALSE(sceneSession->IsStartMoving());
251     SceneInputManager::GetInstance().FlushDisplayInfoToMMI();
252     GTEST_LOG_(INFO) << "SceneInputManagerTest: NotifyMMIWindowPidChange end";
253 }
254 
255 /**
256  * @tc.name: UpdateFocusedSessionId
257  * @tc.desc: UpdateFocusedSessionId
258  * @tc.type: FUNC
259  */
260 HWTEST_F(SceneInputManagerTest, UpdateFocusedSessionId, Function | SmallTest | Level3)
261 {
262     auto sceneInputManager = &SceneInputManager::GetInstance();
263     ASSERT_NE(sceneInputManager, nullptr);
264     EXPECT_EQ(sceneInputManager->focusedSessionId_, -1);
265 
266     SessionInfo info;
267     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
268     ASSERT_NE(sceneSession, nullptr);
269     ssm_->sceneSessionMap_.insert(std::make_pair(sceneSession->GetPersistentId(), sceneSession));
270 
271     sceneInputManager->UpdateFocusedSessionId(INVALID_SESSION_ID);
272     EXPECT_EQ(sceneInputManager->focusedSessionId_, -1);
273     sceneInputManager->UpdateFocusedSessionId(sceneSession->GetPersistentId());
274     EXPECT_EQ(sceneInputManager->focusedSessionId_, -1);
275     ExtensionWindowEventInfo extensionInfo {
276         .persistentId = 12345
277     };
278     sceneSession->AddModalUIExtension(extensionInfo);
279     sceneInputManager->UpdateFocusedSessionId(sceneSession->GetPersistentId());
280     EXPECT_EQ(sceneInputManager->focusedSessionId_, extensionInfo.persistentId);
281 
282     ssm_->sceneSessionMap_.erase(sceneSession->GetPersistentId());
283 }
284 
285 /**
286  * @tc.name: PrintWindowInfo
287  * @tc.desc: PrintWindowInfo
288  * @tc.type: FUNC
289  */
290 HWTEST_F(SceneInputManagerTest, PrintWindowInfo, Function | SmallTest | Level3)
291 {
292     int ret = 0;
293     std::vector<MMI::WindowInfo> windowInfoList;
294     SceneInputManager::GetInstance().PrintWindowInfo(windowInfoList);
295     MMI::WindowInfo windowInfo;
296     windowInfoList.emplace_back(windowInfo);
297     SceneInputManager::GetInstance().PrintWindowInfo(windowInfoList);
298     Rosen::SceneSessionManager::GetInstance().SetFocusedSessionId(-1);
299     SceneInputManager::GetInstance().PrintWindowInfo(windowInfoList);
300     ASSERT_EQ(ret, 0);
301 }
302 
303 /**
304  * @tc.name: FlushFullInfoToMMI
305  * @tc.desc: FlushFullInfoToMMI
306  * @tc.type: FUNC
307  */
308 HWTEST_F(SceneInputManagerTest, FlushFullInfoToMMI, Function | SmallTest | Level3)
309 {
310     int ret = 0;
311     std::vector<MMI::DisplayInfo> displayInfos;
312     std::vector<MMI::WindowInfo> windowInfoList;
313     SceneInputManager::GetInstance().FlushFullInfoToMMI(displayInfos, windowInfoList);
314     MMI::DisplayInfo displayInfo;
315     displayInfos.emplace_back(displayInfo);
316     SceneInputManager::GetInstance().FlushFullInfoToMMI(displayInfos, windowInfoList);
317     auto oldDirty = SceneInputManager::GetInstance().sceneSessionDirty_;
318     SceneInputManager::GetInstance().sceneSessionDirty_ = nullptr;
319     SceneInputManager::GetInstance().FlushFullInfoToMMI(displayInfos, windowInfoList);
320     SceneInputManager::GetInstance().sceneSessionDirty_ = oldDirty;
321     ASSERT_EQ(ret, 0);
322 }
323 
324 /**
325  * @tc.name: FlushChangeInfoToMMI
326  * @tc.desc: FlushChangeInfoToMMI
327  * @tc.type: FUNC
328  */
329 HWTEST_F(SceneInputManagerTest, FlushChangeInfoToMMI, Function | SmallTest | Level3)
330 {
331     int ret = 0;
332     std::map<uint64_t, std::vector<MMI::WindowInfo>> screenId2Windows;
333     SceneInputManager::GetInstance().FlushChangeInfoToMMI(screenId2Windows);
334     std::vector<MMI::WindowInfo> windowInfoList;
335     MMI::WindowInfo windowInfo;
336     windowInfoList.emplace_back(windowInfo);
337     screenId2Windows.emplace(1, windowInfoList);
338     SceneInputManager::GetInstance().FlushChangeInfoToMMI(screenId2Windows);
339     ASSERT_EQ(ret, 0);
340 }
341 
342 /**
343  * @tc.name: ConstructDisplayInfos
344  * @tc.desc: ConstructDisplayInfos
345  * @tc.type: FUNC
346  */
347 HWTEST_F(SceneInputManagerTest, ConstructDisplayInfos, Function | SmallTest | Level3)
348 {
349     int ret = 0;
350     std::vector<MMI::DisplayInfo> displayInfos;
351     SceneInputManager::GetInstance().ConstructDisplayInfos(displayInfos);
352     ScreenProperty screenProperty0;
353     Rosen::ScreenSessionManagerClient::GetInstance().GetAllScreensProperties().insert(
354         std::make_pair(0, screenProperty0));
355     SceneInputManager::GetInstance().ConstructDisplayInfos(displayInfos);
356     ASSERT_EQ(ret, 0);
357 }
358 
359 /**
360  * @tc.name: CheckNeedUpdate
361  * @tc.desc: CheckNeedUpdate
362  * @tc.type: FUNC
363  */
364 HWTEST_F(SceneInputManagerTest, CheckNeedUpdate1, Function | SmallTest | Level3)
365 {
366     std::vector<MMI::DisplayInfo> displayInfos;
367     std::vector<MMI::WindowInfo> windowInfoList;
368     int32_t focusId = 0;
369     Rosen::SceneSessionManager::GetInstance().SetFocusedSessionId(focusId);
370     SceneInputManager::GetInstance().lastFocusId_ = 1;
371     bool ret1 = SceneInputManager::GetInstance().CheckNeedUpdate(displayInfos, windowInfoList);
372     ASSERT_TRUE(ret1);
373 
374     SceneInputManager::GetInstance().lastFocusId_ = 0;
375     MMI::DisplayInfo displayinfo;
376     displayInfos.emplace_back(displayinfo);
377     bool ret2 = SceneInputManager::GetInstance().CheckNeedUpdate(displayInfos, windowInfoList);
378     ASSERT_TRUE(ret2);
379 
380     displayInfos.clear();
381     MMI::WindowInfo windowinfo;
382     windowInfoList.emplace_back(windowinfo);
383     bool ret3 = SceneInputManager::GetInstance().CheckNeedUpdate(displayInfos, windowInfoList);
384     ASSERT_TRUE(ret3);
385 }
386 
387 /**
388  * @tc.name: CheckNeedUpdate
389  * @tc.desc: CheckNeedUpdate
390  * @tc.type: FUNC
391  */
392 HWTEST_F(SceneInputManagerTest, CheckNeedUpdate2, Function | SmallTest | Level3)
393 {
394     std::vector<MMI::DisplayInfo> displayInfos;
395     std::vector<MMI::WindowInfo> windowInfoList;
396     MMI::DisplayInfo displayinfo;
397     displayInfos.emplace_back(displayinfo);
398     MMI::WindowInfo windowinfo;
399     int32_t focusId = 0;
400     Rosen::SceneSessionManager::GetInstance().SetFocusedSessionId(focusId);
401     SceneInputManager::GetInstance().lastFocusId_ = 0;
402     SceneInputManager::GetInstance().lastDisplayInfos_ = displayInfos;
403     SceneInputManager::GetInstance().lastWindowInfoList_ = windowInfoList;
404     bool result = SceneInputManager::GetInstance().CheckNeedUpdate(displayInfos, windowInfoList);
405     ASSERT_FALSE(result);
406     windowInfoList.emplace_back(windowinfo);
407     SceneInputManager::GetInstance().lastWindowInfoList_ = windowInfoList;
408     result = SceneInputManager::GetInstance().CheckNeedUpdate(displayInfos, windowInfoList);
409     ASSERT_FALSE(result);
410 
411     displayInfos[0].id = 1;
412     result = SceneInputManager::GetInstance().CheckNeedUpdate(displayInfos, windowInfoList);
413     ASSERT_TRUE(result);
414     displayInfos[0].id = 0;
415 
416     windowInfoList[0].id = 1;
417     result = SceneInputManager::GetInstance().CheckNeedUpdate(displayInfos, windowInfoList);
418     ASSERT_TRUE(result);
419     windowInfoList[0].id = 0;
420 
421     windowInfoList[0].pid = 1;
422     result = SceneInputManager::GetInstance().CheckNeedUpdate(displayInfos, windowInfoList);
423     ASSERT_TRUE(result);
424     windowInfoList[0].pid = 0;
425 
426     windowInfoList[0].uid = 1;
427     result = SceneInputManager::GetInstance().CheckNeedUpdate(displayInfos, windowInfoList);
428     ASSERT_TRUE(result);
429     windowInfoList[0].uid = 0;
430 
431     windowInfoList[0].agentWindowId = 1;
432     result = SceneInputManager::GetInstance().CheckNeedUpdate(displayInfos, windowInfoList);
433     ASSERT_TRUE(result);
434     windowInfoList[0].agentWindowId = 0;
435 
436     windowInfoList[0].flags = 1;
437     result = SceneInputManager::GetInstance().CheckNeedUpdate(displayInfos, windowInfoList);
438     ASSERT_TRUE(result);
439     windowInfoList[0].flags = 0;
440 
441     windowInfoList[0].displayId = 1;
442     result = SceneInputManager::GetInstance().CheckNeedUpdate(displayInfos, windowInfoList);
443     ASSERT_TRUE(result);
444     windowInfoList[0].displayId = 0;
445 
446     windowInfoList[0].zOrder = 1;
447     result = SceneInputManager::GetInstance().CheckNeedUpdate(displayInfos, windowInfoList);
448     ASSERT_TRUE(result);
449     windowInfoList[0].zOrder = 0;
450 }
451 
452 /**
453  * @tc.name: CheckNeedUpdate
454  * @tc.desc: CheckNeedUpdate
455  * @tc.type: FUNC
456  */
457 HWTEST_F(SceneInputManagerTest, CheckNeedUpdate3, Function | SmallTest | Level3)
458 {
459     std::vector<MMI::DisplayInfo> displayInfos;
460     std::vector<MMI::WindowInfo> windowInfoList;
461     MMI::DisplayInfo displayinfo;
462     displayInfos.emplace_back(displayinfo);
463     MMI::WindowInfo windowinfo;
464     windowInfoList.emplace_back(windowinfo);
465     int32_t focusId = 0;
466     Rosen::SceneSessionManager::GetInstance().SetFocusedSessionId(focusId);
467     SceneInputManager::GetInstance().lastFocusId_ = 0;
468     SceneInputManager::GetInstance().lastDisplayInfos_ = displayInfos;
469     SceneInputManager::GetInstance().lastWindowInfoList_ = windowInfoList;
470     bool result = false;
471     windowInfoList[0].area.x = 1;
472     result = SceneInputManager::GetInstance().CheckNeedUpdate(displayInfos, windowInfoList);
473     ASSERT_TRUE(result);
474     windowInfoList[0].area.x = 0;
475 
476     windowInfoList[0].area.y = 1;
477     result = SceneInputManager::GetInstance().CheckNeedUpdate(displayInfos, windowInfoList);
478     ASSERT_TRUE(result);
479     windowInfoList[0].area.y = 0;
480 
481     windowInfoList[0].area.width = 1;
482     result = SceneInputManager::GetInstance().CheckNeedUpdate(displayInfos, windowInfoList);
483     ASSERT_TRUE(result);
484     windowInfoList[0].area.width = 0;
485 
486     windowInfoList[0].area.height = 1;
487     result = SceneInputManager::GetInstance().CheckNeedUpdate(displayInfos, windowInfoList);
488     ASSERT_TRUE(result);
489     windowInfoList[0].area.height = 0;
490 
491     MMI::Rect area;
492     windowInfoList[0].defaultHotAreas.emplace_back(area);
493     result = SceneInputManager::GetInstance().CheckNeedUpdate(displayInfos, windowInfoList);
494     ASSERT_TRUE(result);
495     windowInfoList[0].defaultHotAreas.clear();
496 
497     windowInfoList[0].pointerHotAreas.emplace_back(area);
498     result = SceneInputManager::GetInstance().CheckNeedUpdate(displayInfos, windowInfoList);
499     ASSERT_TRUE(result);
500     windowInfoList[0].pointerHotAreas.clear();
501 
502     windowInfoList[0].transform.emplace_back(1.0);
503     result = SceneInputManager::GetInstance().CheckNeedUpdate(displayInfos, windowInfoList);
504     ASSERT_TRUE(result);
505     windowInfoList[0].transform.clear();
506 }
507 
508 /**
509  * @tc.name: CheckNeedUpdate
510  * @tc.desc: CheckNeedUpdate
511  * @tc.type: FUNC
512  */
513 HWTEST_F(SceneInputManagerTest, CheckNeedUpdate4, Function | SmallTest | Level3)
514 {
515     std::vector<MMI::DisplayInfo> displayInfos;
516     std::vector<MMI::WindowInfo> windowInfoList;
517     MMI::DisplayInfo displayinfo;
518     displayInfos.emplace_back(displayinfo);
519     MMI::WindowInfo windowinfo;
520     windowInfoList.emplace_back(windowinfo);
521     int32_t focusId = 0;
522     Rosen::SceneSessionManager::GetInstance().SetFocusedSessionId(focusId);
523     SceneInputManager::GetInstance().lastFocusId_ = 0;
524     SceneInputManager::GetInstance().lastDisplayInfos_ = displayInfos;
525     SceneInputManager::GetInstance().lastWindowInfoList_ = windowInfoList;
526     bool result = false;
527     windowInfoList[0].transform.emplace_back(1.0);
528     SceneInputManager::GetInstance().lastWindowInfoList_[0].transform.emplace_back(2.0);
529     result = SceneInputManager::GetInstance().CheckNeedUpdate(displayInfos, windowInfoList);
530     ASSERT_TRUE(result);
531     windowInfoList[0].transform.clear();
532     SceneInputManager::GetInstance().lastWindowInfoList_[0].transform.clear();
533 
534     MMI::Rect area;
535     windowInfoList[0].defaultHotAreas.emplace_back(area);
536     area.x = 1;
537     SceneInputManager::GetInstance().lastWindowInfoList_[0].defaultHotAreas.emplace_back(area);
538     result = SceneInputManager::GetInstance().CheckNeedUpdate(displayInfos, windowInfoList);
539     ASSERT_TRUE(result);
540     windowInfoList[0].defaultHotAreas.clear();
541     SceneInputManager::GetInstance().lastWindowInfoList_[0].defaultHotAreas.clear();
542     area.x = 0;
543 
544     windowInfoList[0].pointerHotAreas.emplace_back(area);
545     area.x = 1;
546     SceneInputManager::GetInstance().lastWindowInfoList_[0].pointerHotAreas.emplace_back(area);
547     result = SceneInputManager::GetInstance().CheckNeedUpdate(displayInfos, windowInfoList);
548     ASSERT_TRUE(result);
549     windowInfoList[0].pointerHotAreas.clear();
550     SceneInputManager::GetInstance().lastWindowInfoList_[0].pointerHotAreas.clear();
551     area.x = 0;
552 
553     windowInfoList[0].pointerChangeAreas.emplace_back(1);
554     SceneInputManager::GetInstance().lastWindowInfoList_[0].pointerChangeAreas.emplace_back(2);
555     result = SceneInputManager::GetInstance().CheckNeedUpdate(displayInfos, windowInfoList);
556     ASSERT_TRUE(result);
557     windowInfoList[0].pointerChangeAreas.clear();
558     SceneInputManager::GetInstance().lastWindowInfoList_[0].pointerChangeAreas.clear();
559 }
560 
561 /**
562  * @tc.name: CheckNeedUpdate
563  * @tc.desc: CheckNeedUpdate
564  * @tc.type: FUNC
565  */
566 HWTEST_F(SceneInputManagerTest, CheckNeedUpdate5, Function | SmallTest | Level3)
567 {
568     std::vector<MMI::DisplayInfo> displayInfos;
569     std::vector<MMI::WindowInfo> windowInfoList;
570     MMI::DisplayInfo displayinfo;
571     displayInfos.emplace_back(displayinfo);
572     MMI::WindowInfo windowinfo;
573     windowInfoList.emplace_back(windowinfo);
574     int32_t focusId = 0;
575     Rosen::SceneSessionManager::GetInstance().SetFocusedSessionId(focusId);
576     SceneInputManager::GetInstance().lastFocusId_ = 0;
577     SceneInputManager::GetInstance().lastDisplayInfos_ = displayInfos;
578     SceneInputManager::GetInstance().lastWindowInfoList_ = windowInfoList;
579     bool result = false;
580     windowInfoList[0].transform.emplace_back(1.0);
581     SceneInputManager::GetInstance().lastWindowInfoList_[0].transform.emplace_back(2.0);
582     result = SceneInputManager::GetInstance().CheckNeedUpdate(displayInfos, windowInfoList);
583     ASSERT_TRUE(result);
584     windowInfoList[0].transform.clear();
585     SceneInputManager::GetInstance().lastWindowInfoList_[0].transform.clear();
586 
587     displayInfos[0].id = 1;
588     result = SceneInputManager::GetInstance().CheckNeedUpdate(displayInfos, windowInfoList);
589     ASSERT_TRUE(result);
590     displayInfos[0].id = 0;
591 
592     displayInfos[0].x = 1;
593     result = SceneInputManager::GetInstance().CheckNeedUpdate(displayInfos, windowInfoList);
594     ASSERT_TRUE(result);
595     displayInfos[0].x = 0;
596 
597     displayInfos[0].y = 1;
598     result = SceneInputManager::GetInstance().CheckNeedUpdate(displayInfos, windowInfoList);
599     ASSERT_TRUE(result);
600     displayInfos[0].y = 0;
601 
602     displayInfos[0].width = 1;
603     result = SceneInputManager::GetInstance().CheckNeedUpdate(displayInfos, windowInfoList);
604     ASSERT_TRUE(result);
605     displayInfos[0].width = 0;
606 
607     displayInfos[0].height = 1;
608     result = SceneInputManager::GetInstance().CheckNeedUpdate(displayInfos, windowInfoList);
609     ASSERT_TRUE(result);
610     displayInfos[0].height = 0;
611 }
612 
613 /**
614  * @tc.name: CheckNeedUpdate
615  * @tc.desc: CheckNeedUpdate
616  * @tc.type: FUNC
617  */
618 HWTEST_F(SceneInputManagerTest, CheckNeedUpdate6, Function | SmallTest | Level3)
619 {
620     std::vector<MMI::DisplayInfo> displayInfos;
621     std::vector<MMI::WindowInfo> windowInfoList;
622     MMI::DisplayInfo displayinfo;
623     displayInfos.emplace_back(displayinfo);
624     MMI::WindowInfo windowinfo;
625     windowInfoList.emplace_back(windowinfo);
626     int32_t focusId = 0;
627     Rosen::SceneSessionManager::GetInstance().SetFocusedSessionId(focusId);
628     SceneInputManager::GetInstance().lastFocusId_ = 0;
629     SceneInputManager::GetInstance().lastDisplayInfos_ = displayInfos;
630     SceneInputManager::GetInstance().lastWindowInfoList_ = windowInfoList;
631     bool result = false;
632     windowInfoList[0].transform.emplace_back(1.0);
633     SceneInputManager::GetInstance().lastWindowInfoList_[0].transform.emplace_back(2.0);
634     result = SceneInputManager::GetInstance().CheckNeedUpdate(displayInfos, windowInfoList);
635     ASSERT_TRUE(result);
636     windowInfoList[0].transform.clear();
637     SceneInputManager::GetInstance().lastWindowInfoList_[0].transform.clear();
638     displayInfos[0].dpi = 1;
639     result = SceneInputManager::GetInstance().CheckNeedUpdate(displayInfos, windowInfoList);
640     ASSERT_TRUE(result);
641     displayInfos[0].dpi = 0;
642 
643     displayInfos[0].name = "TestName";
644     result = SceneInputManager::GetInstance().CheckNeedUpdate(displayInfos, windowInfoList);
645     ASSERT_TRUE(result);
646     displayInfos[0].name = "";
647 
648     displayInfos[0].uniq = "TestUniq";
649     result = SceneInputManager::GetInstance().CheckNeedUpdate(displayInfos, windowInfoList);
650     ASSERT_TRUE(result);
651     displayInfos[0].uniq = "";
652 
653     displayInfos[0].direction = MMI::Direction::DIRECTION90;
654     result = SceneInputManager::GetInstance().CheckNeedUpdate(displayInfos, windowInfoList);
655     ASSERT_TRUE(result);
656     displayInfos[0].direction = MMI::Direction::DIRECTION0;
657 
658     displayInfos[0].displayDirection = MMI::Direction::DIRECTION90;
659     result = SceneInputManager::GetInstance().CheckNeedUpdate(displayInfos, windowInfoList);
660     ASSERT_TRUE(result);
661     displayInfos[0].displayDirection = MMI::Direction::DIRECTION0;
662 
663     displayInfos[0].displayMode = MMI::DisplayMode::FULL;
664     result = SceneInputManager::GetInstance().CheckNeedUpdate(displayInfos, windowInfoList);
665     ASSERT_TRUE(result);
666     displayInfos[0].displayMode = MMI::DisplayMode::UNKNOWN;
667 }
668 
669 /**
670  * @tc.name: CheckNeedUpdate
671  * @tc.desc: CheckNeedUpdate
672  * @tc.type: FUNC
673  */
674 HWTEST_F(SceneInputManagerTest, CheckNeedUpdate7, Function | SmallTest | Level3)
675 {
676     std::vector<MMI::DisplayInfo> displayInfos;
677     std::vector<MMI::WindowInfo> windowInfoList;
678     MMI::DisplayInfo displayinfo;
679     displayInfos.emplace_back(displayinfo);
680     MMI::WindowInfo windowinfo;
681     windowInfoList.emplace_back(windowinfo);
682     int32_t focusId = 0;
683     Rosen::SceneSessionManager::GetInstance().SetFocusedSessionId(focusId);
684     SceneInputManager::GetInstance().lastFocusId_ = 0;
685     SceneInputManager::GetInstance().lastDisplayInfos_ = displayInfos;
686     SceneInputManager::GetInstance().lastWindowInfoList_ = windowInfoList;
687     bool result = false;
688 
689     auto tempPixeMap = std::make_shared<Media::PixelMap>();
690     windowInfoList[0].pixelMap = static_cast<void*>(tempPixeMap.get());
691     result = SceneInputManager::GetInstance().CheckNeedUpdate(displayInfos, windowInfoList);
692     ASSERT_TRUE(result);
693     windowInfoList[0].pixelMap = nullptr;
694 
695     windowInfoList[0].windowInputType = MMI::WindowInputType::TRANSMIT_ALL;
696     result = SceneInputManager::GetInstance().CheckNeedUpdate(displayInfos, windowInfoList);
697     ASSERT_TRUE(result);
698     windowInfoList[0].windowInputType = SceneInputManager::GetInstance().lastWindowInfoList_[0].windowInputType;
699 
700     windowInfoList[0].windowType = static_cast<int32_t>(WindowType::WINDOW_TYPE_APP_COMPONENT);
701     result = SceneInputManager::GetInstance().CheckNeedUpdate(displayInfos, windowInfoList);
702     ASSERT_TRUE(result);
703     windowInfoList[0].windowType = SceneInputManager::GetInstance().lastWindowInfoList_[0].windowType;
704 
705     windowInfoList[0].privacyMode = MMI::SecureFlag::PRIVACY_MODE;
706     result = SceneInputManager::GetInstance().CheckNeedUpdate(displayInfos, windowInfoList);
707     ASSERT_TRUE(result);
708     windowInfoList[0].privacyMode = SceneInputManager::GetInstance().lastWindowInfoList_[0].privacyMode;
709 }
710 
711 /**
712  * @tc.name: UpdateSecSurfaceInfo
713  * @tc.desc: UpdateSecSurfaceInfo
714  * @tc.type: FUNC
715  */
716 HWTEST_F(SceneInputManagerTest, UpdateSecSurfaceInfo, Function | SmallTest | Level3)
717 {
718     int ret = 0;
719     std::map<uint64_t, std::vector<SecSurfaceInfo>> emptyMap;
720     auto oldDirty = SceneInputManager::GetInstance().sceneSessionDirty_;
721     ASSERT_NE(oldDirty, nullptr);
722     SceneInputManager::GetInstance().sceneSessionDirty_ = nullptr;
723     SceneInputManager::GetInstance().UpdateSecSurfaceInfo(emptyMap);
724     ASSERT_EQ(ret, 0);
725 
726     SceneInputManager::GetInstance().sceneSessionDirty_ = oldDirty;
727     SceneInputManager::GetInstance().UpdateSecSurfaceInfo(emptyMap);
728     ASSERT_EQ(ret, 0);
729 }
730 
731 /**
732  * @tc.name: UpdateDisplayAndWindowInfo
733  * @tc.desc: UpdateDisplayAndWindowInfo
734  * @tc.type: FUNC
735  */
736 HWTEST_F(SceneInputManagerTest, UpdateDisplayAndWindowInfo, Function | SmallTest | Level3)
737 {
738     int ret = 0;
739     std::vector<MMI::DisplayInfo> displayInfos;
740     std::vector<MMI::WindowInfo> windowInfoList;
741     MMI::DisplayInfo displayinfo;
742     displayInfos.emplace_back(displayinfo);
743     SceneInputManager::GetInstance().UpdateDisplayAndWindowInfo(displayInfos, windowInfoList);
744     MMI::WindowInfo windowinfo;
745     windowInfoList.emplace_back(windowinfo);
746     windowinfo.defaultHotAreas = std::vector<MMI::Rect>(MMI::WindowInfo::DEFAULT_HOTAREA_COUNT + 1);
747     SceneInputManager::GetInstance().UpdateDisplayAndWindowInfo(displayInfos, windowInfoList);
748     windowinfo.defaultHotAreas = std::vector<MMI::Rect>();
749     windowInfoList = std::vector<MMI::WindowInfo>(MAX_WINDOWINFO_NUM - 1);
750     SceneInputManager::GetInstance().UpdateDisplayAndWindowInfo(displayInfos, windowInfoList);
751     windowInfoList = std::vector<MMI::WindowInfo>(MAX_WINDOWINFO_NUM + 1);
752     SceneInputManager::GetInstance().UpdateDisplayAndWindowInfo(displayInfos, windowInfoList);
753     windowInfoList[0].defaultHotAreas.resize(MMI::WindowInfo::DEFAULT_HOTAREA_COUNT + 1);
754     SceneInputManager::GetInstance().UpdateDisplayAndWindowInfo(displayInfos, windowInfoList);
755     ASSERT_EQ(ret, 0);
756 }
757 
758 /**
759  * @tc.name: FlushEmptyInfoToMMI
760  * @tc.desc: FlushEmptyInfoToMMI
761  * @tc.type: FUNC
762  */
763 HWTEST_F(SceneInputManagerTest, FlushEmptyInfoToMMI, Function | SmallTest | Level3)
764 {
765     int ret = 0;
766     auto preEventHandler = SceneInputManager::GetInstance().eventHandler_;
767     SceneInputManager::GetInstance().eventHandler_ = nullptr;
768     SceneInputManager::GetInstance().FlushEmptyInfoToMMI();
769     SceneInputManager::GetInstance().eventHandler_ = preEventHandler;
770     ASSERT_EQ(ret, 0);
771 }
772 }
773 }
774 }