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

Commit 56beb96e authored by Cosmin Băieș's avatar Cosmin Băieș
Browse files

Add unit tests for hiding the IME nav bar

This adds unit tests for the newly added IME captio bar insetsSource,
and for the code paths through InsetsController for showing and hiding
the IME nav bar.

Bug: 310199730
Test: atest
  FrameworksImeTests:InputMethodServiceTest#testShowHideImeNavigationBar_doesDrawImeNavBar
  FrameworksImeTests:InputMethodServiceTest#testShowHideImeNavigationBar_doesNotDrawImeNavBar
  InsetsSourceTest#testCalculateInsets_imeCaptionBar
Change-Id: I84accc9666eef2bdeaa7073acd7f364938770b65
parent 02b3211e
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -33,6 +33,8 @@ import android.view.inputmethod.InputMethod;
import android.view.inputmethod.InputMethodSession;
import android.window.WindowProviderService;

import com.android.internal.annotations.VisibleForTesting;

import java.io.FileDescriptor;
import java.io.PrintWriter;

@@ -72,8 +74,9 @@ public abstract class AbstractInputMethodService extends WindowProviderService
     *         {@code null} if {@link #onCreateInputMethodInterface()} is not yet called.
     * @hide
     */
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
    @Nullable
    protected final InputMethod getInputMethodInternal() {
    public final InputMethod getInputMethodInternal() {
        return mInputMethod;
    }

+11 −0
Original line number Diff line number Diff line
@@ -149,6 +149,7 @@ import android.window.OnBackInvokedDispatcher;
import android.window.WindowMetricsHelper;

import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.inputmethod.IInlineSuggestionsRequestCallback;
import com.android.internal.inputmethod.IInputContentUriToken;
import com.android.internal.inputmethod.IInputMethod;
@@ -3996,6 +3997,16 @@ public class InputMethodService extends AbstractInputMethodService {
        return 0;
    }

    /**
     * Returns whether the IME navigation bar is currently shown, for testing purposes.
     *
     * @hide
     */
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
    public final boolean isImeNavigationBarShownForTesting() {
        return mNavigationBarController.isShown();
    }

    /**
     * Used to inject custom {@link InputMethodServiceInternal}.
     *
+17 −0
Original line number Diff line number Diff line
@@ -77,6 +77,10 @@ final class NavigationBarController {
        default void onNavButtonFlagsChanged(@InputMethodNavButtonFlags int navButtonFlags) {
        }

        default boolean isShown() {
            return false;
        }

        default String toDebugString() {
            return "No-op implementation";
        }
@@ -117,6 +121,13 @@ final class NavigationBarController {
        mImpl.onNavButtonFlagsChanged(navButtonFlags);
    }

    /**
     * Returns whether the IME navigation bar is currently shown.
     */
    boolean isShown() {
        return mImpl.isShown();
    }

    String toDebugString() {
        return mImpl.toDebugString();
    }
@@ -560,6 +571,12 @@ final class NavigationBarController {
                    : 0;
        }

        @Override
        public boolean isShown() {
            return mNavigationBarFrame != null
                    && mNavigationBarFrame.getVisibility() == View.VISIBLE;
        }

        @Override
        public String toDebugString() {
            return "{mImeDrawsImeNavBar=" + mImeDrawsImeNavBar
+2 −1
Original line number Diff line number Diff line
@@ -49,8 +49,9 @@ public class InsetsSource implements Parcelable {

    /** The insets source ID of IME */
    public static final int ID_IME = createId(null, 0, ime());

    /** The insets source ID of the IME caption bar ("fake" IME navigation bar). */
    static final int ID_IME_CAPTION_BAR =
    public static final int ID_IME_CAPTION_BAR =
            InsetsSource.createId(null /* owner */, 1 /* index */, captionBar());

    /**
+16 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.view;

import static android.view.InsetsSource.ID_IME_CAPTION_BAR;
import static android.view.WindowInsets.Type.FIRST;
import static android.view.WindowInsets.Type.LAST;
import static android.view.WindowInsets.Type.SIZE;
@@ -52,12 +53,15 @@ public class InsetsSourceTest {

    private final InsetsSource mSource = new InsetsSource(0 /* id */, navigationBars());
    private final InsetsSource mImeSource = new InsetsSource(1 /* id */, ime());
    private final InsetsSource mImeCaptionSource = new InsetsSource(
            ID_IME_CAPTION_BAR, captionBar());
    private final InsetsSource mCaptionSource = new InsetsSource(2 /* id */, captionBar());

    @Before
    public void setUp() {
        mSource.setVisible(true);
        mImeSource.setVisible(true);
        mImeCaptionSource.setVisible(true);
        mCaptionSource.setVisible(true);
    }

@@ -109,6 +113,18 @@ public class InsetsSourceTest {
        assertEquals(Insets.of(0, 0, 0, 100), insets);
    }

    @Test
    public void testCalculateInsets_imeCaptionBar() {
        mImeCaptionSource.setFrame(new Rect(0, 400, 500, 500));
        Insets insets = mImeCaptionSource.calculateInsets(new Rect(0, 0, 500, 500), false);
        assertEquals(Insets.of(0, 0, 0, 100), insets);

        // Place caption bar at top; IME caption bar must always return bottom insets
        mImeCaptionSource.setFrame(new Rect(0, 0, 500, 100));
        insets = mImeCaptionSource.calculateInsets(new Rect(0, 0, 500, 500), false);
        assertEquals(Insets.of(0, 0, 0, 100), insets);
    }

    @Test
    public void testCalculateInsets_caption_resizing() {
        mCaptionSource.setFrame(new Rect(0, 0, 100, 100));
Loading