• 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.Handler;
29 import android.os.UserManager;
30 import android.preference.SeekBarVolumizer;
31 
32 import com.android.settings.R;
33 import com.android.settings.testutils.XmlTestUtils;
34 import com.android.settings.testutils.shadow.ShadowAudioHelper;
35 import com.android.settings.testutils.shadow.ShadowDeviceConfig;
36 import com.android.settings.testutils.shadow.ShadowUserManager;
37 
38 import org.junit.Test;
39 import org.junit.runner.RunWith;
40 import org.robolectric.RobolectricTestRunner;
41 import org.robolectric.RuntimeEnvironment;
42 import org.robolectric.annotation.Config;
43 import org.robolectric.util.ReflectionHelpers;
44 
45 import java.util.List;
46 
47 @RunWith(RobolectricTestRunner.class)
48 public class SoundSettingsTest {
49 
50     @Test
51     @Config(shadows = {ShadowUserManager.class, ShadowAudioHelper.class, ShadowDeviceConfig.class})
getNonIndexableKeys_existInXmlLayout()52     public void getNonIndexableKeys_existInXmlLayout() {
53         final Context context = spy(RuntimeEnvironment.application);
54         AudioManager audioManager = mock(AudioManager.class);
55         doReturn(audioManager).when(context).getSystemService(Context.AUDIO_SERVICE);
56 
57         UserManager userManager = mock(UserManager.class);
58         when(userManager.isAdminUser()).thenReturn(false);
59         doReturn(userManager).when(context).getSystemService(Context.USER_SERVICE);
60 
61         final List<String> niks =
62             SoundSettings.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(context);
63         SoundSettings settings = new SoundSettings();
64         final int xmlId = settings.getPreferenceScreenResId();
65         final List<String> keys = XmlTestUtils.getKeysFromPreferenceXml(context, xmlId);
66         keys.addAll(XmlTestUtils.getKeysFromPreferenceXml(context, R.xml.zen_mode_settings));
67         // Add keys with hidden resources
68         keys.add("alarm_volume");
69         keys.add("ring_volume");
70         keys.add("notification_volume");
71 
72         assertThat(keys).containsAllIn(niks);
73     }
74 
75     @Test
onStreamValueChanged_shouldRepostStopSampleMessage()76     public void onStreamValueChanged_shouldRepostStopSampleMessage() {
77         final SoundSettings settings = new SoundSettings();
78         ReflectionHelpers.setField(
79                 settings.mVolumeCallback, "mCurrent", mock(SeekBarVolumizer.class));
80 
81         settings.mVolumeCallback.onStreamValueChanged(0, 5);
82 
83         assertThat(settings.mHandler.hasMessages(SoundSettings.STOP_SAMPLE)).isTrue();
84     }
85 }
86