• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <fstream>
17 #include <list>
18 #include <gtest/gtest.h>
19 
20 #include "display_event_monitor.h"
21 #include "event_log_helper.h"
22 #include "key_option.h"
23 #include "key_gesture_manager.h"
24 #include "key_event.h"
25 #include "mmi_log.h"
26 #include "nap_process.h"
27 #include "switch_subscriber_handler.h"
28 #include "uds_server.h"
29 
30 #undef MMI_LOG_TAG
31 #define MMI_LOG_TAG "KeyGestureManagerTest"
32 
33 namespace OHOS {
34 namespace MMI {
35 namespace {
36 using namespace testing::ext;
37 constexpr int32_t INVALID_ENTITY_ID { -1 };
38 constexpr size_t SINGLE_KEY_PRESSED { 1 };
39 } // namespace
40 
41 class KeyGestureManagerTest : public testing::Test {
42 public:
SetUpTestCase(void)43     static void SetUpTestCase(void) {}
TearDownTestCase(void)44     static void TearDownTestCase(void) {}
45 };
46 
47 class MyKeyGesture : public KeyGestureManager::KeyGesture {
48 public:
49     MyKeyGesture() = default;
50     ~MyKeyGesture() override = default;
51 
IsWorking()52     bool IsWorking() override
53     {
54         return true;
55     }
56 
ShouldIntercept(std::shared_ptr<KeyOption> keyOption) const57     bool ShouldIntercept(std::shared_ptr<KeyOption> keyOption) const override
58     {
59         return true;
60     }
61 
Intercept(std::shared_ptr<KeyEvent> keyEvent)62     bool Intercept(std::shared_ptr<KeyEvent> keyEvent) override
63     {
64         return true;
65     }
66 
Dump(std::ostringstream & output) const67     void Dump(std::ostringstream &output) const override
68     {
69         output << "MyKeyGesture";
70     }
71 };
72 
73 /**
74  * @tc.name: KeyGestureManagerTest_Intercept_002
75  * @tc.desc: Test the funcation Intercept
76  * @tc.type: FUNC
77  * @tc.require:
78  */
79 HWTEST_F(KeyGestureManagerTest, KeyGestureManagerTest_Intercept_002, TestSize.Level1)
80 {
81     CALL_TEST_DEBUG;
82     KeyGestureManager keyGestureManager;
83     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
84     ASSERT_NE(keyEvent, nullptr);
85     auto keyGesture1 = std::make_unique<MyKeyGesture>();
86     auto keyGesture2 = std::make_unique<MyKeyGesture>();
87     auto keyGesture3 = std::make_unique<MyKeyGesture>();
88     keyGestureManager.keyGestures_.push_back(std::move(keyGesture1));
89     keyGestureManager.keyGestures_.push_back(std::move(keyGesture2));
90     keyGestureManager.keyGestures_.push_back(std::move(keyGesture3));
91     EXPECT_FALSE(EventLogHelper::IsBetaVersion());
92     EXPECT_FALSE(keyEvent->HasFlag(InputEvent::EVENT_FLAG_PRIVACY_MODE));
93     EXPECT_TRUE(keyGestureManager.Intercept(keyEvent));
94 }
95 
96 /**
97  * @tc.name: KeyGestureManagerTest_TriggerHandlers_01
98  * @tc.desc: Test the funcation TriggerHandlers
99  * @tc.type: FUNC
100  * @tc.require:
101  */
102 HWTEST_F(KeyGestureManagerTest, KeyGestureManagerTest_TriggerHandlers_01, TestSize.Level1)
103 {
104     CALL_TEST_DEBUG;
105     std::function<void(std::shared_ptr<KeyEvent>)> myCallback;
106     KeyGestureManager::Handler handler1(1, 10, 500, myCallback);
107     KeyGestureManager::Handler handler2(2, 20, 1000, myCallback);
108     KeyGestureManager::Handler handler3(3, 30, 1500, myCallback);
109 
110     std::shared_ptr<MyKeyGesture> myKeyGesture = std::make_shared<MyKeyGesture>();
111     myKeyGesture->handlers_.push_back(handler1);
112     myKeyGesture->handlers_.push_back(handler2);
113     myKeyGesture->handlers_.push_back(handler3);
114     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
115     ASSERT_NE(keyEvent, nullptr);
116 
117     std::set<int32_t> foregroundPids = myKeyGesture->GetForegroundPids();
118     bool haveForeground = myKeyGesture->HaveForegroundHandler(foregroundPids);
119     EXPECT_FALSE(haveForeground);
120     ASSERT_NO_FATAL_FAILURE(myKeyGesture->TriggerHandlers(keyEvent));
121 }
122 
123 /**
124  * @tc.name: LongPressSingleKey_Dump_01
125  * @tc.desc: Test the funcation LongPressSingleKey_Dump
126  * @tc.type: FUNC
127  * @tc.require:
128  */
129 HWTEST_F(KeyGestureManagerTest, LongPressSingleKey_Dump_01, TestSize.Level1)
130 {
131     CALL_TEST_DEBUG;
132     int32_t keyCode = 1;
133     KeyGestureManager::LongPressSingleKey longPressSingleKey(keyCode);
134     std::ostringstream output;
135     longPressSingleKey.keyCode_ = 2;
136 
137     std::function<void(std::shared_ptr<KeyEvent>)> myCallback;
138     KeyGestureManager::Handler handler1(1, 10, 500, myCallback);
139     KeyGestureManager::Handler handler2(2, 20, 1000, myCallback);
140     KeyGestureManager::Handler handler3(3, 30, 1500, myCallback);
141 
142     std::shared_ptr<MyKeyGesture> myKeyGesture = std::make_shared<MyKeyGesture>();
143     myKeyGesture->handlers_.push_back(handler1);
144     myKeyGesture->handlers_.push_back(handler2);
145     myKeyGesture->handlers_.push_back(handler3);
146     ASSERT_NO_FATAL_FAILURE(longPressSingleKey.Dump(output));
147 }
148 
149 /**
150  * @tc.name: LongPressCombinationKey_Dump_01
151  * @tc.desc: Test the funcation LongPressCombinationKey_Dump
152  * @tc.type: FUNC
153  * @tc.require:
154  */
155 HWTEST_F(KeyGestureManagerTest, LongPressCombinationKey_Dump_01, TestSize.Level1)
156 {
157     CALL_TEST_DEBUG;
158     std::set<int32_t> keys = {1, 2, 3};
159     KeyGestureManager::LongPressCombinationKey longPressCombinationKey(keys);
160     std::ostringstream output;
161     longPressCombinationKey.keys_ = {3, 4, 5, 6};
162     ASSERT_NO_FATAL_FAILURE(longPressCombinationKey.Dump(output));
163 
164     longPressCombinationKey.keys_ = {};
165     std::function<void(std::shared_ptr<KeyEvent>)> myCallback;
166     KeyGestureManager::Handler handler1(1, 10, 500, myCallback);
167     KeyGestureManager::Handler handler2(2, 20, 1000, myCallback);
168     KeyGestureManager::Handler handler3(3, 30, 1500, myCallback);
169     std::shared_ptr<MyKeyGesture> myKeyGesture = std::make_shared<MyKeyGesture>();
170     myKeyGesture->handlers_.push_back(handler1);
171     myKeyGesture->handlers_.push_back(handler2);
172     myKeyGesture->handlers_.push_back(handler3);
173     ASSERT_NO_FATAL_FAILURE(longPressCombinationKey.Dump(output));
174 }
175 
176 /**
177  * @tc.name: KeyGestureManagerTest_Intercept_01
178  * @tc.desc: Test the funcation Intercept
179  * @tc.type: FUNC
180  * @tc.require:
181  */
182 HWTEST_F(KeyGestureManagerTest, KeyGestureManagerTest_Intercept_01, TestSize.Level1)
183 {
184     CALL_TEST_DEBUG;
185     KeyGestureManager keyGestureManager;
186     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
187     ASSERT_NE(keyEvent, nullptr);
188     bool ret = keyGestureManager.Intercept(keyEvent);
189     EXPECT_FALSE(ret);
190 }
191 
192 /**
193  * @tc.name: KeyGestureManagerTest_RemoveKeyGesture_01
194  * @tc.desc: Test the funcation RemoveKeyGesture
195  * @tc.type: FUNC
196  * @tc.require:
197  */
198 HWTEST_F(KeyGestureManagerTest, KeyGestureManagerTest_RemoveKeyGesture_01, TestSize.Level1)
199 {
200     CALL_TEST_DEBUG;
201     KeyGestureManager keyGestureManager;
202     int32_t id = 1;
203     ASSERT_NO_FATAL_FAILURE(keyGestureManager.RemoveKeyGesture(id));
204 }
205 
206 /**
207  * @tc.name: KeyGestureManagerTest_RemoveKeyGesture_02
208  * @tc.desc: Test the funcation RemoveKeyGesture
209  * @tc.type: FUNC
210  * @tc.require:
211  */
212 HWTEST_F(KeyGestureManagerTest, KeyGestureManagerTest_RemoveKeyGesture_02, TestSize.Level1)
213 {
214     CALL_TEST_DEBUG;
215     KeyGestureManager keyGestureManager;
216     int32_t id = -2;
217     ASSERT_NO_FATAL_FAILURE(keyGestureManager.RemoveKeyGesture(id));
218 }
219 
220 /**
221  * @tc.name: KeyGestureManagerTest_AddKeyGesture_01
222  * @tc.desc: Test the funcation AddKeyGesture
223  * @tc.type: FUNC
224  * @tc.require:
225  */
226 HWTEST_F(KeyGestureManagerTest, KeyGestureManagerTest_AddKeyGesture_01, TestSize.Level1)
227 {
228     CALL_TEST_DEBUG;
229     KeyGestureManager keyGestureManager;
230     int32_t pid = 1;
231     std::shared_ptr<KeyOption> keyOption = nullptr;
__anone9be5c8a0202(std::shared_ptr<KeyEvent> event) 232     auto callback = [](std::shared_ptr<KeyEvent> event) {};
233     int32_t result = keyGestureManager.AddKeyGesture(pid, keyOption, callback);
234     EXPECT_EQ(result, INVALID_ENTITY_ID);
235 }
236 
237 /**
238  * @tc.name: KeyGestureManagerTest_ShouldIntercept_01
239  * @tc.desc: Test the funcation ShouldIntercept
240  * @tc.type: FUNC
241  * @tc.require:
242  */
243 HWTEST_F(KeyGestureManagerTest, KeyGestureManagerTest_ShouldIntercept_01, TestSize.Level1)
244 {
245     CALL_TEST_DEBUG;
246     KeyGestureManager keyGestureManager;
247     std::shared_ptr<KeyOption> keyOption = nullptr;
248     bool result = keyGestureManager.ShouldIntercept(keyOption);
249     EXPECT_FALSE(result);
250 }
251 
252 /**
253  * @tc.name: KeyGestureManagerTest_Intercept_02
254  * @tc.desc: Test the funcation ShouldIntercept
255  * @tc.type: FUNC
256  * @tc.require:
257  */
258 HWTEST_F(KeyGestureManagerTest, KeyGestureManagerTest_Intercept_02, TestSize.Level1)
259 {
260     CALL_TEST_DEBUG;
261     int32_t keyCode = 1;
262     KeyGestureManager::LongPressSingleKey longPressSingleKey(keyCode);
263     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
264     ASSERT_NE(keyEvent, nullptr);
265     keyEvent->keyCode_ = 2;
266     longPressSingleKey.keyCode_ = 2;
267     keyEvent->keyAction_ = KeyEvent::KEY_ACTION_DOWN;
268 
269     std::shared_ptr<MyKeyGesture> myKeyGesture = std::make_shared<MyKeyGesture>();
270     myKeyGesture->active_ = true;
271     bool ret = longPressSingleKey.Intercept(keyEvent);
272     EXPECT_TRUE(ret);
273 
274     myKeyGesture->active_ = true;
275     bool ret2 = longPressSingleKey.Intercept(keyEvent);
276     EXPECT_TRUE(ret2);
277 }
278 
279 /**
280  * @tc.name: KeyGestureManagerTest_Intercept_03
281  * @tc.desc: Test the funcation ShouldIntercept
282  * @tc.type: FUNC
283  * @tc.require:
284  */
285 HWTEST_F(KeyGestureManagerTest, KeyGestureManagerTest_Intercept_03, TestSize.Level1)
286 {
287     CALL_TEST_DEBUG;
288     int32_t keyCode = 1;
289     KeyGestureManager::LongPressSingleKey longPressSingleKey(keyCode);
290     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
291     ASSERT_NE(keyEvent, nullptr);
292     keyEvent->keyCode_ = 3;
293     longPressSingleKey.keyCode_ = 2;
294     keyEvent->keyAction_ = KeyEvent::KEY_ACTION_DOWN;
295     bool ret = longPressSingleKey.Intercept(keyEvent);
296     EXPECT_FALSE(ret);
297 }
298 
299 /**
300  * @tc.name: KeyGestureManagerTest_Intercept_04
301  * @tc.desc: Test the funcation ShouldIntercept
302  * @tc.type: FUNC
303  * @tc.require:
304  */
305 HWTEST_F(KeyGestureManagerTest, KeyGestureManagerTest_Intercept_04, TestSize.Level1)
306 {
307     CALL_TEST_DEBUG;
308     int32_t keyCode = 1;
309     KeyGestureManager::LongPressSingleKey longPressSingleKey(keyCode);
310     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
311     ASSERT_NE(keyEvent, nullptr);
312     keyEvent->keyCode_ = 2;
313     longPressSingleKey.keyCode_ = 2;
314     keyEvent->keyAction_ = KeyEvent::KEY_ACTION_UP;
315     bool ret = longPressSingleKey.Intercept(keyEvent);
316     EXPECT_FALSE(ret);
317 }
318 
319 /**
320  * @tc.name: KeyGestureManagerTest_Intercept_05
321  * @tc.desc: Test the funcation ShouldIntercept
322  * @tc.type: FUNC
323  * @tc.require:
324  */
325 HWTEST_F(KeyGestureManagerTest, KeyGestureManagerTest_Intercept_05, TestSize.Level1)
326 {
327     CALL_TEST_DEBUG;
328     int32_t keyCode = 1;
329     KeyGestureManager::LongPressSingleKey longPressSingleKey(keyCode);
330     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
331     ASSERT_NE(keyEvent, nullptr);
332     keyEvent->keyCode_ = 3;
333     longPressSingleKey.keyCode_ = 2;
334     keyEvent->keyAction_ = KeyEvent::KEY_ACTION_UP;
335     bool ret = longPressSingleKey.Intercept(keyEvent);
336     EXPECT_FALSE(ret);
337 }
338 
339 /**
340  * @tc.name: KeyGestureManagerTest_Intercept_06
341  * @tc.desc: Test the funcation ShouldIntercept
342  * @tc.type: FUNC
343  * @tc.require:
344  */
345 HWTEST_F(KeyGestureManagerTest, KeyGestureManagerTest_Intercept_06, TestSize.Level1)
346 {
347     CALL_TEST_DEBUG;
348     int32_t keyCode = 1;
349     KeyGestureManager::LongPressSingleKey longPressSingleKey(keyCode);
350     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
351     ASSERT_NE(keyEvent, nullptr);
352     keyEvent->keyCode_ = 3;
353     longPressSingleKey.keyCode_ = 2;
354     keyEvent->keyAction_ = KeyEvent::KEY_ACTION_UP;
355 
356     std::shared_ptr<MyKeyGesture> myKeyGesture = std::make_shared<MyKeyGesture>();
357     myKeyGesture->active_ = true;
358     bool ret = longPressSingleKey.Intercept(keyEvent);
359     EXPECT_FALSE(ret);
360 
361     myKeyGesture->active_ = false;
362     bool ret2 = longPressSingleKey.Intercept(keyEvent);
363     EXPECT_FALSE(ret2);
364 }
365 
366 /**
367  * @tc.name: KeyGestureManagerTest_IsWorking_01
368  * @tc.desc: Test the funcation ShouldIntercept
369  * @tc.type: FUNC
370  * @tc.require:
371  */
372 HWTEST_F(KeyGestureManagerTest, KeyGestureManagerTest_IsWorking_01, TestSize.Level1)
373 {
374     CALL_TEST_DEBUG;
375     KeyGestureManager::PullUpAccessibility pullUpAccessibility;
376     DISPLAY_MONITOR->screenStatus_ = EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_OFF;
377     bool ret = pullUpAccessibility.IsWorking();
378     EXPECT_FALSE(ret);
379 }
380 
381 /**
382  * @tc.name: KeyGestureManagerTest_RecognizeGesture_01
383  * @tc.desc: Test the funcation RecognizeGesture
384  * @tc.type: FUNC
385  * @tc.require:
386  */
387 HWTEST_F(KeyGestureManagerTest, KeyGestureManagerTest_RecognizeGesture_01, TestSize.Level1)
388 {
389     CALL_TEST_DEBUG;
390     std::set<int32_t> keys = {1, 2, 3};
391     KeyGestureManager::LongPressCombinationKey longPressCombinationKey(keys);
392     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
393     ASSERT_NE(keyEvent, nullptr);
394 
395     std::vector<int32_t> pressedKeys = {1};
396     EXPECT_TRUE(pressedKeys.size() == SINGLE_KEY_PRESSED);
397     bool ret = longPressCombinationKey.RecognizeGesture(keyEvent);
398     EXPECT_FALSE(ret);
399 }
400 
401 /**
402  * @tc.name: KeyGestureManagerTest_RecognizeGesture_02
403  * @tc.desc: Test the funcation RecognizeGesture
404  * @tc.type: FUNC
405  * @tc.require:
406  */
407 HWTEST_F(KeyGestureManagerTest, KeyGestureManagerTest_RecognizeGesture_02, TestSize.Level1)
408 {
409     CALL_TEST_DEBUG;
410     std::set<int32_t> keys = { 1, 2, 3 };
411     KeyGestureManager::LongPressCombinationKey longPressCombinationKey(keys);
412     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
413     ASSERT_NE(keyEvent, nullptr);
414 
415     std::vector<int32_t> pressedKeys = { 2, 3, 4 };
416     EXPECT_FALSE(pressedKeys.size() == SINGLE_KEY_PRESSED);
417     bool ret = longPressCombinationKey.RecognizeGesture(keyEvent);
418     EXPECT_FALSE(ret);
419 }
420 
421 /**
422  * @tc.name: KeyGestureManagerTest_TriggerAll_01
423  * @tc.desc: Test the funcation TriggerAll
424  * @tc.type: FUNC
425  * @tc.require:
426  */
427 HWTEST_F(KeyGestureManagerTest, KeyGestureManagerTest_TriggerAll_01, TestSize.Level1)
428 {
429     CALL_TEST_DEBUG;
430     std::set<int32_t> keys = { 1, 2, 3 };
431     KeyGestureManager::LongPressCombinationKey longPressCombinationKey(keys);
432     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
433     ASSERT_NE(keyEvent, nullptr);
434     ASSERT_NO_FATAL_FAILURE(longPressCombinationKey.TriggerAll(keyEvent));
435 }
436 
437 /**
438  * @tc.name: KeyGestureManagerTest_RunPending_01
439  * @tc.desc: Test the funcation RunPending
440  * @tc.type: FUNC
441  * @tc.require:
442  */
443 HWTEST_F(KeyGestureManagerTest, KeyGestureManagerTest_RunPending_01, TestSize.Level1)
444 {
445     CALL_TEST_DEBUG;
446     std::function<void(std::shared_ptr<KeyEvent>)> myCallback;
447     KeyGestureManager::Handler handler(1, 2, 3000, myCallback);
448 
449     handler.keyEvent_ = nullptr;
450     ASSERT_NO_FATAL_FAILURE(handler.RunPending());
451 }
452 
453 /**
454  * @tc.name: KeyGestureManagerTest_RunPending_02
455  * @tc.desc: Test the funcation RunPending
456  * @tc.type: FUNC
457  * @tc.require:
458  */
459 HWTEST_F(KeyGestureManagerTest, KeyGestureManagerTest_RunPending_02, TestSize.Level1)
460 {
461     CALL_TEST_DEBUG;
462     std::function<void(std::shared_ptr<KeyEvent>)> myCallback;
463     KeyGestureManager::Handler handler(1, 2, 3000, myCallback);
464 
465     handler.keyEvent_ = KeyEvent::Create();
466     ASSERT_NE(handler.keyEvent_, nullptr);
467     ASSERT_NO_FATAL_FAILURE(handler.RunPending());
468 }
469 
470 /**
471  * @tc.name: KeyGestureManagerTest_ResetTimer_01
472  * @tc.desc: Test the funcation ResetTimer
473  * @tc.type: FUNC
474  * @tc.require:
475  */
476 HWTEST_F(KeyGestureManagerTest, KeyGestureManagerTest_ResetTimer_01, TestSize.Level1)
477 {
478     CALL_TEST_DEBUG;
479     std::function<void(std::shared_ptr<KeyEvent>)> myCallback;
480     KeyGestureManager::Handler handler(1, 2, 3000, myCallback);
481     handler.timerId_ = 1;
482     ASSERT_NO_FATAL_FAILURE(handler.ResetTimer());
483 }
484 
485 /**
486  * @tc.name: KeyGestureManagerTest_ResetTimer_02
487  * @tc.desc: Test the funcation ResetTimer
488  * @tc.type: FUNC
489  * @tc.require:
490  */
491 HWTEST_F(KeyGestureManagerTest, KeyGestureManagerTest_ResetTimer_02, TestSize.Level1)
492 {
493     CALL_TEST_DEBUG;
494     std::function<void(std::shared_ptr<KeyEvent>)> myCallback;
495     KeyGestureManager::Handler handler(1, 2, 3000, myCallback);
496     handler.timerId_ = -2;
497     ASSERT_NO_FATAL_FAILURE(handler.ResetTimer());
498 }
499 
500 /**
501  * @tc.name: KeyGestureManagerTest_RunPendingHandlers_01
502  * @tc.desc: Test the funcation RunPendingHandlers
503  * @tc.type: FUNC
504  * @tc.require:
505  */
506 HWTEST_F(KeyGestureManagerTest, KeyGestureManagerTest_RunPendingHandlers_01, TestSize.Level1)
507 {
508     CALL_TEST_DEBUG;
509     std::function<void(std::shared_ptr<KeyEvent>)> myCallback;
510     KeyGestureManager::Handler handler1(1, 10, 500, myCallback);
511     KeyGestureManager::Handler handler2(2, 20, 1000, myCallback);
512     KeyGestureManager::Handler handler3(3, 30, 1500, myCallback);
513 
514     std::shared_ptr<MyKeyGesture> myKeyGesture = std::make_shared<MyKeyGesture>();
515     myKeyGesture->handlers_.push_back(handler1);
516     myKeyGesture->handlers_.push_back(handler2);
517     myKeyGesture->handlers_.push_back(handler3);
518 
519     std::set<int32_t> foregroundPids = myKeyGesture->GetForegroundPids();
520     bool haveForeground = myKeyGesture->HaveForegroundHandler(foregroundPids);
521     EXPECT_FALSE(haveForeground);
522 
523     int32_t keyCode = 1;
524     KeyGestureManager::LongPressSingleKey longPressSingleKey(keyCode);
525     ASSERT_NO_FATAL_FAILURE(longPressSingleKey.RunPendingHandlers());
526 }
527 
528 /**
529  * @tc.name: KeyGestureManagerTest_RunHandler_01
530  * @tc.desc: Test the funcation RunHandler
531  * @tc.type: FUNC
532  * @tc.require:
533  */
534 HWTEST_F(KeyGestureManagerTest, KeyGestureManagerTest_RunHandler_01, TestSize.Level1)
535 {
536     CALL_TEST_DEBUG;
537     std::function<void(std::shared_ptr<KeyEvent>)> myCallback;
538     KeyGestureManager::Handler handler1(1, 10, 500, myCallback);
539     KeyGestureManager::Handler handler2(2, 20, 1000, myCallback);
540     KeyGestureManager::Handler handler3(3, 30, 1500, myCallback);
541 
542     std::shared_ptr<MyKeyGesture> myKeyGesture = std::make_shared<MyKeyGesture>();
543     myKeyGesture->handlers_.push_back(handler1);
544     myKeyGesture->handlers_.push_back(handler2);
545     myKeyGesture->handlers_.push_back(handler3);
546 
547     int32_t handlerId = 1;
548     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
549     ASSERT_NE(keyEvent, nullptr);
550     ASSERT_NO_FATAL_FAILURE(myKeyGesture->RunHandler(handlerId, keyEvent));
551 
552     handlerId = 5;
553     ASSERT_NO_FATAL_FAILURE(myKeyGesture->RunHandler(handlerId, keyEvent));
554 }
555 
556 /**
557  * @tc.name: LongPressCombinationKey_Intercept_01
558  * @tc.desc: Test the funcation RecognizeGesture
559  * @tc.type: FUNC
560  * @tc.require:
561  */
562 HWTEST_F(KeyGestureManagerTest, LongPressCombinationKey_Intercept_01, TestSize.Level1)
563 {
564     CALL_TEST_DEBUG;
565     std::set<int32_t> keys = {1, 2, 3};
566     KeyGestureManager::LongPressCombinationKey longPressCombinationKey(keys);
567     std::shared_ptr<MyKeyGesture> myKeyGesture = std::make_shared<MyKeyGesture>();
568     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
569     std::function<void(std::shared_ptr<KeyEvent>)> myCallback;
570     ASSERT_NE(keyEvent, nullptr);
571 
572     keyEvent->keyCode_ = 3;
573     longPressCombinationKey.keys_ = {2, 3, 4};
574     keyEvent->keyAction_ = KeyEvent::KEY_ACTION_DOWN;
575     myKeyGesture->active_ = true;
576     EXPECT_FALSE(EventLogHelper::IsBetaVersion());
577     EXPECT_FALSE(keyEvent->HasFlag(InputEvent::EVENT_FLAG_PRIVACY_MODE));
578     bool ret = longPressCombinationKey.Intercept(keyEvent);
579     EXPECT_FALSE(ret);
580     myKeyGesture->active_ = false;
581     EXPECT_TRUE(myKeyGesture->IsWorking());
582 
583     KeyGestureManager::Handler handler1(1, 10, 500, myCallback);
584     KeyGestureManager::Handler handler2(2, 20, 1000, myCallback);
585     KeyGestureManager::Handler handler3(3, 30, 1500, myCallback);
586     myKeyGesture->handlers_.push_back(handler1);
587     myKeyGesture->handlers_.push_back(handler2);
588     myKeyGesture->handlers_.push_back(handler3);
589     EXPECT_FALSE(myKeyGesture->handlers_.empty());
590     bool ret2 = longPressCombinationKey.Intercept(keyEvent);
591     EXPECT_FALSE(ret2);
592 }
593 
594 /**
595  * @tc.name: LongPressCombinationKey_Intercept_02
596  * @tc.desc: Test the funcation RecognizeGesture
597  * @tc.type: FUNC
598  * @tc.require:
599  */
600 HWTEST_F(KeyGestureManagerTest, LongPressCombinationKey_Intercept_02, TestSize.Level1)
601 {
602     CALL_TEST_DEBUG;
603     std::set<int32_t> keys = {1, 2, 3};
604     KeyGestureManager::LongPressCombinationKey longPressCombinationKey(keys);
605     std::shared_ptr<MyKeyGesture> myKeyGesture = std::make_shared<MyKeyGesture>();
606     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
607     std::function<void(std::shared_ptr<KeyEvent>)> myCallback;
608     ASSERT_NE(keyEvent, nullptr);
609 
610     keyEvent->keyCode_ = 5;
611     longPressCombinationKey.keys_ = {2, 3, 4};
612     keyEvent->keyAction_ = KeyEvent::KEY_ACTION_UP;
613     myKeyGesture->active_ = true;
614     bool ret = longPressCombinationKey.Intercept(keyEvent);
615     EXPECT_FALSE(ret);
616 
617     myKeyGesture->active_ = false;
618     bool ret2 = longPressCombinationKey.Intercept(keyEvent);
619     EXPECT_FALSE(ret2);
620 }
621 
622 /**
623  * @tc.name: LongPressCombinationKey_Intercept_03
624  * @tc.desc: Test the funcation LongPressCombinationKey::Intercept
625  * @tc.type: FUNC
626  * @tc.require:
627  */
628 HWTEST_F(KeyGestureManagerTest, LongPressCombinationKey_Intercept_03, TestSize.Level1)
629 {
630     CALL_TEST_DEBUG;
631     KeyGestureManager::LongPressCombinationKey longPressCombinationKey({
632         KeyEvent::KEYCODE_VOLUME_DOWN, KeyEvent::KEYCODE_VOLUME_UP });
633     longPressCombinationKey.MarkActive(true);
634 
635     auto keyEvent = KeyEvent::Create();
636     ASSERT_NE(keyEvent, nullptr);
637     keyEvent->SetKeyCode(KeyEvent::KEYCODE_VOLUME_DOWN);
638     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
639     EXPECT_TRUE(longPressCombinationKey.Intercept(keyEvent));
640 }
641 
642 /**
643  * @tc.name: LongPressCombinationKey_Intercept_04
644  * @tc.desc: Test the funcation LongPressCombinationKey::Intercept
645  * @tc.type: FUNC
646  * @tc.require:
647  */
648 HWTEST_F(KeyGestureManagerTest, LongPressCombinationKey_Intercept_04, TestSize.Level1)
649 {
650     CALL_TEST_DEBUG;
651     DISPLAY_MONITOR->SetScreenStatus(EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_OFF);
652     KeyGestureManager::LongPressCombinationKey longPressCombinationKey({
653         KeyEvent::KEYCODE_VOLUME_DOWN, KeyEvent::KEYCODE_VOLUME_UP });
654 
655     auto keyEvent = KeyEvent::Create();
656     ASSERT_NE(keyEvent, nullptr);
657     keyEvent->SetKeyCode(KeyEvent::KEYCODE_VOLUME_DOWN);
658     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
659     EXPECT_FALSE(longPressCombinationKey.Intercept(keyEvent));
660 }
661 
662 /**
663  * @tc.name: LongPressCombinationKey_Intercept_05
664  * @tc.desc: Test the funcation LongPressCombinationKey::Intercept
665  * @tc.type: FUNC
666  * @tc.require:
667  */
668 HWTEST_F(KeyGestureManagerTest, LongPressCombinationKey_Intercept_05, TestSize.Level1)
669 {
670     CALL_TEST_DEBUG;
671     KeyGestureManager::LongPressCombinationKey longPressCombinationKey({
672         KeyEvent::KEYCODE_VOLUME_DOWN, KeyEvent::KEYCODE_VOLUME_UP });
673     longPressCombinationKey.MarkKeyConsumed();
674 
675     auto keyEvent = KeyEvent::Create();
676     ASSERT_NE(keyEvent, nullptr);
677     keyEvent->SetKeyCode(KeyEvent::KEYCODE_VOLUME_DOWN);
678     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_UP);
679     EXPECT_TRUE(longPressCombinationKey.Intercept(keyEvent));
680 }
681 
682 /**
683  * @tc.name: LongPressCombinationKey_Intercept_06
684  * @tc.desc: Test the funcation LongPressCombinationKey::Intercept
685  * @tc.type: FUNC
686  * @tc.require:
687  */
688 HWTEST_F(KeyGestureManagerTest, LongPressCombinationKey_Intercept_06, TestSize.Level1)
689 {
690     CALL_TEST_DEBUG;
691     KeyGestureManager::LongPressCombinationKey longPressCombinationKey({
692         KeyEvent::KEYCODE_VOLUME_DOWN, KeyEvent::KEYCODE_VOLUME_UP });
693     auto keyEvent = KeyEvent::Create();
694     ASSERT_NE(keyEvent, nullptr);
695     keyEvent->SetKeyCode(KeyEvent::KEYCODE_VOLUME_DOWN);
696     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_UP);
697     EXPECT_FALSE(longPressCombinationKey.Intercept(keyEvent));
698 }
699 
700 /**
701  * @tc.name: KeyGestureManagerTest_NotifyHandlers_01
702  * @tc.desc: Test the funcation NotifyHandlers
703  * @tc.type: FUNC
704  * @tc.require:
705  */
706 HWTEST_F(KeyGestureManagerTest, KeyGestureManagerTest_NotifyHandlers_01, TestSize.Level1)
707 {
708     CALL_TEST_DEBUG;
709     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
710     ASSERT_NE(keyEvent, nullptr);
711     std::function<void(std::shared_ptr<KeyEvent>)> myCallback;
712     KeyGestureManager::Handler handler1(1, 10, 500, myCallback);
713     KeyGestureManager::Handler handler2(2, 20, 1000, myCallback);
714     KeyGestureManager::Handler handler3(3, 30, 1500, myCallback);
715 
716     std::shared_ptr<MyKeyGesture> myKeyGesture = std::make_shared<MyKeyGesture>();
717     myKeyGesture->handlers_.push_back(handler1);
718     myKeyGesture->handlers_.push_back(handler2);
719     myKeyGesture->handlers_.push_back(handler3);
720 
721     std::set<int32_t> foregroundPids = myKeyGesture->GetForegroundPids();
722     bool haveForeground = myKeyGesture->HaveForegroundHandler(foregroundPids);
723     EXPECT_FALSE(haveForeground);
724     ASSERT_NO_FATAL_FAILURE(myKeyGesture->NotifyHandlers(keyEvent));
725 }
726 
727 /**
728  * @tc.name: KeyGestureManagerTest_AddHandler
729  * @tc.desc: Test the funcation AddHandler
730  * @tc.type: FUNC
731  * @tc.require:
732  */
733 HWTEST_F(KeyGestureManagerTest, AddHandler_Success, TestSize.Level1)
734 {
735     std::function<void(std::shared_ptr<KeyEvent>)> myCallback;
736     std::shared_ptr<MyKeyGesture> myKeyGesture = std::make_shared<MyKeyGesture>();
737 
738     int32_t id1 = myKeyGesture->AddHandler(10, 500, myCallback);
739     EXPECT_GT(id1, 0);
740     EXPECT_EQ(myKeyGesture->handlers_.size(), 1);
741 
742     int32_t id2 = myKeyGesture->AddHandler(20, 1000, myCallback);
743     EXPECT_GT(id2, id1);
744     EXPECT_EQ(myKeyGesture->handlers_.size(), 2);
745 }
746 
747 /**
748  * @tc.name: KeyGestureManagerTest_RemoveHandler
749  * @tc.desc: Test the funcation RemoveHandler
750  * @tc.type: FUNC
751  * @tc.require:
752  */
753 HWTEST_F(KeyGestureManagerTest, KeyGestureManagerTest_RemoveHandler, TestSize.Level1)
754 {
755     CALL_TEST_DEBUG;
756 
757     std::function<void(std::shared_ptr<KeyEvent>)> myCallback;
758     std::shared_ptr<MyKeyGesture> myKeyGesture = std::make_shared<MyKeyGesture>();
759 
760     int32_t id1 = myKeyGesture->AddHandler(10, 500, myCallback);
761     int32_t id2 = myKeyGesture->AddHandler(20, 1000, myCallback);
762 
763     bool resultSuccess = myKeyGesture->RemoveHandler(id1);
764     EXPECT_TRUE(resultSuccess);
765     EXPECT_EQ(myKeyGesture->handlers_.size(), 1);
766 
767     bool resultfailed = myKeyGesture->RemoveHandler(id1);
768     EXPECT_FALSE(resultfailed);
769     EXPECT_EQ(myKeyGesture->handlers_.size(), 1);
770 
771     EXPECT_EQ(myKeyGesture->handlers_.front().GetId(), id2);
772 }
773 
774 /**
775  * @tc.name: KeyGestureManagerTest_ResetTimers
776  * @tc.desc: Test the funcation KeyGestureManager::KeyGesture::ResetTimers
777  * @tc.type: FUNC
778  * @tc.require:
779  */
780 HWTEST_F(KeyGestureManagerTest, KeyGestureManagerTest_KeyGesture_ResetTimers, TestSize.Level1)
781 {
782     CALL_TEST_DEBUG;
783     std::function<void(std::shared_ptr<KeyEvent>)> myCallback;
784     std::shared_ptr<MyKeyGesture> myKeyGesture = std::make_shared<MyKeyGesture>();
785 
786     int32_t id1 = myKeyGesture->AddHandler(10, 500, myCallback);
787     int32_t id2 = myKeyGesture->AddHandler(30, 1500, myCallback);
788 
789     EXPECT_EQ(myKeyGesture->handlers_.size(), 2);
790     myKeyGesture->ResetTimers();
791     EXPECT_EQ(myKeyGesture->handlers_.size(), 2);
792     bool resultfailed1 = myKeyGesture->RemoveHandler(id1);
793     EXPECT_TRUE(resultfailed1);
794     bool resultfailed2 = myKeyGesture->RemoveHandler(id2);
795     EXPECT_TRUE(resultfailed2);
796 }
797 
798 /**
799  * @tc.name: KeyGestureManagerTest_KeyGesture_IsWorking
800  * @tc.desc: Test the funcation KeyGestureManager::KeyGesture::IsWorking
801  * @tc.type: FUNC
802  * @tc.require:
803  */
804 HWTEST_F(KeyGestureManagerTest, KeyGestureManagerTest_KeyGesture_IsWorking, TestSize.Level1)
805 {
806     CALL_TEST_DEBUG;
807     std::shared_ptr<MyKeyGesture> myKeyGesture = std::make_shared<MyKeyGesture>();
808     EXPECT_TRUE(myKeyGesture->IsWorking());
809 }
810 
811 /**
812  * @tc.name: KeyGestureManagerTest_KeyGesture_GetForegroundPids
813  * @tc.desc: Test the funcation KeyGestureManager::KeyGesture::GetForegroundPids
814  * @tc.type: FUNC
815  * @tc.require:
816  */
817 HWTEST_F(KeyGestureManagerTest, KeyGestureManagerTest_KeyGesture_GetForegroundPids, TestSize.Level1)
818 {
819     CALL_TEST_DEBUG;
820     std::shared_ptr<MyKeyGesture> myKeyGesture = std::make_shared<MyKeyGesture>();
821     std::set<int32_t> pids = myKeyGesture->GetForegroundPids();
822     EXPECT_EQ(pids.size(), 0);
823 }
824 
825 /**
826  * @tc.name: KeyGestureManagerTest_KeyGesture_HaveForegroundHandler
827  * @tc.desc: Test the funcation KeyGestureManager::KeyGesture::HaveForegroundHandler
828  * @tc.type: FUNC
829  * @tc.require:
830  */
831 HWTEST_F(KeyGestureManagerTest, KeyGesture_HaveForegroundHandler, TestSize.Level1)
832 {
833     CALL_TEST_DEBUG;
834     std::shared_ptr<MyKeyGesture> myKeyGesture = std::make_shared<MyKeyGesture>();
835     std::set<int32_t> foregroundPids = {1001, 1002};
836     EXPECT_FALSE(myKeyGesture->HaveForegroundHandler(foregroundPids));
837 }
838 
839 /**
840  * @tc.name: KeyGestureManagerTest_KeyGesture_ShowHandlers
841  * @tc.desc: Test the funcation KeyGestureManager::KeyGesture::_ShowHandlers
842  * @tc.type: FUNC
843  * @tc.require:
844  */
845 HWTEST_F(KeyGestureManagerTest, KeyGestureManagerTest_KeyGesture_ShowHandlers, TestSize.Level1)
846 {
847     CALL_TEST_DEBUG;
848     std::function<void(std::shared_ptr<KeyEvent>)> myCallback;
849     std::shared_ptr<MyKeyGesture> myKeyGesture = std::make_shared<MyKeyGesture>();
850     myKeyGesture->AddHandler(1001, 500, myCallback);
851     myKeyGesture->AddHandler(1002, 1500, myCallback);
852     myKeyGesture->AddHandler(1003, 800, myCallback);
853     myKeyGesture->AddHandler(1004, 1600, myCallback);
854     ASSERT_NO_FATAL_FAILURE(myKeyGesture->ShowHandlers("TestPrefix", {1001, 1002, 1003, 1004}));
855 }
856 
857 /**
858  * @tc.name: KeyGestureManagerTest_LongPressSingleKey_ShouldIntercept
859  * @tc.desc: Test the funcation LongPressSingleKey::ShouldIntercept
860  * @tc.type: FUNC
861  * @tc.require:
862  */
863 HWTEST_F(KeyGestureManagerTest, LongPressSingleKey_ShouldIntercept, TestSize.Level1)
864 {
865     CALL_TEST_DEBUG;
866     int32_t keyCode = 1001;
867     KeyGestureManager::LongPressSingleKey longPressSingleKey(keyCode);
868     std::shared_ptr<KeyOption> keyOption = std::make_shared<KeyOption>();
869     keyOption->SetFinalKey(keyCode);
870     keyOption->SetFinalKeyDown(true);
871     keyOption->SetFinalKeyDownDuration(100);
872     EXPECT_TRUE(longPressSingleKey.ShouldIntercept(keyOption));
873 }
874 
875 /**
876  * @tc.name: KeyGestureManagerTest_LongPressSingleKey_Dump
877  * @tc.desc: Test the funcation LongPressSingleKey::Dump
878  * @tc.type: FUNC
879  * @tc.require:
880  */
881 HWTEST_F(KeyGestureManagerTest, LongPressSingleKey_Dump, TestSize.Level1)
882 {
883     CALL_TEST_DEBUG;
884     KeyGestureManager::LongPressSingleKey longPressSingleKey(1001);
885     std::ostringstream output;
886     longPressSingleKey.Dump(output);
887     EXPECT_FALSE(output.str().empty());
888 }
889 
890 /**
891  * @tc.name: LongPressCombinationKey_Intercept
892  * @tc.desc: Test the funcation LongPressCombinationKey::Intercept
893  * @tc.type: FUNC
894  * @tc.require:
895  */
896 HWTEST_F(KeyGestureManagerTest, LongPressCombinationKey_Intercept, TestSize.Level1)
897 {
898     CALL_TEST_DEBUG;
899     std::set<int32_t> keys = {KeyEvent::KEYCODE_VOLUME_DOWN, KeyEvent::KEYCODE_VOLUME_UP};
900     KeyGestureManager::LongPressCombinationKey longPressCombinationKey(keys);
901     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
902     ASSERT_NE(keyEvent, nullptr);
903     keyEvent->SetKeyCode(KeyEvent::KEYCODE_VOLUME_DOWN);
904     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
905     EXPECT_FALSE(longPressCombinationKey.Intercept(keyEvent));
906 }
907 
908 /**
909  * @tc.name: LongPressCombinationKey_Dump
910  * @tc.desc: Test the funcation LongPressCombinationKey::Dump
911  * @tc.type: FUNC
912  * @tc.require:
913  */
914 HWTEST_F(KeyGestureManagerTest, LongPressCombinationKey_Dump, TestSize.Level1)
915 {
916     CALL_TEST_DEBUG;
917     std::set<int32_t> keys = {KeyEvent::KEYCODE_VOLUME_DOWN, KeyEvent::KEYCODE_VOLUME_UP};
918     KeyGestureManager::LongPressCombinationKey longPressCombinationKey(keys);
919     std::ostringstream output;
920     longPressCombinationKey.Dump(output);
921     EXPECT_FALSE(output.str().empty());
922 }
923 
924 /**
925  * @tc.name: LongPressCombinationKey_MarkKeyConsumed
926  * @tc.desc: Test the funcation LongPressCombinationKey::MarkKeyConsumed
927  * @tc.type: FUNC
928  * @tc.require:
929  */
930 HWTEST_F(KeyGestureManagerTest, LongPressCombinationKey_MarkKeyConsumed, TestSize.Level1)
931 {
932     CALL_TEST_DEBUG;
933     KeyGestureManager::LongPressCombinationKey longPressCombinationKey({
934         KeyEvent::KEYCODE_VOLUME_DOWN, KeyEvent::KEYCODE_VOLUME_UP });
935     EXPECT_NO_FATAL_FAILURE(longPressCombinationKey.MarkKeyConsumed());
936 }
937 
938 /**
939  * @tc.name: LongPressCombinationKey_UpdateConsumed_001
940  * @tc.desc: Test the funcation LongPressCombinationKey::UpdateConsumed
941  * @tc.type: FUNC
942  * @tc.require:
943  */
944 HWTEST_F(KeyGestureManagerTest, LongPressCombinationKey_UpdateConsumed_001, TestSize.Level1)
945 {
946     CALL_TEST_DEBUG;
947     KeyGestureManager::LongPressCombinationKey longPressCombinationKey({
948         KeyEvent::KEYCODE_VOLUME_DOWN, KeyEvent::KEYCODE_VOLUME_UP });
949     longPressCombinationKey.MarkKeyConsumed();
950 
951     auto keyEvent = KeyEvent::Create();
952     ASSERT_NE(keyEvent, nullptr);
953     keyEvent->SetKeyCode(KeyEvent::KEYCODE_VOLUME_DOWN);
954     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_UP);
955     EXPECT_TRUE(longPressCombinationKey.UpdateConsumed(keyEvent));
956 }
957 
958 /**
959  * @tc.name: LongPressCombinationKey_UpdateConsumed_002
960  * @tc.desc: Test the funcation LongPressCombinationKey::UpdateConsumed
961  * @tc.type: FUNC
962  * @tc.require:
963  */
964 HWTEST_F(KeyGestureManagerTest, LongPressCombinationKey_UpdateConsumed_002, TestSize.Level1)
965 {
966     CALL_TEST_DEBUG;
967     KeyGestureManager::LongPressCombinationKey longPressCombinationKey({
968         KeyEvent::KEYCODE_VOLUME_DOWN, KeyEvent::KEYCODE_VOLUME_UP });
969     longPressCombinationKey.MarkKeyConsumed();
970 
971     auto keyEvent = KeyEvent::Create();
972     ASSERT_NE(keyEvent, nullptr);
973     keyEvent->SetKeyCode(KeyEvent::KEYCODE_VOLUME_DOWN);
974     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_CANCEL);
975     EXPECT_TRUE(longPressCombinationKey.UpdateConsumed(keyEvent));
976 }
977 
978 /**
979  * @tc.name: LongPressCombinationKey_UpdateConsumed_003
980  * @tc.desc: Test the funcation LongPressCombinationKey::UpdateConsumed
981  * @tc.type: FUNC
982  * @tc.require:
983  */
984 HWTEST_F(KeyGestureManagerTest, LongPressCombinationKey_UpdateConsumed_003, TestSize.Level1)
985 {
986     CALL_TEST_DEBUG;
987     KeyGestureManager::LongPressCombinationKey longPressCombinationKey({
988         KeyEvent::KEYCODE_VOLUME_DOWN, KeyEvent::KEYCODE_VOLUME_UP });
989     longPressCombinationKey.MarkKeyConsumed();
990 
991     auto keyEvent = KeyEvent::Create();
992     ASSERT_NE(keyEvent, nullptr);
993     keyEvent->SetKeyCode(KeyEvent::KEYCODE_VOLUME_DOWN);
994     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
995     EXPECT_FALSE(longPressCombinationKey.UpdateConsumed(keyEvent));
996 }
997 
998 /**
999  * @tc.name: LongPressCombinationKey_UpdateConsumed_004
1000  * @tc.desc: Test the funcation LongPressCombinationKey::UpdateConsumed
1001  * @tc.type: FUNC
1002  * @tc.require:
1003  */
1004 HWTEST_F(KeyGestureManagerTest, LongPressCombinationKey_UpdateConsumed_004, TestSize.Level1)
1005 {
1006     CALL_TEST_DEBUG;
1007     KeyGestureManager::LongPressCombinationKey longPressCombinationKey({
1008         KeyEvent::KEYCODE_VOLUME_DOWN, KeyEvent::KEYCODE_VOLUME_UP });
1009     longPressCombinationKey.MarkKeyConsumed();
1010 
1011     auto keyEvent = KeyEvent::Create();
1012     ASSERT_NE(keyEvent, nullptr);
1013     keyEvent->SetKeyCode(KeyEvent::KEYCODE_POWER);
1014     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_UP);
1015     EXPECT_FALSE(longPressCombinationKey.UpdateConsumed(keyEvent));
1016 }
1017 
1018 /**
1019  * @tc.name: LongPressCombinationKey_UpdateConsumed_005
1020  * @tc.desc: Test the funcation LongPressCombinationKey::UpdateConsumed
1021  * @tc.type: FUNC
1022  * @tc.require:
1023  */
1024 HWTEST_F(KeyGestureManagerTest, LongPressCombinationKey_UpdateConsumed_005, TestSize.Level1)
1025 {
1026     CALL_TEST_DEBUG;
1027     KeyGestureManager::LongPressCombinationKey longPressCombinationKey({
1028         KeyEvent::KEYCODE_VOLUME_DOWN, KeyEvent::KEYCODE_VOLUME_UP });
1029 
1030     auto keyEvent = KeyEvent::Create();
1031     ASSERT_NE(keyEvent, nullptr);
1032     keyEvent->SetKeyCode(KeyEvent::KEYCODE_VOLUME_DOWN);
1033     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_UP);
1034     EXPECT_FALSE(longPressCombinationKey.UpdateConsumed(keyEvent));
1035 }
1036 
1037 /**
1038  * @tc.name: LongPressCombinationKey_RecognizeGesture
1039  * @tc.desc: Test the funcation LongPressCombinationKey::RecognizeGesture
1040  * @tc.type: FUNC
1041  * @tc.require:
1042  */
1043 HWTEST_F(KeyGestureManagerTest, LongPressCombinationKey_RecognizeGesture, TestSize.Level1)
1044 {
1045     CALL_TEST_DEBUG;
1046     std::set<int32_t> keys = {KeyEvent::KEYCODE_VOLUME_DOWN, KeyEvent::KEYCODE_VOLUME_UP};
1047     KeyGestureManager::LongPressCombinationKey longPressCombinationKey(keys);
1048     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1049     ASSERT_NE(keyEvent, nullptr);
1050     keyEvent->SetKeyCode(KeyEvent::KEYCODE_VOLUME_DOWN);
1051     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
1052     EXPECT_FALSE(longPressCombinationKey.RecognizeGesture(keyEvent));
1053 }
1054 
1055 /**
1056  * @tc.name: LongPressCombinationKey_TriggerAll
1057  * @tc.desc: Test the funcation LongPressCombinationKey::TriggerAll
1058  * @tc.type: FUNC
1059  * @tc.require:
1060  */
1061 HWTEST_F(KeyGestureManagerTest, LongPressCombinationKey_TriggerAll, TestSize.Level1)
1062 {
1063     CALL_TEST_DEBUG;
1064     std::set<int32_t> keys = {KeyEvent::KEYCODE_VOLUME_DOWN, KeyEvent::KEYCODE_VOLUME_UP};
1065     KeyGestureManager::LongPressCombinationKey longPressCombinationKey(keys);
1066     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1067     ASSERT_NE(keyEvent, nullptr);
1068     keyEvent->SetKeyCode(KeyEvent::KEYCODE_VOLUME_DOWN);
1069     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
1070     ASSERT_NO_FATAL_FAILURE(longPressCombinationKey.TriggerAll(keyEvent));
1071 }
1072 
1073 /**
1074  * @tc.name: PullUpAccessibility_AddHandler
1075  * @tc.desc: Test the funcation PullUpAccessibility::AddHandler
1076  * @tc.type: FUNC
1077  * @tc.require:
1078  */
1079 HWTEST_F(KeyGestureManagerTest, PullUpAccessibility_AddHandler, TestSize.Level1)
1080 {
1081     CALL_TEST_DEBUG;
1082     KeyGestureManager::PullUpAccessibility pullUpAccessibility;
1083     std::function<void(std::shared_ptr<KeyEvent>)> myCallback;
1084     int32_t id = pullUpAccessibility.AddHandler(10, 500, myCallback);
1085     EXPECT_GT(id, 0);
1086 }
1087 
1088 /**
1089  * @tc.name: PullUpAccessibility_OnTriggerAll
1090  * @tc.desc: Test the funcation PullUpAccessibility::OnTriggerAll
1091  * @tc.type: FUNC
1092  * @tc.require:
1093  */
1094 HWTEST_F(KeyGestureManagerTest, PullUpAccessibility_OnTriggerAll, TestSize.Level1)
1095 {
1096     CALL_TEST_DEBUG;
1097     KeyGestureManager::PullUpAccessibility pullUpAccessibility;
1098     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1099     ASSERT_NE(keyEvent, nullptr);
1100     ASSERT_NO_FATAL_FAILURE(pullUpAccessibility.OnTriggerAll(keyEvent));
1101 }
1102 
1103 /**
1104  * @tc.name: KeyGestureManager_Dump
1105  * @tc.desc: Test the funcation KeyGestureManager::Dump
1106  * @tc.type: FUNC
1107  * @tc.require:
1108  */
1109 HWTEST_F(KeyGestureManagerTest, KeyGestureManager_Dump, TestSize.Level1)
1110 {
1111     CALL_TEST_DEBUG;
1112     KeyGestureManager keyGestureManager;
1113     ASSERT_NO_FATAL_FAILURE(keyGestureManager.Dump());
1114 }
1115 
1116 /**
1117  * @tc.name: KeyGestureManager_KeyMonitorIntercept
1118  * @tc.desc: Test the funcation KeyGestureManager::KeyMonitorIntercept
1119  * @tc.type: FUNC
1120  * @tc.require:
1121  */
1122 HWTEST_F(KeyGestureManagerTest, KeyGestureManager_KeyMonitorIntercept, TestSize.Level1)
1123 {
1124     CALL_TEST_DEBUG;
1125     KeyGestureManager keyGestureManager;
1126     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1127     ASSERT_NE(keyEvent, nullptr);
1128 
1129     keyEvent->SetKeyCode(1001);
1130     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
1131     EXPECT_FALSE(keyGestureManager.KeyMonitorIntercept(keyEvent));
1132 }
1133 } // namespace MMI
1134 } // namespace OHOS