1 /*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <gtest/gtest.h>
17
18 #include "cJSON.h"
19 #include "util.h"
20
21 #include "ability_manager_client.h"
22 #include "common_event_support.h"
23 #include "display_event_monitor.h"
24 #include "event_log_helper.h"
25 #include "gesturesense_wrapper.h"
26 #include "input_event_handler.h"
27 #include "input_handler_type.h"
28 #include "input_windows_manager.h"
29 #include "i_preference_manager.h"
30 #include "key_command_handler.h"
31 #include "key_shortcut_manager.h"
32 #include "mmi_log.h"
33 #include "multimodal_event_handler.h"
34 #include "multimodal_input_preferences_manager.h"
35 #include "system_info.h"
36 #include "stylus_key_handler.h"
37
38 #undef MMI_LOG_TAG
39 #define MMI_LOG_TAG "KeyCommandHandlerTest"
40
41 namespace OHOS {
42 namespace MMI {
43 namespace {
44 using namespace testing::ext;
45 constexpr int32_t NANOSECOND_TO_MILLISECOND = 1000000;
46 constexpr int32_t SEC_TO_NANOSEC = 1000000000;
47 constexpr int32_t COMMON_PARAMETER_ERROR = 401;
48 constexpr int32_t INTERVAL_TIME = 100;
49 constexpr int32_t INTERVAL_TIME_OUT = 500000;
50 constexpr int32_t ERROR_DELAY_VALUE = -1000;
51 constexpr int64_t DOUBLE_CLICK_INTERVAL_TIME_DEFAULT = 250000;
52 constexpr int32_t TWO_FINGERS_TIME_LIMIT = 150000;
53 constexpr int32_t TWO_FINGERS_DISTANCE_LIMIT = 16;
54 constexpr int32_t TOUCH_LIFT_LIMIT = 24;
55 constexpr int32_t TOUCH_RIGHT_LIMIT = 24;
56 constexpr int32_t TOUCH_TOP_LIMIT = 80;
57 constexpr int32_t TOUCH_BOTTOM_LIMIT = 41;
58 constexpr int32_t MAX_SHORT_KEY_DOWN_DURATION = 4000;
59 constexpr int32_t MIN_SHORT_KEY_DOWN_DURATION = 0;
60 constexpr int64_t DOUBLE_CLICK_INTERVAL_TIME_SLOW = 450000;
61 constexpr float DOUBLE_CLICK_DISTANCE_DEFAULT_CONFIG = 64.0;
62 constexpr int32_t WINDOW_INPUT_METHOD_TYPE = 2105;
63 const std::string EXTENSION_ABILITY = "extensionAbility";
64 const std::string EXTENSION_ABILITY_ABNORMAL = "extensionAbilityAbnormal";
65 const std::string SOS_BUNDLE_NAME { "com.hmos.emergencycommunication" };
66 const std::string SCREENRECORDER_BUNDLE_NAME { "com.hmos.screenrecorder" };
67 const vector<float> CIRCLE_COORDINATES = {
68 328.0f, 596.0f, 328.0f, 597.0f, 322.0f, 606.0f,
69 306.0f, 635.0f, 291.0f, 665.0f, 283.0f, 691.0f,
70 291.0f, 739.0f, 300.0f, 751.0f, 312.0f, 759.0f,
71 327.0f, 765.0f, 343.0f, 768.0f, 361.0f, 769.0f,
72 379.0f, 767.0f, 395.0f, 761.0f, 411.0f, 751.0f,
73 425.0f, 737.0f, 439.0f, 718.0f, 449.0f, 709.0f,
74 456.0f, 683.0f, 459.0f, 654.0f, 451.0f, 569.0f,
75 437.0f, 552.0f, 418.0f, 542.0f, 392.0f, 540.0f,
76 363.0f, 545.0f };
77 const vector<int64_t> CIRCLE_TIMESTAMPS = {
78 71304451, 71377126, 71387783, 71398239, 71409629,
79 71419392, 71461386, 71472044, 71483797, 71493077,
80 71503426, 71514339, 71524715, 71535126, 71545652,
81 71556329, 71566506, 71577283, 71587745, 71598921,
82 71630319, 71642155, 71651090, 71662474, 71671657 };
83 const vector<float> CURVE_COORDINATES = {
84 374.0f, 489.0f, 373.0f, 489.0f, 365.0f, 491.0f,
85 341.0f, 503.0f, 316.0f, 519.0f, 300.0f, 541.0f,
86 293.0f, 561.0f, 289.0f, 582.0f, 292.0f, 643.0f,
87 301.0f, 657.0f, 317.0f, 668.0f, 336.0f, 681.0f,
88 358.0f, 695.0f, 381.0f, 706.0f, 403.0f, 717.0f,
89 423.0f, 715.0f, 441.0f, 727.0f, 458.0f, 739.0f,
90 468.0f, 751.0f, 474.0f, 764.0f, 467.0f, 812.0f,
91 455.0f, 828.0f, 435.0f, 844.0f, 412.0f, 860.0f,
92 387.0f, 876.0f, 362.0f, 894.0f, 338.0f, 906.0f,
93 317.0f, 913.0f, 296.0f, 918.0f };
94 const vector<int64_t> CURVE_TIMESTAMPS = {
95 134900436, 134951403, 134962832, 134973234,
96 134983492, 134995390, 135003876, 135014389,
97 135045917, 135057774, 135067076, 135077688,
98 135088139, 135098494, 135109130, 135119679,
99 135130101, 135140670, 135151182, 135161672,
100 135193739, 135203790, 135214272, 135224868,
101 135236197, 135245828, 135256481, 135267186,
102 135276939 };
103 const vector<float> LINE_COORDINATES = {
104 390.0f, 340.0f, 390.0f, 348.0f, 390.0f, 367.0f,
105 387.0f, 417.0f, 385.0f, 455.0f, 384.0f, 491.0f,
106 382.0f, 516.0f, 381.0f, 539.0f, 380.0f, 564.0f,
107 378.0f, 589.0f, 377.0f, 616.0f, 376.0f, 643.0f,
108 375.0f, 669.0f, 375.0f, 694.0f, 374.0f, 718.0f,
109 374.0f, 727.0f, 374.0f, 750.0f, 374.0f, 771.0f,
110 374.0f, 791.0f, 374.0f, 811.0f, 375.0f, 831.0f,
111 375.0f, 851.0f, 376.0f, 870.0f, 377.0f, 886.0f,
112 377.0f, 902.0f, 379.0f, 918.0f, 379.0f, 934.0f,
113 380.0f, 950.0f, 381.0f, 963.0f, 383.0f, 977.0f,
114 385.0f, 992.0f, 387.0f, 1002.0f, 389.0f, 1016.0f,
115 390.0f, 1030.0f, 390.0f, 1042.0f, 390.0f, 1052.0f,
116 390.0f, 1061.0f, 391.0f, 1069.0f, 391.0f, 1075.0f,
117 391.0f, 1080.0f, 391.0f, 1085.0f, 391.0f, 1089.0f,
118 392.0f, 1095.0f, 393.0f, 1099.0f, 394.0f, 1103.0f,
119 395.0f, 1111.0f, 395.0f, 1117.0f, 396.0f, 1124.0f,
120 397.0f, 1130.0f, 397.0f, 1134.0f, 397.0f, 1138.0f };
121 const vector<int64_t> LINE_TIMESTAMPS = {
122 70809086, 70912930, 70923294, 70933960,
123 70944571, 70955130, 70965726, 70976076,
124 70986620, 70997190, 71007517, 71017998,
125 71028551, 71039171, 71049654, 71060120,
126 71070809, 71082130, 71091709, 71102285,
127 71112746, 71123402, 71133898, 71144469,
128 71154894, 71165617, 71175944, 71186477,
129 71197199, 71207737, 71218030, 71228652,
130 71239243, 71249733, 71260291, 71270821,
131 71281313, 71291919, 71302477, 71313573,
132 71323426, 71333880, 71355034, 71376110,
133 71418297, 71439219, 71449749, 71460268,
134 71470874, 71481275, 71744747 };
135 } // namespace
136 class KeyCommandHandlerTest : public testing::Test {
137 public:
SetUpTestCase(void)138 static void SetUpTestCase(void) {}
TearDownTestCase(void)139 static void TearDownTestCase(void) {}
140 std::shared_ptr<KeyEvent> SetupKeyEvent();
141 std::shared_ptr<PointerEvent> SetupThreeFingerTapEvent();
142 std::shared_ptr<PointerEvent> SetupFourFingerTapEvent();
143 #ifdef OHOS_BUILD_ENABLE_TOUCH
144 std::shared_ptr<PointerEvent> SetupDoubleFingerDownEvent();
145 std::shared_ptr<PointerEvent> SetupSingleKnuckleDownEvent();
146 std::shared_ptr<PointerEvent> SetupDoubleKnuckleDownEvent();
147 #endif // OHOS_BUILD_ENABLE_TOUCH
148 };
149
GetNanoTime()150 int64_t GetNanoTime()
151 {
152 struct timespec time = { 0 };
153 clock_gettime(CLOCK_MONOTONIC, &time);
154 return static_cast<int64_t>(time.tv_sec) * SEC_TO_NANOSEC + time.tv_nsec;
155 }
156
SetupKeyEvent()157 std::shared_ptr<KeyEvent> KeyCommandHandlerTest::SetupKeyEvent()
158 {
159 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
160 CHKPP(keyEvent);
161 int64_t downTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND;
162 KeyEvent::KeyItem kitDown;
163 kitDown.SetKeyCode(KeyEvent::KEYCODE_HOME);
164 kitDown.SetPressed(true);
165 kitDown.SetDownTime(downTime);
166 keyEvent->SetKeyCode(KeyEvent::KEYCODE_HOME);
167 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
168 keyEvent->AddPressedKeyItems(kitDown);
169
170 return keyEvent;
171 }
172
173 #ifdef OHOS_BUILD_ENABLE_TOUCH
SetupDoubleFingerDownEvent()174 std::shared_ptr<PointerEvent> KeyCommandHandlerTest::SetupDoubleFingerDownEvent()
175 {
176 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
177 CHKPP(pointerEvent);
178 PointerEvent::PointerItem item;
179 PointerEvent::PointerItem item2;
180 item.SetPointerId(0);
181 item.SetToolType(PointerEvent::TOOL_TYPE_FINGER);
182 int32_t downX = 100;
183 int32_t downY = 200;
184 item.SetDisplayX(downX);
185 item.SetDisplayY(downY);
186 item.SetPressed(true);
187 pointerEvent->SetPointerId(0);
188 pointerEvent->AddPointerItem(item);
189
190 item2.SetPointerId(1);
191 item2.SetToolType(PointerEvent::TOOL_TYPE_FINGER);
192 int32_t secondDownX = 120;
193 int32_t secondDownY = 220;
194 item2.SetDisplayX(secondDownX);
195 item2.SetDisplayY(secondDownY);
196 item2.SetPressed(true);
197 pointerEvent->SetPointerId(1);
198 pointerEvent->AddPointerItem(item2);
199 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
200 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
201 return pointerEvent;
202 }
203
SetupSingleKnuckleDownEvent()204 std::shared_ptr<PointerEvent> KeyCommandHandlerTest::SetupSingleKnuckleDownEvent()
205 {
206 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
207 CHKPP(pointerEvent);
208 PointerEvent::PointerItem item;
209 item.SetPointerId(0);
210 item.SetToolType(PointerEvent::TOOL_TYPE_KNUCKLE);
211 int32_t downX = 100;
212 int32_t downY = 200;
213 item.SetDisplayX(downX);
214 item.SetDisplayY(downY);
215 item.SetPressed(true);
216 pointerEvent->SetPointerId(0);
217 pointerEvent->AddPointerItem(item);
218 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
219 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
220 return pointerEvent;
221 }
222
SetupDoubleKnuckleDownEvent()223 std::shared_ptr<PointerEvent> KeyCommandHandlerTest::SetupDoubleKnuckleDownEvent()
224 {
225 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
226 CHKPP(pointerEvent);
227 PointerEvent::PointerItem item;
228 PointerEvent::PointerItem item2;
229 item.SetPointerId(0);
230 item.SetToolType(PointerEvent::TOOL_TYPE_KNUCKLE);
231 int32_t downX = 100;
232 int32_t downY = 200;
233 item.SetDisplayX(downX);
234 item.SetDisplayY(downY);
235 item.SetPressed(true);
236 pointerEvent->SetPointerId(0);
237 pointerEvent->AddPointerItem(item);
238
239 item2.SetPointerId(1);
240 item2.SetToolType(PointerEvent::TOOL_TYPE_KNUCKLE);
241 int32_t secondDownX = 120;
242 int32_t secondDownY = 220;
243 item2.SetDisplayX(secondDownX);
244 item2.SetDisplayY(secondDownY);
245 item2.SetPressed(true);
246 pointerEvent->SetPointerId(1);
247 pointerEvent->AddPointerItem(item2);
248 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
249 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
250 return pointerEvent;
251 }
252 #endif // OHOS_BUILD_ENABLE_TOUCH
253
SetupThreeFingerTapEvent()254 std::shared_ptr<PointerEvent> KeyCommandHandlerTest::SetupThreeFingerTapEvent()
255 {
256 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
257 CHKPP(pointerEvent);
258 PointerEvent::PointerItem item1;
259 PointerEvent::PointerItem item2;
260 PointerEvent::PointerItem item3;
261
262 int32_t id0 = 0;
263 item1.SetPointerId(id0);
264 int32_t downX1 = 100;
265 int32_t downY1 = 200;
266 int64_t actionTime1 = 1000000;
267 item1.SetDisplayX(downX1);
268 item1.SetDisplayY(downY1);
269 item1.SetDownTime(actionTime1);
270 pointerEvent->SetPointerId(id0);
271 pointerEvent->AddPointerItem(item1);
272
273 int32_t id1 = 1;
274 item2.SetPointerId(id1);
275 int32_t downX2 = 200;
276 int32_t downY2 = 300;
277 int64_t actionTime2 = 1000100;
278 item2.SetDisplayX(downX2);
279 item2.SetDisplayY(downY2);
280 item2.SetDownTime(actionTime2);
281 pointerEvent->SetPointerId(id1);
282 pointerEvent->AddPointerItem(item2);
283
284 int32_t id2 = 2;
285 item3.SetPointerId(id2);
286 int32_t downX3 = 100;
287 int32_t downY3 = 200;
288 int64_t actionTime3 = 1000200;
289 item3.SetDisplayX(downX3);
290 item3.SetDisplayY(downY3);
291 item3.SetDownTime(actionTime3);
292 pointerEvent->SetPointerId(id2);
293 pointerEvent->AddPointerItem(item3);
294
295 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_TRIPTAP);
296 return pointerEvent;
297 }
298
SetupFourFingerTapEvent()299 std::shared_ptr<PointerEvent> KeyCommandHandlerTest::SetupFourFingerTapEvent()
300 {
301 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
302 CHKPP(pointerEvent);
303 PointerEvent::PointerItem item1;
304 PointerEvent::PointerItem item2;
305 PointerEvent::PointerItem item3;
306 PointerEvent::PointerItem item4;
307
308 int32_t id0 = 0;
309 item1.SetPointerId(id0);
310 int32_t downX1 = 100;
311 int32_t downY1 = 200;
312 int64_t actionTime1 = 1000000;
313 item1.SetDisplayX(downX1);
314 item1.SetDisplayY(downY1);
315 item1.SetDownTime(actionTime1);
316 pointerEvent->SetPointerId(id0);
317 pointerEvent->AddPointerItem(item1);
318
319 int32_t id1 = 1;
320 item2.SetPointerId(id1);
321 int32_t downX2 = 200;
322 int32_t downY2 = 300;
323 int64_t actionTime2 = 1000100;
324 item2.SetDisplayX(downX2);
325 item2.SetDisplayY(downY2);
326 item2.SetDownTime(actionTime2);
327 pointerEvent->SetPointerId(id1);
328 pointerEvent->AddPointerItem(item2);
329
330 int32_t id2 = 2;
331 item3.SetPointerId(id2);
332 int32_t downX3 = 100;
333 int32_t downY3 = 200;
334 int64_t actionTime3 = 1000200;
335 item3.SetDisplayX(downX3);
336 item3.SetDisplayY(downY3);
337 item3.SetDownTime(actionTime3);
338 pointerEvent->SetPointerId(id2);
339 pointerEvent->AddPointerItem(item3);
340
341 int32_t id3 = 3;
342 item4.SetPointerId(id3);
343 int32_t downX4 = 400;
344 int32_t downY4 = 280;
345 int64_t actionTime4 = 1000300;
346 item4.SetDisplayX(downX4);
347 item4.SetDisplayY(downY4);
348 item4.SetDownTime(actionTime4);
349 pointerEvent->SetPointerId(id3);
350 pointerEvent->AddPointerItem(item4);
351
352 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_QUADTAP);
353 return pointerEvent;
354 }
355
356 /**
357 * @tc.name: KeyCommandHandlerTest_CheckAndUpdateTappingCountAtDown_01
358 * @tc.desc: Test CheckAndUpdateTappingCountAtDown
359 * @tc.type: Function
360 * @tc.require:
361 */
362 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckAndUpdateTappingCountAtDown_01, TestSize.Level1)
363 {
364 CALL_TEST_DEBUG;
365 KeyCommandHandler handler;
366 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
367 ASSERT_NE(pointerEvent, nullptr);
368 pointerEvent->actionTime_ = 10000;
369 handler.lastDownTime_ = 15000;
370 ASSERT_NO_FATAL_FAILURE(handler.CheckAndUpdateTappingCountAtDown(pointerEvent));
371
372 pointerEvent->actionTime_ = 800000;
373 handler.lastDownTime_ = 200000;
374 ASSERT_NO_FATAL_FAILURE(handler.CheckAndUpdateTappingCountAtDown(pointerEvent));
375 }
376
377 /**
378 * @tc.name: KeyCommandHandlerTest_CheckAndUpdateTappingCountAtDown_02
379 * @tc.desc: Test CheckAndUpdateTappingCountAtDown
380 * @tc.type: Function
381 * @tc.require:
382 */
383 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckAndUpdateTappingCountAtDown_02, TestSize.Level1)
384 {
385 CALL_TEST_DEBUG;
386 KeyCommandHandler handler;
387 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
388 ASSERT_NE(pointerEvent, nullptr);
389
390 pointerEvent->actionTime_ = 800000;
391 handler.lastDownTime_ = 500000;
392 handler.previousUpTime_ = 850000;
393 handler.downToPrevUpTimeConfig_ = 0;
394 handler.tappingCount_ = 2;
395 ASSERT_NO_FATAL_FAILURE(handler.CheckAndUpdateTappingCountAtDown(pointerEvent));
396
397 handler.tappingCount_ = 5;
398 ASSERT_NO_FATAL_FAILURE(handler.CheckAndUpdateTappingCountAtDown(pointerEvent));
399 }
400
401 /**
402 * @tc.name: KeyCommandHandlerTest_MatchShortcutKey_002
403 * @tc.desc: Test the funcation MatchShortcutKey
404 * @tc.type: FUNC
405 * @tc.require:
406 */
407 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_MatchShortcutKey_002, TestSize.Level1)
408 {
409 KeyCommandHandler handler;
410 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
411 ASSERT_NE(keyEvent, nullptr);
412 ShortcutKey shortcutKey;
413 std::vector<ShortcutKey> upAbilities;
414 shortcutKey.statusConfigValue = true;
415 shortcutKey.finalKey = -1;
416 shortcutKey.keyDownDuration = 0;
417 EXPECT_FALSE(handler.IsKeyMatch(shortcutKey, keyEvent));
418 EXPECT_FALSE(handler.MatchShortcutKey(keyEvent, shortcutKey, upAbilities));
419
420 shortcutKey.businessId = "V1";
421 int32_t delay = handler.GetKeyDownDurationFromXml(shortcutKey.businessId);
422 delay = 100;
423 EXPECT_TRUE(delay >= MIN_SHORT_KEY_DOWN_DURATION);
424 EXPECT_TRUE(delay <= MAX_SHORT_KEY_DOWN_DURATION);
425 EXPECT_FALSE(handler.MatchShortcutKey(keyEvent, shortcutKey, upAbilities));
426
427 delay = 5000;
428 shortcutKey.triggerType = KeyEvent::KEY_ACTION_DOWN;
429 EXPECT_FALSE(handler.MatchShortcutKey(keyEvent, shortcutKey, upAbilities));
430
431 shortcutKey.triggerType = KeyEvent::KEY_ACTION_UP;
432 EXPECT_FALSE(handler.MatchShortcutKey(keyEvent, shortcutKey, upAbilities));
433 EXPECT_TRUE(handler.HandleKeyUp(keyEvent, shortcutKey));
434 shortcutKey.keyDownDuration = 100;
435 EXPECT_FALSE(handler.MatchShortcutKey(keyEvent, shortcutKey, upAbilities));
436 }
437
438 /**
439 * @tc.name: KeyCommandHandlerTest_TouchPadKnuckleDoubleClickProcess_01
440 * @tc.desc: Test the funcation TouchPadKnuckleDoubleClickProcess
441 * @tc.type: FUNC
442 * @tc.require:
443 */
444 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_TouchPadKnuckleDoubleClickProcess_01, TestSize.Level1)
445 {
446 CALL_TEST_DEBUG;
447 KeyCommandHandler handler;
448 std::string bundleName = "bundleName";
449 std::string abilityName = "abilityName";
450 std::string action = "move";
451
452 DISPLAY_MONITOR->screenStatus_ = EventFwk::CommonEventSupportTest::COMMON_EVENT_SCREEN_OFF;
453 DISPLAY_MONITOR->isScreenLocked_ = true;
454 ASSERT_NO_FATAL_FAILURE(handler.TouchPadKnuckleDoubleClickProcess(bundleName, abilityName, action));
455
456
457 DISPLAY_MONITOR->screenStatus_ = EventFwk::CommonEventSupportTest::COMMON_EVENT_SCREEN_ON;
458 DISPLAY_MONITOR->isScreenLocked_ = true;
459 ASSERT_NO_FATAL_FAILURE(handler.TouchPadKnuckleDoubleClickProcess(bundleName, abilityName, action));
460
461 DISPLAY_MONITOR->screenStatus_ = EventFwk::CommonEventSupportTest::COMMON_EVENT_SCREEN_OFF;
462 DISPLAY_MONITOR->isScreenLocked_ = false;
463 ASSERT_NO_FATAL_FAILURE(handler.TouchPadKnuckleDoubleClickProcess(bundleName, abilityName, action));
464
465 DISPLAY_MONITOR->screenStatus_ = EventFwk::CommonEventSupportTest::COMMON_EVENT_SCREEN_ON;
466 DISPLAY_MONITOR->isScreenLocked_ = false;
467 ASSERT_NO_FATAL_FAILURE(handler.TouchPadKnuckleDoubleClickProcess(bundleName, abilityName, action));
468 }
469
470 /**
471 * @tc.name: KeyCommandHandlerTest_TouchPadKnuckleDoubleClickHandle_01
472 * @tc.desc: Test the funcation TouchPadKnuckleDoubleClickHandle
473 * @tc.type: FUNC
474 * @tc.require:
475 */
476 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_TouchPadKnuckleDoubleClickHandle_01, TestSize.Level1)
477 {
478 CALL_TEST_DEBUG;
479 KeyCommandHandler handler;
480 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
481 ASSERT_NE(keyEvent, nullptr);
482
483 keyEvent->keyAction_ = KNUCKLE_1F_DOUBLE_CLICK;
484 EXPECT_TRUE(handler.TouchPadKnuckleDoubleClickHandle(keyEvent));
485
486 keyEvent->keyAction_ = KNUCKLE_2F_DOUBLE_CLICK;
487 EXPECT_TRUE(handler.TouchPadKnuckleDoubleClickHandle(keyEvent));
488
489 keyEvent->keyAction_ = KeyEvent::KEY_ACTION_UNKNOWN;
490 EXPECT_FALSE(handler.TouchPadKnuckleDoubleClickHandle(keyEvent));
491 }
492
493 /**
494 * @tc.name: KeyCommandHandlerTest_HandleRepeatKeyOwnCount_001
495 * @tc.desc: Test the funcation HandleRepeatKeyOwnCount
496 * @tc.type: FUNC
497 * @tc.require:
498 */
499 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleRepeatKeyOwnCount_001, TestSize.Level1)
500 {
501 CALL_TEST_DEBUG;
502 KeyCommandHandler handler;
503 RepeatKey repeatKey;
504 ASSERT_NO_FATAL_FAILURE(handler.HandleRepeatKeyOwnCount(repeatKey));
505 }
506
507 /**
508 * @tc.name: KeyCommandHandlerTest_HandleRepeatKeyOwnCount_002
509 * @tc.desc: Test the funcation HandleRepeatKeyOwnCount
510 * @tc.type: FUNC
511 * @tc.require:
512 */
513 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleRepeatKeyOwnCount_002, TestSize.Level1)
514 {
515 CALL_TEST_DEBUG;
516 KeyCommandHandler handler;
517 RepeatKey repeatKey;
518 repeatKey.ability.bundleName = SCREENRECORDER_BUNDLE_NAME;
519 handler.downActionTime_ = 600000;
520 handler.upActionTime_ = 800000;
521 ASSERT_NO_FATAL_FAILURE(handler.HandleRepeatKeyOwnCount(repeatKey));
522 }
523
524 /**
525 * @tc.name: KeyCommandHandlerTest_SendKeyEvent_01
526 * @tc.desc: Test the funcation SendKeyEvent
527 * @tc.type: FUNC
528 * @tc.require:
529 */
530 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_SendKeyEvent_01, TestSize.Level1)
531 {
532 CALL_TEST_DEBUG;
533 KeyCommandHandler handler;
534 handler.isHandleSequence_ = false;
535 handler.launchAbilityCount_ = 1;
536 handler.count_ = 10;
537 handler.repeatKey_.keyCode = 18;
538 handler.repeatKeyMaxTimes_[18] = 11;
539 handler.repeatKeyMaxTimes_[2] = 3;
540 ASSERT_NO_FATAL_FAILURE(handler.SendKeyEvent());
541 }
542
543 /**
544 * @tc.name: KeyCommandHandlerTest_SendKeyEvent_02
545 * @tc.desc: Test the funcation SendKeyEvent
546 * @tc.type: FUNC
547 * @tc.require:
548 */
549 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_SendKeyEvent_02, TestSize.Level1)
550 {
551 CALL_TEST_DEBUG;
552 KeyCommandHandler handler;
553 handler.isHandleSequence_ = false;
554 handler.launchAbilityCount_ = 1;
555 handler.count_ = 10;
556 handler.repeatKey_.keyCode = 16;
557 handler.repeatKeyMaxTimes_[16] = 15;
558 handler.repeatKeyMaxTimes_[2] = 3;
559 ASSERT_NO_FATAL_FAILURE(handler.SendKeyEvent());
560 }
561
562 /**
563 * @tc.name: KeyCommandHandlerTest_CheckInputMethodArea_01
564 * @tc.desc: Test the funcation CheckInputMethodArea
565 * @tc.type: FUNC
566 * @tc.require:
567 */
568 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckInputMethodArea_01, TestSize.Level1)
569 {
570 CALL_TEST_DEBUG;
571 KeyCommandHandler handler;
572 std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
573 ASSERT_NE(touchEvent, nullptr);
574
575 touchEvent->targetDisplayId_ = 10;
576 touchEvent->targetWindowId_ = 5;
577 InputWindowsManager inputWindowsManager;
578 WindowGroupInfo windowGroupInfo;
579 WindowInfo window1;
580 window1.windowType = 2100;
581 window1.id = 1;
582 window1.pid = 2;
583 windowGroupInfo.windowsInfo.push_back(window1);
584 inputWindowsManager.windowsPerDisplay_.insert(std::make_pair(1, windowGroupInfo));
585 ASSERT_FALSE(handler.CheckInputMethodArea(touchEvent));
586 }
587
588 /**
589 * @tc.name: KeyCommandHandlerTest_CheckInputMethodArea_02
590 * @tc.desc: Test the funcation CheckInputMethodArea
591 * @tc.type: FUNC
592 * @tc.require:
593 */
594 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckInputMethodArea_02, TestSize.Level1)
595 {
596 CALL_TEST_DEBUG;
597 KeyCommandHandler handler;
598 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
599 ASSERT_NE(pointerEvent, nullptr);
600 pointerEvent->targetDisplayId_ = 10;
601 pointerEvent->targetWindowId_ = 5;
602 PointerEvent::PointerItem item;
603 item.displayX_ = 10;
604 item.displayY_ = 15;
605
606 InputWindowsManager inputWindowsManager;
607 WindowGroupInfo windowGroupInfo;
608 WindowInfo window1;
609 window1.windowType = 2105;
610 window1.id = 1;
611 window1.pid = 2;
612 window1.area.x = 5;
613 window1.area.y = 8;
614 window1.area.width = 20;
615 windowGroupInfo.windowsInfo.push_back(window1);
616 inputWindowsManager.windowsPerDisplay_.insert(std::make_pair(1, windowGroupInfo));
617 ASSERT_FALSE(handler.CheckInputMethodArea(pointerEvent));
618
619 pointerEvent->targetWindowId_ = 1;
620 int32_t rightDownX = 30;
621 int32_t rightDownY = 40;
622 EXPECT_TRUE(item.displayX_ <= rightDownX);
623 EXPECT_TRUE(item.displayY_ <= rightDownY);
624 pointerEvent->pointerAction_ = PointerEvent::POINTER_ACTION_DOWN;
625 ASSERT_FALSE(handler.CheckInputMethodArea(pointerEvent));
626
627 pointerEvent->pointerAction_ = PointerEvent::POINTER_ACTION_UP;
628 ASSERT_FALSE(handler.CheckInputMethodArea(pointerEvent));
629 }
630
631 /**
632 * @tc.name: KeyCommandHandlerTest_ConvertVPToPX_01
633 * @tc.desc: Test the funcation ConvertVPToPX
634 * @tc.type: FUNC
635 * @tc.require:
636 */
637 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_ConvertVPToPX_01, TestSize.Level1)
638 {
639 CALL_TEST_DEBUG;
640 KeyCommandHandler handler;
641 int32_t vp = -1;
642 ASSERT_NO_FATAL_FAILURE(handler.ConvertVPToPX(vp));
643 vp = 1;
644 DisplayInfo displayInfo;
645 displayInfo.dpi = -20;
646 ASSERT_NO_FATAL_FAILURE(handler.ConvertVPToPX(vp));
647
648 displayInfo.dpi = 30;
649 ASSERT_NO_FATAL_FAILURE(handler.ConvertVPToPX(vp));
650 }
651
652 /**
653 * @tc.name: KeyCommandHandlerTest_HandleKnuckleGestureEvent_01
654 * @tc.desc: Test the funcation HandleKnuckleGestureEvent
655 * @tc.type: FUNC
656 * @tc.require:
657 */
658 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureEvent_01, TestSize.Level1)
659 {
660 CALL_TEST_DEBUG;
661 KeyCommandHandler handler;
662 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
663 ASSERT_NE(pointerEvent, nullptr);
664 EXPECT_FALSE(handler.CheckKnuckleCondition(pointerEvent));
665 ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureEvent(pointerEvent));
666 }
667
668 /**
669 * @tc.name: KeyCommandHandlerTest_HandleKnuckleGestureTouchMove_01
670 * @tc.desc: Test the funcation HandleKnuckleGestureTouchMove
671 * @tc.type: FUNC
672 * @tc.require:
673 */
674 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureTouchMove_01, TestSize.Level1)
675 {
676 CALL_TEST_DEBUG;
677 KeyCommandHandler handler;
678 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
679 ASSERT_NE(pointerEvent, nullptr);
680 PointerEvent::PointerItem item;
681 pointerEvent->pointerId_ = 5;
682 pointerEvent->targetDisplayId_ = 10;
683 item.rawDisplayX_ = 20.0;
684 item.rawDisplayY_ = 25.0;
685 handler.gestureLastX_ = 1.0f;
686 handler.gestureLastY_ = 2.0f;
687
688 handler.isStartBase_ = true;
689 handler.isGesturing_ = false;
690 ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchMove(pointerEvent));
691
692 handler.isGesturing_ = true;
693 handler.isLetterGesturing_ = false;
694 ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchMove(pointerEvent));
695
696 handler.isLetterGesturing_ = true;
697 ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchMove(pointerEvent));
698 }
699
700 /**
701 * @tc.name: KeyCommandHandlerTest_HandleKnuckleGestureTouchUp_04
702 * @tc.desc: Test the funcation HandleKnuckleGestureTouchUp
703 * @tc.type: FUNC
704 * @tc.require:
705 */
706 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureTouchUp_04, TestSize.Level1)
707 {
708 CALL_TEST_DEBUG;
709 KeyCommandHandler handler;
710 std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
711 ASSERT_NE(touchEvent, nullptr);
712 GESTURESENSE_WRAPPER->touchUp_ = [](const std::vector<float> &, const std::vector<int64_t> &, bool, bool)
__anon5dbb74de0202(const std::vector<float> &, const std::vector<int64_t> &, bool, bool) 713 -> int32_t {
714 return 0;
715 };
716 ASSERT_NE(GESTURESENSE_WRAPPER->touchUp_, nullptr);
717 handler.gesturePoints_.assign(LINE_COORDINATES.begin(), LINE_COORDINATES.end());
718 handler.gestureTimeStamps_.assign(LINE_TIMESTAMPS.begin(), LINE_TIMESTAMPS.end());
719 handler.isGesturing_ = true;
720 handler.isLetterGesturing_ = true;
721 NotifyType notifyType;
722 notifyType = NotifyType::REGIONGESTURE;
723 ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchUp(touchEvent));
724
725 notifyType = NotifyType::LETTERGESTURE;
726 ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchUp(touchEvent));
727
728 notifyType = NotifyType::OTHER;
729 ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchUp(touchEvent));
730 }
731
732 /**
733 * @tc.name: KeyCommandHandlerTest_HandleKeyDown_001
734 * @tc.desc: test HandleKeyDown
735 * @tc.type: FUNC
736 * @tc.require:
737 */
738 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKeyDown_001, TestSize.Level1)
739 {
740 CALL_TEST_DEBUG;
741 KeyCommandHandler handler;
742 ShortcutKey shortcutKey;
743 shortcutKey.keyDownDuration = 10;
744 shortcutKey.timerId = -1;
745 ASSERT_TRUE(handler.HandleKeyDown(shortcutKey));
746
747 shortcutKey.timerId = 2;
748 shortcutKey.finalKey = -1;
749 shortcutKey.triggerType = KeyEvent::KEY_ACTION_DOWN;
750 ASSERT_TRUE(handler.HandleKeyDown(shortcutKey));
751 }
752
753 /**
754 * @tc.name: KeyCommandHandlerTest_MatchShortcutKey_01
755 * @tc.desc: Test the funcation MatchShortcutKey
756 * @tc.type: FUNC
757 * @tc.require:
758 */
759 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_MatchShortcutKey_01, TestSize.Level1)
760 {
761 KeyCommandHandler handler;
762 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
763 ASSERT_NE(keyEvent, nullptr);
764 ShortcutKey shortcutKey;
765 std::vector<ShortcutKey> upAbilities;
766 shortcutKey.statusConfigValue = true;
767 shortcutKey.finalKey = -1;
768 shortcutKey.keyDownDuration = 0;
769 EXPECT_FALSE(handler.IsKeyMatch(shortcutKey, keyEvent));
770 EXPECT_FALSE(handler.MatchShortcutKey(keyEvent, shortcutKey, upAbilities));
771
772 shortcutKey.businessId = "V1";
773 int32_t delay = handler.GetKeyDownDurationFromXml(shortcutKey.businessId);
774 delay = 100;
775 EXPECT_TRUE(delay >= MIN_SHORT_KEY_DOWN_DURATION);
776 EXPECT_TRUE(delay <= MAX_SHORT_KEY_DOWN_DURATION);
777 EXPECT_FALSE(handler.MatchShortcutKey(keyEvent, shortcutKey, upAbilities));
778
779 delay = 5000;
780 shortcutKey.triggerType = KeyEvent::KEY_ACTION_DOWN;
781 EXPECT_FALSE(handler.MatchShortcutKey(keyEvent, shortcutKey, upAbilities));
782
783 shortcutKey.triggerType = KeyEvent::KEY_ACTION_UP;
784 EXPECT_FALSE(handler.MatchShortcutKey(keyEvent, shortcutKey, upAbilities));
785 EXPECT_TRUE(handler.HandleKeyUp(keyEvent, shortcutKey));
786 shortcutKey.keyDownDuration = 100;
787 EXPECT_FALSE(handler.MatchShortcutKey(keyEvent, shortcutKey, upAbilities));
788 }
789
790 /**
791 * @tc.name: KeyCommandHandlerTest_MatchShortcutKeys_01
792 * @tc.desc: Test the funcation MatchShortcutKeys
793 * @tc.type: FUNC
794 * @tc.require:
795 */
796 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_MatchShortcutKeys_01, TestSize.Level1)
797 {
798 CALL_TEST_DEBUG;
799 KeyCommandHandler handler;
800 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
801 ASSERT_NE(keyEvent, nullptr);
802 keyEvent->keyAction_ = KeyEvent::KEY_ACTION_UP;
803 bool ret = KEY_SHORTCUT_MGR->HaveShortcutConsumed(keyEvent);
804 EXPECT_FALSE(ret);
805
806 std::vector<ShortcutKey> upAbilities;
807 ShortcutKey key1;
808 key1.preKeys = {1, 2, 3};
809 key1.businessId = "business1";
810 key1.statusConfig = "config1";
811 key1.finalKey = -1;
812 upAbilities.push_back(key1);
813 EXPECT_FALSE(upAbilities.empty());
814 EXPECT_TRUE(handler.MatchShortcutKeys(keyEvent));
815 }
816
817 /**
818 * @tc.name: KeyCommandHandlerTest_HandleRepeatKeyAbility_001
819 * @tc.desc: HandleRepeatKeyAbility
820 * @tc.type: FUNC
821 * @tc.require:
822 */
823 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleRepeatKeyAbility_001, TestSize.Level1)
824 {
825 CALL_TEST_DEBUG;
826 KeyCommandHandler handler;
827 RepeatKey repeatKey;
828 bool isLaunched = false;
829 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
830 ASSERT_NE(keyEvent, nullptr);
831 handler.count_ = 2;
832 repeatKey.ability.bundleName = "bundleName";
833 ASSERT_TRUE(handler.HandleRepeatKeyAbility(repeatKey, isLaunched, keyEvent, false));
834 }
835
836 /**
837 * @tc.name: KeyCommandHandlerTest_HandleRepeatKeyAbility_002
838 * @tc.desc: HandleRepeatKeyAbility
839 * @tc.type: FUNC
840 * @tc.require:
841 */
842 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleRepeatKeyAbility_002, TestSize.Level1)
843 {
844 CALL_TEST_DEBUG;
845 KeyCommandHandler handler;
846 RepeatKey repeatKey;
847 bool isLaunched = false;
848 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
849 ASSERT_NE(keyEvent, nullptr);
850 handler.count_ = 2;
851 repeatKey.ability.bundleName = "bundleName";
852 handler.repeatKeyTimerIds_.emplace(repeatKey.ability.bundleName, 1);
853 ASSERT_TRUE(handler.HandleRepeatKeyAbility(repeatKey, isLaunched, keyEvent, false));
854 }
855
856 /**
857 * @tc.name: KeyCommandHandlerTest_HandleRepeatKeyAbility_003
858 * @tc.desc: HandleRepeatKeyAbility
859 * @tc.type: FUNC
860 * @tc.require:
861 */
862 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleRepeatKeyAbility_003, TestSize.Level1)
863 {
864 CALL_TEST_DEBUG;
865 KeyCommandHandler handler;
866 RepeatKey repeatKey;
867 bool isLaunched = false;
868 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
869 ASSERT_NE(keyEvent, nullptr);
870 bool isMaxTimes = false;
871
872 repeatKey.ability.bundleName = "bundleName1";
873 handler.repeatKeyTimerIds_["bundleName1"] = 1;
874 handler.repeatKeyTimerIds_["bundleName2"] = 2;
875 handler.repeatKeyTimerIds_["bundleName3"] = 3;
876 ASSERT_TRUE(handler.HandleRepeatKeyAbility(repeatKey, isLaunched, keyEvent, isMaxTimes));
877 }
878
879 /**
880 * @tc.name: KeyCommandHandlerTest_HandleRepeatKeyAbility_004
881 * @tc.desc: HandleRepeatKeyAbility
882 * @tc.type: FUNC
883 * @tc.require:
884 */
885 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleRepeatKeyAbility_004, TestSize.Level1)
886 {
887 CALL_TEST_DEBUG;
888 KeyCommandHandler handler;
889 RepeatKey repeatKey;
890 bool isLaunched = true;
891 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
892 ASSERT_NE(keyEvent, nullptr);
893 bool isMaxTimes = false;
894
895 repeatKey.ability.bundleName = "bundleName4";
896 handler.repeatKeyTimerIds_["bundleName1"] = 1;
897 handler.repeatKeyTimerIds_["bundleName2"] = 2;
898 handler.repeatKeyTimerIds_["bundleName3"] = 3;
899
900 handler.repeatTimerId_ = 2;
901 ASSERT_TRUE(handler.HandleRepeatKeyAbility(repeatKey, isLaunched, keyEvent, isMaxTimes));
902 handler.repeatTimerId_ = -1;
903 ASSERT_TRUE(handler.HandleRepeatKeyAbility(repeatKey, isLaunched, keyEvent, isMaxTimes));
904 }
905
906 /**
907 * @tc.name: KeyCommandHandlerTest_HandleRepeatKeyAbility_005
908 * @tc.desc: HandleRepeatKeyAbility
909 * @tc.type: FUNC
910 * @tc.require:
911 */
912 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleRepeatKeyAbility_005, TestSize.Level1)
913 {
914 CALL_TEST_DEBUG;
915 KeyCommandHandler handler;
916 RepeatKey repeatKey;
917 bool isLaunched = false;
918 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
919 ASSERT_NE(keyEvent, nullptr);
920 bool isMaxTimes = true;
921 ASSERT_TRUE(handler.HandleRepeatKeyAbility(repeatKey, isLaunched, keyEvent, isMaxTimes));
922 }
923
924 /**
925 * @tc.name: KeyCommandHandlerTest_OnHandleEvent_002
926 * @tc.desc: Test the funcation OnHandleEvent
927 * @tc.type: FUNC
928 * @tc.require:
929 */
930 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_OnHandleEvent_002, TestSize.Level1)
931 {
932 CALL_TEST_DEBUG;
933 KeyCommandHandler handler;
934 std::shared_ptr<KeyEvent> key = KeyEvent::Create();
935 ASSERT_NE(key, nullptr);
936 key->SetKeyCode(18);
937 handler.specialKeys_.insert(std::make_pair(18, 18));
938 bool ret = handler.OnHandleEvent(key);
939 EXPECT_TRUE(ret);
940 key->SetKeyCode(KeyEvent::KEYCODE_POWER);
941 handler.specialTimers_.insert(std::make_pair(KeyEvent::KEYCODE_POWER, 10));
942 ret = handler.OnHandleEvent(key);
943 EXPECT_TRUE(ret);
944 key->SetKeyCode(5);
945 ret = handler.OnHandleEvent(key);
946 EXPECT_FALSE(ret);
947 }
948
949 /**
950 * @tc.name: KeyCommandHandlerTest_HandleShortKeys_006
951 * @tc.desc: Test the funcation HandleShortKeys
952 * @tc.type: FUNC
953 * @tc.require:
954 */
955 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleShortKeys_006, TestSize.Level1)
956 {
957 KeyCommandHandler handler;
958 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
959 ASSERT_NE(keyEvent, nullptr);
960 ShortcutKey key;
961 key.preKeys = {2, 3, 4};
962 key.businessId = "business";
963 key.statusConfig = "config";
964 key.statusConfigValue = true;
965 key.finalKey = 6;
966 key.keyDownDuration = 7;
967 key.triggerType = KeyEvent::KEY_ACTION_DOWN;
968 key.timerId = 10;
969 handler.shortcutKeys_.insert(std::make_pair("key1", key));
970 bool ret = handler.HandleShortKeys(keyEvent);
971 ASSERT_FALSE(ret);
972 handler.currentLaunchAbilityKey_.businessId = "business1";
973 handler.currentLaunchAbilityKey_.statusConfig = "config1";
974 handler.currentLaunchAbilityKey_.timerId = 6;
975 handler.currentLaunchAbilityKey_.statusConfigValue = true;
976 handler.currentLaunchAbilityKey_.finalKey = 4;
977 handler.currentLaunchAbilityKey_.keyDownDuration = 5;
978 handler.currentLaunchAbilityKey_.triggerType = KeyEvent::KEY_ACTION_DOWN;
979 keyEvent->SetKeyCode(KeyEvent::INTENTION_RIGHT);
980 keyEvent->SetKeyAction(KeyEvent::INTENTION_UP);
981 SequenceKey sequenceKey;
982 sequenceKey.keyCode = 2017;
983 sequenceKey.keyAction = KeyEvent::KEY_ACTION_DOWN;
984 handler.keys_.push_back(sequenceKey);
985 sequenceKey.keyCode = 2022;
986 sequenceKey.keyAction = KeyEvent::INTENTION_UP;
987 handler.keys_.push_back(sequenceKey);
988 EventLogHelper eventLogHelper;
989 eventLogHelper.userType_ = "beta";
990 std::shared_ptr<InputEvent> inputEvent = InputEvent::Create();
991 EXPECT_NE(inputEvent, nullptr);
992 inputEvent->bitwise_ = 0x00000040;
993 ret = handler.HandleShortKeys(keyEvent);
994 ASSERT_FALSE(ret);
995 eventLogHelper.userType_ = "abcde";
996 ret = handler.HandleShortKeys(keyEvent);
997 ASSERT_FALSE(ret);
998 inputEvent->bitwise_ = 0x00000000;
999 ret = handler.HandleShortKeys(keyEvent);
1000 ASSERT_FALSE(ret);
1001 handler.lastMatchedKey_.timerId = -5;
1002 ret = handler.HandleShortKeys(keyEvent);
1003 ASSERT_FALSE(ret);
1004 }
1005
1006 /**
1007 * @tc.name: KeyCommandHandlerTest_HandlePointerEvent_002
1008 * @tc.desc: Test the funcation HandlePointerEvent
1009 * @tc.type: FUNC
1010 * @tc.require:
1011 */
1012 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandlePointerEvent_002, TestSize.Level1)
1013 {
1014 CALL_TEST_DEBUG;
1015 KeyCommandHandler handler;
1016 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
1017 ASSERT_TRUE(pointerEvent != nullptr);
1018 handler.isParseConfig_ = true;
1019 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_QUADTAP);
1020 ASSERT_NO_FATAL_FAILURE(handler.HandlePointerEvent(pointerEvent));
1021
1022 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_TRIPTAP);
1023 EventLogHelper eventLogHelper;
1024 eventLogHelper.userType_ = "beta";
1025 std::shared_ptr<InputEvent> inputEvent = InputEvent::Create();
1026 EXPECT_NE(inputEvent, nullptr);
1027 inputEvent->bitwise_ = 0;
1028 ASSERT_NO_FATAL_FAILURE(handler.HandlePointerEvent(pointerEvent));
1029 eventLogHelper.userType_ = "default";
1030 ASSERT_NO_FATAL_FAILURE(handler.HandlePointerEvent(pointerEvent));
1031 inputEvent->bitwise_ = InputEvent::EVENT_FLAG_PRIVACY_MODE;
1032 ASSERT_NO_FATAL_FAILURE(handler.HandlePointerEvent(pointerEvent));
1033 }
1034
1035 /**
1036 * @tc.name: KeyCommandHandlerTest_StartTwoFingerGesture_003
1037 * @tc.desc: Test the funcation StartTwoFingerGesture
1038 * @tc.type: FUNC
1039 * @tc.require:
1040 */
1041 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_StartTwoFingerGesture_003, TestSize.Level1)
1042 {
1043 CALL_TEST_DEBUG;
1044 KeyCommandHandler handler;
1045 handler.twoFingerGesture_.active = true;
1046 handler.twoFingerGesture_.touches[0].downTime = 150000;
1047 handler.twoFingerGesture_.touches[0].id = 10;
1048 handler.twoFingerGesture_.touches[0].x = 100;
1049 handler.twoFingerGesture_.touches[0].y = 200;
1050 handler.twoFingerGesture_.touches[1].downTime = 100000;
1051 handler.twoFingerGesture_.touches[0].id = 5;
1052 handler.twoFingerGesture_.touches[0].x = 50;
1053 handler.twoFingerGesture_.touches[0].y = 100;
1054 ASSERT_NO_FATAL_FAILURE(handler.StartTwoFingerGesture());
1055 handler.twoFingerGesture_.touches[0].downTime = 350000;
1056 handler.twoFingerGesture_.touches[1].downTime = 100000;
1057 ASSERT_NO_FATAL_FAILURE(handler.StartTwoFingerGesture());
1058 handler.twoFingerGesture_.active = false;
1059 ASSERT_NO_FATAL_FAILURE(handler.StartTwoFingerGesture());
1060 }
1061
1062 /**
1063 * @tc.name: KeyCommandHandlerTest_CheckTwoFingerGestureAction_006
1064 * @tc.desc: Test the funcation CheckTwoFingerGestureAction
1065 * @tc.type: FUNC
1066 * @tc.require:
1067 */
1068 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckTwoFingerGestureAction_006, TestSize.Level1)
1069 {
1070 CALL_TEST_DEBUG;
1071 KeyCommandHandler handler;
1072 handler.twoFingerGesture_.active = true;
1073 handler.twoFingerGesture_.touches[0].id = 1;
1074 handler.twoFingerGesture_.touches[0].x = 30;
1075 handler.twoFingerGesture_.touches[0].y = 20;
1076 handler.twoFingerGesture_.touches[0].downTime = 150000;
1077 handler.twoFingerGesture_.touches[1].id = 2;
1078 handler.twoFingerGesture_.touches[1].x = 20;
1079 handler.twoFingerGesture_.touches[1].y = 10;
1080 handler.twoFingerGesture_.touches[1].downTime = 100000;
1081 InputWindowsManager inputWindowsManager;
1082 DisplayInfo displayInfo;
1083 displayInfo.dpi = 320;
1084 displayInfo.width = 150;
1085 displayInfo.height = 300;
1086 displayInfo.uniq = "default0";
1087 inputWindowsManager.displayGroupInfo_.displaysInfo.push_back(displayInfo);
1088 bool ret = handler.CheckTwoFingerGestureAction();
1089 EXPECT_FALSE(ret);
1090 handler.twoFingerGesture_.touches[0].x = 30;
1091 handler.twoFingerGesture_.touches[0].y = 200;
1092 handler.twoFingerGesture_.touches[1].x = 60;
1093 handler.twoFingerGesture_.touches[1].y = 170;
1094 ret = handler.CheckTwoFingerGestureAction();
1095 EXPECT_FALSE(ret);
1096 handler.twoFingerGesture_.touches[0].x = 120;
1097 ret = handler.CheckTwoFingerGestureAction();
1098 EXPECT_FALSE(ret);
1099 handler.twoFingerGesture_.touches[0].x = 90;
1100 handler.twoFingerGesture_.touches[0].y = 120;
1101 ret = handler.CheckTwoFingerGestureAction();
1102 EXPECT_FALSE(ret);
1103 handler.twoFingerGesture_.touches[0].y = 250;
1104 ret = handler.CheckTwoFingerGestureAction();
1105 EXPECT_FALSE(ret);
1106 }
1107
1108 /**
1109 * @tc.name: KeyCommandHandlerTest_CheckTwoFingerGestureAction_007
1110 * @tc.desc: Test the funcation CheckTwoFingerGestureAction
1111 * @tc.type: FUNC
1112 * @tc.require:
1113 */
1114 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckTwoFingerGestureAction_007, TestSize.Level1)
1115 {
1116 CALL_TEST_DEBUG;
1117 KeyCommandHandler handler;
1118 handler.twoFingerGesture_.active = true;
1119 handler.twoFingerGesture_.touches[0].x = 90;
1120 handler.twoFingerGesture_.touches[0].y = 200;
1121 handler.twoFingerGesture_.touches[0].downTime = 150000;
1122 handler.twoFingerGesture_.touches[1].x = 30;
1123 handler.twoFingerGesture_.touches[1].y = 170;
1124 handler.twoFingerGesture_.touches[1].downTime = 100000;
1125 InputWindowsManager inputWindowsManager;
1126 DisplayInfo displayInfo;
1127 displayInfo.dpi = 320;
1128 displayInfo.width = 150;
1129 displayInfo.height = 300;
1130 displayInfo.uniq = "default0";
1131 inputWindowsManager.displayGroupInfo_.displaysInfo.push_back(displayInfo);
1132 handler.twoFingerGesture_.touches[0].y = 200;
1133 handler.twoFingerGesture_.touches[1].x = 30;
1134 bool ret = handler.CheckTwoFingerGestureAction();
1135 EXPECT_FALSE(ret);
1136 handler.twoFingerGesture_.touches[1].x = 130;
1137 ret = handler.CheckTwoFingerGestureAction();
1138 EXPECT_FALSE(ret);
1139 handler.twoFingerGesture_.touches[1].x = 60;
1140 handler.twoFingerGesture_.touches[1].y = 100;
1141 ret = handler.CheckTwoFingerGestureAction();
1142 EXPECT_FALSE(ret);
1143 handler.twoFingerGesture_.touches[1].y = 250;
1144 ret = handler.CheckTwoFingerGestureAction();
1145 EXPECT_FALSE(ret);
1146 ASSERT_NO_FATAL_FAILURE(handler.StartTwoFingerGesture());
1147 handler.twoFingerGesture_.touches[1].y = 170;
1148 ret = handler.CheckTwoFingerGestureAction();
1149 EXPECT_FALSE(ret);
1150 ASSERT_NO_FATAL_FAILURE(handler.StartTwoFingerGesture());
1151 }
1152
1153 /**
1154 * @tc.name: KeyCommandHandlerTest_CheckTwoFingerGestureAction_008
1155 * @tc.desc: Test the funcation CheckTwoFingerGestureAction
1156 * @tc.type: FUNC
1157 * @tc.require:
1158 */
1159 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckTwoFingerGestureAction_008, TestSize.Level1)
1160 {
1161 CALL_TEST_DEBUG;
1162 KeyCommandHandler handler;
1163 handler.twoFingerGesture_.active = true;
1164 auto firstFinger = handler.twoFingerGesture_.touches[0];
1165 auto secondFinger = handler.twoFingerGesture_.touches[1];
1166
1167 int64_t firstTime = firstFinger.downTime;
1168 firstTime = 150000;
1169 int64_t secondTime = secondFinger.downTime;
1170 secondTime = 200000;
1171 auto pressTimeInterval = fabs(firstTime - secondTime);
1172 EXPECT_FALSE(pressTimeInterval > TWO_FINGERS_TIME_LIMIT);
1173 EXPECT_FALSE(handler.CheckTwoFingerGestureAction());
1174
1175 int32_t firstFingerX = firstFinger.x;
1176 firstFingerX = 90;
1177 int32_t firstFingerY = firstFinger.y;
1178 firstFingerY = 200;
1179 int32_t secondFingerX = secondFinger.x;
1180 secondFingerX = 30;
1181 int32_t secondFingerY = secondFinger.y;
1182 secondFingerY = 170;
1183 int32_t devX = firstFingerX - secondFingerX;
1184 int32_t devY = firstFingerY - secondFingerY;
1185 auto distance = sqrt(pow(devX, 2) + pow(devY, 2));
1186 EXPECT_FALSE(distance < handler.ConvertVPToPX(TWO_FINGERS_DISTANCE_LIMIT));
1187 EXPECT_FALSE(handler.CheckTwoFingerGestureAction());
1188
1189 auto leftLimit = handler.ConvertVPToPX(TOUCH_LIFT_LIMIT);
1190 firstFingerX = -10;
1191 EXPECT_TRUE(firstFingerX <= leftLimit);
1192 EXPECT_FALSE(handler.CheckTwoFingerGestureAction());
1193
1194 InputWindowsManager inputWindowsManager;
1195 DisplayInfo displayInfo;
1196 displayInfo.dpi = 320;
1197 displayInfo.width = 10;
1198 displayInfo.height = 30;
1199 inputWindowsManager.displayGroupInfo_.displaysInfo.push_back(displayInfo);
1200 auto rightLimit = displayInfo.width - handler.ConvertVPToPX(TOUCH_RIGHT_LIMIT);
1201 firstFingerX = 50;
1202 EXPECT_TRUE(firstFingerX >= rightLimit);
1203 EXPECT_FALSE(handler.CheckTwoFingerGestureAction());
1204
1205 auto topLimit = handler.ConvertVPToPX(TOUCH_TOP_LIMIT);
1206 firstFingerY = -20;
1207 EXPECT_TRUE(firstFingerY <= topLimit);
1208 EXPECT_FALSE(handler.CheckTwoFingerGestureAction());
1209
1210 auto bottomLimit = displayInfo.height - handler.ConvertVPToPX(TOUCH_BOTTOM_LIMIT);
1211 firstFingerY = 60;
1212 EXPECT_TRUE(firstFingerY >= bottomLimit);
1213 EXPECT_FALSE(handler.CheckTwoFingerGestureAction());
1214
1215 secondFingerX = -5;
1216 EXPECT_TRUE(secondFingerX <= leftLimit);
1217 secondFingerX = 30;
1218 EXPECT_TRUE(secondFingerX >= rightLimit);
1219 secondFingerY = -1;
1220 EXPECT_TRUE(secondFingerY <= topLimit);
1221 secondFingerY = 50;
1222 EXPECT_TRUE(secondFingerY >= bottomLimit);
1223 EXPECT_FALSE(handler.CheckTwoFingerGestureAction());
1224 }
1225
1226 /**
1227 * @tc.name: KeyCommandHandlerTest_IsKeyMatch_01
1228 * @tc.desc: Test the funcation IsKeyMatch
1229 * @tc.type: FUNC
1230 * @tc.require:
1231 */
1232 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_IsKeyMatch_01, TestSize.Level1)
1233 {
1234 KeyCommandHandler handler;
1235 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1236 ASSERT_NE(keyEvent, nullptr);
1237 ShortcutKey shortcutKey;
1238 std::vector<ShortcutKey> upAbilities;
1239 shortcutKey.statusConfigValue = true;
1240 shortcutKey.finalKey = 2076;
1241 shortcutKey.keyDownDuration = 0;
1242 shortcutKey.triggerType = KeyEvent::KEY_ACTION_DOWN;
1243 keyEvent->keyCode_ = 2076;
1244 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
1245
1246 shortcutKey.preKeys = {2076, 2077};
1247 KeyEvent::KeyItem item;
1248 item.SetKeyCode(KeyEvent::KEYCODE_META_LEFT);
1249 item.SetKeyCode(KeyEvent::KEYCODE_META_RIGHT);
1250 item.SetKeyCode(KeyEvent::KEYCODE_FUNCTION);
1251 keyEvent->AddKeyItem(item);
1252 EXPECT_FALSE(handler.IsKeyMatch(shortcutKey, keyEvent));
1253 }
1254
1255 /**
1256 * @tc.name: KeyCommandHandlerTest_StartTwoFingerGesture_01
1257 * @tc.desc: Test the funcation StartTwoFingerGesture
1258 * @tc.type: FUNC
1259 * @tc.require:
1260 */
1261 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_StartTwoFingerGesture_01, TestSize.Level1)
1262 {
1263 CALL_TEST_DEBUG;
1264 KeyCommandHandler handler;
1265 handler.twoFingerGesture_.active = false;
1266 EXPECT_FALSE(handler.CheckTwoFingerGestureAction());
1267 ASSERT_NO_FATAL_FAILURE(handler.StartTwoFingerGesture());
1268 }
1269
1270 /**
1271 * @tc.name: KeyCommandHandlerTest_StartTwoFingerGesture_02
1272 * @tc.desc: Test the funcation StartTwoFingerGesture
1273 * @tc.type: FUNC
1274 * @tc.require:
1275 */
1276 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_StartTwoFingerGesture_02, TestSize.Level1)
1277 {
1278 CALL_TEST_DEBUG;
1279 KeyCommandHandler handler;
1280 handler.twoFingerGesture_.active = true;
1281 EXPECT_FALSE(handler.CheckTwoFingerGestureAction());
1282 ASSERT_NO_FATAL_FAILURE(handler.StartTwoFingerGesture());
1283 }
1284
1285 /**
1286 * @tc.name: KeyCommandHandlerTest_ConvertVPToPX_004
1287 * @tc.desc: Test the funcation ConvertVPToPX
1288 * @tc.type: FUNC
1289 * @tc.require:
1290 */
1291 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_ConvertVPToPX_004, TestSize.Level1)
1292 {
1293 CALL_TEST_DEBUG;
1294 KeyCommandHandler handler;
1295 int32_t vp = 10;
1296 InputWindowsManager inputWindowsManager;
1297 DisplayInfo displayInfo;
1298 displayInfo.dpi = -10;
1299 displayInfo.uniq = "default0";
1300 inputWindowsManager.displayGroupInfo_.displaysInfo.push_back(displayInfo);
1301 int32_t ret = handler.ConvertVPToPX(vp);
1302 ASSERT_EQ(ret, 0);
1303 displayInfo.dpi = 160;
1304 inputWindowsManager.displayGroupInfo_.displaysInfo.push_back(displayInfo);
1305 ret = handler.ConvertVPToPX(vp);
1306 ASSERT_EQ(ret, 0);
1307 }
1308
1309 /**
1310 * @tc.name: KeyCommandHandlerTest_HandleKnuckleGestureEvent_004
1311 * @tc.desc: Test the funcation HandleKnuckleGestureEvent
1312 * @tc.type: FUNC
1313 * @tc.require:
1314 */
1315 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureEvent_004, TestSize.Level1)
1316 {
1317 CALL_TEST_DEBUG;
1318 KeyCommandHandler handler;
1319 PointerEvent::PointerItem item;
1320 std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
1321 ASSERT_NE(touchEvent, nullptr);
1322 item.SetToolType(PointerEvent::TOOL_TYPE_KNUCKLE);
1323 handler.singleKnuckleGesture_.state = false;
1324 handler.knuckleSwitch_.statusConfigValue = false;
1325 touchEvent->AddPointerItem(item);
1326 touchEvent->SetPointerId(1);
1327 touchEvent->SetPointerAction(PointerEvent::POINTER_ACTION_CANCEL);
1328 ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureEvent(touchEvent));
1329 touchEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP);
1330 ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureEvent(touchEvent));
1331 touchEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE);
1332 ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureEvent(touchEvent));
1333 touchEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
1334 ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureEvent(touchEvent));
1335 touchEvent->SetPointerAction(PointerEvent::POINTER_ACTION_AXIS_BEGIN);
1336 ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureEvent(touchEvent));
1337 touchEvent->SetPointerAction(PointerEvent::POINTER_ACTION_AXIS_UPDATE);
1338 ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureEvent(touchEvent));
1339 touchEvent->SetPointerAction(PointerEvent::POINTER_ACTION_AXIS_END);
1340 ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureEvent(touchEvent));
1341 touchEvent->SetPointerAction(PointerEvent::POINTER_ACTION_BUTTON_DOWN);
1342 ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureEvent(touchEvent));
1343 touchEvent->SetPointerAction(PointerEvent::POINTER_ACTION_PULL_UP);
1344 ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureEvent(touchEvent));
1345 }
1346
1347 /**
1348 * @tc.name: KeyCommandHandlerTest_OnHandleTouchEvent
1349 * @tc.desc: Test OnHandleTouchEvent
1350 * @tc.type: FUNC
1351 * @tc.require:
1352 */
1353 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_OnHandleTouchEvent, TestSize.Level1)
1354 {
1355 CALL_TEST_DEBUG;
1356 KeyCommandHandler handler;
1357 PointerEvent::PointerItem item;
1358 std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
1359 ASSERT_NE(touchEvent, nullptr);
1360 handler.isParseConfig_ = false;
1361 handler.isTimeConfig_ = false;
1362 handler.isDistanceConfig_ = false;
1363 handler.isKnuckleSwitchConfig_ = true;
1364 item.SetPointerId(1);
1365 item.SetToolType(PointerEvent::TOOL_TYPE_PENCIL);
1366 touchEvent->AddPointerItem(item);
1367 touchEvent->SetPointerId(1);
1368 touchEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP);
1369 ASSERT_NO_FATAL_FAILURE(handler.OnHandleTouchEvent(touchEvent));
1370
1371 touchEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
1372 ASSERT_NO_FATAL_FAILURE(handler.OnHandleTouchEvent(touchEvent));
1373
1374 touchEvent->RemovePointerItem(1);
1375 touchEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE);
1376 ASSERT_NO_FATAL_FAILURE(handler.OnHandleTouchEvent(touchEvent));
1377
1378 touchEvent->SetPointerAction(PointerEvent::POINTER_ACTION_BUTTON_DOWN);
1379 ASSERT_NO_FATAL_FAILURE(handler.OnHandleTouchEvent(touchEvent));
1380 }
1381
1382 /**
1383 * @tc.name: KeyCommandHandlerTest_HandlePointerActionMoveEvent
1384 * @tc.desc: Test HandlePointerActionMoveEvent
1385 * @tc.type: FUNC
1386 * @tc.require:
1387 */
1388 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandlePointerActionMoveEvent, TestSize.Level1)
1389 {
1390 CALL_TEST_DEBUG;
1391 KeyCommandHandler handler;
1392 std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
1393 ASSERT_NE(touchEvent, nullptr);
1394 handler.twoFingerGesture_.active = true;
1395 handler.twoFingerGesture_.timerId = -1;
1396 ASSERT_NO_FATAL_FAILURE(handler.HandlePointerActionMoveEvent(touchEvent));
1397
1398 touchEvent->SetPointerId(2);
1399 handler.twoFingerGesture_.timerId = 1;
1400 handler.twoFingerGesture_.touches->id = 1;
1401 handler.twoFingerGesture_.touches->x = 25;
1402 handler.twoFingerGesture_.touches->y = 25;
1403 ASSERT_NO_FATAL_FAILURE(handler.HandlePointerActionMoveEvent(touchEvent));
1404
1405 touchEvent->SetPointerId(1);
1406 PointerEvent::PointerItem item;
1407 item.SetDisplayX(5);
1408 item.SetDisplayY(5);
1409 touchEvent->AddPointerItem(item);
1410 ASSERT_NO_FATAL_FAILURE(handler.HandlePointerActionMoveEvent(touchEvent));
1411 }
1412
1413 /**
1414 * @tc.name: KeyCommandHandlerTest_HandleFingerGestureDownEvent
1415 * @tc.desc: Test HandleFingerGestureDownEvent
1416 * @tc.type: FUNC
1417 * @tc.require:
1418 */
1419 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleFingerGestureDownEvent, TestSize.Level1)
1420 {
1421 CALL_TEST_DEBUG;
1422 KeyCommandHandler handler;
1423 PointerEvent::PointerItem item;
1424 std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
1425 ASSERT_NE(touchEvent, nullptr);
1426 handler.twoFingerGesture_.active = true;
1427 item.SetPointerId(1);
1428 item.SetDisplayX(10);
1429 item.SetDisplayY(10);
1430 touchEvent->AddPointerItem(item);
1431 touchEvent->SetPointerId(1);
1432 ASSERT_NO_FATAL_FAILURE(handler.HandleFingerGestureDownEvent(touchEvent));
1433
1434 item.SetPointerId(2);
1435 item.SetDisplayX(15);
1436 item.SetDisplayY(15);
1437 touchEvent->AddPointerItem(item);
1438 ASSERT_NO_FATAL_FAILURE(handler.HandleFingerGestureDownEvent(touchEvent));
1439
1440 handler.twoFingerGesture_.active = true;
1441 handler.twoFingerGesture_.timerId = 150;
1442 ASSERT_NO_FATAL_FAILURE(handler.HandleFingerGestureUpEvent(touchEvent));
1443 }
1444
1445 /**
1446 * @tc.name: KeyCommandHandlerTest_HandleFingerGestureDownEvent_001
1447 * @tc.desc: Test HandleFingerGestureDownEvent
1448 * @tc.type: FUNC
1449 * @tc.require:
1450 */
1451 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleFingerGestureDownEvent_001, TestSize.Level1)
1452 {
1453 CALL_TEST_DEBUG;
1454 KeyCommandHandler handler;
1455 PointerEvent::PointerItem item;
1456 std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
1457 ASSERT_NE(touchEvent, nullptr);
1458 handler.twoFingerGesture_.active = true;
1459 ASSERT_NO_FATAL_FAILURE(handler.HandleFingerGestureDownEvent(touchEvent));
1460
1461 item.SetPointerId(1);
1462 touchEvent->AddPointerItem(item);
1463 item.SetPointerId(2);
1464 touchEvent->AddPointerItem(item);
1465 item.SetPointerId(3);
1466 touchEvent->AddPointerItem(item);
1467 ASSERT_NO_FATAL_FAILURE(handler.HandleFingerGestureDownEvent(touchEvent));
1468 }
1469
1470 /**
1471 * @tc.name: KeyCommandHandlerTest_HandleKnuckleGestureDownEvent_001
1472 * @tc.desc: Test HandleKnuckleGestureDownEvent_001
1473 * @tc.type: FUNC
1474 * @tc.require:
1475 */
1476 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureDownEvent_001, TestSize.Level1)
1477 {
1478 CALL_TEST_DEBUG;
1479 KeyCommandHandler handler;
1480 PointerEvent::PointerItem item;
1481 std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
1482 ASSERT_NE(touchEvent, nullptr);
1483 handler.twoFingerGesture_.active = true;
1484 item.SetPointerId(1);
1485 item.SetToolType(PointerEvent::TOOL_TYPE_PALM);
1486 touchEvent->AddPointerItem(item);
1487 touchEvent->SetPointerId(1);
1488 ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureDownEvent(touchEvent));
1489
1490 item.SetPointerId(2);
1491 item.SetToolType(PointerEvent::TOOL_TYPE_KNUCKLE);
1492 touchEvent->AddPointerItem(item);
1493 item.SetPointerId(3);
1494 touchEvent->AddPointerItem(item);
1495 touchEvent->SetPointerId(2);
1496 ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureDownEvent(touchEvent));
1497
1498 ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureUpEvent(touchEvent));
1499 }
1500
1501 /**
1502 * @tc.name: KeyCommandHandlerTest_HandleKnuckleGestureDownEvent_002
1503 * @tc.desc: Test HandleKnuckleGestureDownEvent_002
1504 * @tc.type: FUNC
1505 * @tc.require:
1506 */
1507 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureDownEvent_002, TestSize.Level1)
1508 {
1509 CALL_TEST_DEBUG;
1510 KeyCommandHandler handler;
1511 PointerEvent::PointerItem item;
1512 std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
1513 ASSERT_NE(touchEvent, nullptr);
1514 handler.twoFingerGesture_.active = true;
1515 handler.knuckleSwitch_.statusConfigValue = true;
1516
1517 item.SetPointerId(2);
1518 item.SetToolType(PointerEvent::TOOL_TYPE_KNUCKLE);
1519 touchEvent->AddPointerItem(item);
1520 ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureDownEvent(touchEvent));
1521 }
1522
1523 /**
1524 * @tc.name: KeyCommandHandlerTest_HandleKnuckleGestureDownEvent_003
1525 * @tc.desc: Test HandleKnuckleGestureDownEvent_003
1526 * @tc.type: FUNC
1527 * @tc.require:
1528 */
1529 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureDownEvent_003, TestSize.Level1)
1530 {
1531 CALL_TEST_DEBUG;
1532 KeyCommandHandler handler;
1533 PointerEvent::PointerItem item;
1534 std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
1535 ASSERT_NE(touchEvent, nullptr);
1536 handler.twoFingerGesture_.active = true;
1537 handler.knuckleSwitch_.statusConfigValue = false;
1538
1539 item.SetPointerId(2);
1540 item.SetToolType(PointerEvent::TOOL_TYPE_KNUCKLE);
1541 touchEvent->AddPointerItem(item);
1542 ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureDownEvent(touchEvent));
1543 }
1544
1545 /**
1546 * @tc.name: KeyCommandHandlerTest_HandleKnuckleGestureUpEvent
1547 * @tc.desc: Test HandleKnuckleGestureUpEvent
1548 * @tc.type: FUNC
1549 * @tc.require:
1550 */
1551 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureUpEvent, TestSize.Level1)
1552 {
1553 CALL_TEST_DEBUG;
1554 KeyCommandHandler handler;
1555 PointerEvent::PointerItem item;
1556 std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
1557 ASSERT_NE(touchEvent, nullptr);
1558 item.SetPointerId(1);
1559 touchEvent->AddPointerItem(item);
1560 handler.isDoubleClick_ = true;
1561 ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureUpEvent(touchEvent));
1562 }
1563
1564 /**
1565 * @tc.name: KeyCommandHandlerTest_KnuckleGestureProcessor
1566 * @tc.desc: Test KnuckleGestureProcessor
1567 * @tc.type: FUNC
1568 * @tc.require:
1569 */
1570 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_KnuckleGestureProcessor, TestSize.Level1)
1571 {
1572 CALL_TEST_DEBUG;
1573 KeyCommandHandler handler;
1574 KnuckleGesture knuckleGesture;
1575 std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
1576 ASSERT_NE(touchEvent, nullptr);
1577 knuckleGesture.lastPointerDownEvent = touchEvent;
1578 knuckleGesture.lastPointerUpTime = 10;
1579 touchEvent->SetActionTime(5);
1580 handler.knuckleCount_ = 2;
1581 ASSERT_NO_FATAL_FAILURE(handler.KnuckleGestureProcessor(touchEvent,
1582 knuckleGesture, KnuckleType::KNUCKLE_TYPE_SINGLE));
1583 }
1584
1585 /**
1586 * @tc.name: KeyCommandHandlerTest_HandleMultiTapTest__001
1587 * @tc.desc: Test three fingers tap event launch ability
1588 * @tc.type: FUNC
1589 * @tc.require:
1590 */
1591 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleMultiTapTest__001, TestSize.Level1)
1592 {
1593 CALL_TEST_DEBUG;
1594 auto threeFingerTap = SetupThreeFingerTapEvent();
1595 ASSERT_TRUE(threeFingerTap != nullptr);
1596 KeyCommandHandler keyCommandHandler;
1597 ASSERT_TRUE(keyCommandHandler.OnHandleEvent(threeFingerTap));
1598 }
1599
1600 /**
1601 * @tc.name: KeyCommandHandlerTest_HandleMultiTapTest__002
1602 * @tc.desc: Test four fingers tap event launch ability
1603 * @tc.type: FUNC
1604 * @tc.require:
1605 */
1606 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleMultiTapTest__002, TestSize.Level1)
1607 {
1608 CALL_TEST_DEBUG;
1609 auto fourFingerTap = SetupFourFingerTapEvent();
1610 ASSERT_TRUE(fourFingerTap != nullptr);
1611 KeyCommandHandler keyCommandHandler;
1612 ASSERT_FALSE(keyCommandHandler.OnHandleEvent(fourFingerTap));
1613 }
1614
1615 /**
1616 * @tc.name: KeyCommandHandlerTest_001
1617 * @tc.desc: Test update key down duration 0, 100, 4000
1618 * @tc.type: FUNC
1619 * @tc.require:
1620 */
1621 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_001, TestSize.Level1)
1622 {
1623 CALL_TEST_DEBUG;
1624 KeyCommandHandler eventKeyCommandHandler;
1625 std::string businessId = "aaa";
1626 int32_t delay = 0;
1627 ASSERT_EQ(COMMON_PARAMETER_ERROR, eventKeyCommandHandler.UpdateSettingsXml(businessId, delay));
1628 delay = 100;
1629 ASSERT_EQ(COMMON_PARAMETER_ERROR, eventKeyCommandHandler.UpdateSettingsXml(businessId, delay));
1630 delay = 4000;
1631 ASSERT_EQ(COMMON_PARAMETER_ERROR, eventKeyCommandHandler.UpdateSettingsXml(businessId, delay));
1632 }
1633
1634 /**
1635 * @tc.name: KeyCommandHandlerTest_EnableCombineKey_001
1636 * @tc.desc: Test enable combineKey
1637 * @tc.type: FUNC
1638 * @tc.require:
1639 */
1640 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_EnableCombineKey_001, TestSize.Level1)
1641 {
1642 CALL_TEST_DEBUG;
1643 KeyCommandHandler eventKeyCommandHandler;
1644 ASSERT_EQ(eventKeyCommandHandler.EnableCombineKey(true), RET_OK);
1645 }
1646
1647 /**
1648 * @tc.name: KeyCommandHandlerTest_IsEnableCombineKey_001
1649 * @tc.desc: Test IsEnableCombineKey
1650 * @tc.type: FUNC
1651 * @tc.require:
1652 */
1653 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_IsEnableCombineKey_001, TestSize.Level1)
1654 {
1655 CALL_TEST_DEBUG;
1656 KeyCommandHandler eventKeyCommandHandler;
1657 eventKeyCommandHandler.EnableCombineKey(false);
1658 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1659 CHKPV(keyEvent);
1660 KeyEvent::KeyItem item;
1661 item.SetKeyCode(KeyEvent::KEYCODE_POWER);
1662 keyEvent->AddKeyItem(item);
1663 keyEvent->SetKeyCode(KeyEvent::KEYCODE_POWER);
1664 ASSERT_EQ(eventKeyCommandHandler.OnHandleEvent(keyEvent), false);
1665 eventKeyCommandHandler.EnableCombineKey(true);
1666 }
1667
1668 /**
1669 * @tc.name: KeyCommandHandlerTest_IsEnableCombineKey_002
1670 * @tc.desc: Test IsEnableCombineKey
1671 * @tc.type: FUNC
1672 * @tc.require:
1673 */
1674 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_IsEnableCombineKey_002, TestSize.Level1)
1675 {
1676 CALL_TEST_DEBUG;
1677 KeyCommandHandler eventKeyCommandHandler;
1678 eventKeyCommandHandler.EnableCombineKey(false);
1679 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1680 CHKPV(keyEvent);
1681 KeyEvent::KeyItem item1;
1682 item1.SetKeyCode(KeyEvent::KEYCODE_META_LEFT);
1683 keyEvent->AddKeyItem(item1);
1684 KeyEvent::KeyItem item2;
1685 item2.SetKeyCode(KeyEvent::KEYCODE_L);
1686 keyEvent->AddKeyItem(item2);
1687 keyEvent->SetKeyCode(KeyEvent::KEYCODE_L);
1688 ASSERT_EQ(eventKeyCommandHandler.OnHandleEvent(keyEvent), false);
1689 eventKeyCommandHandler.EnableCombineKey(true);
1690 }
1691
1692 /**
1693 * @tc.name: KeyCommandHandlerTest_002
1694 * @tc.desc: Test update key down duration -1 and 4001
1695 * @tc.type: FUNC
1696 * @tc.require:
1697 */
1698 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_002, TestSize.Level1)
1699 {
1700 CALL_TEST_DEBUG;
1701 KeyCommandHandler eventKeyCommandHandler;
1702 std::string businessId = "com.ohos.camera";
1703 int32_t delay = -1;
1704 ASSERT_EQ(COMMON_PARAMETER_ERROR, eventKeyCommandHandler.UpdateSettingsXml(businessId, delay));
1705 delay = 4001;
1706 ASSERT_EQ(COMMON_PARAMETER_ERROR, eventKeyCommandHandler.UpdateSettingsXml(businessId, delay));
1707 }
1708
1709 /**
1710 * @tc.name: KeyCommandHandlerTest_003
1711 * @tc.desc: Test businessId is ""
1712 * @tc.type: FUNC
1713 * @tc.require:
1714 */
1715 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_003, TestSize.Level1)
1716 {
1717 CALL_TEST_DEBUG;
1718 KeyCommandHandler eventKeyCommandHandler;
1719 std::string businessId = "";
1720 int32_t delay = 100;
1721 ASSERT_EQ(COMMON_PARAMETER_ERROR, eventKeyCommandHandler.UpdateSettingsXml(businessId, delay));
1722 }
1723
1724 /**
1725 * @tc.name: KeyCommandHandlerTest_004
1726 * @tc.desc: Test key event
1727 * @tc.type: FUNC
1728 * @tc.require:
1729 */
1730 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_004, TestSize.Level1)
1731 {
1732 CALL_TEST_DEBUG;
1733 auto keyEvent = SetupKeyEvent();
1734 ASSERT_TRUE(keyEvent != nullptr);
1735 KeyCommandHandler eventKeyCommandHandler;
1736 ASSERT_FALSE(eventKeyCommandHandler.OnHandleEvent(keyEvent));
1737 }
1738
1739 /**
1740 * @tc.name: KeyCommandHandlerTest_HandleEvent_01
1741 * @tc.desc: Test HandleEvent
1742 * @tc.type: FUNC
1743 * @tc.require:
1744 */
1745 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleEvent_01, TestSize.Level1)
1746 {
1747 CALL_TEST_DEBUG;
1748 auto keyEvent = SetupKeyEvent();
1749 ASSERT_TRUE(keyEvent != nullptr);
1750 KeyCommandHandler eventKeyCommandHandler;
1751
1752 bool preHandleEvent = eventKeyCommandHandler.PreHandleEvent(keyEvent);
1753 EXPECT_TRUE(preHandleEvent);
1754 bool ret = eventKeyCommandHandler.HandleEvent(keyEvent);
1755 EXPECT_FALSE(ret);
1756 }
1757
1758 /**
1759 * @tc.name: KeyCommandHandlerTest_HandleEvent_02
1760 * @tc.desc: Test HandleEvent
1761 * @tc.type: FUNC
1762 * @tc.require:
1763 */
1764 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleEvent_02, TestSize.Level1)
1765 {
1766 CALL_TEST_DEBUG;
1767 auto keyEvent = SetupKeyEvent();
1768 ASSERT_TRUE(keyEvent != nullptr);
1769 KeyCommandHandler eventKeyCommandHandler;
1770
1771 bool stylusKey = STYLUS_HANDLER->HandleStylusKey(keyEvent);
1772 EXPECT_FALSE(stylusKey);
1773 bool ret = eventKeyCommandHandler.HandleEvent(keyEvent);
1774 EXPECT_FALSE(ret);
1775 }
1776
1777 /**
1778 * @tc.name: KeyCommandHandlerTest_HandleEvent_03
1779 * @tc.desc: Test HandleEvent
1780 * @tc.type: FUNC
1781 * @tc.require:
1782 */
1783 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleEvent_03, TestSize.Level1)
1784 {
1785 CALL_TEST_DEBUG;
1786 auto keyEvent = SetupKeyEvent();
1787 ASSERT_TRUE(keyEvent != nullptr);
1788 KeyCommandHandler eventKeyCommandHandler;
1789
1790 bool isHandled = eventKeyCommandHandler.HandleShortKeys(keyEvent);
1791 EXPECT_FALSE(isHandled);
1792 bool ret = eventKeyCommandHandler.HandleEvent(keyEvent);
1793 EXPECT_FALSE(ret);
1794 }
1795
1796 /**
1797 * @tc.name: KeyCommandHandlerTest_HandleEvent_04
1798 * @tc.desc: Test HandleEvent
1799 * @tc.type: FUNC
1800 * @tc.require:
1801 */
1802 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleEvent_04, TestSize.Level1)
1803 {
1804 CALL_TEST_DEBUG;
1805 auto keyEvent = SetupKeyEvent();
1806 ASSERT_TRUE(keyEvent != nullptr);
1807 KeyCommandHandler eventKeyCommandHandler;
1808
1809 eventKeyCommandHandler.isDownStart_ = true;
1810 bool isRepeatKeyHandle = eventKeyCommandHandler.HandleRepeatKeys(keyEvent);
1811 EXPECT_FALSE(isRepeatKeyHandle);
1812 bool ret = eventKeyCommandHandler.HandleEvent(keyEvent);
1813 EXPECT_FALSE(ret);
1814 }
1815
1816 /**
1817 * @tc.name: KeyCommandHandlerTest_HandleEvent_05
1818 * @tc.desc: Test HandleEvent
1819 * @tc.type: FUNC
1820 * @tc.require:
1821 */
1822 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleEvent_05, TestSize.Level1)
1823 {
1824 CALL_TEST_DEBUG;
1825 auto keyEvent = KeyEvent::Create();
1826 ASSERT_TRUE(keyEvent != nullptr);
1827 KeyCommandHandler keyCommandHandler;
1828 EXPECT_TRUE(keyCommandHandler.PreHandleEvent(keyEvent));
1829 EXPECT_FALSE(STYLUS_HANDLER->HandleStylusKey(keyEvent));
1830 EXPECT_FALSE(keyCommandHandler.HandleShortKeys(keyEvent));
1831
1832 bool ret = keyCommandHandler.HandleEvent(keyEvent);
1833 EXPECT_FALSE(ret);
1834 }
1835
1836 /**
1837 * @tc.name: KeyCommandHandlerTest_HandleEvent_06
1838 * @tc.desc: Test HandleEvent
1839 * @tc.type: FUNC
1840 * @tc.require:
1841 */
1842 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleEvent_06, TestSize.Level1)
1843 {
1844 CALL_TEST_DEBUG;
1845 auto keyEvent = KeyEvent::Create();
1846 ASSERT_TRUE(keyEvent != nullptr);
1847 KeyCommandHandler keyCommandHandler;
1848 EXPECT_TRUE(keyCommandHandler.PreHandleEvent(keyEvent));
1849 EXPECT_FALSE(STYLUS_HANDLER->HandleStylusKey(keyEvent));
1850 EXPECT_FALSE(keyCommandHandler.HandleShortKeys(keyEvent));
1851 EXPECT_FALSE(keyCommandHandler.HandleSequences(keyEvent));
1852 keyEvent->keyCode_ = KeyEvent::KEYCODE_POWER;
1853
1854 bool ret = keyCommandHandler.HandleEvent(keyEvent);
1855 EXPECT_FALSE(ret);
1856 }
1857
1858 /**
1859 * @tc.name: KeyCommandHandlerTest_ParseJson_01
1860 * @tc.desc: Test ParseJson
1861 * @tc.type: FUNC
1862 * @tc.require:
1863 */
1864 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_ParseJson_01, TestSize.Level1)
1865 {
1866 CALL_TEST_DEBUG;
1867 std::string configFile = "abc";
1868 std::string jsonStr = ReadJsonFile(configFile);
1869 KeyCommandHandler eventKeyCommandHandler;
1870
1871 jsonStr = "";
1872 bool ret = eventKeyCommandHandler.ParseJson(configFile);
1873 EXPECT_TRUE(jsonStr.empty());
1874 EXPECT_FALSE(ret);
1875 }
1876
1877 /**
1878 * @tc.name: KeyCommandHandlerTest_ParseJson_02
1879 * @tc.desc: Test ParseJson
1880 * @tc.type: FUNC
1881 * @tc.require:
1882 */
1883 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_ParseJson_02, TestSize.Level1)
1884 {
1885 CALL_TEST_DEBUG;
1886 std::string configFile = "config";
1887 std::string jsonStr = ReadJsonFile(configFile);
1888 KeyCommandHandler eventKeyCommandHandler;
1889
1890 jsonStr = "abc";
1891 bool ret = eventKeyCommandHandler.ParseJson(configFile);
1892 EXPECT_FALSE(jsonStr.empty());
1893 EXPECT_FALSE(ret);
1894 }
1895
1896 /**
1897 * @tc.name: KeyCommandHandlerTest_ProcessKnuckleGestureTouchUp_01
1898 * @tc.desc: Test ProcessKnuckleGestureTouchUp
1899 * @tc.type: FUNC
1900 * @tc.require:
1901 */
1902 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_ProcessKnuckleGestureTouchUp_01, TestSize.Level1)
1903 {
1904 CALL_TEST_DEBUG;
1905 NotifyType type;
1906 KeyCommandHandler handler;
1907 type = NotifyType::REGIONGESTURE;
1908 handler.isStartBase_ = false;
1909 ASSERT_NO_FATAL_FAILURE(handler.ProcessKnuckleGestureTouchUp(type));
1910
1911 handler.isStartBase_ = true;
1912 ASSERT_NO_FATAL_FAILURE(handler.ProcessKnuckleGestureTouchUp(type));
1913 }
1914
1915 /**
1916 * @tc.name: KeyCommandHandlerTest_ProcessKnuckleGestureTouchUp_02
1917 * @tc.desc: Test ProcessKnuckleGestureTouchUp
1918 * @tc.type: FUNC
1919 * @tc.require:
1920 */
1921 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_ProcessKnuckleGestureTouchUp_02, TestSize.Level1)
1922 {
1923 CALL_TEST_DEBUG;
1924 NotifyType type;
1925 KeyCommandHandler eventKeyCommandHandler;
1926 type = NotifyType::LETTERGESTURE;
1927 ASSERT_NO_FATAL_FAILURE(eventKeyCommandHandler.ProcessKnuckleGestureTouchUp(type));
1928 }
1929
1930 /**
1931 * @tc.name: KeyCommandHandlerTest_CheckTwoFingerGestureAction_01
1932 * @tc.desc: Test CheckTwoFingerGestureAction
1933 * @tc.type: FUNC
1934 * @tc.require:
1935 */
1936 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckTwoFingerGestureAction_01, TestSize.Level1)
1937 {
1938 CALL_TEST_DEBUG;
1939 KeyCommandHandler eventKeyCommandHandler;
1940 bool isActive = eventKeyCommandHandler.twoFingerGesture_.active;
1941 EXPECT_FALSE(isActive);
1942 bool ret = eventKeyCommandHandler.CheckTwoFingerGestureAction();
1943 EXPECT_FALSE(ret);
1944 }
1945
1946 /**
1947 * @tc.name: KeyCommandHandlerTest_CheckTwoFingerGestureAction_02
1948 * @tc.desc: Test CheckTwoFingerGestureAction
1949 * @tc.type: FUNC
1950 * @tc.require:
1951 */
1952 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckTwoFingerGestureAction_02, TestSize.Level1)
1953 {
1954 CALL_TEST_DEBUG;
1955 KeyCommandHandler eventKeyCommandHandler;
1956 auto pressTimeInterval = fabs(200000 - 40000);
1957 EXPECT_TRUE(pressTimeInterval > TWO_FINGERS_TIME_LIMIT);
1958 bool ret = eventKeyCommandHandler.CheckTwoFingerGestureAction();
1959 EXPECT_FALSE(ret);
1960 }
1961
1962 /**
1963 * @tc.name: KeyCommandHandlerTest_CheckTwoFingerGestureAction_03
1964 * @tc.desc: Test CheckTwoFingerGestureAction
1965 * @tc.type: FUNC
1966 * @tc.require:
1967 */
1968 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckTwoFingerGestureAction_03, TestSize.Level1)
1969 {
1970 CALL_TEST_DEBUG;
1971 KeyCommandHandler eventKeyCommandHandler;
1972 auto pressTimeInterval = fabs(200000 - 60000);
1973 EXPECT_FALSE(pressTimeInterval > TWO_FINGERS_TIME_LIMIT);
1974 bool ret = eventKeyCommandHandler.CheckTwoFingerGestureAction();
1975 EXPECT_FALSE(ret);
1976 }
1977
1978 #ifdef OHOS_BUILD_ENABLE_TOUCH
1979 /**
1980 * @tc.name: KeyCommandHandlerTest_TouchTest_001
1981 * @tc.desc: Test double finger down event
1982 * @tc.type: FUNC
1983 * @tc.require:
1984 */
1985 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_TouchTest_001, TestSize.Level1)
1986 {
1987 CALL_TEST_DEBUG;
1988 auto pointerEvent = SetupDoubleFingerDownEvent();
1989 ASSERT_TRUE(pointerEvent != nullptr);
1990 KeyCommandHandler keyCommandHandler;
1991 keyCommandHandler.HandlePointerActionDownEvent(pointerEvent);
1992 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE);
1993 keyCommandHandler.HandlePointerActionMoveEvent(pointerEvent);
1994 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP);
1995 keyCommandHandler.HandlePointerActionUpEvent(pointerEvent);
1996 ASSERT_FALSE(keyCommandHandler.GetSingleKnuckleGesture().state);
1997 ASSERT_FALSE(keyCommandHandler.GetDoubleKnuckleGesture().state);
1998 }
1999
2000 /**
2001 * @tc.name: KeyCommandHandlerTest_KnuckleTest_001
2002 * @tc.desc: Test single knuckle double click
2003 * @tc.type: FUNC
2004 * @tc.require:
2005 */
2006 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_KnuckleTest_001, TestSize.Level1)
2007 {
2008 CALL_TEST_DEBUG;
2009 auto pointerEvent = SetupSingleKnuckleDownEvent();
2010 ASSERT_TRUE(pointerEvent != nullptr);
2011 KeyCommandHandler keyCommandHandler;
2012 keyCommandHandler.SetKnuckleDoubleTapIntervalTime(DOUBLE_CLICK_INTERVAL_TIME_DEFAULT);
2013 keyCommandHandler.SetKnuckleDoubleTapDistance(DOUBLE_CLICK_DISTANCE_DEFAULT_CONFIG);
2014 int32_t actionTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND;
2015 pointerEvent->SetActionTime(actionTime);
2016 keyCommandHandler.HandlePointerActionDownEvent(pointerEvent);
2017 ASSERT_FALSE(keyCommandHandler.GetSingleKnuckleGesture().state);
2018 ASSERT_FALSE(keyCommandHandler.GetDoubleKnuckleGesture().state);
2019 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP);
2020 keyCommandHandler.HandlePointerActionUpEvent(pointerEvent);
2021 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
2022 actionTime = actionTime + INTERVAL_TIME;
2023 pointerEvent->SetActionTime(actionTime);
2024 keyCommandHandler.HandlePointerActionDownEvent(pointerEvent);
2025 ASSERT_TRUE(keyCommandHandler.GetSingleKnuckleGesture().state);
2026 ASSERT_FALSE(keyCommandHandler.GetDoubleKnuckleGesture().state);
2027 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP);
2028 keyCommandHandler.HandlePointerActionUpEvent(pointerEvent);
2029 }
2030
2031 /**
2032 * @tc.name: KeyCommandHandlerTest_KnuckleTest_002
2033 * @tc.desc: Test double knuckle double click
2034 * @tc.type: FUNC
2035 * @tc.require:
2036 */
2037 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_KnuckleTest_002, TestSize.Level1)
2038 {
2039 CALL_TEST_DEBUG;
2040 auto pointerEvent = SetupDoubleKnuckleDownEvent();
2041 ASSERT_TRUE(pointerEvent != nullptr);
2042 int32_t actionTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND;
2043 pointerEvent->SetActionTime(actionTime);
2044 KeyCommandHandler keyCommandHandler;
2045 keyCommandHandler.SetKnuckleDoubleTapIntervalTime(DOUBLE_CLICK_INTERVAL_TIME_DEFAULT);
2046 keyCommandHandler.SetKnuckleDoubleTapDistance(DOUBLE_CLICK_DISTANCE_DEFAULT_CONFIG);
2047 keyCommandHandler.HandlePointerActionDownEvent(pointerEvent);
2048 ASSERT_FALSE(keyCommandHandler.GetSingleKnuckleGesture().state);
2049 ASSERT_FALSE(keyCommandHandler.GetDoubleKnuckleGesture().state);
2050 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP);
2051 keyCommandHandler.HandlePointerActionUpEvent(pointerEvent);
2052 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
2053 actionTime = actionTime + INTERVAL_TIME;
2054 pointerEvent->SetActionTime(actionTime);
2055 keyCommandHandler.HandlePointerActionDownEvent(pointerEvent);
2056 ASSERT_FALSE(keyCommandHandler.GetSingleKnuckleGesture().state);
2057 ASSERT_TRUE(keyCommandHandler.GetDoubleKnuckleGesture().state);
2058 }
2059
2060 /**
2061 * @tc.name: KeyCommandHandlerTest_KnuckleTest_003
2062 * @tc.desc: Test single knuckle event to double knuckle event
2063 * @tc.type: FUNC
2064 * @tc.require:
2065 */
2066 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_KnuckleTest_003, TestSize.Level1)
2067 {
2068 CALL_TEST_DEBUG;
2069 auto singlePointerEvent = SetupSingleKnuckleDownEvent();
2070 ASSERT_TRUE(singlePointerEvent != nullptr);
2071 auto pointerEvent = SetupDoubleKnuckleDownEvent();
2072 ASSERT_TRUE(pointerEvent != nullptr);
2073 KeyCommandHandler keyCommandHandler;
2074 keyCommandHandler.HandlePointerActionDownEvent(singlePointerEvent);
2075 singlePointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP);
2076 keyCommandHandler.HandlePointerActionUpEvent(singlePointerEvent);
2077 keyCommandHandler.HandlePointerActionDownEvent(pointerEvent);
2078 ASSERT_FALSE(keyCommandHandler.GetSingleKnuckleGesture().state);
2079 ASSERT_FALSE(keyCommandHandler.GetDoubleKnuckleGesture().state);
2080 }
2081
2082 /**
2083 * @tc.name: KeyCommandHandlerTest_KnuckleTest_004
2084 * @tc.desc: Test sing knuckle double click interval time out
2085 * @tc.type: FUNC
2086 * @tc.require:
2087 */
2088 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_KnuckleTest_004, TestSize.Level1)
2089 {
2090 CALL_DEBUG_ENTER;
2091 auto pointerEvent = SetupSingleKnuckleDownEvent();
2092 ASSERT_TRUE(pointerEvent != nullptr);
2093 KeyCommandHandler keyCommandHandler;
2094 keyCommandHandler.SetKnuckleDoubleTapIntervalTime(DOUBLE_CLICK_INTERVAL_TIME_DEFAULT);
2095 keyCommandHandler.SetKnuckleDoubleTapDistance(DOUBLE_CLICK_DISTANCE_DEFAULT_CONFIG);
2096 int32_t actionTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND;
2097 pointerEvent->SetActionTime(actionTime);
2098 keyCommandHandler.HandlePointerActionDownEvent(pointerEvent);
2099 ASSERT_FALSE(keyCommandHandler.GetSingleKnuckleGesture().state);
2100 ASSERT_FALSE(keyCommandHandler.GetDoubleKnuckleGesture().state);
2101 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP);
2102 keyCommandHandler.HandlePointerActionUpEvent(pointerEvent);
2103 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
2104 actionTime = actionTime + INTERVAL_TIME_OUT;
2105 pointerEvent->SetActionTime(actionTime);
2106 keyCommandHandler.HandlePointerActionDownEvent(pointerEvent);
2107 ASSERT_FALSE(keyCommandHandler.GetSingleKnuckleGesture().state);
2108 ASSERT_FALSE(keyCommandHandler.GetDoubleKnuckleGesture().state);
2109 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP);
2110 keyCommandHandler.HandlePointerActionUpEvent(pointerEvent);
2111 }
2112
2113 /**
2114 * @tc.name: KeyCommandHandlerTest_KnuckleTest_005
2115 * @tc.desc: Test double knuckle double CLICK click interval time out
2116 * @tc.type: FUNC
2117 * @tc.require:
2118 */
2119 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_KnuckleTest_005, TestSize.Level1)
2120 {
2121 CALL_DEBUG_ENTER;
2122 auto pointerEvent = SetupDoubleKnuckleDownEvent();
2123 ASSERT_TRUE(pointerEvent != nullptr);
2124 int32_t actionTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND;
2125 pointerEvent->SetActionTime(actionTime);
2126 KeyCommandHandler keyCommandHandler;
2127 keyCommandHandler.SetKnuckleDoubleTapIntervalTime(DOUBLE_CLICK_INTERVAL_TIME_DEFAULT);
2128 keyCommandHandler.SetKnuckleDoubleTapDistance(DOUBLE_CLICK_DISTANCE_DEFAULT_CONFIG);
2129 keyCommandHandler.HandlePointerActionDownEvent(pointerEvent);
2130 ASSERT_FALSE(keyCommandHandler.GetSingleKnuckleGesture().state);
2131 ASSERT_FALSE(keyCommandHandler.GetDoubleKnuckleGesture().state);
2132 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP);
2133 keyCommandHandler.HandlePointerActionUpEvent(pointerEvent);
2134 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
2135 actionTime = actionTime + INTERVAL_TIME_OUT;
2136 pointerEvent->SetActionTime(actionTime);
2137 keyCommandHandler.HandlePointerActionDownEvent(pointerEvent);
2138 ASSERT_FALSE(keyCommandHandler.GetSingleKnuckleGesture().state);
2139 ASSERT_FALSE(keyCommandHandler.GetDoubleKnuckleGesture().state);
2140 }
2141
2142 /**
2143 * @tc.name: KeyCommandHandlerTest_KnuckleTest_006
2144 * @tc.desc: Test the tool type is TOOL_TYPE_TOUCHPAD Action down
2145 * @tc.type: FUNC
2146 * @tc.require:
2147 */
2148 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_KnuckleTest_006, TestSize.Level1)
2149 {
2150 CALL_DEBUG_ENTER;
2151 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
2152 ASSERT_TRUE(pointerEvent != nullptr);
2153 PointerEvent::PointerItem item;
2154 item.SetPointerId(0);
2155 item.SetToolType(PointerEvent::TOOL_TYPE_TOUCHPAD);
2156 int32_t downX = 100;
2157 int32_t downY = 200;
2158 item.SetDisplayX(downX);
2159 item.SetDisplayY(downY);
2160 item.SetPressed(true);
2161 pointerEvent->SetPointerId(0);
2162 pointerEvent->AddPointerItem(item);
2163 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
2164 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
2165 KeyCommandHandler keyCommandHandler;
2166 keyCommandHandler.HandlePointerActionDownEvent(pointerEvent);
2167 ASSERT_FALSE(keyCommandHandler.GetSingleKnuckleGesture().state);
2168 ASSERT_FALSE(keyCommandHandler.GetDoubleKnuckleGesture().state);
2169 }
2170
2171 /**
2172 * @tc.name: KeyCommandHandlerTest_KnuckleTest_007
2173 * @tc.desc: Test the tool type is TOOL_TYPE_TOUCHPAD Action up
2174 * @tc.type: FUNC
2175 * @tc.require:
2176 */
2177 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_KnuckleTest_007, TestSize.Level1)
2178 {
2179 CALL_DEBUG_ENTER;
2180 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
2181 ASSERT_TRUE(pointerEvent != nullptr);
2182 PointerEvent::PointerItem item;
2183 item.SetPointerId(0);
2184 item.SetToolType(PointerEvent::TOOL_TYPE_TOUCHPAD);
2185 int32_t downX = 100;
2186 int32_t downY = 200;
2187 item.SetDisplayX(downX);
2188 item.SetDisplayY(downY);
2189 item.SetPressed(true);
2190 pointerEvent->SetPointerId(0);
2191 pointerEvent->AddPointerItem(item);
2192 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP);
2193 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
2194 KeyCommandHandler keyCommandHandler;
2195 keyCommandHandler.HandlePointerActionUpEvent(pointerEvent);
2196 ASSERT_FALSE(keyCommandHandler.GetSingleKnuckleGesture().state);
2197 ASSERT_FALSE(keyCommandHandler.GetDoubleKnuckleGesture().state);
2198 }
2199
2200 /**
2201 * @tc.name: KeyCommandHandlerTest_HandleTouchEventTest_001
2202 * @tc.desc: Test signl knuckle CLICK set HandleTouchEvent pointerEvent
2203 * @tc.type: FUNC
2204 * @tc.require:
2205 */
2206 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleTouchEventTest_001, TestSize.Level1)
2207 {
2208 CALL_DEBUG_ENTER;
2209 auto pointerEvent = SetupSingleKnuckleDownEvent();
2210 ASSERT_TRUE(pointerEvent != nullptr);
2211 int32_t actionTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND;
2212 pointerEvent->SetActionTime(actionTime);
2213 KeyCommandHandler keyCommandHandler;
2214 keyCommandHandler.HandleTouchEvent(pointerEvent);
2215 ASSERT_FALSE(keyCommandHandler.GetSingleKnuckleGesture().state);
2216 ASSERT_FALSE(keyCommandHandler.GetDoubleKnuckleGesture().state);
2217 }
2218
2219 /**
2220 * @tc.name: KeyCommandHandlerTest_HandleTouchEventTest_002
2221 * @tc.desc: Test double knuckle CLICK set HandleTouchEvent pointerEvent
2222 * @tc.type: FUNC
2223 * @tc.require:
2224 */
2225 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleTouchEventTest_002, TestSize.Level1)
2226 {
2227 CALL_DEBUG_ENTER;
2228 auto pointerEvent = SetupDoubleKnuckleDownEvent();
2229 ASSERT_TRUE(pointerEvent != nullptr);
2230 int32_t actionTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND;
2231 pointerEvent->SetActionTime(actionTime);
2232 KeyCommandHandler keyCommandHandler;
2233 keyCommandHandler.HandleTouchEvent(pointerEvent);
2234 ASSERT_FALSE(keyCommandHandler.GetSingleKnuckleGesture().state);
2235 ASSERT_FALSE(keyCommandHandler.GetDoubleKnuckleGesture().state);
2236 }
2237
2238 /**
2239 * @tc.name: KeyCommandHandlerTest_HandleTouchEventTest_003
2240 * @tc.desc: Test signl knuckle double CLICK set HandleTouchEvent pointerEvent
2241 * @tc.type: FUNC
2242 * @tc.require:
2243 */
2244 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleTouchEventTest_003, TestSize.Level1)
2245 {
2246 CALL_DEBUG_ENTER;
2247 auto pointerEvent = SetupSingleKnuckleDownEvent();
2248 ASSERT_TRUE(pointerEvent != nullptr);
2249 int32_t actionTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND;
2250 pointerEvent->SetActionTime(actionTime);
2251 KeyCommandHandler keyCommandHandler;
2252 keyCommandHandler.HandleTouchEvent(pointerEvent);
2253 ASSERT_FALSE(keyCommandHandler.GetSingleKnuckleGesture().state);
2254 ASSERT_FALSE(keyCommandHandler.GetDoubleKnuckleGesture().state);
2255 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP);
2256 keyCommandHandler.HandleTouchEvent(pointerEvent);
2257 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
2258 actionTime = actionTime + INTERVAL_TIME;
2259 pointerEvent->SetActionTime(actionTime);
2260 keyCommandHandler.HandleTouchEvent(pointerEvent);
2261 ASSERT_FALSE(keyCommandHandler.GetSingleKnuckleGesture().state);
2262 ASSERT_FALSE(keyCommandHandler.GetDoubleKnuckleGesture().state);
2263 }
2264
2265 /**
2266 * @tc.name: KeyCommandHandlerTest_HandleTouchEventTest_004
2267 * @tc.desc: Test double knuckle double CLICK set HandleTouchEvent pointerEvent
2268 * @tc.type: FUNC
2269 * @tc.require:
2270 */
2271 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleTouchEventTest_004, TestSize.Level1)
2272 {
2273 CALL_DEBUG_ENTER;
2274 auto pointerEvent = SetupDoubleKnuckleDownEvent();
2275 ASSERT_TRUE(pointerEvent != nullptr);
2276 int32_t actionTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND;
2277 pointerEvent->SetActionTime(actionTime);
2278 KeyCommandHandler keyCommandHandler;
2279 keyCommandHandler.HandleTouchEvent(pointerEvent);
2280 ASSERT_FALSE(keyCommandHandler.GetSingleKnuckleGesture().state);
2281 ASSERT_FALSE(keyCommandHandler.GetDoubleKnuckleGesture().state);
2282 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP);
2283 keyCommandHandler.HandleTouchEvent(pointerEvent);
2284 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
2285 actionTime = actionTime + INTERVAL_TIME;
2286 pointerEvent->SetActionTime(actionTime);
2287 keyCommandHandler.HandleTouchEvent(pointerEvent);
2288 ASSERT_FALSE(keyCommandHandler.GetSingleKnuckleGesture().state);
2289 ASSERT_FALSE(keyCommandHandler.GetDoubleKnuckleGesture().state);
2290 }
2291 #endif // OHOS_BUILD_ENABLE_TOUCH
2292
2293 /**
2294 * @tc.name: KeyCommandHandlerTest_UpdateSettingsXml_001
2295 * @tc.desc: Update settings xml verify
2296 * @tc.type: FUNC
2297 * @tc.require:
2298 */
2299 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_UpdateSettingsXml_001, TestSize.Level1)
2300 {
2301 KeyCommandHandler handler;
2302 ASSERT_EQ(handler.UpdateSettingsXml("", 100), COMMON_PARAMETER_ERROR);
2303 ASSERT_EQ(handler.UpdateSettingsXml("businessId", 100), COMMON_PARAMETER_ERROR);
2304 handler.businessIds_ = {"businessId1", "businessId2"};
2305 ASSERT_EQ(handler.UpdateSettingsXml("businessId3", 100), COMMON_PARAMETER_ERROR);
2306 handler.businessIds_ = {"businessId"};
2307 ASSERT_EQ(handler.UpdateSettingsXml("businessId", 1000), 0);
2308 auto result = PREFERENCES_MGR->SetShortKeyDuration("businessId", 100);
2309 ASSERT_EQ(handler.UpdateSettingsXml("businessId", 100), result);
2310 }
2311
2312 /**
2313 * @tc.name: KeyCommandHandlerTest_AdjustTimeIntervalConfigIfNeed_001
2314 * @tc.desc: Adjust timeInterval configIf need verify
2315 * @tc.type: FUNC
2316 * @tc.require:
2317 */
2318 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_AdjustTimeIntervalConfigIfNeed_001, TestSize.Level1)
2319 {
2320 KeyCommandHandler handler;
2321 int64_t DOUBLE_CLICK_INTERVAL_TIME_SLOW = 450000;
2322 handler.downToPrevUpTimeConfig_ = DOUBLE_CLICK_INTERVAL_TIME_DEFAULT;
2323 handler.AdjustTimeIntervalConfigIfNeed(DOUBLE_CLICK_INTERVAL_TIME_SLOW);
2324 ASSERT_EQ(handler.downToPrevUpTimeConfig_, DOUBLE_CLICK_INTERVAL_TIME_DEFAULT);
2325 handler.downToPrevUpTimeConfig_ = DOUBLE_CLICK_INTERVAL_TIME_SLOW;
2326 handler.AdjustTimeIntervalConfigIfNeed(DOUBLE_CLICK_INTERVAL_TIME_DEFAULT);
2327 ASSERT_NE(handler.downToPrevUpTimeConfig_, DOUBLE_CLICK_INTERVAL_TIME_DEFAULT);
2328 handler.downToPrevUpTimeConfig_ = DOUBLE_CLICK_INTERVAL_TIME_DEFAULT;
2329 handler.AdjustTimeIntervalConfigIfNeed(DOUBLE_CLICK_INTERVAL_TIME_DEFAULT);
2330 ASSERT_EQ(handler.downToPrevUpTimeConfig_, DOUBLE_CLICK_INTERVAL_TIME_DEFAULT);
2331 handler.downToPrevUpTimeConfig_ = DOUBLE_CLICK_INTERVAL_TIME_SLOW;
2332 handler.AdjustTimeIntervalConfigIfNeed(DOUBLE_CLICK_INTERVAL_TIME_SLOW);
2333 ASSERT_EQ(handler.downToPrevUpTimeConfig_, DOUBLE_CLICK_INTERVAL_TIME_SLOW);
2334 }
2335
2336 /**
2337 * @tc.name: KeyCommandHandlerTest_AdjustDistanceConfigIfNeed_001
2338 * @tc.desc: Adjust distance configIf need verify
2339 * @tc.type: FUNC
2340 * @tc.require:
2341 */
2342 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_AdjustDistanceConfigIfNeed_001, TestSize.Level1)
2343 {
2344 KeyCommandHandler handler;
2345 handler.downToPrevDownDistanceConfig_ = handler.distanceDefaultConfig_;
2346 handler.AdjustDistanceConfigIfNeed(handler.distanceDefaultConfig_);
2347 ASSERT_EQ(handler.downToPrevDownDistanceConfig_, handler.distanceDefaultConfig_);
2348 handler.AdjustDistanceConfigIfNeed(handler.distanceLongConfig_);
2349 ASSERT_EQ(handler.downToPrevDownDistanceConfig_, handler.distanceDefaultConfig_);
2350 handler.downToPrevDownDistanceConfig_ = handler.distanceLongConfig_;
2351 handler.AdjustDistanceConfigIfNeed(handler.distanceDefaultConfig_);
2352 ASSERT_EQ(handler.downToPrevDownDistanceConfig_, handler.distanceDefaultConfig_);
2353 handler.AdjustDistanceConfigIfNeed(handler.distanceLongConfig_);
2354 ASSERT_EQ(handler.downToPrevDownDistanceConfig_, handler.distanceLongConfig_);
2355 handler.downToPrevDownDistanceConfig_ = handler.distanceDefaultConfig_;
2356 handler.AdjustDistanceConfigIfNeed(handler.distanceDefaultConfig_ - 1);
2357 ASSERT_EQ(handler.downToPrevDownDistanceConfig_, handler.distanceLongConfig_);
2358 handler.downToPrevDownDistanceConfig_ = handler.distanceLongConfig_;
2359 handler.AdjustDistanceConfigIfNeed(handler.distanceDefaultConfig_ - 1);
2360 ASSERT_EQ(handler.downToPrevDownDistanceConfig_, handler.distanceDefaultConfig_);
2361 }
2362
2363 /**
2364 * @tc.name: KeyCommandHandlerTest_StartTwoFingerGesture_001
2365 * @tc.desc: Start two finger gesture verify
2366 * @tc.type: FUNC
2367 * @tc.require:
2368 */
2369 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_StartTwoFingerGesture_001, TestSize.Level1)
2370 {
2371 KeyCommandHandler handler;
2372 handler.twoFingerGesture_.abilityStartDelay = 1000;
2373 handler.StartTwoFingerGesture();
2374 ASSERT_NE(-1, handler.twoFingerGesture_.timerId);
2375 }
2376
2377 /**
2378 * @tc.name: KeyCommandHandlerTest_SkipFinalKey
2379 * @tc.desc: Skip Final Key
2380 * @tc.type: FUNC
2381 * @tc.require:
2382 */
2383 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_SkipFinalKey, TestSize.Level1)
2384 {
2385 CALL_TEST_DEBUG;
2386 KeyCommandHandler handler;
2387 int32_t keyCode = 1024;
2388 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
2389 ASSERT_NE(keyEvent, nullptr);
2390 ASSERT_FALSE(handler.SkipFinalKey(keyCode, keyEvent));
2391 }
2392
2393 /**
2394 * @tc.name: KeyCommandHandlerTest_HandleKeyDown_01
2395 * @tc.desc: Handle Key Down
2396 * @tc.type: FUNC
2397 * @tc.require:
2398 */
2399 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKeyDown_01, TestSize.Level1)
2400 {
2401 CALL_TEST_DEBUG;
2402 KeyCommandHandler handler;
2403 ShortcutKey shortcutKey;
2404 shortcutKey.keyDownDuration = 0;
2405 ASSERT_TRUE(handler.HandleKeyDown(shortcutKey));
2406 }
2407
2408 /**
2409 * @tc.name: KeyCommandHandlerTest_HandleKeyDown_02
2410 * @tc.desc: test HandleKeyDown
2411 * @tc.type: FUNC
2412 * @tc.require:
2413 */
2414 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKeyDown_02, TestSize.Level1)
2415 {
2416 CALL_TEST_DEBUG;
2417 KeyCommandHandler handler;
2418 ShortcutKey shortcutKey;
2419 shortcutKey.timerId = -1;
2420 ASSERT_TRUE(handler.HandleKeyDown(shortcutKey));
2421 }
2422
2423 /**
2424 * @tc.name: KeyCommandHandlerTest_GetKeyDownDurationFromXml
2425 * @tc.desc: GetKeyDownDurationFromXml
2426 * @tc.type: FUNC
2427 * @tc.require:
2428 */
2429 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_GetKeyDownDurationFromXml, TestSize.Level1)
2430 {
2431 CALL_TEST_DEBUG;
2432 KeyCommandHandler handler;
2433 std::string businessId = "power";
2434 int32_t ret = handler.GetKeyDownDurationFromXml(businessId);
2435 ASSERT_EQ(ret, ERROR_DELAY_VALUE);
2436 }
2437
2438 /**
2439 * @tc.name: KeyCommandHandlerTest_HandleKeyUp_001
2440 * @tc.desc: HandleKeyUp
2441 * @tc.type: FUNC
2442 * @tc.require:
2443 */
2444 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKeyUp_001, TestSize.Level1)
2445 {
2446 CALL_TEST_DEBUG;
2447 KeyCommandHandler handler;
2448 ShortcutKey shortcutKey;
2449 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
2450 ASSERT_NE(keyEvent, nullptr);
2451 shortcutKey.keyDownDuration = 0;
2452 ASSERT_TRUE(handler.HandleKeyUp(keyEvent, shortcutKey));
2453 }
2454
2455 /**
2456 * @tc.name: KeyCommandHandlerTest_HandleKeyUp_002
2457 * @tc.desc: HandleKeyUp
2458 * @tc.type: FUNC
2459 * @tc.require:
2460 */
2461 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKeyUp_002, TestSize.Level1)
2462 {
2463 CALL_TEST_DEBUG;
2464 KeyCommandHandler handler;
2465 ShortcutKey shortcutKey;
2466 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
2467 ASSERT_NE(keyEvent, nullptr);
2468 shortcutKey.keyDownDuration = 1;
2469 ASSERT_FALSE(handler.HandleKeyUp(keyEvent, shortcutKey));
2470 }
2471
2472 /**
2473 * @tc.name: KeyCommandHandlerTest_HandleKeyUp_003
2474 * @tc.desc: HandleKeyUp
2475 * @tc.type: FUNC
2476 * @tc.require:
2477 */
2478 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKeyUp_003, TestSize.Level1)
2479 {
2480 CALL_TEST_DEBUG;
2481 KeyCommandHandler handler;
2482 ShortcutKey shortcutKey;
2483 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
2484 KeyEvent::KeyItem item;
2485 ASSERT_NE(keyEvent, nullptr);
2486 shortcutKey.keyDownDuration = 1;
2487 item.SetKeyCode(KeyEvent::KEYCODE_H);
2488 keyEvent->AddKeyItem(item);
2489 keyEvent->SetKeyCode(KeyEvent::KEYCODE_H);
2490 keyEvent->SetActionTime(10000);
2491 ASSERT_TRUE(handler.HandleKeyUp(keyEvent, shortcutKey));
2492 }
2493
2494 /**
2495 * @tc.name: KeyCommandHandlerTest_HandleKeyUp_004
2496 * @tc.desc: HandleKeyUp
2497 * @tc.type: FUNC
2498 * @tc.require:
2499 */
2500 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKeyUp_004, TestSize.Level1)
2501 {
2502 CALL_TEST_DEBUG;
2503 KeyCommandHandler handler;
2504 ShortcutKey shortcutKey;
2505 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
2506 KeyEvent::KeyItem item;
2507 ASSERT_NE(keyEvent, nullptr);
2508 shortcutKey.keyDownDuration = 10;
2509 item.SetKeyCode(KeyEvent::KEYCODE_H);
2510 keyEvent->AddKeyItem(item);
2511 keyEvent->SetKeyCode(KeyEvent::KEYCODE_H);
2512 keyEvent->SetActionTime(100);
2513 ASSERT_FALSE(handler.HandleKeyUp(keyEvent, shortcutKey));
2514 }
2515
2516 /**
2517 * @tc.name: KeyCommandHandlerTest_HandleKeyCancel
2518 * @tc.desc: HandleKeyCancel
2519 * @tc.type: FUNC
2520 * @tc.require:
2521 */
2522 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKeyCancel, TestSize.Level1)
2523 {
2524 CALL_TEST_DEBUG;
2525 KeyCommandHandler handler;
2526 ShortcutKey shortcutKey;
2527 shortcutKey.timerId = -1;
2528 ASSERT_FALSE(handler.HandleKeyCancel(shortcutKey));
2529 shortcutKey.timerId = 10;
2530 ASSERT_FALSE(handler.HandleKeyCancel(shortcutKey));
2531 }
2532
2533 /**
2534 * @tc.name: KeyCommandHandlerTest_LaunchAbility_001
2535 * @tc.desc: LaunchAbility
2536 * @tc.type: FUNC
2537 * @tc.require:
2538 */
2539 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_LaunchAbility_001, TestSize.Level1)
2540 {
2541 CALL_TEST_DEBUG;
2542 KeyCommandHandler handler;
2543 Ability ability;
2544 ability.abilityType = EXTENSION_ABILITY;
2545 ASSERT_NO_FATAL_FAILURE(handler.LaunchAbility(ability));
2546 ability.abilityType = EXTENSION_ABILITY_ABNORMAL;
2547 ASSERT_NO_FATAL_FAILURE(handler.LaunchAbility(ability));
2548 }
2549
2550 /**
2551 * @tc.name: KeyCommandHandlerTest_LaunchAbility_002
2552 * @tc.desc: LaunchAbility
2553 * @tc.type: FUNC
2554 * @tc.require:
2555 */
2556 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_LaunchAbility_002, TestSize.Level1)
2557 {
2558 CALL_TEST_DEBUG;
2559 KeyCommandHandler handler;
2560 ShortcutKey shortcutKey;
2561 ASSERT_NO_FATAL_FAILURE(handler.LaunchAbility(shortcutKey));
2562 }
2563
2564 /**
2565 * @tc.name: KeyCommandHandlerTest_LaunchAbility_003
2566 * @tc.desc: LaunchAbility
2567 * @tc.type: FUNC
2568 * @tc.require:
2569 */
2570 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_LaunchAbility_003, TestSize.Level1)
2571 {
2572 CALL_TEST_DEBUG;
2573 KeyCommandHandler handler;
2574 Sequence sequence;
2575 ASSERT_NO_FATAL_FAILURE(handler.LaunchAbility(sequence));
2576 }
2577
2578 /**
2579 * @tc.name: KeyCommandHandlerTest_LaunchAbility_004
2580 * @tc.desc: LaunchAbility
2581 * @tc.type: FUNC
2582 * @tc.require:
2583 */
2584 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_LaunchAbility_004, TestSize.Level1)
2585 {
2586 CALL_TEST_DEBUG;
2587 KeyCommandHandler handler;
2588 Ability ability;
2589 int64_t delay = 100;
2590 ability.deviceId = "deviceId";
2591 ability.bundleName = "bundleName";
2592 ability.abilityName = "abilityName";
2593 ability.uri = "abilityUri";
2594 ability.type = "type";
2595 ability.action = "abilityAction";
2596 ability.entities.push_back("entities");
2597 ability.params.insert(std::make_pair("paramsFirst", "paramsSecond"));
2598 ASSERT_NO_FATAL_FAILURE(handler.LaunchAbility(ability, delay));
2599 }
2600
2601 /**
2602 * @tc.name: KeyCommandHandlerTest_KeyCommandHandlerPrint
2603 * @tc.desc: Print
2604 * @tc.type: FUNC
2605 * @tc.require:
2606 */
2607 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_KeyCommandHandlerPrint, TestSize.Level1)
2608 {
2609 CALL_TEST_DEBUG;
2610 KeyCommandHandler handler;
2611 ShortcutKey shortcutKey;
2612 Ability ability_temp;
2613 std::string copyShortcutKey = "copyShortcutKey";
2614 shortcutKey.preKeys.insert(2072);
2615 shortcutKey.finalKey = 2019;
2616 shortcutKey.keyDownDuration = 100;
2617 ability_temp.bundleName = "bundleName";
2618 ability_temp.abilityName = "abilityName";
2619 shortcutKey.ability = ability_temp;
2620 handler.shortcutKeys_.insert(std::make_pair(copyShortcutKey, shortcutKey));
2621 ASSERT_NO_FATAL_FAILURE(handler.Print());
2622 }
2623
2624 /**
2625 * @tc.name: KeyCommandHandlerTest_shortcutKeyPrint
2626 * @tc.desc: Print
2627 * @tc.type: FUNC
2628 * @tc.require:
2629 */
2630 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_shortcutKeyPrint, TestSize.Level1)
2631 {
2632 CALL_TEST_DEBUG;
2633 ShortcutKey shortcutKey;
2634 Ability ability_temp;
2635 shortcutKey.preKeys.insert(2072);
2636 shortcutKey.finalKey = 2019;
2637 ability_temp.bundleName = "bundleName";
2638 shortcutKey.ability = ability_temp;
2639 ASSERT_NO_FATAL_FAILURE(shortcutKey.Print());
2640 }
2641
2642 /**
2643 * @tc.name: KeyCommandHandlerTest_RemoveSubscribedTimer
2644 * @tc.desc: RemoveSubscribedTimer
2645 * @tc.type: FUNC
2646 * @tc.require:
2647 */
2648 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_RemoveSubscribedTimer, TestSize.Level1)
2649 {
2650 CALL_TEST_DEBUG;
2651 KeyCommandHandler handler;
2652 int32_t keyCode = 16;
2653 std::list<int32_t> timerIds;
2654 timerIds.push_back(100);
2655 handler.specialTimers_.insert(std::make_pair(keyCode, timerIds));
2656 ASSERT_NO_FATAL_FAILURE(handler.RemoveSubscribedTimer(keyCode));
2657 keyCode = 17;
2658 ASSERT_NO_FATAL_FAILURE(handler.RemoveSubscribedTimer(keyCode));
2659 }
2660
2661 /**
2662 * @tc.name: KeyCommandHandlerTest_HandleSpecialKeys
2663 * @tc.desc: HandleSpecialKeys
2664 * @tc.type: FUNC
2665 * @tc.require:
2666 */
2667 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleSpecialKeys, TestSize.Level1)
2668 {
2669 CALL_TEST_DEBUG;
2670 KeyCommandHandler handler;
2671 int32_t keyCodeVolumeUp = 16;
2672 int32_t keyCodeVolumeDown = 17;
2673 int32_t keyAction = KeyEvent::KEY_ACTION_UP;
2674 handler.specialKeys_.insert(std::make_pair(keyCodeVolumeUp, keyAction));
2675 ASSERT_NO_FATAL_FAILURE(handler.HandleSpecialKeys(keyCodeVolumeUp, keyAction));
2676 handler.specialKeys_.clear();
2677
2678 keyAction = KeyEvent::KEY_ACTION_DOWN;
2679 ASSERT_NO_FATAL_FAILURE(handler.HandleSpecialKeys(keyCodeVolumeDown, keyAction));
2680 }
2681
2682 /**
2683 * @tc.name: KeyCommandHandlerTest_HandleSpecialKeys_001
2684 * @tc.desc: Overrides the HandleSpecialKeys function exception branch
2685 * @tc.type: FUNC
2686 * @tc.require:
2687 */
2688 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleSpecialKeys_001, TestSize.Level1)
2689 {
2690 CALL_DEBUG_ENTER;
2691 KeyCommandHandler handler;
2692 int32_t powerKeyCode = 18;
2693 int32_t keyCode = 2017;
2694 int32_t keyAction = KeyEvent::KEY_ACTION_UP;
2695 handler.specialKeys_.insert(std::make_pair(powerKeyCode, keyAction));
2696 ASSERT_NO_FATAL_FAILURE(handler.HandleSpecialKeys(keyCode, keyAction));
2697
2698 keyAction = KeyEvent::KEY_ACTION_DOWN;
2699 ASSERT_NO_FATAL_FAILURE(handler.HandleSpecialKeys(powerKeyCode, keyAction));
2700 }
2701
2702 /**
2703 * @tc.name: KeyCommandHandlerTest_InterruptTimers
2704 * @tc.desc: InterruptTimers
2705 * @tc.type: FUNC
2706 * @tc.require:
2707 */
2708 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_InterruptTimers, TestSize.Level1)
2709 {
2710 CALL_TEST_DEBUG;
2711 KeyCommandHandler handler;
2712 Sequence sequence;
2713 sequence.timerId = 1;
2714 handler.filterSequences_.push_back(sequence);
2715 ASSERT_NO_FATAL_FAILURE(handler.InterruptTimers());
2716
2717 handler.filterSequences_.clear();
2718 sequence.timerId = -1;
2719 handler.filterSequences_.push_back(sequence);
2720 ASSERT_NO_FATAL_FAILURE(handler.InterruptTimers());
2721 }
2722
2723 /**
2724 * @tc.name: KeyCommandHandlerTest_SetKnuckleDoubleTapIntervalTime
2725 * @tc.desc: SetKnuckleDoubleTapIntervalTime
2726 * @tc.type: FUNC
2727 * @tc.require:
2728 */
2729 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_SetKnuckleDoubleTapIntervalTime, TestSize.Level1)
2730 {
2731 CALL_TEST_DEBUG;
2732 KeyCommandHandler handler;
2733 int64_t interval = -1;
2734 ASSERT_NO_FATAL_FAILURE(handler.SetKnuckleDoubleTapIntervalTime(interval));
2735 }
2736
2737 /**
2738 * @tc.name: KeyCommandHandlerTest_SetKnuckleDoubleTapDistance
2739 * @tc.desc: SetKnuckleDoubleTapDistance
2740 * @tc.type: FUNC
2741 * @tc.require:
2742 */
2743 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_SetKnuckleDoubleTapDistance, TestSize.Level1)
2744 {
2745 CALL_TEST_DEBUG;
2746 KeyCommandHandler handler;
2747 float distance = -1.0f;
2748 ASSERT_NO_FATAL_FAILURE(handler.SetKnuckleDoubleTapDistance(distance));
2749 }
2750
2751 /**
2752 * @tc.name: KeyCommandHandlerTest_HandleMulFingersTap
2753 * @tc.desc: Overrides the HandleMulFingersTap function exception branch
2754 * @tc.type: FUNC
2755 * @tc.require:
2756 */
2757 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleMulFingersTap, TestSize.Level1)
2758 {
2759 CALL_DEBUG_ENTER;
2760 KeyCommandHandler handler;
2761 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
2762 ASSERT_NE(pointerEvent, nullptr);
2763 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_QUADTAP);
2764 ASSERT_FALSE(handler.HandleMulFingersTap(pointerEvent));
2765 }
2766
2767 /**
2768 * @tc.name: KeyCommandHandlerTest_IsKeyMatch
2769 * @tc.desc: IsKeyMatch
2770 * @tc.type: FUNC
2771 * @tc.require:
2772 */
2773 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_IsKeyMatch, TestSize.Level1)
2774 {
2775 CALL_TEST_DEBUG;
2776 KeyCommandHandler handler;
2777 ShortcutKey shortcutKey;
2778 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
2779 ASSERT_NE(keyEvent, nullptr);
2780 KeyEvent::KeyItem item;
2781 shortcutKey.finalKey = 2019;
2782 shortcutKey.preKeys.insert(2072);
2783 shortcutKey.triggerType = KeyEvent::KEY_ACTION_DOWN;
2784 item.SetKeyCode(KeyEvent::KEYCODE_C);
2785 keyEvent->AddKeyItem(item);
2786 keyEvent->SetKeyCode(KeyEvent::KEYCODE_C);
2787 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
2788 ASSERT_FALSE(handler.IsKeyMatch(shortcutKey, keyEvent));
2789
2790 shortcutKey.preKeys.insert(2047);
2791 item.SetKeyCode(KeyEvent::KEYCODE_B);
2792 keyEvent->AddKeyItem(item);
2793 item.SetKeyCode(KeyEvent::KEYCODE_E);
2794 keyEvent->AddKeyItem(item);
2795 ASSERT_FALSE(handler.IsKeyMatch(shortcutKey, keyEvent));
2796 }
2797
2798 /**
2799 * @tc.name: KeyCommandHandlerTest_HandleSequence
2800 * @tc.desc: HandleSequence
2801 * @tc.type: FUNC
2802 * @tc.require:
2803 */
2804 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleSequence, TestSize.Level1)
2805 {
2806 CALL_TEST_DEBUG;
2807 KeyCommandHandler handler;
2808 Sequence sequence;
2809 SequenceKey sequenceKey;
2810 bool isLaunchAbility = false;
2811 sequence.statusConfigValue = false;
2812 ASSERT_FALSE(handler.HandleSequence(sequence, isLaunchAbility));
2813
2814 sequence.statusConfigValue = true;
2815 sequenceKey.keyCode = 2017;
2816 sequenceKey.keyAction = KeyEvent::KEY_ACTION_DOWN;
2817 handler.keys_.push_back(sequenceKey);
2818 sequenceKey.keyCode = 2018;
2819 sequenceKey.keyAction = KeyEvent::KEY_ACTION_DOWN;
2820 handler.keys_.push_back(sequenceKey);
2821
2822 sequenceKey.keyCode = 2019;
2823 sequenceKey.keyAction = KeyEvent::KEY_ACTION_UP;
2824 sequence.sequenceKeys.push_back(sequenceKey);
2825 ASSERT_FALSE(handler.HandleSequence(sequence, isLaunchAbility));
2826
2827 sequenceKey.keyCode = 2017;
2828 sequenceKey.keyAction = KeyEvent::KEY_ACTION_UP;
2829 sequence.sequenceKeys.push_back(sequenceKey);
2830 ASSERT_FALSE(handler.HandleSequence(sequence, isLaunchAbility));
2831 }
2832
2833 /**
2834 * @tc.name: KeyCommandHandlerTest_IsRepeatKeyEvent
2835 * @tc.desc: IsRepeatKeyEvent
2836 * @tc.type: FUNC
2837 * @tc.require:
2838 */
2839 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_IsRepeatKeyEvent, TestSize.Level1)
2840 {
2841 CALL_TEST_DEBUG;
2842 KeyCommandHandler handler;
2843 SequenceKey sequenceKey;
2844 sequenceKey.keyCode = 2018;
2845 sequenceKey.keyAction = KeyEvent::KEY_ACTION_DOWN;
2846 handler.keys_.push_back(sequenceKey);
2847
2848 sequenceKey.keyCode = 2018;
2849 sequenceKey.keyAction = KeyEvent::KEY_ACTION_DOWN;
2850 ASSERT_TRUE(handler.IsRepeatKeyEvent(sequenceKey));
2851
2852 sequenceKey.keyAction = KeyEvent::KEY_ACTION_UP;
2853 ASSERT_FALSE(handler.IsRepeatKeyEvent(sequenceKey));
2854
2855 handler.keys_.clear();
2856 sequenceKey.keyCode = 2019;
2857 handler.keys_.push_back(sequenceKey);
2858 sequenceKey.keyCode = 2020;
2859 ASSERT_FALSE(handler.IsRepeatKeyEvent(sequenceKey));
2860 }
2861
2862 /**
2863 * @tc.name: KeyCommandHandlerTest_HandleSequences
2864 * @tc.desc: HandleSequences
2865 * @tc.type: FUNC
2866 * @tc.require:
2867 */
2868 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleSequences, TestSize.Level1)
2869 {
2870 CALL_TEST_DEBUG;
2871 KeyCommandHandler handler;
2872 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
2873 ASSERT_NE(keyEvent, nullptr);
2874 handler.matchedSequence_.timerId = 10;
2875 ASSERT_FALSE(handler.HandleSequences(keyEvent));
2876 handler.matchedSequence_.timerId = -1;
2877 ASSERT_FALSE(handler.HandleSequences(keyEvent));
2878
2879 keyEvent->SetKeyCode(2017);
2880 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_UP);
2881 keyEvent->SetActionTime(10000);
2882 SequenceKey sequenceKey;
2883 Sequence sequence;
2884 handler.sequences_.push_back(sequence);
2885 sequenceKey.actionTime = 15000;
2886 handler.keys_.push_back(sequenceKey);
2887 ASSERT_FALSE(handler.HandleSequences(keyEvent));
2888
2889 handler.keys_.clear();
2890 keyEvent->SetActionTime(1500000);
2891 sequenceKey.actionTime = 200000;
2892 sequence.statusConfigValue = false;
2893 handler.filterSequences_.push_back(sequence);
2894 ASSERT_FALSE(handler.HandleSequences(keyEvent));
2895 }
2896
2897 /**
2898 * @tc.name: KeyCommandHandlerTest_HandleRepeatKeyCount
2899 * @tc.desc: HandleRepeatKeyCount
2900 * @tc.type: FUNC
2901 * @tc.require:
2902 */
2903 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleRepeatKeyCount, TestSize.Level1)
2904 {
2905 CALL_TEST_DEBUG;
2906 KeyCommandHandler handler;
2907 RepeatKey repeatKey;
2908 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
2909 ASSERT_NE(keyEvent, nullptr);
2910 repeatKey.keyCode = 2017;
2911 keyEvent->SetKeyCode(2017);
2912 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_UP);
2913 keyEvent->SetActionTime(20);
2914 handler.repeatKey_.keyCode = 2018;
2915 ASSERT_TRUE(handler.HandleRepeatKeyCount(repeatKey, keyEvent));
2916
2917 handler.repeatKey_.keyCode = 2017;
2918 ASSERT_TRUE(handler.HandleRepeatKeyCount(repeatKey, keyEvent));
2919
2920 handler.intervalTime_ = 100;
2921 keyEvent->SetActionTime(50);
2922 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
2923 ASSERT_TRUE(handler.HandleRepeatKeyCount(repeatKey, keyEvent));
2924
2925 keyEvent->SetKeyCode(2018);
2926 ASSERT_FALSE(handler.HandleRepeatKeyCount(repeatKey, keyEvent));
2927 }
2928
2929 /**
2930 * @tc.name: KeyCommandHandlerTest_HandleKeyUpCancel
2931 * @tc.desc: HandleKeyUpCancel
2932 * @tc.type: FUNC
2933 * @tc.require:
2934 */
2935 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKeyUpCancel, TestSize.Level1)
2936 {
2937 CALL_TEST_DEBUG;
2938 KeyCommandHandler handler;
2939 RepeatKey repeatKey;
2940 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
2941 ASSERT_NE(keyEvent, nullptr);
2942 repeatKey.keyCode = KeyEvent::KEYCODE_VOLUME_DOWN;
2943 keyEvent->SetKeyCode(KeyEvent::KEYCODE_VOLUME_DOWN);
2944 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_CANCEL);
2945 ASSERT_TRUE(handler.HandleKeyUpCancel(repeatKey, keyEvent));
2946 }
2947
2948 /**
2949 * @tc.name: KeyCommandHandlerTest_HandleRepeatKey
2950 * @tc.desc: HandleRepeatKey
2951 * @tc.type: FUNC
2952 * @tc.require:
2953 */
2954 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleRepeatKey, TestSize.Level1)
2955 {
2956 CALL_TEST_DEBUG;
2957 KeyCommandHandler handler;
2958 RepeatKey repeatKey;
2959 bool isLaunched = false;
2960 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
2961 ASSERT_NE(keyEvent, nullptr);
2962 repeatKey.times = 2;
2963 repeatKey.keyCode = KeyEvent::KEYCODE_POWER;
2964 keyEvent->SetKeyCode(KeyEvent::KEYCODE_POWER);
2965 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_UP);
2966 ASSERT_FALSE(handler.HandleRepeatKey(repeatKey, isLaunched, keyEvent));
2967 }
2968
2969 /**
2970 * @tc.name: KeyCommandHandlerTest_CreateKeyEvent
2971 * @tc.desc: CreateKeyEvent
2972 * @tc.type: FUNC
2973 * @tc.require:
2974 */
2975 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CreateKeyEvent, TestSize.Level1)
2976 {
2977 CALL_TEST_DEBUG;
2978 KeyCommandHandler handler;
2979 int32_t keyCode = 2017;
2980 int32_t keyAction = KeyEvent::KEY_ACTION_DOWN;
2981 bool isPressed = true;
2982 ASSERT_NE(handler.CreateKeyEvent(keyCode, keyAction, isPressed), nullptr);
2983 }
2984
2985 /**
2986 * @tc.name: KeyCommandHandlerTest_IsEnableCombineKey
2987 * @tc.desc: Test IsEnableCombineKey
2988 * @tc.type: FUNC
2989 * @tc.require:
2990 */
2991 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_IsEnableCombineKey, TestSize.Level1)
2992 {
2993 CALL_TEST_DEBUG;
2994 KeyCommandHandler handler;
2995 KeyEvent::KeyItem item;
2996 std::shared_ptr<KeyEvent> key = KeyEvent::Create();
2997 ASSERT_NE(key, nullptr);
2998 handler.enableCombineKey_ = false;
2999 item.SetKeyCode(KeyEvent::KEYCODE_A);
3000 key->SetKeyCode(KeyEvent::KEYCODE_POWER);
3001 key->SetKeyAction(KeyEvent::KEY_ACTION_UP);
3002 key->AddKeyItem(item);
3003 ASSERT_FALSE(handler.IsEnableCombineKey(key));
3004 item.SetKeyCode(KeyEvent::KEYCODE_B);
3005 key->AddKeyItem(item);
3006 ASSERT_FALSE(handler.IsEnableCombineKey(key));
3007 key->SetKeyCode(KeyEvent::KEYCODE_L);
3008 ASSERT_FALSE(handler.IsEnableCombineKey(key));
3009 }
3010
3011 /**
3012 * @tc.name: KeyCommandHandlerTest_AdjustTimeIntervalConfigIfNeed
3013 * @tc.desc: Test AdjustTimeIntervalConfigIfNeed
3014 * @tc.type: FUNC
3015 * @tc.require:
3016 */
3017 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_AdjustTimeIntervalConfigIfNeed, TestSize.Level1)
3018 {
3019 CALL_TEST_DEBUG;
3020 KeyCommandHandler handler;
3021 int64_t intervalTime = 300000;
3022 handler.downToPrevUpTimeConfig_ = DOUBLE_CLICK_INTERVAL_TIME_DEFAULT;
3023 handler.checkAdjustIntervalTimeCount_ = 0;
3024 ASSERT_NO_FATAL_FAILURE(handler.AdjustTimeIntervalConfigIfNeed(intervalTime));
3025
3026 handler.downToPrevUpTimeConfig_ = DOUBLE_CLICK_INTERVAL_TIME_SLOW;
3027 ASSERT_NO_FATAL_FAILURE(handler.AdjustTimeIntervalConfigIfNeed(intervalTime));
3028
3029 intervalTime = 10000;
3030 handler.checkAdjustIntervalTimeCount_ = 6;
3031 ASSERT_NO_FATAL_FAILURE(handler.AdjustTimeIntervalConfigIfNeed(intervalTime));
3032
3033 handler.downToPrevUpTimeConfig_ = 100000;
3034 ASSERT_NO_FATAL_FAILURE(handler.AdjustTimeIntervalConfigIfNeed(intervalTime));
3035 }
3036
3037 /**
3038 * @tc.name: KeyCommandHandlerTest_AdjustDistanceConfigIfNeed
3039 * @tc.desc: Test AdjustDistanceConfigIfNeed
3040 * @tc.type: FUNC
3041 * @tc.require:
3042 */
3043 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_AdjustDistanceConfigIfNeed, TestSize.Level1)
3044 {
3045 CALL_TEST_DEBUG;
3046 KeyCommandHandler handler;
3047 float distance = 5.0f;
3048 handler.downToPrevDownDistanceConfig_ = 10.0f;
3049 handler.distanceDefaultConfig_ = 10.0f;
3050 ASSERT_NO_FATAL_FAILURE(handler.AdjustDistanceConfigIfNeed(distance));
3051
3052 distance = 20.0f;
3053 handler.distanceLongConfig_ = 15.0f;
3054 ASSERT_NO_FATAL_FAILURE(handler.AdjustDistanceConfigIfNeed(distance));
3055
3056 distance = 12.0f;
3057 handler.checkAdjustDistanceCount_ = 6;
3058 ASSERT_NO_FATAL_FAILURE(handler.AdjustDistanceConfigIfNeed(distance));
3059
3060 handler.downToPrevDownDistanceConfig_ = 15.0f;
3061 ASSERT_NO_FATAL_FAILURE(handler.AdjustDistanceConfigIfNeed(distance));
3062
3063 distance = 5.0f;
3064 handler.checkAdjustDistanceCount_ = 0;
3065 ASSERT_NO_FATAL_FAILURE(handler.AdjustDistanceConfigIfNeed(distance));
3066
3067 handler.downToPrevDownDistanceConfig_ = 11.5f;
3068 ASSERT_NO_FATAL_FAILURE(handler.AdjustDistanceConfigIfNeed(distance));
3069 }
3070
3071 /**
3072 * @tc.name: KeyCommandHandlerTest_AdjustDistanceConfigIfNeed_002
3073 * @tc.desc: Test AdjustDistanceConfigIfNeed
3074 * @tc.type: FUNC
3075 * @tc.require:
3076 */
3077 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_AdjustDistanceConfigIfNeed_002, TestSize.Level1)
3078 {
3079 CALL_TEST_DEBUG;
3080 KeyCommandHandler handler;
3081 float distance = 15.0f;
3082 handler.downToPrevDownDistanceConfig_ = 10.0f;
3083 handler.distanceLongConfig_ = 10.0f;
3084 handler.distanceDefaultConfig_ = 5.0f;
3085 ASSERT_NO_FATAL_FAILURE(handler.AdjustDistanceConfigIfNeed(distance));
3086 handler.distanceDefaultConfig_ = 20.0f;
3087 handler.checkAdjustDistanceCount_ = 6;
3088 ASSERT_NO_FATAL_FAILURE(handler.AdjustDistanceConfigIfNeed(distance));
3089 handler.downToPrevDownDistanceConfig_ = 30.0f;
3090 ASSERT_NO_FATAL_FAILURE(handler.AdjustDistanceConfigIfNeed(distance));
3091 }
3092
3093 #ifdef OHOS_BUILD_ENABLE_GESTURESENSE_WRAPPER
3094 /**
3095 * @tc.name: KeyCommandHandlerTest_HandleKnuckleGestureTouchDown_001
3096 * @tc.desc: Test knuckle gesture touch down event
3097 * @tc.type: FUNC
3098 * @tc.require:
3099 */
3100 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureTouchDown_001, TestSize.Level1)
3101 {
3102 CALL_TEST_DEBUG;
3103 KeyCommandHandler handler;
3104 PointerEvent::PointerItem item;
3105 std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
3106 ASSERT_NE(touchEvent, nullptr);
3107
3108 item.SetPointerId(1);
3109 item.SetRawDisplayX(4);
3110 item.SetRawDisplayY(4);
3111 touchEvent->SetPointerId(1);
3112 touchEvent->SetActionTime(1);
3113 touchEvent->AddPointerItem(item);
3114 KeyCommandHandler keyCommandHandler;
3115 keyCommandHandler.HandleKnuckleGestureTouchDown(touchEvent);
3116
3117 ASSERT_TRUE(handler.gestureTimeStamps_.empty());
3118 }
3119
3120 /**
3121 * @tc.name: KeyCommandHandlerTest_HandleKnuckleGestureTouchMove_001
3122 * @tc.desc: Test knuckle gesture touch move event
3123 * @tc.type: FUNC
3124 * @tc.require:
3125 */
3126 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureTouchMove_001, TestSize.Level1)
3127 {
3128 CALL_TEST_DEBUG;
3129 KeyCommandHandler handler;
3130 std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
3131 ASSERT_NE(touchEvent, nullptr);
3132
3133 handler.gestureLastX_ = 4.0;
3134 handler.gestureLastY_ = 4.0;
3135
3136 PointerEvent::PointerItem item1;
3137 item1.SetPointerId(2);
3138 item1.SetRawDisplayX(24);
3139 item1.SetRawDisplayY(24);
3140 touchEvent->AddPointerItem(item1);
3141 touchEvent->SetActionTime(6);
3142 touchEvent->SetPointerId(2);
3143
3144 handler.HandleKnuckleGestureTouchMove(touchEvent);
3145 ASSERT_FALSE(handler.isLetterGesturing_);
3146 }
3147
3148 /**
3149 * @tc.name: KeyCommandHandlerTest_HandleKnuckleGestureTouchUp_001
3150 * @tc.desc: Test knuckle gesture touch up event partial screenshot
3151 * @tc.type: FUNC
3152 * @tc.require:
3153 */
3154 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureTouchUp_001, TestSize.Level1)
3155 {
3156 CALL_TEST_DEBUG;
3157 KeyCommandHandler handler;
3158 std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
3159 ASSERT_NE(touchEvent, nullptr);
3160
3161 handler.gesturePoints_.assign(CIRCLE_COORDINATES.begin(), CIRCLE_COORDINATES.end());
3162 handler.gestureTimeStamps_.assign(CIRCLE_TIMESTAMPS.begin(), CIRCLE_TIMESTAMPS.end());
3163 handler.isGesturing_ = true;
3164 handler.isLetterGesturing_ = true;
3165
3166 ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchUp(touchEvent));
3167 }
3168
3169 /**
3170 * @tc.name: KeyCommandHandlerTest_HandleKnuckleGestureTouchUp_002
3171 * @tc.desc: Test knuckle gesture touch up event long screenshot
3172 * @tc.type: FUNC
3173 * @tc.require:
3174 */
3175 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureTouchUp_002, TestSize.Level1)
3176 {
3177 CALL_TEST_DEBUG;
3178 KeyCommandHandler handler;
3179 std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
3180 ASSERT_NE(touchEvent, nullptr);
3181
3182 handler.gesturePoints_.assign(CURVE_COORDINATES.begin(), CURVE_COORDINATES.end());
3183 handler.gestureTimeStamps_.assign(CURVE_TIMESTAMPS.begin(), CURVE_TIMESTAMPS.end());
3184 handler.isGesturing_ = true;
3185 handler.isLetterGesturing_ = true;
3186
3187 ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchUp(touchEvent));
3188 }
3189
3190 /**
3191 * @tc.name: KeyCommandHandlerTest_HandleKnuckleGestureTouchUp_003
3192 * @tc.desc: Test knuckle gesture touch up event straight line
3193 * @tc.type: FUNC
3194 * @tc.require:
3195 */
3196 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureTouchUp_003, TestSize.Level1)
3197 {
3198 CALL_TEST_DEBUG;
3199 KeyCommandHandler handler;
3200 std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
3201 ASSERT_NE(touchEvent, nullptr);
3202
3203 handler.gesturePoints_.assign(LINE_COORDINATES.begin(), LINE_COORDINATES.end());
3204 handler.gestureTimeStamps_.assign(LINE_TIMESTAMPS.begin(), LINE_TIMESTAMPS.end());
3205 handler.isGesturing_ = true;
3206 handler.isLetterGesturing_ = true;
3207
3208 ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchUp(touchEvent));
3209 }
3210
3211 /**
3212 * @tc.name: KeyCommandHandlerTest_ResetKnuckleGesture_001
3213 * @tc.desc: Test ResetKnuckleGesture function
3214 * @tc.type: FUNC
3215 * @tc.require:
3216 */
3217 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_ResetKnuckleGesture_001, TestSize.Level1)
3218 {
3219 CALL_TEST_DEBUG;
3220 KeyCommandHandler handler;
3221 handler.gestureLastX_ = 1.0f;
3222 handler.gestureLastY_ = 1.0f;
3223 handler.isGesturing_ = true;
3224 handler.isDistanceConfig_ = true;
3225 handler.gestureTrackLength_ = 2.0f;
3226 handler.gesturePoints_.assign(CURVE_COORDINATES.begin(), CURVE_COORDINATES.end());
3227 handler.gestureTimeStamps_.assign(CURVE_TIMESTAMPS.begin(), CURVE_TIMESTAMPS.end());
3228
3229 handler.ResetKnuckleGesture();
3230 ASSERT_EQ(handler.gestureLastX_, 0.0f);
3231 ASSERT_EQ(handler.gestureLastY_, 0.0f);
3232 ASSERT_FALSE(handler.isGesturing_);
3233 ASSERT_TRUE(handler.isDistanceConfig_);
3234 ASSERT_EQ(handler.gestureTrackLength_, 0.0f);
3235 ASSERT_TRUE(handler.gesturePoints_.empty());
3236 ASSERT_TRUE(handler.gestureTimeStamps_.empty());
3237 }
3238
3239 /**
3240 * @tc.name: KeyCommandHandlerTest_GesturePointsToStr_001
3241 * @tc.desc: Test GesturePointsToStr function
3242 * @tc.type: FUNC
3243 * @tc.require:
3244 */
3245 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_GesturePointsToStr_001, TestSize.Level1)
3246 {
3247 CALL_TEST_DEBUG;
3248 KeyCommandHandler handler;
3249 handler.gesturePoints_ = { 0.0f, 1.0f, 2.0f, 3.0f };
3250
3251 auto result = handler.GesturePointsToStr();
3252 ASSERT_EQ(result.length(), 50);
3253 ASSERT_EQ(handler.gesturePoints_.size(), 4);
3254 }
3255
3256 /**
3257 * @tc.name: KeyCommandHandlerTest_GesturePointsToStr_002
3258 * @tc.desc: Test GesturePointsToStr function
3259 * @tc.type: FUNC
3260 * @tc.require:
3261 */
3262 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_GesturePointsToStr_002, TestSize.Level1)
3263 {
3264 CALL_TEST_DEBUG;
3265 KeyCommandHandler handler;
3266
3267 auto result = handler.GesturePointsToStr();
3268 ASSERT_TRUE(result.empty());
3269 ASSERT_TRUE(handler.gesturePoints_.empty());
3270 }
3271
3272 /**
3273 * @tc.name: KeyCommandHandlerTest_GesturePointsToStr_003
3274 * @tc.desc: Test GesturePointsToStr function
3275 * @tc.type: FUNC
3276 * @tc.require:
3277 */
3278 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_GesturePointsToStr_003, TestSize.Level1)
3279 {
3280 CALL_TEST_DEBUG;
3281 KeyCommandHandler handler;
3282 handler.gesturePoints_ = { 0.0f };
3283
3284 auto result = handler.GesturePointsToStr();
3285 ASSERT_TRUE(result.empty());
3286 ASSERT_EQ(handler.gesturePoints_.size(), 1);
3287 }
3288
3289 /**
3290 * @tc.name: KeyCommandHandlerTest_HandleKnuckleGestureEvent_001
3291 * @tc.desc: Test HandleKnuckleGestureEvent function
3292 * @tc.type: FUNC
3293 * @tc.require:
3294 */
3295 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureEvent_001, TestSize.Level1)
3296 {
3297 CALL_TEST_DEBUG;
3298 KeyCommandHandler handler;
3299 PointerEvent::PointerItem item;
3300 std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
3301 ASSERT_NE(touchEvent, nullptr);
3302 item.SetPointerId(1);
3303 item.SetToolType(PointerEvent::TOOL_TYPE_FINGER);
3304 touchEvent->AddPointerItem(item);
3305 touchEvent->SetPointerId(1);
3306 touchEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
3307 ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureEvent(touchEvent));
3308
3309 item.SetToolType(PointerEvent::TOOL_TYPE_KNUCKLE);
3310 touchEvent->AddPointerItem(item);
3311 touchEvent->SetPointerId(1);
3312 touchEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
3313 ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureEvent(touchEvent));
3314
3315 handler.singleKnuckleGesture_.state = true;
3316 ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureEvent(touchEvent));
3317 }
3318
3319 /**
3320 * @tc.name: KeyCommandHandlerTest_HandleKnuckleGestureEvent_002
3321 * @tc.desc: Test HandleKnuckleGestureEvent function
3322 * @tc.type: FUNC
3323 * @tc.require:
3324 */
3325 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureEvent_002, TestSize.Level1)
3326 {
3327 CALL_TEST_DEBUG;
3328 KeyCommandHandler handler;
3329 PointerEvent::PointerItem item;
3330 std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
3331 ASSERT_NE(touchEvent, nullptr);
3332 item.SetPointerId(1);
3333 item.SetToolType(PointerEvent::TOOL_TYPE_KNUCKLE);
3334 touchEvent->AddPointerItem(item);
3335 touchEvent->SetPointerId(1);
3336 touchEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
3337
3338 handler.singleKnuckleGesture_.state = false;
3339 handler.knuckleSwitch_.statusConfigValue = false;
3340 ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureEvent(touchEvent));
3341 }
3342
3343 /**
3344 * @tc.name: KeyCommandHandlerTest_HandleKnuckleGestureEvent_003
3345 * @tc.desc: Test HandleKnuckleGestureEvent function
3346 * @tc.type: FUNC
3347 * @tc.require:
3348 */
3349 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureEvent_003, TestSize.Level1)
3350 {
3351 CALL_TEST_DEBUG;
3352 KeyCommandHandler handler;
3353 PointerEvent::PointerItem item;
3354 std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
3355 ASSERT_NE(touchEvent, nullptr);
3356 item.SetPointerId(1);
3357 item.SetToolType(PointerEvent::TOOL_TYPE_KNUCKLE);
3358 touchEvent->AddPointerItem(item);
3359 touchEvent->SetPointerId(1);
3360 touchEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
3361
3362 handler.singleKnuckleGesture_.state = false;
3363 handler.knuckleSwitch_.statusConfigValue = true;
3364 ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureEvent(touchEvent));
3365 }
3366
3367 /**
3368 * @tc.name: KeyCommandHandlerTest_IsValidAction
3369 * @tc.desc: Test IsValidAction
3370 * @tc.type: FUNC
3371 * @tc.require:
3372 */
3373 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_IsValidAction, TestSize.Level1)
3374 {
3375 CALL_TEST_DEBUG;
3376 KeyCommandHandler handler;
3377 int32_t action = PointerEvent::POINTER_ACTION_DOWN;
3378 ASSERT_NO_FATAL_FAILURE(handler.IsValidAction(action));
3379
3380 action = PointerEvent::POINTER_ACTION_MOVE;
3381 handler.gesturePoints_ = { 0.0f };
3382 ASSERT_NO_FATAL_FAILURE(handler.IsValidAction(action));
3383
3384 action = PointerEvent::POINTER_ACTION_UP;
3385 handler.gesturePoints_.assign(CIRCLE_COORDINATES.begin(), CIRCLE_COORDINATES.end());
3386 ASSERT_NO_FATAL_FAILURE(handler.IsValidAction(action));
3387 }
3388 #endif // OHOS_BUILD_ENABLE_GESTURESENSE_WRAPPER
3389
3390 /**
3391 * @tc.name: KeyCommandHandlerTest_HandleShortKeys_001
3392 * @tc.desc: Test the funcation HandleShortKeys
3393 * @tc.type: FUNC
3394 * @tc.require:
3395 */
3396 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleShortKeys_001, TestSize.Level1)
3397 {
3398 CALL_TEST_DEBUG;
3399 KeyCommandHandler handler;
3400 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
3401 ASSERT_NE(keyEvent, nullptr);
3402 bool ret = handler.HandleShortKeys(keyEvent);
3403 ASSERT_FALSE(ret);
3404 ShortcutKey key;
3405 key.preKeys = {1, 2, 3};
3406 key.businessId = "business1";
3407 key.statusConfig = "config1";
3408 key.statusConfigValue = true;
3409 key.finalKey = 4;
3410 key.keyDownDuration = 5;
3411 key.triggerType = KeyEvent::KEY_ACTION_DOWN;
3412 key.timerId = 6;
3413 Ability ability_temp;
3414 ability_temp.bundleName = "bundleName1";
3415 ability_temp.abilityName = "abilityName1";
3416 key.ability = ability_temp;
3417 handler.shortcutKeys_.insert(std::make_pair("key1", key));
3418 ret = handler.HandleShortKeys(keyEvent);
3419 ASSERT_FALSE(ret);
3420 handler.lastMatchedKey_.timerId = 1;
3421 ret = handler.HandleShortKeys(keyEvent);
3422 ASSERT_FALSE(ret);
3423 handler.lastMatchedKey_.timerId = -1;
3424 ret = handler.HandleShortKeys(keyEvent);
3425 ASSERT_FALSE(ret);
3426 std::string businessId = "power";
3427 ret = handler.HandleShortKeys(keyEvent);
3428 ASSERT_FALSE(ret);
3429 }
3430
3431 /**
3432 * @tc.name: KeyCommandHandlerTest_HandleShortKeys_002
3433 * @tc.desc: Test the funcation HandleShortKeys
3434 * @tc.type: FUNC
3435 * @tc.require:
3436 */
3437 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleShortKeys_002, TestSize.Level1)
3438 {
3439 CALL_TEST_DEBUG;
3440 KeyCommandHandler handler;
3441 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
3442 ASSERT_NE(keyEvent, nullptr);
3443 ShortcutKey key;
3444 key.preKeys = {1, 2, 3};
3445 key.businessId = "business2";
3446 key.statusConfig = "config2";
3447 key.statusConfigValue = true;
3448 key.finalKey = 5;
3449 key.keyDownDuration = 6;
3450 key.triggerType = KeyEvent::KEY_ACTION_UP;
3451 key.timerId = 6;
3452 Ability ability_temp;
3453 ability_temp.bundleName = "bundleName2";
3454 ability_temp.abilityName = "abilityName2";
3455 key.ability = ability_temp;
3456 handler.shortcutKeys_.insert(std::make_pair("key2", key));
3457 bool ret = handler.HandleShortKeys(keyEvent);
3458 ASSERT_FALSE(ret);
3459 handler.lastMatchedKey_.timerId = -1;
3460 ret = handler.HandleShortKeys(keyEvent);
3461 ASSERT_FALSE(ret);
3462 std::string businessId = "power";
3463 ret = handler.HandleShortKeys(keyEvent);
3464 ASSERT_FALSE(ret);
3465 }
3466
3467 /**
3468 * @tc.name: KeyCommandHandlerTest_HandleShortKeys_003
3469 * @tc.desc: Test the funcation HandleShortKeys
3470 * @tc.type: FUNC
3471 * @tc.require:
3472 */
3473 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleShortKeys_003, TestSize.Level1)
3474 {
3475 CALL_TEST_DEBUG;
3476 KeyCommandHandler handler;
3477 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
3478 ASSERT_NE(keyEvent, nullptr);
3479 ShortcutKey key;
3480 key.preKeys = {1, 2, 3};
3481 key.businessId = "business3";
3482 key.statusConfig = "config3";
3483 key.statusConfigValue = true;
3484 key.finalKey = 7;
3485 key.keyDownDuration = 8;
3486 key.triggerType = KeyEvent::KEY_ACTION_CANCEL;
3487 key.timerId = 6;
3488 Ability ability_temp;
3489 ability_temp.bundleName = "bundleName3";
3490 ability_temp.abilityName = "abilityName3";
3491 key.ability = ability_temp;
3492 handler.shortcutKeys_.insert(std::make_pair("key3", key));
3493 bool ret = handler.HandleShortKeys(keyEvent);
3494 ASSERT_FALSE(ret);
3495 handler.lastMatchedKey_.timerId = -1;
3496 ret = handler.HandleShortKeys(keyEvent);
3497 ASSERT_FALSE(ret);
3498 std::string businessId = "power";
3499 ret = handler.HandleShortKeys(keyEvent);
3500 ASSERT_FALSE(ret);
3501 }
3502
3503 /**
3504 * @tc.name: KeyCommandHandlerTest_HandleShortKeys_04
3505 * @tc.desc: Test the funcation HandleShortKeys
3506 * @tc.type: FUNC
3507 * @tc.require:
3508 */
3509 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleShortKeys_04, TestSize.Level1)
3510 {
3511 CALL_TEST_DEBUG;
3512 KeyCommandHandler handler;
3513 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
3514 ASSERT_NE(keyEvent, nullptr);
3515 ShortcutKey key;
3516 key.preKeys = {1, 2, 3};
3517 key.businessId = "business2";
3518 key.statusConfig = "config2";
3519 key.statusConfigValue = true;
3520 key.finalKey = 5;
3521 key.keyDownDuration = 6;
3522 key.triggerType = KeyEvent::KEY_ACTION_UP;
3523 key.timerId = 6;
3524 Ability ability_temp;
3525 ability_temp.bundleName = "bundleName2";
3526 ability_temp.abilityName = "abilityName2";
3527 key.ability = ability_temp;
3528 handler.shortcutKeys_.insert(std::make_pair("key2", key));
3529 bool ret = handler.HandleShortKeys(keyEvent);
3530 EXPECT_FALSE(ret);
3531 handler.lastMatchedKey_.timerId = -1;
3532 ret = handler.HandleShortKeys(keyEvent);
3533 EXPECT_FALSE(ret);
3534
3535 key.businessId = "power";
3536 int32_t delay = handler.GetKeyDownDurationFromXml(key.businessId);
3537 EXPECT_TRUE(delay < 0);
3538 key.triggerType = KeyEvent::KEY_ACTION_DOWN;
3539 ret = handler.HandleShortKeys(keyEvent);
3540 EXPECT_FALSE(ret);
3541
3542 key.triggerType = KeyEvent::KEY_ACTION_UP;
3543 bool handleResult = handler.HandleKeyUp(keyEvent, key);
3544 EXPECT_FALSE(handleResult);
3545 ret = handler.HandleShortKeys(keyEvent);
3546 EXPECT_FALSE(ret);
3547 }
3548
3549 /**
3550 * @tc.name: KeyCommandHandlerTest_AddSequenceKey_001
3551 * @tc.desc: Test the funcation AddSequenceKey
3552 * @tc.type: FUNC
3553 * @tc.require:
3554 */
3555 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_AddSequenceKey_001, TestSize.Level1)
3556 {
3557 CALL_TEST_DEBUG;
3558 KeyCommandHandler handler;
3559 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
3560 ASSERT_NE(keyEvent, nullptr);
3561 SequenceKey sequenceKey;
3562 sequenceKey.keyCode = 1;
3563 sequenceKey.keyAction = 2;
3564 sequenceKey.actionTime = 3;
3565 sequenceKey.delay = 4;
3566 handler.keys_.push_back(sequenceKey);
3567 bool ret = handler.AddSequenceKey(keyEvent);
3568 ASSERT_TRUE(ret);
3569 }
3570
3571 /**
3572 * @tc.name: KeyCommandHandlerTest_AddSequenceKey_002
3573 * @tc.desc: Test the funcation AddSequenceKey
3574 * @tc.type: FUNC
3575 * @tc.require:
3576 */
3577 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_AddSequenceKey_002, TestSize.Level1)
3578 {
3579 CALL_TEST_DEBUG;
3580 KeyCommandHandler handler;
3581 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
3582 ASSERT_NE(keyEvent, nullptr);
3583 SequenceKey sequenceKey;
3584 sequenceKey.keyCode = 1;
3585 sequenceKey.keyAction = 2;
3586 sequenceKey.actionTime = 15;
3587 sequenceKey.delay = 16;
3588 handler.keys_.push_back(sequenceKey);
3589 bool ret = handler.AddSequenceKey(keyEvent);
3590 ASSERT_TRUE(ret);
3591 }
3592
3593 /**
3594 * @tc.name: KeyCommandHandlerTest_AddSequenceKey_003
3595 * @tc.desc: Test the funcation AddSequenceKey
3596 * @tc.type: FUNC
3597 * @tc.require:
3598 */
3599 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_AddSequenceKey_003, TestSize.Level1)
3600 {
3601 CALL_TEST_DEBUG;
3602 KeyCommandHandler handler;
3603 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
3604 ASSERT_NE(keyEvent, nullptr);
3605 SequenceKey sequenceKey;
3606 sequenceKey.keyCode = 1;
3607 sequenceKey.keyAction = 2;
3608 sequenceKey.actionTime = -2;
3609 sequenceKey.delay = -3;
3610 handler.keys_.push_back(sequenceKey);
3611 bool ret = handler.AddSequenceKey(keyEvent);
3612 ASSERT_TRUE(ret);
3613 handler.keys_.clear();
3614 ret = handler.AddSequenceKey(keyEvent);
3615 ASSERT_TRUE(ret);
3616 }
3617
3618 /**
3619 * @tc.name: KeyCommandHandlerTest_HandleNormalSequence_001
3620 * @tc.desc: Test the funcation HandleNormalSequence
3621 * @tc.type: FUNC
3622 * @tc.require:
3623 */
3624 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleNormalSequence_001, TestSize.Level1)
3625 {
3626 CALL_TEST_DEBUG;
3627 KeyCommandHandler handler;
3628 Sequence sequence;
3629 bool isLaunchAbility = true;
3630 sequence.abilityStartDelay = 0;
3631 bool ret = handler.HandleNormalSequence(sequence, isLaunchAbility);
3632 ASSERT_TRUE(ret);
3633 sequence.abilityStartDelay = 1;
3634 sequence.timerId = -1;
3635 ret = handler.HandleNormalSequence(sequence, isLaunchAbility);
3636 ASSERT_TRUE(ret);
3637 sequence.timerId = 1;
3638 ret = handler.HandleNormalSequence(sequence, isLaunchAbility);
3639 ASSERT_TRUE(ret);
3640 }
3641
3642 /**
3643 * @tc.name: KeyCommandHandlerTest_HandleMatchedSequence_001
3644 * @tc.desc: Test the funcation HandleMatchedSequence
3645 * @tc.type: FUNC
3646 * @tc.require:
3647 */
3648 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleMatchedSequence_001, TestSize.Level1)
3649 {
3650 CALL_TEST_DEBUG;
3651 KeyCommandHandler handler;
3652 Sequence sequence;
3653 bool isLaunchAbility = true;
3654 sequence.ability.bundleName = ".screenshot";
3655 bool ret = handler.HandleMatchedSequence(sequence, isLaunchAbility);
3656 ASSERT_TRUE(ret);
3657 sequence.ability.bundleName = "abc";
3658 DisplayEventMonitor displayEventMonitor;
3659 displayEventMonitor.screenStatus_ = "usual.event.SCREEN_OFF";
3660 ret = handler.HandleMatchedSequence(sequence, isLaunchAbility);
3661 ASSERT_TRUE(ret);
3662 displayEventMonitor.screenStatus_ = "usual.event.SCREEN_ON";
3663 ret = handler.HandleMatchedSequence(sequence, isLaunchAbility);
3664 ASSERT_TRUE(ret);
3665 displayEventMonitor.isScreenLocked_ = true;
3666 ret = handler.HandleMatchedSequence(sequence, isLaunchAbility);
3667 ASSERT_TRUE(ret);
3668 displayEventMonitor.isScreenLocked_ = false;
3669 ret = handler.HandleMatchedSequence(sequence, isLaunchAbility);
3670 ASSERT_TRUE(ret);
3671 }
3672
3673 /**
3674 * @tc.name: KeyCommandHandlerTest_HandleSequence_001
3675 * @tc.desc: Test the funcation HandleSequence
3676 * @tc.type: FUNC
3677 * @tc.require:
3678 */
3679 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleSequence_001, TestSize.Level1)
3680 {
3681 CALL_TEST_DEBUG;
3682 KeyCommandHandler handler;
3683 Sequence sequence;
3684 SequenceKey sequenceKey;
3685 bool isLaunchAbility = true;
3686 sequence.statusConfigValue = false;
3687 bool ret = handler.HandleSequence(sequence, isLaunchAbility);
3688 ASSERT_FALSE(ret);
3689 sequence.statusConfigValue = true;
3690 sequenceKey.keyCode = 10;
3691 sequenceKey.keyAction = KeyEvent::KEY_ACTION_DOWN;
3692 sequenceKey.actionTime = 10;
3693 sequenceKey.delay = 10;
3694 handler.keys_.push_back(sequenceKey);
3695 sequence.sequenceKeys.push_back(sequenceKey);
3696 ret = handler.HandleSequence(sequence, isLaunchAbility);
3697 ASSERT_TRUE(ret);
3698 }
3699
3700 /**
3701 * @tc.name: KeyCommandHandlerTest_ConvertKeyActionToString_001
3702 * @tc.desc: Test the funcation ConvertKeyActionToString
3703 * @tc.type: FUNC
3704 * @tc.require:
3705 */
3706 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_ConvertKeyActionToString_001, TestSize.Level1)
3707 {
3708 CALL_TEST_DEBUG;
3709 KeyCommandHandler handler;
3710 int32_t keyAction = 0;
3711 std::string ret = handler.ConvertKeyActionToString(keyAction);
3712 ASSERT_EQ(ret, "UNKNOWN");
3713 keyAction = 1;
3714 ret = handler.ConvertKeyActionToString(keyAction);
3715 ASSERT_EQ(ret, "CANCEL");
3716 keyAction = 2;
3717 ret = handler.ConvertKeyActionToString(keyAction);
3718 ASSERT_EQ(ret, "DOWN");
3719 keyAction = 3;
3720 ret = handler.ConvertKeyActionToString(keyAction);
3721 ASSERT_EQ(ret, "UP");
3722 keyAction = 4;
3723 ret = handler.ConvertKeyActionToString(keyAction);
3724 ASSERT_EQ(ret, "UNKNOWN_ACTION");
3725 }
3726
3727 /**
3728 * @tc.name: KeyCommandHandlerTest_HandleKeyEvent_001
3729 * @tc.desc: Test the funcation HandleKeyEvent
3730 * @tc.type: FUNC
3731 * @tc.require:
3732 */
3733 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKeyEvent_001, TestSize.Level1)
3734 {
3735 CALL_TEST_DEBUG;
3736 KeyCommandHandler handler;
3737 handler.EnableCombineKey(false);
3738 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
3739 ASSERT_NE(keyEvent, nullptr);
3740 KeyEvent::KeyItem item;
3741 item.SetKeyCode(KeyEvent::KEYCODE_POWER);
3742 keyEvent->AddKeyItem(item);
3743 keyEvent->SetKeyCode(KeyEvent::KEYCODE_POWER);
3744 ASSERT_NO_FATAL_FAILURE(handler.HandleKeyEvent(keyEvent));
3745 }
3746
3747 /**
3748 * @tc.name: KeyCommandHandlerTest_HandlePointerEvent_001
3749 * @tc.desc: Test the funcation HandlePointerEvent
3750 * @tc.type: FUNC
3751 * @tc.require:
3752 */
3753 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandlePointerEvent_001, TestSize.Level1)
3754 {
3755 CALL_TEST_DEBUG;
3756 KeyCommandHandler handler;
3757 handler.EnableCombineKey(false);
3758 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
3759 ASSERT_TRUE(pointerEvent != nullptr);
3760 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
3761 ASSERT_NE(keyEvent, nullptr);
3762 KeyEvent::KeyItem item;
3763 item.SetKeyCode(KeyEvent::KEYCODE_POWER);
3764 keyEvent->AddKeyItem(item);
3765 keyEvent->SetKeyCode(KeyEvent::KEYCODE_POWER);
3766 ASSERT_NO_FATAL_FAILURE(handler.HandlePointerEvent(pointerEvent));
3767 }
3768
3769 /**
3770 * @tc.name: KeyCommandHandlerTest_HandleTouchEventTest_005
3771 * @tc.desc: Test the funcation HandleTouchEvent
3772 * @tc.require:
3773 */
3774 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleTouchEventTest_005, TestSize.Level1)
3775 {
3776 CALL_DEBUG_ENTER;
3777 KeyCommandHandler handler;
3778 std::shared_ptr<PointerEvent> pointerEvent = SetupDoubleKnuckleDownEvent();
3779 ASSERT_TRUE(pointerEvent != nullptr);
3780 handler.nextHandler_ = std::make_shared<EventFilterHandler>();
3781 handler.SetNext(handler.nextHandler_);
3782 PointerEvent::PointerItem item;
3783 std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
3784 ASSERT_NE(touchEvent, nullptr);
3785 item.SetPointerId(1);
3786 item.SetToolType(PointerEvent::TOOL_TYPE_KNUCKLE);
3787 touchEvent->AddPointerItem(item);
3788 ASSERT_NO_FATAL_FAILURE(handler.HandleTouchEvent(pointerEvent));
3789 item.SetPointerId(2);
3790 item.SetToolType(PointerEvent::TOOL_TYPE_PALM);
3791 touchEvent->AddPointerItem(item);
3792 ASSERT_NO_FATAL_FAILURE(handler.HandleTouchEvent(pointerEvent));
3793 }
3794
3795 /**
3796 * @tc.name: KeyCommandHandlerTest_CheckTwoFingerGestureAction_001
3797 * @tc.desc: Test the funcation CheckTwoFingerGestureAction
3798 * @tc.type: FUNC
3799 * @tc.require:
3800 */
3801 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckTwoFingerGestureAction_001, TestSize.Level1)
3802 {
3803 CALL_TEST_DEBUG;
3804 KeyCommandHandler handler;
3805 handler.twoFingerGesture_.active = false;
3806 bool ret = handler.CheckTwoFingerGestureAction();
3807 EXPECT_FALSE(ret);
3808 handler.twoFingerGesture_.active = true;
3809 handler.twoFingerGesture_.touches[0].id = 1;
3810 handler.twoFingerGesture_.touches[0].x = 100;
3811 handler.twoFingerGesture_.touches[0].y = 200;
3812 handler.twoFingerGesture_.touches[0].downTime = 250000;
3813 handler.twoFingerGesture_.touches[1].id = 2;
3814 handler.twoFingerGesture_.touches[1].x = 300;
3815 handler.twoFingerGesture_.touches[1].y = 400;
3816 handler.twoFingerGesture_.touches[1].downTime = 50000;
3817 ret = handler.CheckTwoFingerGestureAction();
3818 EXPECT_FALSE(ret);
3819 }
3820
3821 /**
3822 * @tc.name: KeyCommandHandlerTest_CheckTwoFingerGestureAction_002
3823 * @tc.desc: Test the funcation CheckTwoFingerGestureAction
3824 * @tc.type: FUNC
3825 * @tc.require:
3826 */
3827 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckTwoFingerGestureAction_002, TestSize.Level1)
3828 {
3829 CALL_TEST_DEBUG;
3830 KeyCommandHandler handler;
3831 handler.twoFingerGesture_.active = true;
3832 handler.twoFingerGesture_.touches[0].id = 1;
3833 handler.twoFingerGesture_.touches[0].x = 100;
3834 handler.twoFingerGesture_.touches[0].y = 200;
3835 handler.twoFingerGesture_.touches[0].downTime = 150000;
3836 handler.twoFingerGesture_.touches[1].id = 2;
3837 handler.twoFingerGesture_.touches[1].x = 300;
3838 handler.twoFingerGesture_.touches[1].y = 400;
3839 handler.twoFingerGesture_.touches[1].downTime = 50000;
3840 bool ret = handler.CheckTwoFingerGestureAction();
3841 EXPECT_FALSE(ret);
3842 }
3843
3844 /**
3845 * @tc.name: KeyCommandHandlerTest_ConvertVPToPX_001
3846 * @tc.desc: Test the funcation ConvertVPToPX
3847 * @tc.type: FUNC
3848 * @tc.require:
3849 */
3850 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_ConvertVPToPX_001, TestSize.Level1)
3851 {
3852 CALL_TEST_DEBUG;
3853 KeyCommandHandler handler;
3854 int32_t vp = -1;
3855 ASSERT_NO_FATAL_FAILURE(handler.ConvertVPToPX(vp));
3856 vp = 1;
3857 ASSERT_NO_FATAL_FAILURE(handler.ConvertVPToPX(vp));
3858 }
3859
3860 /**
3861 * @tc.name: KeyCommandHandlerTest_HandleKnuckleGestureTouchMove_002
3862 * @tc.desc: Test the funcation HandleKnuckleGestureTouchMove
3863 * @tc.type: FUNC
3864 * @tc.require:
3865 */
3866 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureTouchMove_002, TestSize.Level1)
3867 {
3868 CALL_TEST_DEBUG;
3869 KeyCommandHandler handler;
3870 std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
3871 ASSERT_NE(touchEvent, nullptr);
3872 PointerEvent::PointerItem item;
3873 item.displayX_ = 8.0;
3874 item.displayY_ = 8.0;
3875 handler.gestureLastX_ = 4.0;
3876 handler.gestureLastY_ = 4.0;
3877 handler.isGesturing_ = false;
3878 ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchMove(touchEvent));
3879 handler.isGesturing_ = true;
3880 handler.isLetterGesturing_ = false;
3881 ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchMove(touchEvent));
3882 handler.isLetterGesturing_ = true;
3883 ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchMove(touchEvent));
3884 handler.gestureLastX_ = 6.0;
3885 ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchMove(touchEvent));
3886 handler.gestureLastY_ = 6.0;
3887 ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchMove(touchEvent));
3888 }
3889
3890 /**
3891 * @tc.name: KeyCommandHandlerTest_ReportIfNeed_001
3892 * @tc.desc: Test the funcation ReportIfNeed
3893 * @tc.type: FUNC
3894 * @tc.require:
3895 */
3896 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_ReportIfNeed_001, TestSize.Level1)
3897 {
3898 CALL_TEST_DEBUG;
3899 KeyCommandHandler handler;
3900 ASSERT_NO_FATAL_FAILURE(handler.ReportIfNeed());
3901 handler.isGesturing_ = true;
3902 handler.isLastGestureSucceed_ = true;
3903 ASSERT_NO_FATAL_FAILURE(handler.ReportIfNeed());
3904 handler.isLastGestureSucceed_ = false;
3905 ASSERT_NO_FATAL_FAILURE(handler.ReportIfNeed());
3906 }
3907
3908 /**
3909 * @tc.name: KeyCommandHandlerTest_ReportGestureInfo_001
3910 * @tc.desc: Test the funcation ReportGestureInfo
3911 * @tc.type: FUNC
3912 * @tc.require:
3913 */
3914 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_ReportGestureInfo_001, TestSize.Level1)
3915 {
3916 CALL_TEST_DEBUG;
3917 KeyCommandHandler handler;
3918 handler.isLastGestureSucceed_ = true;
3919 ASSERT_NO_FATAL_FAILURE(handler.ReportGestureInfo());
3920 handler.isLastGestureSucceed_ = false;
3921 ASSERT_NO_FATAL_FAILURE(handler.ReportGestureInfo());
3922 }
3923
3924 /**
3925 * @tc.name: KeyCommandHandlerTest_AddSequenceKey_004
3926 * @tc.desc: Test the funcation AddSequenceKey
3927 * @tc.type: FUNC
3928 * @tc.require:
3929 */
3930 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_AddSequenceKey_004, TestSize.Level1)
3931 {
3932 CALL_TEST_DEBUG;
3933 KeyCommandHandler handler;
3934 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
3935 ASSERT_NE(keyEvent, nullptr);
3936 std::shared_ptr<InputEvent> inputEvent = InputEvent::Create();
3937 EXPECT_NE(inputEvent, nullptr);
3938 inputEvent->actionTime_ = 1;
3939 SequenceKey sequenceKey;
3940 sequenceKey.keyCode = 1;
3941 sequenceKey.keyAction = 2;
3942 sequenceKey.actionTime = 3;
3943 sequenceKey.delay = 4;
3944 handler.keys_.push_back(sequenceKey);
3945 bool ret = handler.AddSequenceKey(keyEvent);
3946 ASSERT_TRUE(ret);
3947 inputEvent->actionTime_ = 1100000;
3948 ret = handler.AddSequenceKey(keyEvent);
3949 ASSERT_FALSE(ret);
3950 inputEvent->actionTime_ = 100000;
3951 ret = handler.AddSequenceKey(keyEvent);
3952 ASSERT_FALSE(ret);
3953 }
3954
3955 /**
3956 * @tc.name: KeyCommandHandlerTest_HandleKnuckleGestureTouchUp_004
3957 * @tc.desc: Test knuckle gesture touch up event straight line
3958 * @tc.type: FUNC
3959 * @tc.require:
3960 */
3961 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureTouchUp_004, TestSize.Level1)
3962 {
3963 CALL_TEST_DEBUG;
3964 KeyCommandHandler handler;
3965 std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
3966 ASSERT_NE(touchEvent, nullptr);
3967 GESTURESENSE_WRAPPER->touchUp_ = [](const std::vector<float> &, const std::vector<int64_t> &, bool, bool)
__anon5dbb74de0302(const std::vector<float> &, const std::vector<int64_t> &, bool, bool) 3968 -> int32_t {
3969 return 0;
3970 };
3971 ASSERT_NE(GESTURESENSE_WRAPPER->touchUp_, nullptr);
3972 handler.gesturePoints_.assign(LINE_COORDINATES.begin(), LINE_COORDINATES.end());
3973 handler.gestureTimeStamps_.assign(LINE_TIMESTAMPS.begin(), LINE_TIMESTAMPS.end());
3974 handler.isGesturing_ = true;
3975 handler.isLetterGesturing_ = true;
3976 ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchUp(touchEvent));
3977 handler.gesturePoints_.assign(CIRCLE_COORDINATES.begin(), CIRCLE_COORDINATES.end());
3978 handler.gestureTimeStamps_.assign(CIRCLE_TIMESTAMPS.begin(), CIRCLE_TIMESTAMPS.end());
3979 handler.isGesturing_ = true;
3980 handler.isLetterGesturing_ = true;
3981 ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchUp(touchEvent));
3982 handler.gesturePoints_.assign(CURVE_COORDINATES.begin(), CURVE_COORDINATES.end());
3983 handler.gestureTimeStamps_.assign(CURVE_TIMESTAMPS.begin(), CURVE_TIMESTAMPS.end());
3984 handler.isGesturing_ = true;
3985 handler.isLetterGesturing_ = true;
3986 ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchUp(touchEvent));
3987 }
3988
3989 /**
3990 * @tc.name: KeyCommandHandlerTest_HandleShortKeys_004
3991 * @tc.desc: Test the funcation HandleShortKeys
3992 * @tc.type: FUNC
3993 * @tc.require:
3994 */
3995 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleShortKeys_004, TestSize.Level1)
3996 {
3997 KeyCommandHandler handler;
3998 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
3999 ASSERT_NE(keyEvent, nullptr);
4000 ShortcutKey key;
4001 key.preKeys = {1, 2, 3};
4002 key.businessId = "business1";
4003 key.statusConfig = "config1";
4004 key.statusConfigValue = true;
4005 key.finalKey = 4;
4006 key.keyDownDuration = 5;
4007 key.triggerType = KeyEvent::KEY_ACTION_DOWN;
4008 key.timerId = 6;
4009 handler.lastMatchedKey_.finalKey = 1;
4010 handler.lastMatchedKey_.triggerType = 2;
4011 keyEvent->SetKeyCode(1);
4012 keyEvent->SetKeyAction(2);
4013 bool result = handler.IsKeyMatch(handler.lastMatchedKey_, keyEvent);
4014 ASSERT_FALSE(result);
4015 handler.shortcutKeys_.insert(std::make_pair("key1", key));
4016 bool ret = handler.HandleShortKeys(keyEvent);
4017 ASSERT_FALSE(ret);
4018 }
4019
4020 /**
4021 * @tc.name: KeyCommandHandlerTest_HandleShortKeys_005
4022 * @tc.desc: Test the funcation HandleShortKeys
4023 * @tc.type: FUNC
4024 * @tc.require:
4025 */
4026 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleShortKeys_005, TestSize.Level1)
4027 {
4028 KeyCommandHandler handler;
4029 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
4030 ASSERT_NE(keyEvent, nullptr);
4031 ShortcutKey key;
4032 key.preKeys = {1, 2, 3};
4033 key.businessId = "business1";
4034 key.statusConfig = "config1";
4035 key.statusConfigValue = true;
4036 key.finalKey = 4;
4037 key.keyDownDuration = 5;
4038 key.triggerType = KeyEvent::KEY_ACTION_DOWN;
4039 key.timerId = 6;
4040 handler.currentLaunchAbilityKey_.finalKey = 1;
4041 handler.currentLaunchAbilityKey_.triggerType = 2;
4042 keyEvent->SetKeyCode(1);
4043 keyEvent->SetKeyAction(2);
4044 bool result = handler.IsKeyMatch(handler.currentLaunchAbilityKey_, keyEvent);
4045 ASSERT_FALSE(result);
4046 handler.shortcutKeys_.insert(std::make_pair("key1", key));
4047 handler.currentLaunchAbilityKey_.timerId = 0;
4048 bool ret = handler.HandleShortKeys(keyEvent);
4049 ASSERT_FALSE(ret);
4050 handler.currentLaunchAbilityKey_.timerId = -1;
4051 ret = handler.HandleShortKeys(keyEvent);
4052 ASSERT_FALSE(ret);
4053 handler.currentLaunchAbilityKey_.timerId = 0;
4054 handler.currentLaunchAbilityKey_.finalKey = 1;
4055 handler.currentLaunchAbilityKey_.triggerType = 2;
4056 keyEvent->SetKeyCode(3);
4057 keyEvent->SetKeyAction(4);
4058 ret = handler.HandleShortKeys(keyEvent);
4059 ASSERT_FALSE(ret);
4060 handler.currentLaunchAbilityKey_.timerId = -1;
4061 handler.currentLaunchAbilityKey_.finalKey = 1;
4062 handler.currentLaunchAbilityKey_.triggerType = 2;
4063 keyEvent->SetKeyCode(3);
4064 keyEvent->SetKeyAction(4);
4065 ret = handler.HandleShortKeys(keyEvent);
4066 ASSERT_FALSE(ret);
4067 }
4068
4069 /**
4070 * @tc.name: KeyCommandHandlerTest_HandleMatchedSequence_002
4071 * @tc.desc: Test the funcation HandleMatchedSequence
4072 * @tc.type: FUNC
4073 * @tc.require:
4074 */
4075 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleMatchedSequence_002, TestSize.Level1)
4076 {
4077 CALL_TEST_DEBUG;
4078 KeyCommandHandler handler;
4079 Sequence sequence;
4080 bool isLaunchAbility = true;
4081 DISPLAY_MONITOR->isScreenLocked_ = false;
4082 sequence.ability.bundleName = ".screenshot";
4083 DISPLAY_MONITOR->screenStatus_ = "usual.event.SCREEN_OFF";
4084 bool ret = handler.HandleMatchedSequence(sequence, isLaunchAbility);
4085 ASSERT_TRUE(ret);
4086 DISPLAY_MONITOR->screenStatus_ = "usual.event.SCREEN_OFF";
4087 sequence.ability.bundleName = "abc";
4088 DisplayEventMonitor displayEventMonitor;
4089 displayEventMonitor.screenStatus_ = "usual.event.SCREEN_OFF";
4090 ret = handler.HandleMatchedSequence(sequence, isLaunchAbility);
4091 ASSERT_TRUE(ret);
4092 DISPLAY_MONITOR->screenStatus_ = "usual.event.SCREEN_LOCKED";
4093 DISPLAY_MONITOR->isScreenLocked_ = true;
4094 sequence.ability.bundleName = ".screenshot";
4095 ret = handler.HandleMatchedSequence(sequence, isLaunchAbility);
4096 ASSERT_TRUE(ret);
4097 DISPLAY_MONITOR->isScreenLocked_ = false;
4098 ret = handler.HandleMatchedSequence(sequence, isLaunchAbility);
4099 ASSERT_TRUE(ret);
4100 DISPLAY_MONITOR->isScreenLocked_ = true;
4101 sequence.ability.bundleName = "abc";
4102 ret = handler.HandleMatchedSequence(sequence, isLaunchAbility);
4103 ASSERT_TRUE(ret);
4104 DISPLAY_MONITOR->isScreenLocked_ = false;
4105 sequence.ability.bundleName = "abc";
4106 ret = handler.HandleMatchedSequence(sequence, isLaunchAbility);
4107 ASSERT_TRUE(ret);
4108 }
4109
4110 /**
4111 * @tc.name: KeyCommandHandlerTest_HandlePointerVisibleKeys_001
4112 * @tc.desc: Test HandlePointerVisibleKeys
4113 * @tc.type: FUNC
4114 * @tc.require:
4115 */
4116 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandlePointerVisibleKeys_001, TestSize.Level1)
4117 {
4118 CALL_TEST_DEBUG;
4119 KeyCommandHandler handler;
4120 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
4121 ASSERT_NE(keyEvent, nullptr);
4122 keyEvent->keyCode_ = KeyEvent::KEYCODE_F9;
4123 handler.lastKeyEventCode_ = KeyEvent::KEYCODE_CTRL_LEFT;
4124 ASSERT_NO_FATAL_FAILURE(handler.HandlePointerVisibleKeys(keyEvent));
4125 keyEvent->keyCode_ = KeyEvent::KEYCODE_F1;
4126 handler.lastKeyEventCode_ = KeyEvent::KEYCODE_CTRL_LEFT;
4127 ASSERT_NO_FATAL_FAILURE(handler.HandlePointerVisibleKeys(keyEvent));
4128 keyEvent->keyCode_ = KeyEvent::KEYCODE_F9;
4129 handler.lastKeyEventCode_ = KeyEvent::KEYCODE_CAPS_LOCK;
4130 ASSERT_NO_FATAL_FAILURE(handler.HandlePointerVisibleKeys(keyEvent));
4131 keyEvent->keyCode_ = KeyEvent::KEYCODE_F1;
4132 handler.lastKeyEventCode_ = KeyEvent::KEYCODE_CAPS_LOCK;
4133 ASSERT_NO_FATAL_FAILURE(handler.HandlePointerVisibleKeys(keyEvent));
4134 }
4135
4136 /**
4137 * @tc.name: KeyCommandHandlerTest_ConvertVPToPX_002
4138 * @tc.desc: Test the funcation ConvertVPToPX
4139 * @tc.type: FUNC
4140 * @tc.require:
4141 */
4142 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_ConvertVPToPX_002, TestSize.Level1)
4143 {
4144 CALL_TEST_DEBUG;
4145 KeyCommandHandler handler;
4146 int32_t vp = -5;
4147 int32_t ret = handler.ConvertVPToPX(vp);
4148 ASSERT_EQ(ret, 0);
4149 vp = 5;
4150 InputWindowsManager inputWindowsManager;
4151 DisplayInfo displayInfo;
4152 displayInfo.id = 1;
4153 displayInfo.x = 2;
4154 displayInfo.y = 3;
4155 displayInfo.width = 4;
4156 displayInfo.height = 5;
4157 displayInfo.dpi = -1;
4158 inputWindowsManager.displayGroupInfo_.displaysInfo.push_back(displayInfo);
4159 ret = handler.ConvertVPToPX(vp);
4160 ASSERT_EQ(ret, 0);
4161 }
4162
4163 /**
4164 * @tc.name: KeyCommandHandlerTest_ConvertVPToPX_003
4165 * @tc.desc: Test the funcation ConvertVPToPX
4166 * @tc.type: FUNC
4167 * @tc.require:
4168 */
4169 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_ConvertVPToPX_003, TestSize.Level1)
4170 {
4171 CALL_TEST_DEBUG;
4172 KeyCommandHandler handler;
4173 int32_t vp = 5;
4174 InputWindowsManager inputWindowsManager;
4175 DisplayInfo displayInfo;
4176 displayInfo.id = 1;
4177 displayInfo.x = 2;
4178 displayInfo.y = 3;
4179 displayInfo.width = 4;
4180 displayInfo.height = 5;
4181 displayInfo.dpi = 160;
4182 inputWindowsManager.displayGroupInfo_.displaysInfo.push_back(displayInfo);
4183 int32_t ret = handler.ConvertVPToPX(vp);
4184 ASSERT_EQ(ret, 0);
4185 }
4186
4187 /**
4188 * @tc.name: KeyCommandHandlerTest_CheckTwoFingerGestureAction_003
4189 * @tc.desc: Test the funcation CheckTwoFingerGestureAction
4190 * @tc.type: FUNC
4191 * @tc.require:
4192 */
4193 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckTwoFingerGestureAction_003, TestSize.Level1)
4194 {
4195 CALL_TEST_DEBUG;
4196 KeyCommandHandler handler;
4197 handler.twoFingerGesture_.active = true;
4198 handler.twoFingerGesture_.touches[0].id = 1;
4199 handler.twoFingerGesture_.touches[0].x = -100;
4200 handler.twoFingerGesture_.touches[0].y = -200;
4201 handler.twoFingerGesture_.touches[0].downTime = 100000;
4202 handler.twoFingerGesture_.touches[1].id = 2;
4203 handler.twoFingerGesture_.touches[1].x = -300;
4204 handler.twoFingerGesture_.touches[1].y = -400;
4205 handler.twoFingerGesture_.touches[1].downTime = 50000;
4206 InputWindowsManager inputWindowsManager;
4207 DisplayInfo displayInfo;
4208 displayInfo.id = 1;
4209 displayInfo.x = 2;
4210 displayInfo.y = 3;
4211 displayInfo.width = 4;
4212 displayInfo.height = 5;
4213 displayInfo.dpi = -1;
4214 inputWindowsManager.displayGroupInfo_.displaysInfo.push_back(displayInfo);
4215 bool ret = handler.CheckTwoFingerGestureAction();
4216 EXPECT_FALSE(ret);
4217 }
4218
4219 /**
4220 * @tc.name: KeyCommandHandlerTest_CheckTwoFingerGestureAction_004
4221 * @tc.desc: Test the funcation CheckTwoFingerGestureAction
4222 * @tc.type: FUNC
4223 * @tc.require:
4224 */
4225 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckTwoFingerGestureAction_004, TestSize.Level1)
4226 {
4227 CALL_TEST_DEBUG;
4228 KeyCommandHandler handler;
4229 handler.twoFingerGesture_.active = true;
4230 handler.twoFingerGesture_.touches[0].id = 1;
4231 handler.twoFingerGesture_.touches[0].x = 100;
4232 handler.twoFingerGesture_.touches[0].y = 200;
4233 handler.twoFingerGesture_.touches[0].downTime = 100000;
4234 handler.twoFingerGesture_.touches[1].id = 2;
4235 handler.twoFingerGesture_.touches[1].x = 300;
4236 handler.twoFingerGesture_.touches[1].y = 400;
4237 handler.twoFingerGesture_.touches[1].downTime = 50000;
4238 InputWindowsManager inputWindowsManager;
4239 DisplayInfo displayInfo;
4240 displayInfo.id = 1;
4241 displayInfo.x = 2;
4242 displayInfo.y = 3;
4243 displayInfo.width = 40;
4244 displayInfo.height = 50;
4245 displayInfo.dpi = -1;
4246 inputWindowsManager.displayGroupInfo_.displaysInfo.push_back(displayInfo);
4247 bool ret = handler.CheckTwoFingerGestureAction();
4248 EXPECT_FALSE(ret);
4249 }
4250
4251 /**
4252 * @tc.name: KeyCommandHandlerTest_CheckTwoFingerGestureAction_005
4253 * @tc.desc: Test the funcation CheckTwoFingerGestureAction
4254 * @tc.type: FUNC
4255 * @tc.require:
4256 */
4257 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckTwoFingerGestureAction_005, TestSize.Level1)
4258 {
4259 CALL_TEST_DEBUG;
4260 KeyCommandHandler handler;
4261 handler.twoFingerGesture_.active = true;
4262 handler.twoFingerGesture_.touches[0].id = 1;
4263 handler.twoFingerGesture_.touches[0].x = 10;
4264 handler.twoFingerGesture_.touches[0].y = 20;
4265 handler.twoFingerGesture_.touches[0].downTime = 100000;
4266 handler.twoFingerGesture_.touches[1].id = 2;
4267 handler.twoFingerGesture_.touches[1].x = 30;
4268 handler.twoFingerGesture_.touches[1].y = 20;
4269 handler.twoFingerGesture_.touches[1].downTime = 50000;
4270 InputWindowsManager inputWindowsManager;
4271 DisplayInfo displayInfo;
4272 displayInfo.id = 1;
4273 displayInfo.x = 2;
4274 displayInfo.y = 3;
4275 displayInfo.width = 40;
4276 displayInfo.height = 50;
4277 displayInfo.dpi = -1;
4278 inputWindowsManager.displayGroupInfo_.displaysInfo.push_back(displayInfo);
4279 bool ret = handler.CheckTwoFingerGestureAction();
4280 EXPECT_FALSE(ret);
4281 }
4282
4283 /**
4284 * @tc.name: KeyCommandHandlerTest_StartTwoFingerGesture_002
4285 * @tc.desc: Test the funcation StartTwoFingerGesture
4286 * @tc.type: FUNC
4287 * @tc.require:
4288 */
4289 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_StartTwoFingerGesture_002, TestSize.Level1)
4290 {
4291 KeyCommandHandler handler;
4292 handler.twoFingerGesture_.active = false;
4293 ASSERT_NO_FATAL_FAILURE(handler.StartTwoFingerGesture());
4294 handler.twoFingerGesture_.active = true;
4295 handler.twoFingerGesture_.touches[0].id = 5;
4296 handler.twoFingerGesture_.touches[0].x = 50;
4297 handler.twoFingerGesture_.touches[0].y = 60;
4298 handler.twoFingerGesture_.touches[0].downTime = 13000;
4299 handler.twoFingerGesture_.touches[1].id = 9;
4300 handler.twoFingerGesture_.touches[1].x = 100;
4301 handler.twoFingerGesture_.touches[1].y = 400;
4302 handler.twoFingerGesture_.touches[1].downTime = 96000;
4303 ASSERT_NO_FATAL_FAILURE(handler.StartTwoFingerGesture());
4304 }
4305
4306 /**
4307 * @tc.name: KeyCommandHandlerTest_HandleKnuckleGestureTouchUp_005
4308 * @tc.desc: Test the funcation HandleKnuckleGestureTouchUp
4309 * @tc.type: FUNC
4310 * @tc.require:
4311 */
4312 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureTouchUp_005, TestSize.Level1)
4313 {
4314 CALL_TEST_DEBUG;
4315 KeyCommandHandler handler;
4316 std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
4317 ASSERT_NE(touchEvent, nullptr);
4318 GESTURESENSE_WRAPPER->touchUp_ = [](const std::vector<float> &, const std::vector<int64_t> &, bool, bool)
__anon5dbb74de0402(const std::vector<float> &, const std::vector<int64_t> &, bool, bool) 4319 -> int32_t {
4320 return 0;
4321 };
4322 ASSERT_NE(GESTURESENSE_WRAPPER->touchUp_, nullptr);
4323 handler.isGesturing_ = false;
4324 handler.isLetterGesturing_ = false;
4325 handler.gesturePoints_.assign(LINE_TIMESTAMPS.begin(), LINE_TIMESTAMPS.end());
4326 handler.gestureTimeStamps_.assign(LINE_COORDINATES.begin(), LINE_COORDINATES.end());
4327 ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchUp(touchEvent));
4328 handler.gesturePoints_.assign(CURVE_COORDINATES.begin(), CURVE_COORDINATES.end());
4329 handler.gestureTimeStamps_.assign(CURVE_TIMESTAMPS.begin(), CURVE_TIMESTAMPS.end());
4330 ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchUp(touchEvent));
4331 handler.isGesturing_ = true;
4332 ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchUp(touchEvent));
4333 handler.isLetterGesturing_ = true;
4334 ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchUp(touchEvent));
4335 }
4336
4337 /**
4338 * @tc.name: KeyCommandHandlerTest_HandleKnuckleGestureTouchUp_01
4339 * @tc.desc: Test HandleKnuckleGestureTouchUp
4340 * @tc.type: FUNC
4341 * @tc.require:
4342 */
4343 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureTouchUp_01, TestSize.Level1)
4344 {
4345 CALL_TEST_DEBUG;
4346 KeyCommandHandler handler;
4347 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
4348 ASSERT_NE(pointerEvent, nullptr);
4349
4350 NotifyType notifyType;
4351 notifyType = NotifyType::REGIONGESTURE;
4352 ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchUp(pointerEvent));
4353 }
4354
4355 /**
4356 * @tc.name: KeyCommandHandlerTest_HandleKnuckleGestureTouchUp_02
4357 * @tc.desc: Test HandleKnuckleGestureTouchUp
4358 * @tc.type: FUNC
4359 * @tc.require:
4360 */
4361 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureTouchUp_02, TestSize.Level1)
4362 {
4363 CALL_TEST_DEBUG;
4364 KeyCommandHandler handler;
4365 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
4366 ASSERT_NE(pointerEvent, nullptr);
4367
4368 NotifyType notifyType;
4369 notifyType = NotifyType::LETTERGESTURE;
4370 ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchUp(pointerEvent));
4371 }
4372
4373 /**
4374 * @tc.name: KeyCommandHandlerTest_HandleKnuckleGestureTouchUp_03
4375 * @tc.desc: Test HandleKnuckleGestureTouchUp
4376 * @tc.type: FUNC
4377 * @tc.require:
4378 */
4379 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureTouchUp_03, TestSize.Level1)
4380 {
4381 CALL_TEST_DEBUG;
4382 KeyCommandHandler handler;
4383 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
4384 ASSERT_NE(pointerEvent, nullptr);
4385
4386 NotifyType notifyType;
4387 notifyType = NotifyType::OTHER;
4388 ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchUp(pointerEvent));
4389 }
4390
4391 /**
4392 * @tc.name: KeyCommandHandlerTest_ParseJson_001
4393 * @tc.desc: Test the funcation ParseJson
4394 * @tc.type: FUNC
4395 * @tc.require:
4396 */
4397 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_ParseJson_001, TestSize.Level1)
4398 {
4399 CALL_TEST_DEBUG;
4400 KeyCommandHandler handler;
4401 std::string configFile;
4402 bool ret = handler.ParseJson(configFile);
4403 EXPECT_FALSE(ret);
4404 configFile = "config";
4405 std::string copyShortcutKey = "copyShortcutKey";
4406 ShortcutKey shortcutKey;
4407 Ability ability_temp;
4408 shortcutKey.preKeys.insert(2072);
4409 shortcutKey.finalKey = 2019;
4410 shortcutKey.keyDownDuration = 100;
4411 ability_temp.bundleName = "bundleName";
4412 ability_temp.abilityName = "abilityName";
4413 shortcutKey.ability = ability_temp;
4414 handler.shortcutKeys_.insert(std::make_pair(copyShortcutKey, shortcutKey));
4415 handler.businessIds_ = {"businessId"};
4416 handler.twoFingerGesture_.active = true;
4417 handler.twoFingerGesture_.timerId = 1;
4418 ret = handler.ParseJson(configFile);
4419 EXPECT_FALSE(ret);
4420 }
4421
4422 /**
4423 * @tc.name: KeyCommandHandlerTest_IsEnableCombineKey_003
4424 * @tc.desc: Test the funcation IsEnableCombineKey
4425 * @tc.type: FUNC
4426 * @tc.require:
4427 */
4428 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_IsEnableCombineKey_003, TestSize.Level1)
4429 {
4430 CALL_TEST_DEBUG;
4431 KeyCommandHandler handler;
4432 std::shared_ptr<KeyEvent> key = KeyEvent::Create();
4433 ASSERT_NE(key, nullptr);
4434 handler.enableCombineKey_ = false;
4435 handler.isParseExcludeConfig_ = false;
4436 ASSERT_FALSE(handler.IsEnableCombineKey(key));
4437 handler.isParseExcludeConfig_ = true;
4438 ExcludeKey excludeKey;
4439 excludeKey.keyCode = 1;
4440 excludeKey.keyAction = 2;
4441 excludeKey.delay = 3;
4442 handler.excludeKeys_.push_back(excludeKey);
4443 key->keyCode_ = 1;
4444 key->keyAction_ = 2;
4445 SequenceKey sequenceKey;
4446 sequenceKey.keyCode = 2017;
4447 sequenceKey.keyAction = KeyEvent::KEY_ACTION_DOWN;
4448 handler.keys_.push_back(sequenceKey);
4449 ASSERT_FALSE(handler.IsEnableCombineKey(key));
4450 sequenceKey.keyCode = 2018;
4451 sequenceKey.keyAction = KeyEvent::KEY_ACTION_DOWN;
4452 handler.keys_.push_back(sequenceKey);
4453 ASSERT_FALSE(handler.IsEnableCombineKey(key));
4454 }
4455
4456 /**
4457 * @tc.name: KeyCommandHandlerTest_IsEnableCombineKey_004
4458 * @tc.desc: Test the funcation IsEnableCombineKey
4459 * @tc.type: FUNC
4460 * @tc.require:
4461 */
4462 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_IsEnableCombineKey_004, TestSize.Level1)
4463 {
4464 CALL_TEST_DEBUG;
4465 KeyCommandHandler handler;
4466 std::shared_ptr<KeyEvent> key = KeyEvent::Create();
4467 ASSERT_NE(key, nullptr);
4468 handler.enableCombineKey_ = false;
4469 handler.isParseExcludeConfig_ = true;
4470 ExcludeKey excludeKey;
4471 excludeKey.keyCode = 1;
4472 excludeKey.keyAction = 2;
4473 excludeKey.delay = 3;
4474 handler.excludeKeys_.push_back(excludeKey);
4475 key->keyCode_ = KeyEvent::KEYCODE_L;
4476 key->keyAction_ = 200;
4477 SequenceKey sequenceKey;
4478 sequenceKey.keyCode = KeyEvent::KEYCODE_SPACE;
4479 sequenceKey.keyAction = KeyEvent::KEY_ACTION_DOWN;
4480 handler.keys_.push_back(sequenceKey);
4481 ASSERT_TRUE(handler.IsEnableCombineKey(key));
4482 sequenceKey.keyCode = KeyEvent::KEYCODE_L;
4483 handler.keys_.push_back(sequenceKey);
4484 ASSERT_TRUE(handler.IsEnableCombineKey(key));
4485 sequenceKey.keyCode = KeyEvent::KEYCODE_META_LEFT;
4486 handler.keys_.push_back(sequenceKey);
4487 ASSERT_TRUE(handler.IsEnableCombineKey(key));
4488 sequenceKey.keyCode = KeyEvent::KEYCODE_META_RIGHT;
4489 handler.keys_.push_back(sequenceKey);
4490 ASSERT_TRUE(handler.IsEnableCombineKey(key));
4491 }
4492
4493 /**
4494 * @tc.name: KeyCommandHandlerTest_HandleEvent_001
4495 * @tc.desc: Test the funcation HandleEvent
4496 * @tc.type: FUNC
4497 * @tc.require:
4498 */
4499 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleEvent_001, TestSize.Level1)
4500 {
4501 CALL_TEST_DEBUG;
4502 KeyCommandHandler handler;
4503 std::shared_ptr<KeyEvent> key = KeyEvent::Create();
4504 ASSERT_NE(key, nullptr);
4505 handler.enableCombineKey_ = false;
4506 handler.isParseExcludeConfig_ = true;
4507 ExcludeKey excludeKey;
4508 excludeKey.keyCode = 3;
4509 excludeKey.keyAction = 5;
4510 excludeKey.delay = 8;
4511 handler.excludeKeys_.push_back(excludeKey);
4512 key->keyCode_ = KeyEvent::KEYCODE_L;
4513 key->keyAction_ = 200;
4514 SequenceKey sequenceKey;
4515 sequenceKey.keyCode = KeyEvent::KEYCODE_SPACE;
4516 sequenceKey.keyAction = KeyEvent::KEY_ACTION_DOWN;
4517 handler.keys_.push_back(sequenceKey);
4518 ShortcutKey shortcutKey;
4519 shortcutKey.preKeys = {1, 2, 3};
4520 shortcutKey.businessId = "business1";
4521 shortcutKey.statusConfig = "config1";
4522 shortcutKey.statusConfigValue = true;
4523 shortcutKey.finalKey = 4;
4524 shortcutKey.keyDownDuration = 5;
4525 shortcutKey.triggerType = KeyEvent::KEY_ACTION_DOWN;
4526 shortcutKey.timerId = 6;
4527 handler.currentLaunchAbilityKey_.finalKey = 1;
4528 handler.currentLaunchAbilityKey_.triggerType = 2;
4529 key->SetKeyCode(1);
4530 key->SetKeyAction(2);
4531 handler.IsKeyMatch(handler.currentLaunchAbilityKey_, key);
4532 handler.shortcutKeys_.insert(std::make_pair("key1", shortcutKey));
4533 handler.currentLaunchAbilityKey_.timerId = 0;
4534 handler.HandleShortKeys(key);
4535 handler.isKeyCancel_ = true;
4536 bool ret = handler.HandleEvent(key);
4537 EXPECT_FALSE(ret);
4538 handler.isKeyCancel_ = false;
4539 ret = handler.HandleEvent(key);
4540 EXPECT_FALSE(ret);
4541 }
4542
4543 /**
4544 * @tc.name: KeyCommandHandlerTest_HandleEvent_002
4545 * @tc.desc: Test the funcation HandleEvent
4546 * @tc.type: FUNC
4547 * @tc.require:
4548 */
4549 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleEvent_002, TestSize.Level1)
4550 {
4551 CALL_TEST_DEBUG;
4552 KeyCommandHandler handler;
4553 std::shared_ptr<KeyEvent> key = KeyEvent::Create();
4554 ASSERT_NE(key, nullptr);
4555 handler.enableCombineKey_ = false;
4556 handler.isParseExcludeConfig_ = true;
4557 ExcludeKey excludeKey;
4558 excludeKey.keyCode = 2;
4559 excludeKey.keyAction = 6;
4560 excludeKey.delay = 9;
4561 handler.excludeKeys_.push_back(excludeKey);
4562 key->keyCode_ = KeyEvent::KEYCODE_L;
4563 key->keyAction_ = 300;
4564 SequenceKey sequenceKey;
4565 sequenceKey.keyCode = KeyEvent::KEYCODE_SPACE;
4566 sequenceKey.keyAction = KeyEvent::KEY_ACTION_DOWN;
4567 handler.keys_.push_back(sequenceKey);
4568 ShortcutKey shortcutKey;
4569 shortcutKey.preKeys = {1, 2, 3};
4570 shortcutKey.businessId = "business2";
4571 shortcutKey.statusConfig = "config2";
4572 shortcutKey.statusConfigValue = true;
4573 shortcutKey.finalKey = 5;
4574 shortcutKey.keyDownDuration = 6;
4575 shortcutKey.triggerType = KeyEvent::KEY_ACTION_UP;
4576 shortcutKey.timerId = 6;
4577 Ability ability_temp;
4578 ability_temp.bundleName = "bundleName2";
4579 ability_temp.abilityName = "abilityName2";
4580 shortcutKey.ability = ability_temp;
4581 handler.shortcutKeys_.insert(std::make_pair("key2", shortcutKey));
4582 handler.HandleShortKeys(key);
4583 handler.isDownStart_ = false;
4584 bool ret = handler.HandleEvent(key);
4585 EXPECT_FALSE(ret);
4586 handler.isDownStart_ = true;
4587 ret = handler.HandleEvent(key);
4588 EXPECT_FALSE(ret);
4589 }
4590
4591 /**
4592 * @tc.name: KeyCommandHandlerTest_OnHandleEvent_001
4593 * @tc.desc: Test the funcation OnHandleEvent
4594 * @tc.type: FUNC
4595 * @tc.require:
4596 */
4597 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_OnHandleEvent_001, TestSize.Level1)
4598 {
4599 CALL_TEST_DEBUG;
4600 KeyCommandHandler handler;
4601 std::shared_ptr<KeyEvent> key = KeyEvent::Create();
4602 ASSERT_NE(key, nullptr);
4603 key->SetKeyCode(KeyEvent::KEYCODE_POWER);
4604 int32_t keyAction = KeyEvent::KEYCODE_VOLUME_UP;
4605 handler.specialKeys_.insert(std::make_pair(10, keyAction));
4606 bool ret = handler.OnHandleEvent(key);
4607 EXPECT_FALSE(ret);
4608 key->SetKeyCode(KeyEvent::KEYCODE_VOLUME_UP);
4609 int32_t keyCode = 99;
4610 std::list<int32_t> timerIds;
4611 timerIds.push_back(100);
4612 handler.specialTimers_.insert(std::make_pair(keyCode, timerIds));
4613 ret = handler.OnHandleEvent(key);
4614 EXPECT_FALSE(ret);
4615 keyCode = KeyEvent::KEYCODE_VOLUME_UP;
4616 handler.specialTimers_.insert(std::make_pair(keyCode, timerIds));
4617 ret = handler.OnHandleEvent(key);
4618 EXPECT_FALSE(ret);
4619 }
4620
4621 /**
4622 * @tc.name: KeyCommandHandlerTest_HandleRepeatKey_001
4623 * @tc.desc: Test the funcation HandleRepeatKey
4624 * @tc.type: FUNC
4625 * @tc.require:
4626 */
4627 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleRepeatKey_001, TestSize.Level1)
4628 {
4629 CALL_TEST_DEBUG;
4630 KeyCommandHandler handler;
4631 RepeatKey item;
4632 bool isLaunched = true;
4633 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
4634 ASSERT_NE(keyEvent, nullptr);
4635 keyEvent->SetKeyCode(KeyEvent::KEYCODE_VOLUME_UP);
4636 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_UP);
4637 item.keyCode = KeyEvent::KEYCODE_VOLUME_DOWN;
4638 item.times = 5;
4639 handler.count_ = 5;
4640 ASSERT_FALSE(handler.HandleRepeatKey(item, isLaunched, keyEvent));
4641 handler.count_ = 10;
4642 ASSERT_FALSE(handler.HandleRepeatKey(item, isLaunched, keyEvent));
4643 }
4644
4645 /**
4646 * @tc.name: KeyCommandHandlerTest_HandleRepeatKey_002
4647 * @tc.desc: Test the funcation HandleRepeatKey
4648 * @tc.type: FUNC
4649 * @tc.require:
4650 */
4651 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleRepeatKey_002, TestSize.Level1)
4652 {
4653 CALL_TEST_DEBUG;
4654 KeyCommandHandler handler;
4655 RepeatKey item;
4656 bool isLaunched = false;
4657 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
4658 ASSERT_NE(keyEvent, nullptr);
4659 keyEvent->SetKeyCode(KeyEvent::KEYCODE_VOLUME_DOWN);
4660 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_UP);
4661 item.keyCode = KeyEvent::KEYCODE_VOLUME_DOWN;
4662 item.times = 6;
4663 handler.count_ = 5;
4664 ASSERT_FALSE(handler.HandleRepeatKey(item, isLaunched, keyEvent));
4665 }
4666
4667 /**
4668 * @tc.name: KeyCommandHandlerTest_HandleRepeatKey_003
4669 * @tc.desc: HandleRepeatKey_003
4670 * @tc.type: FUNC
4671 * @tc.require:
4672 */
4673 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleRepeatKey_003, TestSize.Level1)
4674 {
4675 CALL_TEST_DEBUG;
4676 KeyCommandHandler handler;
4677 RepeatKey repeatKey;
4678 bool isLaunched = false;
4679 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
4680 ASSERT_NE(keyEvent, nullptr);
4681 repeatKey.times = 2;
4682 repeatKey.keyCode = KeyEvent::KEYCODE_POWER;
4683 repeatKey.ability.bundleName = "bundleName";
4684 keyEvent->SetKeyCode(KeyEvent::KEYCODE_POWER);
4685 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
4686 handler.repeatKeyCountMap_.emplace(repeatKey.ability.bundleName, 2);
4687 handler.repeatKeyMaxTimes_.emplace(KeyEvent::KEYCODE_POWER, 2);
4688 ASSERT_FALSE(handler.HandleRepeatKey(repeatKey, isLaunched, keyEvent));
4689 }
4690
4691 /**
4692 * @tc.name: KeyCommandHandlerTest_HandleRepeatKey_004
4693 * @tc.desc: HandleRepeatKey_004
4694 * @tc.type: FUNC
4695 * @tc.require:
4696 */
4697 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleRepeatKey_004, TestSize.Level1)
4698 {
4699 CALL_TEST_DEBUG;
4700 KeyCommandHandler handler;
4701 RepeatKey repeatKey;
4702 bool isLaunched = false;
4703 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
4704 ASSERT_NE(keyEvent, nullptr);
4705 handler.count_ = 3;
4706 repeatKey.times = 2;
4707 repeatKey.statusConfig = "statusConfig";
4708 repeatKey.keyCode = KeyEvent::KEYCODE_POWER;
4709 repeatKey.ability.bundleName = "bundleName";
4710 keyEvent->SetKeyCode(KeyEvent::KEYCODE_POWER);
4711 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
4712 handler.repeatKeyCountMap_.emplace(repeatKey.ability.bundleName, 2);
4713 handler.repeatKeyMaxTimes_.emplace(KeyEvent::KEYCODE_POWER, 5);
4714 ASSERT_FALSE(handler.HandleRepeatKey(repeatKey, isLaunched, keyEvent));
4715 }
4716
4717 /**
4718 * @tc.name: KeyCommandHandlerTest_CheckInputMethodArea_001
4719 * @tc.desc: Test the funcation CheckInputMethodArea
4720 * @tc.type: FUNC
4721 * @tc.require:
4722 */
4723 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckInputMethodArea_001, TestSize.Level1)
4724 {
4725 CALL_TEST_DEBUG;
4726 KeyCommandHandler handler;
4727 std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
4728 ASSERT_NE(touchEvent, nullptr);
4729 WindowInfo windowInfo;
4730 windowInfo.windowType = 2000;
4731 bool ret = handler.CheckInputMethodArea(touchEvent);
4732 ASSERT_FALSE(ret);
4733 windowInfo.windowType = 2105;
4734 windowInfo.area.x = 10;
4735 windowInfo.area.width = INT32_MAX;
4736 windowInfo.area.y = 100;
4737 windowInfo.area.height = 200;
4738 std::vector<WindowInfo> windows;
4739 windows.push_back(windowInfo);
4740 ret = handler.CheckInputMethodArea(touchEvent);
4741 ASSERT_FALSE(ret);
4742 }
4743
4744 /**
4745 * @tc.name: KeyCommandHandlerTest_CheckInputMethodArea_002
4746 * @tc.desc: Test the funcation CheckInputMethodArea
4747 * @tc.type: FUNC
4748 * @tc.require:
4749 */
4750 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckInputMethodArea_002, TestSize.Level1)
4751 {
4752 CALL_TEST_DEBUG;
4753 KeyCommandHandler handler;
4754 std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
4755 ASSERT_NE(touchEvent, nullptr);
4756 WindowInfo windowInfo;
4757 windowInfo.windowType = 2105;
4758 windowInfo.area.x = 10;
4759 windowInfo.area.width = 100;
4760 windowInfo.area.y = 20;
4761 windowInfo.area.height = INT32_MAX;
4762 std::vector<WindowInfo> windows;
4763 windows.push_back(windowInfo);
4764 bool ret = handler.CheckInputMethodArea(touchEvent);
4765 ASSERT_FALSE(ret);
4766 }
4767
4768 /**
4769 * @tc.name: KeyCommandHandlerTest_CheckInputMethodArea_003
4770 * @tc.desc: Test the funcation CheckInputMethodArea
4771 * @tc.type: FUNC
4772 * @tc.require:
4773 */
4774 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckInputMethodArea_003, TestSize.Level1)
4775 {
4776 CALL_TEST_DEBUG;
4777 KeyCommandHandler handler;
4778 std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
4779 ASSERT_NE(touchEvent, nullptr);
4780 WindowInfo windowInfo;
4781 windowInfo.windowType = 2105;
4782 windowInfo.area.x = 30;
4783 windowInfo.area.width = 300;
4784 windowInfo.area.y = 90;
4785 windowInfo.area.height = 1000;
4786 std::vector<WindowInfo> windows;
4787 windows.push_back(windowInfo);
4788 bool ret = handler.CheckInputMethodArea(touchEvent);
4789 ASSERT_FALSE(ret);
4790 }
4791
4792 /**
4793 * @tc.name: KeyCommandHandlerTest_CheckInputMethodArea_004
4794 * @tc.desc: Test the funcation CheckInputMethodArea
4795 * @tc.type: FUNC
4796 * @tc.require:
4797 */
4798 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckInputMethodArea_004, TestSize.Level1)
4799 {
4800 CALL_TEST_DEBUG;
4801 KeyCommandHandler handler;
4802 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
4803 ASSERT_NE(pointerEvent, nullptr);
4804
4805 WindowInfo windowInfo;
4806 windowInfo.windowType = WINDOW_INPUT_METHOD_TYPE;
4807 bool ret = handler.CheckInputMethodArea(pointerEvent);
4808 EXPECT_FALSE(ret);
4809
4810 windowInfo.area.x = 10;
4811 windowInfo.area.width = INT32_MAX;
4812 windowInfo.area.y = 100;
4813 windowInfo.area.height = 200;
4814 ret = handler.CheckInputMethodArea(pointerEvent);
4815 EXPECT_FALSE(ret);
4816 }
4817
4818 /**
4819 * @tc.name: KeyCommandHandlerTest_SendKeyEvent_001
4820 * @tc.desc: Test the funcation SendKeyEvent
4821 * @tc.type: FUNC
4822 * @tc.require:
4823 */
4824 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_SendKeyEvent_001, TestSize.Level1)
4825 {
4826 CALL_TEST_DEBUG;
4827 KeyCommandHandler handler;
4828 handler.isHandleSequence_ = true;
4829 handler.launchAbilityCount_ = 1;
4830 handler.count_ = 5;
4831 ASSERT_NO_FATAL_FAILURE(handler.SendKeyEvent());
4832 }
4833
4834 /**
4835 * @tc.name: KeyCommandHandlerTest_SendKeyEvent_002
4836 * @tc.desc: Test the funcation SendKeyEvent
4837 * @tc.type: FUNC
4838 * @tc.require:
4839 */
4840 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_SendKeyEvent_002, TestSize.Level1)
4841 {
4842 CALL_TEST_DEBUG;
4843 KeyCommandHandler handler;
4844 handler.isHandleSequence_ = false;
4845 handler.launchAbilityCount_ = 1;
4846 handler.repeatKey_.keyCode = 3;
4847 ASSERT_NO_FATAL_FAILURE(handler.SendKeyEvent());
4848 }
4849
4850 /**
4851 * @tc.name: KeyCommandHandlerTest_SendKeyEvent_003
4852 * @tc.desc: Test the funcation SendKeyEvent
4853 * @tc.type: FUNC
4854 * @tc.require:
4855 */
4856 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_SendKeyEvent_003, TestSize.Level1)
4857 {
4858 CALL_TEST_DEBUG;
4859 KeyCommandHandler handler;
4860 handler.isHandleSequence_ = false;
4861 handler.launchAbilityCount_ = 0;
4862 handler.repeatKey_.keyCode = 2;
4863 ASSERT_NO_FATAL_FAILURE(handler.SendKeyEvent());
4864 }
4865
4866 /**
4867 * @tc.name: KeyCommandHandlerTest_CheckAndUpdateTappingCountAtDown_001
4868 * @tc.desc: Test the funcation CheckAndUpdateTappingCountAtDown
4869 * @tc.type: FUNC
4870 * @tc.require:
4871 */
4872 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckAndUpdateTappingCountAtDown_001, TestSize.Level1)
4873 {
4874 CALL_TEST_DEBUG;
4875 KeyCommandHandler handler;
4876 std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
4877 ASSERT_NE(touchEvent, nullptr);
4878 touchEvent->SetActionTime(0);
4879 handler.lastDownTime_ = 0;
4880 ASSERT_NO_FATAL_FAILURE(handler.CheckAndUpdateTappingCountAtDown(touchEvent));
4881 ASSERT_EQ(handler.tappingCount_, 1);
4882
4883 touchEvent->SetActionTime(600000);
4884 ASSERT_NO_FATAL_FAILURE(handler.CheckAndUpdateTappingCountAtDown(touchEvent));
4885 ASSERT_EQ(handler.tappingCount_, 1);
4886 }
4887
4888 /**
4889 * @tc.name: KeyCommandHandlerTest_CheckAndUpdateTappingCountAtDown_002
4890 * @tc.desc: Test the funcation CheckAndUpdateTappingCountAtDown
4891 * @tc.type: FUNC
4892 * @tc.require:
4893 */
4894 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckAndUpdateTappingCountAtDown_002, TestSize.Level1)
4895 {
4896 CALL_TEST_DEBUG;
4897 KeyCommandHandler handler;
4898 std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
4899 ASSERT_NE(touchEvent, nullptr);
4900 touchEvent->SetActionTime(10);
4901 handler.lastDownTime_ = 0;
4902 handler.previousUpTime_ = 0;
4903 handler.downToPrevUpTimeConfig_ = 20;
4904 handler.tappingCount_ = 1;
4905 ASSERT_NO_FATAL_FAILURE(handler.CheckAndUpdateTappingCountAtDown(touchEvent));
4906 ASSERT_EQ(handler.tappingCount_, 2);
4907
4908 touchEvent->SetActionTime(20);
4909 ASSERT_NO_FATAL_FAILURE(handler.CheckAndUpdateTappingCountAtDown(touchEvent));
4910 ASSERT_EQ(handler.tappingCount_, 3);
4911 }
4912
4913 /**
4914 * @tc.name: KeyCommandHandlerTest_CheckInputMethodArea_005
4915 * @tc.desc: Test the funcation CheckInputMethodArea
4916 * @tc.type: FUNC
4917 * @tc.require:
4918 */
4919 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckInputMethodArea_005, TestSize.Level1)
4920 {
4921 CALL_TEST_DEBUG;
4922 KeyCommandHandler handler;
4923 InputWindowsManager inputWindowsManager;
4924 std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
4925 ASSERT_NE(touchEvent, nullptr);
4926 std::shared_ptr<InputEvent> inputEvent = InputEvent::Create();
4927 EXPECT_NE(inputEvent, nullptr);
4928 inputEvent->targetDisplayId_ = 1;
4929 WindowGroupInfo windowGroupInfo;
4930 inputWindowsManager.windowsPerDisplay_.insert(std::make_pair(1, windowGroupInfo));
4931 bool ret = handler.CheckInputMethodArea(touchEvent);
4932 ASSERT_FALSE(ret);
4933 }
4934
4935 /**
4936 * @tc.name: KeyCommandHandlerTest_HandleSequences_001
4937 * @tc.desc: HandleSequences
4938 * @tc.type: FUNC
4939 * @tc.require:
4940 */
4941 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleSequences_001, TestSize.Level1)
4942 {
4943 CALL_TEST_DEBUG;
4944 KeyCommandHandler handler;
4945 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
4946 ASSERT_NE(keyEvent, nullptr);
4947 handler.matchedSequence_.timerId = 10;
4948 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_UP);
4949 ASSERT_FALSE(handler.HandleSequences(keyEvent));
4950 handler.matchedSequence_.timerId = -1;
4951 ASSERT_FALSE(handler.HandleSequences(keyEvent));
4952 keyEvent->SetKeyCode(2017);
4953 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
4954 keyEvent->SetActionTime(10000);
4955 SequenceKey sequenceKey;
4956 Sequence sequence;
4957 sequence.statusConfigValue = false;
4958 sequence.timerId = 1;
4959 handler.filterSequences_.push_back(sequence);
4960 sequenceKey.actionTime = 15000;
4961 handler.keys_.push_back(sequenceKey);
4962 ASSERT_FALSE(handler.HandleSequences(keyEvent));
4963 handler.keys_.clear();
4964 keyEvent->SetActionTime(1500000);
4965 sequenceKey.actionTime = 200000;
4966 sequence.statusConfigValue = false;
4967 sequence.timerId = 1;
4968 handler.filterSequences_.push_back(sequence);
4969 ASSERT_FALSE(handler.HandleSequences(keyEvent));
4970 }
4971
4972 /**
4973 * @tc.name: KeyCommandHandlerTest_HandleConsumedKeyEvent_001
4974 * @tc.desc: Test the funcation HandleConsumedKeyEvent
4975 * @tc.type: FUNC
4976 * @tc.require:
4977 */
4978 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleConsumedKeyEvent_001, TestSize.Level1)
4979 {
4980 CALL_TEST_DEBUG;
4981 KeyCommandHandler handler;
4982 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
4983 ASSERT_NE(keyEvent, nullptr);
4984 ShortcutKey testKey;
4985 testKey.finalKey = -1;
4986 handler.currentLaunchAbilityKey_ = testKey;
4987 int32_t keyCode = -1;
4988 keyEvent->SetKeyCode(keyCode);
4989 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_UP);
4990 bool ret = handler.HandleConsumedKeyEvent(keyEvent);
4991 EXPECT_FALSE(ret);
4992 }
4993
4994 /**
4995 * @tc.name: KeyCommandHandlerTest_HandleSequences_003
4996 * @tc.desc: HandleSequences
4997 * @tc.type: FUNC
4998 * @tc.require:
4999 */
5000 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleSequences_003, TestSize.Level1)
5001 {
5002 CALL_TEST_DEBUG;
5003 KeyCommandHandler handler;
5004 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
5005 ASSERT_NE(keyEvent, nullptr);
5006 handler.sequenceOccurred_ = false;
5007 handler.matchedSequence_.timerId = 1;
5008 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_UP);
5009 bool ret = handler.HandleSequences(keyEvent);
5010 ASSERT_FALSE(ret);
5011 }
5012
5013 /**
5014 * @tc.name: KeyCommandHandlerTest_HandleScreenLocked_001
5015 * @tc.desc: HandleScreenLocked
5016 * @tc.type: FUNC
5017 * @tc.require:
5018 */
5019 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleScreenLocked_001, TestSize.Level1)
5020 {
5021 CALL_TEST_DEBUG;
5022 KeyCommandHandler handler;
5023 Sequence sequence;
5024 sequence.timerId = -1;
5025 bool isLaunchAbility = true;
5026 bool ret = handler.HandleScreenLocked(sequence, isLaunchAbility);
5027 ASSERT_TRUE(ret);
5028 sequence.timerId = 2;
5029 ret = handler.HandleScreenLocked(sequence, isLaunchAbility);
5030 ASSERT_TRUE(ret);
5031 }
5032
5033 /**
5034 * @tc.name: KeyCommandHandlerTest_MatchShortcutKey_001
5035 * @tc.desc: Test the funcation MatchShortcutKey
5036 * @tc.type: FUNC
5037 * @tc.require:
5038 */
5039 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_MatchShortcutKey_001, TestSize.Level1)
5040 {
5041 KeyCommandHandler handler;
5042 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
5043 ASSERT_NE(keyEvent, nullptr);
5044 ShortcutKey shortcutKey;
5045 std::vector<ShortcutKey> upAbilities;
5046 shortcutKey.statusConfigValue = false;
5047 bool ret = handler.MatchShortcutKey(keyEvent, shortcutKey, upAbilities);
5048 ASSERT_FALSE(ret);
5049 shortcutKey.statusConfigValue = true;
5050 shortcutKey.finalKey = 1;
5051 shortcutKey.triggerType = KeyEvent::KEY_ACTION_DOWN;
5052 keyEvent->SetKeyCode(KeyEvent::KEYCODE_HOME);
5053 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
5054 shortcutKey.preKeys.insert(2024);
5055 KeyEvent::KeyItem item1;
5056 item1.SetKeyCode(KeyEvent::KEYCODE_R);
5057 item1.SetPressed(true);
5058 item1.SetDownTime(500);
5059 keyEvent->keys_.push_back(item1);
5060 KeyEvent::KeyItem item2;
5061 item2.SetKeyCode(KeyEvent::KEYCODE_R);
5062 item2.SetPressed(false);
5063 item2.SetDownTime(200);
5064 keyEvent->keys_.push_back(item2);
5065 ret = handler.MatchShortcutKey(keyEvent, shortcutKey, upAbilities);
5066 ASSERT_FALSE(ret);
5067 }
5068
5069 /**
5070 * @tc.name: KeyCommandHandlerTest_PreHandleEvent_001
5071 * @tc.desc: Test the funcation PreHandleEvent
5072 * @tc.type: FUNC
5073 * @tc.require:
5074 */
5075 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_PreHandleEvent_001, TestSize.Level1)
5076 {
5077 KeyCommandHandler handler;
5078 std::shared_ptr<KeyEvent> key = KeyEvent::Create();
5079 ASSERT_NE(key, nullptr);
5080 EventLogHelper eventLogHelper;
5081 eventLogHelper.userType_ = "beta";
5082 std::shared_ptr<InputEvent> inputEvent = InputEvent::Create();
5083 EXPECT_NE(inputEvent, nullptr);
5084 inputEvent->bitwise_ = 0x00000000;
5085 bool ret = handler.PreHandleEvent(key);
5086 ASSERT_TRUE(ret);
5087 inputEvent->bitwise_ = InputEvent::EVENT_FLAG_PRIVACY_MODE;
5088 ret = handler.PreHandleEvent(key);
5089 ASSERT_TRUE(ret);
5090 handler.enableCombineKey_ = false;
5091 ret = handler.PreHandleEvent(key);
5092 ASSERT_FALSE(ret);
5093 handler.enableCombineKey_ = true;
5094 handler.isParseConfig_ = false;
5095 ret = handler.PreHandleEvent(key);
5096 ASSERT_TRUE(ret);
5097 handler.isParseConfig_ = true;
5098 handler.isParseMaxCount_ = false;
5099 ret = handler.PreHandleEvent(key);
5100 ASSERT_TRUE(ret);
5101 handler.isParseMaxCount_ = true;
5102 handler.isParseStatusConfig_ = false;
5103 ret = handler.PreHandleEvent(key);
5104 ASSERT_TRUE(ret);
5105 handler.isParseStatusConfig_ = false;
5106 ret = handler.PreHandleEvent(key);
5107 ASSERT_TRUE(ret);
5108 }
5109
5110 /**
5111 * @tc.name: KeyCommandHandlerTest_CheckInputMethodArea_006
5112 * @tc.desc: Test the funcation CheckInputMethodArea
5113 * @tc.type: FUNC
5114 * @tc.require:
5115 */
5116 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckInputMethodArea_006, TestSize.Level1)
5117 {
5118 CALL_TEST_DEBUG;
5119 KeyCommandHandler handler;
5120 std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
5121 ASSERT_NE(touchEvent, nullptr);
5122 std::shared_ptr<InputEvent> inputEvent = InputEvent::Create();
5123 EXPECT_NE(inputEvent, nullptr);
5124 inputEvent->SetTargetDisplayId(-1);
5125 inputEvent->SetTargetWindowId(5);
5126 InputWindowsManager inputWindowsManager;
5127 WindowInfo windowInfo;
5128 windowInfo.windowType = 2105;
5129 windowInfo.id = 5;
5130 windowInfo.area.x = 10;
5131 windowInfo.area.y = 20;
5132 windowInfo.area.width = 100;
5133 windowInfo.area.height = 200;
5134 inputWindowsManager.displayGroupInfo_.windowsInfo.push_back(windowInfo);
5135 PointerEvent::PointerItem item;
5136 item.SetDisplayX(5);
5137 item.SetDisplayY(10);
5138 touchEvent->AddPointerItem(item);
5139 bool ret = handler.CheckInputMethodArea(touchEvent);
5140 ASSERT_FALSE(ret);
5141 item.SetDisplayX(20);
5142 item.SetDisplayY(30);
5143 touchEvent->AddPointerItem(item);
5144 ret = handler.CheckInputMethodArea(touchEvent);
5145 ASSERT_FALSE(ret);
5146 windowInfo.area.height = INT32_MAX;
5147 inputWindowsManager.displayGroupInfo_.windowsInfo.push_back(windowInfo);
5148 ret = handler.CheckInputMethodArea(touchEvent);
5149 ASSERT_FALSE(ret);
5150 windowInfo.area.width = INT32_MAX;
5151 inputWindowsManager.displayGroupInfo_.windowsInfo.push_back(windowInfo);
5152 ret = handler.CheckInputMethodArea(touchEvent);
5153 ASSERT_FALSE(ret);
5154 inputEvent->SetTargetWindowId(10);
5155 ret = handler.CheckInputMethodArea(touchEvent);
5156 ASSERT_FALSE(ret);
5157 windowInfo.windowType = 1000;
5158 ret = handler.CheckInputMethodArea(touchEvent);
5159 ASSERT_FALSE(ret);
5160 }
5161
5162 /**
5163 * @tc.name: KeyCommandHandlerTest_HandleSequences_004
5164 * @tc.desc: Test the funcation HandleSequences
5165 * @tc.type: FUNC
5166 * @tc.require:
5167 */
5168 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleSequences_004, TestSize.Level1)
5169 {
5170 CALL_TEST_DEBUG;
5171 KeyCommandHandler handler;
5172 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
5173 ASSERT_NE(keyEvent, nullptr);
5174 handler.sequenceOccurred_ = false;
5175 handler.matchedSequence_.timerId = -10;
5176 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
5177 Sequence sequence1;
5178 sequence1.statusConfig = "statusConfig1";
5179 sequence1.statusConfigValue = true;
5180 sequence1.abilityStartDelay = 1;
5181 sequence1.timerId = 5;
5182 handler.sequences_.push_back(sequence1);
5183 Sequence sequence2;
5184 sequence2.statusConfig = "statusConfig2";
5185 sequence2.statusConfigValue = false;
5186 sequence2.abilityStartDelay = 2;
5187 sequence2.timerId = 1;
5188 handler.filterSequences_.push_back(sequence2);
5189 bool ret = handler.HandleSequences(keyEvent);
5190 ASSERT_FALSE(ret);
5191 SequenceKey sequenceKey;
5192 sequenceKey.keyCode = 1;
5193 sequenceKey.keyAction = KeyEvent::KEY_ACTION_DOWN;
5194 sequenceKey.actionTime = 2;
5195 sequenceKey.delay = 5;
5196 handler.keys_.push_back(sequenceKey);
5197 ret = handler.HandleSequences(keyEvent);
5198 ASSERT_FALSE(ret);
5199 }
5200
5201 /**
5202 * @tc.name: KeyCommandHandlerTest_MatchShortcutKey_003
5203 * @tc.desc: Test the funcation MatchShortcutKey
5204 * @tc.type: FUNC
5205 * @tc.require:
5206 */
5207 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_MatchShortcutKey_003, TestSize.Level1)
5208 {
5209 KeyCommandHandler handler;
5210 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
5211 ASSERT_NE(keyEvent, nullptr);
5212 ShortcutKey shortcutKey;
5213 std::vector<ShortcutKey> upAbilities;
5214 shortcutKey.statusConfigValue = true;
5215 shortcutKey.finalKey = 5;
5216 shortcutKey.triggerType = KeyEvent::KEY_ACTION_DOWN;
5217 shortcutKey.preKeys = {1};
5218 shortcutKey.businessId = "Ctrl+O";
5219 std::shared_ptr<KeyEvent> key = KeyEvent::Create();
5220 ASSERT_NE(key, nullptr);
5221 key->SetKeyCode(5);
5222 key->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
5223 KeyEvent::KeyItem item1;
5224 item1.SetKeyCode(1);
5225 item1.SetDownTime(10);
5226 item1.SetDeviceId(3);
5227 KeyEvent::KeyItem item2;
5228 item2.SetKeyCode(1);
5229 item2.SetDownTime(20);
5230 item2.SetDeviceId(4);
5231 keyEvent->AddKeyItem(item1);
5232 keyEvent->AddKeyItem(item2);
5233 MultiModalInputPreferencesManager multiModalInputPreferencesManager;
5234 multiModalInputPreferencesManager.shortcutKeyMap_.insert(std::make_pair("Ctrl+O", 5000));
5235 bool ret = handler.MatchShortcutKey(keyEvent, shortcutKey, upAbilities);
5236 EXPECT_FALSE(ret);
5237 shortcutKey.triggerType = KeyEvent::KEY_ACTION_UP;
5238 key->SetKeyAction(KeyEvent::KEY_ACTION_UP);
5239 ret = handler.MatchShortcutKey(keyEvent, shortcutKey, upAbilities);
5240 EXPECT_FALSE(ret);
5241 shortcutKey.triggerType = KeyEvent::KEY_ACTION_UNKNOWN;
5242 key->SetKeyAction(KeyEvent::KEY_ACTION_UNKNOWN);
5243 ret = handler.MatchShortcutKey(keyEvent, shortcutKey, upAbilities);
5244 EXPECT_FALSE(ret);
5245 }
5246
5247 /**
5248 * @tc.name: KeyCommandHandlerTest_MatchShortcutKey_004
5249 * @tc.desc: Test the funcation MatchShortcutKey
5250 * @tc.type: FUNC
5251 * @tc.require:
5252 */
5253 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_MatchShortcutKey_004, TestSize.Level1)
5254 {
5255 KeyCommandHandler handler;
5256 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
5257 ASSERT_NE(keyEvent, nullptr);
5258 ShortcutKey shortcutKey;
5259 std::vector<ShortcutKey> upAbilities;
5260 shortcutKey.statusConfigValue = true;
5261 shortcutKey.finalKey = 10;
5262 shortcutKey.triggerType = KeyEvent::KEY_ACTION_UP;
5263 shortcutKey.preKeys = {5};
5264 shortcutKey.businessId = "Ctrl+T";
5265 std::shared_ptr<KeyEvent> key = KeyEvent::Create();
5266 ASSERT_NE(key, nullptr);
5267 key->SetKeyCode(10);
5268 key->SetKeyAction(KeyEvent::KEY_ACTION_UP);
5269 KeyEvent::KeyItem item1;
5270 item1.SetKeyCode(5);
5271 item1.SetDownTime(6);
5272 item1.SetDeviceId(7);
5273 KeyEvent::KeyItem item2;
5274 item2.SetKeyCode(5);
5275 item2.SetDownTime(2);
5276 item2.SetDeviceId(1);
5277 keyEvent->AddKeyItem(item1);
5278 keyEvent->AddKeyItem(item2);
5279 MultiModalInputPreferencesManager multiModalInputPreferencesManager;
5280 multiModalInputPreferencesManager.shortcutKeyMap_.insert(std::make_pair("Ctrl+R", 300));
5281 bool ret = handler.MatchShortcutKey(keyEvent, shortcutKey, upAbilities);
5282 EXPECT_FALSE(ret);
5283 }
5284
5285 /**
5286 * @tc.name: KeyCommandHandlerTest_HandleShortKeys_01
5287 * @tc.desc: Test the funcation HandleShortKeys
5288 * @tc.type: FUNC
5289 * @tc.require:
5290 */
5291 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleShortKeys_01, TestSize.Level1)
5292 {
5293 KeyCommandHandler handler;
5294 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
5295 ASSERT_NE(keyEvent, nullptr);
5296 ShortcutKey shortcutKey;
5297 shortcutKey.preKeys = {2};
5298 shortcutKey.statusConfigValue = true;
5299 shortcutKey.finalKey = 6;
5300 shortcutKey.keyDownDuration = 7;
5301 shortcutKey.triggerType = KeyEvent::KEY_ACTION_DOWN;
5302 shortcutKey.timerId = 10;
5303 handler.shortcutKeys_.insert(std::make_pair("key", shortcutKey));
5304 handler.lastMatchedKey_.finalKey = 1;
5305 handler.lastMatchedKey_.triggerType = KeyEvent::KEY_ACTION_UP;
5306 handler.lastMatchedKey_.preKeys = {3};
5307 keyEvent->SetKeyCode(1);
5308 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_UP);
5309 KeyEvent::KeyItem item1;
5310 item1.SetKeyCode(3);
5311 item1.SetDownTime(5);
5312 item1.SetDeviceId(8);
5313 KeyEvent::KeyItem item2;
5314 item2.SetKeyCode(3);
5315 item2.SetDownTime(6);
5316 item2.SetDeviceId(4);
5317 keyEvent->AddKeyItem(item1);
5318 keyEvent->AddKeyItem(item2);
5319 bool ret = handler.HandleShortKeys(keyEvent);
5320 ASSERT_TRUE(ret);
5321 handler.lastMatchedKey_.preKeys = {4, 5, 6};
5322 handler.currentLaunchAbilityKey_.timerId = 5;
5323 handler.currentLaunchAbilityKey_.finalKey = 1;
5324 handler.currentLaunchAbilityKey_.triggerType = KeyEvent::KEY_ACTION_UP;
5325 handler.currentLaunchAbilityKey_.preKeys = {3};
5326 EventLogHelper eventLogHelper;
5327 eventLogHelper.userType_ = "beta";
5328 std::shared_ptr<InputEvent> inputEvent = InputEvent::Create();
5329 EXPECT_NE(inputEvent, nullptr);
5330 inputEvent->bitwise_ = InputEvent::EVENT_FLAG_PRIVACY_MODE;
5331 ret = handler.HandleShortKeys(keyEvent);
5332 ASSERT_TRUE(ret);
5333 eventLogHelper.userType_ = "aaaaaaa";
5334 ret = handler.HandleShortKeys(keyEvent);
5335 ASSERT_TRUE(ret);
5336 inputEvent->bitwise_ = 0;
5337 ret = handler.HandleShortKeys(keyEvent);
5338 ASSERT_TRUE(ret);
5339 }
5340
5341 /**
5342 * @tc.name: KeyCommandHandlerTest_CalcDrawCoordinate_001
5343 * @tc.desc: Test CalcDrawCoordinate
5344 * @tc.type: Function
5345 * @tc.require:
5346 */
5347 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CalcDrawCoordinate_001, TestSize.Level1)
5348 {
5349 CALL_TEST_DEBUG;
5350 KeyCommandHandler handler;
5351 DisplayInfo displayInfo;
5352 PointerEvent::PointerItem pointerItem;
5353 int32_t physicalX = 1;
5354 int32_t physicalY = 1;
5355 pointerItem.SetRawDisplayX(physicalX);
5356 pointerItem.SetRawDisplayY(physicalY);
5357 auto retPair = handler.CalcDrawCoordinate(displayInfo, pointerItem);
5358 EXPECT_EQ(retPair.first, 1);
5359 EXPECT_EQ(retPair.second, 1);
5360 }
5361
5362 /**
5363 * @tc.name: KeyCommandHandlerTest_CalcDrawCoordinate_002
5364 * @tc.desc: Test CalcDrawCoordinate
5365 * @tc.type: Function
5366 * @tc.require:
5367 */
5368 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CalcDrawCoordinate_002, TestSize.Level1)
5369 {
5370 CALL_TEST_DEBUG;
5371 KeyCommandHandler handler;
5372 DisplayInfo displayInfo = {
5373 .id = 0, .x = 0, .y = 0, .width = 100, .height = 200, .dpi = 240,
5374 .transform = {1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f}
5375 };
5376 PointerEvent::PointerItem pointerItem;
5377 int32_t physicalX = 10;
5378 int32_t physicalY = 10;
5379 pointerItem.SetRawDisplayX(physicalX);
5380 pointerItem.SetRawDisplayY(physicalY);
5381 auto retPair = handler.CalcDrawCoordinate(displayInfo, pointerItem);
5382 EXPECT_EQ(retPair.first, 21);
5383 EXPECT_EQ(retPair.second, 21);
5384 }
5385
5386 /**
5387 * @tc.name: KeyCommandHandlerTest_IsMatchedAbility
5388 * @tc.desc: Test IsMatchedAbility
5389 * @tc.type: Function
5390 * @tc.require:
5391 */
5392 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_IsMatchedAbility, TestSize.Level1)
5393 {
5394 CALL_TEST_DEBUG;
5395 KeyCommandHandler handler;
5396 std::vector<float> gesturePoints;
5397 float gestureLastX = 100.0f;
5398 float gestureLastY = 100.0f;
5399 gesturePoints.push_back(10.0f);
5400 EXPECT_FALSE(handler.IsMatchedAbility(gesturePoints, gestureLastX, gestureLastY));
5401
5402 gesturePoints.push_back(15.0f);
5403 gesturePoints.push_back(20.0f);
5404 EXPECT_TRUE(handler.IsMatchedAbility(gesturePoints, gestureLastX, gestureLastY));
5405 }
5406
5407 /**
5408 * @tc.name: KeyCommandHandlerTest_ParseRepeatKeyMaxCount
5409 * @tc.desc: Test ParseRepeatKeyMaxCount
5410 * @tc.type: Function
5411 * @tc.require:
5412 */
5413 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_ParseRepeatKeyMaxCount, TestSize.Level1)
5414 {
5415 CALL_TEST_DEBUG;
5416 KeyCommandHandler handler;
5417 EXPECT_NO_FATAL_FAILURE(handler.ParseRepeatKeyMaxCount());
5418 }
5419
5420 /**
5421 * @tc.name: KeyCommandHandlerTest_SetIsFreezePowerKey
5422 * @tc.desc: Test SetIsFreezePowerKey
5423 * @tc.type: Function
5424 * @tc.require:
5425 */
5426 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_SetIsFreezePowerKey, TestSize.Level1)
5427 {
5428 CALL_TEST_DEBUG;
5429 KeyCommandHandler handler;
5430 std::string pageName = "SosCountup";
5431 EXPECT_EQ(handler.SetIsFreezePowerKey(pageName), RET_OK);
5432 pageName = "SosCountdown";
5433 handler.sosDelayTimerId_ = 100;
5434 EXPECT_EQ(handler.SetIsFreezePowerKey(pageName), RET_OK);
5435 handler.sosDelayTimerId_ = -1;
5436 EXPECT_EQ(handler.SetIsFreezePowerKey(pageName), RET_OK);
5437 }
5438
5439 /**
5440 * @tc.name: KeyCommandHandlerTest_TouchPadKnuckleDoubleClickProcess
5441 * @tc.desc: Test the funcation TouchPadKnuckleDoubleClickProcess
5442 * @tc.type: Function
5443 * @tc.require:
5444 */
5445 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_TouchPadKnuckleDoubleClickProcess, TestSize.Level1)
5446 {
5447 CALL_TEST_DEBUG;
5448 KeyCommandHandler handler;
5449 std::string bundleName = "bundleName";
5450 std::string abilityName = "abilityName";
5451 std::string action = "action";
5452 DISPLAY_MONITOR-> SetScreenStatus(EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_OFF);
5453 DISPLAY_MONITOR->SetScreenLocked(true);
5454 ASSERT_NO_FATAL_FAILURE(handler.TouchPadKnuckleDoubleClickProcess(bundleName, abilityName, action));
5455 DISPLAY_MONITOR-> SetScreenStatus("abc");
5456 ASSERT_NO_FATAL_FAILURE(handler.TouchPadKnuckleDoubleClickProcess(bundleName, abilityName, action));
5457 DISPLAY_MONITOR->SetScreenLocked(false);
5458 ASSERT_NO_FATAL_FAILURE(handler.TouchPadKnuckleDoubleClickProcess(bundleName, abilityName, action));
5459 }
5460
5461 /**
5462 * @tc.name: KeyCommandHandlerTest_TouchPadKnuckleDoubleClickHandle
5463 * @tc.desc: Test the funcation TouchPadKnuckleDoubleClickHandle
5464 * @tc.type: Function
5465 * @tc.require:
5466 */
5467 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_TouchPadKnuckleDoubleClickHandle, TestSize.Level1)
5468 {
5469 CALL_TEST_DEBUG;
5470 KeyCommandHandler handler;
5471 std::shared_ptr<KeyEvent> event = KeyEvent::Create();
5472 ASSERT_NE(event, nullptr);
5473 event->SetKeyAction(KNUCKLE_1F_DOUBLE_CLICK);
5474 bool ret = handler.TouchPadKnuckleDoubleClickHandle(event);
5475 ASSERT_TRUE(ret);
5476 event->SetKeyAction(KNUCKLE_2F_DOUBLE_CLICK);
5477 ret = handler.TouchPadKnuckleDoubleClickHandle(event);
5478 ASSERT_TRUE(ret);
5479 event->SetKeyAction(1);
5480 ret = handler.TouchPadKnuckleDoubleClickHandle(event);
5481 ASSERT_FALSE(ret);
5482 }
5483
5484 /**
5485 * @tc.name: KeyCommandHandlerTest_IsMatchedAbility_001
5486 * @tc.desc: Test the funcation IsMatchedAbility
5487 * @tc.type: Function
5488 * @tc.require:
5489 */
5490 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_IsMatchedAbility_001, TestSize.Level1)
5491 {
5492 CALL_TEST_DEBUG;
5493 KeyCommandHandler handler;
5494 std::vector<float> gesturePoints;
5495 float gestureLastX = 100.0f;
5496 float gestureLastY = 150.0f;
5497 bool ret = handler.IsMatchedAbility(gesturePoints, gestureLastX, gestureLastY);
5498 ASSERT_FALSE(ret);
5499 gesturePoints.push_back(100.0f);
5500 gesturePoints.push_back(150.0f);
5501 ret = handler.IsMatchedAbility(gesturePoints, gestureLastX, gestureLastY);
5502 ASSERT_FALSE(ret);
5503 gesturePoints.push_back(200.0f);
5504 ret = handler.IsMatchedAbility(gesturePoints, gestureLastX, gestureLastY);
5505 ASSERT_FALSE(ret);
5506 }
5507
5508 /**
5509 * @tc.name: KeyCommandHandlerTest_InitKeyObserver
5510 * @tc.desc: Test the funcation InitKeyObserver
5511 * @tc.type: Function
5512 * @tc.require:
5513 */
5514 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_InitKeyObserver, TestSize.Level1)
5515 {
5516 CALL_TEST_DEBUG;
5517 KeyCommandHandler handler;
5518 handler.isParseStatusConfig_ = false;
5519 handler.isKnuckleSwitchConfig_ = false;
5520 ASSERT_NO_FATAL_FAILURE(handler.InitKeyObserver());
5521 handler.isKnuckleSwitchConfig_ = true;
5522 ASSERT_NO_FATAL_FAILURE(handler.InitKeyObserver());
5523 handler.isParseStatusConfig_ = true;
5524 handler.isKnuckleSwitchConfig_ = false;
5525 ASSERT_NO_FATAL_FAILURE(handler.InitKeyObserver());
5526 handler.isKnuckleSwitchConfig_ = true;
5527 ASSERT_NO_FATAL_FAILURE(handler.InitKeyObserver());
5528 }
5529
5530 /**
5531 * @tc.name: KeyCommandHandlerTest_SetIsFreezePowerKey_001
5532 * @tc.desc: Test the funcation SetIsFreezePowerKey
5533 * @tc.type: Function
5534 * @tc.require:
5535 */
5536 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_SetIsFreezePowerKey_001, TestSize.Level1)
5537 {
5538 CALL_TEST_DEBUG;
5539 KeyCommandHandler handler;
5540 handler.isFreezePowerKey_ = true;
5541 std::string pageName = "pageName";
5542 int32_t ret = handler.SetIsFreezePowerKey(pageName);
5543 EXPECT_EQ(ret, RET_OK);
5544 handler.isFreezePowerKey_ = false;
5545 handler.sosDelayTimerId_ = 1;
5546 pageName = "SosCountdown";
5547 ret = handler.SetIsFreezePowerKey(pageName);
5548 EXPECT_EQ(ret, RET_OK);
5549 handler.sosDelayTimerId_ = -1;
5550 ret = handler.SetIsFreezePowerKey(pageName);
5551 EXPECT_EQ(ret, RET_OK);
5552 }
5553
5554 /**
5555 * @tc.name: KeyCommandHandlerTest_ParseStatusConfigObserver_001
5556 * @tc.desc: Test the funcation ParseStatusConfigObserver
5557 * @tc.type: FUNC
5558 * @tc.require:
5559 */
5560 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_ParseStatusConfigObserver_001, TestSize.Level1)
5561 {
5562 CALL_TEST_DEBUG;
5563 KeyCommandHandler handler;
5564 Sequence sequence;
5565 sequence.statusConfig = "statusConfig";
5566 sequence.statusConfigValue = false;
5567 sequence.abilityStartDelay = 1;
5568 sequence.timerId = 1;
5569 handler.sequences_.push_back(sequence);
5570 ShortcutKey key;
5571 key.preKeys = {1, 2, 3};
5572 key.businessId = "business1";
5573 key.statusConfig = "";
5574 handler.shortcutKeys_.insert(std::make_pair("key1", key));
5575 ASSERT_NO_FATAL_FAILURE(handler.ParseStatusConfigObserver());
5576 }
5577
5578 /**
5579 * @tc.name: KeyCommandHandlerTest_ParseStatusConfigObserver_002
5580 * @tc.desc: Test the funcation ParseStatusConfigObserver
5581 * @tc.type: FUNC
5582 * @tc.require:
5583 */
5584 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_ParseStatusConfigObserver_002, TestSize.Level1)
5585 {
5586 CALL_TEST_DEBUG;
5587 KeyCommandHandler handler;
5588 Sequence sequence;
5589 sequence.statusConfig = "abc";
5590 sequence.statusConfigValue = true;
5591 sequence.abilityStartDelay = 1;
5592 sequence.timerId = 5;
5593 handler.sequences_.push_back(sequence);
5594 ShortcutKey key;
5595 key.preKeys = {1, 2, 3};
5596 key.businessId = "business1";
5597 key.statusConfig = "statusConfig";
5598 key.statusConfigValue = true;
5599 key.finalKey = 4;
5600 key.keyDownDuration = 5;
5601 key.triggerType = KeyEvent::KEY_ACTION_DOWN;
5602 key.timerId = 6;
5603 Ability ability_temp;
5604 ability_temp.bundleName = "bundleName";
5605 ability_temp.abilityName = "abilityName";
5606 key.ability = ability_temp;
5607 handler.shortcutKeys_.insert(std::make_pair("key1", key));
5608 ASSERT_NO_FATAL_FAILURE(handler.ParseStatusConfigObserver());
5609 }
5610
5611 /**
5612 * @tc.name: KeyCommandHandlerTest_ParseStatusConfigObserver_003
5613 * @tc.desc: Test the funcation ParseStatusConfigObserver
5614 * @tc.type: FUNC
5615 * @tc.require:
5616 */
5617 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_ParseStatusConfigObserver_003, TestSize.Level1)
5618 {
5619 CALL_TEST_DEBUG;
5620 KeyCommandHandler handler;
5621 Sequence sequence;
5622 sequence.statusConfig = "";
5623 sequence.statusConfigValue = false;
5624 sequence.abilityStartDelay = 2;
5625 sequence.timerId = 2;
5626 handler.sequences_.push_back(sequence);
5627 ASSERT_NO_FATAL_FAILURE(handler.ParseStatusConfigObserver());
5628 }
5629
5630 /**
5631 * @tc.name: KeyCommandHandlerTest_MatchShortcutKey_03
5632 * @tc.desc: Test the funcation MatchShortcutKey
5633 * @tc.type: Function
5634 * @tc.require:
5635 */
5636 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_MatchShortcutKey_03, TestSize.Level1)
5637 {
5638 CALL_TEST_DEBUG;
5639 KeyCommandHandler handler;
5640 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
5641 keyEvent->SetKeyCode(1);
5642 keyEvent->SetKeyAction(5);
5643 ASSERT_NE(keyEvent, nullptr);
5644 ShortcutKey shortcutKey;
5645 shortcutKey.preKeys = {1, 2, 3};
5646 shortcutKey.businessId = "businessId";
5647 shortcutKey.statusConfig = "statusConfig";
5648 shortcutKey.statusConfigValue = true;
5649 shortcutKey.finalKey = 5;
5650 shortcutKey.keyDownDuration = 1;
5651 shortcutKey.triggerType = 10;
5652 shortcutKey.timerId = 1;
5653 std::vector<ShortcutKey> upAbilities;
5654 upAbilities.push_back(shortcutKey);
5655 bool ret = handler.MatchShortcutKey(keyEvent, shortcutKey, upAbilities);
5656 ASSERT_FALSE(ret);
5657 }
5658
5659 /**
5660 * @tc.name: KeyCommandHandlerTest_MatchShortcutKey_02
5661 * @tc.desc: Test the funcation MatchShortcutKey
5662 * @tc.type: Function
5663 * @tc.require:
5664 */
5665 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_MatchShortcutKey_02, TestSize.Level1)
5666 {
5667 CALL_TEST_DEBUG;
5668 KeyCommandHandler handler;
5669 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
5670 keyEvent->SetKeyCode(6);
5671 keyEvent->SetKeyAction(3);
5672 ASSERT_NE(keyEvent, nullptr);
5673 ShortcutKey shortcutKey;
5674 shortcutKey.preKeys = {3, 2, 4};
5675 shortcutKey.businessId = "businessId1";
5676 shortcutKey.statusConfig = "statusConfig1";
5677 shortcutKey.statusConfigValue = false;
5678 shortcutKey.finalKey = 6;
5679 shortcutKey.keyDownDuration = 9;
5680 shortcutKey.triggerType = 1;
5681 shortcutKey.timerId = 3;
5682 std::vector<ShortcutKey> upAbilities;
5683 upAbilities.push_back(shortcutKey);
5684 bool ret = handler.MatchShortcutKey(keyEvent, shortcutKey, upAbilities);
5685 ASSERT_FALSE(ret);
5686 }
5687
5688 /**
5689 * @tc.name: KeyCommandHandlerTest_PreHandleEvent_02
5690 * @tc.desc: Test the funcation PreHandleEvent
5691 * @tc.type: Function
5692 * @tc.require:
5693 */
5694 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_PreHandleEvent_02, TestSize.Level1)
5695 {
5696 CALL_TEST_DEBUG;
5697 KeyCommandHandler handler;
5698
5699 handler.isParseConfig_ = false;
5700 handler.isParseLongPressConfig_ = false;
5701 handler.isParseMaxCount_ = false;
5702 bool ret = false;
5703 ret = handler.PreHandleEvent();
5704 ASSERT_TRUE(ret);
5705 }
5706
5707 /**
5708 * @tc.name: KeyCommandHandlerTest_HandleKnuckleGestureDownEvent_004
5709 * @tc.desc: Test HandleKnuckleGestureDownEvent
5710 * @tc.type: FUNC
5711 * @tc.require:
5712 */
5713 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureDownEvent_004, TestSize.Level1)
5714 {
5715 CALL_TEST_DEBUG;
5716 PointerEvent::PointerItem item;
5717 item.SetPointerId(0);
5718 item.SetToolType(PointerEvent::TOOL_TYPE_KNUCKLE);
5719 int64_t downTime = 100;
5720 item.SetDownTime(downTime);
5721 item.SetTargetWindowId(0);
5722 std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
5723 ASSERT_NE(touchEvent, nullptr);
5724 touchEvent->AddPointerItem(item);
5725 touchEvent->SetTargetDisplayId(0);
5726
5727 KeyCommandHandler handler;
5728 handler.knuckleSwitch_.statusConfigValue = false;
5729
5730 DisplayInfo displayInfo;
5731 displayInfo.id = 0;
5732 WindowInfo windowInfo;
5733 windowInfo.id = 0;
5734 windowInfo.windowType = WINDOW_INPUT_METHOD_TYPE;
5735 auto inputWindowsManager = std::make_shared<InputWindowsManager>();
5736 inputWindowsManager->displayGroupInfo_.windowsInfo.push_back(windowInfo);
5737 inputWindowsManager->displayGroupInfo_.displaysInfo.push_back(displayInfo);
5738 IInputWindowsManager::instance_ = inputWindowsManager;
5739
5740 ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureDownEvent(touchEvent));
5741
5742 touchEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
5743 ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureDownEvent(touchEvent));
5744
5745 touchEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP);
5746 ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureDownEvent(touchEvent));
5747
5748 touchEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE);
5749 ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureDownEvent(touchEvent));
5750 }
5751
5752 /**
5753 * @tc.name: KeyCommandHandlerTest_CheckTwoFingerGestureAction_009
5754 * @tc.desc: Test CheckTwoFingerGestureAction
5755 * @tc.type: FUNC
5756 * @tc.require:
5757 */
5758 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckTwoFingerGestureAction_009, TestSize.Level1)
5759 {
5760 CALL_TEST_DEBUG;
5761 KeyCommandHandler handler;
5762 handler.twoFingerGesture_.active = true;
5763 handler.twoFingerGesture_.touches[0].downTime = 0;
5764 handler.twoFingerGesture_.touches[1].downTime = 1;
5765
5766 DisplayInfo displayInfo;
5767 displayInfo.dpi = 320;
5768 displayInfo.width = 1260;
5769 displayInfo.height = 2720;
5770 displayInfo.uniq = "default0";
5771 auto inputWindowsManager = std::make_shared<InputWindowsManager>();
5772 inputWindowsManager->displayGroupInfo_.displaysInfo.push_back(displayInfo);
5773 IInputWindowsManager::instance_ = inputWindowsManager;
5774 handler.twoFingerGesture_.touches[0].x = 600;
5775 handler.twoFingerGesture_.touches[0].y = 600;
5776
5777 handler.twoFingerGesture_.touches[1].x = 800;
5778 handler.twoFingerGesture_.touches[1].y = 600;
5779 ASSERT_NO_FATAL_FAILURE(handler.CheckTwoFingerGestureAction());
5780
5781 handler.twoFingerGesture_.touches[1].x = 10;
5782 handler.twoFingerGesture_.touches[1].y = 600;
5783 ASSERT_NO_FATAL_FAILURE(handler.CheckTwoFingerGestureAction());
5784
5785 handler.twoFingerGesture_.touches[1].x = 1250;
5786 handler.twoFingerGesture_.touches[1].y = 600;
5787 ASSERT_NO_FATAL_FAILURE(handler.CheckTwoFingerGestureAction());
5788
5789 handler.twoFingerGesture_.touches[1].x = 600;
5790 handler.twoFingerGesture_.touches[1].y = 10;
5791 ASSERT_NO_FATAL_FAILURE(handler.CheckTwoFingerGestureAction());
5792
5793 handler.twoFingerGesture_.touches[1].x = 600;
5794 handler.twoFingerGesture_.touches[1].y = 2710;
5795 ASSERT_NO_FATAL_FAILURE(handler.CheckTwoFingerGestureAction());
5796 }
5797
5798 /**
5799 * @tc.name: KeyCommandHandlerTest_ConvertVPToPX_005
5800 * @tc.desc: Verify if (vp <= 0)
5801 * @tc.type: Function
5802 * @tc.require:
5803 */
5804 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_ConvertVPToPX_005, TestSize.Level1)
5805 {
5806 CALL_TEST_DEBUG;
5807 int32_t vp = -1;
5808 KeyCommandHandler handler;
5809 int32_t ret = handler.ConvertVPToPX(vp);
5810 ASSERT_EQ(ret, 0);
5811 ret = handler.ConvertVPToPX(vp);
5812 }
5813
5814 /**
5815 * @tc.name: KeyCommandHandlerTest_ConvertVPToPX_006
5816 * @tc.desc: Verify if (dpi <= 0)
5817 * @tc.type: Function
5818 * @tc.require:
5819 */
5820 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_ConvertVPToPX_006, TestSize.Level1)
5821 {
5822 CALL_TEST_DEBUG;
5823 int32_t vp = 5;
5824 DisplayInfo displayInfo;
5825 displayInfo.id = 1;
5826 displayInfo.x = 2;
5827 displayInfo.y = 3;
5828 displayInfo.width = 4;
5829 displayInfo.height = 5;
5830 displayInfo.dpi = -1;
5831 displayInfo.uniq = "default0";
5832 auto inputWindowsManager = std::make_shared<InputWindowsManager>();
5833 inputWindowsManager->displayGroupInfo_.displaysInfo.push_back(displayInfo);
5834 IInputWindowsManager::instance_ = inputWindowsManager;
5835 KeyCommandHandler handler;
5836 int32_t ret = handler.ConvertVPToPX(vp);
5837 ASSERT_EQ(ret, 0);
5838 }
5839
5840 /**
5841 * @tc.name: KeyCommandHandlerTest_CheckKnuckleCondition_001
5842 * @tc.desc: Test if (physicDisplayInfo != nullptr && physicDisplayInfo->direction != lastDirection_)
5843 * @tc.type: FUNC
5844 * @tc.require:
5845 */
5846 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckKnuckleCondition_001, TestSize.Level1)
5847 {
5848 CALL_TEST_DEBUG;
5849 PointerEvent::PointerItem item;
5850 item.SetPointerId(0);
5851 item.SetToolType(PointerEvent::TOOL_TYPE_KNUCKLE);
5852 item.SetTargetWindowId(0);
5853 std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
5854 ASSERT_NE(touchEvent, nullptr);
5855 touchEvent->AddPointerItem(item);
5856 touchEvent->SetPointerId(0);
5857
5858 KeyCommandHandler handler;
5859 handler.knuckleSwitch_.statusConfigValue = false;
5860 handler.singleKnuckleGesture_.state = false;
5861
5862 DisplayInfo displayInfo;
5863 displayInfo.id = 0;
5864 displayInfo.direction = DIRECTION0;
5865 WindowInfo windowInfo;
5866 windowInfo.id = 0;
5867 windowInfo.windowType = WINDOW_INPUT_METHOD_TYPE;
5868 auto inputWindowsManager = std::make_shared<InputWindowsManager>();
5869 inputWindowsManager->displayGroupInfo_.windowsInfo.push_back(windowInfo);
5870 inputWindowsManager->displayGroupInfo_.displaysInfo.push_back(displayInfo);
5871 IInputWindowsManager::instance_ = inputWindowsManager;
5872
5873 touchEvent->SetTargetDisplayId(1);
5874 ASSERT_NO_FATAL_FAILURE(handler.CheckKnuckleCondition(touchEvent));
5875
5876 touchEvent->SetTargetDisplayId(0);
5877 handler.lastDirection_ = DIRECTION0;
5878 ASSERT_NO_FATAL_FAILURE(handler.CheckKnuckleCondition(touchEvent));
5879
5880 handler.lastDirection_ = DIRECTION90;
5881 touchEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
5882 ASSERT_NO_FATAL_FAILURE(handler.CheckKnuckleCondition(touchEvent));
5883
5884 handler.lastDirection_ = DIRECTION90;
5885 touchEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE);
5886 ASSERT_NO_FATAL_FAILURE(handler.CheckKnuckleCondition(touchEvent));
5887
5888 handler.lastDirection_ = DIRECTION90;
5889 float pointer = 1.0;
5890 handler.gesturePoints_.push_back(pointer);
5891 ASSERT_NO_FATAL_FAILURE(handler.CheckKnuckleCondition(touchEvent));
5892 }
5893
5894 /**
5895 * @tc.name: KeyCommandHandlerTest_CheckKnuckleCondition_002
5896 * @tc.desc: Test if (touchEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_DOWN ||
5897 * touchEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_UP)
5898 * @tc.type: FUNC
5899 * @tc.require:
5900 */
5901 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckKnuckleCondition_002, TestSize.Level1)
5902 {
5903 CALL_TEST_DEBUG;
5904 PointerEvent::PointerItem item;
5905 item.SetPointerId(0);
5906 item.SetToolType(PointerEvent::TOOL_TYPE_KNUCKLE);
5907 item.SetTargetWindowId(0);
5908 std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
5909 ASSERT_NE(touchEvent, nullptr);
5910 touchEvent->AddPointerItem(item);
5911 touchEvent->SetPointerId(0);
5912
5913 KeyCommandHandler handler;
5914 handler.knuckleSwitch_.statusConfigValue = false;
5915 handler.singleKnuckleGesture_.state = false;
5916
5917 DisplayInfo displayInfo;
5918 displayInfo.id = 0;
5919 displayInfo.direction = DIRECTION0;
5920 WindowInfo windowInfo;
5921 windowInfo.id = 0;
5922 windowInfo.windowType = WINDOW_INPUT_METHOD_TYPE;
5923 auto inputWindowsManager = std::make_shared<InputWindowsManager>();
5924 inputWindowsManager->displayGroupInfo_.windowsInfo.push_back(windowInfo);
5925 inputWindowsManager->displayGroupInfo_.displaysInfo.push_back(displayInfo);
5926 IInputWindowsManager::instance_ = inputWindowsManager;
5927
5928 touchEvent->SetTargetDisplayId(0);
5929 handler.lastDirection_ = DIRECTION0;
5930
5931 touchEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE);
5932 ASSERT_NO_FATAL_FAILURE(handler.CheckKnuckleCondition(touchEvent));
5933
5934 touchEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
5935 ASSERT_NO_FATAL_FAILURE(handler.CheckKnuckleCondition(touchEvent));
5936
5937 touchEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP);
5938 ASSERT_NO_FATAL_FAILURE(handler.CheckKnuckleCondition(touchEvent));
5939 }
5940
5941 /**
5942 * @tc.name: KeyCommandHandlerTest_HandleKnuckleGestureTouchMove_003
5943 * @tc.desc: Test if (dx >= MOVE_TOLERANCE || dy >= MOVE_TOLERANCE)
5944 * @tc.type: FUNC
5945 * @tc.require:
5946 */
5947 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureTouchMove_003, TestSize.Level1)
5948 {
5949 CALL_TEST_DEBUG;
5950 PointerEvent::PointerItem item;
5951 item.SetPointerId(0);
5952 item.SetToolType(PointerEvent::TOOL_TYPE_KNUCKLE);
5953 item.SetTargetWindowId(0);
5954 item.SetRawDisplayX(3.0f);
5955 item.SetRawDisplayY(3.0f);
5956 std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
5957 ASSERT_NE(touchEvent, nullptr);
5958 touchEvent->AddPointerItem(item);
5959 touchEvent->SetPointerId(0);
5960 touchEvent->SetTargetDisplayId(0);
5961
5962 DisplayInfo displayInfo;
5963 displayInfo.id = 0;
5964 displayInfo.direction = DIRECTION0;
5965 auto inputWindowsManager = std::make_shared<InputWindowsManager>();
5966 inputWindowsManager->displayGroupInfo_.displaysInfo.push_back(displayInfo);
5967 IInputWindowsManager::instance_ = inputWindowsManager;
5968
5969 KeyCommandHandler handler;
5970 handler.gestureLastX_ = 3.0f;
5971 handler.gestureLastY_ = 3.0f;
5972 ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchMove(touchEvent));
5973
5974 handler.gestureLastX_ = 0.0f;
5975 handler.gestureLastY_ = 3.0f;
5976 ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchMove(touchEvent));
5977
5978 handler.gestureLastX_ = 3.0f;
5979 handler.gestureLastY_ = 0.0f;
5980 ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchMove(touchEvent));
5981
5982 handler.gestureLastX_ = 0.0f;
5983 handler.gestureLastY_ = 0.0f;
5984 ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchMove(touchEvent));
5985 }
5986
5987 /**
5988 * @tc.name: KeyCommandHandlerTest_HandleKnuckleGestureTouchMove_004
5989 * @tc.desc: Test if (!isStartBase_ && IsMatchedAbility(gesturePoints_, gestureLastX_, gestureLastY_))
5990 * @tc.type: FUNC
5991 * @tc.require:
5992 */
5993 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureTouchMove_004, TestSize.Level1)
5994 {
5995 CALL_TEST_DEBUG;
5996 PointerEvent::PointerItem item;
5997 item.SetPointerId(0);
5998 item.SetToolType(PointerEvent::TOOL_TYPE_KNUCKLE);
5999 item.SetTargetWindowId(0);
6000 item.SetRawDisplayX(3.0f);
6001 item.SetRawDisplayY(3.0f);
6002 std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
6003 ASSERT_NE(touchEvent, nullptr);
6004 touchEvent->AddPointerItem(item);
6005 touchEvent->SetPointerId(0);
6006 touchEvent->SetTargetDisplayId(0);
6007
6008 DisplayInfo displayInfo;
6009 displayInfo.id = 0;
6010 displayInfo.direction = DIRECTION0;
6011 auto inputWindowsManager = std::make_shared<InputWindowsManager>();
6012 inputWindowsManager->displayGroupInfo_.displaysInfo.push_back(displayInfo);
6013 IInputWindowsManager::instance_ = inputWindowsManager;
6014
6015 KeyCommandHandler handler;
6016 handler.gestureLastX_ = 0.0f;
6017 handler.gestureLastY_ = 0.0f;
6018 handler.isStartBase_ = true;
6019
6020 ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchMove(touchEvent));
6021
6022 handler.gesturePoints_.clear();
6023 float pointer = 500.0f;
6024 handler.gesturePoints_.emplace_back(pointer);
6025 pointer = 500.0f;
6026 handler.gesturePoints_.emplace_back(pointer);
6027 handler.isStartBase_ = false;
6028 handler.gestureLastX_ = 0.0f;
6029 handler.gestureLastY_ = 0.0f;
6030 ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchMove(touchEvent));
6031 }
6032
6033 /**
6034 * @tc.name: KeyCommandHandlerTest_HandleKnuckleGestureTouchMove_005
6035 * @tc.desc: Test if (!isGesturing_)
6036 * @tc.type: FUNC
6037 * @tc.require:
6038 */
6039 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureTouchMove_005, TestSize.Level1)
6040 {
6041 CALL_TEST_DEBUG;
6042 PointerEvent::PointerItem item;
6043 item.SetPointerId(0);
6044 item.SetToolType(PointerEvent::TOOL_TYPE_KNUCKLE);
6045 item.SetTargetWindowId(0);
6046 item.SetRawDisplayX(3.0f);
6047 item.SetRawDisplayY(3.0f);
6048 std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
6049 ASSERT_NE(touchEvent, nullptr);
6050 touchEvent->AddPointerItem(item);
6051 touchEvent->SetPointerId(0);
6052 touchEvent->SetTargetDisplayId(0);
6053
6054 DisplayInfo displayInfo;
6055 displayInfo.id = 0;
6056 displayInfo.direction = DIRECTION0;
6057 auto inputWindowsManager = std::make_shared<InputWindowsManager>();
6058 inputWindowsManager->displayGroupInfo_.displaysInfo.push_back(displayInfo);
6059 IInputWindowsManager::instance_ = inputWindowsManager;
6060
6061 KeyCommandHandler handler;
6062 handler.gestureLastX_ = 0.0f;
6063 handler.gestureLastY_ = 0.0f;
6064 handler.isStartBase_ = true;
6065 handler.isGesturing_ = true;
6066
6067 ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchMove(touchEvent));
6068
6069 handler.isStartBase_ = true;
6070 handler.isGesturing_ = false;
6071 handler.gestureLastX_ = 0.0f;
6072 handler.gestureLastY_ = 0.0f;
6073 ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchMove(touchEvent));
6074 }
6075
6076 /**
6077 * @tc.name: KeyCommandHandlerTest_HandleKnuckleGestureTouchMove_006
6078 * @tc.desc: Test if (gestureTrackLength_ > MIN_GESTURE_STROKE_LENGTH)
6079 * @tc.type: FUNC
6080 * @tc.require:
6081 */
6082 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureTouchMove_006, TestSize.Level1)
6083 {
6084 CALL_TEST_DEBUG;
6085 PointerEvent::PointerItem item;
6086 item.SetPointerId(0);
6087 item.SetToolType(PointerEvent::TOOL_TYPE_KNUCKLE);
6088 item.SetTargetWindowId(0);
6089 item.SetRawDisplayX(3.0f);
6090 item.SetRawDisplayY(3.0f);
6091 std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
6092 ASSERT_NE(touchEvent, nullptr);
6093 touchEvent->AddPointerItem(item);
6094 touchEvent->SetPointerId(0);
6095 touchEvent->SetTargetDisplayId(0);
6096
6097 DisplayInfo displayInfo;
6098 displayInfo.id = 0;
6099 displayInfo.direction = DIRECTION0;
6100 auto inputWindowsManager = std::make_shared<InputWindowsManager>();
6101 inputWindowsManager->displayGroupInfo_.displaysInfo.push_back(displayInfo);
6102 IInputWindowsManager::instance_ = inputWindowsManager;
6103
6104 KeyCommandHandler handler;
6105 handler.gestureLastX_ = 0.0f;
6106 handler.gestureLastY_ = 0.0f;
6107 handler.gestureTrackLength_ = 0.0f;
6108 handler.isStartBase_ = true;
6109 handler.isGesturing_ = false;
6110
6111 handler.gestureTrackLength_ = 0.0f;
6112 ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchMove(touchEvent));
6113
6114 handler.gestureTrackLength_ = 300.0f;
6115 handler.gestureLastX_ = 0.0f;
6116 handler.gestureLastY_ = 0.0f;
6117 handler.isStartBase_ = true;
6118 handler.isGesturing_ = false;
6119 ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchMove(touchEvent));
6120 }
6121
6122 /**
6123 * @tc.name: KeyCommandHandlerTest_HandleKnuckleGestureTouchMove_007
6124 * @tc.desc: Test if (isGesturing_ && !isLetterGesturing_)
6125 * @tc.type: FUNC
6126 * @tc.require:
6127 */
6128 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureTouchMove_007, TestSize.Level1)
6129 {
6130 CALL_TEST_DEBUG;
6131 PointerEvent::PointerItem item;
6132 item.SetPointerId(0);
6133 item.SetToolType(PointerEvent::TOOL_TYPE_KNUCKLE);
6134 item.SetTargetWindowId(0);
6135 item.SetRawDisplayX(3.0f);
6136 item.SetRawDisplayY(3.0f);
6137 std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
6138 ASSERT_NE(touchEvent, nullptr);
6139 touchEvent->AddPointerItem(item);
6140 touchEvent->SetPointerId(0);
6141 touchEvent->SetTargetDisplayId(0);
6142
6143 DisplayInfo displayInfo;
6144 displayInfo.id = 0;
6145 displayInfo.direction = DIRECTION0;
6146 auto inputWindowsManager = std::make_shared<InputWindowsManager>();
6147 inputWindowsManager->displayGroupInfo_.displaysInfo.push_back(displayInfo);
6148 IInputWindowsManager::instance_ = inputWindowsManager;
6149
6150 KeyCommandHandler handler;
6151 handler.gestureLastX_ = 0.0f;
6152 handler.gestureLastY_ = 0.0f;
6153 handler.gestureTrackLength_ = 0.0f;
6154 handler.isStartBase_ = true;
6155 handler.isGesturing_ = true;
6156 handler.isLetterGesturing_ = true;
6157 ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchMove(touchEvent));
6158
6159 handler.isStartBase_ = true;
6160 handler.isGesturing_ = true;
6161 handler.isLetterGesturing_ = false;
6162 handler.gestureLastX_ = 0.0f;
6163 handler.gestureLastY_ = 0.0f;
6164 ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchMove(touchEvent));
6165 }
6166
6167 /**
6168 * @tc.name: KeyCommandHandlerTest_HandleKnuckleGestureTouchMove_008
6169 * @tc.desc: Test if (boundingSquareness > MIN_LETTER_GESTURE_SQUARENESS)
6170 * @tc.type: FUNC
6171 * @tc.require:
6172 */
6173 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureTouchMove_008, TestSize.Level1)
6174 {
6175 CALL_TEST_DEBUG;
6176 PointerEvent::PointerItem item;
6177 item.SetPointerId(0);
6178 item.SetToolType(PointerEvent::TOOL_TYPE_KNUCKLE);
6179 item.SetTargetWindowId(0);
6180 item.SetRawDisplayX(3.0f);
6181 item.SetRawDisplayY(3.0f);
6182 std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
6183 ASSERT_NE(touchEvent, nullptr);
6184 touchEvent->AddPointerItem(item);
6185 touchEvent->SetPointerId(0);
6186 touchEvent->SetTargetDisplayId(0);
6187
6188 DisplayInfo displayInfo;
6189 displayInfo.id = 0;
6190 displayInfo.direction = DIRECTION0;
6191 auto inputWindowsManager = std::make_shared<InputWindowsManager>();
6192 inputWindowsManager->displayGroupInfo_.displaysInfo.push_back(displayInfo);
6193 IInputWindowsManager::instance_ = inputWindowsManager;
6194
6195 KeyCommandHandler handler;
6196 handler.gestureLastX_ = 0.0f;
6197 handler.gestureLastY_ = 0.0f;
6198 handler.gestureTrackLength_ = 0.0f;
6199 handler.isStartBase_ = true;
6200 handler.isGesturing_ = true;
6201 handler.isLetterGesturing_ = false;
6202
6203 ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchMove(touchEvent));
6204 }
6205
6206 /**
6207 * @tc.name: KeyCommandHandlerTest_ParseJson_002
6208 * @tc.desc: Test the funcation ParseJson
6209 * @tc.type: FUNC
6210 * @tc.require:
6211 */
6212 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_ParseJson_002, TestSize.Level1)
6213 {
6214 CALL_TEST_DEBUG;
6215 KeyCommandHandler handler;
6216 std::string defaultConfig = "/system/etc/multimodalinput/ability_launch_config.json";
6217 ASSERT_NO_FATAL_FAILURE(handler.ParseJson(defaultConfig));
6218 }
6219
6220 /**
6221 * @tc.name: KeyCommandHandlerTest_HandleEvent_003
6222 * @tc.desc: Test the funcation HandleEvent
6223 * @tc.type: FUNC
6224 * @tc.require:
6225 */
6226 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleEvent_003, TestSize.Level1)
6227 {
6228 CALL_TEST_DEBUG;
6229 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
6230 ASSERT_NE(keyEvent, nullptr);
6231 keyEvent->SetKeyCode(KeyEvent::KEYCODE_POWER);
6232 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
6233 int64_t time = 4000000;
6234 keyEvent->SetActionTime(time);
6235 KeyCommandHandler handler;
6236 handler.powerUpTime_ = 0;
6237 handler.sosLaunchTime_ = 0;
6238 handler.isParseConfig_ = true;
6239 handler.isParseLongPressConfig_ = true;
6240 handler.isParseMaxCount_ = true;
6241 ASSERT_NO_FATAL_FAILURE(handler.HandleEvent(keyEvent));
6242 }
6243
6244 /**
6245 * @tc.name: KeyCommandHandlerTest_HandleEvent_004
6246 * @tc.desc: Test if ((key->GetActionTime() - powerUpTime_) > POWER_ACTION_INTERVAL * FREQUENCY &&
6247 * (key->GetActionTime() - sosLaunchTime_) > SOS_WAIT_TIME * FREQUENCY)
6248 * @tc.type: FUNC
6249 * @tc.require:
6250 */
6251 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleEvent_004, TestSize.Level1)
6252 {
6253 CALL_TEST_DEBUG;
6254 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
6255 ASSERT_NE(keyEvent, nullptr);
6256 keyEvent->SetKeyCode(KeyEvent::KEYCODE_POWER);
6257 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
6258 int64_t time = 0;
6259 keyEvent->SetActionTime(time);
6260 KeyCommandHandler handler;
6261 handler.powerUpTime_ = 0;
6262 handler.sosLaunchTime_ = 0;
6263 handler.isParseConfig_ = true;
6264 handler.isParseLongPressConfig_ = true;
6265 handler.isParseMaxCount_ = true;
6266 ASSERT_NO_FATAL_FAILURE(handler.HandleEvent(keyEvent));
6267 }
6268
6269 /**
6270 * @tc.name: KeyCommandHandlerTest_HandleEvent_005
6271 * @tc.desc: Test if ((key->GetActionTime() - powerUpTime_) > POWER_ACTION_INTERVAL * FREQUENCY &&
6272 * (key->GetActionTime() - sosLaunchTime_) > SOS_WAIT_TIME * FREQUENCY)
6273 * @tc.type: FUNC
6274 * @tc.require:
6275 */
6276 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleEvent_005, TestSize.Level1)
6277 {
6278 CALL_TEST_DEBUG;
6279 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
6280 ASSERT_NE(keyEvent, nullptr);
6281 keyEvent->SetKeyCode(KeyEvent::KEYCODE_POWER);
6282 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
6283 int64_t time = 700000;
6284 keyEvent->SetActionTime(time);
6285 KeyCommandHandler handler;
6286 handler.powerUpTime_ = 0;
6287 handler.sosLaunchTime_ = 0;
6288 handler.isParseConfig_ = true;
6289 handler.isParseLongPressConfig_ = true;
6290 handler.isParseMaxCount_ = true;
6291 ASSERT_NO_FATAL_FAILURE(handler.HandleEvent(keyEvent));
6292 }
6293
6294 /**
6295 * @tc.name: KeyCommandHandlerTest_IsMusicActivate_001
6296 * @tc.desc: Test the funcation IsMusicActivate
6297 * @tc.type: FUNC
6298 * @tc.require:
6299 */
6300 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_IsMusicActivate_001, TestSize.Level1)
6301 {
6302 CALL_TEST_DEBUG;
6303 KeyCommandHandler handler;
6304 ASSERT_NO_FATAL_FAILURE(handler.IsMusicActivate());
6305 }
6306
6307 /**
6308 * @tc.name: KeyCommandHandlerTest_HandleRepeatKeyOwnCount_003
6309 * @tc.desc: Test if (item.ability.bundleName == SOS_BUNDLE_NAME)
6310 * @tc.type: FUNC
6311 * @tc.require:
6312 */
6313 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleRepeatKeyOwnCount_003, TestSize.Level1)
6314 {
6315 CALL_TEST_DEBUG;
6316 KeyCommandHandler handler;
6317 RepeatKey repeatKey;
6318 repeatKey.ability.bundleName = SOS_BUNDLE_NAME;
6319 ASSERT_NO_FATAL_FAILURE(handler.HandleRepeatKeyOwnCount(repeatKey));
6320
6321 repeatKey.ability.bundleName = "test";
6322 ASSERT_NO_FATAL_FAILURE(handler.HandleRepeatKeyOwnCount(repeatKey));
6323 }
6324
6325 /**
6326 * @tc.name: KeyCommandHandlerTest_HandleRepeatKeyOwnCount_004
6327 * @tc.desc: Test if (item.ability.bundleName == SOS_BUNDLE_NAME)
6328 * @tc.type: FUNC
6329 * @tc.require:
6330 */
6331 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleRepeatKeyOwnCount_004, TestSize.Level1)
6332 {
6333 CALL_TEST_DEBUG;
6334 KeyCommandHandler handler;
6335 RepeatKey repeatKey;
6336 repeatKey.ability.bundleName = SOS_BUNDLE_NAME;
6337 repeatKey.delay = 10;
6338 handler.downActionTime_ = 10;
6339 handler.lastDownActionTime_ = 10;
6340 ASSERT_NO_FATAL_FAILURE(handler.HandleRepeatKeyOwnCount(repeatKey));
6341
6342 handler.downActionTime_ = 100;
6343 ASSERT_NO_FATAL_FAILURE(handler.HandleRepeatKeyOwnCount(repeatKey));
6344 }
6345
6346 /**
6347 * @tc.name: KeyCommandHandlerTest_HandleRepeatKeyOwnCount_005
6348 * @tc.desc: Test if (item.ability.bundleName == SOS_BUNDLE_NAME)
6349 * @tc.type: FUNC
6350 * @tc.require:
6351 */
6352 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleRepeatKeyOwnCount_005, TestSize.Level1)
6353 {
6354 CALL_TEST_DEBUG;
6355 KeyCommandHandler handler;
6356 RepeatKey repeatKey;
6357 repeatKey.ability.bundleName = "test";
6358 repeatKey.delay = 10;
6359 handler.upActionTime_ = 10;
6360 handler.lastDownActionTime_ = 10;
6361 ASSERT_NO_FATAL_FAILURE(handler.HandleRepeatKeyOwnCount(repeatKey));
6362
6363 handler.downActionTime_ = 100;
6364 ASSERT_NO_FATAL_FAILURE(handler.HandleRepeatKeyOwnCount(repeatKey));
6365 }
6366
6367 /**
6368 * @tc.name: KeyCommandHandlerTest_CheckSpecialRepeatKey_001
6369 * @tc.desc: Test if (bundleName.find(matchName) == std::string::npos)
6370 * @tc.type: FUNC
6371 * @tc.require:
6372 */
6373 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckSpecialRepeatKey_001, TestSize.Level1)
6374 {
6375 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
6376 ASSERT_NE(keyEvent, nullptr);
6377 keyEvent->SetKeyCode(KeyEvent::KEYCODE_VOLUME_DOWN);
6378
6379 RepeatKey repeatKey;
6380 repeatKey.keyCode = KeyEvent::KEYCODE_VOLUME_DOWN;
6381 repeatKey.ability.bundleName = ".camera";
6382
6383 KeyCommandHandler handler;
6384 ASSERT_NO_FATAL_FAILURE(handler.CheckSpecialRepeatKey(repeatKey, keyEvent));
6385
6386 repeatKey.ability.bundleName = ".test";
6387 ASSERT_NO_FATAL_FAILURE(handler.CheckSpecialRepeatKey(repeatKey, keyEvent));
6388 }
6389
6390 /**
6391 * @tc.name: KeyCommandHandlerTest_CheckSpecialRepeatKey_002
6392 * @tc.desc: Test if (bundleName.find(matchName) == std::string::npos)
6393 * @tc.type: FUNC
6394 * @tc.require:
6395 */
6396 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckSpecialRepeatKey_002, TestSize.Level1)
6397 {
6398 CALL_TEST_DEBUG;
6399 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
6400 ASSERT_NE(keyEvent, nullptr);
6401 keyEvent->SetKeyCode(KeyEvent::KEYCODE_VOLUME_DOWN);
6402
6403 RepeatKey repeatKey;
6404 repeatKey.keyCode = KeyEvent::KEYCODE_VOLUME_DOWN;
6405 repeatKey.ability.bundleName = ".camera";
6406
6407 auto inputWindowsManager = std::make_shared<InputWindowsManager>();
6408 WindowInfo windowInfo;
6409 windowInfo.id = 0;
6410 inputWindowsManager->displayGroupInfo_.windowsInfo.push_back(windowInfo);
6411 inputWindowsManager->displayGroupInfo_.focusWindowId = 0;
6412 UDSServer udsServer;
6413 udsServer.idxPidMap_.insert(std::make_pair(0, 1));
6414 SessionPtr sessionPtr = std::make_shared<UDSSession>(repeatKey.ability.bundleName, 0, 0, 0, 0);
6415 udsServer.sessionsMap_[1] = sessionPtr;
6416 inputWindowsManager->udsServer_ = &udsServer;
6417 EXPECT_NE(inputWindowsManager->udsServer_, nullptr);
6418 IInputWindowsManager::instance_ = inputWindowsManager;
6419
6420 KeyCommandHandler handler;
6421 DISPLAY_MONITOR->SetScreenStatus("test");
6422 DISPLAY_MONITOR->SetScreenLocked(true);
6423 ASSERT_NO_FATAL_FAILURE(handler.CheckSpecialRepeatKey(repeatKey, keyEvent));
6424 }
6425
6426 /**
6427 * @tc.name: KeyCommandHandlerTest_CheckSpecialRepeatKey_003
6428 * @tc.desc: Test if (WIN_MGR->JudgeCaramaInFore() &&
6429 * (screenStatus != EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_OFF && isScreenLocked))
6430 * @tc.type: FUNC
6431 * @tc.require:
6432 */
6433 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckSpecialRepeatKey_003, TestSize.Level1)
6434 {
6435 CALL_TEST_DEBUG;
6436 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
6437 ASSERT_NE(keyEvent, nullptr);
6438 keyEvent->SetKeyCode(KeyEvent::KEYCODE_VOLUME_DOWN);
6439
6440 RepeatKey repeatKey;
6441 repeatKey.keyCode = KeyEvent::KEYCODE_VOLUME_DOWN;
6442 repeatKey.ability.bundleName = ".camera";
6443
6444 auto inputWindowsManager = std::make_shared<InputWindowsManager>();
6445 WindowInfo windowInfo;
6446 windowInfo.id = 0;
6447 inputWindowsManager->displayGroupInfo_.windowsInfo.push_back(windowInfo);
6448 inputWindowsManager->displayGroupInfo_.focusWindowId = 0;
6449 UDSServer udsServer;
6450 udsServer.idxPidMap_.insert(std::make_pair(0, 1));
6451 SessionPtr sessionPtr = std::make_shared<UDSSession>(repeatKey.ability.bundleName, 0, 0, 0, 0);
6452 udsServer.sessionsMap_[1] = sessionPtr;
6453 inputWindowsManager->udsServer_ = &udsServer;
6454 EXPECT_NE(inputWindowsManager->udsServer_, nullptr);
6455 IInputWindowsManager::instance_ = inputWindowsManager;
6456
6457 KeyCommandHandler handler;
6458 DISPLAY_MONITOR->SetScreenStatus(EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_OFF);
6459 DISPLAY_MONITOR->SetScreenLocked(true);
6460 ASSERT_NO_FATAL_FAILURE(handler.CheckSpecialRepeatKey(repeatKey, keyEvent));
6461 }
6462
6463 /**
6464 * @tc.name: KeyCommandHandlerTest_CheckSpecialRepeatKey_004
6465 * @tc.desc: Test if (WIN_MGR->JudgeCaramaInFore() &&
6466 * (screenStatus != EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_OFF && isScreenLocked))
6467 * @tc.type: FUNC
6468 * @tc.require:
6469 */
6470 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckSpecialRepeatKey_004, TestSize.Level1)
6471 {
6472 CALL_TEST_DEBUG;
6473 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
6474 ASSERT_NE(keyEvent, nullptr);
6475 keyEvent->SetKeyCode(KeyEvent::KEYCODE_VOLUME_DOWN);
6476
6477 RepeatKey repeatKey;
6478 repeatKey.keyCode = KeyEvent::KEYCODE_VOLUME_DOWN;
6479 repeatKey.ability.bundleName = ".camera";
6480
6481 auto inputWindowsManager = std::make_shared<InputWindowsManager>();
6482 WindowInfo windowInfo;
6483 windowInfo.id = 0;
6484 inputWindowsManager->displayGroupInfo_.windowsInfo.push_back(windowInfo);
6485 inputWindowsManager->displayGroupInfo_.focusWindowId = 0;
6486 UDSServer udsServer;
6487 udsServer.idxPidMap_.insert(std::make_pair(0, 1));
6488 SessionPtr sessionPtr = std::make_shared<UDSSession>(repeatKey.ability.bundleName, 0, 0, 0, 0);
6489 udsServer.sessionsMap_[1] = sessionPtr;
6490 inputWindowsManager->udsServer_ = &udsServer;
6491 EXPECT_NE(inputWindowsManager->udsServer_, nullptr);
6492 IInputWindowsManager::instance_ = inputWindowsManager;
6493
6494 KeyCommandHandler handler;
6495 DISPLAY_MONITOR->SetScreenStatus("test");
6496 DISPLAY_MONITOR->SetScreenLocked(false);
6497 ASSERT_NO_FATAL_FAILURE(handler.CheckSpecialRepeatKey(repeatKey, keyEvent));
6498 }
6499
6500 /**
6501 * @tc.name: KeyCommandHandlerTest_HandleRepeatKeyCount_001
6502 * @tc.desc: Test if (walletLaunchDelayTimes_ != 0)
6503 * @tc.type: FUNC
6504 * @tc.require:
6505 */
6506 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleRepeatKeyCount_001, TestSize.Level1)
6507 {
6508 CALL_TEST_DEBUG;
6509 KeyCommandHandler handler;
6510 RepeatKey repeatKey;
6511 repeatKey.keyCode = KeyEvent::KEYCODE_POWER;
6512 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
6513 ASSERT_NE(keyEvent, nullptr);
6514 keyEvent->SetKeyCode(KeyEvent::KEYCODE_POWER);
6515 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_UP);
6516 handler.walletLaunchDelayTimes_ = 0;
6517 ASSERT_NO_FATAL_FAILURE(handler.HandleRepeatKeyCount(repeatKey, keyEvent));
6518
6519 handler.walletLaunchDelayTimes_ = 1;
6520 ASSERT_NO_FATAL_FAILURE(handler.HandleRepeatKeyCount(repeatKey, keyEvent));
6521 }
6522 } // namespace MMI
6523 } // namespace OHOS