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.test.uiautomator.By;
22 import androidx.test.uiautomator.BySelector;
23 import androidx.test.uiautomator.UiObject2;
24 
25 import com.android.launcher3.testing.TestProtocol;
26 
27 import java.util.regex.Pattern;
28 
29 /**
30  * App icon, whether in all apps or in workspace/
31  */
32 public final class AppIcon extends Launchable {
33 
34     private static final Pattern LONG_CLICK_EVENT = Pattern.compile("onAllAppsItemLongClick");
35 
AppIcon(LauncherInstrumentation launcher, UiObject2 icon)36     AppIcon(LauncherInstrumentation launcher, UiObject2 icon) {
37         super(launcher, icon);
38     }
39 
getAppIconSelector(String appName, LauncherInstrumentation launcher)40     static BySelector getAppIconSelector(String appName, LauncherInstrumentation launcher) {
41         return By.clazz(TextView.class).text(appName).pkg(launcher.getLauncherPackageName());
42     }
43 
44     /**
45      * Long-clicks the icon to open its menu.
46      */
openMenu()47     public AppIconMenu openMenu() {
48         try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck()) {
49             return new AppIconMenu(mLauncher, mLauncher.clickAndGet(
50                     mObject, "deep_shortcuts_container", LONG_CLICK_EVENT));
51         }
52     }
53 
54     @Override
addExpectedEventsForLongClick()55     protected void addExpectedEventsForLongClick() {
56         mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN, LONG_CLICK_EVENT);
57     }
58 
59     @Override
getLongPressIndicator()60     protected String getLongPressIndicator() {
61         return "deep_shortcuts_container";
62     }
63 
64     @Override
expectActivityStartEvents()65     protected void expectActivityStartEvents() {
66         mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN, LauncherInstrumentation.EVENT_START);
67     }
68 }
69