1 /*
2  * Copyright (C) 2015 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.documentsui.bots;
18 
19 import static junit.framework.Assert.assertFalse;
20 import static junit.framework.Assert.assertTrue;
21 
22 import android.content.Context;
23 
24 import androidx.test.uiautomator.By;
25 import androidx.test.uiautomator.UiDevice;
26 import androidx.test.uiautomator.UiObjectNotFoundException;
27 
28 import java.util.Map;
29 
30 /**
31  * A test helper class that provides support for controlling menu items.
32  */
33 public class MenuBot extends Bots.BaseBot {
34 
MenuBot( UiDevice device, Context context, int timeout)35     public MenuBot(
36             UiDevice device, Context context, int timeout) {
37         super(device, context, timeout);
38     }
39 
hasMenuItem(String menuLabel)40     public boolean hasMenuItem(String menuLabel) throws UiObjectNotFoundException {
41         return mDevice.findObject(By.text(menuLabel)) != null;
42     }
43 
hasMenuItemByDesc(String menuDesc)44     public boolean hasMenuItemByDesc(String menuDesc) throws UiObjectNotFoundException {
45         return mDevice.findObject(By.desc(menuDesc)) != null;
46     }
47 
assertPresentMenuItems(Map<String, Boolean> menuStates)48     public void assertPresentMenuItems(Map<String, Boolean> menuStates) throws Exception {
49         for (String key : menuStates.keySet()) {
50             if (menuStates.get(key)) {
51                 assertTrue(key + " expected to be shown", hasMenuItem(key));
52             } else {
53                 assertFalse(key + " expected not to be shown", hasMenuItem(key));
54             }
55         }
56     }
57 }
58