diff options
author | Vadim Tryshev <vadimt@google.com> | 2018-06-18 19:14:44 -0700 |
---|---|---|
committer | Vadim Tryshev <vadimt@google.com> | 2018-07-20 14:43:05 -0700 |
commit | 2ce6a13f6096ed5e08b252e7e53255ef1027f65e (patch) | |
tree | 40030752744b5a3f170f1dea3cab149aa5c13ab7 /tests/tapl/com/android/launcher3/tapl/AllApps.java | |
parent | 32f91ab991dd2a1c6c0054c86b8700f2b966fd36 (diff) | |
download | android_packages_apps_Trebuchet-2ce6a13f6096ed5e08b252e7e53255ef1027f65e.tar.gz android_packages_apps_Trebuchet-2ce6a13f6096ed5e08b252e7e53255ef1027f65e.tar.bz2 android_packages_apps_Trebuchet-2ce6a13f6096ed5e08b252e7e53255ef1027f65e.zip |
Tapl library
The public API of the library has finalized; flakiness has been removed;
code polished.
Bug: 110103162
Test: TaplTests suite
Change-Id: Ic156bbfeedb1cb9c4a48ef907f97e396e8e81936
Diffstat (limited to 'tests/tapl/com/android/launcher3/tapl/AllApps.java')
-rw-r--r-- | tests/tapl/com/android/launcher3/tapl/AllApps.java | 142 |
1 files changed, 142 insertions, 0 deletions
diff --git a/tests/tapl/com/android/launcher3/tapl/AllApps.java b/tests/tapl/com/android/launcher3/tapl/AllApps.java new file mode 100644 index 000000000..d849e2d80 --- /dev/null +++ b/tests/tapl/com/android/launcher3/tapl/AllApps.java @@ -0,0 +1,142 @@ +/* + * 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 android.support.annotation.NonNull; +import android.support.test.uiautomator.BySelector; +import android.support.test.uiautomator.Direction; +import android.support.test.uiautomator.UiObject2; + +/** + * Operations on AllApps opened from Home. Also a parent for All Apps opened from Overview. + */ +public class AllApps extends LauncherInstrumentation.VisibleContainer { + private static final int MAX_SCROLL_ATTEMPTS = 40; + private static final int MIN_INTERACT_SIZE = 100; + private static final int FLING_SPEED = 12000; + + private final int mHeight; + + AllApps(LauncherInstrumentation launcher) { + super(launcher); + final UiObject2 allAppsContainer = verifyActiveContainer(); + mHeight = allAppsContainer.getVisibleBounds().height(); + } + + @Override + protected LauncherInstrumentation.ContainerType getContainerType() { + return LauncherInstrumentation.ContainerType.ALL_APPS; + } + + /** + * Finds an icon. Fails if the icon doesn't exist. Scrolls the app list when needed to make + * sure the icon is visible. + * + * @param appName name of the app. + * @return The app. + */ + @NonNull + public AppIcon getAppIcon(String appName) { + final UiObject2 allAppsContainer = verifyActiveContainer(); + final BySelector appIconSelector = AppIcon.getAppIconSelector(appName); + if (!allAppsContainer.hasObject(appIconSelector)) { + scrollBackToBeginning(); + int attempts = 0; + while (!allAppsContainer.hasObject(appIconSelector) && + allAppsContainer.scroll(Direction.DOWN, 0.8f)) { + assertTrue("Exceeded max scroll attempts: " + MAX_SCROLL_ATTEMPTS, + ++attempts <= MAX_SCROLL_ATTEMPTS); + verifyActiveContainer(); + } + } + verifyActiveContainer(); + + final UiObject2 appIcon = mLauncher.getObjectInContainer(allAppsContainer, appIconSelector); + ensureIconVisible(appIcon, allAppsContainer); + return new AppIcon(mLauncher, appIcon); + } + + protected int getBottomMarginForSwipeUp() { + return 5; + } + + private void scrollBackToBeginning() { + final UiObject2 allAppsContainer = verifyActiveContainer(); + + int attempts = 0; + allAppsContainer.setGestureMargins(5, 600, 5, getBottomMarginForSwipeUp()); + + while (allAppsContainer.scroll(Direction.UP, 0.5f)) { + mLauncher.waitForIdle(); + verifyActiveContainer(); + + assertTrue("Exceeded max scroll attempts: " + MAX_SCROLL_ATTEMPTS, + ++attempts <= MAX_SCROLL_ATTEMPTS); + } + + mLauncher.waitForIdle(); + verifyActiveContainer(); + } + + private void ensureIconVisible(UiObject2 appIcon, UiObject2 allAppsContainer) { + final int appHeight = appIcon.getVisibleBounds().height(); + if (appHeight < MIN_INTERACT_SIZE) { + // Try to figure out how much percentage of the container needs to be scrolled in order + // to reveal the app icon to have the MIN_INTERACT_SIZE + final float pct = Math.max(((float) (MIN_INTERACT_SIZE - appHeight)) / mHeight, 0.2f); + allAppsContainer.scroll(Direction.DOWN, pct); + mLauncher.waitForIdle(); + verifyActiveContainer(); + } + } + + /** + * Flings forward (down) and waits the fling's end. + */ + public void flingForward() { + final UiObject2 allAppsContainer = verifyActiveContainer(); + // Start the gesture in the center to avoid starting at elements near the top. + allAppsContainer.setGestureMargins(0, 0, 0, mHeight / 2); + allAppsContainer.fling(Direction.DOWN, FLING_SPEED); + verifyActiveContainer(); + } + + /** + * Flings backward (up) and waits the fling's end. + */ + public void flingBackward() { + final UiObject2 allAppsContainer = verifyActiveContainer(); + // Start the gesture in the center, for symmetry with forward. + allAppsContainer.setGestureMargins(0, mHeight / 2, 0, 0); + allAppsContainer.fling(Direction.UP, FLING_SPEED); + verifyActiveContainer(); + } + + /** + * Gets the UI object for AllApps. + * Used by NexusLauncherStrategy.openAllApps(). No one else should use it. + * + * @return container object. + */ + @Deprecated + @NonNull + public UiObject2 getObjectDeprecated() { + return verifyActiveContainer(); + } +} |