Merge "Allow page to suppress all of its content from search."
This commit is contained in:
committed by
Android (Google) Code Review
commit
0ef2a55b08
@@ -16,22 +16,29 @@
|
||||
|
||||
package com.android.settings.enterprise;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
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;
|
||||
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 static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* Tests for {@link EnterprisePrivacySettings}.
|
||||
*/
|
||||
@@ -39,10 +46,17 @@ import java.util.List;
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public final class EnterprisePrivacySettingsTest {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Context mContext;
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
private EnterprisePrivacySettings mSettings;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
FakeFeatureFactory.setupForTest(mContext);
|
||||
mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
|
||||
|
||||
mSettings = new EnterprisePrivacySettings();
|
||||
}
|
||||
|
||||
@@ -68,6 +82,24 @@ public final class EnterprisePrivacySettingsTest {
|
||||
.isEqualTo(R.xml.enterprise_privacy_settings);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isPageEnabled_hasDeviceOwner_shouldReturnTrue() {
|
||||
when(mFeatureFactory.enterprisePrivacyFeatureProvider.hasDeviceOwner())
|
||||
.thenReturn(true);
|
||||
|
||||
assertThat(EnterprisePrivacySettings.isPageEnabled(mContext))
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isPageEnabled_noDeviceOwner_shouldReturnFalse() {
|
||||
when(mFeatureFactory.enterprisePrivacyFeatureProvider.hasDeviceOwner())
|
||||
.thenReturn(false);
|
||||
|
||||
assertThat(EnterprisePrivacySettings.isPageEnabled(mContext))
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPreferenceControllers() {
|
||||
final List<PreferenceController> controllers = mSettings.getPreferenceControllers(
|
||||
|
@@ -18,7 +18,9 @@ package com.android.settings.search;
|
||||
|
||||
|
||||
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;
|
||||
@@ -28,9 +30,11 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@@ -96,4 +100,34 @@ public class BaseSearchIndexProviderTest {
|
||||
|
||||
assertThat(mIndexProvider.getNonIndexableKeys(mContext)).contains(TEST_PREF_KEY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getNonIndexableKeys_pageSearchIsDisabled_shouldSuppressEverything() {
|
||||
final BaseSearchIndexProvider provider = new BaseSearchIndexProvider() {
|
||||
@Override
|
||||
public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
|
||||
boolean enabled) {
|
||||
final SearchIndexableResource sir = new SearchIndexableResource(context);
|
||||
sir.xmlResId = R.xml.language_and_input;
|
||||
return Arrays.asList(sir);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isPageSearchEnabled(Context context) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
final List<String> nonIndexableKeys = provider
|
||||
.getNonIndexableKeys(RuntimeEnvironment.application);
|
||||
|
||||
assertThat(nonIndexableKeys).containsAllOf("phone_language", "spellcheckers_settings",
|
||||
"key_user_dictionary_settings", "gesture_settings_category", "gesture_assist",
|
||||
"gesture_swipe_down_fingerprint", "gesture_double_tap_power",
|
||||
"gesture_double_twist", "gesture_double_tap_screen", "gesture_pick_up",
|
||||
"pointer_settings_category", "pointer_speed", "voice_category", "tts_settings",
|
||||
"game_controller_settings_category", "vibrate_input_devices");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user