Delete DevelopmentSettings.java

- Remove the old DevelopmentSettings
 - Remove references to the feature flag

Fixes: 65522949
Test: make RunSettingsRoboTests -j40
Change-Id: Ie2eb3465127d79a027de6bb58a47bb15e3094f89
This commit is contained in:
jeffreyhuang
2017-11-17 11:19:44 -08:00
parent 1eaf52aad4
commit cb823d5983
27 changed files with 27 additions and 4683 deletions

View File

@@ -1,192 +0,0 @@
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.development;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Answers.RETURNS_DEEP_STUBS;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.UserManager;
import android.provider.Settings;
import android.support.v14.preference.SwitchPreference;
import android.support.v7.preference.PreferenceScreen;
import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;
/**
* deprecated in favor of {@link BugReportInPowerPreferenceControllerV2}
*/
@Deprecated
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class BugReportInPowerPreferenceControllerTest {
@Mock(answer = RETURNS_DEEP_STUBS)
private PreferenceScreen mScreen;
@Mock
private UserManager mUserManager;
@Mock
private PackageManager mPackageManager;
private Context mContext;
private SwitchPreference mPreference;
private BugReportInPowerPreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
ShadowApplication shadowContext = ShadowApplication.getInstance();
shadowContext.setSystemService(Context.USER_SERVICE, mUserManager);
mContext = spy(shadowContext.getApplicationContext());
when(mContext.getPackageManager()).thenReturn(mPackageManager);
mPreference = new SwitchPreference(mContext);
when(mScreen.findPreference(anyString())).thenReturn(mPreference);
mController = new BugReportInPowerPreferenceController(mContext);
mPreference.setKey(mController.getPreferenceKey());
}
@Test
public void displayPreference_hasDebugRestriction_shouldRemovePreference() {
when(mUserManager.hasUserRestriction(anyString())).thenReturn(true);
mController.displayPreference(mScreen);
assertThat(mPreference.isVisible()).isFalse();
}
@Test
public void displayPreference_noDebugRestriction_shouldNotRemovePreference() {
when(mUserManager.hasUserRestriction(anyString())).thenReturn(false);
mController.displayPreference(mScreen);
assertThat(mPreference.isVisible()).isTrue();
}
@Test
public void enablePreference_hasDebugRestriction_shouldNotEnable() {
when(mUserManager.hasUserRestriction(anyString())).thenReturn(true);
mController.displayPreference(mScreen);
mPreference.setEnabled(false);
mController.enablePreference(true);
assertThat(mPreference.isEnabled()).isFalse();
}
@Test
public void enablePreference_noDebugRestriction_shouldEnable() {
when(mUserManager.hasUserRestriction(anyString())).thenReturn(false);
mController.displayPreference(mScreen);
mPreference.setEnabled(false);
mController.enablePreference(true);
assertThat(mPreference.isEnabled()).isTrue();
}
@Test
public void resetPreference_shouldUncheck() {
when(mUserManager.hasUserRestriction(anyString())).thenReturn(false);
mController.displayPreference(mScreen);
mPreference.setChecked(true);
mController.resetPreference();
assertThat(mPreference.isChecked()).isFalse();
}
@Test
public void handlePreferenceTreeClick_shouldUpdateSettings() {
when(mUserManager.hasUserRestriction(anyString())).thenReturn(false);
Settings.Secure.putInt(mContext.getContentResolver(),
Settings.Global.BUGREPORT_IN_POWER_MENU, 0);
mPreference.setChecked(true);
mController.displayPreference(mScreen);
mController.handlePreferenceTreeClick(mPreference);
assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Global.BUGREPORT_IN_POWER_MENU, 0)).isEqualTo(1);
}
@Test
public void updateState_settingsOn_shouldCheck() {
when(mUserManager.hasUserRestriction(anyString())).thenReturn(false);
Settings.Secure.putInt(mContext.getContentResolver(),
Settings.Global.BUGREPORT_IN_POWER_MENU, 1);
mPreference.setChecked(false);
mController.displayPreference(mScreen);
mController.updateState(mPreference);
assertThat(mPreference.isChecked()).isTrue();
}
@Test
public void updateState_settingsOff_shouldUncheck() {
when(mUserManager.hasUserRestriction(anyString())).thenReturn(false);
Settings.Secure.putInt(mContext.getContentResolver(),
Settings.Global.BUGREPORT_IN_POWER_MENU, 0);
mPreference.setChecked(true);
mController.displayPreference(mScreen);
mController.updateState(mPreference);
assertThat(mPreference.isChecked()).isFalse();
}
@Test
public void updateBugreportOptions_shouldEnable() {
when(mUserManager.hasUserRestriction(anyString())).thenReturn(false);
mPreference.setEnabled(false);
mController.displayPreference(mScreen);
mController.updateBugreportOptions();
assertThat(mPreference.isEnabled()).isTrue();
}
@Test
public void updateBugreportOptions_shouldEnableBugReportStorage() {
final ComponentName componentName = new ComponentName("com.android.shell",
"com.android.shell.BugreportStorageProvider");
when(mUserManager.hasUserRestriction(anyString())).thenReturn(false);
mController.displayPreference(mScreen);
mController.updateBugreportOptions();
verify(mPackageManager).setComponentEnabledSetting(eq(componentName), anyInt(), anyInt());
}
}

