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

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

Remove unnecessary assert helpers from WindowTestBase

Bug: 116449554
Test: atest TaskStackContainersTests
Test: atest ZOrderingTests
Change-Id: I5baa7bf17561105ca2c724be1fee48755e0e1975
parent c8f2c148
Loading
Loading
Loading
Loading
+7 −5
Original line number Original line Diff line number Diff line
@@ -19,6 +19,8 @@ package com.android.server.wm;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD;
import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED;
import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED;


import static com.google.common.truth.Truth.assertThat;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertTrue;
@@ -68,7 +70,7 @@ public class TaskStackContainersTests extends WindowTestsBase {
    }
    }


    @Test
    @Test
    public void testStackPositionChildAt() throws Exception {
    public void testStackPositionChildAt() {
        // Test that always-on-top stack can't be moved to position other than top.
        // Test that always-on-top stack can't be moved to position other than top.
        final TaskStack stack1 = createTaskStackOnDisplay(mDisplayContent);
        final TaskStack stack1 = createTaskStackOnDisplay(mDisplayContent);
        final TaskStack stack2 = createTaskStackOnDisplay(mDisplayContent);
        final TaskStack stack2 = createTaskStackOnDisplay(mDisplayContent);
@@ -78,8 +80,8 @@ public class TaskStackContainersTests extends WindowTestsBase {
        final int stack1Pos = taskStackContainer.mChildren.indexOf(stack1);
        final int stack1Pos = taskStackContainer.mChildren.indexOf(stack1);
        final int stack2Pos = taskStackContainer.mChildren.indexOf(stack2);
        final int stack2Pos = taskStackContainer.mChildren.indexOf(stack2);
        final int pinnedStackPos = taskStackContainer.mChildren.indexOf(mPinnedStack);
        final int pinnedStackPos = taskStackContainer.mChildren.indexOf(mPinnedStack);
        assertGreaterThan(pinnedStackPos, stack2Pos);
        assertThat(pinnedStackPos).isGreaterThan(stack2Pos);
        assertGreaterThan(stack2Pos, stack1Pos);
        assertThat(stack2Pos).isGreaterThan(stack1Pos);


        taskStackContainer.positionChildAt(WindowContainer.POSITION_BOTTOM, mPinnedStack, false);
        taskStackContainer.positionChildAt(WindowContainer.POSITION_BOTTOM, mPinnedStack, false);
        assertEquals(taskStackContainer.mChildren.get(stack1Pos), stack1);
        assertEquals(taskStackContainer.mChildren.get(stack1Pos), stack1);
@@ -93,7 +95,7 @@ public class TaskStackContainersTests extends WindowTestsBase {
    }
    }


    @Test
    @Test
    public void testStackPositionBelowPinnedStack() throws Exception {
    public void testStackPositionBelowPinnedStack() {
        // Test that no stack can be above pinned stack.
        // Test that no stack can be above pinned stack.
        final TaskStack stack1 = createTaskStackOnDisplay(mDisplayContent);
        final TaskStack stack1 = createTaskStackOnDisplay(mDisplayContent);


@@ -101,7 +103,7 @@ public class TaskStackContainersTests extends WindowTestsBase {


        final int stackPos = taskStackContainer.mChildren.indexOf(stack1);
        final int stackPos = taskStackContainer.mChildren.indexOf(stack1);
        final int pinnedStackPos = taskStackContainer.mChildren.indexOf(mPinnedStack);
        final int pinnedStackPos = taskStackContainer.mChildren.indexOf(mPinnedStack);
        assertGreaterThan(pinnedStackPos, stackPos);
        assertThat(pinnedStackPos).isGreaterThan(stackPos);


        taskStackContainer.positionChildAt(WindowContainer.POSITION_TOP, stack1, false);
        taskStackContainer.positionChildAt(WindowContainer.POSITION_TOP, stack1, false);
        assertEquals(taskStackContainer.mChildren.get(stackPos), stack1);
        assertEquals(taskStackContainer.mChildren.get(stackPos), stack1);
+2 −21
Original line number Original line Diff line number Diff line
@@ -48,18 +48,17 @@ import android.view.DisplayInfo;
import android.view.IWindow;
import android.view.IWindow;
import android.view.WindowManager;
import android.view.WindowManager;


import androidx.test.InstrumentationRegistry;

import com.android.server.AttributeCache;
import com.android.server.AttributeCache;


import org.junit.After;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Rule;


import java.util.HashSet;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.LinkedList;


import androidx.test.InstrumentationRegistry;

/**
/**
 * Common base class for window manager unit test classes.
 * Common base class for window manager unit test classes.
 *
 *
@@ -194,14 +193,6 @@ class WindowTestsBase {
        }
        }
    }
    }


    /**
     * @return A SurfaceBuilderFactory to inject in to the WindowManagerService during
     *         set-up (or null).
     */
    SurfaceBuilderFactory getSurfaceBuilderFactory() {
        return null;
    }

    private WindowState createCommonWindow(WindowState parent, int type, String name) {
    private WindowState createCommonWindow(WindowState parent, int type, String name) {
        synchronized (sWm.mWindowMap) {
        synchronized (sWm.mWindowMap) {
            final WindowState win = createWindow(parent, type, name);
            final WindowState win = createWindow(parent, type, name);
@@ -212,16 +203,6 @@ class WindowTestsBase {
        }
        }
    }
    }


    /** Asserts that the first entry is greater than the second entry. */
    void assertGreaterThan(int first, int second) throws Exception {
        Assert.assertTrue("Excepted " + first + " to be greater than " + second, first > second);
    }

    /** Asserts that the first entry is greater than the second entry. */
    void assertLessThan(int first, int second) throws Exception {
        Assert.assertTrue("Excepted " + first + " to be less than " + second, first < second);
    }

    /**
    /**
     * Waits until the main handler for WM has processed all messages.
     * Waits until the main handler for WM has processed all messages.
     */
     */
+28 −30
Original line number Original line Diff line number Diff line
@@ -32,36 +32,35 @@ import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL;
import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_SUB_PANEL;
import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_SUB_PANEL;
import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY;
import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY;


import static com.google.common.truth.Truth.assertThat;

import android.platform.test.annotations.Presubmit;
import android.platform.test.annotations.Presubmit;
import android.view.SurfaceControl;
import android.view.SurfaceControl;
import android.view.SurfaceSession;
import android.view.SurfaceSession;


import androidx.test.filters.FlakyTest;
import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;

import org.junit.After;
import org.junit.After;
import org.junit.Test;
import org.junit.Test;
import org.junit.runner.RunWith;


import java.util.HashMap;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.LinkedList;


import androidx.test.filters.FlakyTest;
import androidx.test.filters.SmallTest;

/**
/**
 * Tests for the {@link WindowLayersController} class.
 * Tests for the {@link WindowLayersController} class.
 *
 *
 * Build/Install/Run:
 * Build/Install/Run:
 *  bit FrameworksServicesTests:com.android.server.wm.ZOrderingTests
 *  atest FrameworksServicesTests:com.android.server.wm.ZOrderingTests
 */
 */
@SmallTest
@SmallTest
@FlakyTest(bugId = 74078662)
@FlakyTest(bugId = 74078662)
@Presubmit
@Presubmit
@RunWith(AndroidJUnit4.class)
public class ZOrderingTests extends WindowTestsBase {
public class ZOrderingTests extends WindowTestsBase {


    private class LayerRecordingTransaction extends SurfaceControl.Transaction {
    private class LayerRecordingTransaction extends SurfaceControl.Transaction {
        HashMap<SurfaceControl, Integer> mLayersForControl = new HashMap();
        HashMap<SurfaceControl, Integer> mLayersForControl = new HashMap<>();
        HashMap<SurfaceControl, SurfaceControl> mRelativeLayersForControl = new HashMap();
        HashMap<SurfaceControl, SurfaceControl> mRelativeLayersForControl = new HashMap<>();


        @Override
        @Override
        public SurfaceControl.Transaction setLayer(SurfaceControl sc, int layer) {
        public SurfaceControl.Transaction setLayer(SurfaceControl sc, int layer) {
@@ -86,11 +85,11 @@ public class ZOrderingTests extends WindowTestsBase {
        private SurfaceControl getRelativeLayer(SurfaceControl sc) {
        private SurfaceControl getRelativeLayer(SurfaceControl sc) {
            return mRelativeLayersForControl.get(sc);
            return mRelativeLayersForControl.get(sc);
        }
        }
    };
    }


    // We have WM use our Hierarchy recording subclass of SurfaceControl.Builder
    // We have WM use our Hierarchy recording subclass of SurfaceControl.Builder
    // such that we can keep track of the parents of Surfaces as they are constructed.
    // such that we can keep track of the parents of Surfaces as they are constructed.
    private HashMap<SurfaceControl, SurfaceControl> mParentFor = new HashMap();
    private HashMap<SurfaceControl, SurfaceControl> mParentFor = new HashMap<>();


    private class HierarchyRecorder extends SurfaceControl.Builder {
    private class HierarchyRecorder extends SurfaceControl.Builder {
        SurfaceControl mPendingParent;
        SurfaceControl mPendingParent;
@@ -109,13 +108,13 @@ public class ZOrderingTests extends WindowTestsBase {
            mPendingParent = null;
            mPendingParent = null;
            return sc;
            return sc;
        }
        }
    };
    }


    class HierarchyRecordingBuilderFactory implements SurfaceBuilderFactory {
    class HierarchyRecordingBuilderFactory implements SurfaceBuilderFactory {
        public SurfaceControl.Builder make(SurfaceSession s) {
        public SurfaceControl.Builder make(SurfaceSession s) {
            return new HierarchyRecorder(s);
            return new HierarchyRecorder(s);
        }
        }
    };
    }


    private LayerRecordingTransaction mTransaction;
    private LayerRecordingTransaction mTransaction;


@@ -136,7 +135,7 @@ public class ZOrderingTests extends WindowTestsBase {
    }
    }


    LinkedList<SurfaceControl> getAncestors(LayerRecordingTransaction t, SurfaceControl sc) {
    LinkedList<SurfaceControl> getAncestors(LayerRecordingTransaction t, SurfaceControl sc) {
        LinkedList<SurfaceControl> p = new LinkedList();
        LinkedList<SurfaceControl> p = new LinkedList<>();
        SurfaceControl current = sc;
        SurfaceControl current = sc;
        do {
        do {
            p.addLast(current);
            p.addLast(current);
@@ -153,7 +152,7 @@ public class ZOrderingTests extends WindowTestsBase {




    void assertZOrderGreaterThan(LayerRecordingTransaction t, SurfaceControl left,
    void assertZOrderGreaterThan(LayerRecordingTransaction t, SurfaceControl left,
            SurfaceControl right) throws Exception {
            SurfaceControl right) {
        final LinkedList<SurfaceControl> leftParentChain = getAncestors(t, left);
        final LinkedList<SurfaceControl> leftParentChain = getAncestors(t, left);
        final LinkedList<SurfaceControl> rightParentChain = getAncestors(t, right);
        final LinkedList<SurfaceControl> rightParentChain = getAncestors(t, right);


@@ -168,16 +167,15 @@ public class ZOrderingTests extends WindowTestsBase {
        }
        }


        if (rightTop == null) { // right is the parent of left.
        if (rightTop == null) { // right is the parent of left.
            assertGreaterThan(t.getLayer(leftTop), 0);
            assertThat(t.getLayer(leftTop)).isGreaterThan(0);
        } else if (leftTop == null) { // left is the parent of right.
        } else if (leftTop == null) { // left is the parent of right.
            assertGreaterThan(0, t.getLayer(rightTop));
            assertThat(t.getLayer(rightTop)).isLessThan(0);
        } else {
        } else {
            assertGreaterThan(t.getLayer(leftTop),
            assertThat(t.getLayer(leftTop)).isGreaterThan(t.getLayer(rightTop));
                    t.getLayer(rightTop));
        }
        }
    }
    }


    void assertWindowHigher(WindowState left, WindowState right) throws Exception {
    void assertWindowHigher(WindowState left, WindowState right) {
        assertZOrderGreaterThan(mTransaction, left.getSurfaceControl(), right.getSurfaceControl());
        assertZOrderGreaterThan(mTransaction, left.getSurfaceControl(), right.getSurfaceControl());
    }
    }


@@ -186,7 +184,7 @@ public class ZOrderingTests extends WindowTestsBase {
    }
    }


    @Test
    @Test
    public void testAssignWindowLayers_ForImeWithNoTarget() throws Exception {
    public void testAssignWindowLayers_ForImeWithNoTarget() {
        sWm.mInputMethodTarget = null;
        sWm.mInputMethodTarget = null;
        mDisplayContent.assignChildLayers(mTransaction);
        mDisplayContent.assignChildLayers(mTransaction);


@@ -203,7 +201,7 @@ public class ZOrderingTests extends WindowTestsBase {
    }
    }


    @Test
    @Test
    public void testAssignWindowLayers_ForImeWithAppTarget() throws Exception {
    public void testAssignWindowLayers_ForImeWithAppTarget() {
        final WindowState imeAppTarget = createWindow("imeAppTarget");
        final WindowState imeAppTarget = createWindow("imeAppTarget");
        sWm.mInputMethodTarget = imeAppTarget;
        sWm.mInputMethodTarget = imeAppTarget;


@@ -222,7 +220,7 @@ public class ZOrderingTests extends WindowTestsBase {
    }
    }


    @Test
    @Test
    public void testAssignWindowLayers_ForImeWithAppTargetWithChildWindows() throws Exception {
    public void testAssignWindowLayers_ForImeWithAppTargetWithChildWindows() {
        final WindowState imeAppTarget = createWindow("imeAppTarget");
        final WindowState imeAppTarget = createWindow("imeAppTarget");
        final WindowState imeAppTargetChildAboveWindow = createWindow(imeAppTarget,
        final WindowState imeAppTargetChildAboveWindow = createWindow(imeAppTarget,
                TYPE_APPLICATION_ATTACHED_DIALOG, imeAppTarget.mToken,
                TYPE_APPLICATION_ATTACHED_DIALOG, imeAppTarget.mToken,
@@ -248,7 +246,7 @@ public class ZOrderingTests extends WindowTestsBase {
    }
    }


    @Test
    @Test
    public void testAssignWindowLayers_ForImeWithAppTargetAndAppAbove() throws Exception {
    public void testAssignWindowLayers_ForImeWithAppTargetAndAppAbove() {
        final WindowState appBelowImeTarget = createWindow("appBelowImeTarget");
        final WindowState appBelowImeTarget = createWindow("appBelowImeTarget");
        final WindowState imeAppTarget = createWindow("imeAppTarget");
        final WindowState imeAppTarget = createWindow("imeAppTarget");
        final WindowState appAboveImeTarget = createWindow("appAboveImeTarget");
        final WindowState appAboveImeTarget = createWindow("appAboveImeTarget");
@@ -271,7 +269,7 @@ public class ZOrderingTests extends WindowTestsBase {
    }
    }


    @Test
    @Test
    public void testAssignWindowLayers_ForImeNonAppImeTarget() throws Exception {
    public void testAssignWindowLayers_ForImeNonAppImeTarget() {
        final WindowState imeSystemOverlayTarget = createWindow(null, TYPE_SYSTEM_OVERLAY,
        final WindowState imeSystemOverlayTarget = createWindow(null, TYPE_SYSTEM_OVERLAY,
                mDisplayContent, "imeSystemOverlayTarget",
                mDisplayContent, "imeSystemOverlayTarget",
                true /* ownerCanAddInternalSystemWindow */);
                true /* ownerCanAddInternalSystemWindow */);
@@ -298,7 +296,7 @@ public class ZOrderingTests extends WindowTestsBase {
    }
    }


    @Test
    @Test
    public void testAssignWindowLayers_ForStatusBarImeTarget() throws Exception {
    public void testAssignWindowLayers_ForStatusBarImeTarget() {
        sWm.mInputMethodTarget = mStatusBarWindow;
        sWm.mInputMethodTarget = mStatusBarWindow;
        mDisplayContent.assignChildLayers(mTransaction);
        mDisplayContent.assignChildLayers(mTransaction);


@@ -312,7 +310,7 @@ public class ZOrderingTests extends WindowTestsBase {
    }
    }


    @Test
    @Test
    public void testStackLayers() throws Exception {
    public void testStackLayers() {
        final WindowState anyWindow1 = createWindow("anyWindow");
        final WindowState anyWindow1 = createWindow("anyWindow");
        final WindowState pinnedStackWindow = createWindowOnStack(null, WINDOWING_MODE_PINNED,
        final WindowState pinnedStackWindow = createWindowOnStack(null, WINDOWING_MODE_PINNED,
                ACTIVITY_TYPE_STANDARD, TYPE_BASE_APPLICATION, mDisplayContent,
                ACTIVITY_TYPE_STANDARD, TYPE_BASE_APPLICATION, mDisplayContent,
@@ -342,7 +340,7 @@ public class ZOrderingTests extends WindowTestsBase {
    }
    }


    @Test
    @Test
    public void testAssignWindowLayers_ForSysUiPanels() throws Exception {
    public void testAssignWindowLayers_ForSysUiPanels() {
        final WindowState navBarPanel =
        final WindowState navBarPanel =
                createWindow(null, TYPE_NAVIGATION_BAR_PANEL, mDisplayContent, "NavBarPanel");
                createWindow(null, TYPE_NAVIGATION_BAR_PANEL, mDisplayContent, "NavBarPanel");
        final WindowState statusBarPanel =
        final WindowState statusBarPanel =
@@ -359,7 +357,7 @@ public class ZOrderingTests extends WindowTestsBase {
    }
    }


    @Test
    @Test
    public void testAssignWindowLayers_ForNegativelyZOrderedSubtype() throws Exception {
    public void testAssignWindowLayers_ForNegativelyZOrderedSubtype() {
        // TODO(b/70040778): We should aim to eliminate the last user of TYPE_APPLICATION_MEDIA
        // TODO(b/70040778): We should aim to eliminate the last user of TYPE_APPLICATION_MEDIA
        // then we can drop all negative layering on the windowing side.
        // then we can drop all negative layering on the windowing side.


@@ -376,7 +374,7 @@ public class ZOrderingTests extends WindowTestsBase {
    }
    }


    @Test
    @Test
    public void testDockedDividerPosition() throws Exception {
    public void testDockedDividerPosition() {
        final WindowState pinnedStackWindow = createWindowOnStack(null, WINDOWING_MODE_PINNED,
        final WindowState pinnedStackWindow = createWindowOnStack(null, WINDOWING_MODE_PINNED,
                ACTIVITY_TYPE_STANDARD, TYPE_BASE_APPLICATION, mDisplayContent,
                ACTIVITY_TYPE_STANDARD, TYPE_BASE_APPLICATION, mDisplayContent,
                "pinnedStackWindow");
                "pinnedStackWindow");