Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4797b930 authored by Jimmy's avatar Jimmy
Browse files

Add additional test cases for interceptKeyBeforeDispatching

Add missing test cases for when the permission and private flag
overrides are not a factor for intercepting keys before dispatching.

Bug: 384113980
Test: atest InputTests:InputManagerServiceTests
Flag: TEST_ONLY

Change-Id: Ie401dfe3e10ec71e2054cb19cd2ce2d4d913b239
parent e579b0d6
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
@@ -358,6 +358,34 @@ class InputManagerServiceTests {
        verifyNoMoreInteractions(listener)
    }

    @Test
    fun testKeyEventsForwardedToFocusedWindow_whenWmAllows() {
        service.systemRunning()
        overrideSendActionKeyEventsToFocusedWindow(
            /* hasPermission = */false,
            /* hasPrivateFlag = */false
        )
        whenever(wmCallbacks.interceptKeyBeforeDispatching(any(), any(), anyInt())).thenReturn(0)

        val event = KeyEvent( /* downTime= */0, /* eventTime= */0, KeyEvent.ACTION_DOWN,
            KeyEvent.KEYCODE_SPACE, /* repeat= */0, KeyEvent.META_CTRL_ON)
        assertEquals(0, service.interceptKeyBeforeDispatching(null, event, 0))
    }

    @Test
    fun testKeyEventsNotForwardedToFocusedWindow_whenWmConsumes() {
        service.systemRunning()
        overrideSendActionKeyEventsToFocusedWindow(
            /* hasPermission = */false,
            /* hasPrivateFlag = */false
        )
        whenever(wmCallbacks.interceptKeyBeforeDispatching(any(), any(), anyInt())).thenReturn(-1)

        val event = KeyEvent( /* downTime= */0, /* eventTime= */0, KeyEvent.ACTION_DOWN,
            KeyEvent.KEYCODE_SPACE, /* repeat= */0, KeyEvent.META_CTRL_ON)
        assertEquals(-1, service.interceptKeyBeforeDispatching(null, event, 0))
    }

    private class AutoClosingVirtualDisplays(val displays: List<VirtualDisplay>) : AutoCloseable {
        operator fun get(i: Int): VirtualDisplay = displays[i]