View File

@@ -1,108 +0,0 @@
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.development;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Answers.RETURNS_DEEP_STUBS;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.os.UserManager;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import org.junit.Before;
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;
/**
* deprecated in favor of {@link BugReportPreferenceControllerV2}
*/
@Deprecated
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class BugReportPreferenceControllerTest {
@Mock
private Context mContext;
@Mock(answer = RETURNS_DEEP_STUBS)
private PreferenceScreen mScreen;
@Mock
private UserManager mUserManager;
private BugReportPreferenceController mController;
private Preference mPreference;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
mController = new BugReportPreferenceController(mContext);
mPreference = new Preference(RuntimeEnvironment.application);
mPreference.setKey(mController.getPreferenceKey());
when(mScreen.findPreference(mPreference.getKey())).thenReturn(mPreference);
}
@Test
public void displayPreference_hasDebugRestriction_shouldRemovePreference() {
when(mUserManager.hasUserRestriction(anyString())).thenReturn(true);
mController.displayPreference(mScreen);
assertThat(mPreference.isVisible()).isFalse();
}
@Test
public void displayPreference_noDebugRestriction_shouldNotRemovePreference() {
when(mUserManager.hasUserRestriction(anyString())).thenReturn(false);
mController.displayPreference(mScreen);
assertThat(mPreference.isVisible()).isTrue();
}
@Test
public void enablePreference_hasDebugRestriction_shouldNotEnable() {
when(mUserManager.hasUserRestriction(anyString())).thenReturn(true);
mController.displayPreference(mScreen);
mPreference.setEnabled(false);
mController.enablePreference(true);
assertThat(mPreference.isEnabled()).isFalse();
}
@Test
public void enablePreference_noDebugRestriction_shouldEnable() {
when(mUserManager.hasUserRestriction(anyString())).thenReturn(false);
mController.displayPreference(mScreen);
mPreference.setEnabled(false);
mController.enablePreference(true);
assertThat(mPreference.isEnabled()).isTrue();
}
}

View File

