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