From 9b4309b145e576bfec56148bdd21a0a54375112a Mon Sep 17 00:00:00 2001 From: Robin Lee Date: Tue, 31 Jan 2017 00:09:20 +0000 Subject: [PATCH] Add another work sounds test This was removed when fixing the 4 broken tests. Here it is again to get the coverage back to where it was, using mAudioHelper to get the profile unlocked state this time instead of UserManager directly (where this is a hidden API, so not something robolectric supports) Test: make RunSettingsRoboTests Change-Id: I8bd383ea8a899004a6208968911d60df9b3b17bc --- .../WorkSoundPreferenceControllerTest.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/robotests/src/com/android/settings/notification/WorkSoundPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/WorkSoundPreferenceControllerTest.java index 419fd0086be..acfd400383c 100644 --- a/tests/robotests/src/com/android/settings/notification/WorkSoundPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/notification/WorkSoundPreferenceControllerTest.java @@ -193,6 +193,30 @@ public class WorkSoundPreferenceControllerTest { verify(preference).setSummary(anyString()); } + @Test + public void onResume_availableButLocked_shouldRedactPreferences() { + final String notAvailable = "(not available)"; + when(mContext.getString(R.string.managed_profile_not_available_label)) + .thenReturn(notAvailable); + + // Given a device with a managed profile: + when(mAudioHelper.isSingleVolume()).thenReturn(false); + when(mFragment.getPreferenceScreen()).thenReturn(mScreen); + when(mAudioHelper.createPackageContextAsUser(anyInt())).thenReturn(mContext); + when(mAudioHelper.getManagedProfileId(any(UserManager.class))) + .thenReturn(UserHandle.myUserId()); + when(mAudioHelper.isUserUnlocked(any(UserManager.class), anyInt())).thenReturn(false); + mockWorkCategory(); + + // When resumed: + mController.onResume(); + + // Sound preferences should explain that the profile isn't available yet. + verify(mScreen.findPreference(KEY_WORK_PHONE_RINGTONE)).setSummary(eq(notAvailable)); + verify(mScreen.findPreference(KEY_WORK_NOTIFICATION_RINGTONE)).setSummary(eq(notAvailable)); + verify(mScreen.findPreference(KEY_WORK_ALARM_RINGTONE)).setSummary(eq(notAvailable)); + } + private void mockWorkCategory() { when(mScreen.findPreference(KEY_WORK_CATEGORY)) .thenReturn(mock(PreferenceGroup.class));