Update settings notification ui tests

Test: atest AppNotificationSettingsTest
Test: atest ZenModeSettingsIntegrationTest
Test: atest ChannelNotificationSettingsTest
Fixes: 126253682
Change-Id: Ie7fc5f177eb418162ecf24b0c4818ee52a8088db
This commit is contained in:
Beverly
2019-02-26 10:38:53 -05:00
parent 986f2ecc55
commit 5588921190
3 changed files with 49 additions and 52 deletions

View File

@@ -41,6 +41,7 @@ import android.app.NotificationManager;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.provider.Settings; import android.provider.Settings;
import android.support.test.uiautomator.UiDevice;
import androidx.test.InstrumentationRegistry; import androidx.test.InstrumentationRegistry;
import androidx.test.espresso.intent.Intents; import androidx.test.espresso.intent.Intents;
@@ -55,7 +56,9 @@ import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
@SmallTest @SmallTest
public class AppNotificationSettingsTest { public class AppNotificationSettingsTest {
private static final String WM_DISMISS_KEYGUARD_COMMAND = "wm dismiss-keyguard";
private UiDevice mUiDevice;
private Context mTargetContext; private Context mTargetContext;
private Instrumentation mInstrumentation; private Instrumentation mInstrumentation;
@@ -68,9 +71,14 @@ public class AppNotificationSettingsTest {
private NotificationChannel mUngroupedChannel; private NotificationChannel mUngroupedChannel;
@Before @Before
public void setUp() { public void setUp() throws Exception {
mInstrumentation = InstrumentationRegistry.getInstrumentation(); mInstrumentation = InstrumentationRegistry.getInstrumentation();
mTargetContext = mInstrumentation.getTargetContext(); mTargetContext = mInstrumentation.getTargetContext();
mUiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
mUiDevice.wakeUp();
mUiDevice.executeShellCommand(WM_DISMISS_KEYGUARD_COMMAND);
mNm = (NotificationManager) mTargetContext.getSystemService(Context.NOTIFICATION_SERVICE); mNm = (NotificationManager) mTargetContext.getSystemService(Context.NOTIFICATION_SERVICE);
mGroup1 = new NotificationChannelGroup(this.getClass().getName() + "1", "group1"); mGroup1 = new NotificationChannelGroup(this.getClass().getName() + "1", "group1");
@@ -87,7 +95,8 @@ public class AppNotificationSettingsTest {
@Test @Test
public void launchNotificationSetting_shouldNotHaveAppInfoLink() { public void launchNotificationSetting_shouldNotHaveAppInfoLink() {
final Intent intent = new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS) 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); mInstrumentation.startActivitySync(intent);
@@ -99,60 +108,38 @@ public class AppNotificationSettingsTest {
@Test @Test
public void launchNotificationSetting_showGroupsWithMultipleChannels() { public void launchNotificationSetting_showGroupsWithMultipleChannels() {
final Intent intent = new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS) 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); mInstrumentation.startActivitySync(intent);
onView(allOf(withText(mGroup1.getName().toString()))).check( onView(allOf(withText(mGroup1.getName().toString()))).check(
matches(isDisplayed())); matches(isDisplayed()));
try { onView(allOf(withText(mGroup1Channel1.getName().toString()))).check(
onView(allOf(withText(mGroup1Channel1.getName().toString()))) matches(isDisplayed()));
.check(matches(isDisplayed())); onView(allOf(withText(mGroup1Channel2.getName().toString()))).check(
fail("Channel erroneously appearing"); matches(isDisplayed()));
} 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();
} }
@Test @Test
public void launchNotificationSetting_showUngroupedChannels() { public void launchNotificationSetting_showUngroupedChannels() {
final Intent intent = new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS) 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); mInstrumentation.startActivitySync(intent);
onView(allOf(withText(mUngroupedChannel.getName().toString()))) onView(allOf(withText(mUngroupedChannel.getName().toString())))
.check(matches(isDisplayed())); .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 @Test
public void launchNotificationSetting_showGroupsWithOneChannel() { public void launchNotificationSetting_showGroupsWithOneChannel() {
final Intent intent = new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS) 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); mInstrumentation.startActivitySync(intent);
onView(allOf(withText(mGroup2.getName().toString())))
.check(matches(isDisplayed()));
onView(allOf(withText(mGroup2Channel1.getName().toString()))) onView(allOf(withText(mGroup2Channel1.getName().toString())))
.check(matches(isDisplayed())); .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, private NotificationChannel createChannel(NotificationChannelGroup group,

View File

@@ -36,6 +36,7 @@ import android.content.Intent;
import android.os.Process; import android.os.Process;
import android.os.ServiceManager; import android.os.ServiceManager;
import android.provider.Settings; import android.provider.Settings;
import android.support.test.uiautomator.UiDevice;
import androidx.test.InstrumentationRegistry; import androidx.test.InstrumentationRegistry;
import androidx.test.filters.SmallTest; import androidx.test.filters.SmallTest;
@@ -48,17 +49,23 @@ import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
@SmallTest @SmallTest
public class ChannelNotificationSettingsTest { public class ChannelNotificationSettingsTest {
private static final String WM_DISMISS_KEYGUARD_COMMAND = "wm dismiss-keyguard";
private UiDevice mUiDevice;
private Context mTargetContext; private Context mTargetContext;
private Instrumentation mInstrumentation; private Instrumentation mInstrumentation;
private NotificationChannel mNotificationChannel; private NotificationChannel mNotificationChannel;
private NotificationManager mNm; private NotificationManager mNm;
@Before @Before
public void setUp() { public void setUp() throws Exception {
mInstrumentation = InstrumentationRegistry.getInstrumentation(); mInstrumentation = InstrumentationRegistry.getInstrumentation();
mTargetContext = mInstrumentation.getTargetContext(); mTargetContext = mInstrumentation.getTargetContext();
mUiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
mUiDevice.wakeUp();
mUiDevice.executeShellCommand(WM_DISMISS_KEYGUARD_COMMAND);
mNm = (NotificationManager) mTargetContext.getSystemService(Context.NOTIFICATION_SERVICE); mNm = (NotificationManager) mTargetContext.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationChannel = new NotificationChannel(this.getClass().getName(), mNotificationChannel = new NotificationChannel(this.getClass().getName(),
this.getClass().getName(), IMPORTANCE_MIN); this.getClass().getName(), IMPORTANCE_MIN);
@@ -69,7 +76,8 @@ public class ChannelNotificationSettingsTest {
public void launchNotificationSetting_shouldNotCrash() { public void launchNotificationSetting_shouldNotCrash() {
final Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS) final Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS)
.putExtra(Settings.EXTRA_APP_PACKAGE, mTargetContext.getPackageName()) .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); mInstrumentation.startActivitySync(intent);
onView(allOf(withText(mNotificationChannel.getName().toString()))).check( onView(allOf(withText(mNotificationChannel.getName().toString()))).check(
@@ -90,12 +98,12 @@ public class ChannelNotificationSettingsTest {
final Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS) final Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS)
.putExtra(Settings.EXTRA_APP_PACKAGE, mTargetContext.getPackageName()) .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); mInstrumentation.startActivitySync(intent);
onView(allOf(withText("Off"), isDisplayed())).check(matches(isDisplayed())); onView(allOf(withText("At your request, Android is blocking this category of notifications"
onView(allOf(withText("Android is blocking this category of notifications from" + " from appearing on this device"))).check(matches(isDisplayed()));
+ " appearing on this device"))).check(matches(isDisplayed()));
try { try {
onView(allOf(withText("On the lock screen"))).check(matches(isDisplayed())); onView(allOf(withText("On the lock screen"))).check(matches(isDisplayed()));

View File

@@ -37,27 +37,29 @@ public class ZenModeSettingsIntegrationTest {
@Test @Test
public void testZenModeSettingsPreferences() { public void testZenModeSettingsPreferences() {
launchZenSettings(); launchZenSettings();
onView(withText("Behavior")).check(matches(isDisplayed())); onView(withText("Calls")).check(matches(isDisplayed()));
onView(withText("Turn on automatically")).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 @Test
public void testZenModeBehaviorPreferences() { public void testZenModeBehaviorPreferences() {
launchZenBehaviorSettings(); 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("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 @Test
public void testZenModeAutomationPreferences() { public void testZenModeAutomationPreferences() {
launchZenAutomationSettings(); launchZenAutomationSettings();
onView(withText("Weekend")).check(matches(isDisplayed())); onView(withText("Sleeping")).check(matches(isDisplayed()));
onView(withText("Add rule")).check(matches(isDisplayed())); onView(withText("Event")).check(matches(isDisplayed()));
onView(withText("Add more")).check(matches(isDisplayed()));
} }
private void launchZenSettings() { private void launchZenSettings() {