• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.android.settings;
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
setUp()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
testZenModeSettingsPreferences()39     public void testZenModeSettingsPreferences() {
40         launchZenSettings();
41         onView(withText("Behavior")).check(matches(isDisplayed()));
42         onView(withText("Turn on automatically")).check(matches(isDisplayed()));
43     }
44 
45     @Test
testZenModeBehaviorPreferences()46     public void testZenModeBehaviorPreferences() {
47         launchZenBehaviorSettings();
48         onView(withText("Alarms")).check(matches(isDisplayed()));
49         onView(withText("Media and system feedback")).check(matches(isDisplayed()));
50         onView(withText("Reminders")).check(matches(isDisplayed()));
51         onView(withText("Events")).check(matches(isDisplayed()));
52         onView(withText("Messages")).check(matches(isDisplayed()));
53         onView(withText("Calls")).check(matches(isDisplayed()));
54         onView(withText("Repeat callers")).check(matches(isDisplayed()));
55     }
56 
57     @Test
testZenModeAutomationPreferences()58     public void testZenModeAutomationPreferences() {
59         launchZenAutomationSettings();
60         onView(withText("Weekend")).check(matches(isDisplayed()));
61         onView(withText("Add rule")).check(matches(isDisplayed()));
62     }
63 
launchZenSettings()64     private void launchZenSettings() {
65         Intent settingsIntent = new Intent(Settings.ACTION_ZEN_MODE_SETTINGS)
66                 .setPackage(mContext.getPackageName())
67                 .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
68         mContext.startActivity(settingsIntent);
69     }
70 
launchZenAutomationSettings()71     private void launchZenAutomationSettings() {
72         Intent settingsIntent = new Intent(Settings.ACTION_ZEN_MODE_AUTOMATION_SETTINGS)
73                 .setPackage(mContext.getPackageName())
74                 .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
75         mContext.startActivity(settingsIntent);
76     }
77 
launchZenBehaviorSettings()78     private void launchZenBehaviorSettings() {
79         Intent settingsIntent = new Intent(Settings.ACTION_ZEN_MODE_PRIORITY_SETTINGS)
80                 .setPackage(mContext.getPackageName())
81                 .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
82         mContext.startActivity(settingsIntent);
83     }
84 }