18fcf4d83493eef3a76bbf729277fdc08a383c9adPhil Weaver/* 28fcf4d83493eef3a76bbf729277fdc08a383c9adPhil Weaver * Copyright (C) 2017 The Android Open Source Project 38fcf4d83493eef3a76bbf729277fdc08a383c9adPhil Weaver * 48fcf4d83493eef3a76bbf729277fdc08a383c9adPhil Weaver * Licensed under the Apache License, Version 2.0 (the "License"); 58fcf4d83493eef3a76bbf729277fdc08a383c9adPhil Weaver * you may not use this file except in compliance with the License. 68fcf4d83493eef3a76bbf729277fdc08a383c9adPhil Weaver * You may obtain a copy of the License at 78fcf4d83493eef3a76bbf729277fdc08a383c9adPhil Weaver * 88fcf4d83493eef3a76bbf729277fdc08a383c9adPhil Weaver * http://www.apache.org/licenses/LICENSE-2.0 98fcf4d83493eef3a76bbf729277fdc08a383c9adPhil Weaver * 108fcf4d83493eef3a76bbf729277fdc08a383c9adPhil Weaver * Unless required by applicable law or agreed to in writing, software 118fcf4d83493eef3a76bbf729277fdc08a383c9adPhil Weaver * distributed under the License is distributed on an "AS IS" BASIS, 128fcf4d83493eef3a76bbf729277fdc08a383c9adPhil Weaver * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 138fcf4d83493eef3a76bbf729277fdc08a383c9adPhil Weaver * See the License for the specific language governing permissions and 148fcf4d83493eef3a76bbf729277fdc08a383c9adPhil Weaver * limitations under the License. 158fcf4d83493eef3a76bbf729277fdc08a383c9adPhil Weaver */ 168fcf4d83493eef3a76bbf729277fdc08a383c9adPhil Weaver 1749915a64c5a30401d78245ad7739777a5b13d49fMatthew Fritzepackage com.android.settings.accessibility; 1849915a64c5a30401d78245ad7739777a5b13d49fMatthew Fritze 1922a39c2b93bc66db71238274a7683d329232d124James Lemieuximport static com.google.common.truth.Truth.assertThat; 2022a39c2b93bc66db71238274a7683d329232d124James Lemieux 2192216ae14886de5db8c8a1af7dd4210d762a00c2AL Hoimport static org.mockito.Matchers.anyString; 2292216ae14886de5db8c8a1af7dd4210d762a00c2AL Hoimport static org.mockito.Mockito.doReturn; 2392216ae14886de5db8c8a1af7dd4210d762a00c2AL Hoimport static org.mockito.Mockito.spy; 2492216ae14886de5db8c8a1af7dd4210d762a00c2AL Hoimport static org.mockito.Mockito.when; 2592216ae14886de5db8c8a1af7dd4210d762a00c2AL Ho 2649915a64c5a30401d78245ad7739777a5b13d49fMatthew Fritzeimport android.content.Context; 2792216ae14886de5db8c8a1af7dd4210d762a00c2AL Hoimport android.os.Bundle; 2892216ae14886de5db8c8a1af7dd4210d762a00c2AL Hoimport android.os.Vibrator; 2992216ae14886de5db8c8a1af7dd4210d762a00c2AL Hoimport android.provider.Settings; 3092216ae14886de5db8c8a1af7dd4210d762a00c2AL Hoimport android.support.v7.preference.Preference; 3149915a64c5a30401d78245ad7739777a5b13d49fMatthew Fritze 3249915a64c5a30401d78245ad7739777a5b13d49fMatthew Fritzeimport com.android.settings.R; 339f1e911759dc6fedaac9fa65afb79f6a93022bf4Andrew Sappersteinimport com.android.settings.testutils.SettingsRobolectricTestRunner; 3449915a64c5a30401d78245ad7739777a5b13d49fMatthew Fritzeimport com.android.settings.testutils.XmlTestUtils; 3522a39c2b93bc66db71238274a7683d329232d124James Lemieux 3649915a64c5a30401d78245ad7739777a5b13d49fMatthew Fritzeimport org.junit.Test; 3749915a64c5a30401d78245ad7739777a5b13d49fMatthew Fritzeimport org.junit.runner.RunWith; 3892216ae14886de5db8c8a1af7dd4210d762a00c2AL Hoimport org.mockito.Mock; 3992216ae14886de5db8c8a1af7dd4210d762a00c2AL Hoimport org.mockito.MockitoAnnotations; 4049915a64c5a30401d78245ad7739777a5b13d49fMatthew Fritzeimport org.robolectric.RuntimeEnvironment; 4149915a64c5a30401d78245ad7739777a5b13d49fMatthew Fritze 4249915a64c5a30401d78245ad7739777a5b13d49fMatthew Fritzeimport java.util.ArrayList; 4349915a64c5a30401d78245ad7739777a5b13d49fMatthew Fritzeimport java.util.List; 4449915a64c5a30401d78245ad7739777a5b13d49fMatthew Fritze 4549915a64c5a30401d78245ad7739777a5b13d49fMatthew Fritze@RunWith(SettingsRobolectricTestRunner.class) 4649915a64c5a30401d78245ad7739777a5b13d49fMatthew Fritzepublic class AccessibilitySettingsTest { 4749915a64c5a30401d78245ad7739777a5b13d49fMatthew Fritze 4849915a64c5a30401d78245ad7739777a5b13d49fMatthew Fritze @Test 4949915a64c5a30401d78245ad7739777a5b13d49fMatthew Fritze public void testNonIndexableKeys_existInXmlLayout() { 50463c9a07f04a10209f9010590e79603762aa8677Ben Lin final Context context = RuntimeEnvironment.application; 5149915a64c5a30401d78245ad7739777a5b13d49fMatthew Fritze final List<String> niks = AccessibilitySettings.SEARCH_INDEX_DATA_PROVIDER 5292216ae14886de5db8c8a1af7dd4210d762a00c2AL Ho .getNonIndexableKeys(context); 5349915a64c5a30401d78245ad7739777a5b13d49fMatthew Fritze final List<String> keys = new ArrayList<>(); 5449915a64c5a30401d78245ad7739777a5b13d49fMatthew Fritze 55463c9a07f04a10209f9010590e79603762aa8677Ben Lin keys.addAll(XmlTestUtils.getKeysFromPreferenceXml(context, R.xml.accessibility_settings)); 5649915a64c5a30401d78245ad7739777a5b13d49fMatthew Fritze 5749915a64c5a30401d78245ad7739777a5b13d49fMatthew Fritze assertThat(keys).containsAllIn(niks); 5849915a64c5a30401d78245ad7739777a5b13d49fMatthew Fritze } 5992216ae14886de5db8c8a1af7dd4210d762a00c2AL Ho 6092216ae14886de5db8c8a1af7dd4210d762a00c2AL Ho @Test 6192216ae14886de5db8c8a1af7dd4210d762a00c2AL Ho public void testUpdateVibrationSummary_shouldUpdateSummary() { 6292216ae14886de5db8c8a1af7dd4210d762a00c2AL Ho MockitoAnnotations.initMocks(this); 6392216ae14886de5db8c8a1af7dd4210d762a00c2AL Ho final Context mContext = RuntimeEnvironment.application; 6492216ae14886de5db8c8a1af7dd4210d762a00c2AL Ho final AccessibilitySettings mSettings = spy(new AccessibilitySettings()); 6592216ae14886de5db8c8a1af7dd4210d762a00c2AL Ho 6692216ae14886de5db8c8a1af7dd4210d762a00c2AL Ho final Preference mVibrationPreferenceScreen = new Preference(mContext); 6792216ae14886de5db8c8a1af7dd4210d762a00c2AL Ho doReturn(mVibrationPreferenceScreen).when(mSettings).findPreference(anyString()); 6892216ae14886de5db8c8a1af7dd4210d762a00c2AL Ho 6992216ae14886de5db8c8a1af7dd4210d762a00c2AL Ho doReturn(mContext).when(mSettings).getContext(); 7092216ae14886de5db8c8a1af7dd4210d762a00c2AL Ho 7192216ae14886de5db8c8a1af7dd4210d762a00c2AL Ho mVibrationPreferenceScreen.setKey("vibration_preference_screen"); 7292216ae14886de5db8c8a1af7dd4210d762a00c2AL Ho 7392216ae14886de5db8c8a1af7dd4210d762a00c2AL Ho Settings.System.putInt(mContext.getContentResolver(), 7492216ae14886de5db8c8a1af7dd4210d762a00c2AL Ho Settings.System.NOTIFICATION_VIBRATION_INTENSITY, 7592216ae14886de5db8c8a1af7dd4210d762a00c2AL Ho Vibrator.VIBRATION_INTENSITY_OFF); 7692216ae14886de5db8c8a1af7dd4210d762a00c2AL Ho 7792216ae14886de5db8c8a1af7dd4210d762a00c2AL Ho Settings.System.putInt(mContext.getContentResolver(), 7892216ae14886de5db8c8a1af7dd4210d762a00c2AL Ho Settings.System.HAPTIC_FEEDBACK_INTENSITY, 7992216ae14886de5db8c8a1af7dd4210d762a00c2AL Ho Vibrator.VIBRATION_INTENSITY_OFF); 8092216ae14886de5db8c8a1af7dd4210d762a00c2AL Ho 8192216ae14886de5db8c8a1af7dd4210d762a00c2AL Ho mSettings.updateVibrationSummary(mVibrationPreferenceScreen); 8292216ae14886de5db8c8a1af7dd4210d762a00c2AL Ho assertThat(mVibrationPreferenceScreen.getSummary()).isEqualTo( 8392216ae14886de5db8c8a1af7dd4210d762a00c2AL Ho VibrationIntensityPreferenceController.getIntensityString(mContext, 8492216ae14886de5db8c8a1af7dd4210d762a00c2AL Ho Vibrator.VIBRATION_INTENSITY_OFF)); 8592216ae14886de5db8c8a1af7dd4210d762a00c2AL Ho } 8692216ae14886de5db8c8a1af7dd4210d762a00c2AL Ho} 87