OSDN Git Service

Add another work sounds test
authorRobin Lee <rgl@google.com>
Tue, 31 Jan 2017 00:09:20 +0000 (00:09 +0000)
committerRobin Lee <rgl@google.com>
Thu, 2 Feb 2017 17:08:05 +0000 (17:08 +0000)
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

tests/robotests/src/com/android/settings/notification/WorkSoundPreferenceControllerTest.java

index 419fd00..acfd400 100644 (file)
@@ -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));