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

Commit 71278caa authored by Ben Murdoch's avatar Ben Murdoch Committed by Android (Google) Code Review
Browse files

Merge "Add test case for ModifierShortcutManager" into main

parents 486b26e3 177b99e9
Loading
Loading
Loading
Loading
+15 −12
Original line number Diff line number Diff line
@@ -41,31 +41,34 @@
        category="android.intent.category.APP_CALCULATOR"
        shortcut="u" />

    <!-- The following shortcuts will not be invoked by tests but are here to
         provide test coverage of parsing the different types of shortcut. -->
    <bookmark
        package="com.test"
        class="com.test.BookmarkTest"
        shortcut="a" />
    <bookmark
        package="com.test2"
        class="com.test.BookmarkTest"
        shortcut="d" />

    <bookmark
        role="android.app.role.BROWSER"
        shortcut="b"
        shift="true" />

    <bookmark
        category="android.intent.category.APP_CONTACTS"
        shortcut="c"
        shift="true" />

    <bookmark
        package="com.test"
        class="com.test.BookmarkTest"
        shortcut="a"
        shortcut="j"
        shift="true" />

    <!-- The following shortcuts will not be invoked by tests but are here to
         provide test coverage of parsing the different types of shortcut. -->
    <bookmark
        package="com.test"
        class="com.test.BookmarkTest"
        shortcut="j" />
    <bookmark
        package="com.test2"
        class="com.test.BookmarkTest"
        shortcut="d" />


    <!-- It's intended that this package/class will NOT resolve so we test the resolution
         failure case. -->
    <bookmark
+13 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import static android.view.KeyEvent.KEYCODE_DEL;
import static android.view.KeyEvent.KEYCODE_E;
import static android.view.KeyEvent.KEYCODE_ENTER;
import static android.view.KeyEvent.KEYCODE_H;
import static android.view.KeyEvent.KEYCODE_J;
import static android.view.KeyEvent.KEYCODE_K;
import static android.view.KeyEvent.KEYCODE_M;
import static android.view.KeyEvent.KEYCODE_META_LEFT;
@@ -40,6 +41,7 @@ import static android.view.KeyEvent.KEYCODE_U;
import static android.view.KeyEvent.KEYCODE_Z;

import android.app.role.RoleManager;
import android.content.ComponentName;
import android.content.Intent;
import android.os.RemoteException;
import android.platform.test.annotations.Presubmit;
@@ -105,6 +107,17 @@ public class ModifierShortcutTests extends ShortcutKeyTestBase {
            sendKeyCombination(new int[]{KEYCODE_META_LEFT, keyCode}, 0);
            mPhoneWindowManager.assertLaunchRole(role);
        }

        sendKeyCombination(new int[]{KEYCODE_META_LEFT, KEYCODE_SHIFT_LEFT, KEYCODE_B}, 0);
        mPhoneWindowManager.assertLaunchRole(RoleManager.ROLE_BROWSER);

        sendKeyCombination(new int[]{KEYCODE_META_LEFT, KEYCODE_SHIFT_LEFT, KEYCODE_C}, 0);
        mPhoneWindowManager.assertLaunchCategory(Intent.CATEGORY_APP_CONTACTS);

        sendKeyCombination(new int[]{KEYCODE_META_LEFT, KEYCODE_SHIFT_LEFT, KEYCODE_J}, 0);
        mPhoneWindowManager.assertActivityTargetLaunched(
                new ComponentName("com.test", "com.test.BookmarkTest"));

    }

    /**
+20 −0
Original line number Diff line number Diff line
@@ -43,11 +43,17 @@ import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.spy;
import static com.android.server.policy.WindowManagerPolicy.ACTION_PASS_TO_USER;

import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyObject;
import static org.mockito.ArgumentMatchers.eq;

import static java.util.Collections.unmodifiableMap;

import android.content.ComponentName;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.content.res.XmlResourceParser;
import android.platform.test.flag.junit.SetFlagsRule;
@@ -76,6 +82,7 @@ class ShortcutKeyTestBase {
    public RuleChain rules = RuleChain.outerRule(mSettingsProviderRule).around(mSetFlagsRule);

    private Resources mResources;
    private PackageManager mPackageManager;
    TestPhoneWindowManager mPhoneWindowManager;
    DispatchedKeyHandler mDispatchedKeyHandler = event -> false;
    Context mContext;
@@ -100,12 +107,25 @@ class ShortcutKeyTestBase {
    public void setup() {
        mContext = spy(getInstrumentation().getTargetContext());
        mResources = spy(mContext.getResources());
        mPackageManager = spy(mContext.getPackageManager());
        doReturn(mContext).when(mContext).createContextAsUser(anyObject(), anyInt());
        doReturn(mResources).when(mContext).getResources();
        doReturn(mSettingsProviderRule.mockContentResolver(mContext))
                .when(mContext).getContentResolver();
        XmlResourceParser testBookmarks = mResources.getXml(
                com.android.frameworks.wmtests.R.xml.bookmarks);
        doReturn(testBookmarks).when(mResources).getXml(com.android.internal.R.xml.bookmarks);

        try {
            // Keep packageName / className in sync with
            // services/tests/wmtests/res/xml/bookmarks.xml
            ActivityInfo testActivityInfo = new ActivityInfo();
            testActivityInfo.applicationInfo = new ApplicationInfo();
            testActivityInfo.packageName =
                    testActivityInfo.applicationInfo.packageName = "com.test";
            doReturn(testActivityInfo).when(mPackageManager).getActivityInfo(
                    eq(new ComponentName("com.test", "com.test.BookmarkTest")), anyInt());
        } catch (PackageManager.NameNotFoundException ignored) { }
    }


+0 −9
Original line number Diff line number Diff line
@@ -50,7 +50,6 @@ import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.Mockito.CALLS_REAL_METHODS;
import static org.mockito.Mockito.after;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mockingDetails;
import static org.mockito.Mockito.timeout;
import static org.mockito.Mockito.withSettings;
@@ -311,13 +310,6 @@ class TestPhoneWindowManager {
                eq(AccessibilityManager.class));
        doReturn(false).when(mAccessibilityManager).isEnabled();
        doReturn(false).when(mPackageManager).hasSystemFeature(any());
        try {
            doThrow(new PackageManager.NameNotFoundException("test")).when(mPackageManager)
                    .getActivityInfo(any(), anyInt());
            doReturn(new String[] { "testPackage" }).when(mPackageManager)
                    .canonicalToCurrentPackageNames(any());
        } catch (PackageManager.NameNotFoundException ignored) { }

        doReturn(false).when(mTelecomManager).isInCall();
        doReturn(false).when(mTelecomManager).isRinging();
        doReturn(mTelecomManager).when(mPhoneWindowManager).getTelecommService();
@@ -740,7 +732,6 @@ class TestPhoneWindowManager {
        Mockito.clearInvocations(mContext);
    }


    void assertShowRecentApps() {
        mTestLooper.dispatchAll();
        verify(mStatusBarManagerInternal).showRecentApps(anyBoolean());