106976317cb7365affab2e991c1f3456738919098Matthew Fritze/*
206976317cb7365affab2e991c1f3456738919098Matthew Fritze * Copyright (C) 2017 The Android Open Source Project
306976317cb7365affab2e991c1f3456738919098Matthew Fritze *
406976317cb7365affab2e991c1f3456738919098Matthew Fritze * Licensed under the Apache License, Version 2.0 (the "License");
506976317cb7365affab2e991c1f3456738919098Matthew Fritze * you may not use this file except in compliance with the License.
606976317cb7365affab2e991c1f3456738919098Matthew Fritze * You may obtain a copy of the License at
706976317cb7365affab2e991c1f3456738919098Matthew Fritze *
806976317cb7365affab2e991c1f3456738919098Matthew Fritze *      http://www.apache.org/licenses/LICENSE-2.0
906976317cb7365affab2e991c1f3456738919098Matthew Fritze *
1006976317cb7365affab2e991c1f3456738919098Matthew Fritze * Unless required by applicable law or agreed to in writing, software
1106976317cb7365affab2e991c1f3456738919098Matthew Fritze * distributed under the License is distributed on an "AS IS" BASIS,
1206976317cb7365affab2e991c1f3456738919098Matthew Fritze * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1306976317cb7365affab2e991c1f3456738919098Matthew Fritze * See the License for the specific language governing permissions and
1406976317cb7365affab2e991c1f3456738919098Matthew Fritze * limitations under the License.
1506976317cb7365affab2e991c1f3456738919098Matthew Fritze */
1606976317cb7365affab2e991c1f3456738919098Matthew Fritze
1706976317cb7365affab2e991c1f3456738919098Matthew Fritzepackage com.android.settings.notification;
1806976317cb7365affab2e991c1f3456738919098Matthew Fritze
1906976317cb7365affab2e991c1f3456738919098Matthew Fritzeimport android.content.Context;
2006976317cb7365affab2e991c1f3456738919098Matthew Fritze
2106976317cb7365affab2e991c1f3456738919098Matthew Fritzeimport android.media.AudioManager;
2206976317cb7365affab2e991c1f3456738919098Matthew Fritzeimport android.os.UserManager;
2306976317cb7365affab2e991c1f3456738919098Matthew Fritzeimport com.android.settings.R;
249f1e911759dc6fedaac9fa65afb79f6a93022bf4Andrew Sappersteinimport com.android.settings.testutils.SettingsRobolectricTestRunner;
2506976317cb7365affab2e991c1f3456738919098Matthew Fritzeimport com.android.settings.TestConfig;
2606976317cb7365affab2e991c1f3456738919098Matthew Fritzeimport com.android.settings.testutils.XmlTestUtils;
2706976317cb7365affab2e991c1f3456738919098Matthew Fritzeimport com.android.settings.testutils.shadow.ShadowAudioHelper;
2806976317cb7365affab2e991c1f3456738919098Matthew Fritzeimport com.android.settings.testutils.shadow.ShadowUserManager;
2906976317cb7365affab2e991c1f3456738919098Matthew Fritzeimport org.junit.Test;
3006976317cb7365affab2e991c1f3456738919098Matthew Fritzeimport org.junit.runner.RunWith;
3106976317cb7365affab2e991c1f3456738919098Matthew Fritzeimport org.robolectric.RuntimeEnvironment;
3206976317cb7365affab2e991c1f3456738919098Matthew Fritzeimport org.robolectric.annotation.Config;
3306976317cb7365affab2e991c1f3456738919098Matthew Fritze
3406976317cb7365affab2e991c1f3456738919098Matthew Fritzeimport java.util.List;
3506976317cb7365affab2e991c1f3456738919098Matthew Fritze
3606976317cb7365affab2e991c1f3456738919098Matthew Fritzeimport static com.google.common.truth.Truth.assertThat;
3706976317cb7365affab2e991c1f3456738919098Matthew Fritzeimport static org.mockito.Mockito.doReturn;
3806976317cb7365affab2e991c1f3456738919098Matthew Fritzeimport static org.mockito.Mockito.mock;
3906976317cb7365affab2e991c1f3456738919098Matthew Fritzeimport static org.mockito.Mockito.spy;
4006976317cb7365affab2e991c1f3456738919098Matthew Fritzeimport static org.mockito.Mockito.when;
4106976317cb7365affab2e991c1f3456738919098Matthew Fritze
4206976317cb7365affab2e991c1f3456738919098Matthew Fritze@RunWith(SettingsRobolectricTestRunner.class)
4306976317cb7365affab2e991c1f3456738919098Matthew Fritze@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
4406976317cb7365affab2e991c1f3456738919098Matthew Fritzepublic class SoundSettingsTest {
4506976317cb7365affab2e991c1f3456738919098Matthew Fritze
4606976317cb7365affab2e991c1f3456738919098Matthew Fritze    @Test
4706976317cb7365affab2e991c1f3456738919098Matthew Fritze    @Config( shadows = {
4806976317cb7365affab2e991c1f3456738919098Matthew Fritze            ShadowUserManager.class,
4906976317cb7365affab2e991c1f3456738919098Matthew Fritze            ShadowAudioHelper.class,
5006976317cb7365affab2e991c1f3456738919098Matthew Fritze    })
5106976317cb7365affab2e991c1f3456738919098Matthew Fritze    public void testNonIndexableKeys_existInXmlLayout() {
5206976317cb7365affab2e991c1f3456738919098Matthew Fritze        final Context context = spy(RuntimeEnvironment.application);
5306976317cb7365affab2e991c1f3456738919098Matthew Fritze        AudioManager audioManager = mock(AudioManager.class);
5406976317cb7365affab2e991c1f3456738919098Matthew Fritze        doReturn(audioManager).when(context).getSystemService(Context.AUDIO_SERVICE);
5506976317cb7365affab2e991c1f3456738919098Matthew Fritze
5606976317cb7365affab2e991c1f3456738919098Matthew Fritze        UserManager userManager = mock(UserManager.class);
5706976317cb7365affab2e991c1f3456738919098Matthew Fritze        when(userManager.isAdminUser()).thenReturn(false);
5806976317cb7365affab2e991c1f3456738919098Matthew Fritze        doReturn(userManager).when(context).getSystemService(Context.USER_SERVICE);
5906976317cb7365affab2e991c1f3456738919098Matthew Fritze
6006976317cb7365affab2e991c1f3456738919098Matthew Fritze        final List<String> niks = SoundSettings.SEARCH_INDEX_DATA_PROVIDER
6106976317cb7365affab2e991c1f3456738919098Matthew Fritze                .getNonIndexableKeys(context);
6206976317cb7365affab2e991c1f3456738919098Matthew Fritze        final int xmlId = (new SoundSettings()).getPreferenceScreenResId();
6306976317cb7365affab2e991c1f3456738919098Matthew Fritze        final List<String> keys = XmlTestUtils.getKeysFromPreferenceXml(context, xmlId);
6406976317cb7365affab2e991c1f3456738919098Matthew Fritze        keys.addAll(XmlTestUtils.getKeysFromPreferenceXml(context,
6506976317cb7365affab2e991c1f3456738919098Matthew Fritze                R.xml.zen_mode_settings));
6606976317cb7365affab2e991c1f3456738919098Matthew Fritze        // Add keys with hidden resources
6706976317cb7365affab2e991c1f3456738919098Matthew Fritze        keys.add("alarm_volume");
6806976317cb7365affab2e991c1f3456738919098Matthew Fritze        keys.add("ring_volume");
6906976317cb7365affab2e991c1f3456738919098Matthew Fritze        keys.add("notification_volume");
7006976317cb7365affab2e991c1f3456738919098Matthew Fritze
7106976317cb7365affab2e991c1f3456738919098Matthew Fritze        assertThat(keys).containsAllIn(niks);
7206976317cb7365affab2e991c1f3456738919098Matthew Fritze    }
7306976317cb7365affab2e991c1f3456738919098Matthew Fritze}