Move AutoStorageManagementSwitchPrefCtrl to sdk 26
Test: make RunSettingsRoboTests -j40 Change-Id: I78ee508de3b76d19dc801950ee3513a115d0c22b
This commit is contained in:
@@ -17,6 +17,7 @@
|
|||||||
package com.android.settings.deviceinfo.storage;
|
package com.android.settings.deviceinfo.storage;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.Matchers.any;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.Matchers.eq;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
@@ -34,6 +35,7 @@ import android.support.v7.preference.Preference;
|
|||||||
import android.support.v7.preference.PreferenceScreen;
|
import android.support.v7.preference.PreferenceScreen;
|
||||||
|
|
||||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||||
|
import com.android.internal.os.RoSystemProperties;
|
||||||
import com.android.settings.TestConfig;
|
import com.android.settings.TestConfig;
|
||||||
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
|
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
|
||||||
import com.android.settings.deletionhelper.ActivationWarningFragment;
|
import com.android.settings.deletionhelper.ActivationWarningFragment;
|
||||||
@@ -52,12 +54,13 @@ import org.mockito.Mock;
|
|||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
import org.robolectric.annotation.Config;
|
import org.robolectric.annotation.Config;
|
||||||
|
import org.robolectric.util.ReflectionHelpers;
|
||||||
|
|
||||||
|
|
||||||
@RunWith(SettingsRobolectricTestRunner.class)
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
@Config(
|
@Config(
|
||||||
manifest = TestConfig.MANIFEST_PATH,
|
manifest = TestConfig.MANIFEST_PATH,
|
||||||
sdk = TestConfig.SDK_VERSION,
|
sdk = TestConfig.SDK_VERSION_O,
|
||||||
shadows = {SettingsShadowSystemProperties.class}
|
shadows = {SettingsShadowSystemProperties.class}
|
||||||
)
|
)
|
||||||
public class AutomaticStorageManagementSwitchPreferenceControllerTest {
|
public class AutomaticStorageManagementSwitchPreferenceControllerTest {
|
||||||
@@ -79,13 +82,14 @@ public class AutomaticStorageManagementSwitchPreferenceControllerTest {
|
|||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
mContext = RuntimeEnvironment.application.getApplicationContext();
|
mContext = RuntimeEnvironment.application.getApplicationContext();
|
||||||
FeatureFactory factory = FeatureFactory.getFactory(mContext);
|
final FeatureFactory factory = FeatureFactory.getFactory(mContext);
|
||||||
mMetricsFeature = factory.getMetricsFeatureProvider();
|
mMetricsFeature = factory.getMetricsFeatureProvider();
|
||||||
|
|
||||||
mController = new AutomaticStorageManagementSwitchPreferenceController(
|
mController = new AutomaticStorageManagementSwitchPreferenceController(
|
||||||
mContext, mMetricsFeature, mFragmentManager);
|
mContext, mMetricsFeature, mFragmentManager);
|
||||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
|
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() {
|
public void tearDown() {
|
||||||
SettingsShadowSystemProperties.clear();
|
SettingsShadowSystemProperties.clear();
|
||||||
@@ -98,15 +102,15 @@ public class AutomaticStorageManagementSwitchPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAvailable_shouldAlwaysReturnFalse_forLowRamDevice() {
|
public void isAvailable_shouldAlwaysReturnFalse_forLowRamDevice() {
|
||||||
SettingsShadowSystemProperties.set("ro.config.low_ram", "true");
|
ReflectionHelpers.setStaticField(RoSystemProperties.class, "CONFIG_LOW_RAM", true);
|
||||||
assertThat(mController.isAvailable()).isFalse();
|
assertThat(mController.isAvailable()).isFalse();
|
||||||
SettingsShadowSystemProperties.clear();
|
ReflectionHelpers.setStaticField(RoSystemProperties.class, "CONFIG_LOW_RAM", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onResume_shouldReflectEnabledStatus() {
|
public void onResume_shouldReflectEnabledStatus() {
|
||||||
mController.displayPreference(mScreen);
|
mController.displayPreference(mScreen);
|
||||||
ContentResolver resolver = mContext.getContentResolver();
|
final ContentResolver resolver = mContext.getContentResolver();
|
||||||
Settings.Secure.putInt(resolver, Settings.Secure.AUTOMATIC_STORAGE_MANAGER_ENABLED, 1);
|
Settings.Secure.putInt(resolver, Settings.Secure.AUTOMATIC_STORAGE_MANAGER_ENABLED, 1);
|
||||||
|
|
||||||
mController.onResume();
|
mController.onResume();
|
||||||
@@ -128,9 +132,9 @@ public class AutomaticStorageManagementSwitchPreferenceControllerTest {
|
|||||||
// FakeFeatureFactory uses mock contexts, so this test scaffolds itself rather than using
|
// FakeFeatureFactory uses mock contexts, so this test scaffolds itself rather than using
|
||||||
// the instance variables.
|
// the instance variables.
|
||||||
FakeFeatureFactory.setupForTest(mMockContext);
|
FakeFeatureFactory.setupForTest(mMockContext);
|
||||||
FakeFeatureFactory factory =
|
final FakeFeatureFactory factory =
|
||||||
(FakeFeatureFactory) FakeFeatureFactory.getFactory(mMockContext);
|
(FakeFeatureFactory) FakeFeatureFactory.getFactory(mMockContext);
|
||||||
AutomaticStorageManagementSwitchPreferenceController controller =
|
final AutomaticStorageManagementSwitchPreferenceController controller =
|
||||||
new AutomaticStorageManagementSwitchPreferenceController(
|
new AutomaticStorageManagementSwitchPreferenceController(
|
||||||
mMockContext, factory.metricsFeatureProvider, mFragmentManager);
|
mMockContext, factory.metricsFeatureProvider, mFragmentManager);
|
||||||
|
|
||||||
@@ -144,14 +148,14 @@ public class AutomaticStorageManagementSwitchPreferenceControllerTest {
|
|||||||
public void togglingShouldUpdateSettingsSecure() {
|
public void togglingShouldUpdateSettingsSecure() {
|
||||||
mController.onSwitchToggled(true);
|
mController.onSwitchToggled(true);
|
||||||
|
|
||||||
ContentResolver resolver = mContext.getContentResolver();
|
final ContentResolver resolver = mContext.getContentResolver();
|
||||||
assertThat(Settings.Secure.getInt(
|
assertThat(Settings.Secure.getInt(
|
||||||
resolver, Settings.Secure.AUTOMATIC_STORAGE_MANAGER_ENABLED, 0)).isNotEqualTo(0);
|
resolver, Settings.Secure.AUTOMATIC_STORAGE_MANAGER_ENABLED, 0)).isNotEqualTo(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void togglingOnShouldTriggerWarningFragment() {
|
public void togglingOnShouldTriggerWarningFragment() {
|
||||||
FragmentTransaction transaction = mock(FragmentTransaction.class);
|
final FragmentTransaction transaction = mock(FragmentTransaction.class);
|
||||||
when(mFragmentManager.beginTransaction()).thenReturn(transaction);
|
when(mFragmentManager.beginTransaction()).thenReturn(transaction);
|
||||||
SettingsShadowSystemProperties.set(
|
SettingsShadowSystemProperties.set(
|
||||||
AutomaticStorageManagementSwitchPreferenceController
|
AutomaticStorageManagementSwitchPreferenceController
|
||||||
@@ -164,7 +168,7 @@ public class AutomaticStorageManagementSwitchPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void togglingOffShouldTriggerWarningFragment() {
|
public void togglingOffShouldTriggerWarningFragment() {
|
||||||
FragmentTransaction transaction = mock(FragmentTransaction.class);
|
final FragmentTransaction transaction = mock(FragmentTransaction.class);
|
||||||
when(mFragmentManager.beginTransaction()).thenReturn(transaction);
|
when(mFragmentManager.beginTransaction()).thenReturn(transaction);
|
||||||
|
|
||||||
mController.onSwitchToggled(false);
|
mController.onSwitchToggled(false);
|
||||||
@@ -175,7 +179,7 @@ public class AutomaticStorageManagementSwitchPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void togglingOnShouldNotTriggerWarningFragmentIfEnabledByDefault() {
|
public void togglingOnShouldNotTriggerWarningFragmentIfEnabledByDefault() {
|
||||||
FragmentTransaction transaction = mock(FragmentTransaction.class);
|
final FragmentTransaction transaction = mock(FragmentTransaction.class);
|
||||||
when(mFragmentManager.beginTransaction()).thenReturn(transaction);
|
when(mFragmentManager.beginTransaction()).thenReturn(transaction);
|
||||||
SettingsShadowSystemProperties.set(
|
SettingsShadowSystemProperties.set(
|
||||||
AutomaticStorageManagementSwitchPreferenceController
|
AutomaticStorageManagementSwitchPreferenceController
|
||||||
@@ -188,7 +192,7 @@ public class AutomaticStorageManagementSwitchPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void togglingOnShouldTriggerWarningFragmentIfEnabledByDefaultAndDisabledByPolicy() {
|
public void togglingOnShouldTriggerWarningFragmentIfEnabledByDefaultAndDisabledByPolicy() {
|
||||||
FragmentTransaction transaction = mock(FragmentTransaction.class);
|
final FragmentTransaction transaction = mock(FragmentTransaction.class);
|
||||||
when(mFragmentManager.beginTransaction()).thenReturn(transaction);
|
when(mFragmentManager.beginTransaction()).thenReturn(transaction);
|
||||||
SettingsShadowSystemProperties.set(
|
SettingsShadowSystemProperties.set(
|
||||||
AutomaticStorageManagementSwitchPreferenceController
|
AutomaticStorageManagementSwitchPreferenceController
|
||||||
|
|||||||
Reference in New Issue
Block a user