summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Cam Bickel <cambickel@google.com> 2024-11-19 21:56:57 +0000
committer Cam Bickel <cambickel@google.com> 2024-11-20 18:33:14 +0000
commit5e293d6ddfcec99451fc3e0521838ccd7e9a060c (patch)
treeadc5c713071e406f1ebdb055fd4e5c27af416e81
parent03e5fb05ca2a0ea7603ddf9dbe8cba8e07c15a8e (diff)
Fix broken MediaSwitchingControllerTest
This CL fixes the MediaSwitchingControllerTest on AL, where input routing is enabled by default. Test: atest MediaSwitchingControllerTest Bug: b/379880745 Flag: TEST_ONLY Change-Id: I48eaeb30f1ae74552736b057621efa54e30070c5
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaSwitchingControllerTest.java91
1 files changed, 87 insertions, 4 deletions
diff --git a/packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaSwitchingControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaSwitchingControllerTest.java
index bf4ef509ac80..eb1b44b75247 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaSwitchingControllerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaSwitchingControllerTest.java
@@ -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;
@@ -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);
@@ -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).
@@ -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).
@@ -547,6 +590,7 @@ 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();
@@ -554,6 +598,45 @@ public class MediaSwitchingControllerTest extends SysuiTestCase {
@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() {
AudioDeviceInfo[] audioDeviceInfos = {};
when(mAudioManager.getDevices(AudioManager.GET_DEVICES_INPUTS))