@@ -1,178 +0,0 @@
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.development;
import android.content.Context;
import android.os.SystemProperties;
import android.support.v14.preference.SwitchPreference;
import android.support.v7.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import com.android.settings.testutils.shadow.SettingsShadowSystemProperties;
import org.junit.After;
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 static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
/**
* deprecated in favour of {@link CameraLaserSensorPreferenceControllerV2}
*/
@Deprecated
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
shadows = {SettingsShadowSystemProperties.class})
public class CameraLaserSensorPreferenceControllerTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private Context mContext;
@Mock
private PreferenceScreen mScreen;
@Mock
private SwitchPreference mPreference;
static final String USERDEBUG_BUILD = "userdebug";
static final String ENG_BUILD = "eng";
static final String USER_BUILD = "user";
private CameraLaserSensorPreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mController = new CameraLaserSensorPreferenceController(mContext);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
when(mPreference.getKey()).thenReturn(mController.getPreferenceKey());
}
@After
public void tearDown() {
SettingsShadowSystemProperties.clear();
}
@Test
public void isAvailable_withConfigNoShow_shouldReturnFalse() {
when(mContext.getResources().getBoolean(R.bool.config_show_camera_laser_sensor))
.thenReturn(false);
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void isAvailable_withUserdebugBuild_shouldReturnTrue() {
when(mContext.getResources().getBoolean(R.bool.config_show_camera_laser_sensor))
.thenReturn(true);
SettingsShadowSystemProperties.set(
CameraLaserSensorPreferenceController.BUILD_TYPE, USERDEBUG_BUILD);
assertThat(mController.isAvailable()).isTrue();
}
@Test
public void isAvailable_withEngBuild_shouldReturnTrue() {
when(mContext.getResources().getBoolean(R.bool.config_show_camera_laser_sensor))
.thenReturn(true);
SettingsShadowSystemProperties.set(
CameraLaserSensorPreferenceController.BUILD_TYPE, ENG_BUILD);
assertThat(mController.isAvailable()).isTrue();
}
@Test
public void isAvailable_withUserBuild_shouldReturnFalse() {
when(mContext.getResources().getBoolean(R.bool.config_show_camera_laser_sensor))
.thenReturn(true);
SettingsShadowSystemProperties.set(
CameraLaserSensorPreferenceController.BUILD_TYPE, USER_BUILD);
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void displayPreference_cameraLaserSensorEnabled_shouldCheckedPreference() {
when(mContext.getResources().getBoolean(R.bool.config_show_camera_laser_sensor))
.thenReturn(true);
SettingsShadowSystemProperties.set(
CameraLaserSensorPreferenceController.PROPERTY_CAMERA_LASER_SENSOR,
Integer.toString(CameraLaserSensorPreferenceController.ENABLED));
SettingsShadowSystemProperties.set(
CameraLaserSensorPreferenceController.BUILD_TYPE, USERDEBUG_BUILD);
mController.displayPreference(mScreen);
verify(mPreference).setChecked(true);
}
@Test
public void displayPreference_cameraLaserSensorEnabled_shouldUncheckedPreference() {
when(mContext.getResources().getBoolean(R.bool.config_show_camera_laser_sensor))
.thenReturn(true);
SettingsShadowSystemProperties.set(
CameraLaserSensorPreferenceController.PROPERTY_CAMERA_LASER_SENSOR,
Integer.toString(CameraLaserSensorPreferenceController.DISABLED));
SettingsShadowSystemProperties.set(
CameraLaserSensorPreferenceController.BUILD_TYPE, USERDEBUG_BUILD);
mController.displayPreference(mScreen);
verify(mPreference).setChecked(false);
}
@Test
public void handlePreferenceTreeClick_preferenceChecked_shouldEnableCameraLaserSensor() {
when(mContext.getResources().getBoolean(R.bool.config_show_camera_laser_sensor))
.thenReturn(true);
when(mPreference.isChecked()).thenReturn(true);
mController.handlePreferenceTreeClick(mPreference);
assertThat(Integer.toString(CameraLaserSensorPreferenceController.ENABLED).equals(
SystemProperties.get(
CameraLaserSensorPreferenceController.PROPERTY_CAMERA_LASER_SENSOR,
Integer.toString(CameraLaserSensorPreferenceController.ENABLED)))).isTrue();
}
@Test
public void handlePreferenceTreeClick_preferenceUnchecked_shouldDisableCameraLaserSensor() {
when(mContext.getResources().getBoolean(R.bool.config_show_camera_laser_sensor))
.thenReturn(true);
when(mPreference.isChecked()).thenReturn(false);
mController.handlePreferenceTreeClick(mPreference);
assertThat(Integer.toString(CameraLaserSensorPreferenceController.DISABLED).equals(
SystemProperties.get(
CameraLaserSensorPreferenceController.PROPERTY_CAMERA_LASER_SENSOR,
Integer.toString(CameraLaserSensorPreferenceController.ENABLED)))).isTrue();
}
}

View File

@@ -1,229 +0,0 @@
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.development;
import android.content.Context;
import android.os.SystemProperties;
import android.support.v14.preference.SwitchPreference;
import android.support.v7.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import com.android.settings.testutils.shadow.SettingsShadowSystemProperties;
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 static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
/**
* deprecated in favor of {@link ConnectivityMonitorPreferenceControllerV2}
*/
@Deprecated
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class ConnectivityMonitorPreferenceControllerTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private Context mContext;
@Mock
private PreferenceScreen mScreen;
@Mock
private SwitchPreference mPreference;
private ConnectivityMonitorPreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
SettingsShadowSystemProperties.clear();
mController = new ConnectivityMonitorPreferenceController(mContext);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
when(mPreference.getKey()).thenReturn(mController.getPreferenceKey());
}
@Config(shadows = {SettingsShadowSystemProperties.class})
@Test
public void isAvailable_trueShowFlagWithUserdebugBuild_shouldReturnTrue() {
when(mContext.getResources().getBoolean(R.bool.config_show_connectivity_monitor))
.thenReturn(true);
SettingsShadowSystemProperties.set(
ConnectivityMonitorPreferenceController.BUILD_TYPE, "userdebug");
assertThat(mController.isAvailable()).isTrue();
}
@Config(shadows = {SettingsShadowSystemProperties.class})
@Test
public void isAvailable_trueShowFlagWithEngBuild_shouldReturnTrue() {
when(mContext.getResources().getBoolean(R.bool.config_show_connectivity_monitor))
.thenReturn(true);
SettingsShadowSystemProperties.set(
ConnectivityMonitorPreferenceController.BUILD_TYPE, "eng");
assertThat(mController.isAvailable()).isTrue();
}
@Config(shadows = {SettingsShadowSystemProperties.class})
@Test
public void isAvailable_trueShowFlagWithUserBuild_shouldReturnFalse() {
when(mContext.getResources().getBoolean(R.bool.config_show_connectivity_monitor))
.thenReturn(true);
SettingsShadowSystemProperties.set(
ConnectivityMonitorPreferenceController.BUILD_TYPE, "user");
assertThat(mController.isAvailable()).isFalse();
}
@Config(shadows = {SettingsShadowSystemProperties.class})
@Test
public void isAvailable_falseShowFlagWithUserdebugBuild_shouldReturnFalse() {
when(mContext.getResources().getBoolean(R.bool.config_show_connectivity_monitor))
.thenReturn(false);
SettingsShadowSystemProperties.set(
ConnectivityMonitorPreferenceController.BUILD_TYPE, "userdebug");
assertThat(mController.isAvailable()).isFalse();
}
@Config(shadows = {SettingsShadowSystemProperties.class})
@Test
public void isAvailable_falseShowFlagWithEngBuild_shouldReturnFalse() {
when(mContext.getResources().getBoolean(R.bool.config_show_connectivity_monitor))
.thenReturn(false);
SettingsShadowSystemProperties.set(
ConnectivityMonitorPreferenceController.BUILD_TYPE, "eng");
assertThat(mController.isAvailable()).isFalse();
}
@Config(shadows = {SettingsShadowSystemProperties.class})
@Test
public void isAvailable_falseShowFlagWithUserBuild_shouldReturnFalse() {
when(mContext.getResources().getBoolean(R.bool.config_show_connectivity_monitor))
.thenReturn(false);
SettingsShadowSystemProperties.set(
ConnectivityMonitorPreferenceController.BUILD_TYPE, "user");
assertThat(mController.isAvailable()).isFalse();
}
@Config(shadows = {SettingsShadowSystemProperties.class})
@Test
public void displayPreference_connectivityMonitorEnabled_shouldCheckedPreference() {
when(mContext.getResources().getBoolean(R.bool.config_show_connectivity_monitor))
.thenReturn(true);
SettingsShadowSystemProperties.set(
ConnectivityMonitorPreferenceController.PROPERTY_CONNECTIVITY_MONITOR,
ConnectivityMonitorPreferenceController.ENABLED_STATUS);
SettingsShadowSystemProperties.set(
ConnectivityMonitorPreferenceController.BUILD_TYPE, "userdebug");
mController.displayPreference(mScreen);
verify(mPreference).setChecked(true);
}
@Config(shadows = {SettingsShadowSystemProperties.class})
@Test
public void displayPreference_connectivityMonitorUserEnabled_shouldCheckedPreference() {
when(mContext.getResources().getBoolean(R.bool.config_show_connectivity_monitor))
.thenReturn(true);
SettingsShadowSystemProperties.set(
ConnectivityMonitorPreferenceController.PROPERTY_CONNECTIVITY_MONITOR,
ConnectivityMonitorPreferenceController.USER_ENABLED_STATUS);
SettingsShadowSystemProperties.set(
ConnectivityMonitorPreferenceController.BUILD_TYPE, "userdebug");
mController.displayPreference(mScreen);
verify(mPreference).setChecked(true);
}
@Config(shadows = {SettingsShadowSystemProperties.class})
@Test
public void displayPreference_connectivityMonitorDisabled_shouldUncheckedPreference() {
when(mContext.getResources().getBoolean(R.bool.config_show_connectivity_monitor))
.thenReturn(true);
SettingsShadowSystemProperties.set(
ConnectivityMonitorPreferenceController.PROPERTY_CONNECTIVITY_MONITOR,
ConnectivityMonitorPreferenceController.DISABLED_STATUS);
SettingsShadowSystemProperties.set(
ConnectivityMonitorPreferenceController.BUILD_TYPE, "userdebug");
mController.displayPreference(mScreen);
verify(mPreference).setChecked(false);
}
@Config(shadows = {SettingsShadowSystemProperties.class})
@Test
public void displayPreference_connectivityMonitorUserDisabled_shouldUncheckedPreference() {
when(mContext.getResources().getBoolean(R.bool.config_show_connectivity_monitor))
.thenReturn(true);
SettingsShadowSystemProperties.set(
ConnectivityMonitorPreferenceController.PROPERTY_CONNECTIVITY_MONITOR,
ConnectivityMonitorPreferenceController.USER_DISABLED_STATUS);
SettingsShadowSystemProperties.set(
ConnectivityMonitorPreferenceController.BUILD_TYPE, "userdebug");
mController.displayPreference(mScreen);
verify(mPreference).setChecked(false);
}
@Config(shadows = {SettingsShadowSystemProperties.class})
@Test
public void handlePreferenceTreeClick_preferenceChecked_shouldEnableConnectivityMonitor() {
when(mPreference.isChecked()).thenReturn(true);
when(mContext.getResources().getString(R.string.connectivity_monitor_toast))
.thenReturn("To apply connectivity monitor change, reboot device");
mController.handlePreferenceTreeClick(mPreference);
assertThat(ConnectivityMonitorPreferenceController.USER_ENABLED_STATUS.equals(
SystemProperties.get(
ConnectivityMonitorPreferenceController.PROPERTY_CONNECTIVITY_MONITOR,
ConnectivityMonitorPreferenceController.DISABLED_STATUS))).isTrue();
}
@Config(shadows = {SettingsShadowSystemProperties.class})
@Test
public void handlePreferenceTreeClick_preferenceUnchecked_shouldDisableConnectivityMonitor() {
when(mPreference.isChecked()).thenReturn(false);
when(mContext.getResources().getString(R.string.connectivity_monitor_toast))
.thenReturn("To apply connectivity monitor change, reboot device");
mController.handlePreferenceTreeClick(mPreference);
assertThat(ConnectivityMonitorPreferenceController.USER_DISABLED_STATUS.equals(
SystemProperties.get(
ConnectivityMonitorPreferenceController.PROPERTY_CONNECTIVITY_MONITOR,
ConnectivityMonitorPreferenceController.DISABLED_STATUS))).isTrue();
}
}

