• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.settings.notification;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 import static junit.framework.Assert.assertEquals;
21 
22 import android.app.NotificationManager;
23 import android.app.NotificationManager.Policy;
24 import android.content.Context;
25 import android.provider.SearchIndexableResource;
26 
27 import com.android.settings.R;
28 import com.android.settings.testutils.SettingsRobolectricTestRunner;
29 
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.junit.runner.RunWith;
33 import org.robolectric.RuntimeEnvironment;
34 
35 import java.util.List;
36 
37 @RunWith(SettingsRobolectricTestRunner.class)
38 public class ZenModeSettingsTest {
39 
40     private ZenModeSettings.SummaryBuilder mBuilder;
41     private Context mContext;
42 
43     @Before
setUp()44     public void setUp() {
45         mContext = RuntimeEnvironment.application.getApplicationContext();
46         mBuilder = new ZenModeSettings.SummaryBuilder(mContext);
47     }
48 
49     @Test
testBlockedEffectsSummary_none()50     public void testBlockedEffectsSummary_none() {
51         Policy policy = new Policy(0, 0, 0, 0);
52         assertEquals(mContext.getString(R.string.zen_mode_restrict_notifications_summary_muted),
53                 mBuilder.getBlockedEffectsSummary(policy));
54     }
55 
56     @Test
testBlockedEffectsSummary_some()57     public void testBlockedEffectsSummary_some() {
58         Policy policy = new Policy(0, 0, 0, NotificationManager.Policy.SUPPRESSED_EFFECT_PEEK);
59         assertEquals(mContext.getString(R.string.zen_mode_restrict_notifications_summary_custom),
60                 mBuilder.getBlockedEffectsSummary(policy));
61     }
62 
63     @Test
testBlockedEffectsSummary_all()64     public void testBlockedEffectsSummary_all() {
65         Policy policy = new Policy(0, 0, 0, 511);
66         assertEquals(mContext.getString(R.string.zen_mode_restrict_notifications_summary_hidden),
67                 mBuilder.getBlockedEffectsSummary(policy));
68     }
69 
70     @Test
testGetMsgEventReminderSettingSummary_none()71     public void testGetMsgEventReminderSettingSummary_none() {
72         Policy policy = new Policy(0, 0, 0, 0);
73         assertThat(mBuilder.getMsgEventReminderSettingSummary(policy)).isEqualTo("None");
74     }
75 
76     @Test
testGetMsgEventReminderSettingSummary_single()77     public void testGetMsgEventReminderSettingSummary_single() {
78         Policy policy = new Policy(
79                 Policy.PRIORITY_CATEGORY_ALARMS | Policy.PRIORITY_CATEGORY_EVENTS, 0 , 0 , 0);
80         assertThat(mBuilder.getMsgEventReminderSettingSummary(policy)).isEqualTo("Events");
81     }
82 
83     @Test
testGetMsgEventReminderSettingSummary_someMsgs()84     public void testGetMsgEventReminderSettingSummary_someMsgs() {
85         Policy policy = new Policy(Policy.PRIORITY_CATEGORY_MESSAGES, 0,
86                 Policy.PRIORITY_SENDERS_CONTACTS , 0);
87         assertThat(mBuilder.getMsgEventReminderSettingSummary(policy)).isEqualTo("Some messages");
88 
89         policy = new Policy(Policy.PRIORITY_CATEGORY_MESSAGES, 0,
90                 Policy.PRIORITY_SENDERS_STARRED , 0);
91         assertThat(mBuilder.getMsgEventReminderSettingSummary(policy)).isEqualTo("Some messages");
92     }
93 
94     @Test
testGetMsgEventReminderSettingSummary_msgs()95     public void testGetMsgEventReminderSettingSummary_msgs() {
96         Policy policy = new Policy(Policy.PRIORITY_CATEGORY_MESSAGES, 0, 0, 0);
97         assertThat(mBuilder.getMsgEventReminderSettingSummary(policy)).isEqualTo("Messages");
98     }
99 
100     @Test
testGetMsgEventReminderSettingSummary_someMsgsAndOther()101     public void testGetMsgEventReminderSettingSummary_someMsgsAndOther() {
102         Policy policy = new Policy(
103                 Policy.PRIORITY_CATEGORY_MESSAGES | Policy.PRIORITY_CATEGORY_REMINDERS,
104                 0, Policy.PRIORITY_SENDERS_CONTACTS , 0);
105         assertThat(mBuilder.getMsgEventReminderSettingSummary(policy))
106                 .isEqualTo("Some messages and reminders");
107     }
108 
109     @Test
testGetMsgEventReminderSettingSummary_someMsgsAndAllOthers()110     public void testGetMsgEventReminderSettingSummary_someMsgsAndAllOthers() {
111         Policy policy = new Policy(Policy.PRIORITY_CATEGORY_EVENTS
112                 | Policy.PRIORITY_CATEGORY_MESSAGES | Policy.PRIORITY_CATEGORY_REMINDERS,
113                 0, Policy.PRIORITY_SENDERS_CONTACTS , 0);
114         assertThat(mBuilder.getMsgEventReminderSettingSummary(policy))
115                 .isEqualTo("Some messages, events, and reminders");
116     }
117 
118     @Test
testGetMsgEventReminderSettingSummary_noMsgsAndOther()119     public void testGetMsgEventReminderSettingSummary_noMsgsAndOther() {
120         Policy policy = new Policy(
121                 Policy.PRIORITY_CATEGORY_EVENTS | Policy.PRIORITY_CATEGORY_REMINDERS,
122                 0,0, 0);
123         assertThat(mBuilder.getMsgEventReminderSettingSummary(policy))
124                 .isEqualTo("Events and reminders");
125     }
126 
127     @Test
testGetCallsSettingSummary_none()128     public void testGetCallsSettingSummary_none() {
129         Policy policy = new Policy(0, 0, 0, 0);
130         assertThat(mBuilder.getCallsSettingSummary(policy)).isEqualTo("None");
131     }
132 
133     @Test
testGetCallsSettingSummary_contacts()134     public void testGetCallsSettingSummary_contacts() {
135         Policy policy = new Policy(Policy.PRIORITY_CATEGORY_ALARMS | Policy.PRIORITY_CATEGORY_CALLS,
136                 Policy.PRIORITY_SENDERS_CONTACTS, 0, 0);
137         assertThat(mBuilder.getCallsSettingSummary(policy)).isEqualTo("From contacts");
138     }
139 
140     @Test
testGetCallsSettingSummary_repeatCallers()141     public void testGetCallsSettingSummary_repeatCallers() {
142         Policy policy = new Policy(Policy.PRIORITY_CATEGORY_REPEAT_CALLERS, 0, 0, 0);
143         assertThat(mBuilder.getCallsSettingSummary(policy)).isEqualTo("From repeat callers");
144     }
145 
146     @Test
testGetCallsSettingSummary_starredRepeatCallers()147     public void testGetCallsSettingSummary_starredRepeatCallers() {
148         Policy policy = new Policy(
149                 Policy.PRIORITY_CATEGORY_REPEAT_CALLERS | Policy.PRIORITY_CATEGORY_CALLS,
150                 Policy.PRIORITY_SENDERS_STARRED, 0, 0);
151         assertThat(mBuilder.getCallsSettingSummary(policy))
152                 .isEqualTo("From starred contacts and repeat callers");
153     }
154 
155     @Test
testGetSoundSettingSummary_allOff()156     public void testGetSoundSettingSummary_allOff() {
157         Policy policy = new Policy(0, 0, 0, 0);
158         assertThat(mBuilder.getSoundSettingSummary(policy)).isEqualTo("Muted");
159     }
160 
161     @Test
testGetSoundSettingSummary_allOn()162     public void testGetSoundSettingSummary_allOn() {
163         Policy policy = new Policy(Policy.PRIORITY_CATEGORY_ALARMS | Policy.PRIORITY_CATEGORY_SYSTEM
164                 | Policy.PRIORITY_CATEGORY_MEDIA, 0, 0, 0);
165         assertThat(mBuilder.getSoundSettingSummary(policy))
166                 .isEqualTo("Muted, but allow alarms, media, and touch sounds");
167     }
168 
169     @Test
testGetSoundSettingSummary_allOffButOne()170     public void testGetSoundSettingSummary_allOffButOne() {
171         Policy policy = new Policy(Policy.PRIORITY_CATEGORY_MEDIA, 0, 0, 0);
172         assertThat(mBuilder.getSoundSettingSummary(policy)).isEqualTo("Muted, but allow media");
173     }
174 
175     @Test
testGetSoundSettingSummary_allOffButTwo()176     public void testGetSoundSettingSummary_allOffButTwo() {
177         Policy policy = new Policy(Policy.PRIORITY_CATEGORY_SYSTEM
178                 | Policy.PRIORITY_CATEGORY_MEDIA, 0, 0, 0);
179         assertThat(mBuilder.getSoundSettingSummary(policy))
180                 .isEqualTo("Muted, but allow media and touch sounds");
181     }
182 
183     @Test
searchProvider_shouldIndexDefaultXml()184     public void searchProvider_shouldIndexDefaultXml() {
185         final List<SearchIndexableResource> sir = ZenModeSettings.SEARCH_INDEX_DATA_PROVIDER
186                 .getXmlResourcesToIndex(mContext, true /* enabled */);
187 
188         assertThat(sir).hasSize(1);
189         assertThat(sir.get(0).xmlResId).isEqualTo(R.xml.zen_mode_settings);
190     }
191 }
192