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

Commit c4f6b122 authored by Tiger Huang's avatar Tiger Huang
Browse files

Fix DisplayPolicyLayoutTests

WindowTestsBase.createWindow() would not only create a WindowState
object, but would also create its parents and add it to the scene
graph. When WindowTestsBase is creating the StackWindowController, it
will invoke controller.onOverrideConfigurationChanged() which
eventually requests a traversal to layout all the windows. The layout
caused by the traversal has chances to impact the test.

DisplayPolicyLayoutTests uses its own display frame to perform the
layout. The width and height are arbitrary which may not be the same
as the width and height of the mDisplayContent in the scene graph.
So if the layout is performed by the mDisplayContent (instead of
DisplayPolicyLayoutTests), the window frames will be different.

With this change, we use the mGlobalLock to protect our tests. It
ensures that no one would modify the window frames computed by
layoutWindowLw() when we are testing them.

Bug: 120075361
Test: atest DisplayPolicyInsetsTests \
            DisplayPolicyLayoutTests \
            DisplayPolicyTests
Change-Id: I11420d3ddfc1d0610d000919574ad5bfba27345a
parent ff9d6ab6
Loading
Loading
Loading
Loading
+254 −222
Original line number Diff line number Diff line
@@ -94,8 +94,18 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase {
        mFrames = new DisplayFrames(mDisplayContent.getDisplayId(), info.first, info.second);
    }

    @Test
    public void addingWindow_doesNotTamperWithSysuiFlags() {
        mWindow.mAttrs.flags |= FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
        addWindow(mWindow);

        assertEquals(0, mWindow.mAttrs.systemUiVisibility);
        assertEquals(0, mWindow.mAttrs.subtreeSystemUiVisibility);
    }

    @Test
    public void layoutWindowLw_appDrawsBars() {
        synchronized (mWm.mGlobalLock) {
            mWindow.mAttrs.flags |= FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
            addWindow(mWindow);

@@ -108,9 +118,11 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase {
            assertInsetByTopBottom(mWindow.getDecorFrame(), 0, 0);
            assertInsetBy(mWindow.getDisplayFrameLw(), 0, 0, 0, 0);
        }
    }

    @Test
    public void layoutWindowLw_appWontDrawBars() {
        synchronized (mWm.mGlobalLock) {
            mWindow.mAttrs.flags &= ~FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
            addWindow(mWindow);

@@ -123,9 +135,11 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase {
            assertInsetByTopBottom(mWindow.getDecorFrame(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
            assertInsetByTopBottom(mWindow.getDisplayFrameLw(), 0, NAV_BAR_HEIGHT);
        }
    }

    @Test
    public void layoutWindowLw_appWontDrawBars_forceStatus() throws Exception {
        synchronized (mWm.mGlobalLock) {
            mWindow.mAttrs.flags &= ~FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
            mWindow.mAttrs.privateFlags |= PRIVATE_FLAG_FORCE_DRAW_STATUS_BAR_BACKGROUND;
            addWindow(mWindow);
@@ -139,18 +153,11 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase {
            assertInsetByTopBottom(mWindow.getDecorFrame(), 0, NAV_BAR_HEIGHT);
            assertInsetByTopBottom(mWindow.getDisplayFrameLw(), 0, NAV_BAR_HEIGHT);
        }

    @Test
    public void addingWindow_doesNotTamperWithSysuiFlags() {
        mWindow.mAttrs.flags |= FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
        addWindow(mWindow);

        assertEquals(0, mWindow.mAttrs.systemUiVisibility);
        assertEquals(0, mWindow.mAttrs.subtreeSystemUiVisibility);
    }

    @Test
    public void layoutWindowLw_withDisplayCutout() {
        synchronized (mWm.mGlobalLock) {
            addDisplayCutout();

            addWindow(mWindow);
@@ -164,9 +171,11 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase {
            assertInsetByTopBottom(mWindow.getDecorFrame(), 0, 0);
            assertInsetByTopBottom(mWindow.getDisplayFrameLw(), 0, 0);
        }
    }

    @Test
    public void layoutWindowLw_withDisplayCutout_never() {
        synchronized (mWm.mGlobalLock) {
            addDisplayCutout();

            mWindow.mAttrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER;
@@ -181,9 +190,11 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase {
            assertInsetByTopBottom(mWindow.getDecorFrame(), 0, 0);
            assertInsetByTopBottom(mWindow.getDisplayFrameLw(), STATUS_BAR_HEIGHT, 0);
        }
    }

    @Test
    public void layoutWindowLw_withDisplayCutout_layoutFullscreen() {
        synchronized (mWm.mGlobalLock) {
            addDisplayCutout();

            mWindow.mAttrs.subtreeSystemUiVisibility |= SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
@@ -198,9 +209,11 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase {
            assertInsetByTopBottom(mWindow.getDecorFrame(), 0, 0);
            assertInsetBy(mWindow.getDisplayFrameLw(), 0, 0, 0, 0);
        }
    }

    @Test
    public void layoutWindowLw_withDisplayCutout_fullscreen() {
        synchronized (mWm.mGlobalLock) {
            addDisplayCutout();

            mWindow.mAttrs.subtreeSystemUiVisibility |= SYSTEM_UI_FLAG_FULLSCREEN;
@@ -215,9 +228,11 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase {
            assertInsetByTopBottom(mWindow.getDecorFrame(), 0, 0);
            assertInsetByTopBottom(mWindow.getDisplayFrameLw(), STATUS_BAR_HEIGHT, 0);
        }
    }

    @Test
    public void layoutWindowLw_withDisplayCutout_fullscreenInCutout() {
        synchronized (mWm.mGlobalLock) {
            addDisplayCutout();

            mWindow.mAttrs.subtreeSystemUiVisibility |= SYSTEM_UI_FLAG_FULLSCREEN;
@@ -233,10 +248,12 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase {
            assertInsetByTopBottom(mWindow.getDecorFrame(), 0, 0);
            assertInsetByTopBottom(mWindow.getDisplayFrameLw(), 0, 0);
        }
    }


    @Test
    public void layoutWindowLw_withDisplayCutout_landscape() {
        synchronized (mWm.mGlobalLock) {
            addDisplayCutout();
            setRotation(ROTATION_90);
            addWindow(mWindow);
@@ -251,9 +268,11 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase {
            assertInsetBy(mWindow.getDecorFrame(), 0, 0, 0, 0);
            assertInsetBy(mWindow.getDisplayFrameLw(), DISPLAY_CUTOUT_HEIGHT, 0, 0, 0);
        }
    }

    @Test
    public void layoutWindowLw_withDisplayCutout_seascape() {
        synchronized (mWm.mGlobalLock) {
            addDisplayCutout();
            setRotation(ROTATION_270);
            addWindow(mWindow);
@@ -268,9 +287,11 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase {
            assertInsetBy(mWindow.getDecorFrame(), 0, 0, 0, 0);
            assertInsetBy(mWindow.getDisplayFrameLw(), 0, 0, DISPLAY_CUTOUT_HEIGHT, 0);
        }
    }

    @Test
    public void layoutWindowLw_withDisplayCutout_fullscreen_landscape() {
        synchronized (mWm.mGlobalLock) {
            addDisplayCutout();
            setRotation(ROTATION_90);

@@ -286,9 +307,11 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase {
                    DISPLAY_CUTOUT_HEIGHT, STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT, 0);
            assertInsetBy(mWindow.getDecorFrame(), 0, 0, 0, 0);
        }
    }

    @Test
    public void layoutWindowLw_withDisplayCutout_floatingInScreen() {
        synchronized (mWm.mGlobalLock) {
            addDisplayCutout();

            mWindow.mAttrs.flags = FLAG_LAYOUT_IN_SCREEN;
@@ -303,9 +326,11 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase {
            assertInsetByTopBottom(mWindow.getParentFrame(), 0, NAV_BAR_HEIGHT);
            assertInsetByTopBottom(mWindow.getDisplayFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
        }
    }

    @Test
    public void layoutWindowLw_withDisplayCutout_fullscreenInCutout_landscape() {
        synchronized (mWm.mGlobalLock) {
            addDisplayCutout();
            setRotation(ROTATION_90);

@@ -322,9 +347,11 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase {
                    DISPLAY_CUTOUT_HEIGHT, STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT, 0);
            assertInsetBy(mWindow.getDecorFrame(), 0, 0, 0, 0);
        }
    }

    @Test
    public void layoutHint_appWindow() {
        synchronized (mWm.mGlobalLock) {
            // Initialize DisplayFrames
            mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);

@@ -336,8 +363,8 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase {
                    new DisplayCutout.ParcelableWrapper();

            mDisplayPolicy.getLayoutHintLw(mWindow.mAttrs, null, mFrames,
                false /* floatingStack */, outFrame, outContentInsets, outStableInsets, outOutsets,
                outDisplayCutout);
                    false /* floatingStack */, outFrame, outContentInsets, outStableInsets,
                    outOutsets, outDisplayCutout);

            assertThat(outFrame, is(mFrames.mUnrestricted));
            assertThat(outContentInsets, is(new Rect(0, STATUS_BAR_HEIGHT, 0, NAV_BAR_HEIGHT)));
@@ -345,9 +372,11 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase {
            assertThat(outOutsets, is(new Rect()));
            assertThat(outDisplayCutout, is(new DisplayCutout.ParcelableWrapper()));
        }
    }

    @Test
    public void layoutHint_appWindowInTask() {
        synchronized (mWm.mGlobalLock) {
            // Initialize DisplayFrames
            mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);

@@ -361,8 +390,8 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase {
                    new DisplayCutout.ParcelableWrapper();

            mDisplayPolicy.getLayoutHintLw(mWindow.mAttrs, taskBounds, mFrames,
                false /* floatingStack */, outFrame, outContentInsets, outStableInsets, outOutsets,
                outDisplayCutout);
                    false /* floatingStack */, outFrame, outContentInsets, outStableInsets,
                    outOutsets, outDisplayCutout);

            assertThat(outFrame, is(taskBounds));
            assertThat(outContentInsets, is(new Rect()));
@@ -370,14 +399,16 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase {
            assertThat(outOutsets, is(new Rect()));
            assertThat(outDisplayCutout, is(new DisplayCutout.ParcelableWrapper()));
        }
    }

    @Test
    public void layoutHint_appWindowInTask_outsideContentFrame() {
        synchronized (mWm.mGlobalLock) {
            // Initialize DisplayFrames
            mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);

        // Task is in the nav bar area (usually does not happen, but this is similar enough to the
        // possible overlap with the IME)
            // Task is in the nav bar area (usually does not happen, but this is similar enough to
            // the possible overlap with the IME)
            final Rect taskBounds = new Rect(100, mFrames.mContent.bottom + 1,
                    200, mFrames.mContent.bottom + 10);

@@ -389,8 +420,8 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase {
                    new DisplayCutout.ParcelableWrapper();

            mDisplayPolicy.getLayoutHintLw(mWindow.mAttrs, taskBounds, mFrames,
                true /* floatingStack */, outFrame, outContentInsets, outStableInsets, outOutsets,
                outDisplayCutout);
                    true /* floatingStack */, outFrame, outContentInsets, outStableInsets,
                    outOutsets, outDisplayCutout);

            assertThat(outFrame, is(taskBounds));
            assertThat(outContentInsets, is(new Rect()));
@@ -398,6 +429,7 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase {
            assertThat(outOutsets, is(new Rect()));
            assertThat(outDisplayCutout, is(new DisplayCutout.ParcelableWrapper()));
        }
    }

    /**
     * Asserts that {@code actual} is inset by the given amounts from the full display rect.