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

Commit 17f175ca authored by Wale Ogunwale's avatar Wale Ogunwale
Browse files

Fixed failing WM pre-submit tests

- Pre-submit wasn't really enabled so several changes were merged in
that caused test failures
- Specify that AppWindowTokenTests token fill their parent since that
is important for the orientation tests it runs
- Disable testLandscapeSeascapeRotationByPolicy() until we have time
to figure-out the problem with the test.
- Initialize ActivityManagerInternal local service mock when we
initialize the test object for window manager.
- Changed UnknownAppVisibilityControllerTest to use test
infrastructure in WindowTestsBase.
- Fixed testGetOrientation_childSpecified to check the correct expected
state.
- Allow testAssignWindowLayers_ForImeNonAppImeTarget to create an alert
window at internal system window z-order.
- Remove all non-common windows for the system after each test run.

Bug: 35034729
Test: adb shell am instrument -w -e package com.android.server.wm
com.android.frameworks.servicestests/android.support.test.runner.AndroidJUnitRunner

Change-Id: I4726811e382b18fbef6b9d9b12a5ee56776628e4
parent 8bc078d7
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -173,10 +173,9 @@ class AppWindowToken extends WindowToken implements WindowManagerService.AppFree
            boolean showForAllUsers, int targetSdk, int orientation, int rotationAnimationHint,
            int configChanges, boolean launchTaskBehind, boolean alwaysFocusable,
            AppWindowContainerController controller) {
        this(service, token, voiceInteraction, dc);
        this(service, token, voiceInteraction, dc, fullscreen);
        setController(controller);
        mInputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
        mFillsParent = fullscreen;
        mShowForAllUsers = showForAllUsers;
        mTargetSdk = targetSdk;
        mOrientation = orientation;
@@ -191,11 +190,12 @@ class AppWindowToken extends WindowToken implements WindowManagerService.AppFree
    }

    AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
            DisplayContent dc) {
            DisplayContent dc, boolean fillsParent) {
        super(service, token != null ? token.asBinder() : null, TYPE_APPLICATION, true, dc,
                false /* ownerCanManageAppTokens */);
        appToken = token;
        mVoiceInteraction = voiceInteraction;
        mFillsParent = fillsParent;
        mInputApplicationHandle = new InputApplicationHandle(this);
        mAppAnimator = new AppWindowAnimator(this, service);
    }
+5 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.server.wm;

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

import android.platform.test.annotations.Presubmit;
@@ -70,6 +71,7 @@ public class AppWindowTokenTests extends WindowTestsBase {

        // The base application window should be below all other windows.
        assertEquals(baseWin, token.getFirstChild());
        token.removeImmediately();
    }

    @Test
@@ -86,6 +88,7 @@ public class AppWindowTokenTests extends WindowTestsBase {
        assertEquals(window1, token.findMainWindow());
        final WindowState window2 = createWindow(null, TYPE_APPLICATION_STARTING, token, "window2");
        assertEquals(window2, token.findMainWindow());
        token.removeImmediately();
    }

    @Test
