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

Commit c49c7b45 authored by Ming-Shin Lu's avatar Ming-Shin Lu
Browse files

Remove TODO in InputMethodStressTest

Since CL[1] has fixed WIC#hide(ime()) not work in onCreate,
now we can remove the comment of verifyHideBehavior back for following
test methods in ImeOpenCloseStressTest to ensure the test coverage:

- testShowHideWithInputMethodManager_onCreate
- testHideWithWindowInsetsController_onCraate_requestFocus
- testShowHideWithInputMethodManager_inSameFrame

Also, in case calling show/hide IME consecutively when in
Activity#onCreate that comes before the window focus changed and the
final IME visiblity may be affected by SOFT_INPUT_STATE_.* visiblity
flag after gaining the window focus, ensure setting
SOFT_INPUT_STATE_UNCHANGED flag in following tests:

- testHideWithWindowInsetsController_onCreate_requestFocus
- testShowHideWithInputMethodManager_onCreate

[1]: Id3aebca3348888826bc5d3c6694e94cddb80b4d4

Fix: 248456059
Test: atest InputMethodStressTest:ImeOpenCloseStressTest

Change-Id: Ib7baf28036f01201176d2a5bba4ebde319ca8f1a
parent 737c7915
Loading
Loading
Loading
Loading
+34 −8
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.inputmethod.stresstest;

import static android.view.WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED;

import static com.android.inputmethod.stresstest.ImeStressTestUtil.INPUT_METHOD_MANAGER_HIDE_ON_CREATE;
import static com.android.inputmethod.stresstest.ImeStressTestUtil.INPUT_METHOD_MANAGER_SHOW_ON_CREATE;
import static com.android.inputmethod.stresstest.ImeStressTestUtil.REQUEST_FOCUS_ON_CREATE;
@@ -209,8 +211,23 @@ public final class ImeOpenCloseStressTest {
        verifyShowBehavior(activity);
    }

    /**
     * Test IME hidden by calling show and hide IME consecutively with
     * {@link android.view.inputmethod.InputMethodManager} APIs in
     * {@link android.app.Activity#onCreate}.
     *
     * <p> Note for developers: Use {@link WindowManager.LayoutParams#SOFT_INPUT_STATE_UNCHANGED}
     * window flag to avoid some softInputMode visibility flags may take presence over
     * {@link android.view.inputmethod.InputMethodManager} APIs (e.g. use showSoftInput to show
     * IME in {@link android.app.Activity#onCreate} but being hidden by
     * {@link WindowManager.LayoutParams#SOFT_INPUT_STATE_ALWAYS_HIDDEN} window flag after the
     * activity window focused).</p>
     */
    @Test
    public void testShowHideWithInputMethodManager_onCreate() {
        if (mSoftInputFlags != SOFT_INPUT_STATE_UNCHANGED) {
            return;
        }
        // Show and hide with InputMethodManager at onCreate()
        Intent intent =
                createIntent(
@@ -222,10 +239,7 @@ public final class ImeOpenCloseStressTest {
                                INPUT_METHOD_MANAGER_HIDE_ON_CREATE));
        TestActivity activity = TestActivity.start(intent);

        // TODO: The Ime is expected to show first and then hide. But show or hide
        // with InputMethodManager at onCreate() would always fail because the window
        // has not gained focus, so the actual behavior will be the same as auto-show.
        // verifyHideBehavior(activity);
        verifyHideBehavior(activity);
    }

    @Test
@@ -352,8 +366,7 @@ public final class ImeOpenCloseStressTest {
        // Wait until IMMS / IMS handles messages.
        SystemClock.sleep(1000);
        mInstrumentation.waitForIdleSync();
        // TODO(b/248456059): Ime should be hidden but is shown.
        // verifyHideBehavior(activity);
        verifyHideBehavior(activity);

        mInstrumentation.runOnMainSync(activity::showImeWithWindowInsetsController);
        verifyShowBehavior(activity);
@@ -420,11 +433,25 @@ public final class ImeOpenCloseStressTest {
        verifyShowBehaviorNotRequestFocus(activity);
    }

    /**
     * Test IME hidden by calling show and hide IME consecutively with
     * {@link android.view.WindowInsetsController} APIs in {@link android.app.Activity#onCreate}.
     *
     * <p> Note for developers: Use {@link WindowManager.LayoutParams#SOFT_INPUT_STATE_UNCHANGED}
     * window flag to avoid some softInputMode visibility flags may take presence over
     * {@link android.view.WindowInsetsController} APIs (e.g. use showSoftInput to show
     * IME in {@link android.app.Activity#onCreate} but being hidden by
     * {@link WindowManager.LayoutParams#SOFT_INPUT_STATE_ALWAYS_HIDDEN} window flag after the
     * activity window focused).</p>
     */
    @Test
    public void testHideWithWindowInsetsController_onCreate_requestFocus() {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
            return;
        }
        if (mSoftInputFlags != SOFT_INPUT_STATE_UNCHANGED) {
            return;
        }
        // Show and hide with InputMethodManager at onCreate()
        Intent intent =
                createIntent(
@@ -436,8 +463,7 @@ public final class ImeOpenCloseStressTest {
                                WINDOW_INSETS_CONTROLLER_HIDE_ON_CREATE));
        TestActivity activity = TestActivity.start(intent);

        // TODO(b/248456059): Ime should be hidden but is shown.
        //verifyHideBehavior(activity);
        verifyHideBehavior(activity);
    }

    @Test