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

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

Move simple WindowManager tests to WmTests

Bug: 113800711
Test: Pass all WM presubmit tests in WmTests
  $ tradefed.sh run commandAndExit WmTests \
      --include-filter com.android.server.wm. \
      --include-annotation android.platform.test.annotations.Presubmit \
      --exclude-annotation androidx.test.filters.FlakyTest
Change-Id: I28076aad00b0fe4b4d35552677436e0f3e37eafe
parent 56682c2b
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -30,6 +30,10 @@
    <uses-permission android:name="android.permission.STORAGE_INTERNAL" />
    <uses-permission android:name="android.permission.ACCESS_KEYGUARD_SECURE_STORAGE" />
    <uses-permission android:name="android.permission.STATUS_BAR_SERVICE" />
    <uses-permission android:name="android.permission.CHANGE_CONFIGURATION" />
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
    <uses-permission android:name="android.permission.ACCESS_SURFACE_FLINGER" />
    <uses-permission android:name="android.permission.READ_FRAME_BUFFER" />

    <application android:testOnly="true">
        <activity android:name="com.android.server.am.TaskStackChangedListenerTest$ActivityA" />
@@ -37,6 +41,7 @@
        <activity android:name="com.android.server.am.TaskStackChangedListenerTest$ActivityRequestedOrientationChange" />
        <activity android:name="com.android.server.am.TaskStackChangedListenerTest$ActivityTaskChangeCallbacks" />
        <activity android:name="com.android.server.am.TaskStackChangedListenerTest$ActivityTaskDescriptionChange" />
        <activity android:name="com.android.server.wm.ScreenDecorWindowTests$TestActivity" />
    </application>

    <instrumentation
+10 −13
Original line number Diff line number Diff line
@@ -11,13 +11,12 @@
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License
 * limitations under the License.
 */

package com.android.server.wm;

import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_RECENTS;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED;
import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM;
@@ -36,10 +35,8 @@ import android.content.res.Configuration;
import android.platform.test.annotations.Presubmit;

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

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

import java.util.ArrayList;
import java.util.List;
@@ -48,15 +45,14 @@ import java.util.List;
 * Test class for {@link ConfigurationContainer}.
 *
 * Build/Install/Run:
 *  bit FrameworksServicesTests:com.android.server.wm.ConfigurationContainerTests
 *  atest WmTests:ConfigurationContainerTests
 */
@SmallTest
@Presubmit
@RunWith(AndroidJUnit4.class)
public class ConfigurationContainerTests {

