Merge "Make Settings robotest work with tot Robolectric"
This commit is contained in:
committed by
Android (Google) Code Review
commit
6d2fbea6e5
@@ -68,7 +68,7 @@ public class AdbPreferenceControllerTest {
|
||||
@Test
|
||||
public void onDeveloperOptionsDisabled_shouldDisablePreference() {
|
||||
mController.onDeveloperOptionsDisabled();
|
||||
final int mode = Settings.System.getInt(mContext.getContentResolver(),
|
||||
final int mode = Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.ADB_ENABLED, -1);
|
||||
|
||||
assertThat(mode).isEqualTo(AdbPreferenceController.ADB_SETTING_OFF);
|
||||
@@ -79,7 +79,7 @@ public class AdbPreferenceControllerTest {
|
||||
@Test
|
||||
public void onAdbDialogConfirmed_shouldEnableAdbSetting() {
|
||||
mController.onAdbDialogConfirmed();
|
||||
final int mode = Settings.System.getInt(mContext.getContentResolver(),
|
||||
final int mode = Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.ADB_ENABLED, -1);
|
||||
|
||||
assertThat(mode).isEqualTo(AdbPreferenceController.ADB_SETTING_ON);
|
||||
@@ -87,7 +87,7 @@ public class AdbPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void onAdbDialogDismissed_preferenceShouldNotBeChecked() {
|
||||
Settings.System.putInt(mContext.getContentResolver(), Settings.Global.ADB_ENABLED,
|
||||
Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.ADB_ENABLED,
|
||||
AdbPreferenceController.ADB_SETTING_OFF);
|
||||
mController.onAdbDialogDismissed();
|
||||
|
||||
|
@@ -25,6 +25,7 @@ import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.SystemProperties;
|
||||
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.preference.SwitchPreference;
|
||||
@@ -37,7 +38,6 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.shadows.ShadowSystemProperties;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class BluetoothDeviceNoNamePreferenceControllerTest {
|
||||
@@ -56,7 +56,7 @@ public class BluetoothDeviceNoNamePreferenceControllerTest {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mController = new BluetoothDeviceNoNamePreferenceController(mContext);
|
||||
when(mPreferenceScreen.findPreference(mController.getPreferenceKey()))
|
||||
.thenReturn(mPreference);
|
||||
.thenReturn(mPreference);
|
||||
mController.displayPreference(mPreferenceScreen);
|
||||
}
|
||||
|
||||
@@ -64,8 +64,9 @@ public class BluetoothDeviceNoNamePreferenceControllerTest {
|
||||
public void onPreferenceChanged_settingEnabled_shouldTurnOnBluetoothDeviceNoName() {
|
||||
mController.onPreferenceChange(mPreference, true /* new value */);
|
||||
|
||||
final boolean mode = ShadowSystemProperties
|
||||
.native_get_boolean(BLUETOOTH_SHOW_DEVICES_WITHOUT_NAMES_PROPERTY, false /* default */);
|
||||
final boolean mode = SystemProperties.getBoolean(
|
||||
BLUETOOTH_SHOW_DEVICES_WITHOUT_NAMES_PROPERTY,
|
||||
false /* default */);
|
||||
|
||||
assertThat(mode).isTrue();
|
||||
}
|
||||
@@ -74,16 +75,16 @@ public class BluetoothDeviceNoNamePreferenceControllerTest {
|
||||
public void onPreferenceChanged_settingDisabled_shouldTurnOffBluetoothDeviceNoName() {
|
||||
mController.onPreferenceChange(mPreference, false /* new value */);
|
||||
|
||||
final boolean mode = ShadowSystemProperties
|
||||
.native_get_boolean(BLUETOOTH_SHOW_DEVICES_WITHOUT_NAMES_PROPERTY, true /* default */);
|
||||
final boolean mode = SystemProperties.getBoolean(
|
||||
BLUETOOTH_SHOW_DEVICES_WITHOUT_NAMES_PROPERTY, true /* default */);
|
||||
|
||||
assertThat(mode).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_settingEnabled_preferenceShouldBeChecked() {
|
||||
ShadowSystemProperties
|
||||
.native_set(BLUETOOTH_SHOW_DEVICES_WITHOUT_NAMES_PROPERTY, Boolean.toString(true));
|
||||
SystemProperties.set(BLUETOOTH_SHOW_DEVICES_WITHOUT_NAMES_PROPERTY,
|
||||
Boolean.toString(true));
|
||||
mController.updateState(mPreference);
|
||||
|
||||
verify(mPreference).setChecked(true);
|
||||
@@ -91,8 +92,8 @@ public class BluetoothDeviceNoNamePreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void updateState_settingDisabled_preferenceShouldNotBeChecked() {
|
||||
ShadowSystemProperties
|
||||
.native_set(BLUETOOTH_SHOW_DEVICES_WITHOUT_NAMES_PROPERTY, Boolean.toString(false));
|
||||
SystemProperties.set(BLUETOOTH_SHOW_DEVICES_WITHOUT_NAMES_PROPERTY,
|
||||
Boolean.toString(false));
|
||||
mController.updateState(mPreference);
|
||||
|
||||
verify(mPreference).setChecked(false);
|
||||
@@ -102,8 +103,9 @@ public class BluetoothDeviceNoNamePreferenceControllerTest {
|
||||
public void onDeveloperOptionsDisabled_shouldDisablePreference() {
|
||||
mController.onDeveloperOptionsDisabled();
|
||||
|
||||
final boolean mode = ShadowSystemProperties
|
||||
.native_get_boolean(BLUETOOTH_SHOW_DEVICES_WITHOUT_NAMES_PROPERTY, true /* default */);
|
||||
final boolean mode = SystemProperties.getBoolean(
|
||||
BLUETOOTH_SHOW_DEVICES_WITHOUT_NAMES_PROPERTY,
|
||||
true /* default */);
|
||||
|
||||
assertThat(mode).isFalse();
|
||||
verify(mPreference).setEnabled(false);
|
||||
|
@@ -61,7 +61,7 @@ public class DebugViewAttributesPreferenceControllerTest {
|
||||
public void onPreferenceChanged_turnOnViewAttributes() {
|
||||
mController.onPreferenceChange(null, true);
|
||||
|
||||
final int mode = Settings.System.getInt(mContext.getContentResolver(),
|
||||
final int mode = Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.DEBUG_VIEW_ATTRIBUTES, -1);
|
||||
|
||||
assertThat(mode).isEqualTo(DebugViewAttributesPreferenceController.SETTING_VALUE_ON);
|
||||
@@ -71,7 +71,7 @@ public class DebugViewAttributesPreferenceControllerTest {
|
||||
public void onPreferenceChanged_turnOffViewAttributes() {
|
||||
mController.onPreferenceChange(null, false);
|
||||
|
||||
final int mode = Settings.System.getInt(mContext.getContentResolver(),
|
||||
final int mode = Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.DEBUG_VIEW_ATTRIBUTES, -1);
|
||||
|
||||
assertThat(mode).isEqualTo(DebugViewAttributesPreferenceController.SETTING_VALUE_OFF);
|
||||
@@ -79,7 +79,7 @@ public class DebugViewAttributesPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void updateState_preferenceShouldBeChecked() {
|
||||
Settings.System.putInt(mContext.getContentResolver(), Settings.Global.DEBUG_VIEW_ATTRIBUTES,
|
||||
Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.DEBUG_VIEW_ATTRIBUTES,
|
||||
DebugViewAttributesPreferenceController.SETTING_VALUE_ON);
|
||||
mController.updateState(mPreference);
|
||||
|
||||
@@ -88,7 +88,7 @@ public class DebugViewAttributesPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void updateState_preferenceShouldNotBeChecked() {
|
||||
Settings.System.putInt(mContext.getContentResolver(), Settings.Global.DEBUG_VIEW_ATTRIBUTES,
|
||||
Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.DEBUG_VIEW_ATTRIBUTES,
|
||||
DebugViewAttributesPreferenceController.SETTING_VALUE_OFF);
|
||||
mController.updateState(mPreference);
|
||||
|
||||
@@ -98,7 +98,7 @@ public class DebugViewAttributesPreferenceControllerTest {
|
||||
@Test
|
||||
public void onDeveloperOptionsDisabled_shouldDisablePreference() {
|
||||
mController.onDeveloperOptionsDisabled();
|
||||
final int mode = Settings.System.getInt(mContext.getContentResolver(),
|
||||
final int mode = Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.DEBUG_VIEW_ATTRIBUTES, -1);
|
||||
|
||||
assertThat(mode).isEqualTo(DebugViewAttributesPreferenceController.SETTING_VALUE_OFF);
|
||||
|
@@ -25,7 +25,6 @@ import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.UserManager;
|
||||
import android.provider.SearchIndexableResource;
|
||||
import android.provider.Settings;
|
||||
|
||||
@@ -33,6 +32,7 @@ import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||
import com.android.settings.testutils.shadow.ShadowUserManager;
|
||||
import com.android.settings.widget.SwitchBar;
|
||||
import com.android.settings.widget.ToggleSwitch;
|
||||
import com.android.settingslib.development.AbstractEnableAdbPreferenceController;
|
||||
@@ -44,16 +44,15 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.Shadows;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.annotation.Implementation;
|
||||
import org.robolectric.annotation.Implements;
|
||||
import org.robolectric.shadows.ShadowUserManager;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(shadows = ShadowUserManager.class)
|
||||
public class DevelopmentSettingsDashboardFragmentTest {
|
||||
|
||||
private ToggleSwitch mSwitch;
|
||||
@@ -69,14 +68,14 @@ public class DevelopmentSettingsDashboardFragmentTest {
|
||||
mSwitch = switchBar.getSwitch();
|
||||
mDashboard = spy(new DevelopmentSettingsDashboardFragment());
|
||||
ReflectionHelpers.setField(mDashboard, "mSwitchBar", switchBar);
|
||||
UserManager userManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
|
||||
mShadowUserManager = Shadows.shadowOf(userManager);
|
||||
mShadowUserManager = ShadowUserManager.getShadow();
|
||||
mShadowUserManager.setIsAdminUser(true);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
ShadowEnableDevelopmentSettingWarningDialog.reset();
|
||||
mShadowUserManager.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -87,7 +86,7 @@ public class DevelopmentSettingsDashboardFragmentTest {
|
||||
@Test
|
||||
public void shouldLogAsFeatureFlagPage() {
|
||||
assertThat(mDashboard.getMetricsCategory())
|
||||
.isEqualTo(MetricsProto.MetricsEvent.DEVELOPMENT);
|
||||
.isEqualTo(MetricsProto.MetricsEvent.DEVELOPMENT);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -184,7 +183,7 @@ public class DevelopmentSettingsDashboardFragmentTest {
|
||||
public void onOemUnlockDialogConfirmed_shouldCallControllerOemConfirmed() {
|
||||
final OemUnlockPreferenceController controller = mock(OemUnlockPreferenceController.class);
|
||||
doReturn(controller).when(mDashboard)
|
||||
.getDevelopmentOptionsController(OemUnlockPreferenceController.class);
|
||||
.getDevelopmentOptionsController(OemUnlockPreferenceController.class);
|
||||
mDashboard.onOemUnlockDialogConfirmed();
|
||||
verify(controller).onOemUnlockConfirmed();
|
||||
}
|
||||
@@ -193,7 +192,7 @@ public class DevelopmentSettingsDashboardFragmentTest {
|
||||
public void onOemUnlockDialogConfirmed_shouldCallControllerOemDismissed() {
|
||||
final OemUnlockPreferenceController controller = mock(OemUnlockPreferenceController.class);
|
||||
doReturn(controller).when(mDashboard)
|
||||
.getDevelopmentOptionsController(OemUnlockPreferenceController.class);
|
||||
.getDevelopmentOptionsController(OemUnlockPreferenceController.class);
|
||||
mDashboard.onOemUnlockDialogDismissed();
|
||||
verify(controller).onOemUnlockDismissed();
|
||||
}
|
||||
@@ -202,7 +201,7 @@ public class DevelopmentSettingsDashboardFragmentTest {
|
||||
public void onAdbDialogConfirmed_shouldCallControllerDialogConfirmed() {
|
||||
final AdbPreferenceController controller = mock(AdbPreferenceController.class);
|
||||
doReturn(controller).when(mDashboard)
|
||||
.getDevelopmentOptionsController(AdbPreferenceController.class);
|
||||
.getDevelopmentOptionsController(AdbPreferenceController.class);
|
||||
mDashboard.onEnableAdbDialogConfirmed();
|
||||
|
||||
verify(controller).onAdbDialogConfirmed();
|
||||
@@ -212,7 +211,7 @@ public class DevelopmentSettingsDashboardFragmentTest {
|
||||
public void onAdbDialogDismissed_shouldCallControllerOemDismissed() {
|
||||
final AdbPreferenceController controller = mock(AdbPreferenceController.class);
|
||||
doReturn(controller).when(mDashboard)
|
||||
.getDevelopmentOptionsController(AdbPreferenceController.class);
|
||||
.getDevelopmentOptionsController(AdbPreferenceController.class);
|
||||
mDashboard.onEnableAdbDialogDismissed();
|
||||
|
||||
verify(controller).onAdbDialogDismissed();
|
||||
@@ -221,9 +220,9 @@ public class DevelopmentSettingsDashboardFragmentTest {
|
||||
@Test
|
||||
public void onAdbClearKeysDialogConfirmed_shouldCallControllerDialogConfirmed() {
|
||||
final ClearAdbKeysPreferenceController controller =
|
||||
mock(ClearAdbKeysPreferenceController.class);
|
||||
mock(ClearAdbKeysPreferenceController.class);
|
||||
doReturn(controller).when(mDashboard)
|
||||
.getDevelopmentOptionsController(ClearAdbKeysPreferenceController.class);
|
||||
.getDevelopmentOptionsController(ClearAdbKeysPreferenceController.class);
|
||||
mDashboard.onAdbClearKeysDialogConfirmed();
|
||||
|
||||
verify(controller).onClearAdbKeysConfirmed();
|
||||
@@ -232,9 +231,9 @@ public class DevelopmentSettingsDashboardFragmentTest {
|
||||
@Test
|
||||
public void onDisableLogPersistDialogConfirmed_shouldCallControllerDialogConfirmed() {
|
||||
final LogPersistPreferenceController controller =
|
||||
mock(LogPersistPreferenceController.class);
|
||||
mock(LogPersistPreferenceController.class);
|
||||
doReturn(controller).when(mDashboard)
|
||||
.getDevelopmentOptionsController(LogPersistPreferenceController.class);
|
||||
.getDevelopmentOptionsController(LogPersistPreferenceController.class);
|
||||
mDashboard.onDisableLogPersistDialogConfirmed();
|
||||
|
||||
verify(controller).onDisableLogPersistDialogConfirmed();
|
||||
@@ -243,9 +242,9 @@ public class DevelopmentSettingsDashboardFragmentTest {
|
||||
@Test
|
||||
public void onDisableLogPersistDialogRejected_shouldCallControllerDialogRejected() {
|
||||
final LogPersistPreferenceController controller =
|
||||
mock(LogPersistPreferenceController.class);
|
||||
mock(LogPersistPreferenceController.class);
|
||||
doReturn(controller).when(mDashboard)
|
||||
.getDevelopmentOptionsController(LogPersistPreferenceController.class);
|
||||
.getDevelopmentOptionsController(LogPersistPreferenceController.class);
|
||||
mDashboard.onDisableLogPersistDialogRejected();
|
||||
|
||||
verify(controller).onDisableLogPersistDialogRejected();
|
||||
|
@@ -24,11 +24,11 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.UserManager;
|
||||
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.ShadowUserManager;
|
||||
import com.android.settings.testutils.shadow.ShadowUtils;
|
||||
import com.android.settings.widget.SwitchBar;
|
||||
import com.android.settings.widget.SwitchBar.OnSwitchChangeListener;
|
||||
@@ -41,14 +41,13 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.Shadows;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(shadows = ShadowUtils.class)
|
||||
@Config(shadows = {ShadowUtils.class, ShadowUserManager.class})
|
||||
public class DevelopmentSwitchBarControllerTest {
|
||||
|
||||
@Mock
|
||||
@@ -61,8 +60,7 @@ public class DevelopmentSwitchBarControllerTest {
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
final Context context = RuntimeEnvironment.application;
|
||||
UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
|
||||
Shadows.shadowOf(userManager).setIsAdminUser(true);
|
||||
ShadowUserManager.getShadow().setIsAdminUser(true);
|
||||
mLifecycleOwner = () -> mLifecycle;
|
||||
mLifecycle = new Lifecycle(mLifecycleOwner);
|
||||
mSwitchBar = new SwitchBar(context);
|
||||
@@ -72,6 +70,7 @@ public class DevelopmentSwitchBarControllerTest {
|
||||
@After
|
||||
public void tearDown() {
|
||||
ShadowUtils.reset();
|
||||
ShadowUserManager.getShadow().reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -61,7 +61,7 @@ public class DisableAutomaticUpdatesPreferenceControllerTest {
|
||||
public void onPreferenceChanged_turnOnAutomaticUpdates() {
|
||||
mController.onPreferenceChange(null, true);
|
||||
|
||||
final int mode = Settings.System.getInt(mContext.getContentResolver(),
|
||||
final int mode = Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.OTA_DISABLE_AUTOMATIC_UPDATE, -1);
|
||||
|
||||
assertThat(mode).isEqualTo(
|
||||
@@ -72,7 +72,7 @@ public class DisableAutomaticUpdatesPreferenceControllerTest {
|
||||
public void onPreferenceChanged_turnOffAutomaticUpdates() {
|
||||
mController.onPreferenceChange(null, false);
|
||||
|
||||
final int mode = Settings.System.getInt(mContext.getContentResolver(),
|
||||
final int mode = Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.OTA_DISABLE_AUTOMATIC_UPDATE, -1);
|
||||
|
||||
assertThat(mode).isEqualTo(
|
||||
@@ -81,7 +81,7 @@ public class DisableAutomaticUpdatesPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void updateState_preferenceShouldBeChecked() {
|
||||
Settings.System
|
||||
Settings.Global
|
||||
.putInt(mContext.getContentResolver(), Settings.Global.OTA_DISABLE_AUTOMATIC_UPDATE,
|
||||
DisableAutomaticUpdatesPreferenceController.ENABLE_UPDATES_SETTING);
|
||||
mController.updateState(mPreference);
|
||||
@@ -91,7 +91,7 @@ public class DisableAutomaticUpdatesPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void updateState_preferenceShouldNotBeChecked() {
|
||||
Settings.System
|
||||
Settings.Global
|
||||
.putInt(mContext.getContentResolver(), Settings.Global.OTA_DISABLE_AUTOMATIC_UPDATE,
|
||||
DisableAutomaticUpdatesPreferenceController.DISABLE_UPDATES_SETTING);
|
||||
mController.updateState(mPreference);
|
||||
|
@@ -84,7 +84,7 @@ public class KeepActivitiesPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void updateState_settingEnabled_preferenceShouldBeChecked() {
|
||||
Settings.System.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.ALWAYS_FINISH_ACTIVITIES, SETTING_VALUE_ON);
|
||||
mController.updateState(mPreference);
|
||||
|
||||
@@ -93,7 +93,7 @@ public class KeepActivitiesPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void updateState_settingDisabled_preferenceShouldNotBeChecked() {
|
||||
Settings.System.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.ALWAYS_FINISH_ACTIVITIES, SETTING_VALUE_OFF);
|
||||
mController.updateState(mPreference);
|
||||
|
||||
|
@@ -61,7 +61,7 @@ public class MobileDataAlwaysOnPreferenceControllerTest {
|
||||
public void onPreferenceChanged_turnOnPreference_shouldEnableMobileDataAlwaysOn() {
|
||||
mController.onPreferenceChange(mPreference, true /* new value */);
|
||||
|
||||
final int mode = Settings.System.getInt(mContext.getContentResolver(),
|
||||
final int mode = Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.MOBILE_DATA_ALWAYS_ON, -1 /* default */);
|
||||
|
||||
assertThat(mode).isEqualTo(MobileDataAlwaysOnPreferenceController.SETTING_VALUE_ON);
|
||||
@@ -71,7 +71,7 @@ public class MobileDataAlwaysOnPreferenceControllerTest {
|
||||
public void onPreferenceChanged_turnOffPreference_shouldDisableMobileDataAlwaysOn() {
|
||||
mController.onPreferenceChange(mPreference, false /* new value */);
|
||||
|
||||
final int mode = Settings.System.getInt(mContext.getContentResolver(),
|
||||
final int mode = Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.MOBILE_DATA_ALWAYS_ON, -1 /* default */);
|
||||
|
||||
assertThat(mode).isEqualTo(MobileDataAlwaysOnPreferenceController.SETTING_VALUE_OFF);
|
||||
@@ -79,7 +79,7 @@ public class MobileDataAlwaysOnPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void updateState_settingEnabled_preferenceShouldBeChecked() {
|
||||
Settings.System.putInt(mContext.getContentResolver(), Settings.Global.MOBILE_DATA_ALWAYS_ON,
|
||||
Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.MOBILE_DATA_ALWAYS_ON,
|
||||
MobileDataAlwaysOnPreferenceController.SETTING_VALUE_ON);
|
||||
mController.updateState(mPreference);
|
||||
|
||||
@@ -88,7 +88,7 @@ public class MobileDataAlwaysOnPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void updateState_settingDisabled_preferenceShouldNotBeChecked() {
|
||||
Settings.System.putInt(mContext.getContentResolver(), Settings.Global.MOBILE_DATA_ALWAYS_ON,
|
||||
Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.MOBILE_DATA_ALWAYS_ON,
|
||||
MobileDataAlwaysOnPreferenceController.SETTING_VALUE_OFF);
|
||||
mController.updateState(mPreference);
|
||||
|
||||
@@ -98,7 +98,7 @@ public class MobileDataAlwaysOnPreferenceControllerTest {
|
||||
@Test
|
||||
public void onDeveloperOptionsSwitchDisabled_preferenceShouldBeDisabled() {
|
||||
mController.onDeveloperOptionsSwitchDisabled();
|
||||
final int mode = Settings.System.getInt(mContext.getContentResolver(),
|
||||
final int mode = Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.MOBILE_DATA_ALWAYS_ON, -1 /* default */);
|
||||
|
||||
assertThat(mode).isEqualTo(MobileDataAlwaysOnPreferenceController.SETTING_VALUE_OFF);
|
||||
|
@@ -72,7 +72,7 @@ public class StayAwakePreferenceControllerTest {
|
||||
public void onPreferenceChanged_turnOnStayAwake() {
|
||||
mController.onPreferenceChange(null, true);
|
||||
|
||||
final int mode = Settings.System.getInt(mContentResolver,
|
||||
final int mode = Settings.Global.getInt(mContentResolver,
|
||||
Settings.Global.STAY_ON_WHILE_PLUGGED_IN, -1);
|
||||
|
||||
assertThat(mode).isEqualTo(StayAwakePreferenceController.SETTING_VALUE_ON);
|
||||
@@ -82,7 +82,7 @@ public class StayAwakePreferenceControllerTest {
|
||||
public void onPreferenceChanged_turnOffStayAwake() {
|
||||
mController.onPreferenceChange(null, false);
|
||||
|
||||
final int mode = Settings.System.getInt(mContentResolver,
|
||||
final int mode = Settings.Global.getInt(mContentResolver,
|
||||
Settings.Global.STAY_ON_WHILE_PLUGGED_IN, -1);
|
||||
|
||||
assertThat(mode).isEqualTo(StayAwakePreferenceController.SETTING_VALUE_OFF);
|
||||
@@ -90,7 +90,7 @@ public class StayAwakePreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void updateState_preferenceShouldBeChecked() {
|
||||
Settings.System.putInt(mContentResolver, Settings.Global.STAY_ON_WHILE_PLUGGED_IN,
|
||||
Settings.Global.putInt(mContentResolver, Settings.Global.STAY_ON_WHILE_PLUGGED_IN,
|
||||
StayAwakePreferenceController.SETTING_VALUE_ON);
|
||||
mController.updateState(mPreference);
|
||||
|
||||
@@ -99,7 +99,7 @@ public class StayAwakePreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void updateState_preferenceShouldNotBeChecked() {
|
||||
Settings.System.putInt(mContentResolver, Settings.Global.STAY_ON_WHILE_PLUGGED_IN,
|
||||
Settings.Global.putInt(mContentResolver, Settings.Global.STAY_ON_WHILE_PLUGGED_IN,
|
||||
StayAwakePreferenceController.SETTING_VALUE_OFF);
|
||||
mController.updateState(mPreference);
|
||||
|
||||
@@ -119,7 +119,7 @@ public class StayAwakePreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void observerOnChangeCalledWithSameUri_preferenceShouldBeUpdated() {
|
||||
Settings.System.putInt(mContentResolver, Settings.Global.STAY_ON_WHILE_PLUGGED_IN,
|
||||
Settings.Global.putInt(mContentResolver, Settings.Global.STAY_ON_WHILE_PLUGGED_IN,
|
||||
StayAwakePreferenceController.SETTING_VALUE_ON);
|
||||
mController.onResume();
|
||||
mController.mSettingsObserver.onChange(false,
|
||||
@@ -130,7 +130,7 @@ public class StayAwakePreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void observerOnChangeCalledWithDifferentUri_preferenceShouldNotBeUpdated() {
|
||||
Settings.System.putInt(mContentResolver, Settings.Global.STAY_ON_WHILE_PLUGGED_IN,
|
||||
Settings.Global.putInt(mContentResolver, Settings.Global.STAY_ON_WHILE_PLUGGED_IN,
|
||||
StayAwakePreferenceController.SETTING_VALUE_ON);
|
||||
mController.onResume();
|
||||
mController.mSettingsObserver.onChange(false, null);
|
||||
|
@@ -61,7 +61,7 @@ public class TetheringHardwareAccelPreferenceControllerTest {
|
||||
public void onPreferenceChanged_settingEnabled_turnOnTetheringAccel() {
|
||||
mController.onPreferenceChange(mPreference, true /* new value */);
|
||||
|
||||
final int mode = Settings.System.getInt(mContext.getContentResolver(),
|
||||
final int mode = Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.TETHER_OFFLOAD_DISABLED, -1 /* default */);
|
||||
|
||||
assertThat(mode).isEqualTo(TetheringHardwareAccelPreferenceController.SETTING_VALUE_ON);
|
||||
@@ -71,7 +71,7 @@ public class TetheringHardwareAccelPreferenceControllerTest {
|
||||
public void onPreferenceChanged_settingDisabled_turnOffTetheringAccel() {
|
||||
mController.onPreferenceChange(mPreference, false /* new value */);
|
||||
|
||||
final int mode = Settings.System.getInt(mContext.getContentResolver(),
|
||||
final int mode = Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.TETHER_OFFLOAD_DISABLED, -1 /* default */);
|
||||
|
||||
assertThat(mode).isEqualTo(TetheringHardwareAccelPreferenceController.SETTING_VALUE_OFF);
|
||||
@@ -79,7 +79,7 @@ public class TetheringHardwareAccelPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void updateState_settingEnabled_preferenceShouldBeChecked() {
|
||||
Settings.System.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.TETHER_OFFLOAD_DISABLED,
|
||||
TetheringHardwareAccelPreferenceController.SETTING_VALUE_ON);
|
||||
mController.updateState(mPreference);
|
||||
@@ -89,7 +89,7 @@ public class TetheringHardwareAccelPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void updateState_settingDisabled_preferenceShouldNotBeChecked() {
|
||||
Settings.System.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.TETHER_OFFLOAD_DISABLED,
|
||||
TetheringHardwareAccelPreferenceController.SETTING_VALUE_OFF);
|
||||
mController.updateState(mPreference);
|
||||
@@ -100,7 +100,7 @@ public class TetheringHardwareAccelPreferenceControllerTest {
|
||||
@Test
|
||||
public void onDeveloperOptionsSwitchDisabled_shouldDisablePreference() {
|
||||
mController.onDeveloperOptionsSwitchDisabled();
|
||||
final int mode = Settings.System.getInt(mContext.getContentResolver(),
|
||||
final int mode = Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.TETHER_OFFLOAD_DISABLED, -1 /* default */);
|
||||
|
||||
assertThat(mode).isEqualTo(TetheringHardwareAccelPreferenceController.SETTING_VALUE_OFF);
|
||||
|
@@ -61,7 +61,7 @@ public class WifiDisplayCertificationPreferenceControllerTest {
|
||||
public void onPreferenceChanged_turnOnWifiDisplayCertification() {
|
||||
mController.onPreferenceChange(mPreference, true /* new value */);
|
||||
|
||||
final int mode = Settings.System.getInt(mContext.getContentResolver(),
|
||||
final int mode = Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.WIFI_DISPLAY_CERTIFICATION_ON, -1 /* default */);
|
||||
|
||||
assertThat(mode).isEqualTo(WifiDisplayCertificationPreferenceController.SETTING_VALUE_ON);
|
||||
@@ -71,7 +71,7 @@ public class WifiDisplayCertificationPreferenceControllerTest {
|
||||
public void onPreferenceChanged_turnOffWifiDisplayCertification() {
|
||||
mController.onPreferenceChange(mPreference, false /* new value */);
|
||||
|
||||
final int mode = Settings.System.getInt(mContext.getContentResolver(),
|
||||
final int mode = Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.WIFI_DISPLAY_CERTIFICATION_ON, -1 /* default */);
|
||||
|
||||
assertThat(mode).isEqualTo(WifiDisplayCertificationPreferenceController.SETTING_VALUE_OFF);
|
||||
@@ -79,7 +79,7 @@ public class WifiDisplayCertificationPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void updateState_preferenceShouldBeChecked() {
|
||||
Settings.System.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.WIFI_DISPLAY_CERTIFICATION_ON,
|
||||
WifiDisplayCertificationPreferenceController.SETTING_VALUE_ON);
|
||||
mController.updateState(mPreference);
|
||||
@@ -89,7 +89,7 @@ public class WifiDisplayCertificationPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void updateState_preferenceShouldNotBeChecked() {
|
||||
Settings.System.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.WIFI_DISPLAY_CERTIFICATION_ON,
|
||||
WifiDisplayCertificationPreferenceController.SETTING_VALUE_OFF);
|
||||
mController.updateState(mPreference);
|
||||
@@ -100,7 +100,7 @@ public class WifiDisplayCertificationPreferenceControllerTest {
|
||||
@Test
|
||||
public void onDeveloperOptionsDisabled_shouldDisablePreference() {
|
||||
mController.onDeveloperOptionsDisabled();
|
||||
final int mode = Settings.System.getInt(mContext.getContentResolver(),
|
||||
final int mode = Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.WIFI_DISPLAY_CERTIFICATION_ON, -1 /* default */);
|
||||
|
||||
assertThat(mode).isEqualTo(WifiDisplayCertificationPreferenceController.SETTING_VALUE_OFF);
|
||||
|
@@ -24,6 +24,7 @@ import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.UserManager;
|
||||
import android.service.quicksettings.Tile;
|
||||
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
@@ -35,6 +36,9 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.Shadows;
|
||||
import org.robolectric.shadows.ShadowUserManager;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class DevelopmentTilesTest {
|
||||
@@ -50,6 +54,9 @@ public class DevelopmentTilesTest {
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mService = spy(Robolectric.setupService(DevelopmentTiles.ShowLayout.class));
|
||||
final ShadowUserManager um = Shadows.shadowOf(
|
||||
RuntimeEnvironment.application.getSystemService(UserManager.class));
|
||||
um.setIsAdminUser(true);
|
||||
doReturn(mTile).when(mService).getQsTile();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user