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