diff options
| author | 2019-01-15 11:49:27 +0900 | |
|---|---|---|
| committer | 2019-01-16 10:46:15 +0900 | |
| commit | ff6f8b8d3a9d23f73fca0539ea551b20e57a568a (patch) | |
| tree | 3ec72144c5ff6fc7a288cab725f5602e444cfb0c | |
| parent | 74fe901315d088fe393207919bf4773713ff67c9 (diff) | |
Fix harmful nesting spy on RootWindowContainer
Since ag/5842826, WindowManagerService instance under tests is a singleton
instance shared among all tests that extends WindowTestsBase class, creating
spied object on each test's @Before create chain of spied objects on
|mWm.mRoot| which may raise UnfinishedStubbingException at some points.
Bug: 122621913
Test: Pass all non-flaky presubmit tests on WM
$ atest --test-mapping frameworks/base/services/core/java/com/android/server/wm
Change-Id: I2f215a24da14d3da42358af173796f4b8153ab91
| -rw-r--r-- | services/tests/wmtests/src/com/android/server/wm/AppTransitionTests.java | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/services/tests/wmtests/src/com/android/server/wm/AppTransitionTests.java b/services/tests/wmtests/src/com/android/server/wm/AppTransitionTests.java index fa4228908cea..51bebbbcd6b0 100644 --- a/services/tests/wmtests/src/com/android/server/wm/AppTransitionTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/AppTransitionTests.java @@ -39,7 +39,9 @@ import android.view.Display; import androidx.test.filters.SmallTest; +import org.junit.AfterClass; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; /** @@ -52,15 +54,34 @@ import org.junit.Test; @Presubmit public class AppTransitionTests extends WindowTestsBase { + private static RootWindowContainer sOriginalRootWindowContainer; + private DisplayContent mDc; + @BeforeClass + public static void setUpRootWindowContainerMock() { + final WindowManagerService wm = WmServiceUtils.getWindowManagerService(); + // For unit test, we don't need to test performSurfacePlacement to prevent some abnormal + // interaction with surfaceflinger native side. + sOriginalRootWindowContainer = wm.mRoot; + // Creating spied mock of RootWindowContainer shouldn't be done in @Before, since it will + // create unnecessary nested spied objects chain, because WindowManagerService object under + // test is a single instance shared among all tests that extend WindowTestsBase class. + // Instead it should be done once before running all tests in this test class. + wm.mRoot = spy(wm.mRoot); + doNothing().when(wm.mRoot).performSurfacePlacement(anyBoolean()); + } + + @AfterClass + public static void tearDownRootWindowContainerMock() { + final WindowManagerService wm = WmServiceUtils.getWindowManagerService(); + wm.mRoot = sOriginalRootWindowContainer; + sOriginalRootWindowContainer = null; + } + @Before public void setUp() throws Exception { mDc = mWm.getDefaultDisplayContentLocked(); - // For unit test, we don't need to test performSurfacePlacement to prevent some - // abnormal interaction with surfaceflinger native side. - mWm.mRoot = spy(mWm.mRoot); - doNothing().when(mWm.mRoot).performSurfacePlacement(anyBoolean()); } @Test |