1 package com.android.settings.notification; 2 3 import static android.support.test.espresso.Espresso.onView; 4 import static android.support.test.espresso.action.ViewActions.click; 5 import static android.support.test.espresso.assertion.ViewAssertions.matches; 6 import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; 7 import static android.support.test.espresso.matcher.ViewMatchers.withText; 8 9 import android.content.Context; 10 import android.content.Intent; 11 import android.provider.Settings; 12 import android.support.test.InstrumentationRegistry; 13 import android.support.test.filters.LargeTest; 14 import android.support.test.runner.AndroidJUnit4; 15 import android.support.test.uiautomator.UiDevice; 16 17 import org.junit.Before; 18 import org.junit.Rule; 19 import org.junit.Test; 20 import org.junit.runner.RunWith; 21 22 @RunWith(AndroidJUnit4.class) 23 @LargeTest 24 public class ZenModeSettingsIntegrationTest { 25 private static final String WM_DISMISS_KEYGUARD_COMMAND = "wm dismiss-keyguard"; 26 27 private Context mContext; 28 private UiDevice mUiDevice; 29 30 @Before 31 public void setUp() throws Exception { 32 mContext = InstrumentationRegistry.getTargetContext(); 33 mUiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()); 34 mUiDevice.wakeUp(); 35 mUiDevice.executeShellCommand(WM_DISMISS_KEYGUARD_COMMAND); 36 } 37 38 @Test 39 public void testAutomaticRulesAppear() { 40 launchZenSettings(); 41 onView(withText("Automatic rules")).check(matches(isDisplayed())); 42 onView(withText("Weekend")).check(matches(isDisplayed())); 43 onView(withText("Add more")).check(matches(isDisplayed())).perform(click()); 44 onView(withText("Choose rule type")).check(matches(isDisplayed())); 45 } 46 47 private void launchZenSettings() { 48 Intent settingsIntent = new Intent(Settings.ACTION_ZEN_MODE_SETTINGS) 49 .setPackage(mContext.getPackageName()) 50 .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 51 mContext.startActivity(settingsIntent); 52 } 53 } 54