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

Commit 5a06af21 authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Fix high flakiness of InsetsPolicyTest

The spy() will return a different instance. The caller who
doesn't use the instance will only update its own fields.

The test app window was default non-focusable set up by test.
So it was no problem before the change [1], that there will be
no candidate window in updateSystemBarAttributes.

Now updateSystemBarAttributes will choose the app window and
then updateBarControlTarget(). That causes abortTransient()
because focus change. And the focus change is because the
policy.updateBarControlTarget updated to a different instance
of InsetsPolicy#mFocusedWin.

[1] I957e1eddcfa3f7b873f7a9b32eeaf69db5927b00

Bug: 254268165
Test: atest InsetsPolicyTest
Change-Id: I21eb14313cc848894b6be3aafc4965a42c10ae0d
parent b29e4dc3
Loading
Loading
Loading
Loading
+12 −5
Original line number Diff line number Diff line
@@ -37,6 +37,8 @@ import static android.view.WindowManager.LayoutParams.TYPE_NOTIFICATION_SHADE;
import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR;
import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_SUB_PANEL;

import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -46,7 +48,6 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.Mockito.clearInvocations;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;

import android.app.StatusBarManager;
@@ -265,7 +266,8 @@ public class InsetsPolicyTest extends WindowTestsBase {
        final WindowState navBar = addNavigationBar();
        navBar.setHasSurface(true);
        navBar.getControllableInsetProvider().setServerVisible(true);
        final InsetsPolicy policy = spy(mDisplayContent.getInsetsPolicy());
        final InsetsPolicy policy = mDisplayContent.getInsetsPolicy();
        spyOn(policy);
        doNothing().when(policy).startAnimation(anyBoolean(), any());

        // Make both system bars invisible.
@@ -302,12 +304,15 @@ public class InsetsPolicyTest extends WindowTestsBase {
        addStatusBar().getControllableInsetProvider().getSource().setVisible(false);
        addNavigationBar().getControllableInsetProvider().setServerVisible(true);

        final InsetsPolicy policy = spy(mDisplayContent.getInsetsPolicy());
        final InsetsPolicy policy = mDisplayContent.getInsetsPolicy();
        spyOn(policy);
        doNothing().when(policy).startAnimation(anyBoolean(), any());
        policy.updateBarControlTarget(mAppWindow);
        policy.showTransient(new int[]{ITYPE_STATUS_BAR, ITYPE_NAVIGATION_BAR},
                true /* isGestureOnSystemBar */);
        waitUntilWindowAnimatorIdle();
        assertTrue(policy.isTransient(ITYPE_STATUS_BAR));
        assertFalse(policy.isTransient(ITYPE_NAVIGATION_BAR));
        final InsetsSourceControl[] controls =
                mDisplayContent.getInsetsStateController().getControlsForDispatch(mAppWindow);

@@ -335,7 +340,8 @@ public class InsetsPolicyTest extends WindowTestsBase {
        navBarSource.setVisible(false);
        mAppWindow.mAboveInsetsState.addSource(navBarSource);
        mAppWindow.mAboveInsetsState.addSource(statusBarSource);
        final InsetsPolicy policy = spy(mDisplayContent.getInsetsPolicy());
        final InsetsPolicy policy = mDisplayContent.getInsetsPolicy();
        spyOn(policy);
        doNothing().when(policy).startAnimation(anyBoolean(), any());
        policy.updateBarControlTarget(mAppWindow);
        policy.showTransient(new int[]{ITYPE_STATUS_BAR, ITYPE_NAVIGATION_BAR},
@@ -383,7 +389,8 @@ public class InsetsPolicyTest extends WindowTestsBase {
        final WindowState app = addWindow(TYPE_APPLICATION, "app");
        final WindowState app2 = addWindow(TYPE_APPLICATION, "app");

        final InsetsPolicy policy = spy(mDisplayContent.getInsetsPolicy());
        final InsetsPolicy policy = mDisplayContent.getInsetsPolicy();
        spyOn(policy);
        doNothing().when(policy).startAnimation(anyBoolean(), any());
        policy.updateBarControlTarget(app);
        policy.showTransient(new int[]{ITYPE_STATUS_BAR, ITYPE_NAVIGATION_BAR},