import android.content.Context;
import android.content.Intent;
import android.provider.Settings;
+import android.support.test.uiautomator.UiDevice;
import androidx.test.InstrumentationRegistry;
import androidx.test.espresso.intent.Intents;
@RunWith(AndroidJUnit4.class)
@SmallTest
public class AppNotificationSettingsTest {
+ private static final String WM_DISMISS_KEYGUARD_COMMAND = "wm dismiss-keyguard";
+ private UiDevice mUiDevice;
private Context mTargetContext;
private Instrumentation mInstrumentation;
private NotificationChannel mUngroupedChannel;
@Before
- public void setUp() {
+ public void setUp() throws Exception {
mInstrumentation = InstrumentationRegistry.getInstrumentation();
mTargetContext = mInstrumentation.getTargetContext();
+
+ mUiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
+ mUiDevice.wakeUp();
+ mUiDevice.executeShellCommand(WM_DISMISS_KEYGUARD_COMMAND);
+
mNm = (NotificationManager) mTargetContext.getSystemService(Context.NOTIFICATION_SERVICE);
mGroup1 = new NotificationChannelGroup(this.getClass().getName() + "1", "group1");
@Test
public void launchNotificationSetting_shouldNotHaveAppInfoLink() {
final Intent intent = new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS)
- .putExtra(Settings.EXTRA_APP_PACKAGE, mTargetContext.getPackageName());
+ .putExtra(Settings.EXTRA_APP_PACKAGE, mTargetContext.getPackageName())
+ .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mInstrumentation.startActivitySync(intent);
@Test
public void launchNotificationSetting_showGroupsWithMultipleChannels() {
final Intent intent = new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS)
- .putExtra(Settings.EXTRA_APP_PACKAGE, mTargetContext.getPackageName());
+ .putExtra(Settings.EXTRA_APP_PACKAGE, mTargetContext.getPackageName())
+ .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mInstrumentation.startActivitySync(intent);
onView(allOf(withText(mGroup1.getName().toString()))).check(
matches(isDisplayed()));
- try {
- onView(allOf(withText(mGroup1Channel1.getName().toString())))
- .check(matches(isDisplayed()));
- fail("Channel erroneously appearing");
- } catch (Exception e) {
- // expected
- }
- // links to group page
- Intents.init();
- onView(allOf(withText(mGroup1.getName().toString()))).perform(click());
- intended(allOf(hasExtra(EXTRA_SHOW_FRAGMENT,
- ChannelGroupNotificationSettings.class.getName())));
- Intents.release();
+ onView(allOf(withText(mGroup1Channel1.getName().toString()))).check(
+ matches(isDisplayed()));
+ onView(allOf(withText(mGroup1Channel2.getName().toString()))).check(
+ matches(isDisplayed()));
}
@Test
public void launchNotificationSetting_showUngroupedChannels() {
final Intent intent = new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS)
- .putExtra(Settings.EXTRA_APP_PACKAGE, mTargetContext.getPackageName());
+ .putExtra(Settings.EXTRA_APP_PACKAGE, mTargetContext.getPackageName())
+ .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mInstrumentation.startActivitySync(intent);
onView(allOf(withText(mUngroupedChannel.getName().toString())))
.check(matches(isDisplayed()));
- // links directly to channel page
- Intents.init();
- onView(allOf(withText(mUngroupedChannel.getName().toString()))).perform(click());
- intended(allOf(hasExtra(EXTRA_SHOW_FRAGMENT, ChannelNotificationSettings.class.getName())));
- Intents.release();
}
@Test
public void launchNotificationSetting_showGroupsWithOneChannel() {
final Intent intent = new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS)
- .putExtra(Settings.EXTRA_APP_PACKAGE, mTargetContext.getPackageName());
+ .putExtra(Settings.EXTRA_APP_PACKAGE, mTargetContext.getPackageName())
+ .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mInstrumentation.startActivitySync(intent);
+ onView(allOf(withText(mGroup2.getName().toString())))
+ .check(matches(isDisplayed()));
onView(allOf(withText(mGroup2Channel1.getName().toString())))
.check(matches(isDisplayed()));
- try {
- onView(allOf(withText(mGroup2.getName().toString()))).check(
- matches(isDisplayed()));
- fail("Group erroneously appearing");
- } catch (Exception e) {
- // expected
- }
-
- // links directly to channel page
- Intents.init();
- onView(allOf(withText(mGroup2Channel1.getName().toString()))).perform(click());
- intended(allOf(hasExtra(EXTRA_SHOW_FRAGMENT, ChannelNotificationSettings.class.getName())));
- Intents.release();
}
private NotificationChannel createChannel(NotificationChannelGroup group,
import android.os.Process;
import android.os.ServiceManager;
import android.provider.Settings;
+import android.support.test.uiautomator.UiDevice;
import androidx.test.InstrumentationRegistry;
import androidx.test.filters.SmallTest;
@RunWith(AndroidJUnit4.class)
@SmallTest
public class ChannelNotificationSettingsTest {
+ private static final String WM_DISMISS_KEYGUARD_COMMAND = "wm dismiss-keyguard";
+ private UiDevice mUiDevice;
private Context mTargetContext;
private Instrumentation mInstrumentation;
private NotificationChannel mNotificationChannel;
private NotificationManager mNm;
@Before
- public void setUp() {
+ public void setUp() throws Exception {
mInstrumentation = InstrumentationRegistry.getInstrumentation();
mTargetContext = mInstrumentation.getTargetContext();
+ mUiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
+ mUiDevice.wakeUp();
+ mUiDevice.executeShellCommand(WM_DISMISS_KEYGUARD_COMMAND);
+
mNm = (NotificationManager) mTargetContext.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationChannel = new NotificationChannel(this.getClass().getName(),
this.getClass().getName(), IMPORTANCE_MIN);
public void launchNotificationSetting_shouldNotCrash() {
final Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS)
.putExtra(Settings.EXTRA_APP_PACKAGE, mTargetContext.getPackageName())
- .putExtra(Settings.EXTRA_CHANNEL_ID, mNotificationChannel.getId());
+ .putExtra(Settings.EXTRA_CHANNEL_ID, mNotificationChannel.getId())
+ .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mInstrumentation.startActivitySync(intent);
onView(allOf(withText(mNotificationChannel.getName().toString()))).check(
final Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS)
.putExtra(Settings.EXTRA_APP_PACKAGE, mTargetContext.getPackageName())
- .putExtra(Settings.EXTRA_CHANNEL_ID, blocked.getId());
+ .putExtra(Settings.EXTRA_CHANNEL_ID, blocked.getId())
+ .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mInstrumentation.startActivitySync(intent);
- onView(allOf(withText("Off"), isDisplayed())).check(matches(isDisplayed()));
- onView(allOf(withText("Android is blocking this category of notifications from"
- + " appearing on this device"))).check(matches(isDisplayed()));
+ onView(allOf(withText("At your request, Android is blocking this category of notifications"
+ + " from appearing on this device"))).check(matches(isDisplayed()));
try {
onView(allOf(withText("On the lock screen"))).check(matches(isDisplayed()));
@Test
public void testZenModeSettingsPreferences() {
launchZenSettings();
- onView(withText("Behavior")).check(matches(isDisplayed()));
- onView(withText("Turn on automatically")).check(matches(isDisplayed()));
+ onView(withText("Calls")).check(matches(isDisplayed()));
+ onView(withText("SMS, MMS, and messaging apps")).check(matches(isDisplayed()));
+ onView(withText("Restrict notifications")).check(matches(isDisplayed()));
+ onView(withText("Duration")).check(matches(isDisplayed()));
+ onView(withText("Schedules")).check(matches(isDisplayed()));
}
@Test
public void testZenModeBehaviorPreferences() {
launchZenBehaviorSettings();
- onView(withText("Alarms")).check(matches(isDisplayed()));
- onView(withText("Media and system feedback")).check(matches(isDisplayed()));
- onView(withText("Reminders")).check(matches(isDisplayed()));
- onView(withText("Events")).check(matches(isDisplayed()));
- onView(withText("Messages")).check(matches(isDisplayed()));
onView(withText("Calls")).check(matches(isDisplayed()));
- onView(withText("Repeat callers")).check(matches(isDisplayed()));
+ onView(withText("SMS, MMS, and messaging apps")).check(matches(isDisplayed()));
+ onView(withText("Restrict notifications")).check(matches(isDisplayed()));
+ onView(withText("Duration")).check(matches(isDisplayed()));
+ onView(withText("Schedules")).check(matches(isDisplayed()));
}
@Test
public void testZenModeAutomationPreferences() {
launchZenAutomationSettings();
- onView(withText("Weekend")).check(matches(isDisplayed()));
- onView(withText("Add rule")).check(matches(isDisplayed()));
+ onView(withText("Sleeping")).check(matches(isDisplayed()));
+ onView(withText("Event")).check(matches(isDisplayed()));
+ onView(withText("Add more")).check(matches(isDisplayed()));
}
private void launchZenSettings() {