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