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

Commit c6b1386f authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Presubmit com.android.wm.shell.onehanded test flaky"

parents a40c3b30 42af4e54
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -339,8 +339,8 @@ public class OneHandedDisplayAreaOrganizer extends DisplayAreaOrganizer {
    }

    @VisibleForTesting
    Handler getUpdateHandler() {
        return mUpdateHandler;
    void setUpdateHandler(Handler updateHandler) {
        mUpdateHandler = updateHandler;
    }

    /**
+39 −55
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import static org.mockito.ArgumentMatchers.anyFloat;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@@ -45,7 +46,6 @@ import androidx.test.filters.SmallTest;
import com.android.wm.shell.common.DisplayController;

import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -60,7 +60,6 @@ public class OneHandedDisplayAreaOrganizerTest extends OneHandedTestCase {

    DisplayAreaInfo mDisplayAreaInfo;
    Display mDisplay;
    Handler mUpdateHandler;
    OneHandedDisplayAreaOrganizer mDisplayAreaOrganizer;
    OneHandedTutorialHandler mTutorialHandler;
    OneHandedAnimationController.OneHandedTransitionAnimator mFakeAnimator;
@@ -82,6 +81,9 @@ public class OneHandedDisplayAreaOrganizerTest extends OneHandedTestCase {
    @Mock
    WindowContainerTransaction mMockWindowContainerTransaction;

    Handler mSpyUpdateHandler;
    Handler.Callback mUpdateCallback = (msg) -> false;

    @Before
    public void setUp() throws Exception {
        MockitoAnnotations.initMocks(this);
@@ -110,7 +112,8 @@ public class OneHandedDisplayAreaOrganizerTest extends OneHandedTestCase {
                mMockDisplayController,
                mMockAnimationController,
                mTutorialHandler);
        mUpdateHandler = mDisplayAreaOrganizer.getUpdateHandler();
        mSpyUpdateHandler = spy(new Handler(OneHandedThread.get().getLooper(), mUpdateCallback));
        mDisplayAreaOrganizer.setUpdateHandler(mSpyUpdateHandler);
    }

    @Test
@@ -130,7 +133,6 @@ public class OneHandedDisplayAreaOrganizerTest extends OneHandedTestCase {
        assertThat(mDisplayAreaOrganizer.mDisplayAreaMap).isEmpty();
    }

    @Ignore("b/160848002")
    @Test
    public void testScheduleOffset() {
        final int xOffSet = 0;
@@ -138,200 +140,182 @@ public class OneHandedDisplayAreaOrganizerTest extends OneHandedTestCase {
        mDisplayAreaOrganizer.scheduleOffset(xOffSet, yOffSet);
        mTestableLooper.processAllMessages();

        assertThat(mUpdateHandler.hasMessages(
                OneHandedDisplayAreaOrganizer.MSG_OFFSET_ANIMATE)).isEqualTo(true);
        verify(mSpyUpdateHandler).sendMessage(any());
    }

    @Test
    public void testRotation_portrait_0_to_landscape_90() {
        when(mMockLeash.isValid()).thenReturn(false);
        // Rotate 0 -> 90
        mTestableLooper.processAllMessages();
        mDisplayAreaOrganizer.onRotateDisplay(Surface.ROTATION_0, Surface.ROTATION_90,
                mMockWindowContainerTransaction);
        mTestableLooper.processAllMessages();

        assertThat(mUpdateHandler.hasMessages(
                OneHandedDisplayAreaOrganizer.MSG_RESET_IMMEDIATE)).isEqualTo(true);
        verify(mSpyUpdateHandler).sendMessage(any());
    }

    @Test
    public void testRotation_portrait_0_to_seascape_270() {
        when(mMockLeash.isValid()).thenReturn(false);
        // Rotate 0 -> 270
        mTestableLooper.processAllMessages();
        mDisplayAreaOrganizer.onRotateDisplay(Surface.ROTATION_0, Surface.ROTATION_270,
                mMockWindowContainerTransaction);
        mTestableLooper.processAllMessages();

        assertThat(mUpdateHandler.hasMessages(
                OneHandedDisplayAreaOrganizer.MSG_RESET_IMMEDIATE)).isEqualTo(true);

        verify(mSpyUpdateHandler).sendMessage(any());
    }

    @Test
    public void testRotation_portrait_180_to_landscape_90() {
        when(mMockLeash.isValid()).thenReturn(false);
        // Rotate 180 -> 90
        mTestableLooper.processAllMessages();
        mDisplayAreaOrganizer.onRotateDisplay(Surface.ROTATION_180, Surface.ROTATION_90,
                mMockWindowContainerTransaction);
        mTestableLooper.processAllMessages();

        assertThat(mUpdateHandler.hasMessages(
                OneHandedDisplayAreaOrganizer.MSG_RESET_IMMEDIATE)).isEqualTo(true);
        verify(mSpyUpdateHandler).sendMessage(any());
    }

    @Test
    public void testRotation_portrait_180_to_seascape_270() {
        when(mMockLeash.isValid()).thenReturn(false);
        // Rotate 180 -> 270
        mTestableLooper.processAllMessages();
        mDisplayAreaOrganizer.onRotateDisplay(Surface.ROTATION_180, Surface.ROTATION_270,
                mMockWindowContainerTransaction);
        mTestableLooper.processAllMessages();

        assertThat(mUpdateHandler.hasMessages(
                OneHandedDisplayAreaOrganizer.MSG_RESET_IMMEDIATE)).isEqualTo(true);
        verify(mSpyUpdateHandler).sendMessage(any());
    }

    @Test
    public void testRotation_landscape_90_to_portrait_0() {
        when(mMockLeash.isValid()).thenReturn(false);
        // Rotate 90 -> 0
        mTestableLooper.processAllMessages();
        mDisplayAreaOrganizer.onRotateDisplay(Surface.ROTATION_90, Surface.ROTATION_0,
                mMockWindowContainerTransaction);
        mTestableLooper.processAllMessages();

        assertThat(mUpdateHandler.hasMessages(
                OneHandedDisplayAreaOrganizer.MSG_RESET_IMMEDIATE)).isEqualTo(true);
        verify(mSpyUpdateHandler).sendMessage(any());
    }

    @Test
    public void testRotation_landscape_90_to_portrait_180() {
        when(mMockLeash.isValid()).thenReturn(false);
        // Rotate 90 -> 180
        mTestableLooper.processAllMessages();
        mDisplayAreaOrganizer.onRotateDisplay(Surface.ROTATION_90, Surface.ROTATION_180,
                mMockWindowContainerTransaction);
        mTestableLooper.processAllMessages();

        assertThat(mUpdateHandler.hasMessages(
                OneHandedDisplayAreaOrganizer.MSG_RESET_IMMEDIATE)).isEqualTo(true);
        verify(mSpyUpdateHandler).sendMessage(any());
    }

    @Test
    public void testRotation_Seascape_270_to_portrait_0() {
        when(mMockLeash.isValid()).thenReturn(false);
        // Rotate 270 -> 0
        mTestableLooper.processAllMessages();
        mDisplayAreaOrganizer.onRotateDisplay(Surface.ROTATION_270, Surface.ROTATION_0,
                mMockWindowContainerTransaction);
        mTestableLooper.processAllMessages();

        assertThat(mUpdateHandler.hasMessages(
                OneHandedDisplayAreaOrganizer.MSG_RESET_IMMEDIATE)).isEqualTo(true);
        verify(mSpyUpdateHandler).sendMessage(any());
    }

    @Test
    public void testRotation_seascape_90_to_portrait_180() {
        when(mMockLeash.isValid()).thenReturn(false);
        // Rotate 270 -> 180
        mTestableLooper.processAllMessages();
        mDisplayAreaOrganizer.onRotateDisplay(Surface.ROTATION_270, Surface.ROTATION_180,
                mMockWindowContainerTransaction);
        mTestableLooper.processAllMessages();

        assertThat(mUpdateHandler.hasMessages(
                OneHandedDisplayAreaOrganizer.MSG_RESET_IMMEDIATE)).isEqualTo(true);
        verify(mSpyUpdateHandler).sendMessage(any());
    }

    @Test
    public void testRotation_portrait_0_to_portrait_0() {
        when(mMockLeash.isValid()).thenReturn(false);
        // Rotate 0 -> 0
        mTestableLooper.processAllMessages();
        mDisplayAreaOrganizer.onRotateDisplay(Surface.ROTATION_0, Surface.ROTATION_0,
                mMockWindowContainerTransaction);
        mTestableLooper.processAllMessages();

        assertThat(mUpdateHandler.hasMessages(
                OneHandedDisplayAreaOrganizer.MSG_RESET_IMMEDIATE)).isEqualTo(false);
        verify(mSpyUpdateHandler, never()).sendMessage(any());
    }

    @Test
    public void testRotation_portrait_0_to_portrait_180() {
        when(mMockLeash.isValid()).thenReturn(false);
        // Rotate 0 -> 180
        mTestableLooper.processAllMessages();
        mDisplayAreaOrganizer.onRotateDisplay(Surface.ROTATION_0, Surface.ROTATION_180,
                mMockWindowContainerTransaction);
        mTestableLooper.processAllMessages();

        assertThat(mUpdateHandler.hasMessages(
                OneHandedDisplayAreaOrganizer.MSG_RESET_IMMEDIATE)).isEqualTo(false);
        verify(mSpyUpdateHandler, never()).sendMessage(any());
    }

    @Test
    public void testRotation_portrait_180_to_portrait_180() {
        when(mMockLeash.isValid()).thenReturn(false);
        // Rotate 180 -> 180
        mTestableLooper.processAllMessages();
        mDisplayAreaOrganizer.onRotateDisplay(Surface.ROTATION_180, Surface.ROTATION_180,
                mMockWindowContainerTransaction);
        mTestableLooper.processAllMessages();

        assertThat(mUpdateHandler.hasMessages(
                OneHandedDisplayAreaOrganizer.MSG_RESET_IMMEDIATE)).isEqualTo(false);
        verify(mSpyUpdateHandler, never()).sendMessage(any());
    }

    @Test
    public void testRotation_portrait_180_to_portrait_0() {
        when(mMockLeash.isValid()).thenReturn(false);
        // Rotate 180 -> 0
        mTestableLooper.processAllMessages();
        mDisplayAreaOrganizer.onRotateDisplay(Surface.ROTATION_180, Surface.ROTATION_0,
                mMockWindowContainerTransaction);
        mTestableLooper.processAllMessages();

        assertThat(mUpdateHandler.hasMessages(
                OneHandedDisplayAreaOrganizer.MSG_RESET_IMMEDIATE)).isEqualTo(false);
        verify(mSpyUpdateHandler, never()).sendMessage(any());
    }

    @Test
    public void testRotation_landscape_90_to_landscape_90() {
        when(mMockLeash.isValid()).thenReturn(false);
        // Rotate 90 -> 90
        mTestableLooper.processAllMessages();
        mDisplayAreaOrganizer.onRotateDisplay(Surface.ROTATION_90, Surface.ROTATION_90,
                mMockWindowContainerTransaction);
        mTestableLooper.processAllMessages();

        assertThat(mUpdateHandler.hasMessages(
                OneHandedDisplayAreaOrganizer.MSG_RESET_IMMEDIATE)).isEqualTo(false);
        verify(mSpyUpdateHandler, never()).sendMessage(any());
    }

    @Test
    public void testRotation_landscape_90_to_seascape_270() {
        when(mMockLeash.isValid()).thenReturn(false);
        // Rotate 90 -> 270
        mTestableLooper.processAllMessages();
        mDisplayAreaOrganizer.onRotateDisplay(Surface.ROTATION_90, Surface.ROTATION_270,
                mMockWindowContainerTransaction);
        mTestableLooper.processAllMessages();

        assertThat(mUpdateHandler.hasMessages(
                OneHandedDisplayAreaOrganizer.MSG_RESET_IMMEDIATE)).isEqualTo(false);
        verify(mSpyUpdateHandler, never()).sendMessage(any());
    }

    @Test
    public void testRotation_seascape_270_to_seascape_270() {
        when(mMockLeash.isValid()).thenReturn(false);
        // Rotate 270 -> 270
        mTestableLooper.processAllMessages();
        mDisplayAreaOrganizer.onRotateDisplay(Surface.ROTATION_270, Surface.ROTATION_270,
                mMockWindowContainerTransaction);
        mTestableLooper.processAllMessages();

        assertThat(mUpdateHandler.hasMessages(
                OneHandedDisplayAreaOrganizer.MSG_RESET_IMMEDIATE)).isEqualTo(false);
        verify(mSpyUpdateHandler, never()).sendMessage(any());
    }

    @Test
    public void testRotation_seascape_90_to_landscape_90() {
        when(mMockLeash.isValid()).thenReturn(false);
        // Rotate 270 -> 90
        mTestableLooper.processAllMessages();
        mDisplayAreaOrganizer.onRotateDisplay(Surface.ROTATION_270, Surface.ROTATION_90,
                mMockWindowContainerTransaction);
        mTestableLooper.processAllMessages();

        assertThat(mUpdateHandler.hasMessages(
                OneHandedDisplayAreaOrganizer.MSG_RESET_IMMEDIATE)).isEqualTo(false);
        verify(mSpyUpdateHandler, never()).sendMessage(any());
    }
}