@@ -365,8 +365,8 @@ class FakeApplicationHandle : public InputApplicationHandle {
365365
366366class FakeInputReceiver {
367367public:
368- void consumeEvent (int32_t expectedEventType, int32_t expectedDisplayId,
369- int32_t expectedFlags = 0 ) {
368+ void consumeEvent (int32_t expectedEventType, int32_t expectedAction, int32_t expectedDisplayId,
369+ int32_t expectedFlags ) {
370370 uint32_t consumeSeq;
371371 InputEvent* event;
372372 status_t status = mConsumer ->consume (&mEventFactory , false /* consumeBatches*/ , -1 ,
@@ -379,33 +379,41 @@ class FakeInputReceiver {
379379 ASSERT_EQ (expectedEventType, event->getType ())
380380 << mName .c_str () << " : event type should match." ;
381381
382- ASSERT_EQ (expectedDisplayId, event->getDisplayId ())
383- << mName .c_str () << " : event displayId should be the same as expected." ;
382+ EXPECT_EQ (expectedDisplayId, event->getDisplayId ());
384383
385- int32_t flags;
386384 switch (expectedEventType) {
387385 case AINPUT_EVENT_TYPE_KEY: {
388- KeyEvent* typedEvent = static_cast <KeyEvent*>(event);
389- flags = typedEvent->getFlags ();
386+ const KeyEvent& keyEvent = static_cast <const KeyEvent&>(*event);
387+ EXPECT_EQ (expectedAction, keyEvent.getAction ());
388+ EXPECT_EQ (expectedFlags, keyEvent.getFlags ());
390389 break ;
391390 }
392391 case AINPUT_EVENT_TYPE_MOTION: {
393- MotionEvent* typedEvent = static_cast <MotionEvent*>(event);
394- flags = typedEvent->getFlags ();
392+ const MotionEvent& motionEvent = static_cast <const MotionEvent&>(*event);
393+ EXPECT_EQ (expectedAction, motionEvent.getAction ());
394+ EXPECT_EQ (expectedFlags, motionEvent.getFlags ());
395395 break ;
396396 }
397397 default : {
398398 FAIL () << mName .c_str () << " : invalid event type: " << expectedEventType;
399399 }
400400 }
401- ASSERT_EQ (expectedFlags, flags)
402- << mName .c_str () << " : event flags should be the same as expected." ;
403401
404402 status = mConsumer ->sendFinishedSignal (consumeSeq, handled ());
405403 ASSERT_EQ (OK, status)
406404 << mName .c_str () << " : consumer sendFinishedSignal should return OK." ;
407405 }
408406
407+ void consumeKeyDown (int32_t expectedDisplayId, int32_t expectedFlags = 0 ) {
408+ consumeEvent (AINPUT_EVENT_TYPE_KEY, AKEY_EVENT_ACTION_DOWN, expectedDisplayId,
409+ expectedFlags);
410+ }
411+
412+ void consumeMotionDown (int32_t expectedDisplayId, int32_t expectedFlags = 0 ) {
413+ consumeEvent (AINPUT_EVENT_TYPE_MOTION, AMOTION_EVENT_ACTION_DOWN, expectedDisplayId,
414+ expectedFlags);
415+ }
416+
409417 void assertNoEvents () {
410418 uint32_t consumeSeq;
411419 InputEvent* event;
@@ -611,7 +619,7 @@ TEST_F(InputDispatcherTest, SetInputWindow_SingleWindowTouch) {
611619 << " Inject motion event should return INPUT_EVENT_INJECTION_SUCCEEDED" ;
612620
613621 // Window should receive motion event.
614- window->consumeEvent (AINPUT_EVENT_TYPE_MOTION, ADISPLAY_ID_DEFAULT);
622+ window->consumeMotionDown ( ADISPLAY_ID_DEFAULT);
615623}
616624
617625// The foreground window should receive the first touch down event.
@@ -632,7 +640,7 @@ TEST_F(InputDispatcherTest, SetInputWindow_MultiWindowsTouch) {
632640 << " Inject motion event should return INPUT_EVENT_INJECTION_SUCCEEDED" ;
633641
634642 // Top window should receive the touch down event. Second window should not receive anything.
635- windowTop->consumeEvent (AINPUT_EVENT_TYPE_MOTION, ADISPLAY_ID_DEFAULT);
643+ windowTop->consumeMotionDown ( ADISPLAY_ID_DEFAULT);
636644 windowSecond->assertNoEvents ();
637645}
638646
@@ -658,7 +666,7 @@ TEST_F(InputDispatcherTest, SetInputWindow_FocusedWindow) {
658666
659667 // Focused window should receive event.
660668 windowTop->assertNoEvents ();
661- windowSecond->consumeEvent (AINPUT_EVENT_TYPE_KEY, ADISPLAY_ID_NONE);
669+ windowSecond->consumeKeyDown ( ADISPLAY_ID_NONE);
662670}
663671
664672TEST_F (InputDispatcherTest, SetInputWindow_FocusPriority) {
@@ -683,7 +691,7 @@ TEST_F(InputDispatcherTest, SetInputWindow_FocusPriority) {
683691 << " Inject key event should return INPUT_EVENT_INJECTION_SUCCEEDED" ;
684692
685693 // Top focused window should receive event.
686- windowTop->consumeEvent (AINPUT_EVENT_TYPE_KEY, ADISPLAY_ID_NONE);
694+ windowTop->consumeKeyDown ( ADISPLAY_ID_NONE);
687695 windowSecond->assertNoEvents ();
688696}
689697
@@ -713,7 +721,7 @@ TEST_F(InputDispatcherTest, SetInputWindow_InputWindowInfo) {
713721
714722 // Top window is invalid, so it should not receive any input event.
715723 windowTop->assertNoEvents ();
716- windowSecond->consumeEvent (AINPUT_EVENT_TYPE_KEY, ADISPLAY_ID_NONE);
724+ windowSecond->consumeKeyDown ( ADISPLAY_ID_NONE);
717725}
718726
719727TEST_F (InputDispatcherTest, DispatchMouseEventsUnderCursor) {
@@ -738,7 +746,7 @@ TEST_F(InputDispatcherTest, DispatchMouseEventsUnderCursor) {
738746 ASSERT_EQ (INPUT_EVENT_INJECTION_SUCCEEDED,
739747 injectMotionEvent (mDispatcher , AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_MOUSE,
740748 ADISPLAY_ID_DEFAULT, 610 , 400 , 599 , 400 ));
741- windowLeft->consumeEvent (AINPUT_EVENT_TYPE_MOTION, ADISPLAY_ID_DEFAULT);
749+ windowLeft->consumeMotionDown ( ADISPLAY_ID_DEFAULT);
742750 windowRight->assertNoEvents ();
743751}
744752
@@ -794,37 +802,37 @@ TEST_F(InputDispatcherFocusOnTwoDisplaysTest, SetInputWindow_MultiDisplayTouch)
794802 ASSERT_EQ (INPUT_EVENT_INJECTION_SUCCEEDED, injectMotionDown (mDispatcher ,
795803 AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT))
796804 << " Inject motion event should return INPUT_EVENT_INJECTION_SUCCEEDED" ;
797- windowInPrimary->consumeEvent (AINPUT_EVENT_TYPE_MOTION, ADISPLAY_ID_DEFAULT);
805+ windowInPrimary->consumeMotionDown ( ADISPLAY_ID_DEFAULT);
798806 windowInSecondary->assertNoEvents ();
799807
800808 // Test touch down on second display.
801809 ASSERT_EQ (INPUT_EVENT_INJECTION_SUCCEEDED, injectMotionDown (mDispatcher ,
802810 AINPUT_SOURCE_TOUCHSCREEN, SECOND_DISPLAY_ID))
803811 << " Inject motion event should return INPUT_EVENT_INJECTION_SUCCEEDED" ;
804812 windowInPrimary->assertNoEvents ();
805- windowInSecondary->consumeEvent (AINPUT_EVENT_TYPE_MOTION, SECOND_DISPLAY_ID);
813+ windowInSecondary->consumeMotionDown ( SECOND_DISPLAY_ID);
806814}
807815
808816TEST_F (InputDispatcherFocusOnTwoDisplaysTest, SetInputWindow_MultiDisplayFocus) {
809817 // Test inject a key down with display id specified.
810818 ASSERT_EQ (INPUT_EVENT_INJECTION_SUCCEEDED, injectKeyDown (mDispatcher , ADISPLAY_ID_DEFAULT))
811819 << " Inject key event should return INPUT_EVENT_INJECTION_SUCCEEDED" ;
812- windowInPrimary->consumeEvent (AINPUT_EVENT_TYPE_KEY, ADISPLAY_ID_DEFAULT);
820+ windowInPrimary->consumeKeyDown ( ADISPLAY_ID_DEFAULT);
813821 windowInSecondary->assertNoEvents ();
814822
815823 // Test inject a key down without display id specified.
816824 ASSERT_EQ (INPUT_EVENT_INJECTION_SUCCEEDED, injectKeyDown (mDispatcher ))
817825 << " Inject key event should return INPUT_EVENT_INJECTION_SUCCEEDED" ;
818826 windowInPrimary->assertNoEvents ();
819- windowInSecondary->consumeEvent (AINPUT_EVENT_TYPE_KEY, ADISPLAY_ID_NONE);
827+ windowInSecondary->consumeKeyDown ( ADISPLAY_ID_NONE);
820828
821829 // Remove secondary display.
822830 std::vector<sp<InputWindowHandle>> noWindows;
823831 mDispatcher ->setInputWindows (noWindows, SECOND_DISPLAY_ID);
824832
825833 // Expect old focus should receive a cancel event.
826- windowInSecondary->consumeEvent (AINPUT_EVENT_TYPE_KEY, ADISPLAY_ID_NONE,
827- AKEY_EVENT_FLAG_CANCELED);
834+ windowInSecondary->consumeEvent (AINPUT_EVENT_TYPE_KEY, AKEY_EVENT_ACTION_UP, ADISPLAY_ID_NONE,
835+ AKEY_EVENT_FLAG_CANCELED);
828836
829837 // Test inject a key down, should timeout because of no target window.
830838 ASSERT_EQ (INPUT_EVENT_INJECTION_TIMED_OUT, injectKeyDown (mDispatcher ))
@@ -853,8 +861,8 @@ TEST_F(InputDispatcherFocusOnTwoDisplaysTest, MonitorMotionEvent_MultiDisplay) {
853861 ASSERT_EQ (INPUT_EVENT_INJECTION_SUCCEEDED, injectMotionDown (mDispatcher ,
854862 AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT))
855863 << " Inject motion event should return INPUT_EVENT_INJECTION_SUCCEEDED" ;
856- windowInPrimary->consumeEvent (AINPUT_EVENT_TYPE_MOTION, ADISPLAY_ID_DEFAULT);
857- monitorInPrimary->consumeEvent (AINPUT_EVENT_TYPE_MOTION, ADISPLAY_ID_DEFAULT);
864+ windowInPrimary->consumeMotionDown ( ADISPLAY_ID_DEFAULT);
865+ monitorInPrimary->consumeMotionDown ( ADISPLAY_ID_DEFAULT);
858866 windowInSecondary->assertNoEvents ();
859867 monitorInSecondary->assertNoEvents ();
860868
@@ -864,8 +872,8 @@ TEST_F(InputDispatcherFocusOnTwoDisplaysTest, MonitorMotionEvent_MultiDisplay) {
864872 << " Inject motion event should return INPUT_EVENT_INJECTION_SUCCEEDED" ;
865873 windowInPrimary->assertNoEvents ();
866874 monitorInPrimary->assertNoEvents ();
867- windowInSecondary->consumeEvent (AINPUT_EVENT_TYPE_MOTION, SECOND_DISPLAY_ID);
868- monitorInSecondary->consumeEvent (AINPUT_EVENT_TYPE_MOTION, SECOND_DISPLAY_ID);
875+ windowInSecondary->consumeMotionDown ( SECOND_DISPLAY_ID);
876+ monitorInSecondary->consumeMotionDown ( SECOND_DISPLAY_ID);
869877
870878 // Test inject a non-pointer motion event.
871879 // If specific a display, it will dispatch to the focused window of particular display,
@@ -875,8 +883,8 @@ TEST_F(InputDispatcherFocusOnTwoDisplaysTest, MonitorMotionEvent_MultiDisplay) {
875883 << " Inject motion event should return INPUT_EVENT_INJECTION_SUCCEEDED" ;
876884 windowInPrimary->assertNoEvents ();
877885 monitorInPrimary->assertNoEvents ();
878- windowInSecondary->consumeEvent (AINPUT_EVENT_TYPE_MOTION, ADISPLAY_ID_NONE);
879- monitorInSecondary->consumeEvent (AINPUT_EVENT_TYPE_MOTION, ADISPLAY_ID_NONE);
886+ windowInSecondary->consumeMotionDown ( ADISPLAY_ID_NONE);
887+ monitorInSecondary->consumeMotionDown ( ADISPLAY_ID_NONE);
880888}
881889
882890// Test per-display input monitors for key event.
@@ -892,8 +900,8 @@ TEST_F(InputDispatcherFocusOnTwoDisplaysTest, MonitorKeyEvent_MultiDisplay) {
892900 << " Inject key event should return INPUT_EVENT_INJECTION_SUCCEEDED" ;
893901 windowInPrimary->assertNoEvents ();
894902 monitorInPrimary->assertNoEvents ();
895- windowInSecondary->consumeEvent (AINPUT_EVENT_TYPE_KEY, ADISPLAY_ID_NONE);
896- monitorInSecondary->consumeEvent (AINPUT_EVENT_TYPE_KEY, ADISPLAY_ID_NONE);
903+ windowInSecondary->consumeKeyDown ( ADISPLAY_ID_NONE);
904+ monitorInSecondary->consumeKeyDown ( ADISPLAY_ID_NONE);
897905}
898906
899907class InputFilterTest : public InputDispatcherTest {
0 commit comments