Loading tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java +0 −5 Original line number Diff line number Diff line Loading @@ -296,11 +296,6 @@ public abstract class AbstractLauncherUiTest { Process.myUserHandle()).get(0); } protected LauncherActivityInfo getChromeApp() { return LauncherAppsCompat.getInstance(mTargetContext) .getActivityList("com.android.chrome", Process.myUserHandle()).get(0); } /** * Broadcast receiver which blocks until the result is received. */ Loading tests/src/com/android/launcher3/ui/ShortcutsLaunchTest.java +24 −40 Original line number Diff line number Diff line package com.android.launcher3.ui; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import android.content.pm.LauncherActivityInfo; import android.graphics.Point; import androidx.test.filters.LargeTest; import androidx.test.runner.AndroidJUnit4; import androidx.test.uiautomator.By; import androidx.test.uiautomator.UiObject2; import androidx.test.uiautomator.Until; import android.view.MotionEvent; import com.android.launcher3.R; import com.android.launcher3.util.Condition; import com.android.launcher3.util.Wait; import com.android.launcher3.Launcher; import com.android.launcher3.popup.ArrowPopup; import com.android.launcher3.tapl.AppIconMenu; import com.android.launcher3.tapl.AppIconMenuItem; import com.android.launcher3.views.OptionsPopupView; import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; Loading @@ -27,47 +25,33 @@ import org.junit.runner.RunWith; @RunWith(AndroidJUnit4.class) public class ShortcutsLaunchTest extends AbstractLauncherUiTest { @Test @Ignore public void testAppLauncher_portrait() throws Exception { lockRotation(true); performTest(); private boolean isOptionsPopupVisible(Launcher launcher) { final ArrowPopup popup = OptionsPopupView.getOptionsPopup(launcher); return popup != null && popup.isShown(); } @Test @Ignore public void testAppLauncher_landscape() throws Exception { lockRotation(false); performTest(); } private void performTest() throws Exception { @PortraitLandscape public void testAppLauncher() throws Exception { mActivityMonitor.startLauncher(); LauncherActivityInfo testApp = getSettingsApp(); final LauncherActivityInfo testApp = getSettingsApp(); // Open all apps and wait for load complete final UiObject2 appsContainer = TestViewHelpers.openAllApps(); Wait.atMost(null, Condition.minChildCount(appsContainer, 2), DEFAULT_UI_TIMEOUT); final AppIconMenu menu = mLauncher. pressHome(). switchToAllApps(). getAppIcon(testApp.getLabel().toString()). openMenu(); // Find settings app and verify shortcuts appear when long pressed UiObject2 icon = scrollAndFind(appsContainer, By.text(testApp.getLabel().toString())); // Press icon center until shortcuts appear Point iconCenter = icon.getVisibleCenter(); TestViewHelpers.sendPointer(MotionEvent.ACTION_DOWN, iconCenter); UiObject2 deepShortcutsContainer = TestViewHelpers.findViewById( R.id.deep_shortcuts_container); assertNotNull(deepShortcutsContainer); TestViewHelpers.sendPointer(MotionEvent.ACTION_UP, iconCenter); executeOnLauncher( launcher -> assertTrue("Launcher internal state didn't switch to Showing Menu", isOptionsPopupVisible(launcher))); // Verify that launching a shortcut opens a page with the same text assertTrue(deepShortcutsContainer.getChildCount() > 0); final AppIconMenuItem menuItem = menu.getMenuItem(1); final String itemName = menuItem.getText(); // Pick second children as it starts showing shortcuts. UiObject2 shortcut = deepShortcutsContainer.getChildren().get(1) .findObject(TestViewHelpers.getSelectorForId(R.id.bubble_text)); shortcut.click(); menuItem.launch(); assertTrue(mDevice.wait(Until.hasObject(By.pkg( testApp.getComponentName().getPackageName()) .text(shortcut.getText())), DEFAULT_UI_TIMEOUT)); .text(itemName)), DEFAULT_UI_TIMEOUT)); } } tests/tapl/com/android/launcher3/tapl/AppIcon.java +12 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.launcher3.tapl; import android.graphics.Point; import android.widget.TextView; import androidx.test.uiautomator.By; Loading Loading @@ -56,4 +57,15 @@ public final class AppIcon { UiObject2 getIcon() { return mIcon; } /** * Long-clicks the icon to open its menu. */ public AppIconMenu openMenu() { final Point iconCenter = mIcon.getVisibleCenter(); mLauncher.longTap(iconCenter.x, iconCenter.y); final UiObject2 deepShortcutsContainer = mLauncher.waitForLauncherObject( "deep_shortcuts_container"); return new AppIconMenu(mLauncher, deepShortcutsContainer); } } tests/tapl/com/android/launcher3/tapl/AppIconMenu.java 0 → 100644 +46 −0 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.launcher3.tapl; import static org.junit.Assert.assertTrue; import androidx.test.uiautomator.UiObject2; /** * Context menu of an app icon. */ public class AppIconMenu { private final LauncherInstrumentation mLauncher; private final UiObject2 mDeepShortcutsContainer; AppIconMenu(LauncherInstrumentation launcher, UiObject2 deepShortcutsContainer) { mLauncher = launcher; mDeepShortcutsContainer = deepShortcutsContainer; } /** * Returns a menu item with a given number. Fails if it doesn't exist. */ public AppIconMenuItem getMenuItem(int itemNumber) { assertTrue(mDeepShortcutsContainer.getChildCount() > itemNumber); final UiObject2 shortcut = mLauncher.waitForObjectInContainer( mDeepShortcutsContainer.getChildren().get(itemNumber), "bubble_text"); return new AppIconMenuItem(mLauncher, shortcut); } } tests/tapl/com/android/launcher3/tapl/AppIconMenuItem.java 0 → 100644 +52 −0 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.launcher3.tapl; import static org.junit.Assert.assertTrue; import androidx.test.uiautomator.UiObject2; import androidx.test.uiautomator.Until; /** * Menu item in an app icon menu. */ public class AppIconMenuItem { private final LauncherInstrumentation mLauncher; final UiObject2 mShortcut; AppIconMenuItem(LauncherInstrumentation launcher, UiObject2 shortcut) { mLauncher = launcher; mShortcut = shortcut; } /** * Returns the visible text of the menu item. */ public String getText() { return mShortcut.getText(); } /** * Launches the action for the menu item. */ public Background launch() { assertTrue("Clicking a menu item didn't open a new window: " + mShortcut.getText(), mShortcut.clickAndWait(Until.newWindow(), LauncherInstrumentation.WAIT_TIME_MS)); return new Background(mLauncher); } } Loading
tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java +0 −5 Original line number Diff line number Diff line Loading @@ -296,11 +296,6 @@ public abstract class AbstractLauncherUiTest { Process.myUserHandle()).get(0); } protected LauncherActivityInfo getChromeApp() { return LauncherAppsCompat.getInstance(mTargetContext) .getActivityList("com.android.chrome", Process.myUserHandle()).get(0); } /** * Broadcast receiver which blocks until the result is received. */ Loading
tests/src/com/android/launcher3/ui/ShortcutsLaunchTest.java +24 −40 Original line number Diff line number Diff line package com.android.launcher3.ui; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import android.content.pm.LauncherActivityInfo; import android.graphics.Point; import androidx.test.filters.LargeTest; import androidx.test.runner.AndroidJUnit4; import androidx.test.uiautomator.By; import androidx.test.uiautomator.UiObject2; import androidx.test.uiautomator.Until; import android.view.MotionEvent; import com.android.launcher3.R; import com.android.launcher3.util.Condition; import com.android.launcher3.util.Wait; import com.android.launcher3.Launcher; import com.android.launcher3.popup.ArrowPopup; import com.android.launcher3.tapl.AppIconMenu; import com.android.launcher3.tapl.AppIconMenuItem; import com.android.launcher3.views.OptionsPopupView; import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; Loading @@ -27,47 +25,33 @@ import org.junit.runner.RunWith; @RunWith(AndroidJUnit4.class) public class ShortcutsLaunchTest extends AbstractLauncherUiTest { @Test @Ignore public void testAppLauncher_portrait() throws Exception { lockRotation(true); performTest(); private boolean isOptionsPopupVisible(Launcher launcher) { final ArrowPopup popup = OptionsPopupView.getOptionsPopup(launcher); return popup != null && popup.isShown(); } @Test @Ignore public void testAppLauncher_landscape() throws Exception { lockRotation(false); performTest(); } private void performTest() throws Exception { @PortraitLandscape public void testAppLauncher() throws Exception { mActivityMonitor.startLauncher(); LauncherActivityInfo testApp = getSettingsApp(); final LauncherActivityInfo testApp = getSettingsApp(); // Open all apps and wait for load complete final UiObject2 appsContainer = TestViewHelpers.openAllApps(); Wait.atMost(null, Condition.minChildCount(appsContainer, 2), DEFAULT_UI_TIMEOUT); final AppIconMenu menu = mLauncher. pressHome(). switchToAllApps(). getAppIcon(testApp.getLabel().toString()). openMenu(); // Find settings app and verify shortcuts appear when long pressed UiObject2 icon = scrollAndFind(appsContainer, By.text(testApp.getLabel().toString())); // Press icon center until shortcuts appear Point iconCenter = icon.getVisibleCenter(); TestViewHelpers.sendPointer(MotionEvent.ACTION_DOWN, iconCenter); UiObject2 deepShortcutsContainer = TestViewHelpers.findViewById( R.id.deep_shortcuts_container); assertNotNull(deepShortcutsContainer); TestViewHelpers.sendPointer(MotionEvent.ACTION_UP, iconCenter); executeOnLauncher( launcher -> assertTrue("Launcher internal state didn't switch to Showing Menu", isOptionsPopupVisible(launcher))); // Verify that launching a shortcut opens a page with the same text assertTrue(deepShortcutsContainer.getChildCount() > 0); final AppIconMenuItem menuItem = menu.getMenuItem(1); final String itemName = menuItem.getText(); // Pick second children as it starts showing shortcuts. UiObject2 shortcut = deepShortcutsContainer.getChildren().get(1) .findObject(TestViewHelpers.getSelectorForId(R.id.bubble_text)); shortcut.click(); menuItem.launch(); assertTrue(mDevice.wait(Until.hasObject(By.pkg( testApp.getComponentName().getPackageName()) .text(shortcut.getText())), DEFAULT_UI_TIMEOUT)); .text(itemName)), DEFAULT_UI_TIMEOUT)); } }
tests/tapl/com/android/launcher3/tapl/AppIcon.java +12 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.launcher3.tapl; import android.graphics.Point; import android.widget.TextView; import androidx.test.uiautomator.By; Loading Loading @@ -56,4 +57,15 @@ public final class AppIcon { UiObject2 getIcon() { return mIcon; } /** * Long-clicks the icon to open its menu. */ public AppIconMenu openMenu() { final Point iconCenter = mIcon.getVisibleCenter(); mLauncher.longTap(iconCenter.x, iconCenter.y); final UiObject2 deepShortcutsContainer = mLauncher.waitForLauncherObject( "deep_shortcuts_container"); return new AppIconMenu(mLauncher, deepShortcutsContainer); } }
tests/tapl/com/android/launcher3/tapl/AppIconMenu.java 0 → 100644 +46 −0 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.launcher3.tapl; import static org.junit.Assert.assertTrue; import androidx.test.uiautomator.UiObject2; /** * Context menu of an app icon. */ public class AppIconMenu { private final LauncherInstrumentation mLauncher; private final UiObject2 mDeepShortcutsContainer; AppIconMenu(LauncherInstrumentation launcher, UiObject2 deepShortcutsContainer) { mLauncher = launcher; mDeepShortcutsContainer = deepShortcutsContainer; } /** * Returns a menu item with a given number. Fails if it doesn't exist. */ public AppIconMenuItem getMenuItem(int itemNumber) { assertTrue(mDeepShortcutsContainer.getChildCount() > itemNumber); final UiObject2 shortcut = mLauncher.waitForObjectInContainer( mDeepShortcutsContainer.getChildren().get(itemNumber), "bubble_text"); return new AppIconMenuItem(mLauncher, shortcut); } }
tests/tapl/com/android/launcher3/tapl/AppIconMenuItem.java 0 → 100644 +52 −0 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.launcher3.tapl; import static org.junit.Assert.assertTrue; import androidx.test.uiautomator.UiObject2; import androidx.test.uiautomator.Until; /** * Menu item in an app icon menu. */ public class AppIconMenuItem { private final LauncherInstrumentation mLauncher; final UiObject2 mShortcut; AppIconMenuItem(LauncherInstrumentation launcher, UiObject2 shortcut) { mLauncher = launcher; mShortcut = shortcut; } /** * Returns the visible text of the menu item. */ public String getText() { return mShortcut.getText(); } /** * Launches the action for the menu item. */ public Background launch() { assertTrue("Clicking a menu item didn't open a new window: " + mShortcut.getText(), mShortcut.clickAndWait(Until.newWindow(), LauncherInstrumentation.WAIT_TIME_MS)); return new Background(mLauncher); } }