Loading packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaSwitchingControllerTest.java +87 −4 Original line number Diff line number Diff line Loading @@ -59,6 +59,7 @@ import android.os.Bundle; import android.os.PowerExemptionManager; import android.os.RemoteException; import android.os.UserHandle; import android.platform.test.annotations.DisableFlags; import android.platform.test.annotations.EnableFlags; import android.service.notification.StatusBarNotification; import android.testing.TestableLooper; Loading Loading @@ -242,10 +243,14 @@ public class MediaSwitchingControllerTest extends SysuiTestCase { mLocalMediaManager = spy(mMediaSwitchingController.mLocalMediaManager); when(mLocalMediaManager.isPreferenceRouteListingExist()).thenReturn(false); mMediaSwitchingController.mLocalMediaManager = mLocalMediaManager; mMediaSwitchingController.mInputRouteManager = new InputRouteManager(mContext, mAudioManager); mInputRouteManager = spy(mMediaSwitchingController.mInputRouteManager); mMediaSwitchingController.mInputRouteManager = mInputRouteManager; when(mAudioManager.getDevices(AudioManager.GET_DEVICES_INPUTS)) .thenReturn(new AudioDeviceInfo[0]); MediaDescription.Builder builder = new MediaDescription.Builder(); builder.setTitle(TEST_SONG); builder.setSubtitle(TEST_ARTIST); Loading Loading @@ -483,11 +488,11 @@ public class MediaSwitchingControllerTest extends SysuiTestCase { verify(mMediaDevice2, never()).setRangeZone(anyInt()); } @DisableFlags(Flags.FLAG_ENABLE_AUDIO_INPUT_DEVICE_ROUTING_AND_VOLUME_CONTROL) @Test public void onDeviceListUpdate_verifyDeviceListCallback() { // This test relies on mMediaSwitchingController.start being called while the selected // device // list has exactly one item, and that item's id is: // device list has exactly one item, and that item's id is: // - Different from both ids in mMediaDevices. // - Different from the id of the route published by the device under test (usually the // built-in speakers). Loading @@ -511,16 +516,54 @@ public class MediaSwitchingControllerTest extends SysuiTestCase { assertThat(devices.containsAll(mMediaDevices)).isTrue(); assertThat(devices.size()).isEqualTo(mMediaDevices.size()); // There should be 2 non-MediaDevice items: the "Speakers & Display" title, and the "Connect // a device" button. assertThat(mMediaSwitchingController.getMediaItemList().size()) .isEqualTo(mMediaDevices.size() + 2); verify(mCb).onDeviceListChanged(); } @EnableFlags(Flags.FLAG_ENABLE_AUDIO_INPUT_DEVICE_ROUTING_AND_VOLUME_CONTROL) @Test public void onDeviceListUpdate_verifyDeviceListCallback_inputRouting() { // This test relies on mMediaSwitchingController.start being called while the selected // device list has exactly one item, and that item's id is: // - Different from both ids in mMediaDevices. // - Different from the id of the route published by the device under test (usually the // built-in speakers). // So mock the selected device to respect these two preconditions. MediaDevice mockSelectedMediaDevice = Mockito.mock(MediaDevice.class); when(mockSelectedMediaDevice.getId()).thenReturn(TEST_DEVICE_3_ID); doReturn(List.of(mockSelectedMediaDevice)) .when(mLocalMediaManager) .getSelectedMediaDevice(); mMediaSwitchingController.start(mCb); reset(mCb); mMediaSwitchingController.onDeviceListUpdate(mMediaDevices); final List<MediaDevice> devices = new ArrayList<>(); for (MediaItem item : mMediaSwitchingController.getMediaItemList()) { if (item.getMediaDevice().isPresent()) { devices.add(item.getMediaDevice().get()); } } assertThat(devices.containsAll(mMediaDevices)).isTrue(); assertThat(devices.size()).isEqualTo(mMediaDevices.size()); // When input routing is enabled, there should be 4 non-MediaDevice items: one for // the "Output" title, one for the "Speakers & Displays" title, one for the "Connect a // device" button, and one for the "Input" title. assertThat(mMediaSwitchingController.getMediaItemList().size()) .isEqualTo(mMediaDevices.size() + 4); verify(mCb).onDeviceListChanged(); } @DisableFlags(Flags.FLAG_ENABLE_AUDIO_INPUT_DEVICE_ROUTING_AND_VOLUME_CONTROL) @Test public void advanced_onDeviceListUpdateWithConnectedDeviceRemote_verifyItemSize() { // This test relies on mMediaSwitchingController.start being called while the selected // device // list has exactly one item, and that item's id is: // device list has exactly one item, and that item's id is: // - Different from both ids in mMediaDevices. // - Different from the id of the route published by the device under test (usually the // built-in speakers). Loading @@ -547,11 +590,51 @@ public class MediaSwitchingControllerTest extends SysuiTestCase { assertThat(devices.containsAll(mMediaDevices)).isTrue(); assertThat(devices.size()).isEqualTo(mMediaDevices.size()); // There should be 1 non-MediaDevice item: the "Speakers & Display" title. assertThat(mMediaSwitchingController.getMediaItemList().size()) .isEqualTo(mMediaDevices.size() + 1); verify(mCb).onDeviceListChanged(); } @EnableFlags(Flags.FLAG_ENABLE_AUDIO_INPUT_DEVICE_ROUTING_AND_VOLUME_CONTROL) @Test public void advanced_onDeviceListUpdateWithConnectedDeviceRemote_verifyItemSize_inputRouting() { // This test relies on mMediaSwitchingController.start being called while the selected // device list has exactly one item, and that item's id is: // - Different from both ids in mMediaDevices. // - Different from the id of the route published by the device under test (usually the // built-in speakers). // So mock the selected device to respect these two preconditions. MediaDevice mockSelectedMediaDevice = Mockito.mock(MediaDevice.class); when(mockSelectedMediaDevice.getId()).thenReturn(TEST_DEVICE_3_ID); doReturn(List.of(mockSelectedMediaDevice)) .when(mLocalMediaManager) .getSelectedMediaDevice(); when(mMediaDevice1.getFeatures()) .thenReturn(ImmutableList.of(MediaRoute2Info.FEATURE_REMOTE_PLAYBACK)); when(mLocalMediaManager.getCurrentConnectedDevice()).thenReturn(mMediaDevice1); mMediaSwitchingController.start(mCb); reset(mCb); mMediaSwitchingController.onDeviceListUpdate(mMediaDevices); final List<MediaDevice> devices = new ArrayList<>(); for (MediaItem item : mMediaSwitchingController.getMediaItemList()) { if (item.getMediaDevice().isPresent()) { devices.add(item.getMediaDevice().get()); } } assertThat(devices.containsAll(mMediaDevices)).isTrue(); assertThat(devices.size()).isEqualTo(mMediaDevices.size()); // When input routing is enabled, there should be 3 non-MediaDevice items: one for // the "Output" title, one for the "Speakers & Displays" title, and one for the "Input" // title. assertThat(mMediaSwitchingController.getMediaItemList().size()) .isEqualTo(mMediaDevices.size() + 3); verify(mCb).onDeviceListChanged(); } @EnableFlags(Flags.FLAG_ENABLE_AUDIO_INPUT_DEVICE_ROUTING_AND_VOLUME_CONTROL) @Test public void onInputDeviceListUpdate_verifyDeviceListCallback() { Loading Loading
packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaSwitchingControllerTest.java +87 −4 Original line number Diff line number Diff line Loading @@ -59,6 +59,7 @@ import android.os.Bundle; import android.os.PowerExemptionManager; import android.os.RemoteException; import android.os.UserHandle; import android.platform.test.annotations.DisableFlags; import android.platform.test.annotations.EnableFlags; import android.service.notification.StatusBarNotification; import android.testing.TestableLooper; Loading Loading @@ -242,10 +243,14 @@ public class MediaSwitchingControllerTest extends SysuiTestCase { mLocalMediaManager = spy(mMediaSwitchingController.mLocalMediaManager); when(mLocalMediaManager.isPreferenceRouteListingExist()).thenReturn(false); mMediaSwitchingController.mLocalMediaManager = mLocalMediaManager; mMediaSwitchingController.mInputRouteManager = new InputRouteManager(mContext, mAudioManager); mInputRouteManager = spy(mMediaSwitchingController.mInputRouteManager); mMediaSwitchingController.mInputRouteManager = mInputRouteManager; when(mAudioManager.getDevices(AudioManager.GET_DEVICES_INPUTS)) .thenReturn(new AudioDeviceInfo[0]); MediaDescription.Builder builder = new MediaDescription.Builder(); builder.setTitle(TEST_SONG); builder.setSubtitle(TEST_ARTIST); Loading Loading @@ -483,11 +488,11 @@ public class MediaSwitchingControllerTest extends SysuiTestCase { verify(mMediaDevice2, never()).setRangeZone(anyInt()); } @DisableFlags(Flags.FLAG_ENABLE_AUDIO_INPUT_DEVICE_ROUTING_AND_VOLUME_CONTROL) @Test public void onDeviceListUpdate_verifyDeviceListCallback() { // This test relies on mMediaSwitchingController.start being called while the selected // device // list has exactly one item, and that item's id is: // device list has exactly one item, and that item's id is: // - Different from both ids in mMediaDevices. // - Different from the id of the route published by the device under test (usually the // built-in speakers). Loading @@ -511,16 +516,54 @@ public class MediaSwitchingControllerTest extends SysuiTestCase { assertThat(devices.containsAll(mMediaDevices)).isTrue(); assertThat(devices.size()).isEqualTo(mMediaDevices.size()); // There should be 2 non-MediaDevice items: the "Speakers & Display" title, and the "Connect // a device" button. assertThat(mMediaSwitchingController.getMediaItemList().size()) .isEqualTo(mMediaDevices.size() + 2); verify(mCb).onDeviceListChanged(); } @EnableFlags(Flags.FLAG_ENABLE_AUDIO_INPUT_DEVICE_ROUTING_AND_VOLUME_CONTROL) @Test public void onDeviceListUpdate_verifyDeviceListCallback_inputRouting() { // This test relies on mMediaSwitchingController.start being called while the selected // device list has exactly one item, and that item's id is: // - Different from both ids in mMediaDevices. // - Different from the id of the route published by the device under test (usually the // built-in speakers). // So mock the selected device to respect these two preconditions. MediaDevice mockSelectedMediaDevice = Mockito.mock(MediaDevice.class); when(mockSelectedMediaDevice.getId()).thenReturn(TEST_DEVICE_3_ID); doReturn(List.of(mockSelectedMediaDevice)) .when(mLocalMediaManager) .getSelectedMediaDevice(); mMediaSwitchingController.start(mCb); reset(mCb); mMediaSwitchingController.onDeviceListUpdate(mMediaDevices); final List<MediaDevice> devices = new ArrayList<>(); for (MediaItem item : mMediaSwitchingController.getMediaItemList()) { if (item.getMediaDevice().isPresent()) { devices.add(item.getMediaDevice().get()); } } assertThat(devices.containsAll(mMediaDevices)).isTrue(); assertThat(devices.size()).isEqualTo(mMediaDevices.size()); // When input routing is enabled, there should be 4 non-MediaDevice items: one for // the "Output" title, one for the "Speakers & Displays" title, one for the "Connect a // device" button, and one for the "Input" title. assertThat(mMediaSwitchingController.getMediaItemList().size()) .isEqualTo(mMediaDevices.size() + 4); verify(mCb).onDeviceListChanged(); } @DisableFlags(Flags.FLAG_ENABLE_AUDIO_INPUT_DEVICE_ROUTING_AND_VOLUME_CONTROL) @Test public void advanced_onDeviceListUpdateWithConnectedDeviceRemote_verifyItemSize() { // This test relies on mMediaSwitchingController.start being called while the selected // device // list has exactly one item, and that item's id is: // device list has exactly one item, and that item's id is: // - Different from both ids in mMediaDevices. // - Different from the id of the route published by the device under test (usually the // built-in speakers). Loading @@ -547,11 +590,51 @@ public class MediaSwitchingControllerTest extends SysuiTestCase { assertThat(devices.containsAll(mMediaDevices)).isTrue(); assertThat(devices.size()).isEqualTo(mMediaDevices.size()); // There should be 1 non-MediaDevice item: the "Speakers & Display" title. assertThat(mMediaSwitchingController.getMediaItemList().size()) .isEqualTo(mMediaDevices.size() + 1); verify(mCb).onDeviceListChanged(); } @EnableFlags(Flags.FLAG_ENABLE_AUDIO_INPUT_DEVICE_ROUTING_AND_VOLUME_CONTROL) @Test public void advanced_onDeviceListUpdateWithConnectedDeviceRemote_verifyItemSize_inputRouting() { // This test relies on mMediaSwitchingController.start being called while the selected // device list has exactly one item, and that item's id is: // - Different from both ids in mMediaDevices. // - Different from the id of the route published by the device under test (usually the // built-in speakers). // So mock the selected device to respect these two preconditions. MediaDevice mockSelectedMediaDevice = Mockito.mock(MediaDevice.class); when(mockSelectedMediaDevice.getId()).thenReturn(TEST_DEVICE_3_ID); doReturn(List.of(mockSelectedMediaDevice)) .when(mLocalMediaManager) .getSelectedMediaDevice(); when(mMediaDevice1.getFeatures()) .thenReturn(ImmutableList.of(MediaRoute2Info.FEATURE_REMOTE_PLAYBACK)); when(mLocalMediaManager.getCurrentConnectedDevice()).thenReturn(mMediaDevice1); mMediaSwitchingController.start(mCb); reset(mCb); mMediaSwitchingController.onDeviceListUpdate(mMediaDevices); final List<MediaDevice> devices = new ArrayList<>(); for (MediaItem item : mMediaSwitchingController.getMediaItemList()) { if (item.getMediaDevice().isPresent()) { devices.add(item.getMediaDevice().get()); } } assertThat(devices.containsAll(mMediaDevices)).isTrue(); assertThat(devices.size()).isEqualTo(mMediaDevices.size()); // When input routing is enabled, there should be 3 non-MediaDevice items: one for // the "Output" title, one for the "Speakers & Displays" title, and one for the "Input" // title. assertThat(mMediaSwitchingController.getMediaItemList().size()) .isEqualTo(mMediaDevices.size() + 3); verify(mCb).onDeviceListChanged(); } @EnableFlags(Flags.FLAG_ENABLE_AUDIO_INPUT_DEVICE_ROUTING_AND_VOLUME_CONTROL) @Test public void onInputDeviceListUpdate_verifyDeviceListCallback() { Loading