From d11d08658ff07d594ff50d038dc1e5865327ae08 Mon Sep 17 00:00:00 2001 From: Ben Lin Date: Wed, 6 Dec 2017 11:31:55 -0800 Subject: [PATCH] Hide Location Mode from search results if it's not available. Test: make RunSettingsRoboTests ROBOTEST_FILTER=LocationModeTest all passes. Bug: 70283459 Change-Id: Id99d4a8f694b6f223ee8ead9701569840e333a9e --- .../settings/location/LocationMode.java | 5 ++ .../settings/location/LocationModeTest.java | 73 +++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 tests/robotests/src/com/android/settings/location/LocationModeTest.java diff --git a/src/com/android/settings/location/LocationMode.java b/src/com/android/settings/location/LocationMode.java index 34f082b226a..5931f9e364a 100644 --- a/src/com/android/settings/location/LocationMode.java +++ b/src/com/android/settings/location/LocationMode.java @@ -94,6 +94,11 @@ public class LocationMode extends DashboardFragment { return Arrays.asList(sir); } + @Override + protected boolean isPageSearchEnabled(Context context) { + return context.getResources().getBoolean(R.bool.config_location_mode_available); + } + @Override public List getPreferenceControllers(Context context) { diff --git a/tests/robotests/src/com/android/settings/location/LocationModeTest.java b/tests/robotests/src/com/android/settings/location/LocationModeTest.java new file mode 100644 index 00000000000..0e7a9d72ed0 --- /dev/null +++ b/tests/robotests/src/com/android/settings/location/LocationModeTest.java @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2017 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.location; + +import static com.google.common.truth.Truth.assertThat; +import static org.mockito.Mockito.spy; + +import android.content.Context; +import android.provider.SearchIndexableResource; + +import com.android.settings.TestConfig; +import com.android.settings.testutils.SettingsRobolectricTestRunner; +import com.android.settings.testutils.XmlTestUtils; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.MockitoAnnotations; +import org.robolectric.RuntimeEnvironment; +import org.robolectric.annotation.Config; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +@RunWith(SettingsRobolectricTestRunner.class) +@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) +public class LocationModeTest { + + private Context mContext; + private LocationMode mFragment; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + mContext = spy(RuntimeEnvironment.application); + mFragment = new LocationMode(); + } + + @Test + public void testSearchIndexProvider_shouldIndexResource() { + final List indexRes = + mFragment.SEARCH_INDEX_DATA_PROVIDER.getXmlResourcesToIndex(mContext, + true /* enabled */); + + assertThat(indexRes).isNotNull(); + assertThat(indexRes.get(0).xmlResId).isEqualTo(mFragment.getPreferenceScreenResId()); + } + + @Test + @Config(qualifiers = "mcc999") + public void testSearchIndexProvider_ifPageDisabled_shouldNotIndexResource() { + final List niks = LocationMode.SEARCH_INDEX_DATA_PROVIDER + .getNonIndexableKeys(mContext); + final int xmlId = mFragment.getPreferenceScreenResId(); + + final List keys = XmlTestUtils.getKeysFromPreferenceXml(mContext, xmlId); + assertThat(niks).containsAllIn(keys); + } +}