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

Commit 37efb549 authored by Cosmin Băieș's avatar Cosmin Băieș
Browse files

Wait for IME hide in verifyFullscreenMode

The testFullScreenMode has one scenario for each of natural orientaiton,
left orientation and right orientation. Each of these triggers an IME
show, waits for it to complete, and then presses the back key to hide
the IME, however without waiting for this to take effect.

We use the same countDownLatch to verify either IME show, IME hide or
IME rotation change. When going from left to right orientation, we don't
expect a rotation change. However, the hide request from the left
orientation is still ongoing when moving to right orientation, and will
trigger the countDownLatch, failing the test.

This fixes the test by waiting for the IME visibility to change at the
end of each scenario.

Additionally, this removes the dependency of finding and clicking on the
EditText, and pressing the back key, by using the insets APIs to show
and hide the IME, reducing the test time. To make this work we have to
get the newly created Activity after the configuration change took
effect.

Flag: EXEMPT testfix
Bug: 393025053
Test: atest InputMethodService#testFullScreenMode
Change-Id: I3bfb84e37e198ff89fd9e7e36a2e2236c5571b36
parent 2025a585
Loading
Loading
Loading
Loading
+29 −26
Original line number Diff line number Diff line
@@ -992,35 +992,26 @@ public class InputMethodServiceTest {
     * @param expected whether the runnable is expected to trigger the signal.
     * @param orientationPortrait whether the orientation is expected to be portrait.
     */
    private void verifyFullscreenMode(
            Runnable runnable, boolean expected, boolean orientationPortrait)
            throws InterruptedException {
        CountDownLatch signal = new CountDownLatch(1);
        mInputMethodService.setCountDownLatchForTesting(signal);

        // Runnable to trigger onConfigurationChanged()
        try {
            runnable.run();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        // Waits for onConfigurationChanged() to finish.
        mInstrumentation.waitForIdleSync();
        boolean completed = signal.await(TIMEOUT_IN_SECONDS, TimeUnit.SECONDS);
        if (expected && !completed) {
            fail("Timed out waiting for onConfigurationChanged()");
        } else if (!expected && completed) {
            fail("Unexpected call onConfigurationChanged()");
    private void verifyFullscreenMode(@NonNull Runnable runnable, boolean expected,
            boolean orientationPortrait) throws InterruptedException {
        verifyInputViewStatus(runnable, expected, false /* inputViewStarted */);
        if (expected) {
            // Wait for the TestActivity to be recreated.
            eventually(() ->
                    assertThat(TestActivity.getLastCreatedInstance()).isNotEqualTo(mActivity));
            // Get the new TestActivity.
            mActivity = TestActivity.getLastCreatedInstance();
        }

        clickOnEditorText();
        eventually(() -> assertThat(mInputMethodService.isInputViewShown()).isTrue());
        verifyInputViewStatusOnMainSync(
                () -> mActivity.showImeWithWindowInsetsController(),
                true /* expected */,
                true /* inputViewStarted */);
        assertThat(mInputMethodService.isInputViewShown()).isTrue();

        assertThat(mInputMethodService.getResources().getConfiguration().orientation)
                .isEqualTo(
                        orientationPortrait
                                ? Configuration.ORIENTATION_PORTRAIT
                                : Configuration.ORIENTATION_LANDSCAPE);
                .isEqualTo(orientationPortrait
                        ? Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE);
        EditorInfo editorInfo = mInputMethodService.getCurrentInputEditorInfo();
        assertThat(editorInfo.imeOptions & EditorInfo.IME_FLAG_NO_FULLSCREEN).isEqualTo(0);
        assertThat(editorInfo.internalImeOptions & EditorInfo.IME_INTERNAL_FLAG_APP_WINDOW_PORTRAIT)
@@ -1029,7 +1020,19 @@ public class InputMethodServiceTest {
        assertThat(mInputMethodService.onEvaluateFullscreenMode()).isEqualTo(!orientationPortrait);
        assertThat(mInputMethodService.isFullscreenMode()).isEqualTo(!orientationPortrait);

        mUiDevice.pressBack();
        // Hide IME before finishing the run.
        verifyInputViewStatusOnMainSync(
                () -> mActivity.hideImeWithWindowInsetsController(),
                true /* expected */,
                false /* inputViewStarted */);

        if (mFlagsValueProvider.getBoolean(Flags.FLAG_REFACTOR_INSETS_CONTROLLER)) {
            // The IME visibility is only sent at the end of the animation. Therefore, we have to
            // wait until the visibility was sent to the server and the IME window hidden.
            eventually(() -> assertThat(mInputMethodService.isInputViewShown()).isFalse());
        } else {
            assertThat(mInputMethodService.isInputViewShown()).isFalse();
        }
    }

    private void prepareIme() throws Exception {