Converting ShortcutsLaunchTest gesture-stable

By converting to TAPL.

Bug: 110103162
Test; TaplTests

Change-Id: I788405f2e52cc0e29ebf69e58feda46b408e9eb9
This commit is contained in:
Vadim Tryshev 2018-08-23 13:37:38 -07:00
parent b3fe661860
commit ba8957b3c2
6 changed files with 146 additions and 52 deletions

View File

@ -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.
*/

View File

@ -1,22 +1,20 @@
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;
@ -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));
}
}

View File

@ -16,6 +16,7 @@
package com.android.launcher3.tapl;
import android.graphics.Point;
import android.widget.TextView;
import androidx.test.uiautomator.By;
@ -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);
}
}

View File

@ -0,0 +1,46 @@
/*
* 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);
}
}

View File

@ -0,0 +1,52 @@
/*
* 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);
}
}

View File

@ -28,6 +28,13 @@ import android.util.Log;
import android.view.Surface;
import android.view.accessibility.AccessibilityEvent;
import androidx.annotation.NonNull;
import androidx.test.uiautomator.By;
import androidx.test.uiautomator.BySelector;
import androidx.test.uiautomator.UiDevice;
import androidx.test.uiautomator.UiObject2;
import androidx.test.uiautomator.Until;
import com.android.launcher3.TestProtocol;
import com.android.quickstep.SwipeUpSetting;
@ -36,13 +43,6 @@ import org.junit.Assert;
import java.lang.ref.WeakReference;
import java.util.concurrent.TimeoutException;
import androidx.annotation.NonNull;
import androidx.test.uiautomator.By;
import androidx.test.uiautomator.BySelector;
import androidx.test.uiautomator.UiDevice;
import androidx.test.uiautomator.UiObject2;
import androidx.test.uiautomator.Until;
/**
* The main tapl object. The only object that can be explicitly constructed by the using code. It
* produces all other objects.
@ -394,6 +394,11 @@ public final class LauncherInstrumentation {
return mDevice;
}
void longTap(int x, int y) {
mDevice.drag(x, y, x, y, 0);
}
void swipe(int startX, int startY, int endX, int endY) {
executeAndWaitForEvent(
() -> mDevice.swipe(startX, startY, endX, endY, 60),