Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Unified Diff: chromeos/audio/cras_audio_handler_unittest.cc

Issue 1380103003: Store audio device's active state in preference (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chromeos/audio/cras_audio_handler_unittest.cc
diff --git a/chromeos/audio/cras_audio_handler_unittest.cc b/chromeos/audio/cras_audio_handler_unittest.cc
index 46e7d3e8e347a1b437a8de4740a44fd26ebda4df..fd6432dfd4780ce49f03bcd5eeb3fe2b75dc5392 100644
--- a/chromeos/audio/cras_audio_handler_unittest.cc
+++ b/chromeos/audio/cras_audio_handler_unittest.cc
@@ -45,6 +45,7 @@ const uint64_t kUSBCameraInputId = 90007;
const AudioNode kInternalSpeaker(
false,
kInternalSpeakerId,
+ kInternalSpeakerId,
"Fake Speaker",
"INTERNAL_SPEAKER",
"Speaker",
@@ -55,6 +56,7 @@ const AudioNode kInternalSpeaker(
const AudioNode kHeadphone(
false,
kHeadphoneId,
+ kHeadphoneId,
"Fake Headphone",
"HEADPHONE",
"Headphone",
@@ -65,6 +67,7 @@ const AudioNode kHeadphone(
const AudioNode kInternalMic(
true,
kInternalMicId,
+ kInternalMicId,
"Fake Mic",
"INTERNAL_MIC",
"Internal Mic",
@@ -75,6 +78,7 @@ const AudioNode kInternalMic(
const AudioNode kMicJack(
true,
kMicJackId,
+ kMicJackId,
"Fake Mic Jack",
"MIC",
"Mic Jack",
@@ -85,6 +89,7 @@ const AudioNode kMicJack(
const AudioNode kUSBMic(
true,
kUSBMicId,
+ kUSBMicId,
"Fake USB Mic",
"USB",
"USB Microphone",
@@ -95,6 +100,7 @@ const AudioNode kUSBMic(
const AudioNode kKeyboardMic(
true,
kKeyboardMicId,
+ kKeyboardMicId,
"Fake Keyboard Mic",
"KEYBOARD_MIC",
"Keyboard Mic",
@@ -105,6 +111,7 @@ const AudioNode kKeyboardMic(
const AudioNode kOtherTypeOutput(
false,
kOtherTypeOutputId,
+ kOtherTypeOutputId,
"Output Device",
"SOME_OTHER_TYPE",
"Other Type Output Device",
@@ -115,6 +122,7 @@ const AudioNode kOtherTypeOutput(
const AudioNode kOtherTypeInput(
true,
kOtherTypeInputId,
+ kOtherTypeInputId,
"Input Device",
"SOME_OTHER_TYPE",
"Other Type Input Device",
@@ -124,6 +132,7 @@ const AudioNode kOtherTypeInput(
const AudioNode kBluetoothHeadset(false,
kBluetoothHeadsetId,
+ kBluetoothHeadsetId,
"Bluetooth Headset",
"BLUETOOTH",
"Bluetooth Headset 1",
@@ -132,6 +141,7 @@ const AudioNode kBluetoothHeadset(false,
const AudioNode kHDMIOutput(false,
kHDMIOutputId,
+ kHDMIOutputId,
"HDMI output",
"HDMI",
"HDMI output",
@@ -140,6 +150,7 @@ const AudioNode kHDMIOutput(false,
const AudioNode kUSBHeadphone1(false,
kUSBHeadphoneId1,
+ kUSBHeadphoneId1,
"USB Headphone",
"USB",
"USB Headphone 1",
@@ -148,6 +159,7 @@ const AudioNode kUSBHeadphone1(false,
const AudioNode kUSBHeadphone2(false,
kUSBHeadphoneId2,
+ kUSBHeadphoneId2,
"USB Headphone",
"USB",
"USB Headphone 1",
@@ -156,6 +168,7 @@ const AudioNode kUSBHeadphone2(false,
const AudioNode kUSBJabraSpeakerOutput1(false,
kUSBJabraSpeakerOutputId1,
+ kUSBJabraSpeakerOutputId1,
"Jabra Speaker 1",
"USB",
"Jabra Speaker 1",
@@ -164,6 +177,7 @@ const AudioNode kUSBJabraSpeakerOutput1(false,
const AudioNode kUSBJabraSpeakerOutput2(false,
kUSBJabraSpeakerOutputId2,
+ kUSBJabraSpeakerOutputId2,
"Jabra Speaker 2",
"USB",
"Jabra Speaker 2",
@@ -172,6 +186,7 @@ const AudioNode kUSBJabraSpeakerOutput2(false,
const AudioNode kUSBJabraSpeakerInput1(true,
kUSBJabraSpeakerInputId1,
+ kUSBJabraSpeakerInputId1,
"Jabra Speaker 1",
"USB",
"Jabra Speaker",
@@ -180,6 +195,7 @@ const AudioNode kUSBJabraSpeakerInput1(true,
const AudioNode kUSBJabraSpeakerInput2(true,
kUSBJabraSpeakerInputId2,
+ kUSBJabraSpeakerInputId2,
"Jabra Speaker 2",
"USB",
"Jabra Speaker 2",
@@ -188,6 +204,7 @@ const AudioNode kUSBJabraSpeakerInput2(true,
const AudioNode kUSBCameraInput(true,
kUSBCameraInputId,
+ kUSBCameraInputId,
"USB Camera",
"USB",
"USB Camera",
@@ -2043,6 +2060,86 @@ TEST_F(CrasAudioHandlerTest, HandleOtherDeviceType) {
EXPECT_TRUE(cras_audio_handler_->has_alternative_input());
}
+TEST_F(CrasAudioHandlerTest, ActiveDeviceSelectionWithStableDeviceId) {
+ AudioNodeList audio_nodes;
+ AudioNode internal_speaker(kInternalSpeaker);
+ audio_nodes.push_back(internal_speaker);
+ AudioNode usb_headset(kUSBHeadphone1);
+ usb_headset.plugged_time = 80000000;
+ audio_nodes.push_back(usb_headset);
+ SetUpCrasAudioHandler(audio_nodes);
+
+ // Verify the audio devices size.
+ AudioDeviceList audio_devices;
+ cras_audio_handler_->GetAudioDevices(&audio_devices);
+ EXPECT_EQ(audio_nodes.size(), audio_devices.size());
+
+ // Initially active node is selected base on priority, so USB headphone
+ // is selected.
+ EXPECT_EQ(kUSBHeadphone1.id,
+ cras_audio_handler_->GetPrimaryActiveOutputNode());
+
+ // Change the active device to internal speaker, now USB headphone becomes
+ // inactive.
+ AudioDevice speaker(kInternalSpeaker);
+ cras_audio_handler_->SwitchToDevice(speaker, true);
+ EXPECT_NE(kUSBHeadphone1.id,
+ cras_audio_handler_->GetPrimaryActiveOutputNode());
+
+ // Unplug USB headset.
+ audio_nodes.clear();
+ internal_speaker.active = true;
+ audio_nodes.push_back(internal_speaker);
+ ChangeAudioNodes(audio_nodes);
+ EXPECT_EQ(kInternalSpeaker.id,
+ cras_audio_handler_->GetPrimaryActiveOutputNode());
+
+ // Plug the same USB headset back, id is different, but stable_device_id
+ // remains the same.
+ usb_headset.active = false;
+ usb_headset.id = 98765;
+ audio_nodes.push_back(usb_headset);
+ ChangeAudioNodes(audio_nodes);
+
+ // Since USB headset was inactive before it was unplugged, it won't be
+ // selected as active after it's plugged in again.
+ EXPECT_EQ(kInternalSpeaker.id,
+ cras_audio_handler_->GetPrimaryActiveOutputNode());
+
+ // Plug the second USB headset.
+ AudioNode usb_headset2(kUSBHeadphone2);
+ usb_headset2.plugged_time = 80000001;
+ audio_nodes.push_back(usb_headset2);
+ ChangeAudioNodes(audio_nodes);
+
+ // Since the second USB device is new, it's selected as the active device
+ // by its priority.
+ EXPECT_EQ(kUSBHeadphone2.id,
+ cras_audio_handler_->GetPrimaryActiveOutputNode());
+
+ // Unplug the second USB headset.
+ audio_nodes.clear();
+ internal_speaker.active = false;
+ audio_nodes.push_back(internal_speaker);
+ audio_nodes.push_back(usb_headset);
+ ChangeAudioNodes(audio_nodes);
+
+ // There is no active node after USB2 unplugged, the 1st USB got selected
+ // by its priority.
+ EXPECT_EQ(usb_headset.id,
+ cras_audio_handler_->GetPrimaryActiveOutputNode());
+
+ usb_headset2.active = false;
+ usb_headset2.plugged_time = 80000002;
+ audio_nodes.push_back(usb_headset2);
+ ChangeAudioNodes(audio_nodes);
+
+ // Plug the second USB again. Since it was the active node before it got
+ // unplugged, it is now selected as the active node.
+ EXPECT_EQ(usb_headset2.id,
+ cras_audio_handler_->GetPrimaryActiveOutputNode());
+}
+
TEST_F(CrasAudioHandlerTest, ChangeActiveNodesHotrodInit) {
AudioNodeList audio_nodes;
audio_nodes.push_back(kHDMIOutput);

Powered by Google App Engine
This is Rietveld 408576698