Hide Location Mode from search results if it's not available.

Test: make RunSettingsRoboTests ROBOTEST_FILTER=LocationModeTest all
passes.
Bug: 70283459
Change-Id: Id99d4a8f694b6f223ee8ead9701569840e333a9e
This commit is contained in:
Ben Lin
2017-12-06 11:31:55 -08:00
parent 30ba48c540
commit d11d08658f
2 changed files with 78 additions and 0 deletions

View File

@@ -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<AbstractPreferenceController> getPreferenceControllers(Context
context) {

View File

@@ -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<SearchIndexableResource> 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<String> niks = LocationMode.SEARCH_INDEX_DATA_PROVIDER
.getNonIndexableKeys(mContext);
final int xmlId = mFragment.getPreferenceScreenResId();
final List<String> keys = XmlTestUtils.getKeysFromPreferenceXml(mContext, xmlId);
assertThat(niks).containsAllIn(keys);
}
}