Create a feature flag for Search v2.
Also moved all other flags in a common file so we can track them more easily. Bug: 68825426 Bug: 64938328 Test: rerun robotests Change-Id: I3fc805054cb960bedd965b1b907be759df50b95d
This commit is contained in:
@@ -17,7 +17,6 @@
|
||||
package com.android.settings;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
@@ -29,13 +28,11 @@ import static org.mockito.Mockito.when;
|
||||
import android.app.ActivityManager;
|
||||
import android.app.FragmentManager;
|
||||
import android.app.FragmentTransaction;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.android.settings.search.SearchActivity;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -46,7 +43,6 @@ import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
@@ -97,15 +93,4 @@ public class SettingsActivityTest {
|
||||
|
||||
assertThat((boolean) bundle.get(SettingsActivity.SAVE_KEY_SHOW_HOME_AS_UP)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnClick() {
|
||||
doReturn("com.android.settings").when(mActivity).getPackageName();
|
||||
|
||||
mActivity.onClick(null);
|
||||
|
||||
Intent intent = ShadowApplication.getInstance().getNextStartedActivity();
|
||||
assertThat(intent.getComponent()).isEqualTo(
|
||||
new ComponentName("com.android.settings", SearchActivity.class.getName()));
|
||||
}
|
||||
}
|
||||
|
@@ -31,9 +31,9 @@ import android.util.FeatureFlagUtils;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowSystemProperties;
|
||||
import com.android.settings.TestConfig;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
@@ -45,7 +45,7 @@ import org.robolectric.annotation.Config;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION, shadows = {
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O, shadows = {
|
||||
SettingsShadowSystemProperties.class
|
||||
})
|
||||
public class InstrumentedPreferenceFragmentTest {
|
||||
@@ -76,7 +76,7 @@ public class InstrumentedPreferenceFragmentTest {
|
||||
@Test
|
||||
public void onCreatePreferences_noPreferenceScreenResId_shouldNotAddPreference() {
|
||||
SettingsShadowSystemProperties.set(
|
||||
FeatureFlagUtils.FFLAG_PREFIX + mFragment.FEATURE_FLAG_USE_PREFERENCE_SCREEN_TITLE,
|
||||
FeatureFlagUtils.FFLAG_PREFIX + FeatureFlags.USE_PREFERENCE_SCREEN_TITLE,
|
||||
"true");
|
||||
|
||||
mFragment.onCreatePreferences(Bundle.EMPTY, null /* rootKey */);
|
||||
@@ -87,7 +87,7 @@ public class InstrumentedPreferenceFragmentTest {
|
||||
@Test
|
||||
public void onCreatePreferences_gotPreferenceScreenResId_shouldAddPreferences() {
|
||||
SettingsShadowSystemProperties.set(
|
||||
FeatureFlagUtils.FFLAG_PREFIX + mFragment.FEATURE_FLAG_USE_PREFERENCE_SCREEN_TITLE,
|
||||
FeatureFlagUtils.FFLAG_PREFIX + FeatureFlags.USE_PREFERENCE_SCREEN_TITLE,
|
||||
"true");
|
||||
mFragment.setPreferenceScreenResId(R.xml.screen_pinning_settings);
|
||||
when(mFragment.getActivity()).thenReturn(mActivity);
|
||||
@@ -101,7 +101,7 @@ public class InstrumentedPreferenceFragmentTest {
|
||||
@Test
|
||||
public void onCreatePreferences_gotPrefScreenResIdAndTitle_shouldAddPreferencesAndSetTitle() {
|
||||
SettingsShadowSystemProperties.set(
|
||||
FeatureFlagUtils.FFLAG_PREFIX + mFragment.FEATURE_FLAG_USE_PREFERENCE_SCREEN_TITLE,
|
||||
FeatureFlagUtils.FFLAG_PREFIX + FeatureFlags.USE_PREFERENCE_SCREEN_TITLE,
|
||||
"true");
|
||||
mFragment.setPreferenceScreenResId(R.xml.screen_pinning_settings);
|
||||
when(mFragment.getActivity()).thenReturn(mActivity);
|
||||
@@ -114,14 +114,11 @@ public class InstrumentedPreferenceFragmentTest {
|
||||
verify(mActivity).setTitle(title);
|
||||
}
|
||||
|
||||
private static class InstrumentedPreferenceFragmentTestable
|
||||
public static class InstrumentedPreferenceFragmentTestable
|
||||
extends InstrumentedPreferenceFragment {
|
||||
|
||||
private int mScreenId = -1;
|
||||
|
||||
public InstrumentedPreferenceFragmentTestable() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsEvent.VIEW_UNKNOWN;
|
||||
|
@@ -42,6 +42,7 @@ import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.Settings.NightDisplaySuggestionActivity;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.core.FeatureFlags;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||
@@ -67,7 +68,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION, shadows = {
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O, shadows = {
|
||||
ShadowSecureSettings.class,
|
||||
SettingsShadowResources.class,
|
||||
SettingsShadowSystemProperties.class
|
||||
@@ -136,7 +137,7 @@ public class SuggestionFeatureProviderImplTest {
|
||||
public void isSuggestionV2Enabled_isNotLowMemoryDevice_sysPropOn_shouldReturnTrue() {
|
||||
when(mActivityManager.isLowRamDevice()).thenReturn(false);
|
||||
SettingsShadowSystemProperties.set(
|
||||
FeatureFlagUtils.FFLAG_PREFIX + mProvider.FEATURE_FLAG_SUGGESTIONS_V2, "true");
|
||||
FeatureFlagUtils.FFLAG_PREFIX + FeatureFlags.SUGGESTIONS_V2, "true");
|
||||
assertThat(mProvider.isSuggestionV2Enabled(mContext)).isTrue();
|
||||
}
|
||||
|
||||
|
@@ -18,13 +18,24 @@
|
||||
package com.android.settings.search;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.robolectric.Shadows.shadowOf;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Intent;
|
||||
import android.util.FeatureFlagUtils;
|
||||
import android.widget.Toolbar;
|
||||
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.core.FeatureFlags;
|
||||
import com.android.settings.dashboard.SiteMapManager;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowSystemProperties;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -32,13 +43,12 @@ import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O, shadows = {
|
||||
SettingsShadowSystemProperties.class
|
||||
})
|
||||
public class SearchFeatureProviderImplTest {
|
||||
|
||||
private SearchFeatureProviderImpl mProvider;
|
||||
private Activity mActivity;
|
||||
|
||||
@@ -49,6 +59,11 @@ public class SearchFeatureProviderImplTest {
|
||||
mProvider = spy(new SearchFeatureProviderImpl());
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
SettingsShadowSystemProperties.clear();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSiteMapManager_shouldCacheInstance() {
|
||||
final SiteMapManager manager1 = mProvider.getSiteMapManager();
|
||||
@@ -75,13 +90,51 @@ public class SearchFeatureProviderImplTest {
|
||||
verify(mProvider).cleanQuery(eq(query));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initSearchToolbar_searchV2_shouldInitWithOnClickListener() {
|
||||
mProvider.initSearchToolbar(mActivity, null);
|
||||
// Should not crash.
|
||||
|
||||
SettingsShadowSystemProperties.set(
|
||||
FeatureFlagUtils.FFLAG_PREFIX + FeatureFlags.SEARCH_V2,
|
||||
"true");
|
||||
final Toolbar toolbar = new Toolbar(mActivity);
|
||||
mProvider.initSearchToolbar(mActivity, toolbar);
|
||||
|
||||
toolbar.performClick();
|
||||
|
||||
final Intent launchIntent = shadowOf(mActivity).getNextStartedActivity();
|
||||
|
||||
assertThat(launchIntent.getAction())
|
||||
.isEqualTo("com.android.settings.action.SETTINGS_SEARCH");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initSearchToolbar_searchV1_shouldInitWithOnClickListener() {
|
||||
mProvider.initSearchToolbar(mActivity, null);
|
||||
// Should not crash.
|
||||
|
||||
SettingsShadowSystemProperties.set(
|
||||
FeatureFlagUtils.FFLAG_PREFIX + FeatureFlags.SEARCH_V2,
|
||||
"false");
|
||||
final Toolbar toolbar = new Toolbar(mActivity);
|
||||
mProvider.initSearchToolbar(mActivity, toolbar);
|
||||
|
||||
toolbar.performClick();
|
||||
|
||||
final Intent launchIntent = shadowOf(mActivity).getNextStartedActivity();
|
||||
|
||||
assertThat(launchIntent.getComponent().getClassName())
|
||||
.isEqualTo(SearchActivity.class.getName());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void verifyLaunchSearchResultPageCaller_nullCaller_shouldCrash() {
|
||||
mProvider.verifyLaunchSearchResultPageCaller(mActivity, null /* caller */);
|
||||
}
|
||||
|
||||
@Test(expected = SecurityException.class)
|
||||
public void everifyLaunchSearchResultPageCaller_badCaller_shouldCrash() {
|
||||
public void verifyLaunchSearchResultPageCaller_badCaller_shouldCrash() {
|
||||
final ComponentName cn = new ComponentName("pkg", "class");
|
||||
mProvider.verifyLaunchSearchResultPageCaller(mActivity, cn);
|
||||
}
|
||||
|
Reference in New Issue
Block a user