Convert SecuritySubSetting into DashboardFragment
Bug: 32953042 Test: robotests Change-Id: Iecdb0a42695644ff8aa095bcd49b5ccb16aa46d4
This commit is contained in:
@@ -17,10 +17,14 @@
|
||||
package com.android.settings.security;
|
||||
|
||||
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.content.DialogInterface;
|
||||
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.ShadowEventLogWriter;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -29,10 +33,6 @@ import org.robolectric.Robolectric;
|
||||
import org.robolectric.android.controller.FragmentController;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(
|
||||
manifest = TestConfig.MANIFEST_PATH,
|
||||
|
@@ -15,16 +15,27 @@
|
||||
*/
|
||||
package com.android.settings.security;
|
||||
|
||||
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.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
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.app.FragmentManager;
|
||||
import android.app.FragmentTransaction;
|
||||
import android.content.Context;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.support.v14.preference.PreferenceFragment;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.internal.widget.LockPatternUtils;
|
||||
import com.android.settings.OwnerInfoSettings;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.users.OwnerInfoSettings;
|
||||
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||
import com.android.settingslib.RestrictedPreference;
|
||||
|
||||
@@ -37,18 +48,6 @@ import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
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.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class OwnerInfoPreferenceControllerTest {
|
||||
@@ -139,7 +138,7 @@ public class OwnerInfoPreferenceControllerTest {
|
||||
mController.updateSummary();
|
||||
|
||||
verify(mPreference).setSummary(mContext.getString(
|
||||
com.android.settings.R.string.owner_info_settings_summary));
|
||||
com.android.settings.R.string.owner_info_settings_summary));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -179,7 +178,7 @@ public class OwnerInfoPreferenceControllerTest {
|
||||
public void performClick_shouldLaunchOwnerInfoSettings() {
|
||||
final ShadowApplication application = ShadowApplication.getInstance();
|
||||
final RestrictedPreference preference =
|
||||
new RestrictedPreference(application.getApplicationContext());
|
||||
new RestrictedPreference(application.getApplicationContext());
|
||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(preference);
|
||||
doReturn(false).when(mController).isDeviceOwnerInfoEnabled();
|
||||
doReturn(false).when(mLockPatternUtils).isLockScreenDisabled(anyInt());
|
||||
@@ -190,7 +189,7 @@ public class OwnerInfoPreferenceControllerTest {
|
||||
|
||||
verify(mFragment).getFragmentManager();
|
||||
verify(mFragment.getFragmentManager().beginTransaction())
|
||||
.add(any(OwnerInfoSettings.class), anyString());
|
||||
.add(any(OwnerInfoSettings.class), anyString());
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* 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.security.screenlock;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.Context;
|
||||
import android.support.v14.preference.SwitchPreference;
|
||||
|
||||
import com.android.internal.widget.LockPatternUtils;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.security.trustagent.TrustAgentManager;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
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;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
|
||||
public class LockAfterTimeoutPreferenceControllerTest {
|
||||
|
||||
private static final int TEST_USER_ID = 0;
|
||||
|
||||
@Mock
|
||||
private LockPatternUtils mLockPatternUtils;
|
||||
@Mock
|
||||
private TrustAgentManager mTrustAgentManager;
|
||||
|
||||
private Context mContext;
|
||||
private LockAfterTimeoutPreferenceController mController;
|
||||
private SwitchPreference mPreference;
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||
when(mFeatureFactory.securityFeatureProvider.getTrustAgentManager())
|
||||
.thenReturn(mTrustAgentManager);
|
||||
|
||||
mPreference = new SwitchPreference(mContext);
|
||||
mController = new LockAfterTimeoutPreferenceController(
|
||||
mContext, TEST_USER_ID, mLockPatternUtils);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_lockSetToPattern_shouldReturnTrue() {
|
||||
when(mLockPatternUtils.isSecure(TEST_USER_ID)).thenReturn(true);
|
||||
when(mLockPatternUtils.getKeyguardStoredPasswordQuality(TEST_USER_ID))
|
||||
.thenReturn(DevicePolicyManager.PASSWORD_QUALITY_SOMETHING);
|
||||
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_lockSetToPin_shouldReturnTrue() {
|
||||
when(mLockPatternUtils.isSecure(TEST_USER_ID)).thenReturn(true);
|
||||
when(mLockPatternUtils.getKeyguardStoredPasswordQuality(TEST_USER_ID))
|
||||
.thenReturn(DevicePolicyManager.PASSWORD_QUALITY_NUMERIC);
|
||||
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_lockSetToPassword_shouldReturnTrue() {
|
||||
when(mLockPatternUtils.isSecure(TEST_USER_ID)).thenReturn(true);
|
||||
when(mLockPatternUtils.getKeyguardStoredPasswordQuality(TEST_USER_ID))
|
||||
.thenReturn(DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC);
|
||||
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_lockSetToNone_shouldReturnFalse() {
|
||||
when(mLockPatternUtils.isSecure(TEST_USER_ID)).thenReturn(false);
|
||||
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* 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.security.screenlock;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.Context;
|
||||
import android.support.v14.preference.SwitchPreference;
|
||||
|
||||
import com.android.internal.widget.LockPatternUtils;
|
||||
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;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
|
||||
public class PatternVisiblePreferenceControllerTest {
|
||||
|
||||
private static final int TEST_USER_ID = 0;
|
||||
|
||||
@Mock
|
||||
private LockPatternUtils mLockPatternUtils;
|
||||
private Context mContext;
|
||||
private PatternVisiblePreferenceController mController;
|
||||
private SwitchPreference mPreference;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mController = new PatternVisiblePreferenceController(
|
||||
mContext, TEST_USER_ID, mLockPatternUtils);
|
||||
mPreference = new SwitchPreference(mContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_lockSetToPattern_shouldReturnTrue() {
|
||||
when(mLockPatternUtils.isSecure(TEST_USER_ID)).thenReturn(true);
|
||||
when(mLockPatternUtils.getKeyguardStoredPasswordQuality(TEST_USER_ID))
|
||||
.thenReturn(DevicePolicyManager.PASSWORD_QUALITY_SOMETHING);
|
||||
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_lockSetToPin_shouldReturnFalse() {
|
||||
when(mLockPatternUtils.isSecure(TEST_USER_ID)).thenReturn(true);
|
||||
when(mLockPatternUtils.getKeyguardStoredPasswordQuality(TEST_USER_ID))
|
||||
.thenReturn(DevicePolicyManager.PASSWORD_QUALITY_NUMERIC);
|
||||
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_lockSetToNone_shouldReturnFalse() {
|
||||
when(mLockPatternUtils.isSecure(TEST_USER_ID)).thenReturn(false);
|
||||
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_shouldSetPref() {
|
||||
when(mLockPatternUtils.isVisiblePatternEnabled(TEST_USER_ID)).thenReturn(true);
|
||||
mController.updateState(mPreference);
|
||||
assertThat(mPreference.isChecked()).isTrue();
|
||||
|
||||
when(mLockPatternUtils.isVisiblePatternEnabled(TEST_USER_ID)).thenReturn(false);
|
||||
mController.updateState(mPreference);
|
||||
assertThat(mPreference.isChecked()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChange_shouldUpdateLockPatternUtils() {
|
||||
mController.onPreferenceChange(mPreference, true /* newValue */);
|
||||
|
||||
verify(mLockPatternUtils).setVisiblePatternEnabled(true, TEST_USER_ID);
|
||||
}
|
||||
}
|
@@ -0,0 +1,133 @@
|
||||
/*
|
||||
* 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.security.screenlock;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.Context;
|
||||
import android.support.v14.preference.SwitchPreference;
|
||||
|
||||
import com.android.internal.widget.LockPatternUtils;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.security.trustagent.TrustAgentManager;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
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;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
|
||||
public class PowerButtonInstantLockPreferenceControllerTest {
|
||||
|
||||
private static final int TEST_USER_ID = 0;
|
||||
|
||||
@Mock
|
||||
private LockPatternUtils mLockPatternUtils;
|
||||
@Mock
|
||||
private TrustAgentManager mTrustAgentManager;
|
||||
|
||||
private Context mContext;
|
||||
private PowerButtonInstantLockPreferenceController mController;
|
||||
private SwitchPreference mPreference;
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||
when(mFeatureFactory.securityFeatureProvider.getTrustAgentManager())
|
||||
.thenReturn(mTrustAgentManager);
|
||||
|
||||
mPreference = new SwitchPreference(mContext);
|
||||
mController = new PowerButtonInstantLockPreferenceController(
|
||||
mContext, TEST_USER_ID, mLockPatternUtils);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_lockSetToPattern_shouldReturnTrue() {
|
||||
when(mLockPatternUtils.isSecure(TEST_USER_ID)).thenReturn(true);
|
||||
when(mLockPatternUtils.getKeyguardStoredPasswordQuality(TEST_USER_ID))
|
||||
.thenReturn(DevicePolicyManager.PASSWORD_QUALITY_SOMETHING);
|
||||
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_lockSetToPin_shouldReturnTrue() {
|
||||
when(mLockPatternUtils.isSecure(TEST_USER_ID)).thenReturn(true);
|
||||
when(mLockPatternUtils.getKeyguardStoredPasswordQuality(TEST_USER_ID))
|
||||
.thenReturn(DevicePolicyManager.PASSWORD_QUALITY_NUMERIC);
|
||||
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_lockSetToPassword_shouldReturnTrue() {
|
||||
when(mLockPatternUtils.isSecure(TEST_USER_ID)).thenReturn(true);
|
||||
when(mLockPatternUtils.getKeyguardStoredPasswordQuality(TEST_USER_ID))
|
||||
.thenReturn(DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC);
|
||||
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_lockSetToNone_shouldReturnFalse() {
|
||||
when(mLockPatternUtils.isSecure(TEST_USER_ID)).thenReturn(false);
|
||||
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_shouldSetPref() {
|
||||
final String fakeTrustAgent = "trust_agent";
|
||||
when(mTrustAgentManager.getActiveTrustAgentLabel(mContext, mLockPatternUtils))
|
||||
.thenReturn(fakeTrustAgent);
|
||||
when(mLockPatternUtils.getPowerButtonInstantlyLocks(TEST_USER_ID)).thenReturn(true);
|
||||
mController.updateState(mPreference);
|
||||
assertThat(mPreference.isChecked()).isTrue();
|
||||
assertThat(mPreference.getSummary()).isEqualTo(mContext.getString(
|
||||
R.string.lockpattern_settings_power_button_instantly_locks_summary,
|
||||
fakeTrustAgent));
|
||||
|
||||
when(mTrustAgentManager.getActiveTrustAgentLabel(mContext, mLockPatternUtils))
|
||||
.thenReturn(null);
|
||||
when(mLockPatternUtils.getPowerButtonInstantlyLocks(TEST_USER_ID)).thenReturn(false);
|
||||
mController.updateState(mPreference);
|
||||
assertThat(mPreference.isChecked()).isFalse();
|
||||
assertThat(mPreference.getSummary()).isEqualTo(mContext.getString(
|
||||
R.string.summary_placeholder));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChange_shouldUpdateLockPatternUtils() {
|
||||
mController.onPreferenceChange(mPreference, true /* newValue */);
|
||||
|
||||
verify(mLockPatternUtils).setPowerButtonInstantlyLocks(true, TEST_USER_ID);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* 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.security.screenlock;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.security.OwnerInfoPreferenceController;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
|
||||
public class ScreenLockSettingsTest {
|
||||
|
||||
private ScreenLockSettings mSettings;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mSettings = new ScreenLockSettings();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyConstants() {
|
||||
assertThat(mSettings.getMetricsCategory()).isEqualTo(MetricsProto.MetricsEvent.SECURITY);
|
||||
assertThat(mSettings.getPreferenceScreenResId()).isEqualTo(R.xml.screen_lock_settings);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onOwnerInfoUpdated_shouldUpdateOwnerInfoController() {
|
||||
final Map<Class, AbstractPreferenceController> preferenceControllers =
|
||||
ReflectionHelpers.getField(mSettings, "mPreferenceControllers");
|
||||
final OwnerInfoPreferenceController controller = mock(OwnerInfoPreferenceController.class);
|
||||
preferenceControllers.put(OwnerInfoPreferenceController.class, controller);
|
||||
|
||||
mSettings.onOwnerInfoUpdated();
|
||||
|
||||
verify(controller).updateSummary();
|
||||
}
|
||||
|
||||
}
|
@@ -15,6 +15,10 @@
|
||||
*/
|
||||
package com.android.settings.testutils;
|
||||
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.applications.ApplicationFeatureProvider;
|
||||
@@ -30,14 +34,12 @@ import com.android.settings.gestures.AssistGestureFeatureProvider;
|
||||
import com.android.settings.localepicker.LocaleFeatureProvider;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.overlay.SupportFeatureProvider;
|
||||
import com.android.settings.security.SecurityFeatureProvider;
|
||||
import com.android.settings.search.SearchFeatureProvider;
|
||||
import com.android.settings.overlay.SurveyFeatureProvider;
|
||||
import com.android.settings.search.SearchFeatureProvider;
|
||||
import com.android.settings.security.SecurityFeatureProvider;
|
||||
import com.android.settings.users.UserFeatureProvider;
|
||||
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
import org.mockito.Answers;
|
||||
|
||||
/**
|
||||
* Test util to provide fake FeatureFactory. To use this factory, call {@code setupForTest} in
|
||||
@@ -67,6 +69,7 @@ public class FakeFeatureFactory extends FeatureFactory {
|
||||
*
|
||||
* @param context The context must be a deep mock.
|
||||
*/
|
||||
@Deprecated
|
||||
public static FakeFeatureFactory setupForTest(Context context) {
|
||||
sFactory = null;
|
||||
when(context.getString(com.android.settings.R.string.config_featureFactory))
|
||||
@@ -80,6 +83,14 @@ public class FakeFeatureFactory extends FeatureFactory {
|
||||
return (FakeFeatureFactory) FakeFeatureFactory.getFactory(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call this in {@code @Before} method of the test class to use fake factory.
|
||||
*/
|
||||
public static FakeFeatureFactory setupForTest() {
|
||||
final Context context = mock(Context.class, Answers.RETURNS_DEEP_STUBS);
|
||||
return setupForTest(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used by reflection. Do not call directly.
|
||||
*/
|
||||
|
Reference in New Issue
Block a user