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