Sound + Output Switcher on Sound Setting

1. Show "play media to" item when Previously Connected device is available
2. Click "Play media to" to launch output slice
3. Update test case

Bug: 126475101
Test: make -j50 RunSettingsRoboTests
Change-Id: Id8afd1a2407acb78c11e81d2420ae8c16130a321
This commit is contained in:
timhypeng
2019-03-04 16:32:47 +08:00
committed by tim peng
parent 94240c5a52
commit abdf739071
8 changed files with 350 additions and 522 deletions

View File

@@ -57,6 +57,7 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.Shadows;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowBluetoothDevice;
@@ -107,7 +108,7 @@ public class HandsFreeProfileOutputPreferenceControllerTest {
private BluetoothDevice mLeftBluetoothHapDevice;
private BluetoothDevice mRightBluetoothHapDevice;
private LocalBluetoothManager mLocalBluetoothManager;
private AudioSwitchPreferenceController mController;
private HandsFreeProfileOutputPreferenceController mController;
private List<BluetoothDevice> mProfileConnectedDevices;
private List<BluetoothDevice> mHearingAidActiveDevices;
@@ -478,4 +479,61 @@ public class HandsFreeProfileOutputPreferenceControllerTest {
assertThat(mController.findActiveDevice()).isNull();
}
/**
* One Bluetooth devices are available, and select the device.
* Preference summary should be device name.
*/
@Test
public void onPreferenceChange_toBtDevice_shouldSetBtDeviceName() {
mController.mConnectedDevices.clear();
mController.mConnectedDevices.add(mBluetoothDevice);
mController.onPreferenceChange(mPreference, TEST_DEVICE_ADDRESS_1);
assertThat(mPreference.getSummary()).isEqualTo(TEST_DEVICE_NAME_1);
}
/**
* More than one Bluetooth devices are available, and select second device.
* Preference summary should be second device name.
*/
@Test
public void onPreferenceChange_toBtDevices_shouldSetSecondBtDeviceName() {
ShadowBluetoothDevice shadowBluetoothDevice;
BluetoothDevice secondBluetoothDevice;
secondBluetoothDevice = mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_2);
shadowBluetoothDevice = Shadows.shadowOf(secondBluetoothDevice);
shadowBluetoothDevice.setName(TEST_DEVICE_NAME_2);
mController.mConnectedDevices.clear();
mController.mConnectedDevices.add(mBluetoothDevice);
mController.mConnectedDevices.add(secondBluetoothDevice);
mController.onPreferenceChange(mPreference, TEST_DEVICE_ADDRESS_2);
assertThat(mPreference.getSummary()).isEqualTo(TEST_DEVICE_NAME_2);
}
/**
* mConnectedDevices is empty.
* onPreferenceChange should return false.
*/
@Test
public void onPreferenceChange_connectedDeviceIsNull_shouldReturnFalse() {
mController.mConnectedDevices.clear();
assertThat(mController.onPreferenceChange(mPreference, TEST_DEVICE_ADDRESS_1)).isFalse();
}
@Test
public void onPreferenceChange_toThisDevice_shouldSetDefaultSummary() {
mController.mConnectedDevices.clear();
mController.mConnectedDevices.add(mBluetoothDevice);
mController.onPreferenceChange(mPreference,
mContext.getText(R.string.media_output_default_summary));
assertThat(mPreference.getSummary()).isEqualTo(
mContext.getText(R.string.media_output_default_summary));
}
}