Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 406def2b authored by jeffreyhuang's avatar jeffreyhuang
Browse files

Move AutoStorageManagementSwitchPrefCtrl to sdk 26

Test: make RunSettingsRoboTests -j40
Change-Id: I78ee508de3b76d19dc801950ee3513a115d0c22b
parent 5b431132
Loading
Loading
Loading
Loading
+21 −17
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.settings.deviceinfo.storage;

import static com.google.common.truth.Truth.assertThat;

import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
@@ -34,6 +35,7 @@ import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;

import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.internal.os.RoSystemProperties;
import com.android.settings.TestConfig;
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
import com.android.settings.deletionhelper.ActivationWarningFragment;
@@ -52,12 +54,13 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.util.ReflectionHelpers;


@RunWith(SettingsRobolectricTestRunner.class)
@Config(
        manifest = TestConfig.MANIFEST_PATH,
    sdk = TestConfig.SDK_VERSION,
        sdk = TestConfig.SDK_VERSION_O,
        shadows = {SettingsShadowSystemProperties.class}
)
public class AutomaticStorageManagementSwitchPreferenceControllerTest {
@@ -79,13 +82,14 @@ public class AutomaticStorageManagementSwitchPreferenceControllerTest {
    public void setUp() {
        MockitoAnnotations.initMocks(this);
        mContext = RuntimeEnvironment.application.getApplicationContext();
        FeatureFactory factory = FeatureFactory.getFactory(mContext);
        final FeatureFactory factory = FeatureFactory.getFactory(mContext);
        mMetricsFeature = factory.getMetricsFeatureProvider();

        mController = new AutomaticStorageManagementSwitchPreferenceController(
                mContext, mMetricsFeature, mFragmentManager);
        when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
    }

    @After
    public void tearDown() {
        SettingsShadowSystemProperties.clear();
@@ -98,15 +102,15 @@ public class AutomaticStorageManagementSwitchPreferenceControllerTest {

    @Test
    public void isAvailable_shouldAlwaysReturnFalse_forLowRamDevice() {
        SettingsShadowSystemProperties.set("ro.config.low_ram", "true");
        ReflectionHelpers.setStaticField(RoSystemProperties.class, "CONFIG_LOW_RAM", true);
        assertThat(mController.isAvailable()).isFalse();
        SettingsShadowSystemProperties.clear();
        ReflectionHelpers.setStaticField(RoSystemProperties.class, "CONFIG_LOW_RAM", false);
    }

    @Test
    public void onResume_shouldReflectEnabledStatus() {
        mController.displayPreference(mScreen);
        ContentResolver resolver = mContext.getContentResolver();
        final ContentResolver resolver = mContext.getContentResolver();
        Settings.Secure.putInt(resolver, Settings.Secure.AUTOMATIC_STORAGE_MANAGER_ENABLED, 1);

        mController.onResume();
@@ -128,9 +132,9 @@ public class AutomaticStorageManagementSwitchPreferenceControllerTest {
        // FakeFeatureFactory uses mock contexts, so this test scaffolds itself rather than using
        // the instance variables.
        FakeFeatureFactory.setupForTest(mMockContext);
        FakeFeatureFactory factory =
        final FakeFeatureFactory factory =
                (FakeFeatureFactory) FakeFeatureFactory.getFactory(mMockContext);
        AutomaticStorageManagementSwitchPreferenceController controller =
        final AutomaticStorageManagementSwitchPreferenceController controller =
                new AutomaticStorageManagementSwitchPreferenceController(
                        mMockContext, factory.metricsFeatureProvider, mFragmentManager);

@@ -144,14 +148,14 @@ public class AutomaticStorageManagementSwitchPreferenceControllerTest {
    public void togglingShouldUpdateSettingsSecure() {
        mController.onSwitchToggled(true);

        ContentResolver resolver = mContext.getContentResolver();
        final ContentResolver resolver = mContext.getContentResolver();
        assertThat(Settings.Secure.getInt(
                resolver, Settings.Secure.AUTOMATIC_STORAGE_MANAGER_ENABLED, 0)).isNotEqualTo(0);
    }

    @Test
    public void togglingOnShouldTriggerWarningFragment() {
        FragmentTransaction transaction = mock(FragmentTransaction.class);
        final FragmentTransaction transaction = mock(FragmentTransaction.class);
        when(mFragmentManager.beginTransaction()).thenReturn(transaction);
        SettingsShadowSystemProperties.set(
                AutomaticStorageManagementSwitchPreferenceController
@@ -164,7 +168,7 @@ public class AutomaticStorageManagementSwitchPreferenceControllerTest {

    @Test
    public void togglingOffShouldTriggerWarningFragment() {
        FragmentTransaction transaction = mock(FragmentTransaction.class);
        final FragmentTransaction transaction = mock(FragmentTransaction.class);
        when(mFragmentManager.beginTransaction()).thenReturn(transaction);

        mController.onSwitchToggled(false);
@@ -175,7 +179,7 @@ public class AutomaticStorageManagementSwitchPreferenceControllerTest {

    @Test
    public void togglingOnShouldNotTriggerWarningFragmentIfEnabledByDefault() {
        FragmentTransaction transaction = mock(FragmentTransaction.class);
        final FragmentTransaction transaction = mock(FragmentTransaction.class);
        when(mFragmentManager.beginTransaction()).thenReturn(transaction);
        SettingsShadowSystemProperties.set(
                AutomaticStorageManagementSwitchPreferenceController
@@ -188,7 +192,7 @@ public class AutomaticStorageManagementSwitchPreferenceControllerTest {

    @Test
    public void togglingOnShouldTriggerWarningFragmentIfEnabledByDefaultAndDisabledByPolicy() {
        FragmentTransaction transaction = mock(FragmentTransaction.class);
        final FragmentTransaction transaction = mock(FragmentTransaction.class);
        when(mFragmentManager.beginTransaction()).thenReturn(transaction);
        SettingsShadowSystemProperties.set(
                AutomaticStorageManagementSwitchPreferenceController