Merge "[Output Switcher] Fix LocalMediaManagerTest" into tm-qpr-dev
This commit is contained in:
@@ -84,7 +84,8 @@ public class LocalMediaManager implements BluetoothCallback {
|
||||
private InfoMediaManager mInfoMediaManager;
|
||||
private String mPackageName;
|
||||
private MediaDevice mOnTransferBluetoothDevice;
|
||||
private AudioManager mAudioManager;
|
||||
@VisibleForTesting
|
||||
AudioManager mAudioManager;
|
||||
|
||||
@VisibleForTesting
|
||||
List<MediaDevice> mMediaDevices = new CopyOnWriteArrayList<>();
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package com.android.settingslib.media;
|
||||
|
||||
import static android.bluetooth.BluetoothClass.Device.AUDIO_VIDEO_HEADPHONES;
|
||||
import static android.media.MediaRoute2ProviderService.REASON_UNKNOWN_ERROR;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
@@ -29,10 +28,12 @@ import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothClass;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.bluetooth.BluetoothProfile;
|
||||
import android.content.Context;
|
||||
import android.media.AudioDeviceAttributes;
|
||||
import android.media.AudioManager;
|
||||
import android.media.AudioSystem;
|
||||
import android.media.MediaRoute2Info;
|
||||
import android.media.MediaRouter2Manager;
|
||||
import android.media.RoutingSessionInfo;
|
||||
@@ -71,6 +72,7 @@ public class LocalMediaManagerTest {
|
||||
private static final String TEST_CURRENT_DEVICE_ID = "currentDevice_id";
|
||||
private static final String TEST_PACKAGE_NAME = "com.test.playmusic";
|
||||
private static final String TEST_SESSION_ID = "session_id";
|
||||
private static final String TEST_ADDRESS = "00:01:02:03:04:05";
|
||||
|
||||
@Mock
|
||||
private InfoMediaManager mInfoMediaManager;
|
||||
@@ -90,6 +92,8 @@ public class LocalMediaManagerTest {
|
||||
private MediaRoute2Info mRouteInfo1;
|
||||
@Mock
|
||||
private MediaRoute2Info mRouteInfo2;
|
||||
@Mock
|
||||
private AudioManager mAudioManager;
|
||||
|
||||
private Context mContext;
|
||||
private LocalMediaManager mLocalMediaManager;
|
||||
@@ -118,6 +122,7 @@ public class LocalMediaManagerTest {
|
||||
TEST_PACKAGE_NAME);
|
||||
mLocalMediaManager = new LocalMediaManager(mContext, mLocalBluetoothManager,
|
||||
mInfoMediaManager, "com.test.packagename");
|
||||
mLocalMediaManager.mAudioManager = mAudioManager;
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -551,16 +556,12 @@ public class LocalMediaManagerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onDeviceListAdded_haveDisconnectedDevice_addDisconnectedDevice() {
|
||||
public void onDeviceListAdded_haveMutingExpectedDevice_addMutingExpectedDevice() {
|
||||
final List<MediaDevice> devices = new ArrayList<>();
|
||||
final MediaDevice device1 = mock(MediaDevice.class);
|
||||
final MediaDevice device2 = mock(MediaDevice.class);
|
||||
final MediaDevice device3 = mock(MediaDevice.class);
|
||||
mLocalMediaManager.mPhoneDevice = mock(PhoneMediaDevice.class);
|
||||
devices.add(device1);
|
||||
devices.add(device2);
|
||||
mLocalMediaManager.mMediaDevices.add(device3);
|
||||
mLocalMediaManager.mMediaDevices.add(mLocalMediaManager.mPhoneDevice);
|
||||
devices.add(mLocalMediaManager.mPhoneDevice);
|
||||
|
||||
final List<LocalBluetoothProfile> profiles = new ArrayList<>();
|
||||
final A2dpProfile a2dpProfile = mock(A2dpProfile.class);
|
||||
@@ -573,22 +574,25 @@ public class LocalMediaManagerTest {
|
||||
bluetoothDevices.add(bluetoothDevice);
|
||||
mShadowBluetoothAdapter.setMostRecentlyConnectedDevices(bluetoothDevices);
|
||||
|
||||
AudioDeviceAttributes audioDeviceAttributes = new AudioDeviceAttributes(
|
||||
AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP, TEST_ADDRESS);
|
||||
|
||||
when(mAudioManager.getMutingExpectedDevice()).thenReturn(audioDeviceAttributes);
|
||||
when(mLocalBluetoothManager.getCachedDeviceManager()).thenReturn(cachedManager);
|
||||
when(cachedManager.findDevice(bluetoothDevice)).thenReturn(cachedDevice);
|
||||
when(cachedDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED);
|
||||
when(cachedDevice.isConnected()).thenReturn(false);
|
||||
when(cachedDevice.getConnectableProfiles()).thenReturn(profiles);
|
||||
when(cachedDevice.getDevice()).thenReturn(bluetoothDevice);
|
||||
when(cachedDevice.getAddress()).thenReturn(TEST_ADDRESS);
|
||||
when(mA2dpProfile.getActiveDevice()).thenReturn(bluetoothDevice);
|
||||
when(mHapProfile.getActiveDevices()).thenReturn(new ArrayList<>());
|
||||
|
||||
when(device1.getId()).thenReturn(TEST_DEVICE_ID_1);
|
||||
when(device2.getId()).thenReturn(TEST_DEVICE_ID_2);
|
||||
when(device3.getId()).thenReturn(TEST_DEVICE_ID_3);
|
||||
when(device1.getDeviceType()).thenReturn(MediaDevice.MediaDeviceType.TYPE_PHONE_DEVICE);
|
||||
when(mLocalMediaManager.mPhoneDevice.getId()).thenReturn("test_phone_id");
|
||||
|
||||
assertThat(mLocalMediaManager.mMediaDevices).hasSize(2);
|
||||
assertThat(mLocalMediaManager.mMediaDevices).hasSize(0);
|
||||
mLocalMediaManager.registerCallback(mCallback);
|
||||
mLocalMediaManager.mMediaDeviceCallback.onDeviceListAdded(devices);
|
||||
|
||||
@@ -633,68 +637,6 @@ public class LocalMediaManagerTest {
|
||||
verify(mCallback).onRequestFailed(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onDeviceListAdded_haveDisconnectedDevice_list5DisconnectedDevice() {
|
||||
final List<MediaDevice> devices = new ArrayList<>();
|
||||
final MediaDevice device1 = mock(MediaDevice.class);
|
||||
final MediaDevice device2 = mock(MediaDevice.class);
|
||||
final MediaDevice device3 = mock(MediaDevice.class);
|
||||
mLocalMediaManager.mPhoneDevice = mock(PhoneMediaDevice.class);
|
||||
devices.add(device1);
|
||||
devices.add(device2);
|
||||
mLocalMediaManager.mMediaDevices.add(device3);
|
||||
mLocalMediaManager.mMediaDevices.add(mLocalMediaManager.mPhoneDevice);
|
||||
|
||||
final List<LocalBluetoothProfile> profiles = new ArrayList<>();
|
||||
final A2dpProfile a2dpProfile = mock(A2dpProfile.class);
|
||||
profiles.add(a2dpProfile);
|
||||
|
||||
final List<BluetoothDevice> bluetoothDevices = new ArrayList<>();
|
||||
final BluetoothDevice bluetoothDevice = mock(BluetoothDevice.class);
|
||||
final BluetoothDevice bluetoothDevice2 = mock(BluetoothDevice.class);
|
||||
final BluetoothDevice bluetoothDevice3 = mock(BluetoothDevice.class);
|
||||
final BluetoothDevice bluetoothDevice4 = mock(BluetoothDevice.class);
|
||||
final BluetoothDevice bluetoothDevice5 = mock(BluetoothDevice.class);
|
||||
final BluetoothDevice bluetoothDevice6 = mock(BluetoothDevice.class);
|
||||
final BluetoothClass bluetoothClass = mock(BluetoothClass.class);
|
||||
final CachedBluetoothDevice cachedDevice = mock(CachedBluetoothDevice.class);
|
||||
final CachedBluetoothDeviceManager cachedManager = mock(CachedBluetoothDeviceManager.class);
|
||||
bluetoothDevices.add(bluetoothDevice);
|
||||
bluetoothDevices.add(bluetoothDevice2);
|
||||
bluetoothDevices.add(bluetoothDevice3);
|
||||
bluetoothDevices.add(bluetoothDevice4);
|
||||
bluetoothDevices.add(bluetoothDevice5);
|
||||
bluetoothDevices.add(bluetoothDevice6);
|
||||
mShadowBluetoothAdapter.setMostRecentlyConnectedDevices(bluetoothDevices);
|
||||
|
||||
when(mLocalBluetoothManager.getCachedDeviceManager()).thenReturn(cachedManager);
|
||||
when(cachedManager.findDevice(bluetoothDevice)).thenReturn(cachedDevice);
|
||||
when(cachedManager.findDevice(bluetoothDevice2)).thenReturn(cachedDevice);
|
||||
when(cachedManager.findDevice(bluetoothDevice3)).thenReturn(cachedDevice);
|
||||
when(cachedManager.findDevice(bluetoothDevice4)).thenReturn(cachedDevice);
|
||||
when(cachedManager.findDevice(bluetoothDevice5)).thenReturn(cachedDevice);
|
||||
when(cachedManager.findDevice(bluetoothDevice6)).thenReturn(cachedDevice);
|
||||
when(cachedDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED);
|
||||
when(cachedDevice.isConnected()).thenReturn(false);
|
||||
when(cachedDevice.getDevice()).thenReturn(bluetoothDevice);
|
||||
when(cachedDevice.getConnectableProfiles()).thenReturn(profiles);
|
||||
when(bluetoothDevice.getBluetoothClass()).thenReturn(bluetoothClass);
|
||||
when(bluetoothClass.getDeviceClass()).thenReturn(AUDIO_VIDEO_HEADPHONES);
|
||||
|
||||
when(device1.getId()).thenReturn(TEST_DEVICE_ID_1);
|
||||
when(device2.getId()).thenReturn(TEST_DEVICE_ID_2);
|
||||
when(device3.getId()).thenReturn(TEST_DEVICE_ID_3);
|
||||
when(device1.getDeviceType()).thenReturn(MediaDevice.MediaDeviceType.TYPE_PHONE_DEVICE);
|
||||
when(mLocalMediaManager.mPhoneDevice.getId()).thenReturn("test_phone_id");
|
||||
|
||||
assertThat(mLocalMediaManager.mMediaDevices).hasSize(2);
|
||||
mLocalMediaManager.registerCallback(mCallback);
|
||||
mLocalMediaManager.mMediaDeviceCallback.onDeviceListAdded(devices);
|
||||
|
||||
assertThat(mLocalMediaManager.mMediaDevices).hasSize(7);
|
||||
verify(mCallback).onDeviceListUpdate(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onDeviceListAdded_bluetoothAdapterIsNull_noDisconnectedDeviceAdded() {
|
||||
final List<MediaDevice> devices = new ArrayList<>();
|
||||
|
||||
Reference in New Issue
Block a user