1 /* 2 * Copyright (C) 2017 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.settings; 18 19 import static android.support.test.espresso.Espresso.onView; 20 import static android.support.test.espresso.action.ViewActions.click; 21 import static android.support.test.espresso.matcher.ViewMatchers.withText; 22 23 import android.app.Instrumentation; 24 import android.content.Context; 25 import android.content.Intent; 26 import android.support.test.InstrumentationRegistry; 27 import android.support.test.filters.SmallTest; 28 import android.support.test.runner.AndroidJUnit4; 29 import android.support.test.uiautomator.UiDevice; 30 import org.junit.Before; 31 import org.junit.Test; 32 import org.junit.runner.RunWith; 33 34 @RunWith(AndroidJUnit4.class) 35 @SmallTest 36 public class DisplaySettingsTest { 37 38 private Instrumentation mInstrumentation; 39 private Context mContext; 40 private UiDevice mDevice; 41 42 @Before 43 public void setUp() { 44 mInstrumentation = InstrumentationRegistry.getInstrumentation(); 45 mContext = mInstrumentation.getTargetContext(); 46 mDevice = UiDevice.getInstance(mInstrumentation); 47 } 48 49 @Test 50 public void launchBrightnessLevel_shouldNotCrash() { 51 mInstrumentation.startActivitySync( 52 new Intent(mContext, DisplaySettings.class)); 53 onView(withText(mContext.getString(R.string.brightness))).perform(click()); 54 // should not crash 55 mDevice.pressBack(); // dismiss the brightness dialog 56 } 57 } 58