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