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.testutils.FakeFeatureFactory;
28import com.android.settings.testutils.SettingsRobolectricTestRunner;
29
30import org.junit.Before;
31import org.junit.Test;
32import org.junit.runner.RunWith;
33import org.mockito.MockitoAnnotations;
34import org.robolectric.RuntimeEnvironment;
35
36import java.util.List;
37
38@RunWith(SettingsRobolectricTestRunner.class)
39public class AssistGestureSettingsTest {
40
41    private FakeFeatureFactory mFakeFeatureFactory;
42    private AssistGestureSettings mSettings;
43
44    @Before
45    public void setUp() {
46        MockitoAnnotations.initMocks(this);
47        mFakeFeatureFactory = FakeFeatureFactory.setupForTest();
48        mSettings = new AssistGestureSettings();
49    }
50
51    @Test
52    public void testGetPreferenceScreenResId() {
53        assertThat(mSettings.getPreferenceScreenResId())
54                .isEqualTo(R.xml.assist_gesture_settings);
55    }
56
57    @Test
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
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