    @Test
    public void testConfigurationInit() throws Exception {
    public void testConfigurationInit() {
        // Check root container initial config.
        final TestConfigurationContainer root = new TestConfigurationContainer();
        assertEquals(EMPTY, root.getOverrideConfiguration());
@@ -93,7 +89,7 @@ public class ConfigurationContainerTests {
    }

    @Test
    public void testConfigurationChangeOnAddRemove() throws Exception {
    public void testConfigurationChangeOnAddRemove() {
        // Init root's config.
        final TestConfigurationContainer root = new TestConfigurationContainer();
        final Configuration rootOverrideConfig = new Configuration();
@@ -135,7 +131,7 @@ public class ConfigurationContainerTests {
    }

    @Test
    public void testConfigurationChangePropagation() throws Exception {
    public void testConfigurationChangePropagation() {
        // Builds 3-level vertical hierarchy with one configuration container on each level.
        // In addition to different overrides on each level, everyone in hierarchy will have one
        // common overridden value - orientation;
@@ -212,7 +208,7 @@ public class ConfigurationContainerTests {
    }

    @Test
    public void testSetWindowingMode() throws Exception {
    public void testSetWindowingMode() {
        final TestConfigurationContainer root = new TestConfigurationContainer();
        root.setWindowingMode(WINDOWING_MODE_UNDEFINED);
        final TestConfigurationContainer child = root.addChild();
@@ -226,7 +222,7 @@ public class ConfigurationContainerTests {
    }

    @Test
    public void testSetActivityType() throws Exception {
    public void testSetActivityType() {
        final TestConfigurationContainer root = new TestConfigurationContainer();
        root.setActivityType(ACTIVITY_TYPE_UNDEFINED);
        final TestConfigurationContainer child = root.addChild();
@@ -272,7 +268,7 @@ public class ConfigurationContainerTests {
    }

    @Test
    public void testRegisterConfigurationChangeListener() throws Exception {
    public void testRegisterConfigurationChangeListener() {
        final TestConfigurationContainer container = new TestConfigurationContainer();
        final TestConfigurationChangeListener listener = new TestConfigurationChangeListener();
        final Configuration config = new Configuration();
@@ -328,10 +324,11 @@ public class ConfigurationContainerTests {
        }
    }

    private class TestConfigurationChangeListener implements ConfigurationContainerListener {
    private static class TestConfigurationChangeListener implements ConfigurationContainerListener {

        final Configuration mOverrideConfiguration = new Configuration();

        @Override
        public void onOverrideConfigurationChanged(Configuration overrideConfiguration) {
            mOverrideConfiguration.setTo(overrideConfiguration);
        }
+0 −46
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.server.wm;

import android.platform.test.annotations.Presubmit;

import org.junit.Test;

import androidx.test.filters.FlakyTest;

/**
 * Dummy test for com.android.server.wm
 * TODO(b/113800711): Remove this class once the actual tests are moved from servicestests.
 */
public class DummyWmTests {

    @Presubmit
    @Test
    public void preSubmitTest() {}

    @FlakyTest
    @Presubmit
    @Test
    public void flakyPreSubmitTest() {}

    @Test
    public void postSubmitTest() {}

    @FlakyTest
    @Test
    public void flakyPostSubmitTest() {}
}
+24 −27
Original line number Diff line number Diff line
@@ -11,7 +11,7 @@
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License
 * limitations under the License.
 */

package com.android.server.wm;
@@ -33,6 +33,8 @@ import static android.view.WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_IS_SCREEN_DECOR;
import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;

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

import static org.junit.Assert.assertEquals;

import android.app.Activity;
@@ -46,6 +48,7 @@ import android.hardware.display.DisplayManager;
import android.hardware.display.VirtualDisplay;
import android.media.ImageReader;
import android.os.Handler;
import android.os.SystemClock;
import android.platform.test.annotations.Presubmit;
import android.util.Pair;
import android.view.Display;
@@ -57,13 +60,10 @@ import android.widget.TextView;

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

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

import java.util.ArrayList;
import java.util.function.BooleanSupplier;
@@ -72,13 +72,12 @@ import java.util.function.BooleanSupplier;
 * Tests for the {@link android.view.WindowManager.LayoutParams#PRIVATE_FLAG_IS_SCREEN_DECOR} flag.
 *
 * Build/Install/Run:
 *  atest FrameworksServicesTests:com.android.server.wm.ScreenDecorWindowTests
 *  atest WmTests:ScreenDecorWindowTests
 */
// TODO: Add test for FLAG_FULLSCREEN which hides the status bar and also other flags.
// TODO: Test non-Activity windows.
@SmallTest
@Presubmit
@RunWith(AndroidJUnit4.class)
public class ScreenDecorWindowTests {

    private final Context mContext = InstrumentationRegistry.getTargetContext();
@@ -120,7 +119,7 @@ public class ScreenDecorWindowTests {
    }

    @Test
    public void testScreenSides() throws Exception {
    public void testScreenSides() {
        // Decor on top
        final View decorWindow = createDecorWindow(TOP, MATCH_PARENT, mDecorThickness);
        assertInsetGreaterOrEqual(mTestActivity, TOP, mDecorThickness);
@@ -139,7 +138,7 @@ public class ScreenDecorWindowTests {
    }

    @Test
    public void testMultipleDecors() throws Exception {
    public void testMultipleDecors() {
        // Test 2 decor windows on-top.
        createDecorWindow(TOP, MATCH_PARENT, mHalfDecorThickness);
        assertInsetGreaterOrEqual(mTestActivity, TOP, mHalfDecorThickness);
@@ -153,7 +152,7 @@ public class ScreenDecorWindowTests {
    }

    @Test
    public void testFlagChange() throws Exception {
    public void testFlagChange() {
        WindowInsets initialInsets = getInsets(mTestActivity);

        final View decorWindow = createDecorWindow(TOP, MATCH_PARENT, mDecorThickness);
@@ -174,7 +173,7 @@ public class ScreenDecorWindowTests {
    }

    @Test
    public void testRemoval() throws Exception {
    public void testRemoval() {
        WindowInsets initialInsets = getInsets(mTestActivity);

        final View decorWindow = createDecorWindow(TOP, MATCH_PARENT, mDecorThickness);
@@ -256,7 +255,7 @@ public class ScreenDecorWindowTests {
    /**
     * Asserts the top inset of {@param activity} is equal to {@param expected} waiting as needed.
     */
    private void assertTopInsetEquals(Activity activity, int expected) throws Exception {
    private void assertTopInsetEquals(Activity activity, int expected) {
        waitForTopInsetEqual(activity, expected);
        assertEquals(expected, getInsets(activity).getSystemWindowInsetTop());
    }
@@ -269,16 +268,23 @@ public class ScreenDecorWindowTests {
     * Asserts the inset at {@param side} of {@param activity} is equal to {@param expected}
     * waiting as needed.
     */
    private void assertInsetGreaterOrEqual(Activity activity, int side, int expected)
            throws Exception {
    private void assertInsetGreaterOrEqual(Activity activity, int side, int expected) {
        waitForInsetGreaterOrEqual(activity, side, expected);

        final WindowInsets insets = getInsets(activity);
        switch (side) {
            case TOP: assertGreaterOrEqual(insets.getSystemWindowInsetTop(), expected); break;
            case BOTTOM: assertGreaterOrEqual(insets.getSystemWindowInsetBottom(), expected); break;
            case LEFT: assertGreaterOrEqual(insets.getSystemWindowInsetLeft(), expected); break;
            case RIGHT: assertGreaterOrEqual(insets.getSystemWindowInsetRight(), expected); break;
            case TOP:
                assertThat(insets.getSystemWindowInsetTop()).isAtLeast(expected);
                break;
            case BOTTOM:
                assertThat(insets.getSystemWindowInsetBottom()).isAtLeast(expected);
                break;
            case LEFT:
                assertThat(insets.getSystemWindowInsetLeft()).isAtLeast(expected);
                break;
            case RIGHT:
                assertThat(insets.getSystemWindowInsetRight()).isAtLeast(expected);
                break;
        }
    }

@@ -295,22 +301,13 @@ public class ScreenDecorWindowTests {
        });
    }

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

    private void waitFor(BooleanSupplier waitCondition) {
        int retriesLeft = 5;
        do {
            if (waitCondition.getAsBoolean()) {
                break;
            }
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                // Well I guess we are not waiting...
            }
            SystemClock.sleep(500);
        } while (retriesLeft-- > 0);
    }

+3 −5
Original line number Diff line number Diff line
@@ -11,7 +11,7 @@
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License
 * limitations under the License.
 */

package com.android.server.wm;
@@ -33,19 +33,17 @@ import android.view.animation.Animation;
import android.view.animation.ClipRectAnimation;

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

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

/**
 * Tests for the {@link WindowAnimationSpec} class.
 *
 *  atest FrameworksServicesTests:com.android.server.wm.WindowAnimationSpecTest
 * Build/Install/Run:
 *  atest WmTests:WindowAnimationSpecTest
 */
@SmallTest
@Presubmit
@RunWith(AndroidJUnit4.class)
public class WindowAnimationSpecTest {
    private final SurfaceControl mSurfaceControl = mock(SurfaceControl.class);
    private final SurfaceControl.Transaction mTransaction = mock(SurfaceControl.Transaction.class);
Loading