1 /* 2 * Copyright (C) 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.launcher3.tapl; 18 19 import android.widget.TextView; 20 21 import androidx.annotation.NonNull; 22 import androidx.test.uiautomator.By; 23 import androidx.test.uiautomator.BySelector; 24 import androidx.test.uiautomator.UiObject2; 25 26 import com.android.launcher3.testing.shared.TestProtocol; 27 28 import java.util.regex.Pattern; 29 30 /** 31 * App icon, whether in all apps, workspace or the taskbar. 32 */ 33 public abstract class AppIcon extends Launchable { 34 AppIcon(LauncherInstrumentation launcher, UiObject2 icon)35 AppIcon(LauncherInstrumentation launcher, UiObject2 icon) { 36 super(launcher, icon); 37 } 38 getAppIconSelector(String appName, LauncherInstrumentation launcher)39 static BySelector getAppIconSelector(String appName, LauncherInstrumentation launcher) { 40 return By.clazz(TextView.class).text(appName).pkg(launcher.getLauncherPackageName()); 41 } 42 getAnyAppIconSelector()43 static BySelector getAnyAppIconSelector() { 44 return By.clazz(TextView.class); 45 } 46 getLongClickEvent()47 protected abstract Pattern getLongClickEvent(); 48 49 /** 50 * Long-clicks the icon to open its menu. 51 */ openMenu()52 public AppIconMenu openMenu() { 53 try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck()) { 54 return createMenu(mLauncher.clickAndGet( 55 mObject, /* resName= */ "popup_container", getLongClickEvent())); 56 } 57 } 58 59 /** 60 * Long-clicks the icon to open its menu, and looks at the deep shortcuts container only. 61 */ openDeepShortcutMenu()62 public AppIconMenu openDeepShortcutMenu() { 63 try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck()) { 64 return createMenu(mLauncher.clickAndGet( 65 mObject, /* resName= */ "deep_shortcuts_container", getLongClickEvent())); 66 } 67 } 68 createMenu(UiObject2 menu)69 protected abstract AppIconMenu createMenu(UiObject2 menu); 70 71 @Override addExpectedEventsForLongClick()72 protected void addExpectedEventsForLongClick() { 73 mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN, getLongClickEvent()); 74 } 75 76 @Override waitForLongPressConfirmation()77 protected void waitForLongPressConfirmation() { 78 mLauncher.waitForLauncherObject("popup_container"); 79 } 80 81 @Override expectActivityStartEvents()82 protected void expectActivityStartEvents() { 83 mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN, LauncherInstrumentation.EVENT_START); 84 } 85 86 @Override launchableType()87 protected String launchableType() { 88 return "app icon"; 89 } 90 91 /** Return the app name of a icon */ 92 @NonNull getIconName()93 public String getIconName() { 94 return getObject().getText(); 95 } 96 } 97