AssistGestureSettingsTest.java revision dff6dd687e7a2bb75a5b7d42a693630debf51a92
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.gestures; 18 19import static com.google.common.truth.Truth.assertThat; 20import static org.mockito.Matchers.any; 21import static org.mockito.Mockito.when; 22 23import android.content.Context; 24import android.provider.SearchIndexableResource; 25 26import com.android.settings.R; 27import com.android.settings.TestConfig; 28import com.android.settings.testutils.FakeFeatureFactory; 29import com.android.settings.testutils.SettingsRobolectricTestRunner; 30 31import org.junit.Before; 32import org.junit.Test; 33import org.junit.runner.RunWith; 34import org.mockito.MockitoAnnotations; 35import org.robolectric.RuntimeEnvironment; 36import org.robolectric.annotation.Config; 37import org.robolectric.shadows.ShadowApplication; 38 39import java.util.List; 40 41@RunWith(SettingsRobolectricTestRunner.class) 42@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O) 43public class AssistGestureSettingsTest { 44 45 private FakeFeatureFactory mFakeFeatureFactory; 46 private AssistGestureSettings mSettings; 47 48 @Before 49 public void setUp() { 50 MockitoAnnotations.initMocks(this); 51 mFakeFeatureFactory = FakeFeatureFactory.setupForTest(); 52 mSettings = new AssistGestureSettings(); 53 } 54 55 @Test 56 public void testGetPreferenceScreenResId() { 57 assertThat(mSettings.getPreferenceScreenResId()) 58 .isEqualTo(R.xml.assist_gesture_settings); 59 } 60 61 @Test 62 public void testSearchIndexProvider_shouldIndexResource() { 63 final List<SearchIndexableResource> indexRes = 64 AssistGestureSettings.SEARCH_INDEX_DATA_PROVIDER.getXmlResourcesToIndex( 65 ShadowApplication.getInstance().getApplicationContext(), 66 true /* enabled */); 67 68 assertThat(indexRes).isNotNull(); 69 assertThat(indexRes.get(0).xmlResId).isEqualTo(mSettings.getPreferenceScreenResId()); 70 } 71 72 @Test 73 public void testSearchIndexProvider_noSensor_shouldDisablePageSearch() { 74 when(mFakeFeatureFactory.assistGestureFeatureProvider.isSensorAvailable(any(Context.class))) 75 .thenReturn(false); 76 77 assertThat(AssistGestureSettings.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys( 78 RuntimeEnvironment.application)) 79 .contains("gesture_assist_settings_page"); 80 } 81} 82 83