From ee524404fff60d457e66c32d4d3b37dae178e12f Mon Sep 17 00:00:00 2001 From: Fan Zhang Date: Mon, 5 Dec 2016 12:58:03 -0800 Subject: [PATCH] Add search indexing for new gesture pages. Bug: 33252252 Test: make RunSettingsRoboTests Change-Id: I927e5b9b87b226ea5ce2006fc2524ac8db740446 --- res/xml/pick_up_gesture_settings.xml | 5 +- .../gestures/DoubleTapPowerSettings.java | 19 +++++ .../gestures/DoubleTapScreenSettings.java | 19 +++++ .../gestures/DoubleTwistGestureSettings.java | 19 +++++ .../gestures/PickupGestureSettings.java | 20 ++++++ .../gestures/SwipeToNotificationSettings.java | 19 +++++ .../android/settings/search/Indexable.java | 2 +- .../search/SearchIndexableResources.java | 11 +++ ...randfather_not_implementing_index_provider | 6 -- .../gestures/DoubleTapPowerSettingsTest.java | 69 ++++++++++++++++++ .../gestures/DoubleTapScreenSettingsTest.java | 69 ++++++++++++++++++ .../DoubleTwistGestureSettingsTest.java | 68 ++++++++++++++++++ .../gestures/PickupGestureSettingsTest.java | 70 +++++++++++++++++++ .../SwipeToNotificationSettingsTest.java | 18 +++++ 14 files changed, 405 insertions(+), 9 deletions(-) create mode 100644 tests/robotests/src/com/android/settings/gestures/DoubleTapPowerSettingsTest.java create mode 100644 tests/robotests/src/com/android/settings/gestures/DoubleTapScreenSettingsTest.java create mode 100644 tests/robotests/src/com/android/settings/gestures/DoubleTwistGestureSettingsTest.java create mode 100644 tests/robotests/src/com/android/settings/gestures/PickupGestureSettingsTest.java diff --git a/res/xml/pick_up_gesture_settings.xml b/res/xml/pick_up_gesture_settings.xml index 4ef81a225df..6b67e642627 100644 --- a/res/xml/pick_up_gesture_settings.xml +++ b/res/xml/pick_up_gesture_settings.xml @@ -15,8 +15,9 @@ limitations under the License. --> - + getXmlResourcesToIndex( + Context context, boolean enabled) { + if (!FeatureFactory.getFactory(context).getDashboardFeatureProvider(context) + .isEnabled()) { + return null; + } + final SearchIndexableResource sir = new SearchIndexableResource(context); + sir.xmlResId = R.xml.double_tap_power_settings; + return Arrays.asList(sir); + } + }; } diff --git a/src/com/android/settings/gestures/DoubleTapScreenSettings.java b/src/com/android/settings/gestures/DoubleTapScreenSettings.java index 3c53947725b..c10fbb74e29 100644 --- a/src/com/android/settings/gestures/DoubleTapScreenSettings.java +++ b/src/com/android/settings/gestures/DoubleTapScreenSettings.java @@ -18,13 +18,17 @@ package com.android.settings.gestures; import android.content.Context; import android.os.UserHandle; +import android.provider.SearchIndexableResource; import com.android.internal.hardware.AmbientDisplayConfiguration; import com.android.settings.R; import com.android.settings.core.PreferenceController; import com.android.settings.dashboard.DashboardFragment; +import com.android.settings.overlay.FeatureFactory; +import com.android.settings.search.BaseSearchIndexProvider; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; public class DoubleTapScreenSettings extends DashboardFragment { @@ -58,4 +62,19 @@ public class DoubleTapScreenSettings extends DashboardFragment { new AmbientDisplayConfiguration(context), UserHandle.myUserId())); return controllers; } + + public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = + new BaseSearchIndexProvider() { + @Override + public List getXmlResourcesToIndex( + Context context, boolean enabled) { + if (!FeatureFactory.getFactory(context).getDashboardFeatureProvider(context) + .isEnabled()) { + return null; + } + final SearchIndexableResource sir = new SearchIndexableResource(context); + sir.xmlResId = R.xml.double_tap_screen_settings; + return Arrays.asList(sir); + } + }; } diff --git a/src/com/android/settings/gestures/DoubleTwistGestureSettings.java b/src/com/android/settings/gestures/DoubleTwistGestureSettings.java index 07b40bb2b22..c11f4a515c9 100644 --- a/src/com/android/settings/gestures/DoubleTwistGestureSettings.java +++ b/src/com/android/settings/gestures/DoubleTwistGestureSettings.java @@ -17,12 +17,16 @@ package com.android.settings.gestures; import android.content.Context; +import android.provider.SearchIndexableResource; import com.android.settings.R; import com.android.settings.core.PreferenceController; import com.android.settings.dashboard.DashboardFragment; +import com.android.settings.overlay.FeatureFactory; +import com.android.settings.search.BaseSearchIndexProvider; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; public class DoubleTwistGestureSettings extends DashboardFragment { @@ -55,4 +59,19 @@ public class DoubleTwistGestureSettings extends DashboardFragment { controllers.add(new DoubleTwistPreferenceController(context, getLifecycle())); return controllers; } + + public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = + new BaseSearchIndexProvider() { + @Override + public List getXmlResourcesToIndex( + Context context, boolean enabled) { + if (!FeatureFactory.getFactory(context).getDashboardFeatureProvider(context) + .isEnabled()) { + return null; + } + final SearchIndexableResource sir = new SearchIndexableResource(context); + sir.xmlResId = R.xml.double_twist_gesture_settings; + return Arrays.asList(sir); + } + }; } diff --git a/src/com/android/settings/gestures/PickupGestureSettings.java b/src/com/android/settings/gestures/PickupGestureSettings.java index 1298dfed9c4..63d39680671 100644 --- a/src/com/android/settings/gestures/PickupGestureSettings.java +++ b/src/com/android/settings/gestures/PickupGestureSettings.java @@ -18,13 +18,17 @@ package com.android.settings.gestures; import android.content.Context; import android.os.UserHandle; +import android.provider.SearchIndexableResource; import com.android.internal.hardware.AmbientDisplayConfiguration; import com.android.settings.R; import com.android.settings.core.PreferenceController; import com.android.settings.dashboard.DashboardFragment; +import com.android.settings.overlay.FeatureFactory; +import com.android.settings.search.BaseSearchIndexProvider; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; public class PickupGestureSettings extends DashboardFragment { @@ -58,4 +62,20 @@ public class PickupGestureSettings extends DashboardFragment { new AmbientDisplayConfiguration(context), UserHandle.myUserId())); return controllers; } + + public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = + new BaseSearchIndexProvider() { + @Override + public List getXmlResourcesToIndex( + Context context, boolean enabled) { + if (!FeatureFactory.getFactory(context).getDashboardFeatureProvider(context) + .isEnabled()) { + return null; + } + final SearchIndexableResource sir = new SearchIndexableResource(context); + sir.xmlResId = R.xml.pick_up_gesture_settings; + return Arrays.asList(sir); + } + }; + } diff --git a/src/com/android/settings/gestures/SwipeToNotificationSettings.java b/src/com/android/settings/gestures/SwipeToNotificationSettings.java index 7eeba292f44..57796a6897e 100644 --- a/src/com/android/settings/gestures/SwipeToNotificationSettings.java +++ b/src/com/android/settings/gestures/SwipeToNotificationSettings.java @@ -17,12 +17,16 @@ package com.android.settings.gestures; import android.content.Context; +import android.provider.SearchIndexableResource; import com.android.settings.R; import com.android.settings.core.PreferenceController; import com.android.settings.dashboard.DashboardFragment; +import com.android.settings.overlay.FeatureFactory; +import com.android.settings.search.BaseSearchIndexProvider; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; public class SwipeToNotificationSettings extends DashboardFragment { @@ -55,4 +59,19 @@ public class SwipeToNotificationSettings extends DashboardFragment { controllers.add(new SwipeToNotificationPreferenceController(context, getLifecycle())); return controllers; } + + public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = + new BaseSearchIndexProvider() { + @Override + public List getXmlResourcesToIndex( + Context context, boolean enabled) { + if (!FeatureFactory.getFactory(context).getDashboardFeatureProvider(context) + .isEnabled()) { + return null; + } + final SearchIndexableResource sir = new SearchIndexableResource(context); + sir.xmlResId = R.xml.swipe_to_notification_settings; + return Arrays.asList(sir); + } + }; } diff --git a/src/com/android/settings/search/Indexable.java b/src/com/android/settings/search/Indexable.java index 19f88ae1153..e87d9dca9dd 100644 --- a/src/com/android/settings/search/Indexable.java +++ b/src/com/android/settings/search/Indexable.java @@ -33,7 +33,7 @@ import java.util.List; */ public interface Indexable { - public interface SearchIndexProvider { + interface SearchIndexProvider { /** * Return a list of references for indexing. * diff --git a/src/com/android/settings/search/SearchIndexableResources.java b/src/com/android/settings/search/SearchIndexableResources.java index 959f4444d42..72aee1620d4 100644 --- a/src/com/android/settings/search/SearchIndexableResources.java +++ b/src/com/android/settings/search/SearchIndexableResources.java @@ -46,7 +46,12 @@ import com.android.settings.display.ScreenZoomSettings; import com.android.settings.enterprise.EnterprisePrivacySettings; import com.android.settings.fuelgauge.BatterySaverSettings; import com.android.settings.fuelgauge.PowerUsageSummary; +import com.android.settings.gestures.DoubleTapPowerSettings; +import com.android.settings.gestures.DoubleTapScreenSettings; +import com.android.settings.gestures.DoubleTwistGestureSettings; import com.android.settings.gestures.GestureSettings; +import com.android.settings.gestures.PickupGestureSettings; +import com.android.settings.gestures.SwipeToNotificationSettings; import com.android.settings.inputmethod.InputMethodAndLanguageSettings; import com.android.settings.location.LocationSettings; import com.android.settings.location.ScanningSettings; @@ -114,6 +119,12 @@ public final class SearchIndexableResources { R.xml.special_access, R.drawable.ic_settings_applications); addIndex(UserSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_multiuser); addIndex(GestureSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_gestures); + addIndex(PickupGestureSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_gestures); + addIndex(DoubleTapScreenSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_gestures); + addIndex(DoubleTapPowerSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_gestures); + addIndex(DoubleTwistGestureSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_gestures); + addIndex(SwipeToNotificationSettings.class, NO_DATA_RES_ID, + R.drawable.ic_settings_gestures); addIndex(LocationSettings.class, R.xml.location_settings, R.drawable.ic_settings_location); addIndex(ScanningSettings.class, R.xml.location_scanning, R.drawable.ic_settings_location); addIndex(SecuritySettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_security); diff --git a/tests/robotests/assets/grandfather_not_implementing_index_provider b/tests/robotests/assets/grandfather_not_implementing_index_provider index 554ea3c8291..2b3ca09f5ff 100644 --- a/tests/robotests/assets/grandfather_not_implementing_index_provider +++ b/tests/robotests/assets/grandfather_not_implementing_index_provider @@ -1,14 +1,8 @@ -com.android.settings.connecteddevice.ConnectedDeviceDashboardFragment -com.android.settings.gestures.PickupGestureSettings com.android.settings.notification.ConfigureNotificationSettings com.android.settings.language.LanguageAndRegionSettings com.android.settings.accounts.UserAndAccountDashboardFragment -com.android.settings.gestures.DoubleTapScreenSettings com.android.settings.network.NetworkDashboardFragment com.android.settings.applications.AppAndNotificationDashboardFragment -com.android.settings.gestures.SwipeToNotificationSettings com.android.settings.notification.ZenModePrioritySettings -com.android.settings.gestures.DoubleTapPowerSettings com.android.settings.inputmethod.InputAndGestureSettings -com.android.settings.gestures.DoubleTwistGestureSettings com.android.settings.accounts.AccountDetailDashboardFragment \ No newline at end of file diff --git a/tests/robotests/src/com/android/settings/gestures/DoubleTapPowerSettingsTest.java b/tests/robotests/src/com/android/settings/gestures/DoubleTapPowerSettingsTest.java new file mode 100644 index 00000000000..b5fdfea1496 --- /dev/null +++ b/tests/robotests/src/com/android/settings/gestures/DoubleTapPowerSettingsTest.java @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.settings.gestures; + +import android.content.Context; +import android.provider.SearchIndexableResource; + +import com.android.settings.SettingsRobolectricTestRunner; +import com.android.settings.TestConfig; +import com.android.settings.testutils.FakeFeatureFactory; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Answers; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.robolectric.annotation.Config; +import org.robolectric.shadows.ShadowApplication; + +import java.util.List; + +import static com.google.common.truth.Truth.assertThat; +import static org.mockito.Mockito.when; + +@RunWith(SettingsRobolectricTestRunner.class) +@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) +public class DoubleTapPowerSettingsTest { + + @Mock(answer = Answers.RETURNS_DEEP_STUBS) + private Context mContext; + + private DoubleTapPowerSettings mSettings; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + FakeFeatureFactory.setupForTest(mContext); + final FakeFeatureFactory factory = + (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext); + when(factory.dashboardFeatureProvider.isEnabled()).thenReturn(true); + mSettings = new DoubleTapPowerSettings(); + } + + @Test + public void testSearchIndexProvider_shouldIndexResource() { + final List indexRes = + DoubleTapPowerSettings.SEARCH_INDEX_DATA_PROVIDER.getXmlResourcesToIndex( + ShadowApplication.getInstance().getApplicationContext(), + true /* enabled */); + + assertThat(indexRes).isNotNull(); + assertThat(indexRes.get(0).xmlResId).isEqualTo(mSettings.getPreferenceScreenResId()); + } +} diff --git a/tests/robotests/src/com/android/settings/gestures/DoubleTapScreenSettingsTest.java b/tests/robotests/src/com/android/settings/gestures/DoubleTapScreenSettingsTest.java new file mode 100644 index 00000000000..c0aac43846f --- /dev/null +++ b/tests/robotests/src/com/android/settings/gestures/DoubleTapScreenSettingsTest.java @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.settings.gestures; + +import android.content.Context; +import android.provider.SearchIndexableResource; + +import com.android.settings.SettingsRobolectricTestRunner; +import com.android.settings.TestConfig; +import com.android.settings.testutils.FakeFeatureFactory; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Answers; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.robolectric.annotation.Config; +import org.robolectric.shadows.ShadowApplication; + +import java.util.List; + +import static com.google.common.truth.Truth.assertThat; +import static org.mockito.Mockito.when; + +@RunWith(SettingsRobolectricTestRunner.class) +@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) +public class DoubleTapScreenSettingsTest { + + @Mock(answer = Answers.RETURNS_DEEP_STUBS) + private Context mContext; + + private DoubleTapScreenSettings mSettings; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + FakeFeatureFactory.setupForTest(mContext); + final FakeFeatureFactory factory = + (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext); + when(factory.dashboardFeatureProvider.isEnabled()).thenReturn(true); + mSettings = new DoubleTapScreenSettings(); + } + + @Test + public void testSearchIndexProvider_shouldIndexResource() { + final List indexRes = + DoubleTapScreenSettings.SEARCH_INDEX_DATA_PROVIDER.getXmlResourcesToIndex( + ShadowApplication.getInstance().getApplicationContext(), + true /* enabled */); + + assertThat(indexRes).isNotNull(); + assertThat(indexRes.get(0).xmlResId).isEqualTo(mSettings.getPreferenceScreenResId()); + } +} diff --git a/tests/robotests/src/com/android/settings/gestures/DoubleTwistGestureSettingsTest.java b/tests/robotests/src/com/android/settings/gestures/DoubleTwistGestureSettingsTest.java new file mode 100644 index 00000000000..f2a56d7fba6 --- /dev/null +++ b/tests/robotests/src/com/android/settings/gestures/DoubleTwistGestureSettingsTest.java @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.settings.gestures; + +import android.content.Context; +import android.provider.SearchIndexableResource; + +import com.android.settings.SettingsRobolectricTestRunner; +import com.android.settings.TestConfig; +import com.android.settings.testutils.FakeFeatureFactory; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Answers; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.robolectric.annotation.Config; +import org.robolectric.shadows.ShadowApplication; + +import java.util.List; + +import static com.google.common.truth.Truth.assertThat; +import static org.mockito.Mockito.when; + +@RunWith(SettingsRobolectricTestRunner.class) +@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) +public class DoubleTwistGestureSettingsTest { + @Mock(answer = Answers.RETURNS_DEEP_STUBS) + private Context mContext; + + private DoubleTwistGestureSettings mSettings; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + FakeFeatureFactory.setupForTest(mContext); + final FakeFeatureFactory factory = + (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext); + when(factory.dashboardFeatureProvider.isEnabled()).thenReturn(true); + mSettings = new DoubleTwistGestureSettings(); + } + + @Test + public void testSearchIndexProvider_shouldIndexResource() { + final List indexRes = + DoubleTwistGestureSettings.SEARCH_INDEX_DATA_PROVIDER.getXmlResourcesToIndex( + ShadowApplication.getInstance().getApplicationContext(), + true /* enabled */); + + assertThat(indexRes).isNotNull(); + assertThat(indexRes.get(0).xmlResId).isEqualTo(mSettings.getPreferenceScreenResId()); + } +} diff --git a/tests/robotests/src/com/android/settings/gestures/PickupGestureSettingsTest.java b/tests/robotests/src/com/android/settings/gestures/PickupGestureSettingsTest.java new file mode 100644 index 00000000000..cf088361733 --- /dev/null +++ b/tests/robotests/src/com/android/settings/gestures/PickupGestureSettingsTest.java @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.settings.gestures; + +import android.content.Context; +import android.provider.SearchIndexableResource; + +import com.android.settings.SettingsRobolectricTestRunner; +import com.android.settings.TestConfig; +import com.android.settings.testutils.FakeFeatureFactory; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Answers; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.robolectric.annotation.Config; +import org.robolectric.shadows.ShadowApplication; + +import java.util.List; + +import static com.google.common.truth.Truth.assertThat; +import static org.mockito.Mockito.when; + +@RunWith(SettingsRobolectricTestRunner.class) +@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) +public class PickupGestureSettingsTest { + + @Mock(answer = Answers.RETURNS_DEEP_STUBS) + private Context mContext; + + private PickupGestureSettings mSettings; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + FakeFeatureFactory.setupForTest(mContext); + final FakeFeatureFactory factory = + (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext); + when(factory.dashboardFeatureProvider.isEnabled()).thenReturn(true); + mSettings = new PickupGestureSettings(); + } + + @Test + public void testSearchIndexProvider_shouldIndexResource() { + final List indexRes = + PickupGestureSettings.SEARCH_INDEX_DATA_PROVIDER.getXmlResourcesToIndex( + ShadowApplication.getInstance().getApplicationContext(), + true /* enabled */); + + assertThat(indexRes).isNotNull(); + assertThat(indexRes.get(0).xmlResId).isEqualTo(mSettings.getPreferenceScreenResId()); + } + +} diff --git a/tests/robotests/src/com/android/settings/gestures/SwipeToNotificationSettingsTest.java b/tests/robotests/src/com/android/settings/gestures/SwipeToNotificationSettingsTest.java index 19185a080d2..b9f3bac7466 100644 --- a/tests/robotests/src/com/android/settings/gestures/SwipeToNotificationSettingsTest.java +++ b/tests/robotests/src/com/android/settings/gestures/SwipeToNotificationSettingsTest.java @@ -17,11 +17,13 @@ package com.android.settings.gestures; import android.content.Context; +import android.provider.SearchIndexableResource; import com.android.settings.R; import com.android.settings.SettingsRobolectricTestRunner; import com.android.settings.TestConfig; import com.android.settings.core.PreferenceController; +import com.android.settings.testutils.FakeFeatureFactory; import org.junit.Before; import org.junit.Test; @@ -30,10 +32,12 @@ import org.mockito.Answers; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.robolectric.annotation.Config; +import org.robolectric.shadows.ShadowApplication; import java.util.List; import static com.google.common.truth.Truth.assertThat; +import static org.mockito.Mockito.when; @RunWith(SettingsRobolectricTestRunner.class) @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) @@ -46,6 +50,10 @@ public class SwipeToNotificationSettingsTest { @Before public void setUp() { MockitoAnnotations.initMocks(this); + FakeFeatureFactory.setupForTest(mContext); + final FakeFeatureFactory factory = + (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext); + when(factory.dashboardFeatureProvider.isEnabled()).thenReturn(true); mFragment = new SwipeToNotificationSettings(); } @@ -62,4 +70,14 @@ public class SwipeToNotificationSettingsTest { assertThat(controllers.isEmpty()).isFalse(); } + @Test + public void testSearchIndexProvider_shouldIndexResource() { + final List indexRes = + SwipeToNotificationSettings.SEARCH_INDEX_DATA_PROVIDER.getXmlResourcesToIndex( + ShadowApplication.getInstance().getApplicationContext(), + true /* enabled */); + + assertThat(indexRes).isNotNull(); + assertThat(indexRes.get(0).xmlResId).isEqualTo(mFragment.getPreferenceScreenResId()); + } }