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 com.android.settingslib.drawer; 18 19 import static android.support.test.espresso.Espresso.onView; 20 import static android.support.test.espresso.assertion.ViewAssertions.doesNotExist; 21 import static android.support.test.espresso.assertion.ViewAssertions.matches; 22 import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; 23 import static android.support.test.espresso.matcher.ViewMatchers.withContentDescription; 24 25 import android.app.Instrumentation; 26 import android.content.Intent; 27 import android.support.test.InstrumentationRegistry; 28 import android.support.test.filters.SmallTest; 29 import android.support.test.rule.ActivityTestRule; 30 import android.support.test.runner.AndroidJUnit4; 31 32 import org.junit.Before; 33 import org.junit.Rule; 34 import org.junit.Test; 35 import org.junit.runner.RunWith; 36 import org.mockito.MockitoAnnotations; 37 38 @RunWith(AndroidJUnit4.class) 39 @SmallTest 40 public class SettingsDrawerActivityTest { 41 42 @Rule 43 public ActivityTestRule<TestActivity> mActivityRule = 44 new ActivityTestRule<>(TestActivity.class, true, true); 45 46 @Before 47 public void setUp() throws Exception { 48 MockitoAnnotations.initMocks(this); 49 } 50 51 @Test 52 public void startActivityWithNoExtra_showNoNavUp() { 53 Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation(); 54 instrumentation.startActivitySync(new Intent(instrumentation.getTargetContext(), 55 TestActivity.class)); 56 57 onView(withContentDescription(com.android.internal.R.string.action_bar_up_description)) 58 .check(doesNotExist()); 59 } 60 61 @Test 62 public void startActivityWithExtraToHideMenu_showNavUp() { 63 Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation(); 64 Intent intent = new Intent(instrumentation.getTargetContext(), TestActivity.class) 65 .putExtra(TestActivity.EXTRA_SHOW_MENU, false); 66 instrumentation.startActivitySync(intent); 67 68 onView(withContentDescription(com.android.internal.R.string.action_bar_up_description)) 69 .check(doesNotExist()); 70 } 71 72 @Test 73 public void startActivityWithExtraToShowMenu_showNavUp() { 74 Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation(); 75 Intent intent = new Intent(instrumentation.getTargetContext(), TestActivity.class) 76 .putExtra(TestActivity.EXTRA_SHOW_MENU, true); 77 instrumentation.startActivitySync(intent); 78 79 onView(withContentDescription(com.android.internal.R.string.action_bar_up_description)) 80 .check(matches(isDisplayed())); 81 } 82 83 /** 84 * Test Activity in this test. 85 * 86 * Use this activity because SettingsDrawerActivity hasn't been registered in its 87 * AndroidManifest.xml 88 */ 89 public static class TestActivity extends SettingsDrawerActivity {} 90 } 91