AccessibilitySettingsTest.java revision 92216ae14886de5db8c8a1af7dd4210d762a00c2
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.accessibility;
18
19import static com.google.common.truth.Truth.assertThat;
20
21import static org.mockito.Matchers.anyString;
22import static org.mockito.Mockito.doReturn;
23import static org.mockito.Mockito.spy;
24import static org.mockito.Mockito.when;
25
26import android.content.Context;
27import android.os.Bundle;
28import android.os.Vibrator;
29import android.provider.Settings;
30import android.support.v7.preference.Preference;
31
32import com.android.settings.R;
33import com.android.settings.testutils.SettingsRobolectricTestRunner;
34import com.android.settings.testutils.XmlTestUtils;
35
36import org.junit.Test;
37import org.junit.runner.RunWith;
38import org.mockito.Mock;
39import org.mockito.MockitoAnnotations;
40import org.robolectric.RuntimeEnvironment;
41
42import java.util.ArrayList;
43import java.util.List;
44
45@RunWith(SettingsRobolectricTestRunner.class)
46public class AccessibilitySettingsTest {
47
48    @Test
49    public void testNonIndexableKeys_existInXmlLayout() {
50        final Context context = RuntimeEnvironment.application;
51        final List<String> niks = AccessibilitySettings.SEARCH_INDEX_DATA_PROVIDER
52                .getNonIndexableKeys(context);
53        final List<String> keys = new ArrayList<>();
54
55        keys.addAll(XmlTestUtils.getKeysFromPreferenceXml(context, R.xml.accessibility_settings));
56
57        assertThat(keys).containsAllIn(niks);
58    }
59
60    @Test
61    public void testUpdateVibrationSummary_shouldUpdateSummary() {
62        MockitoAnnotations.initMocks(this);
63        final Context mContext = RuntimeEnvironment.application;
64        final AccessibilitySettings mSettings = spy(new AccessibilitySettings());
65
66        final Preference mVibrationPreferenceScreen = new Preference(mContext);
67        doReturn(mVibrationPreferenceScreen).when(mSettings).findPreference(anyString());
68
69        doReturn(mContext).when(mSettings).getContext();
70
71        mVibrationPreferenceScreen.setKey("vibration_preference_screen");
72
73        Settings.System.putInt(mContext.getContentResolver(),
74                Settings.System.NOTIFICATION_VIBRATION_INTENSITY,
75                Vibrator.VIBRATION_INTENSITY_OFF);
76
77        Settings.System.putInt(mContext.getContentResolver(),
78                Settings.System.HAPTIC_FEEDBACK_INTENSITY,
79                Vibrator.VIBRATION_INTENSITY_OFF);
80
81        mSettings.updateVibrationSummary(mVibrationPreferenceScreen);
82        assertThat(mVibrationPreferenceScreen.getSummary()).isEqualTo(
83                VibrationIntensityPreferenceController.getIntensityString(mContext,
84                        Vibrator.VIBRATION_INTENSITY_OFF));
85    }
86}
87