• 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 
21 import static org.junit.Assert.assertEquals;
22 
23 import android.app.NotificationManager;
24 import android.app.NotificationManager.Policy;
25 import android.content.Context;
26 import android.provider.SearchIndexableResource;
27 
28 import com.android.settings.R;
29 
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.junit.runner.RunWith;
33 import org.robolectric.RobolectricTestRunner;
34 import org.robolectric.RuntimeEnvironment;
35 
36 import java.util.List;
37 
38 @RunWith(RobolectricTestRunner.class)
39 public class ZenModeSettingsTest {
40 
41     private ZenModeSettings.SummaryBuilder mBuilder;
42     private Context mContext;
43 
44     @Before
setUp()45     public void setUp() {
46         mContext = RuntimeEnvironment.application.getApplicationContext();
47         mBuilder = new ZenModeSettings.SummaryBuilder(mContext);
48     }
49 
50     @Test
testBlockedEffectsSummary_none()51     public void testBlockedEffectsSummary_none() {
52         Policy policy = new Policy(0, 0, 0, 0);
53         assertEquals(mContext.getString(R.string.zen_mode_restrict_notifications_summary_muted),
54                 mBuilder.getBlockedEffectsSummary(policy));
55     }
56 
57     @Test
testBlockedEffectsSummary_some()58     public void testBlockedEffectsSummary_some() {
59         Policy policy = new Policy(0, 0, 0, NotificationManager.Policy.SUPPRESSED_EFFECT_PEEK);
60         assertEquals(mContext.getString(R.string.zen_mode_restrict_notifications_summary_custom),
61                 mBuilder.getBlockedEffectsSummary(policy));
62     }
63 
64     @Test
testBlockedEffectsSummary_all()65     public void testBlockedEffectsSummary_all() {
66         Policy policy = new Policy(0, 0, 0, 511);
67         assertEquals(mContext.getString(R.string.zen_mode_restrict_notifications_summary_hidden),
68                 mBuilder.getBlockedEffectsSummary(policy));
69     }
70 
71     @Test
testGetCallsSettingSummary_none()72     public void testGetCallsSettingSummary_none() {
73         Policy policy = new Policy(0, 0, 0, 0);
74         assertThat(mBuilder.getCallsSettingSummary(policy)).isEqualTo("Don\u2019t allow any calls");
75     }
76 
77     @Test
testGetCallsSettingSummary_contacts()78     public void testGetCallsSettingSummary_contacts() {
79         Policy policy = new Policy(Policy.PRIORITY_CATEGORY_ALARMS | Policy.PRIORITY_CATEGORY_CALLS,
80                 Policy.PRIORITY_SENDERS_CONTACTS, 0, 0);
81         assertThat(mBuilder.getCallsSettingSummary(policy)).isEqualTo("Allow from contacts");
82     }
83 
84     @Test
testGetCallsSettingSummary_repeatCallers()85     public void testGetCallsSettingSummary_repeatCallers() {
86         Policy policy = new Policy(Policy.PRIORITY_CATEGORY_REPEAT_CALLERS, 0, 0, 0);
87         assertThat(mBuilder.getCallsSettingSummary(policy)).isEqualTo("Allow from repeat callers");
88     }
89 
90     @Test
testGetCallsSettingSummary_starredRepeatCallers()91     public void testGetCallsSettingSummary_starredRepeatCallers() {
92         Policy policy = new Policy(
93                 Policy.PRIORITY_CATEGORY_REPEAT_CALLERS | Policy.PRIORITY_CATEGORY_CALLS,
94                 Policy.PRIORITY_SENDERS_STARRED, 0, 0);
95         assertThat(mBuilder.getCallsSettingSummary(policy))
96                 .isEqualTo("Allow from starred contacts and repeat callers");
97     }
98 
99     @Test
testGetSoundSettingSummary_allOff()100     public void testGetSoundSettingSummary_allOff() {
101         Policy policy = new Policy(0, 0, 0, 0);
102         assertThat(mBuilder.getSoundSettingSummary(policy)).isEqualTo("Muted");
103     }
104 
105     @Test
testGetSoundSettingSummary_allOn()106     public void testGetSoundSettingSummary_allOn() {
107         Policy policy = new Policy(Policy.PRIORITY_CATEGORY_ALARMS | Policy.PRIORITY_CATEGORY_SYSTEM
108                 | Policy.PRIORITY_CATEGORY_MEDIA, 0, 0, 0);
109         assertThat(mBuilder.getSoundSettingSummary(policy))
110                 .isEqualTo("Muted, but allow alarms, media, and touch sounds");
111     }
112 
113     @Test
testGetSoundSettingSummary_allOffButOne()114     public void testGetSoundSettingSummary_allOffButOne() {
115         Policy policy = new Policy(Policy.PRIORITY_CATEGORY_MEDIA, 0, 0, 0);
116         assertThat(mBuilder.getSoundSettingSummary(policy)).isEqualTo("Muted, but allow media");
117     }
118 
119     @Test
testGetSoundSettingSummary_allOffButTwo()120     public void testGetSoundSettingSummary_allOffButTwo() {
121         Policy policy = new Policy(Policy.PRIORITY_CATEGORY_SYSTEM
122                 | Policy.PRIORITY_CATEGORY_MEDIA, 0, 0, 0);
123         assertThat(mBuilder.getSoundSettingSummary(policy))
124                 .isEqualTo("Muted, but allow media and touch sounds");
125     }
126 
127     @Test
searchProvider_shouldIndexDefaultXml()128     public void searchProvider_shouldIndexDefaultXml() {
129         final List<SearchIndexableResource> sir = ZenModeSettings.SEARCH_INDEX_DATA_PROVIDER
130                 .getXmlResourcesToIndex(mContext, true /* enabled */);
131 
132         assertThat(sir).hasSize(1);
133         assertThat(sir.get(0).xmlResId).isEqualTo(R.xml.zen_mode_settings);
134     }
135 }
136