DND settings redesign

Test: robotests
Change-Id: I7b980218feea28e945994c8b7f8a934df6bc11f9
Bug: 78447976
This commit is contained in:
Julia Reynolds
2018-05-04 08:54:53 -04:00
committed by Beverly
parent f95ed0925b
commit 200da8978f
22 changed files with 1027 additions and 259 deletions

View File

@@ -0,0 +1,79 @@
/*
* Copyright (C) 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.notification;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.app.NotificationManager;
import android.content.Context;
import androidx.preference.Preference;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settingslib.core.lifecycle.Lifecycle;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.shadows.ShadowApplication;
import org.robolectric.util.ReflectionHelpers;
@RunWith(SettingsRobolectricTestRunner.class)
public final class ZenModeBehaviorCallsPreferenceControllerTest {
private ZenModeBehaviorCallsPreferenceController mController;
@Mock
private NotificationManager mNotificationManager;
@Mock
private NotificationManager.Policy mPolicy;
private Context mContext;
@Mock
private ZenModeBackend mBackend;
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
ShadowApplication shadowApplication = ShadowApplication.getInstance();
shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNotificationManager);
mContext = RuntimeEnvironment.application;
when(mNotificationManager.getNotificationPolicy()).thenReturn(mPolicy);
mController = new ZenModeBehaviorCallsPreferenceController(
mContext, mock(Lifecycle.class));
ReflectionHelpers.setField(mController, "mBackend", mBackend);
}
@Test
public void testIsAvailable() {
assertTrue(mController.isAvailable());
}
@Test
public void testHasSummary() {
Preference pref = mock(Preference.class);
mController.updateState(pref);
verify(pref).setSummary(any());
}
}

View File

@@ -41,6 +41,7 @@ import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import android.util.ArrayMap;
import com.android.settings.R;
import com.android.settings.notification.AbstractZenModePreferenceController.ZenModeConfigWrapper;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settingslib.core.lifecycle.Lifecycle;
@@ -77,6 +78,7 @@ public class ZenModeBehaviorFooterPreferenceControllerTest {
private Context mContext;
private ContentResolver mContentResolver;
private int mTitleResId = R.string.zen_sound_title;
@Before
public void setup() {
@@ -88,8 +90,8 @@ public class ZenModeBehaviorFooterPreferenceControllerTest {
mContentResolver = RuntimeEnvironment.application.getContentResolver();
when(mNotificationManager.getZenModeConfig()).thenReturn(mZenModeConfig);
mController =
new ZenModeBehaviorFooterPreferenceController(mContext, mock(Lifecycle.class));
mController = new ZenModeBehaviorFooterPreferenceController(
mContext, mock(Lifecycle.class), mTitleResId);
ReflectionHelpers.setField(mController, "mZenModeConfigWrapper", mConfigWrapper);
when(mPreferenceScreen.findPreference(mController.getPreferenceKey()))
@@ -112,13 +114,13 @@ public class ZenModeBehaviorFooterPreferenceControllerTest {
@Test
public void priorityOnly_footerIsAvailable() {
Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_IMPORTANT_INTERRUPTIONS);
assertFalse(mController.isAvailable());
assertTrue(mController.isAvailable());
}
@Test
public void zenModeOff_footerIsNotAvailable() {
public void zenModeOff_footerIsAvailable() {
Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_OFF);
assertFalse(mController.isAvailable());
assertTrue(mController.isAvailable());
}
@Test
@@ -126,7 +128,7 @@ public class ZenModeBehaviorFooterPreferenceControllerTest {
Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_OFF);
mController.updateState(mockPref);
verify(mockPref, never()).setTitle(any(String.class));
verify(mockPref).setTitle(mContext.getString(mTitleResId));
}
@Test
@@ -134,7 +136,7 @@ public class ZenModeBehaviorFooterPreferenceControllerTest {
Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_IMPORTANT_INTERRUPTIONS);
mController.updateState(mockPref);
verify(mockPref, never()).setTitle(any(String.class));
verify(mockPref).setTitle(mContext.getString(mTitleResId));
}
@Test

View File

@@ -0,0 +1,79 @@
/*
* Copyright (C) 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.notification;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.app.NotificationManager;
import android.content.Context;
import androidx.preference.Preference;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settingslib.core.lifecycle.Lifecycle;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.shadows.ShadowApplication;
import org.robolectric.util.ReflectionHelpers;
@RunWith(SettingsRobolectricTestRunner.class)
public final class ZenModeBehaviorMsgEventReminderPreferenceControllerTest {
private ZenModeBehaviorMsgEventReminderPreferenceController mController;
@Mock
private NotificationManager mNotificationManager;
@Mock
private NotificationManager.Policy mPolicy;
private Context mContext;
@Mock
private ZenModeBackend mBackend;
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
ShadowApplication shadowApplication = ShadowApplication.getInstance();
shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNotificationManager);
mContext = RuntimeEnvironment.application;
when(mNotificationManager.getNotificationPolicy()).thenReturn(mPolicy);
mController = new ZenModeBehaviorMsgEventReminderPreferenceController(
mContext, mock(Lifecycle.class));
ReflectionHelpers.setField(mController, "mBackend", mBackend);
}
@Test
public void testIsAvailable() {
assertTrue(mController.isAvailable());
}
@Test
public void testHasSummary() {
Preference pref = mock(Preference.class);
mController.updateState(pref);
verify(pref).setSummary(any());
}
}

View File

@@ -0,0 +1,79 @@
/*
* Copyright (C) 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.notification;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.app.NotificationManager;
import android.content.Context;
import androidx.preference.Preference;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settingslib.core.lifecycle.Lifecycle;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.shadows.ShadowApplication;
import org.robolectric.util.ReflectionHelpers;
@RunWith(SettingsRobolectricTestRunner.class)
public final class ZenModeBehaviorSoundPreferenceControllerTest {
private ZenModeBehaviorSoundPreferenceController mController;
@Mock
private NotificationManager mNotificationManager;
@Mock
private NotificationManager.Policy mPolicy;
private Context mContext;
@Mock
private ZenModeBackend mBackend;
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
ShadowApplication shadowApplication = ShadowApplication.getInstance();
shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNotificationManager);
mContext = RuntimeEnvironment.application;
when(mNotificationManager.getNotificationPolicy()).thenReturn(mPolicy);
mController = new ZenModeBehaviorSoundPreferenceController(
mContext, mock(Lifecycle.class));
ReflectionHelpers.setField(mController, "mBackend", mBackend);
}
@Test
public void testIsAvailable() {
assertTrue(mController.isAvailable());
}
@Test
public void testHasSummary() {
Preference pref = mock(Preference.class);
mController.updateState(pref);
verify(pref).setSummary(any());
}
}

View File

@@ -20,9 +20,9 @@ import static com.google.common.truth.Truth.assertThat;
import static junit.framework.Assert.assertEquals;
import android.app.NotificationManager;
import android.app.NotificationManager.Policy;
import android.content.Context;
import android.provider.SearchIndexableResource;
import android.provider.Settings;
import com.android.settings.R;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
@@ -46,54 +46,140 @@ public class ZenModeSettingsTest {
mBuilder = new ZenModeSettings.SummaryBuilder(mContext);
}
@Test
public void testGetBehaviorSettingSummary_noSoundsCanBypass() {
NotificationManager.Policy policy = new NotificationManager.Policy(0, 0, 0);
final String result = mBuilder.getBehaviorSettingSummary(policy,
Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS);
String totalSilence = mContext.getString(R.string.zen_mode_no_exceptions);
assertEquals(totalSilence, result);
}
@Test
public void testGetBehaviorSettingSummary_alarmsAndMedia() {
NotificationManager.Policy policy = new NotificationManager.Policy(
NotificationManager.Policy.PRIORITY_CATEGORY_ALARMS
| NotificationManager.Policy.PRIORITY_CATEGORY_MEDIA,
0, 0);
final String result = mBuilder.getBehaviorSettingSummary(policy,
Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS);
String alarmsAndMedia = mContext.getString(R.string.join_two_items,
mContext.getString(R.string.zen_mode_alarms),
mContext.getString(R.string.zen_mode_media).toLowerCase());
assertEquals(alarmsAndMedia, result);
}
@Test
public void testBlockedEffectsSummary_none() {
NotificationManager.Policy policy = new NotificationManager.Policy(0, 0, 0, 0);
Policy policy = new Policy(0, 0, 0, 0);
assertEquals(mContext.getString(R.string.zen_mode_restrict_notifications_summary_muted),
mBuilder.getBlockedEffectsSummary(policy));
}
@Test
public void testBlockedEffectsSummary_some() {
NotificationManager.Policy policy = new NotificationManager.Policy(
0, 0, 0, NotificationManager.Policy.SUPPRESSED_EFFECT_PEEK);
Policy policy = new Policy(0, 0, 0, NotificationManager.Policy.SUPPRESSED_EFFECT_PEEK);
assertEquals(mContext.getString(R.string.zen_mode_restrict_notifications_summary_custom),
mBuilder.getBlockedEffectsSummary(policy));
}
@Test
public void testBlockedEffectsSummary_all() {
NotificationManager.Policy policy = new NotificationManager.Policy(
0, 0, 0, 511);
Policy policy = new Policy(0, 0, 0, 511);
assertEquals(mContext.getString(R.string.zen_mode_restrict_notifications_summary_hidden),
mBuilder.getBlockedEffectsSummary(policy));
}
@Test
public void testGetMsgEventReminderSettingSummary_none() {
Policy policy = new Policy(0, 0, 0, 0);
assertThat(mBuilder.getMsgEventReminderSettingSummary(policy)).isEqualTo("None");
}
@Test
public void testGetMsgEventReminderSettingSummary_single() {
Policy policy = new Policy(
Policy.PRIORITY_CATEGORY_ALARMS | Policy.PRIORITY_CATEGORY_EVENTS, 0 , 0 , 0);
assertThat(mBuilder.getMsgEventReminderSettingSummary(policy)).isEqualTo("Events");
}
@Test
public void testGetMsgEventReminderSettingSummary_someMsgs() {
Policy policy = new Policy(Policy.PRIORITY_CATEGORY_MESSAGES, 0,
Policy.PRIORITY_SENDERS_CONTACTS , 0);
assertThat(mBuilder.getMsgEventReminderSettingSummary(policy)).isEqualTo("Some messages");
policy = new Policy(Policy.PRIORITY_CATEGORY_MESSAGES, 0,
Policy.PRIORITY_SENDERS_STARRED , 0);
assertThat(mBuilder.getMsgEventReminderSettingSummary(policy)).isEqualTo("Some messages");
}
@Test
public void testGetMsgEventReminderSettingSummary_msgs() {
Policy policy = new Policy(Policy.PRIORITY_CATEGORY_MESSAGES, 0, 0, 0);
assertThat(mBuilder.getMsgEventReminderSettingSummary(policy)).isEqualTo("Messages");
}
@Test
public void testGetMsgEventReminderSettingSummary_someMsgsAndOther() {
Policy policy = new Policy(
Policy.PRIORITY_CATEGORY_MESSAGES | Policy.PRIORITY_CATEGORY_REMINDERS,
0, Policy.PRIORITY_SENDERS_CONTACTS , 0);
assertThat(mBuilder.getMsgEventReminderSettingSummary(policy))
.isEqualTo("Some messages and reminders");
}
@Test
public void testGetMsgEventReminderSettingSummary_someMsgsAndAllOthers() {
Policy policy = new Policy(Policy.PRIORITY_CATEGORY_EVENTS
| Policy.PRIORITY_CATEGORY_MESSAGES | Policy.PRIORITY_CATEGORY_REMINDERS,
0, Policy.PRIORITY_SENDERS_CONTACTS , 0);
assertThat(mBuilder.getMsgEventReminderSettingSummary(policy))
.isEqualTo("Some messages, events, and reminders");
}
@Test
public void testGetMsgEventReminderSettingSummary_noMsgsAndOther() {
Policy policy = new Policy(
Policy.PRIORITY_CATEGORY_EVENTS | Policy.PRIORITY_CATEGORY_REMINDERS,
0,0, 0);
assertThat(mBuilder.getMsgEventReminderSettingSummary(policy))
.isEqualTo("Events and reminders");
}
@Test
public void testGetCallsSettingSummary_none() {
Policy policy = new Policy(0, 0, 0, 0);
assertThat(mBuilder.getCallsSettingSummary(policy)).isEqualTo("None");
}
@Test
public void testGetCallsSettingSummary_contacts() {
Policy policy = new Policy(Policy.PRIORITY_CATEGORY_ALARMS | Policy.PRIORITY_CATEGORY_CALLS,
Policy.PRIORITY_SENDERS_CONTACTS, 0, 0);
assertThat(mBuilder.getCallsSettingSummary(policy)).isEqualTo("From contacts only");
}
@Test
public void testGetCallsSettingSummary_repeatCallers() {
Policy policy = new Policy(Policy.PRIORITY_CATEGORY_REPEAT_CALLERS, 0, 0, 0);
assertThat(mBuilder.getCallsSettingSummary(policy)).isEqualTo("From repeat callers only");
}
@Test
public void testGetCallsSettingSummary_starredRepeatCallers() {
Policy policy = new Policy(
Policy.PRIORITY_CATEGORY_REPEAT_CALLERS | Policy.PRIORITY_CATEGORY_CALLS,
Policy.PRIORITY_SENDERS_STARRED, 0, 0);
assertThat(mBuilder.getCallsSettingSummary(policy))
.isEqualTo("From starred contacts and repeat callers");
}
@Test
public void testGetSoundSettingSummary_allOff() {
Policy policy = new Policy(0, 0, 0, 0);
assertThat(mBuilder.getSoundSettingSummary(policy)).isEqualTo("Muted");
}
@Test
public void testGetSoundSettingSummary_allOn() {
Policy policy = new Policy(Policy.PRIORITY_CATEGORY_ALARMS | Policy.PRIORITY_CATEGORY_SYSTEM
| Policy.PRIORITY_CATEGORY_MEDIA, 0, 0, 0);
assertThat(mBuilder.getSoundSettingSummary(policy))
.isEqualTo("Muted, but allow alarms, media, and touch sounds");
}
@Test
public void testGetSoundSettingSummary_allOffButOne() {
Policy policy = new Policy(Policy.PRIORITY_CATEGORY_MEDIA, 0, 0, 0);
assertThat(mBuilder.getSoundSettingSummary(policy)).isEqualTo("Muted, but allow media");
}
@Test
public void testGetSoundSettingSummary_allOffButTwo() {
Policy policy = new Policy(Policy.PRIORITY_CATEGORY_SYSTEM
| Policy.PRIORITY_CATEGORY_MEDIA, 0, 0, 0);
assertThat(mBuilder.getSoundSettingSummary(policy))
.isEqualTo("Muted, but allow media and touch sounds");
}
@Test
public void searchProvider_shouldIndexDefaultXml() {
final List<SearchIndexableResource> sir = ZenModeSettings.SEARCH_INDEX_DATA_PROVIDER