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

Commit acadc177 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fix harmful nesting spy on RootWindowContainer"

parents 86c7e98c ff6f8b8d
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