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

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

Merge "Move simple WindowManager tests to WmTests"

parents dd0e346a a65212d4
Loading
Loading
Loading
Loading
+5 −0
Original line number Original line Diff line number Diff line
@@ -30,6 +30,10 @@
    <uses-permission android:name="android.permission.STORAGE_INTERNAL" />
    <uses-permission android:name="android.permission.STORAGE_INTERNAL" />
    <uses-permission android:name="android.permission.ACCESS_KEYGUARD_SECURE_STORAGE" />
    <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.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">
    <application android:testOnly="true">
        <activity android:name="com.android.server.am.TaskStackChangedListenerTest$ActivityA" />
        <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$ActivityRequestedOrientationChange" />
        <activity android:name="com.android.server.am.TaskStackChangedListenerTest$ActivityTaskChangeCallbacks" />
        <activity android:name="com.android.server.am.TaskStackChangedListenerTest$ActivityTaskChangeCallbacks" />
        <activity android:name="com.android.server.am.TaskStackChangedListenerTest$ActivityTaskDescriptionChange" />
        <activity android:name="com.android.server.am.TaskStackChangedListenerTest$ActivityTaskDescriptionChange" />
        <activity android:name="com.android.server.wm.ScreenDecorWindowTests$TestActivity" />
    </application>
    </application>


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


package com.android.server.wm;
package com.android.server.wm;


import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME;
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_STANDARD;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED;
import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM;
import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM;
@@ -36,10 +35,8 @@ import android.content.res.Configuration;
import android.platform.test.annotations.Presubmit;
import android.platform.test.annotations.Presubmit;


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


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


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


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


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


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


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


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


    @Test
    @Test
    public void testRegisterConfigurationChangeListener() throws Exception {
    public void testRegisterConfigurationChangeListener() {
        final TestConfigurationContainer container = new TestConfigurationContainer();
        final TestConfigurationContainer container = new TestConfigurationContainer();
        final TestConfigurationChangeListener listener = new TestConfigurationChangeListener();
        final TestConfigurationChangeListener listener = new TestConfigurationChangeListener();
        final Configuration config = new Configuration();
        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();
        final Configuration mOverrideConfiguration = new Configuration();


        @Override
        public void onOverrideConfigurationChanged(Configuration overrideConfiguration) {
        public void onOverrideConfigurationChanged(Configuration overrideConfiguration) {
            mOverrideConfiguration.setTo(overrideConfiguration);
            mOverrideConfiguration.setTo(overrideConfiguration);
        }
        }
+0 −46
Original line number Original line 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 Original line Diff line number Diff line
@@ -11,7 +11,7 @@
 * distributed under the License is distributed on an "AS IS" BASIS,
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * See the License for the specific language governing permissions and
 * limitations under the License
 * limitations under the License.
 */
 */


package com.android.server.wm;
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.PRIVATE_FLAG_IS_SCREEN_DECOR;
import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;


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

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertEquals;


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


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


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


import java.util.ArrayList;
import java.util.ArrayList;
import java.util.function.BooleanSupplier;
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.
 * Tests for the {@link android.view.WindowManager.LayoutParams#PRIVATE_FLAG_IS_SCREEN_DECOR} flag.
 *
 *
 * Build/Install/Run:
 * 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: Add test for FLAG_FULLSCREEN which hides the status bar and also other flags.
// TODO: Test non-Activity windows.
// TODO: Test non-Activity windows.
@SmallTest
@SmallTest
@Presubmit
@Presubmit
@RunWith(AndroidJUnit4.class)
public class ScreenDecorWindowTests {
public class ScreenDecorWindowTests {


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


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


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


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


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


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


        final View decorWindow = createDecorWindow(TOP, MATCH_PARENT, mDecorThickness);
        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.
     * 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);
        waitForTopInsetEqual(activity, expected);
        assertEquals(expected, getInsets(activity).getSystemWindowInsetTop());
        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}
     * Asserts the inset at {@param side} of {@param activity} is equal to {@param expected}
     * waiting as needed.
     * waiting as needed.
     */
     */
    private void assertInsetGreaterOrEqual(Activity activity, int side, int expected)
    private void assertInsetGreaterOrEqual(Activity activity, int side, int expected) {
            throws Exception {
        waitForInsetGreaterOrEqual(activity, side, expected);
        waitForInsetGreaterOrEqual(activity, side, expected);


        final WindowInsets insets = getInsets(activity);
        final WindowInsets insets = getInsets(activity);
        switch (side) {
        switch (side) {
            case TOP: assertGreaterOrEqual(insets.getSystemWindowInsetTop(), expected); break;
            case TOP:
            case BOTTOM: assertGreaterOrEqual(insets.getSystemWindowInsetBottom(), expected); break;
                assertThat(insets.getSystemWindowInsetTop()).isAtLeast(expected);
            case LEFT: assertGreaterOrEqual(insets.getSystemWindowInsetLeft(), expected); break;
                break;
            case RIGHT: assertGreaterOrEqual(insets.getSystemWindowInsetRight(), 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) {
    private void waitFor(BooleanSupplier waitCondition) {
        int retriesLeft = 5;
        int retriesLeft = 5;
        do {
        do {
            if (waitCondition.getAsBoolean()) {
            if (waitCondition.getAsBoolean()) {
                break;
                break;
            }
            }
            try {
            SystemClock.sleep(500);
                Thread.sleep(500);
            } catch (InterruptedException e) {
                // Well I guess we are not waiting...
            }
        } while (retriesLeft-- > 0);
        } while (retriesLeft-- > 0);
    }
    }


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


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


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


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


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