diff options
| author | 2023-06-09 13:23:53 -0700 | |
|---|---|---|
| committer | 2023-06-13 20:57:37 +0000 | |
| commit | f54d2ab0f37699ac44324cbae475be1c5289dc71 (patch) | |
| tree | a8656efb62c624b7bad0a7defe16ba384b1bb2c9 | |
| parent | 21b3d3f3d949f5080f213b45b435c31cabbbe73b (diff) | |
Deflake InterceptKeyIfKeyUp
The test checks that the keys with ACTION_UP are delivered immediately.
Therefore, the injection of ACTION_DOWN key should be done before we set
the intercept timeout.
Bug: 282837934
Test: m inputflinger_tests && $ANDROID_HOST_OUT/nativetest64/inputflinger_tests/inputflinger_tests --gtest_filter="*InterceptKeyIfKeyUp*" --gtest_repeat=100000 --gtest_break_on_failure
Change-Id: I93f34d578eacb93cfd8f9794a6f0af6e601d7956
| -rw-r--r-- | services/inputflinger/tests/InputDispatcher_test.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/services/inputflinger/tests/InputDispatcher_test.cpp b/services/inputflinger/tests/InputDispatcher_test.cpp index 8b74b2524d..8a49ba1542 100644 --- a/services/inputflinger/tests/InputDispatcher_test.cpp +++ b/services/inputflinger/tests/InputDispatcher_test.cpp @@ -3644,6 +3644,9 @@ TEST_F(InputDispatcherTest, InterceptKeyByPolicy) { std::chrono::nanoseconds(interceptKeyTimeout).count()); } +/** + * Keys with ACTION_UP are delivered immediately, even if a long 'intercept key timeout' is set. + */ TEST_F(InputDispatcherTest, InterceptKeyIfKeyUp) { std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, @@ -3655,12 +3658,14 @@ TEST_F(InputDispatcherTest, InterceptKeyIfKeyUp) { window->consumeFocusEvent(true); - mFakePolicy->setInterceptKeyTimeout(150ms); mDispatcher->notifyKey(generateKeyArgs(AKEY_EVENT_ACTION_DOWN, ADISPLAY_ID_DEFAULT)); - mDispatcher->notifyKey(generateKeyArgs(AKEY_EVENT_ACTION_UP, ADISPLAY_ID_DEFAULT)); + window->consumeKeyDown(ADISPLAY_ID_DEFAULT); + // Set a value that's significantly larger than the default consumption timeout. If the + // implementation is correct, the actual value doesn't matter; it won't slow down the test. + mFakePolicy->setInterceptKeyTimeout(600ms); + mDispatcher->notifyKey(generateKeyArgs(AKEY_EVENT_ACTION_UP, ADISPLAY_ID_DEFAULT)); // Window should receive key event immediately when same key up. - window->consumeKeyDown(ADISPLAY_ID_DEFAULT); window->consumeKeyUp(ADISPLAY_ID_DEFAULT); } |