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

Commit 8321a2a4 authored by Taran Singh's avatar Taran Singh
Browse files

Add test for ImeInsetsSourceConsumer

Add test to verify that requestedVisibleAwaitingControl starts
animation. This is followup test for comment in commit
I958fc5747382109aa2f21bc1067a28746e7242d8

Bug: 154440912
Fix: 153577930
Test: atest ImeInsetsSourceConsumerTest
Change-Id: I08db27151605ac53b0575b08343b5a75dc2e5fc2
parent ed642064
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -1002,7 +1002,8 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
        }
    }

    private void applyAnimation(@InsetsType final int types, boolean show, boolean fromIme) {
    @VisibleForTesting
    public void applyAnimation(@InsetsType final int types, boolean show, boolean fromIme) {
        if (types == 0) {
            // nothing to animate.
            return;
+30 −5
Original line number Diff line number Diff line
@@ -23,13 +23,16 @@ import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;

import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;

import android.content.Context;
import android.graphics.Insets;
import android.graphics.Point;
import android.graphics.Rect;
import android.os.Bundle;
import android.platform.test.annotations.Presubmit;
import android.view.SurfaceControl.Transaction;
import android.view.WindowManager.BadTokenException;
import android.view.WindowManager.LayoutParams;
import android.view.inputmethod.EditorInfo;
@@ -42,6 +45,8 @@ import androidx.test.runner.AndroidJUnit4;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.mockito.Spy;

import java.util.ArrayList;

@@ -52,7 +57,7 @@ public class ImeInsetsSourceConsumerTest {

    Context mContext = InstrumentationRegistry.getTargetContext();
    ImeInsetsSourceConsumer mImeConsumer;
    InsetsController mController;
    @Spy InsetsController mController;
    SurfaceControl mLeash;

    @Before
@@ -67,7 +72,7 @@ public class ImeInsetsSourceConsumerTest {
            } catch (BadTokenException e) {
                // activity isn't running, we will ignore BadTokenException.
            }
            mController = new InsetsController(viewRootImpl);
            mController = Mockito.spy(new InsetsController(viewRootImpl));
            final Rect rect = new Rect(5, 5, 5, 5);
            mController.calculateInsets(
                    false,
@@ -75,8 +80,7 @@ public class ImeInsetsSourceConsumerTest {
                    new DisplayCutout(
                            Insets.of(10, 10, 10, 10), rect, rect, rect, rect),
                    SOFT_INPUT_ADJUST_RESIZE, 0);
            mImeConsumer = new ImeInsetsSourceConsumer(
                    new InsetsState(), Transaction::new, mController);
            mImeConsumer = (ImeInsetsSourceConsumer) mController.getSourceConsumer(ITYPE_IME);
        });
    }

@@ -99,6 +103,27 @@ public class ImeInsetsSourceConsumerTest {
        });
    }

    @Test
    public void testImeRequestedVisibleAwaitingControl() {
        // Set null control and then request show.
        mController.onControlsChanged(new InsetsSourceControl[] { null });

        InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> {
            // Request IME visible before control is available.
            mImeConsumer.onWindowFocusGained();
            mImeConsumer.applyImeVisibility(true /* setVisible */);

            // set control and verify visibility is applied.
            InsetsSourceControl control = new InsetsSourceControl(ITYPE_IME, mLeash, new Point());
            mController.onControlsChanged(new InsetsSourceControl[] { control });
            // IME show animation should be triggered when control becomes available.
            verify(mController).applyAnimation(
                    eq(WindowInsets.Type.ime()), eq(true) /* show */, eq(true) /* fromIme */);
            verify(mController, never()).applyAnimation(
                    eq(WindowInsets.Type.ime()), eq(false) /* show */, eq(true) /* fromIme */);
        });
    }

    @Test
    public void testAreEditorsSimilar() {
        EditorInfo info1 = new EditorInfo();