• 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.accessibility;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 
21 import static org.mockito.Matchers.anyString;
22 import static org.mockito.Mockito.doReturn;
23 import static org.mockito.Mockito.spy;
24 import static org.mockito.Mockito.when;
25 
26 import android.content.Context;
27 import android.os.Bundle;
28 import android.os.Vibrator;
29 import android.provider.Settings;
30 import android.support.v7.preference.Preference;
31 
32 import com.android.settings.R;
33 import com.android.settings.testutils.SettingsRobolectricTestRunner;
34 import com.android.settings.testutils.XmlTestUtils;
35 
36 import org.junit.Test;
37 import org.junit.runner.RunWith;
38 import org.mockito.Mock;
39 import org.mockito.MockitoAnnotations;
40 import org.robolectric.RuntimeEnvironment;
41 
42 import java.util.ArrayList;
43 import java.util.List;
44 
45 @RunWith(SettingsRobolectricTestRunner.class)
46 public class AccessibilitySettingsTest {
47 
48     @Test
testNonIndexableKeys_existInXmlLayout()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
testUpdateVibrationSummary_shouldUpdateSummary()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