1 /*
2  * Copyright (C) 2016 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 android.platform.helpers;
18 
19 import androidx.test.uiautomator.Direction;
20 import androidx.test.uiautomator.UiObject2;
21 
22 public interface IChromeHelper extends IAppHelper {
23     public enum MenuItem {
24         BOOKMARKS("Bookmarks"),
25         NEW_TAB("New tab"),
26         CLOSE_ALL_TABS("Close all tabs"),
27         DOWNLOADS("Downloads"),
28         HISTORY("History"),
29         SETTINGS("Settings");
30 
31         private String mDisplayName;
32 
MenuItem(String displayName)33         MenuItem(String displayName) {
34             mDisplayName = displayName;
35         }
36 
37         @Override
toString()38         public String toString() {
39             return mDisplayName;
40         }
41     }
42 
43     public enum ClearRange {
44         PAST_HOUR("past hour"),
45         PAST_DAY("past day"),
46         PAST_WEEK("past week"),
47         LAST_4_WEEKS("last 4 weeks"),
48         BEGINNING_OF_TIME("beginning of time");
49 
50         private String mDisplayName;
51 
ClearRange(String displayName)52         ClearRange(String displayName) {
53             mDisplayName = displayName;
54         }
55 
56         @Override
toString()57         public String toString() {
58             return mDisplayName;
59         }
60     }
61 
62     /**
63      * Setup expectations: Chrome is open and on a standard page, i.e. a tab is open.
64      *
65      * <p>This method will open the URL supplied and block until the page is open.
66      */
openUrl(String url)67     public abstract void openUrl(String url);
68 
69     /**
70      * Setup expectations: Chrome is open on a page.
71      *
72      * <p>This method will scroll the page as directed and block until idle.
73      */
flingPage(Direction dir)74     public abstract void flingPage(Direction dir);
75 
76     /**
77      * Setup expectations: Chrome is open on a page.
78      *
79      * <p>This method will open the overload menu, indicated by three dots and block until open.
80      */
openMenu()81     public abstract void openMenu();
82 
83     /**
84      * Setup expectations: Chrome is open on a page.
85      *
86      * <p>This method will open provided item in the menu.
87      */
openMenuItem(IChromeHelper.MenuItem menuItem)88     public abstract void openMenuItem(IChromeHelper.MenuItem menuItem);
89 
90     /**
91      * Setup expectations: Chrome is open on a page.
92      *
93      * <p>This method will open provided item in the menu.
94      *
95      * @param menuItem The name of menu item.
96      * @param waitForPageLoad Wait for the page to load completely or not.
97      */
openMenuItem(IChromeHelper.MenuItem menuItem, boolean waitForPageLoad)98     public default void openMenuItem(IChromeHelper.MenuItem menuItem, boolean waitForPageLoad) {
99         throw new UnsupportedOperationException("Not yet implemented.");
100     }
101 
102     /**
103      * Setup expectations: Chrome is open on a page.
104      *
105      * <p>This method will add a new tab and land on the webpage of given url.
106      */
addNewTab(String url)107     public abstract void addNewTab(String url);
108 
109     /**
110      * Setup expectations: Chrome is open on a page.
111      *
112      * <p>This method will go to tab switcher by clicking tab switcher button.
113      */
openTabSwitcher()114     public abstract void openTabSwitcher();
115 
116     /**
117      * Setup expectations: Chrome is open on a page or in tab switcher.
118      *
119      * <p>This method will switch to the tab at tabIndex.
120      */
switchTab(int tabIndex)121     public abstract void switchTab(int tabIndex);
122 
123     /**
124      * Setup expectations: Chrome has at least one tab.
125      *
126      * <p>This method will close all tabs.
127      */
closeAllTabs()128     public abstract void closeAllTabs();
129 
130     /**
131      * Setup expectations: Chrome is open on a page and the tabs are treated as apps.
132      *
133      * <p>This method will change the settings to treat tabs inside of Chrome and block until Chrome
134      * is open on the original tab.
135      */
mergeTabs()136     public abstract void mergeTabs();
137 
138     /**
139      * Setup expectations: Chrome is open on a page and the tabs are merged.
140      *
141      * <p>This method will change the settings to treat tabs outside of Chrome and block until
142      * Chrome is open on the original tab.
143      */
unmergeTabs()144     public abstract void unmergeTabs();
145 
146     /**
147      * Setup expectations: Chrome is open on a page.
148      *
149      * <p>This method will reload the page by clicking the refresh button, and block until the page
150      * is reopened.
151      */
reloadPage()152     public abstract void reloadPage();
153 
154     /**
155      * Setup expectations: Chrome is open on a page.
156      *
157      * <p>This method will stop loading page then reload the page by clicking the refresh button,
158      * and block until the page is reopened.
159      */
stopAndReloadPage()160     public default void stopAndReloadPage() {
161         throw new UnsupportedOperationException("Not yet implemented.");
162     }
163 
164     /**
165      * Setup expectations: Chrome is open on a page.
166      *
167      * <p>This method will stop loading page then reload the page by clicking the refresh button,
168      *
169      * @param waitForPageLoad Wait for the page to load completely or not.
170      */
stopAndReloadPage(boolean waitForPageLoad)171     public default void stopAndReloadPage(boolean waitForPageLoad) {
172         throw new UnsupportedOperationException("Not yet implemented.");
173     }
174 
175     /**
176      * Setup expectations: Chrome is open on a page.
177      *
178      * <p>This method is getter for contentDescription of Tab elements.
179      */
getTabDescription()180     public abstract String getTabDescription();
181 
182     /**
183      * Setup expectations: Chrome is open on a History page.
184      *
185      * <p>This method clears browser history for provided period of time.
186      */
clearBrowsingData(IChromeHelper.ClearRange range)187     public abstract void clearBrowsingData(IChromeHelper.ClearRange range);
188 
189     /**
190      * Setup expectations: Chrome is open on a Downloads page.
191      *
192      * <p>This method checks header is displayed on Downloads page.
193      */
checkIfDownloadsOpened()194     public abstract void checkIfDownloadsOpened();
195 
196     /**
197      * Setup expectations: Chrome is open on a Settings page.
198      *
199      * <p>This method clicks on Privacy setting on Settings page.
200      */
openPrivacySettings()201     public abstract void openPrivacySettings();
202 
203     /**
204      * Setup expectations: Chrome is open on a page.
205      *
206      * <p>This method will add the current page to Bookmarks
207      */
addCurrentPageToBookmark()208     public default boolean addCurrentPageToBookmark() {
209         throw new UnsupportedOperationException("Not yet implemented.");
210     }
211 
212     /**
213      * Setup expectations: Chrome is open on a Bookmarks page.
214      *
215      * <p>This method selects a bookmark from the Bookmarks page.
216      *
217      * @param index The Index of bookmark to select.
218      */
openBookmark(int index)219     public default void openBookmark(int index) {
220         throw new UnsupportedOperationException("Not yet implemented.");
221     }
222 
223     /**
224      * Setup expectations: Chrome is open on a Bookmarks page.
225      *
226      * <p>This method selects a bookmark from the Bookmarks page.
227      *
228      * @param bookmarkName The string of the target bookmark to select.
229      * @param waitForPageLoad Wait for the page to load completely or not.
230      */
openBookmark(String bookmarkName, boolean waitForPageLoad)231     public default void openBookmark(String bookmarkName, boolean waitForPageLoad) {
232         throw new UnsupportedOperationException("Not yet implemented.");
233     }
234 
235     /**
236      * Setup expectations: Chrome is open on a page.
237      *
238      * <p>Selects the link with specific text.
239      *
240      * @param linkText The text of the link to select.
241      */
selectLink(String linkText)242     public default void selectLink(String linkText) {
243         throw new UnsupportedOperationException("Not yet implemented.");
244     }
245 
246     /**
247      * Setup expectations: Chrome is open on a page.
248      *
249      * <p>Performs a scroll gesture on the page.
250      *
251      * @param dir The direction on the page to scroll.
252      * @param percent The distance to scroll as a percentage of the page's visible size.
253      */
scrollPage(Direction dir, float percent)254     public default void scrollPage(Direction dir, float percent) {
255         throw new UnsupportedOperationException("Not yet implemented.");
256     }
257 
258     /**
259      * Setup expectations: Chrome is open on a page.
260      *
261      * <p>Get the UiObject2 of the page screen.
262      */
getWebPage()263     public default UiObject2 getWebPage() {
264         throw new UnsupportedOperationException("Not yet implemented.");
265     }
266 
267     /**
268      * Setup expectation: Chrome was loading a web page.
269      *
270      * <p>Returns a boolean to state if current page is loaded.
271      */
isWebPageLoaded()272     public default boolean isWebPageLoaded() {
273         throw new UnsupportedOperationException("Not yet implemented.");
274     }
275 
276     /**
277      * Setup expectation: Chrome was loading a web page.
278      *
279      * <p>Checks number of active tabs.
280      */
tabsCount(int number)281     public default void tabsCount(int number) {
282         throw new UnsupportedOperationException("Not yet implemented.");
283     }
284 }
285