1 /* 2 * Copyright (c) 2021-2022 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 <cstdio> 17 #include <fstream> 18 #include <gtest/gtest.h> 19 20 #include "input_windows_manager.h" 21 #include "mmi_log.h" 22 #include "uds_server.h" 23 #include "scene_board_judgement.h" 24 25 namespace OHOS { 26 namespace MMI { 27 namespace { 28 using namespace testing::ext; 29 } // namespace 30 31 class InputWindowsManagerTest : public testing::Test { 32 public: SetUpTestCase(void)33 static void SetUpTestCase(void) {}; TearDownTestCase(void)34 static void TearDownTestCase(void) {}; SetUp(void)35 void SetUp(void) 36 { 37 // 创建displayGroupInfo_ 38 DisplayGroupInfo displayGroupInfo; 39 displayGroupInfo.width = 20; 40 displayGroupInfo.height = 20; 41 displayGroupInfo.focusWindowId = 1; 42 uint32_t num = 1; 43 for (uint32_t i = 0; i < num; i++) { 44 WindowInfo info; 45 info.id = 1; 46 info.pid = 1; 47 info.uid = 1; 48 info.area = {1, 1, 1, 1}; 49 info.defaultHotAreas = { info.area }; 50 info.pointerHotAreas = { info.area }; 51 info.agentWindowId = 1; 52 info.flags = 1; 53 info.transform = {1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f}; 54 info.pointerChangeAreas = { 1, 2, 1, 2, 1, 2, 1, 2, 1 }; 55 displayGroupInfo.windowsInfo.push_back(info); 56 } 57 for (uint32_t i = 0; i < num; i++) { 58 DisplayInfo info; 59 info.id = 1; 60 info.x =1; 61 info.y = 1; 62 info.width = 2; 63 info.height = 2; 64 info.dpi = 240; 65 info.name = "pp"; 66 info.uniq = "pp"; 67 info.direction = DIRECTION0; 68 displayGroupInfo.displaysInfo.push_back(info); 69 } 70 WinMgr->UpdateDisplayInfo(displayGroupInfo); 71 preHoverScrollState_ = WinMgr->GetHoverScrollState(); 72 } // void SetUp(void) 73 TearDown(void)74 void TearDown(void) 75 { 76 WinMgr->SetHoverScrollState(preHoverScrollState_); 77 } 78 79 private: 80 bool preHoverScrollState_ { true }; 81 }; 82 83 84 /** 85 * @tc.name: InputWindowsManagerTest_GetClientFd_001 86 * @tc.desc: Test GetClientFd 87 * @tc.type: FUNC 88 * @tc.require: 89 */ 90 HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_GetClientFd_001, TestSize.Level1) 91 { 92 auto pointerEvent = PointerEvent::Create(); 93 UDSServer udsServer; 94 WinMgr->Init(udsServer); 95 WinMgr->GetDisplayGroupInfo(); 96 int32_t idNames = -1; 97 ASSERT_EQ(WinMgr->GetClientFd(pointerEvent), idNames); 98 } 99 100 /** 101 * @tc.name: InputWindowsManagerTest_GetPidAndUpdateTarget_002 102 * @tc.desc: Test GetPidAndUpdateTarget 103 * @tc.type: FUNC 104 * @tc.require: 105 */ 106 HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_GetPidAndUpdateTarget_002, TestSize.Level1) 107 { 108 UDSServer udsServer; 109 WinMgr->Init(udsServer); 110 auto keyEvent = KeyEvent::Create(); 111 ASSERT_NE(keyEvent, nullptr); 112 keyEvent->SetDeviceId(1); 113 keyEvent->SetTargetWindowId(1); 114 keyEvent->SetAgentWindowId(1); 115 ASSERT_EQ(WinMgr->GetPidAndUpdateTarget(keyEvent), 1); 116 } 117 118 /** 119 * @tc.name: InputWindowsManagerTest_UpdateTarget_003 120 * @tc.desc: Test UpdateTarget 121 * @tc.type: FUNC 122 * @tc.require: 123 */ 124 HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_UpdateTarget_003, TestSize.Level1) 125 { 126 UDSServer udsServer; 127 WinMgr->Init(udsServer); 128 auto keyEvent = KeyEvent::Create(); 129 ASSERT_NE(keyEvent, nullptr); 130 keyEvent->SetDeviceId(1); 131 keyEvent->SetTargetWindowId(1); 132 keyEvent->SetAgentWindowId(1); 133 ASSERT_EQ(WinMgr->UpdateTarget(keyEvent), -1); 134 } 135 136 /** 137 * @tc.name: InputWindowsManagerTest_UpdateDisplayId_004 138 * @tc.desc: Test UpdateDisplayId 139 * @tc.type: FUNC 140 * @tc.require: 141 */ 142 HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_UpdateDisplayId_004, TestSize.Level1) 143 { 144 // 创建displayGroupInfo_ 145 DisplayGroupInfo displayGroupInfo; 146 displayGroupInfo.width = 20; 147 displayGroupInfo.height = 20; 148 displayGroupInfo.focusWindowId = 1; 149 uint32_t num = 1; 150 for (uint32_t i = 0; i < num; i++) { 151 WindowInfo info; 152 info.id = 1; 153 info.pid = 1; 154 info.uid = 1; 155 info.area = {1, 1, 1, 1}; 156 info.defaultHotAreas = { info.area }; 157 info.pointerHotAreas = { info.area }; 158 info.agentWindowId = 1; 159 info.pointerChangeAreas = { 1, 2, 1, 2, 1, 2, 1, 2, 1 }; 160 info.transform = {1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f}; 161 info.flags = 1; 162 displayGroupInfo.windowsInfo.push_back(info); 163 } 164 165 for (uint32_t i = 0; i < num; i++) { 166 DisplayInfo info; 167 info.id = 1; 168 info.x =1; 169 info.y = 1; 170 info.width = 2; 171 info.height = 2; 172 info.dpi = 240; 173 info.name = "pp"; 174 info.uniq = "pp"; 175 info.direction = DIRECTION0; 176 displayGroupInfo.displaysInfo.push_back(info); 177 } 178 WinMgr->UpdateDisplayInfo(displayGroupInfo); 179 180 UDSServer udsServer; 181 WinMgr->Init(udsServer); 182 WinMgr->UpdateDisplayInfo(displayGroupInfo); 183 int32_t displayId= 1; 184 double x = 0; 185 double y = 0; 186 WinMgr->UpdateAndAdjustMouseLocation(displayId, x, y); 187 ASSERT_EQ(WinMgr->UpdateDisplayId(displayId), true); 188 displayId= -1; 189 WinMgr->UpdateAndAdjustMouseLocation(displayId, x, y); 190 ASSERT_EQ(WinMgr->UpdateDisplayId(displayId), true); 191 } 192 193 /** 194 * @tc.name: InputWindowsManagerTest_UpdateWindow_001 195 * @tc.desc: Test UpdateWindow 196 * @tc.type: FUNC 197 * @tc.require: 198 */ 199 HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_UpdateWindow_001, TestSize.Level1) 200 { 201 WindowInfo window; 202 window.id = 11; 203 window.pid = 1221; 204 window.uid = 1; 205 window.area = {1, 1, 1, 1}; 206 window.defaultHotAreas = { window.area }; 207 window.pointerHotAreas = { window.area }; 208 window.pointerChangeAreas = {1, 2, 1, 2}; 209 window.displayId = 0; 210 window.agentWindowId = 1; 211 window.flags = 1; 212 window.action = WINDOW_UPDATE_ACTION::ADD; 213 window.transform = {1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f}; 214 WinMgr->UpdateWindowInfo({0, 11, {window}}); 215 ASSERT_EQ(WinMgr->GetWindowPid(11), 1221); 216 217 window.action = WINDOW_UPDATE_ACTION::CHANGE; 218 window.pid = 1222; 219 WinMgr->UpdateWindowInfo({0, 11, {window}}); 220 ASSERT_EQ(WinMgr->GetWindowPid(11), 1222); 221 222 window.action = WINDOW_UPDATE_ACTION::DEL; 223 WinMgr->UpdateWindowInfo({0, 11, {window}}); 224 ASSERT_EQ(WinMgr->GetWindowPid(11), -1); 225 } 226 227 /** 228 * @tc.name: InputWindowsManagerTest_UpdateWindow_002 229 * @tc.desc: Test UpdateWindow 230 * @tc.type: FUNC 231 * @tc.require: 232 */ 233 HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_UpdateWindow_002, TestSize.Level1) 234 { 235 WindowInfo window; 236 window.id = 11; 237 window.pid = 1221; 238 window.uid = 1; 239 window.area = {1, 1, 1, 1}; 240 window.defaultHotAreas = { window.area }; 241 window.pointerHotAreas = { window.area }; 242 window.pointerChangeAreas = {1, 2, 1, 2}; 243 window.displayId = 0; 244 window.agentWindowId = 1; 245 window.flags = 1; 246 window.action = WINDOW_UPDATE_ACTION::UNKNOWN; 247 WinMgr->UpdateWindowInfo({0, 11, {window}}); 248 ASSERT_EQ(WinMgr->GetWindowPid(11), -1); 249 } 250 251 /** 252 * @tc.name: InputWindowsManagerTest_UpdateTargetPointer_005 253 * @tc.desc: Test UpdateTargetPointer 254 * @tc.type: FUNC 255 * @tc.require: 256 */ 257 HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_UpdateTargetPointer_005, TestSize.Level1) 258 { 259 UDSServer udsServer; 260 WinMgr->Init(udsServer); 261 auto pointerEvent = PointerEvent::Create(); 262 ASSERT_EQ(WinMgr->UpdateTargetPointer(pointerEvent), -1); 263 } 264 265 /** 266 * @tc.name: InputWindowsManagerTest_IsNeedRefreshLayer_006 267 * @tc.desc: Test IsNeedRefreshLayer 268 * @tc.type: FUNC 269 * @tc.require: 270 */ 271 HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_IsNeedRefreshLayer_006, TestSize.Level1) 272 { 273 UDSServer udsServer; 274 WinMgr->Init(udsServer); 275 if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { 276 ASSERT_EQ(WinMgr->IsNeedRefreshLayer(-1), true); 277 ASSERT_EQ(WinMgr->IsNeedRefreshLayer(0), true); 278 ASSERT_EQ(WinMgr->IsNeedRefreshLayer(1), true); 279 } else { 280 ASSERT_EQ(WinMgr->IsNeedRefreshLayer(-1), false); 281 ASSERT_EQ(WinMgr->IsNeedRefreshLayer(0), false); 282 ASSERT_EQ(WinMgr->IsNeedRefreshLayer(1), false); 283 } 284 } 285 286 /** 287 * @tc.name: InputWindowsManagerTest_GetWindowPid_007 288 * @tc.desc: Test GetWindowPid 289 * @tc.type: FUNC 290 * @tc.require: 291 */ 292 HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_GetWindowPid_002, TestSize.Level1) 293 { 294 UDSServer udsServer; 295 WinMgr->Init(udsServer); 296 ASSERT_EQ(WinMgr->GetWindowPid(1), 1); 297 ASSERT_EQ(WinMgr->GetWindowPid(2), -1); 298 } 299 300 301 /** 302 * @tc.name: InputWindowsManagerTest_SetMouseCaptureMode_008 303 * @tc.desc: Test SetMouseCaptureMode 304 * @tc.type: FUNC 305 * @tc.require: 306 */ 307 HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_SetMouseCaptureMode_008, TestSize.Level1) 308 { 309 UDSServer udsServer; 310 WinMgr->Init(udsServer); 311 bool isCaptureMode = false; 312 ASSERT_EQ(WinMgr->SetMouseCaptureMode(-1, isCaptureMode), -1); 313 ASSERT_EQ(WinMgr->SetMouseCaptureMode(1, isCaptureMode), 0); 314 isCaptureMode = true; 315 ASSERT_EQ(WinMgr->SetMouseCaptureMode(1, isCaptureMode), 0); 316 } 317 318 /** 319 * @tc.name: InputWindowsManagerTest_SetDisplayBind_009 320 * @tc.desc: Test SetDisplayBind 321 * @tc.type: FUNC 322 * @tc.require: 323 */ 324 HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_SetDisplayBind_009, TestSize.Level1) 325 { 326 UDSServer udsServer; 327 WinMgr->Init(udsServer); 328 std::string sysUid = "james"; 329 std::string devStatus = "add"; 330 WinMgr->DeviceStatusChanged(2, sysUid, devStatus); 331 devStatus = "remove"; 332 WinMgr->DeviceStatusChanged(2, sysUid, devStatus); 333 std::string msg = "There is in InputWindowsManagerTest_GetDisplayIdNames_009"; 334 ASSERT_EQ(WinMgr->SetDisplayBind(-1, 1, msg), -1); 335 } 336 337 /** 338 * @tc.name: InputWindowsManagerTest_SetHoverScrollState_010 339 * @tc.desc: Test SetHoverScrollState 340 * @tc.type: FUNC 341 * @tc.require: 342 */ 343 HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_SetHoverScrollState_010, TestSize.Level1) 344 { 345 ASSERT_TRUE(WinMgr->SetHoverScrollState(false) == RET_OK); 346 WinMgr->SetHoverScrollState(true); 347 } 348 349 /** 350 * @tc.name: InputWindowsManagerTest_GetHoverScrollState_011 351 * @tc.desc: Test GetHoverScrollState 352 * @tc.type: FUNC 353 * @tc.require: 354 */ 355 HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_GetHoverScrollState_011, TestSize.Level1) 356 { 357 WinMgr->SetHoverScrollState(true); 358 ASSERT_TRUE(WinMgr->GetHoverScrollState()); 359 } 360 } // namespace MMI 361 } // namespace OHOS 362