1 package com.android.settings; 2 3 import static androidx.test.espresso.Espresso.onView; 4 import static androidx.test.espresso.assertion.ViewAssertions.matches; 5 import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; 6 import static androidx.test.espresso.matcher.ViewMatchers.withText; 7 8 import android.content.Context; 9 import android.content.Intent; 10 import android.provider.Settings; 11 import android.support.test.uiautomator.UiDevice; 12 13 import androidx.test.InstrumentationRegistry; 14 import androidx.test.filters.LargeTest; 15 import androidx.test.runner.AndroidJUnit4; 16 17 import org.junit.Before; 18 import org.junit.Test; 19 import org.junit.runner.RunWith; 20 21 @RunWith(AndroidJUnit4.class) 22 @LargeTest 23 public class ZenModeSettingsIntegrationTest { 24 private static final String WM_DISMISS_KEYGUARD_COMMAND = "wm dismiss-keyguard"; 25 26 private Context mContext; 27 private UiDevice mUiDevice; 28 29 @Before setUp()30 public void setUp() throws Exception { 31 mContext = InstrumentationRegistry.getTargetContext(); 32 mUiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()); 33 mUiDevice.wakeUp(); 34 mUiDevice.executeShellCommand(WM_DISMISS_KEYGUARD_COMMAND); 35 } 36 37 @Test testZenModeSettingsPreferences()38 public void testZenModeSettingsPreferences() { 39 launchZenSettings(); 40 onView(withText("Calls")).check(matches(isDisplayed())); 41 onView(withText("SMS, MMS, and messaging apps")).check(matches(isDisplayed())); 42 onView(withText("Restrict notifications")).check(matches(isDisplayed())); 43 onView(withText("Duration")).check(matches(isDisplayed())); 44 onView(withText("Schedules")).check(matches(isDisplayed())); 45 } 46 47 @Test testZenModeBehaviorPreferences()48 public void testZenModeBehaviorPreferences() { 49 launchZenBehaviorSettings(); 50 onView(withText("Calls")).check(matches(isDisplayed())); 51 onView(withText("SMS, MMS, and messaging apps")).check(matches(isDisplayed())); 52 onView(withText("Restrict notifications")).check(matches(isDisplayed())); 53 onView(withText("Duration")).check(matches(isDisplayed())); 54 onView(withText("Schedules")).check(matches(isDisplayed())); 55 } 56 57 @Test testZenModeAutomationPreferences()58 public void testZenModeAutomationPreferences() { 59 launchZenAutomationSettings(); 60 onView(withText("Sleeping")).check(matches(isDisplayed())); 61 onView(withText("Event")).check(matches(isDisplayed())); 62 onView(withText("Add more")).check(matches(isDisplayed())); 63 } 64 launchZenSettings()65 private void launchZenSettings() { 66 Intent settingsIntent = new Intent(Settings.ACTION_ZEN_MODE_SETTINGS) 67 .setPackage(mContext.getPackageName()) 68 .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 69 mContext.startActivity(settingsIntent); 70 } 71 launchZenAutomationSettings()72 private void launchZenAutomationSettings() { 73 Intent settingsIntent = new Intent(Settings.ACTION_ZEN_MODE_AUTOMATION_SETTINGS) 74 .setPackage(mContext.getPackageName()) 75 .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 76 mContext.startActivity(settingsIntent); 77 } 78 launchZenBehaviorSettings()79 private void launchZenBehaviorSettings() { 80 Intent settingsIntent = new Intent(Settings.ACTION_ZEN_MODE_PRIORITY_SETTINGS) 81 .setPackage(mContext.getPackageName()) 82 .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 83 mContext.startActivity(settingsIntent); 84 } 85 }