1a9831d40d081cc8c7ca32891e64c09b5e1d19abbPhilip Quinn/* 2a9831d40d081cc8c7ca32891e64c09b5e1d19abbPhilip Quinn * Copyright (C) 2017 The Android Open Source Project 3a9831d40d081cc8c7ca32891e64c09b5e1d19abbPhilip Quinn * 4a9831d40d081cc8c7ca32891e64c09b5e1d19abbPhilip Quinn * Licensed under the Apache License, Version 2.0 (the "License"); 5a9831d40d081cc8c7ca32891e64c09b5e1d19abbPhilip Quinn * you may not use this file except in compliance with the License. 6a9831d40d081cc8c7ca32891e64c09b5e1d19abbPhilip Quinn * You may obtain a copy of the License at 7a9831d40d081cc8c7ca32891e64c09b5e1d19abbPhilip Quinn * 8a9831d40d081cc8c7ca32891e64c09b5e1d19abbPhilip Quinn * http://www.apache.org/licenses/LICENSE-2.0 9a9831d40d081cc8c7ca32891e64c09b5e1d19abbPhilip Quinn * 10a9831d40d081cc8c7ca32891e64c09b5e1d19abbPhilip Quinn * Unless required by applicable law or agreed to in writing, software 11a9831d40d081cc8c7ca32891e64c09b5e1d19abbPhilip Quinn * distributed under the License is distributed on an "AS IS" BASIS, 12a9831d40d081cc8c7ca32891e64c09b5e1d19abbPhilip Quinn * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13a9831d40d081cc8c7ca32891e64c09b5e1d19abbPhilip Quinn * See the License for the specific language governing permissions and 14a9831d40d081cc8c7ca32891e64c09b5e1d19abbPhilip Quinn * limitations under the License. 15a9831d40d081cc8c7ca32891e64c09b5e1d19abbPhilip Quinn */ 16a9831d40d081cc8c7ca32891e64c09b5e1d19abbPhilip Quinn 17a9831d40d081cc8c7ca32891e64c09b5e1d19abbPhilip Quinnpackage com.android.settings.gestures; 18a9831d40d081cc8c7ca32891e64c09b5e1d19abbPhilip Quinn 191d583e125faf3ae4c9cd82636d8f3ecf1cdec3aaTony Mantlerimport static com.google.common.truth.Truth.assertThat; 20eef16a8b0fc52a5378f2a364ed8a003470a76e84Fan Zhangimport static org.mockito.Matchers.any; 211d583e125faf3ae4c9cd82636d8f3ecf1cdec3aaTony Mantlerimport static org.mockito.Mockito.when; 221d583e125faf3ae4c9cd82636d8f3ecf1cdec3aaTony Mantler 23a9831d40d081cc8c7ca32891e64c09b5e1d19abbPhilip Quinnimport android.content.Context; 24a9831d40d081cc8c7ca32891e64c09b5e1d19abbPhilip Quinnimport android.provider.SearchIndexableResource; 25a9831d40d081cc8c7ca32891e64c09b5e1d19abbPhilip Quinn 26a9831d40d081cc8c7ca32891e64c09b5e1d19abbPhilip Quinnimport com.android.settings.R; 27f475bc2fbe6c00f383a2a3292258d2b552decb5aKevin Chynimport com.android.settings.testutils.FakeFeatureFactory; 289f1e911759dc6fedaac9fa65afb79f6a93022bf4Andrew Sappersteinimport com.android.settings.testutils.SettingsRobolectricTestRunner; 29a9831d40d081cc8c7ca32891e64c09b5e1d19abbPhilip Quinn 30a9831d40d081cc8c7ca32891e64c09b5e1d19abbPhilip Quinnimport org.junit.Before; 31a9831d40d081cc8c7ca32891e64c09b5e1d19abbPhilip Quinnimport org.junit.Test; 32a9831d40d081cc8c7ca32891e64c09b5e1d19abbPhilip Quinnimport org.junit.runner.RunWith; 33a9831d40d081cc8c7ca32891e64c09b5e1d19abbPhilip Quinnimport org.mockito.MockitoAnnotations; 34eef16a8b0fc52a5378f2a364ed8a003470a76e84Fan Zhangimport org.robolectric.RuntimeEnvironment; 35a9831d40d081cc8c7ca32891e64c09b5e1d19abbPhilip Quinn 36a9831d40d081cc8c7ca32891e64c09b5e1d19abbPhilip Quinnimport java.util.List; 37a9831d40d081cc8c7ca32891e64c09b5e1d19abbPhilip Quinn 38a9831d40d081cc8c7ca32891e64c09b5e1d19abbPhilip Quinn@RunWith(SettingsRobolectricTestRunner.class) 39a9831d40d081cc8c7ca32891e64c09b5e1d19abbPhilip Quinnpublic class AssistGestureSettingsTest { 40dff6dd687e7a2bb75a5b7d42a693630debf51a92Fan Zhang 41f475bc2fbe6c00f383a2a3292258d2b552decb5aKevin Chyn private FakeFeatureFactory mFakeFeatureFactory; 42a9831d40d081cc8c7ca32891e64c09b5e1d19abbPhilip Quinn private AssistGestureSettings mSettings; 43a9831d40d081cc8c7ca32891e64c09b5e1d19abbPhilip Quinn 44a9831d40d081cc8c7ca32891e64c09b5e1d19abbPhilip Quinn @Before 45a9831d40d081cc8c7ca32891e64c09b5e1d19abbPhilip Quinn public void setUp() { 46a9831d40d081cc8c7ca32891e64c09b5e1d19abbPhilip Quinn MockitoAnnotations.initMocks(this); 47dff6dd687e7a2bb75a5b7d42a693630debf51a92Fan Zhang mFakeFeatureFactory = FakeFeatureFactory.setupForTest(); 48a9831d40d081cc8c7ca32891e64c09b5e1d19abbPhilip Quinn mSettings = new AssistGestureSettings(); 49a9831d40d081cc8c7ca32891e64c09b5e1d19abbPhilip Quinn } 50a9831d40d081cc8c7ca32891e64c09b5e1d19abbPhilip Quinn 51a9831d40d081cc8c7ca32891e64c09b5e1d19abbPhilip Quinn @Test 52a9831d40d081cc8c7ca32891e64c09b5e1d19abbPhilip Quinn public void testGetPreferenceScreenResId() { 53a9831d40d081cc8c7ca32891e64c09b5e1d19abbPhilip Quinn assertThat(mSettings.getPreferenceScreenResId()) 54a9831d40d081cc8c7ca32891e64c09b5e1d19abbPhilip Quinn .isEqualTo(R.xml.assist_gesture_settings); 55a9831d40d081cc8c7ca32891e64c09b5e1d19abbPhilip Quinn } 56a9831d40d081cc8c7ca32891e64c09b5e1d19abbPhilip Quinn 57a9831d40d081cc8c7ca32891e64c09b5e1d19abbPhilip Quinn @Test 58a9831d40d081cc8c7ca32891e64c09b5e1d19abbPhilip Quinn public void testSearchIndexProvider_shouldIndexResource() { 59a9831d40d081cc8c7ca32891e64c09b5e1d19abbPhilip Quinn final List<SearchIndexableResource> indexRes = 60a9831d40d081cc8c7ca32891e64c09b5e1d19abbPhilip Quinn AssistGestureSettings.SEARCH_INDEX_DATA_PROVIDER.getXmlResourcesToIndex( 6122a39c2b93bc66db71238274a7683d329232d124James Lemieux RuntimeEnvironment.application, true /* enabled */); 62a9831d40d081cc8c7ca32891e64c09b5e1d19abbPhilip Quinn 63a9831d40d081cc8c7ca32891e64c09b5e1d19abbPhilip Quinn assertThat(indexRes).isNotNull(); 64a9831d40d081cc8c7ca32891e64c09b5e1d19abbPhilip Quinn assertThat(indexRes.get(0).xmlResId).isEqualTo(mSettings.getPreferenceScreenResId()); 65a9831d40d081cc8c7ca32891e64c09b5e1d19abbPhilip Quinn } 66eef16a8b0fc52a5378f2a364ed8a003470a76e84Fan Zhang 67eef16a8b0fc52a5378f2a364ed8a003470a76e84Fan Zhang @Test 68eef16a8b0fc52a5378f2a364ed8a003470a76e84Fan Zhang public void testSearchIndexProvider_noSensor_shouldDisablePageSearch() { 69eef16a8b0fc52a5378f2a364ed8a003470a76e84Fan Zhang when(mFakeFeatureFactory.assistGestureFeatureProvider.isSensorAvailable(any(Context.class))) 70eef16a8b0fc52a5378f2a364ed8a003470a76e84Fan Zhang .thenReturn(false); 71eef16a8b0fc52a5378f2a364ed8a003470a76e84Fan Zhang 72eef16a8b0fc52a5378f2a364ed8a003470a76e84Fan Zhang assertThat(AssistGestureSettings.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys( 73eef16a8b0fc52a5378f2a364ed8a003470a76e84Fan Zhang RuntimeEnvironment.application)) 74eef16a8b0fc52a5378f2a364ed8a003470a76e84Fan Zhang .contains("gesture_assist_settings_page"); 75eef16a8b0fc52a5378f2a364ed8a003470a76e84Fan Zhang } 76a9831d40d081cc8c7ca32891e64c09b5e1d19abbPhilip Quinn} 77