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

Commit ff6f8b8d authored by Tadashi G. Takaoka's avatar Tadashi G. Takaoka
Browse files

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
parent 74fe9013
Loading
Loading
Loading
Loading
+25 −4
Original line number Diff line number Diff line
@@ -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