Redesign zen visual effects screens

Test: robotests
Bug: 78448988
Change-Id: I3040c1103d76c75601e82e3660a2ace202837ec2
Merged-In: I3040c1103d76c75601e82e3660a2ace202837ec2
This commit is contained in:
Julia Reynolds
2018-04-23 12:24:21 -04:00
parent 3f5444b9e4
commit 4cf8bfd5b2
21 changed files with 1507 additions and 60 deletions

View File

@@ -0,0 +1,113 @@
/*
* 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 com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import android.content.Context;
import android.support.v7.preference.Preference.OnPreferenceChangeListener;
import android.support.v7.preference.PreferenceViewHolder;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.Switch;
import com.android.settings.R;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.widget.MasterSwitchPreference;
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RuntimeEnvironment;
@RunWith(SettingsRobolectricTestRunner.class)
public class ZenCustomRadioButtonPreferenceTest {
private Context mContext;
@Before
public void setUp() {
mContext = RuntimeEnvironment.application;
}
@Test
public void createNewPreference_shouldSetLayout() {
final ZenCustomRadioButtonPreference preference
= new ZenCustomRadioButtonPreference(mContext);
assertThat(preference.getLayoutResource()).isEqualTo(R.layout.preference_two_target_radio);
assertThat(preference.getWidgetLayoutResource())
.isEqualTo(R.layout.preference_widget_gear);
}
@Test
public void setChecked_shouldUpdateButtonCheckedState() {
final ZenCustomRadioButtonPreference preference =
new ZenCustomRadioButtonPreference(mContext);
final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(
LayoutInflater.from(mContext).inflate(
R.layout.preference_two_target_radio, null));
final RadioButton toggle = (RadioButton) holder.findViewById(android.R.id.checkbox);
preference.onBindViewHolder(holder);
preference.setChecked(true);
assertThat(toggle.isChecked()).isTrue();
preference.setChecked(false);
assertThat(toggle.isChecked()).isFalse();
}
@Test
public void clickRadioButton_shouldNotifyRadioButtonClicked() {
final ZenCustomRadioButtonPreference preference
= new ZenCustomRadioButtonPreference(mContext);
final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(
LayoutInflater.from(mContext).inflate(R.layout.preference_two_target_radio, null));
final View toggle = holder.findViewById(R.id.checkbox_frame);
ZenCustomRadioButtonPreference.OnRadioButtonClickListener l = mock(
ZenCustomRadioButtonPreference.OnRadioButtonClickListener.class);
preference.setOnRadioButtonClickListener(l);
preference.onBindViewHolder(holder);
toggle.performClick();
verify(l).onRadioButtonClick(preference);
}
@Test
public void clickWidgetView_shouldNotifyWidgetClicked() {
final ZenCustomRadioButtonPreference preference =
new ZenCustomRadioButtonPreference(mContext);
final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(
LayoutInflater.from(mContext).inflate(R.layout.preference_two_target_radio, null));
final View widgetView = holder.findViewById(android.R.id.widget_frame);
ZenCustomRadioButtonPreference.OnGearClickListener l = mock(
ZenCustomRadioButtonPreference.OnGearClickListener.class);
preference.setOnGearClickListener(l);
preference.onBindViewHolder(holder);
widgetView.performClick();
verify(l).onGearClick(preference);
}
}

View File

@@ -0,0 +1,138 @@
/*
* 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 android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_AMBIENT;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_BADGE;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_FULL_SCREEN_INTENT;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_LIGHTS;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_NOTIFICATION_LIST;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_PEEK;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_SCREEN_OFF;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_SCREEN_ON;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_STATUS_BAR;
import static com.google.common.truth.Truth.assertThat;
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 android.support.v7.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.widget.FooterPreference;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.shadows.ShadowApplication;
import org.robolectric.util.ReflectionHelpers;
@RunWith(SettingsRobolectricTestRunner.class)
public class ZenFooterPreferenceControllerTest {
private ZenFooterPreferenceController mController;
@Mock
private ZenModeBackend mBackend;
@Mock
private FooterPreference mockPref;
private Context mContext;
@Mock
private PreferenceScreen mScreen;
@Mock NotificationManager mNotificationManager;
private static final String PREF_KEY = "main_pref";
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
ShadowApplication shadowApplication = ShadowApplication.getInstance();
mContext = shadowApplication.getApplicationContext();
shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNotificationManager);
when(mNotificationManager.getNotificationPolicy()).thenReturn(
mock(NotificationManager.Policy.class));
mController = new ZenFooterPreferenceController(
mContext, mock(Lifecycle.class), PREF_KEY);
ReflectionHelpers.setField(mController, "mBackend", mBackend);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mockPref);
}
@Test
public void isAvailable_noVisEffects() {
mBackend.mPolicy = new NotificationManager.Policy(0, 0, 0, 0);
assertThat(mController.isAvailable()).isTrue();
}
@Test
public void isAvailable_someVisEffects() {
mBackend.mPolicy = new NotificationManager.Policy(0, 0, 0, 2);
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void isAvailable_allVisEffects() {
int allSuppressed = SUPPRESSED_EFFECT_SCREEN_OFF
| SUPPRESSED_EFFECT_SCREEN_ON
| SUPPRESSED_EFFECT_FULL_SCREEN_INTENT
| SUPPRESSED_EFFECT_AMBIENT
| SUPPRESSED_EFFECT_STATUS_BAR
| SUPPRESSED_EFFECT_BADGE
| SUPPRESSED_EFFECT_LIGHTS
| SUPPRESSED_EFFECT_PEEK
| SUPPRESSED_EFFECT_NOTIFICATION_LIST;
mBackend.mPolicy = new NotificationManager.Policy(0, 0, 0, allSuppressed);
assertThat(mController.isAvailable()).isTrue();
}
@Test
public void updateSummary_noVisEffects() {
mBackend.mPolicy = new NotificationManager.Policy(0, 0, 0, 0);
mController.updateState(mockPref);
verify(mockPref).setTitle(R.string.zen_mode_restrict_notifications_mute_footer);
}
@Test
public void getSummary_someVisEffects() {
mBackend.mPolicy = new NotificationManager.Policy(0, 0, 0, 2);
mController.updateState(mockPref);
verify(mockPref).setTitle(null);
}
@Test
public void getSummary_allVisEffects() {
int allSuppressed = SUPPRESSED_EFFECT_SCREEN_OFF
| SUPPRESSED_EFFECT_SCREEN_ON
| SUPPRESSED_EFFECT_FULL_SCREEN_INTENT
| SUPPRESSED_EFFECT_AMBIENT
| SUPPRESSED_EFFECT_STATUS_BAR
| SUPPRESSED_EFFECT_BADGE
| SUPPRESSED_EFFECT_LIGHTS
| SUPPRESSED_EFFECT_PEEK
| SUPPRESSED_EFFECT_NOTIFICATION_LIST;
mBackend.mPolicy = new NotificationManager.Policy(0, 0, 0, allSuppressed);
mController.updateState(mockPref);
verify(mockPref).setTitle(R.string.zen_mode_restrict_notifications_hide_footer);
}
}

View File

@@ -74,29 +74,23 @@ public class ZenModeSettingsTest {
@Test
public void testBlockedEffectsSummary_none() {
NotificationManager.Policy policy = new NotificationManager.Policy(0, 0, 0, 0);
assertEquals("Never", mBuilder.getBlockedEffectsSummary(policy));
assertEquals(mContext.getString(R.string.zen_mode_restrict_notifications_summary_muted),
mBuilder.getBlockedEffectsSummary(policy));
}
@Test
public void testBlockedEffectsSummary_screen_on() {
public void testBlockedEffectsSummary_some() {
NotificationManager.Policy policy = new NotificationManager.Policy(
0, 0, 0, NotificationManager.Policy.SUPPRESSED_EFFECT_PEEK);
assertEquals("When screen is on", mBuilder.getBlockedEffectsSummary(policy));
assertEquals(mContext.getString(R.string.zen_mode_restrict_notifications_summary_custom),
mBuilder.getBlockedEffectsSummary(policy));
}
@Test
public void testBlockedEffectsSummary_screen_off() {
public void testBlockedEffectsSummary_all() {
NotificationManager.Policy policy = new NotificationManager.Policy(
0, 0, 0, NotificationManager.Policy.SUPPRESSED_EFFECT_AMBIENT);
assertEquals("When screen is off", mBuilder.getBlockedEffectsSummary(policy));
}
@Test
public void testBlockedEffectsSummary_both() {
NotificationManager.Policy policy = new NotificationManager.Policy(0, 0, 0,
NotificationManager.Policy.SUPPRESSED_EFFECT_NOTIFICATION_LIST
| NotificationManager.Policy.SUPPRESSED_EFFECT_LIGHTS);
assertEquals("When screen is off, When screen is on",
0, 0, 0, 511);
assertEquals(mContext.getString(R.string.zen_mode_restrict_notifications_summary_hidden),
mBuilder.getBlockedEffectsSummary(policy));
}

View File

@@ -0,0 +1,141 @@
/*
* 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 android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_AMBIENT;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_BADGE;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_FULL_SCREEN_INTENT;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_LIGHTS;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_NOTIFICATION_LIST;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_PEEK;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_SCREEN_OFF;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_SCREEN_ON;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_STATUS_BAR;
import static com.android.internal.logging.nano.MetricsProto.MetricsEvent
.ACTION_ZEN_SOUND_AND_VIS_EFFECTS;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.app.NotificationManager;
import android.content.Context;
import android.support.v7.preference.PreferenceScreen;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.widget.DisabledCheckBoxPreference;
import com.android.settings.widget.RadioButtonPreference;
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.shadows.ShadowApplication;
import org.robolectric.util.ReflectionHelpers;
@RunWith(SettingsRobolectricTestRunner.class)
public class ZenModeVisEffectsAllPreferenceControllerTest {
private ZenModeVisEffectsAllPreferenceController mController;
@Mock
private ZenModeBackend mBackend;
@Mock
private ZenCustomRadioButtonPreference mockPref;
private Context mContext;
private FakeFeatureFactory mFeatureFactory;
@Mock
private PreferenceScreen mScreen;
@Mock NotificationManager mNotificationManager;
private static final String PREF_KEY = "main_pref";
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
ShadowApplication shadowApplication = ShadowApplication.getInstance();
mContext = shadowApplication.getApplicationContext();
mFeatureFactory = FakeFeatureFactory.setupForTest();
shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNotificationManager);
when(mNotificationManager.getNotificationPolicy()).thenReturn(
mock(NotificationManager.Policy.class));
mController = new ZenModeVisEffectsAllPreferenceController(
mContext, mock(Lifecycle.class), PREF_KEY);
ReflectionHelpers.setField(mController, "mBackend", mBackend);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mockPref);
mController.displayPreference(mScreen);
}
@Test
public void isAvailable() {
assertTrue(mController.isAvailable());
}
@Test
public void updateState_notChecked() {
mBackend.mPolicy = new NotificationManager.Policy(0, 0, 0, 1);
mController.updateState(mockPref);
verify(mockPref).setChecked(false);
}
@Test
public void updateState_checked() {
int allSuppressed = SUPPRESSED_EFFECT_SCREEN_OFF
| SUPPRESSED_EFFECT_SCREEN_ON
| SUPPRESSED_EFFECT_FULL_SCREEN_INTENT
| SUPPRESSED_EFFECT_AMBIENT
| SUPPRESSED_EFFECT_STATUS_BAR
| SUPPRESSED_EFFECT_BADGE
| SUPPRESSED_EFFECT_LIGHTS
| SUPPRESSED_EFFECT_PEEK
| SUPPRESSED_EFFECT_NOTIFICATION_LIST;
mBackend.mPolicy = new NotificationManager.Policy(0, 0, 0, allSuppressed);
mController.updateState(mockPref);
verify(mockPref).setChecked(true);
}
@Test
public void onPreferenceChanged_checkedTrue() {
int allSuppressed = SUPPRESSED_EFFECT_SCREEN_OFF
| SUPPRESSED_EFFECT_SCREEN_ON
| SUPPRESSED_EFFECT_FULL_SCREEN_INTENT
| SUPPRESSED_EFFECT_AMBIENT
| SUPPRESSED_EFFECT_STATUS_BAR
| SUPPRESSED_EFFECT_BADGE
| SUPPRESSED_EFFECT_LIGHTS
| SUPPRESSED_EFFECT_PEEK
| SUPPRESSED_EFFECT_NOTIFICATION_LIST;
mBackend.mPolicy = new NotificationManager.Policy(0, 0, 0, 1);
mController.onRadioButtonClick(mockPref);
verify(mBackend).saveVisualEffectsPolicy(allSuppressed, true);
verify(mFeatureFactory.metricsFeatureProvider).action(eq(mContext),
eq(ACTION_ZEN_SOUND_AND_VIS_EFFECTS),
eq(true));
}
}

View File

@@ -0,0 +1,167 @@
/*
* 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 android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_AMBIENT;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_BADGE;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_FULL_SCREEN_INTENT;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_LIGHTS;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_NOTIFICATION_LIST;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_PEEK;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_SCREEN_OFF;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_SCREEN_ON;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_STATUS_BAR;
import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.ACTION_ZEN_CUSTOM;
import static com.android.internal.logging.nano.MetricsProto.MetricsEvent
.ACTION_ZEN_SOUND_AND_VIS_EFFECTS;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
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 android.support.v7.preference.PreferenceScreen;
import com.android.settings.testutils.FakeFeatureFactory;
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.shadows.ShadowApplication;
import org.robolectric.util.ReflectionHelpers;
@RunWith(SettingsRobolectricTestRunner.class)
public class ZenModeVisEffectsCustomPreferenceControllerTest {
private ZenModeVisEffectsCustomPreferenceController mController;
@Mock
private ZenModeBackend mBackend;
@Mock
private ZenCustomRadioButtonPreference mockPref;
private Context mContext;
private FakeFeatureFactory mFeatureFactory;
@Mock
private PreferenceScreen mScreen;
@Mock NotificationManager mNotificationManager;
private static final String PREF_KEY = "main_pref";
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
ShadowApplication shadowApplication = ShadowApplication.getInstance();
mContext = shadowApplication.getApplicationContext();
mFeatureFactory = FakeFeatureFactory.setupForTest();
shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNotificationManager);
when(mNotificationManager.getNotificationPolicy()).thenReturn(
mock(NotificationManager.Policy.class));
mController = new ZenModeVisEffectsCustomPreferenceController(
mContext, mock(Lifecycle.class), PREF_KEY);
ReflectionHelpers.setField(mController, "mBackend", mBackend);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mockPref);
}
@Test
public void isAvailable_menuOff_noVisEffects() {
mBackend.mPolicy = new NotificationManager.Policy(0, 0, 0, 0);
mController.mShowMenuSelected = false;
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void isAvailable_menuOn_noVisEffects() {
mBackend.mPolicy = new NotificationManager.Policy(0, 0, 0, 0);
mController.mShowMenuSelected = true;
assertThat(mController.isAvailable()).isTrue();
}
@Test
public void isAvailable_menuOn_visEffects() {
mBackend.mPolicy = new NotificationManager.Policy(0, 0, 0, 1);
mController.mShowMenuSelected = false;
assertThat(mController.isAvailable()).isTrue();
}
@Test
public void updateState_notChecked_noVisEffects() {
mBackend.mPolicy = new NotificationManager.Policy(0, 0, 0, 0);
mController.updateState(mockPref);
verify(mockPref).setChecked(false);
}
@Test
public void updateState_notChecked_allVisEffects() {
int allSuppressed = SUPPRESSED_EFFECT_SCREEN_OFF
| SUPPRESSED_EFFECT_SCREEN_ON
| SUPPRESSED_EFFECT_FULL_SCREEN_INTENT
| SUPPRESSED_EFFECT_AMBIENT
| SUPPRESSED_EFFECT_STATUS_BAR
| SUPPRESSED_EFFECT_BADGE
| SUPPRESSED_EFFECT_LIGHTS
| SUPPRESSED_EFFECT_PEEK
| SUPPRESSED_EFFECT_NOTIFICATION_LIST;
mBackend.mPolicy = new NotificationManager.Policy(0, 0, 0, allSuppressed);
mController.updateState(mockPref);
verify(mockPref).setChecked(false);
}
@Test
public void updateState_checked() {
mBackend.mPolicy = new NotificationManager.Policy(0, 0, 0, 2);
mController.updateState(mockPref);
verify(mockPref).setChecked(true);
}
@Test
public void updateState_listeners() {
mBackend.mPolicy = new NotificationManager.Policy(0, 0, 0, 2);
mController.updateState(mockPref);
verify(mockPref).setOnGearClickListener(any());
verify(mockPref).setOnRadioButtonClickListener(any());
}
@Test
public void select() {
int interruptiveSuppressed = SUPPRESSED_EFFECT_FULL_SCREEN_INTENT
| SUPPRESSED_EFFECT_AMBIENT
| SUPPRESSED_EFFECT_LIGHTS
| SUPPRESSED_EFFECT_PEEK;
mBackend.mPolicy = new NotificationManager.Policy(0, 0, 0, 1);
mController.select();
verify(mBackend).savePolicy(anyInt(), anyInt(), anyInt(), eq(interruptiveSuppressed));
verify(mFeatureFactory.metricsFeatureProvider).action(eq(mContext),
eq(ACTION_ZEN_CUSTOM),
eq(true));
}
}

View File

@@ -0,0 +1,132 @@
/*
* 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 android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_AMBIENT;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_BADGE;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_FULL_SCREEN_INTENT;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_LIGHTS;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_NOTIFICATION_LIST;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_PEEK;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_SCREEN_OFF;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_SCREEN_ON;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_STATUS_BAR;
import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.ACTION_ZEN_SOUND_ONLY;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.app.NotificationManager;
import android.content.Context;
import android.support.v7.preference.PreferenceScreen;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.widget.DisabledCheckBoxPreference;
import com.android.settings.widget.RadioButtonPreference;
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.shadows.ShadowApplication;
import org.robolectric.util.ReflectionHelpers;
@RunWith(SettingsRobolectricTestRunner.class)
public class ZenModeVisEffectsNonePreferenceControllerTest {
private ZenModeVisEffectsNonePreferenceController mController;
@Mock
private ZenModeBackend mBackend;
@Mock
private ZenCustomRadioButtonPreference mockPref;
private Context mContext;
private FakeFeatureFactory mFeatureFactory;
@Mock
private PreferenceScreen mScreen;
@Mock NotificationManager mNotificationManager;
private static final String PREF_KEY = "main_pref";
private static final int PREF_METRICS = 1;
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
ShadowApplication shadowApplication = ShadowApplication.getInstance();
mContext = shadowApplication.getApplicationContext();
mFeatureFactory = FakeFeatureFactory.setupForTest();
shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNotificationManager);
when(mNotificationManager.getNotificationPolicy()).thenReturn(
mock(NotificationManager.Policy.class));
mController = new ZenModeVisEffectsNonePreferenceController(
mContext, mock(Lifecycle.class), PREF_KEY);
ReflectionHelpers.setField(mController, "mBackend", mBackend);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mockPref);
mController.displayPreference(mScreen);
}
@Test
public void isAvailable() {
assertTrue(mController.isAvailable());
}
@Test
public void updateState_notChecked() {
mBackend.mPolicy = new NotificationManager.Policy(0, 0, 0, 1);
mController.updateState(mockPref);
verify(mockPref).setChecked(false);
}
@Test
public void updateState_checked() {
mBackend.mPolicy = new NotificationManager.Policy(0, 0, 0, 0);
mController.updateState(mockPref);
verify(mockPref).setChecked(true);
}
@Test
public void onRadioButtonClick() {
int allSuppressed = SUPPRESSED_EFFECT_SCREEN_OFF
| SUPPRESSED_EFFECT_SCREEN_ON
| SUPPRESSED_EFFECT_FULL_SCREEN_INTENT
| SUPPRESSED_EFFECT_AMBIENT
| SUPPRESSED_EFFECT_STATUS_BAR
| SUPPRESSED_EFFECT_BADGE
| SUPPRESSED_EFFECT_LIGHTS
| SUPPRESSED_EFFECT_PEEK
| SUPPRESSED_EFFECT_NOTIFICATION_LIST;
mBackend.mPolicy = new NotificationManager.Policy(0, 0, 0, 1);
mController.onRadioButtonClick(mockPref);
verify(mBackend).saveVisualEffectsPolicy(allSuppressed, false);
verify(mFeatureFactory.metricsFeatureProvider).action(nullable(Context.class),
eq(ACTION_ZEN_SOUND_ONLY),
eq(true));
}
}