View File

@@ -1,135 +0,0 @@
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.development;
import android.app.Activity;
import android.content.Context;
import android.provider.SearchIndexableResource;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceManager;
import android.support.v7.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.shadow.SettingsShadowResources;
import com.android.settingslib.development.DevelopmentSettingsEnabler;
import com.android.settingslib.drawer.CategoryKey;
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.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;
import java.util.ArrayList;
import java.util.List;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Answers.RETURNS_DEEP_STUBS;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
shadows = {
SettingsShadowResources.class,
SettingsShadowResources.SettingsShadowTheme.class
})
public class DevelopmentSettingsTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private Context mContext;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private Activity mActivity;
@Mock(answer = RETURNS_DEEP_STUBS)
private PreferenceScreen mScreen;
@Mock
private PreferenceManager mPreferenceManager;
private FakeFeatureFactory mFeatureFactory;
private DevelopmentSettings mSettings;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
FakeFeatureFactory.setupForTest(mContext);
mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
mSettings = spy(new DevelopmentSettings());
}
@Test
public void addDashboardCategoryPreference_shouldAddToScreen() {
final List<Preference> preferences = new ArrayList<>();
preferences.add(new Preference(ShadowApplication.getInstance().getApplicationContext()));
preferences.add(new Preference(ShadowApplication.getInstance().getApplicationContext()));
doReturn(mScreen).when(mSettings).getPreferenceScreen();
doReturn(mPreferenceManager).when(mSettings).getPreferenceManager();
doReturn(mActivity).when(mSettings).getActivity();
when(mPreferenceManager.getContext()).thenReturn(mContext);
when(mFeatureFactory.dashboardFeatureProvider.getPreferencesForCategory(
mActivity, mContext, mSettings.getMetricsCategory(),
CategoryKey.CATEGORY_SYSTEM_DEVELOPMENT))
.thenReturn(preferences);
mSettings.onAttach(mContext);
mSettings.addDashboardCategoryPreferences();
verify(mScreen, times(2)).addPreference(any(Preference.class));
}
@Test
public void searchIndex_shouldIndexFromPrefXml() {
final List<SearchIndexableResource> index =
DevelopmentSettings.SEARCH_INDEX_DATA_PROVIDER.getXmlResourcesToIndex(
RuntimeEnvironment.application, true);
assertThat(index.size()).isEqualTo(1);
assertThat(index.get(0).xmlResId).isEqualTo(R.xml.development_settings);
}
@Test
public void searchIndex_pageDisabled_shouldAddAllKeysToNonIndexable() {
final Context appContext = RuntimeEnvironment.application;
DevelopmentSettingsEnabler.setDevelopmentSettingsEnabled(appContext, false);
final List<String> nonIndexableKeys =
DevelopmentSettings.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(appContext);
assertThat(nonIndexableKeys).contains("development_prefs_screen");
}
@Test
public void searchIndex_pageEnabled_shouldNotAddKeysToNonIndexable() {
final Context appContext = RuntimeEnvironment.application;
DevelopmentSettingsEnabler.setDevelopmentSettingsEnabled(appContext, true);
final List<String> nonIndexableKeys =
DevelopmentSettings.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(appContext);
assertThat(nonIndexableKeys).doesNotContain("development_prefs_screen");
}
}

