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