1/* 2 * Copyright (C) 2014 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.google.android.apps.common.testing.ui.testapp; 18 19import static com.google.android.apps.common.testing.ui.espresso.Espresso.onView; 20import static com.google.android.apps.common.testing.ui.espresso.action.ViewActions.click; 21import static com.google.android.apps.common.testing.ui.espresso.action.ViewActions.longClick; 22import static com.google.android.apps.common.testing.ui.espresso.action.ViewActions.pressMenuKey; 23import static com.google.android.apps.common.testing.ui.espresso.assertion.ViewAssertions.doesNotExist; 24import static com.google.android.apps.common.testing.ui.espresso.assertion.ViewAssertions.matches; 25import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.isDisplayed; 26import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.isRoot; 27import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withId; 28import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withText; 29 30import android.os.Build; 31import android.test.ActivityInstrumentationTestCase2; 32import android.test.suitebuilder.annotation.LargeTest; 33 34/** 35 * Ensures view root ordering works properly. 36 */ 37@LargeTest 38public class MenuTest extends ActivityInstrumentationTestCase2<MenuActivity> { 39 @SuppressWarnings("deprecation") 40 public MenuTest() { 41 // This constructor was deprecated - but we want to support lower API levels. 42 super("com.google.android.apps.common.testing.ui.testapp", MenuActivity.class); 43 } 44 45 @Override 46 public void setUp() throws Exception { 47 super.setUp(); 48 getActivity(); 49 } 50 51 public void testPopupMenu() { 52 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { 53 // popup menus are post honeycomb. 54 return; 55 } 56 onView(withText(R.string.popup_item_1_text)).check(doesNotExist()); 57 onView(withId(R.id.popup_button)).perform(click()); 58 onView(withText(R.string.popup_item_1_text)).check(matches(isDisplayed())).perform(click()); 59 60 onView(withId(R.id.text_menu_result)).check(matches(withText(R.string.popup_item_1_text))); 61 } 62 63 public void testContextMenu() { 64 onView(withText(R.string.context_item_2_text)).check(doesNotExist()); 65 onView(withId(R.id.text_context_menu)).perform(longClick()); 66 onView(withText(R.string.context_item_2_text)).check(matches(isDisplayed())).perform(click()); 67 68 onView(withId(R.id.text_menu_result)).check(matches(withText(R.string.context_item_2_text))); 69 } 70 71 public void testOptionMenu() { 72 onView(withText(R.string.options_item_3_text)).check(doesNotExist()); 73 onView(isRoot()).perform(pressMenuKey()); 74 onView(withText(R.string.options_item_3_text)).check(matches(isDisplayed())).perform(click()); 75 76 onView(withId(R.id.text_menu_result)).check(matches(withText(R.string.options_item_3_text))); 77 } 78} 79