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