View File

@@ -23,6 +23,8 @@ import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.when;
import android.content.Context;
import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.ShadowUtils;
@@ -49,9 +51,8 @@ import java.util.ArrayList;
public class DevelopmentSwitchBarControllerTest {
@Mock
private DevelopmentSettings mSettings;
@Mock
private DevelopmentSettingsDashboardFragment mNewSettings;
private DevelopmentSettingsDashboardFragment mSettings;
private Context mContext;
private Lifecycle mLifecycle;
private SwitchBar mSwitchBar;
private DevelopmentSwitchBarController mController;
@@ -59,8 +60,10 @@ public class DevelopmentSwitchBarControllerTest {
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
mLifecycle = new Lifecycle(() -> mLifecycle);
mSwitchBar = new SwitchBar(RuntimeEnvironment.application);
mSwitchBar = new SwitchBar(mContext);
when(mSettings.getContext()).thenReturn(mContext);
}
@After
@@ -69,7 +72,7 @@ public class DevelopmentSwitchBarControllerTest {
}
@Test
public void runThroughLifecycle_isMonkeyRun_shouldNotRegisterListener() {
public void runThroughLifecycle_v2_isMonkeyRun_shouldNotRegisterListener() {
ShadowUtils.setIsUserAMonkey(true);
mController = new DevelopmentSwitchBarController(mSettings, mSwitchBar,
true /* isAvailable */, mLifecycle);
@@ -83,21 +86,6 @@ public class DevelopmentSwitchBarControllerTest {
assertThat(listeners).doesNotContain(mSettings);
}
@Test
public void runThroughLifecycle_v2_isMonkeyRun_shouldNotRegisterListener() {
ShadowUtils.setIsUserAMonkey(true);
mController = new DevelopmentSwitchBarController(mNewSettings, mSwitchBar,
true /* isAvailable */, mLifecycle);
final ArrayList<SwitchBar.OnSwitchChangeListener> listeners =
ReflectionHelpers.getField(mSwitchBar, "mSwitchChangeListeners");
mLifecycle.handleLifecycleEvent(ON_START);
assertThat(listeners).doesNotContain(mNewSettings);
mLifecycle.handleLifecycleEvent(ON_STOP);
assertThat(listeners).doesNotContain(mNewSettings);
}
@Test
public void runThroughLifecycle_isNotMonkeyRun_shouldRegisterAndRemoveListener() {
ShadowUtils.setIsUserAMonkey(false);
@@ -115,18 +103,18 @@ public class DevelopmentSwitchBarControllerTest {
@Test
public void runThroughLifecycle_v2_isNotMonkeyRun_shouldRegisterAndRemoveListener() {
when(mNewSettings.getContext()).thenReturn(RuntimeEnvironment.application);
when(mSettings.getContext()).thenReturn(RuntimeEnvironment.application);
ShadowUtils.setIsUserAMonkey(false);
mController = new DevelopmentSwitchBarController(mNewSettings, mSwitchBar,
mController = new DevelopmentSwitchBarController(mSettings, mSwitchBar,
true /* isAvailable */, mLifecycle);
final ArrayList<SwitchBar.OnSwitchChangeListener> listeners =
ReflectionHelpers.getField(mSwitchBar, "mSwitchChangeListeners");
mLifecycle.handleLifecycleEvent(ON_START);
assertThat(listeners).contains(mNewSettings);
assertThat(listeners).contains(mSettings);
mLifecycle.handleLifecycleEvent(ON_STOP);
assertThat(listeners).doesNotContain(mNewSettings);
assertThat(listeners).doesNotContain(mSettings);
}
@Test

View File

@@ -1,62 +0,0 @@
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.development;
import static com.google.common.truth.Truth.assertThat;
import android.support.v14.preference.SwitchPreference;
import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import org.junit.Before;
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;
/**
* @deprecated in favor of {@link AdbPreferenceController}
*/
@Deprecated
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class EnableAdbPreferenceControllerTest {
@Mock
private SwitchPreference mSwitchPreference;
private EnableAdbPreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mController
= new EnableAdbPreferenceController(RuntimeEnvironment.application);
}
@Test
public void testIsConfirmationDialogShowing() {
assertThat(mController.isConfirmationDialogShowing()).isFalse();
mController.showConfirmationDialog(mSwitchPreference);
assertThat(mController.isConfirmationDialogShowing()).isTrue();
mController.dismissConfirmationDialog();
assertThat(mController.isConfirmationDialogShowing()).isFalse();
}
}

View File

@@ -1,66 +0,0 @@
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.development;
import static com.google.common.truth.Truth.assertThat;
import android.support.v7.preference.ListPreference;
import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settingslib.core.lifecycle.Lifecycle;
import org.junit.Before;
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;
/**
* deprecated in favor of {@link LogPersistPreferenceControllerV2}
*/
@Deprecated
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class LogpersistPreferenceControllerTest {
private Lifecycle mLifecycle;
@Mock
private ListPreference mListPreference;
private LogpersistPreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mLifecycle = new Lifecycle(() -> mLifecycle);
mController
= new LogpersistPreferenceController(RuntimeEnvironment.application, mLifecycle);
}
@Test
public void testIsConfirmationDialogShowing() {
assertThat(mController.isConfirmationDialogShowing()).isFalse();
mController.showConfirmationDialog(mListPreference);
assertThat(mController.isConfirmationDialogShowing()).isTrue();
mController.dismissConfirmationDialog();
assertThat(mController.isConfirmationDialogShowing()).isFalse();
}
}

View File

@@ -1,184 +0,0 @@
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.development;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.provider.Settings.Global;
import android.support.v7.preference.PreferenceScreen;
import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
import com.android.settingslib.RestrictedSwitchPreference;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;
import org.robolectric.util.ReflectionHelpers;
import java.util.Collections;
import java.util.List;
/**
* deprecated in favor of {@link VerifyAppsOverUsbPreferenceControllerV2}
*/
@Deprecated
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class VerifyAppsOverUsbPreferenceControllerTest {
@Mock
private PackageManager mPackageManager;
@Mock
private PreferenceScreen mScreen;
@Mock
private RestrictedSwitchPreference mPreference;
@Mock
private VerifyAppsOverUsbPreferenceController.RestrictedLockUtilsDelegate
mRestrictedLockUtilsDelegate;
private Context mContext;
private VerifyAppsOverUsbPreferenceController mController;
/** Convenience class for setting global int settings. */
class GlobalSetter {
public GlobalSetter set(String setting, int value) {
Global.putInt(mContext.getContentResolver(), setting, value);
return this;
}
}
private final GlobalSetter mGlobals = new GlobalSetter();
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
final ShadowApplication shadowContext = ShadowApplication.getInstance();
mContext = spy(shadowContext.getApplicationContext());
when(mScreen.findPreference(anyString())).thenReturn(mPreference);
when(mContext.getPackageManager()).thenReturn(mPackageManager);
mController = new VerifyAppsOverUsbPreferenceController(mContext);
ReflectionHelpers.setField(
mController, "mRestrictedLockUtils", mRestrictedLockUtilsDelegate);
}
private void setupVerifyBroadcastReceivers(boolean nonEmpty) {
final List<ResolveInfo> resolveInfos = nonEmpty
? Collections.singletonList(mock(ResolveInfo.class))
: Collections.<ResolveInfo>emptyList();
when(mPackageManager.queryBroadcastReceivers((Intent) any(), anyInt()))
.thenReturn(resolveInfos);
}
private void setupEnforcedAdmin(EnforcedAdmin result) {
when(mRestrictedLockUtilsDelegate.checkIfRestrictionEnforced(
(Context) any(), anyString(), anyInt())).thenReturn(result);
}
@Test
public void updateState_preferenceCheckedWhenSettingIsOn() {
setupVerifyBroadcastReceivers(true);
setupEnforcedAdmin(null);
mGlobals.set(Global.ADB_ENABLED, 1).set(Global.PACKAGE_VERIFIER_INCLUDE_ADB, 1);
mController.displayPreference(mScreen);
mController.updatePreference();
verify(mPreference).setChecked(true);
}
@Test
public void updateState_preferenceUncheckedWhenSettingIsOff() {
setupVerifyBroadcastReceivers(true);
setupEnforcedAdmin(null);
mGlobals.set(Global.ADB_ENABLED, 1).set(Global.PACKAGE_VERIFIER_INCLUDE_ADB, 0);
mController.displayPreference(mScreen);
mController.updatePreference();
verify(mPreference).setChecked(false);
}
@Test
public void updateState_preferenceUncheckedWhenNoAdb() {
setupVerifyBroadcastReceivers(true);
setupEnforcedAdmin(null);
mGlobals.set(Global.ADB_ENABLED, 0).set(Global.PACKAGE_VERIFIER_INCLUDE_ADB, 1);
mController.displayPreference(mScreen);
mController.updatePreference();
verify(mPreference).setChecked(false);
}
@Test
public void updateState_preferenceUncheckedWhenVerifierIsOff() {
setupVerifyBroadcastReceivers(true);
setupEnforcedAdmin(null);
mGlobals.set(Global.ADB_ENABLED, 1)
.set(Global.PACKAGE_VERIFIER_INCLUDE_ADB, 1)
.set(Global.PACKAGE_VERIFIER_ENABLE, 0);
mController.displayPreference(mScreen);
mController.updatePreference();
verify(mPreference).setChecked(false);
}
@Test
public void updateState_preferenceUncheckedWhenNoVerifyBroadcastReceivers() {
setupVerifyBroadcastReceivers(false);
setupEnforcedAdmin(null);
mGlobals.set(Global.ADB_ENABLED, 1)
.set(Global.PACKAGE_VERIFIER_INCLUDE_ADB, 1);
mController.displayPreference(mScreen);
mController.updatePreference();
verify(mPreference).setChecked(false);
}
@Test
public void updateState_preferenceDisabledWhenRestrictedByAdmin() {
setupVerifyBroadcastReceivers(true);
final EnforcedAdmin admin = new EnforcedAdmin();
setupEnforcedAdmin(admin);
mGlobals.set(Global.ADB_ENABLED, 1)
.set(Global.PACKAGE_VERIFIER_INCLUDE_ADB, 1);
mController.displayPreference(mScreen);
mController.updatePreference();
verify(mPreference).setDisabledByAdmin(admin);
}
@Test
public void updateState_preferenceRemovedWhenVerifierSettingsVisibleIsOff() {
setupVerifyBroadcastReceivers(true);
mGlobals.set(Global.PACKAGE_VERIFIER_SETTING_VISIBLE, 0);
when(mPreference.getKey()).thenReturn(mController.getPreferenceKey());
when(mScreen.getPreferenceCount()).thenReturn(1);
when(mScreen.getPreference(anyInt())).thenReturn(mPreference);
mController.displayPreference(mScreen);
verify(mPreference).setVisible(false);
}
}