From db39c1668c50a14bc8ef97cbca0267f7d11da85b Mon Sep 17 00:00:00 2001 From: Yunfan Chen Date: Fri, 8 Feb 2019 16:14:14 +0900 Subject: [PATCH] Fix flaky testVisibleWithInsetsProvider test The test would always fail if we wait until the handler idle. The reason is, when layoutAndAssignWindowLayersIfNeeded is called, in DisplayPolicy, the mTopFullscreenOpaqueWindowState will take the control of the insets visibility back by calling onControlChanged. At that time, the visibility will get back to true, no matter what happened before. Mock the DC and let the function do nothing would help the test to be a unit test and all the test will be no longer flaky. Test: atest WindowStateTests Bug: 74078662 Bug: 69229402 Change-Id: I91255e2e7d5c8f2dcdf3faf72aa87c4df77a94ec --- .../com/android/server/wm/WindowStateTests.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/services/tests/wmtests/src/com/android/server/wm/WindowStateTests.java b/services/tests/wmtests/src/com/android/server/wm/WindowStateTests.java index 8876214b9636b..3eb9085b68f69 100644 --- a/services/tests/wmtests/src/com/android/server/wm/WindowStateTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/WindowStateTests.java @@ -39,6 +39,7 @@ import static com.android.dx.mockito.inline.extended.ExtendedMockito.mock; import static com.android.dx.mockito.inline.extended.ExtendedMockito.never; import static com.android.dx.mockito.inline.extended.ExtendedMockito.reset; import static com.android.dx.mockito.inline.extended.ExtendedMockito.spy; +import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn; import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify; import static org.hamcrest.Matchers.is; @@ -53,6 +54,7 @@ import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doNothing; import android.graphics.Insets; import android.graphics.Matrix; @@ -65,11 +67,13 @@ import android.view.SurfaceControl; import android.view.ViewRootImpl; import android.view.WindowManager; +import androidx.test.filters.FlakyTest; import androidx.test.filters.SmallTest; import com.android.server.wm.utils.WmDisplayCutout; import org.junit.AfterClass; +import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; @@ -88,6 +92,7 @@ public class WindowStateTests extends WindowTestsBase { @BeforeClass public static void setUpOnce() { + // TODO: Make use of SettingsSession when it becomes feasible for this. sPreviousNewInsetsMode = ViewRootImpl.sNewInsetsMode; // To let the insets provider control the insets visibility, the insets mode has to be // NEW_INSETS_MODE_FULL. @@ -99,6 +104,15 @@ public class WindowStateTests extends WindowTestsBase { ViewRootImpl.sNewInsetsMode = sPreviousNewInsetsMode; } + @Before + public void setUp() { + // TODO: Let the insets source with new mode keep the visibility control, and remove this + // setup code. Now mTopFullscreenOpaqueWindowState will take back the control of insets + // visibility. + spyOn(mDisplayContent); + doNothing().when(mDisplayContent).layoutAndAssignWindowLayersIfNeeded(); + } + @Test public void testIsParentWindowHidden() { final WindowState parentWindow = createWindow(null, TYPE_APPLICATION, "parentWindow"); @@ -345,6 +359,7 @@ public class WindowStateTests extends WindowTestsBase { assertFalse(app.canAffectSystemUiFlags()); } + @FlakyTest(detail = "Promote to presubmit when shown to be stable.") @Test public void testVisibleWithInsetsProvider() throws Exception { final WindowState topBar = createWindow(null, TYPE_STATUS_BAR, "topBar"); @@ -356,6 +371,7 @@ public class WindowStateTests extends WindowTestsBase { mDisplayContent.getInsetsStateController().onBarControllingWindowChanged(app); mDisplayContent.getInsetsStateController().getSourceProvider(TYPE_TOP_BAR) .onInsetsModified(app, new InsetsSource(TYPE_TOP_BAR)); + waitUntilHandlersIdle(); assertFalse(topBar.isVisible()); }