• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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.mockito.Mockito.doReturn;
22 import static org.mockito.Mockito.mock;
23 import static org.mockito.Mockito.spy;
24 import static org.mockito.Mockito.when;
25 
26 import android.content.Context;
27 import android.media.AudioManager;
28 import android.os.UserManager;
29 import android.preference.SeekBarVolumizer;
30 
31 import com.android.settings.R;
32 import com.android.settings.testutils.XmlTestUtils;
33 import com.android.settings.testutils.shadow.ShadowAudioHelper;
34 import com.android.settings.testutils.shadow.ShadowBluetoothAdapter;
35 import com.android.settings.testutils.shadow.ShadowDeviceConfig;
36 import com.android.settings.testutils.shadow.ShadowUserManager;
37 
38 import org.junit.Ignore;
39 import org.junit.Test;
40 import org.junit.runner.RunWith;
41 import org.robolectric.RobolectricTestRunner;
42 import org.robolectric.RuntimeEnvironment;
43 import org.robolectric.annotation.Config;
44 import org.robolectric.util.ReflectionHelpers;
45 
46 import java.util.List;
47 
48 @RunWith(RobolectricTestRunner.class)
49 public class SoundSettingsTest {
50 
51     @Test
52     @Config(shadows = {ShadowUserManager.class, ShadowAudioHelper.class, ShadowDeviceConfig.class,
53             ShadowBluetoothAdapter.class})
54     @Ignore
getNonIndexableKeys_existInXmlLayout()55     public void getNonIndexableKeys_existInXmlLayout() {
56         final Context context = spy(RuntimeEnvironment.application);
57         AudioManager audioManager = mock(AudioManager.class);
58         doReturn(audioManager).when(context).getSystemService(Context.AUDIO_SERVICE);
59 
60         UserManager userManager = mock(UserManager.class);
61         when(userManager.isAdminUser()).thenReturn(false);
62         doReturn(userManager).when(context).getSystemService(Context.USER_SERVICE);
63 
64         final List<String> niks =
65             SoundSettings.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(context);
66         SoundSettings settings = new SoundSettings();
67         final int xmlId = settings.getPreferenceScreenResId();
68         final List<String> keys = XmlTestUtils.getKeysFromPreferenceXml(context, xmlId);
69         keys.addAll(XmlTestUtils.getKeysFromPreferenceXml(context, R.xml.zen_mode_settings));
70         // Add keys with hidden resources
71         keys.add("alarm_volume");
72         keys.add("separate_ring_volume");
73         keys.add("notification_volume");
74 
75         assertThat(keys).containsAtLeastElementsIn(niks);
76     }
77 
78     @Test
onStreamValueChanged_shouldRepostStopSampleMessage()79     public void onStreamValueChanged_shouldRepostStopSampleMessage() {
80         final SoundSettings settings = new SoundSettings();
81         ReflectionHelpers.setField(
82                 settings.mVolumeCallback, "mCurrent", mock(SeekBarVolumizer.class));
83 
84         settings.mVolumeCallback.onStreamValueChanged(0, 5);
85 
86         assertThat(settings.mHandler.hasMessages(SoundSettings.STOP_SAMPLE)).isTrue();
87     }
88 
89     @Test
notificationVolume_isBetweenRingAndAlarm()90     public void notificationVolume_isBetweenRingAndAlarm() {
91         final Context context = spy(RuntimeEnvironment.application);
92         final SoundSettings settings = new SoundSettings();
93         final int xmlId = settings.getPreferenceScreenResId();
94         final List<String> keys = XmlTestUtils.getKeysFromPreferenceXml(context, xmlId);
95 
96         int ring = keys.indexOf("separate_ring_volume");
97         int notification = keys.indexOf("notification_volume");
98         int alarm = keys.indexOf("alarm_volume");
99 
100         assertThat(ring < notification).isTrue();
101         assertThat(notification < alarm).isTrue();
102     }
103 }
104