AssistGestureSettingsTest.java revision 563af1cda94bcaadee75250d7e2f339604f2bffc
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;
30import com.android.settingslib.core.AbstractPreferenceController;
31
32import org.junit.Before;
33import org.junit.Test;
34import org.junit.runner.RunWith;
35import org.mockito.Answers;
36import org.mockito.Mock;
37import org.mockito.MockitoAnnotations;
38import org.robolectric.RuntimeEnvironment;
39import org.robolectric.annotation.Config;
40import org.robolectric.shadows.ShadowApplication;
41
42import java.util.List;
43
44@RunWith(SettingsRobolectricTestRunner.class)
45@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
46public class AssistGestureSettingsTest {
47    @Mock(answer = Answers.RETURNS_DEEP_STUBS)
48    private Context mContext;
49    private FakeFeatureFactory mFakeFeatureFactory;
50    private AssistGestureSettings mSettings;
51
52    @Before
53    public void setUp() {
54        MockitoAnnotations.initMocks(this);
55        FakeFeatureFactory.setupForTest(mContext);
56        mFakeFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
57        mSettings = new AssistGestureSettings();
58    }
59
60    @Test
61    public void testGetPreferenceScreenResId() {
62        assertThat(mSettings.getPreferenceScreenResId())
63                .isEqualTo(R.xml.assist_gesture_settings);
64    }
65
66    @Test
67    public void testSearchIndexProvider_shouldIndexResource() {
68        final List<SearchIndexableResource> indexRes =
69                AssistGestureSettings.SEARCH_INDEX_DATA_PROVIDER.getXmlResourcesToIndex(
70                        ShadowApplication.getInstance().getApplicationContext(),
71                        true /* enabled */);
72
73        assertThat(indexRes).isNotNull();
74        assertThat(indexRes.get(0).xmlResId).isEqualTo(mSettings.getPreferenceScreenResId());
75    }
76
77    @Test
78    public void testSearchIndexProvider_noSensor_shouldDisablePageSearch() {
79        when(mFakeFeatureFactory.assistGestureFeatureProvider.isSensorAvailable(any(Context.class)))
80                .thenReturn(false);
81
82        assertThat(AssistGestureSettings.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(
83                RuntimeEnvironment.application))
84                .contains("gesture_assist_settings_page");
85    }
86}
87
88