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
17package com.android.settings.notification;
18
19import android.content.Context;
20
21import android.media.AudioManager;
22import android.os.UserManager;
23import com.android.settings.R;
24import com.android.settings.testutils.SettingsRobolectricTestRunner;
25import com.android.settings.TestConfig;
26import com.android.settings.testutils.XmlTestUtils;
27import com.android.settings.testutils.shadow.ShadowAudioHelper;
28import com.android.settings.testutils.shadow.ShadowUserManager;
29import org.junit.Test;
30import org.junit.runner.RunWith;
31import org.robolectric.RuntimeEnvironment;
32import org.robolectric.annotation.Config;
33
34import java.util.List;
35
36import static com.google.common.truth.Truth.assertThat;
37import static org.mockito.Mockito.doReturn;
38import static org.mockito.Mockito.mock;
39import static org.mockito.Mockito.spy;
40import static org.mockito.Mockito.when;
41
42@RunWith(SettingsRobolectricTestRunner.class)
43@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
44public class SoundSettingsTest {
45
46    @Test
47    @Config( shadows = {
48            ShadowUserManager.class,
49            ShadowAudioHelper.class,
50    })
51    public void testNonIndexableKeys_existInXmlLayout() {
52        final Context context = spy(RuntimeEnvironment.application);
53        AudioManager audioManager = mock(AudioManager.class);
54        doReturn(audioManager).when(context).getSystemService(Context.AUDIO_SERVICE);
55
56        UserManager userManager = mock(UserManager.class);
57        when(userManager.isAdminUser()).thenReturn(false);
58        doReturn(userManager).when(context).getSystemService(Context.USER_SERVICE);
59
60        final List<String> niks = SoundSettings.SEARCH_INDEX_DATA_PROVIDER
61                .getNonIndexableKeys(context);
62        final int xmlId = (new SoundSettings()).getPreferenceScreenResId();
63        final List<String> keys = XmlTestUtils.getKeysFromPreferenceXml(context, xmlId);
64        keys.addAll(XmlTestUtils.getKeysFromPreferenceXml(context,
65                R.xml.zen_mode_settings));
66        // Add keys with hidden resources
67        keys.add("alarm_volume");
68        keys.add("ring_volume");
69        keys.add("notification_volume");
70
71        assertThat(keys).containsAllIn(niks);
72    }
73}