Instead of using summary for verifer, change the security setting summary to a static text. Bug: 36889582 Test: make RunSettingsRoboTests Change-Id: Ia3e2c7c595f403965751bacf2239c70070408e49
186 lines
7.4 KiB
Java
186 lines
7.4 KiB
Java
/*
|
|
* 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;
|
|
|
|
import android.app.Activity;
|
|
import android.content.Context;
|
|
import android.content.IContentProvider;
|
|
import android.content.pm.PackageManager;
|
|
import android.hardware.fingerprint.FingerprintManager;
|
|
import android.os.Bundle;
|
|
import android.provider.Settings;
|
|
import android.support.v7.preference.Preference;
|
|
import android.support.v7.preference.PreferenceGroup;
|
|
import android.support.v7.preference.PreferenceScreen;
|
|
|
|
import com.android.internal.widget.LockPatternUtils;
|
|
import com.android.settings.dashboard.SummaryLoader;
|
|
import com.android.settings.notification.LockScreenNotificationPreferenceController;
|
|
import com.android.settings.testutils.FakeFeatureFactory;
|
|
import com.android.settings.testutils.shadow.ShadowSecureSettings;
|
|
import com.android.settingslib.drawer.DashboardCategory;
|
|
import com.android.settingslib.drawer.Tile;
|
|
import com.android.settingslib.drawer.TileUtils;
|
|
|
|
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 org.robolectric.annotation.Implementation;
|
|
import org.robolectric.annotation.Implements;
|
|
import org.robolectric.shadows.ShadowApplication;
|
|
import org.robolectric.util.ReflectionHelpers;
|
|
|
|
import java.util.Map;
|
|
import org.robolectric.util.ReflectionHelpers;
|
|
|
|
import static com.google.common.truth.Truth.assertThat;
|
|
import static org.mockito.Matchers.any;
|
|
import static org.mockito.Matchers.anyInt;
|
|
import static org.mockito.Matchers.isNull;
|
|
import static org.mockito.Mockito.mock;
|
|
import static org.mockito.Mockito.spy;
|
|
import static org.mockito.Mockito.times;
|
|
import static org.mockito.Mockito.verify;
|
|
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
|
import static org.mockito.Mockito.when;
|
|
|
|
@RunWith(SettingsRobolectricTestRunner.class)
|
|
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
|
public class SecuritySettingsTest {
|
|
|
|
private static final String MOCK_SUMMARY = "summary";
|
|
|
|
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
|
private Context mContext;
|
|
@Mock
|
|
private DashboardCategory mDashboardCategory;
|
|
@Mock
|
|
private SummaryLoader mSummaryLoader;
|
|
|
|
private SecuritySettings.SummaryProvider mSummaryProvider;
|
|
|
|
@Implements(com.android.settingslib.drawer.TileUtils.class)
|
|
public static class ShadowTileUtils {
|
|
@Implementation
|
|
public static String getTextFromUri(Context context, String uriString,
|
|
Map<String, IContentProvider> providerMap, String key) {
|
|
return MOCK_SUMMARY;
|
|
}
|
|
}
|
|
|
|
@Before
|
|
public void setUp() {
|
|
MockitoAnnotations.initMocks(this);
|
|
FakeFeatureFactory.setupForTest(mContext);
|
|
mSummaryProvider = new SecuritySettings.SummaryProvider(mContext, mSummaryLoader);
|
|
}
|
|
|
|
@Test
|
|
public void testSummaryProvider_notListening() {
|
|
mSummaryProvider.setListening(false);
|
|
|
|
verifyNoMoreInteractions(mSummaryLoader);
|
|
}
|
|
|
|
@Test
|
|
public void testSummaryProvider_hasFingerPrint_hasStaticSummary() {
|
|
final FingerprintManager fpm = mock(FingerprintManager.class);
|
|
when(mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FINGERPRINT))
|
|
.thenReturn(true);
|
|
|
|
// Cast to Object to workaround a robolectric casting bug
|
|
when((Object) mContext.getSystemService(FingerprintManager.class)).thenReturn(fpm);
|
|
when(fpm.isHardwareDetected()).thenReturn(true);
|
|
|
|
mSummaryProvider.setListening(true);
|
|
|
|
verify(mContext).getString(R.string.security_dashboard_summary);
|
|
}
|
|
|
|
@Test
|
|
public void testSummaryProvider_noFpFeature_shouldSetSummaryWithNoFingerprint() {
|
|
final FingerprintManager fpm = mock(FingerprintManager.class);
|
|
when(mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FINGERPRINT))
|
|
.thenReturn(false);
|
|
|
|
mSummaryProvider.setListening(true);
|
|
|
|
verify(mContext).getString(R.string.security_dashboard_summary_no_fingerprint);
|
|
}
|
|
|
|
@Test
|
|
public void testSummaryProvider_noFpHardware_shouldSetSummaryWithNoFingerprint() {
|
|
final FingerprintManager fpm = mock(FingerprintManager.class);
|
|
when(mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FINGERPRINT))
|
|
.thenReturn(true);
|
|
|
|
// Cast to Object to workaround a robolectric casting bug
|
|
when((Object) mContext.getSystemService(FingerprintManager.class)).thenReturn(fpm);
|
|
when(fpm.isHardwareDetected()).thenReturn(false);
|
|
|
|
mSummaryProvider.setListening(true);
|
|
|
|
verify(mContext).getString(R.string.security_dashboard_summary_no_fingerprint);
|
|
}
|
|
|
|
@Test
|
|
public void testInitTrustAgentPreference_secure_shouldSetSummaryToNumberOfTrustAgent() {
|
|
final Preference preference = mock(Preference.class);
|
|
final PreferenceScreen screen = mock(PreferenceScreen.class);
|
|
when(screen.findPreference(SecuritySettings.KEY_MANAGE_TRUST_AGENTS))
|
|
.thenReturn(preference);
|
|
final LockPatternUtils utils = mock(LockPatternUtils.class);
|
|
when(utils.isSecure(anyInt())).thenReturn(true);
|
|
final Context context = ShadowApplication.getInstance().getApplicationContext();
|
|
final Activity activity = mock(Activity.class);
|
|
when(activity.getResources()).thenReturn(context.getResources());
|
|
final SecuritySettings securitySettings = spy(new SecuritySettings());
|
|
when(securitySettings.getActivity()).thenReturn(activity);
|
|
|
|
ReflectionHelpers.setField(securitySettings, "mLockPatternUtils", utils);
|
|
|
|
securitySettings.initTrustAgentPreference(screen, 0);
|
|
verify(preference).setSummary(R.string.manage_trust_agents_summary);
|
|
|
|
securitySettings.initTrustAgentPreference(screen, 2);
|
|
verify(preference).setSummary(context.getResources().getQuantityString(
|
|
R.plurals.manage_trust_agents_summary_on, 2, 2));
|
|
}
|
|
|
|
@Test
|
|
public void testSetLockscreenPreferencesSummary_shouldSetSummaryFromLockScreenNotification() {
|
|
final Preference preference = mock(Preference.class);
|
|
final PreferenceGroup group = mock(PreferenceGroup.class);
|
|
when(group.findPreference(SecuritySettings.KEY_LOCKSCREEN_PREFERENCES))
|
|
.thenReturn(preference);
|
|
final LockScreenNotificationPreferenceController controller =
|
|
mock(LockScreenNotificationPreferenceController.class);
|
|
|
|
final SecuritySettings securitySettings = new SecuritySettings();
|
|
ReflectionHelpers.setField(securitySettings,
|
|
"mLockScreenNotificationPreferenceController", controller);
|
|
|
|
when(controller.getSummaryResource()).thenReturn(1234);
|
|
securitySettings.setLockscreenPreferencesSummary(group);
|
|
verify(preference).setSummary(1234);
|
|
}
|
|
}
|