1 /*
2  * Copyright (C) 2020 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 androidx.annotation.NonNull;
20 import androidx.test.uiautomator.UiObject2;
21 
22 /**
23  * View containing overview actions
24  */
25 public class OverviewActions {
26     private final UiObject2 mOverviewActions;
27     private final LauncherInstrumentation mLauncher;
28 
OverviewActions(UiObject2 overviewActions, LauncherInstrumentation launcherInstrumentation)29     OverviewActions(UiObject2 overviewActions, LauncherInstrumentation launcherInstrumentation) {
30         this.mOverviewActions = overviewActions;
31         this.mLauncher = launcherInstrumentation;
32     }
33 
34     /**
35      * Clicks screenshot button and closes screenshot ui.
36      */
37     @NonNull
clickAndDismissScreenshot()38     public Overview clickAndDismissScreenshot() {
39         try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck();
40              LauncherInstrumentation.Closable c = mLauncher.addContextLayer(
41                      "want to click screenshot button and exit screenshot ui")) {
42             mLauncher.setIndefiniteAccessibilityInteractiveUiTimeout(true);
43 
44             UiObject2 screenshot = mLauncher.waitForObjectInContainer(mOverviewActions,
45                     "action_screenshot");
46 
47             mLauncher.clickLauncherObject(screenshot);
48             try (LauncherInstrumentation.Closable c1 = mLauncher.addContextLayer(
49                     "clicked screenshot button")) {
50                 UiObject2 closeScreenshot = mLauncher.waitForSystemUiObject(
51                         "screenshot_dismiss_image");
52                 closeScreenshot.click();
53                 try (LauncherInstrumentation.Closable c2 = mLauncher.addContextLayer(
54                         "dismissed screenshot")) {
55                     return new Overview(mLauncher);
56                 }
57             }
58         } finally {
59             mLauncher.setIndefiniteAccessibilityInteractiveUiTimeout(false);
60         }
61     }
62 
63     /**
64      * Click select button
65      *
66      * @return The select mode buttons that are now shown instead of action buttons.
67      */
68     @NonNull
clickSelect()69     public SelectModeButtons clickSelect() {
70         try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck();
71              LauncherInstrumentation.Closable c =
72                      mLauncher.addContextLayer("want to click select button")) {
73             UiObject2 select = mLauncher.waitForObjectInContainer(mOverviewActions,
74                     "action_select");
75             mLauncher.clickLauncherObject(select);
76             try (LauncherInstrumentation.Closable c1 = mLauncher.addContextLayer(
77                     "clicked select button")) {
78                 return getSelectModeButtons();
79             }
80         }
81     }
82 
83     /**
84      * Gets the Select Mode Buttons.
85      *
86      * @return The Select Mode Buttons.
87      */
88     @NonNull
getSelectModeButtons()89     private SelectModeButtons getSelectModeButtons() {
90         try (LauncherInstrumentation.Closable c = mLauncher.addContextLayer(
91                 "want to get select mode buttons")) {
92             return new SelectModeButtons(mLauncher);
93         }
94     }
95 
96     /**
97      * Clicks split button and enters split select mode.
98      */
99     @NonNull
clickSplit()100     public SplitScreenSelect clickSplit() {
101         try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck();
102              LauncherInstrumentation.Closable c = mLauncher.addContextLayer(
103                      "want to click split button to enter split select mode")) {
104             UiObject2 split = mLauncher.waitForObjectInContainer(mOverviewActions,
105                     "action_split");
106             mLauncher.clickLauncherObject(split);
107             try (LauncherInstrumentation.Closable c2 = mLauncher.addContextLayer(
108                     "clicked split")) {
109                 return new SplitScreenSelect(mLauncher);
110             }
111         }
112     }
113 }
114