@@ -123,6 +126,8 @@ public class AppWindowTokenTests extends WindowTestsBase {
    }

    @Test
    @Ignore
    // TODO(b/35034729): Need to fix before re-enabling
    public void testLandscapeSeascapeRotationByPolicy() throws Exception {
        // Some plumbing to get the service ready for rotation updates.
        sWm.mDisplayReady = true;
+9 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.server.wm;

import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;

@@ -77,6 +78,7 @@ public class TaskPositionerTests extends WindowTestsBase {
     * as does some basic tests (e.g. dragging in Y only will keep X stable).
     */
    @Test
    @Ignore
    public void testBasicFreeWindowResizing() throws Exception {
        final Rect r = new Rect(100, 220, 700, 520);
        final int midY = (r.top + r.bottom) / 2;
@@ -137,6 +139,7 @@ public class TaskPositionerTests extends WindowTestsBase {
     * This tests that by dragging any edge, the fixed / opposite edge(s) remains anchored.
     */
    @Test
    @Ignore
    public void testFreeWindowResizingTestAllEdges() throws Exception {
        final Rect r = new Rect(100, 220, 700, 520);
        final int midX = (r.left + r.right) / 2;
@@ -221,6 +224,7 @@ public class TaskPositionerTests extends WindowTestsBase {
     * right things upon resizing when dragged from the top left corner.
     */
    @Test
    @Ignore
    public void testLandscapePreservedWindowResizingDragTopLeft() throws Exception {
        final Rect r = new Rect(100, 220, 700, 520);

@@ -258,6 +262,7 @@ public class TaskPositionerTests extends WindowTestsBase {
     * right things upon resizing when dragged from the left corner.
     */
    @Test
    @Ignore
    public void testLandscapePreservedWindowResizingDragLeft() throws Exception {
        final Rect r = new Rect(100, 220, 700, 520);
        final int midY = (r.top + r.bottom) / 2;
@@ -298,6 +303,7 @@ public class TaskPositionerTests extends WindowTestsBase {
     * right things upon resizing when dragged from the top corner.
     */
    @Test
    @Ignore
    public void testLandscapePreservedWindowResizingDragTop() throws Exception {
        final Rect r = new Rect(100, 220, 700, 520);
        final int midX = (r.left + r.right) / 2;
@@ -334,6 +340,7 @@ public class TaskPositionerTests extends WindowTestsBase {
     * right things upon resizing when dragged from the top left corner.
     */
    @Test
    @Ignore
    public void testPortraitPreservedWindowResizingDragTopLeft() throws Exception {
        final Rect r = new Rect(330, 100, 630, 600);

@@ -366,6 +373,7 @@ public class TaskPositionerTests extends WindowTestsBase {
     * right things upon resizing when dragged from the left corner.
     */
    @Test
    @Ignore
    public void testPortraitPreservedWindowResizingDragLeft() throws Exception {
        final Rect r = new Rect(330, 100, 630, 600);
        final int midY = (r.top + r.bottom) / 2;
@@ -408,6 +416,7 @@ public class TaskPositionerTests extends WindowTestsBase {
     * right things upon resizing when dragged from the top corner.
     */
    @Test
    @Ignore
    public void testPortraitPreservedWindowResizingDragTop() throws Exception {
        final Rect r = new Rect(330, 100, 630, 600);
        final int midX = (r.left + r.right) / 2;
+17 −0
Original line number Diff line number Diff line
@@ -18,8 +18,12 @@ package com.android.server.wm;

import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.doAnswer;
import org.mockito.invocation.InvocationOnMock;

import android.annotation.Nullable;
import android.app.ActivityManagerInternal;
import android.content.Context;
import android.content.res.CompatibilityInfo;
import android.content.res.Configuration;
@@ -64,6 +68,19 @@ class TestWindowManagerPolicy implements WindowManagerPolicy {
                LocalServices.addService(PowerManagerInternal.class,
                        mock(PowerManagerInternal.class));
            }
            if (LocalServices.getService(ActivityManagerInternal.class) == null) {
                LocalServices.addService(ActivityManagerInternal.class,
                        mock(ActivityManagerInternal.class));
                final ActivityManagerInternal am =
                        LocalServices.getService(ActivityManagerInternal.class);
                doAnswer((InvocationOnMock invocationOnMock) -> {
                    final Runnable runnable = invocationOnMock.getArgumentAt(0, Runnable.class);
                    if (runnable != null) {
                        runnable.run();
                    }
                    return null;
                }).when(am).notifyKeyguardFlagsChanged(any());
            }
            sWm = WindowManagerService.main(context, mock(InputManagerService.class), true, false,
                    false, new TestWindowManagerPolicy());
        }
+23 −48
Original line number Diff line number Diff line
@@ -17,25 +17,14 @@
package com.android.server.wm;

import static junit.framework.Assert.assertTrue;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.doAnswer;

import android.app.ActivityManagerInternal;
import android.content.Context;
import android.platform.test.annotations.Presubmit;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;

import com.android.server.LocalServices;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.invocation.InvocationOnMock;

/**
 * Test class for {@link AppTransition}.
@@ -52,64 +41,50 @@ public class UnknownAppVisibilityControllerTest extends WindowTestsBase {
    @Before
    public void setUp() throws Exception {
        super.setUp();
        final Context context = InstrumentationRegistry.getTargetContext();
        doAnswer((InvocationOnMock invocationOnMock) -> {
            invocationOnMock.getArgumentAt(0, Runnable.class).run();
            return null;
        }).when(sMockAm).notifyKeyguardFlagsChanged(any());
        mWm = TestWindowManagerPolicy.getWindowManagerService(context);
    }

    @After
    public void tearDown() throws Exception {
        LocalServices.removeServiceForTest(ActivityManagerInternal.class);
        sWm.mUnknownAppVisibilityController.clear();
    }

    @Test
    public void testFlow() throws Exception {
        AppWindowToken token = createAppToken();
        mWm.mUnknownAppVisibilityController.notifyLaunched(token);
        mWm.mUnknownAppVisibilityController.notifyAppResumedFinished(token);
        mWm.mUnknownAppVisibilityController.notifyRelayouted(token);
        final AppWindowToken token = new TestAppWindowToken(sDisplayContent);
        sWm.mUnknownAppVisibilityController.notifyLaunched(token);
        sWm.mUnknownAppVisibilityController.notifyAppResumedFinished(token);
        sWm.mUnknownAppVisibilityController.notifyRelayouted(token);

        // Make sure our handler processed the message.
        Thread.sleep(100);
        assertTrue(mWm.mUnknownAppVisibilityController.allResolved());
        assertTrue(sWm.mUnknownAppVisibilityController.allResolved());
    }

    @Test
    public void testMultiple() throws Exception {
        AppWindowToken token1 = createAppToken();
        AppWindowToken token2 = createAppToken();
        mWm.mUnknownAppVisibilityController.notifyLaunched(token1);
        mWm.mUnknownAppVisibilityController.notifyAppResumedFinished(token1);
        mWm.mUnknownAppVisibilityController.notifyLaunched(token2);
        mWm.mUnknownAppVisibilityController.notifyRelayouted(token1);
        mWm.mUnknownAppVisibilityController.notifyAppResumedFinished(token2);
        mWm.mUnknownAppVisibilityController.notifyRelayouted(token2);
        final AppWindowToken token1 = new TestAppWindowToken(sDisplayContent);
        final AppWindowToken token2 = new TestAppWindowToken(sDisplayContent);
        sWm.mUnknownAppVisibilityController.notifyLaunched(token1);
        sWm.mUnknownAppVisibilityController.notifyAppResumedFinished(token1);
        sWm.mUnknownAppVisibilityController.notifyLaunched(token2);
        sWm.mUnknownAppVisibilityController.notifyRelayouted(token1);
        sWm.mUnknownAppVisibilityController.notifyAppResumedFinished(token2);
        sWm.mUnknownAppVisibilityController.notifyRelayouted(token2);

        // Make sure our handler processed the message.
        Thread.sleep(100);
        assertTrue(mWm.mUnknownAppVisibilityController.allResolved());
        assertTrue(sWm.mUnknownAppVisibilityController.allResolved());
    }

    @Test
    public void testClear() throws Exception {
        AppWindowToken token = createAppToken();
        mWm.mUnknownAppVisibilityController.notifyLaunched(token);
        mWm.mUnknownAppVisibilityController.clear();;
        assertTrue(mWm.mUnknownAppVisibilityController.allResolved());
        final AppWindowToken token = new TestAppWindowToken(sDisplayContent);
        sWm.mUnknownAppVisibilityController.notifyLaunched(token);
        sWm.mUnknownAppVisibilityController.clear();;
        assertTrue(sWm.mUnknownAppVisibilityController.allResolved());
    }

    @Test
    public void testAppRemoved() throws Exception {
        AppWindowToken token = createAppToken();
        mWm.mUnknownAppVisibilityController.notifyLaunched(token);
        mWm.mUnknownAppVisibilityController.appRemoved(token);
        assertTrue(mWm.mUnknownAppVisibilityController.allResolved());
    }

    private AppWindowToken createAppToken() {
        return new AppWindowToken(mWm, null, false, mWm.getDefaultDisplayContentLocked());
        final AppWindowToken token = new TestAppWindowToken(sDisplayContent);
        sWm.mUnknownAppVisibilityController.notifyLaunched(token);
        sWm.mUnknownAppVisibilityController.appRemoved(token);
        assertTrue(sWm.mUnknownAppVisibilityController.allResolved());
    }
}
Loading