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

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 5 years, 2 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 4633d8773f0a4b19d76ab08866ea9b074d9662b8..79e73c6e1f007724f6a1f2bbd1c603da4db94fcf 100644
--- a/chromeos/audio/cras_audio_handler_unittest.cc
+++ b/chromeos/audio/cras_audio_handler_unittest.cc
@@ -41,6 +41,7 @@ const uint64 kUSBCameraInputId = 90007;
const AudioNode kInternalSpeaker(
false,
kInternalSpeakerId,
+ kInternalSpeakerId,
"Fake Speaker",
"INTERNAL_SPEAKER",
"Speaker",
@@ -51,6 +52,7 @@ const AudioNode kInternalSpeaker(
const AudioNode kHeadphone(
false,
kHeadphoneId,
+ kHeadphoneId,
"Fake Headphone",
"HEADPHONE",
"Headphone",
@@ -61,6 +63,7 @@ const AudioNode kHeadphone(
const AudioNode kInternalMic(
true,
kInternalMicId,
+ kInternalMicId,
"Fake Mic",
"INTERNAL_MIC",
"Internal Mic",
@@ -71,6 +74,7 @@ const AudioNode kInternalMic(
const AudioNode kMicJack(
true,
kMicJackId,
+ kMicJackId,
"Fake Mic Jack",
"MIC",
"Mic Jack",
@@ -81,6 +85,7 @@ const AudioNode kMicJack(
const AudioNode kUSBMic(
true,
kUSBMicId,
+ kUSBMicId,
"Fake USB Mic",
"USB",
"USB Microphone",
@@ -91,6 +96,7 @@ const AudioNode kUSBMic(
const AudioNode kKeyboardMic(
true,
kKeyboardMicId,
+ kKeyboardMicId,
"Fake Keyboard Mic",
"KEYBOARD_MIC",
"Keyboard Mic",
@@ -101,6 +107,7 @@ const AudioNode kKeyboardMic(
const AudioNode kOtherTypeOutput(
false,
kOtherTypeOutputId,
+ kOtherTypeOutputId,
"Output Device",
"SOME_OTHER_TYPE",
"Other Type Output Device",
@@ -111,6 +118,7 @@ const AudioNode kOtherTypeOutput(
const AudioNode kOtherTypeInput(
true,
kOtherTypeInputId,
+ kOtherTypeInputId,
"Input Device",
"SOME_OTHER_TYPE",
"Other Type Input Device",
@@ -120,6 +128,7 @@ const AudioNode kOtherTypeInput(
const AudioNode kBluetoothHeadset(false,
kBluetoothHeadsetId,
+ kBluetoothHeadsetId,
"Bluetooth Headset",
"BLUETOOTH",
"Bluetooth Headset 1",
@@ -128,6 +137,7 @@ const AudioNode kBluetoothHeadset(false,
const AudioNode kHDMIOutput(false,
kHDMIOutputId,
+ kHDMIOutputId,
"HDMI output",
"HDMI",
"HDMI output",
@@ -136,6 +146,7 @@ const AudioNode kHDMIOutput(false,
const AudioNode kUSBHeadphone1(false,
kUSBHeadphoneId1,
+ kUSBHeadphoneId1,
"USB Headphone",
"USB",
"USB Headphone 1",
@@ -144,6 +155,7 @@ const AudioNode kUSBHeadphone1(false,
const AudioNode kUSBHeadphone2(false,
kUSBHeadphoneId2,
+ kUSBHeadphoneId2,
"USB Headphone",
"USB",
"USB Headphone 1",
@@ -152,6 +164,7 @@ const AudioNode kUSBHeadphone2(false,
const AudioNode kUSBJabraSpeakerOutput1(false,
kUSBJabraSpeakerOutputId1,
+ kUSBJabraSpeakerOutputId1,
"Jabra Speaker 1",
"USB",
"Jabra Speaker 1",
@@ -160,6 +173,7 @@ const AudioNode kUSBJabraSpeakerOutput1(false,
const AudioNode kUSBJabraSpeakerOutput2(false,
kUSBJabraSpeakerOutputId2,
+ kUSBJabraSpeakerOutputId2,
"Jabra Speaker 2",
"USB",
"Jabra Speaker 2",
@@ -168,6 +182,7 @@ const AudioNode kUSBJabraSpeakerOutput2(false,
const AudioNode kUSBJabraSpeakerInput1(true,
kUSBJabraSpeakerInputId1,
+ kUSBJabraSpeakerInputId1,
"Jabra Speaker 1",
"USB",
"Jabra Speaker",
@@ -176,6 +191,7 @@ const AudioNode kUSBJabraSpeakerInput1(true,
const AudioNode kUSBJabraSpeakerInput2(true,
kUSBJabraSpeakerInputId2,
+ kUSBJabraSpeakerInputId2,
"Jabra Speaker 2",
"USB",
"Jabra Speaker 2",
@@ -184,6 +200,7 @@ const AudioNode kUSBJabraSpeakerInput2(true,
const AudioNode kUSBCameraInput(true,
kUSBCameraInputId,
+ kUSBCameraInputId,
"USB Camera",
"USB",
"USB Camera",
@@ -2039,6 +2056,60 @@ TEST_F(CrasAudioHandlerTest, HandleOtherDeviceType) {
EXPECT_TRUE(cras_audio_handler_->has_alternative_input());
}
+TEST_F(CrasAudioHandlerTest, UnselectActiveDeviceAndPlugAnother) {
jennyz 2015/12/17 22:50:21 The test case name can be changed to something mor
hychao 2015/12/29 10:57:25 Done. This do sounds better, thanks.
+ 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());
+
+ EXPECT_EQ(kUSBHeadphone1.id,
+ cras_audio_handler_->GetPrimaryActiveOutputNode());
jennyz 2015/12/17 22:50:21 Add some comment will be more helpful to explain w
hychao 2015/12/29 10:57:25 Done.
+
+ AudioDevice speaker(kInternalSpeaker);
+ cras_audio_handler_->SwitchToDevice(speaker, true);
jennyz 2015/12/17 22:50:21 Please add a comment: Now change the active device
hychao 2015/12/29 10:57:25 Done. Also added a check below to make sure USB is
+
+ // 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 USB headset of the same device stable id, but with different id
jennyz 2015/12/17 22:50:21 nits: add "." at the end. How about: Plug the same
hychao 2015/12/29 10:57:25 Done.
+ usb_headset.active = false;
+ usb_headset.id = 98765;
+ audio_nodes.push_back(usb_headset);
+ ChangeAudioNodes(audio_nodes);
+ EXPECT_EQ(kInternalSpeaker.id,
+ cras_audio_handler_->GetPrimaryActiveOutputNode());
jennyz 2015/12/17 22:50:21 Please add a comment: "Since usb headset was inact
hychao 2015/12/29 10:57:25 Done.
+
+ // Plug the second USB headset
+ AudioNode usb_headset2(kUSBHeadphone2);
+ usb_headset2.plugged_time = 80000001;
+ audio_nodes.push_back(usb_headset2);
+ ChangeAudioNodes(audio_nodes);
+ EXPECT_EQ(kUSBHeadphone2.id,
+ cras_audio_handler_->GetPrimaryActiveOutputNode());
jennyz 2015/12/17 22:50:21 Please add a comment: Since the second usb headset
hychao 2015/12/29 10:57:25 Done.
+
+ // 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);
+ EXPECT_EQ(usb_headset.id,
+ cras_audio_handler_->GetPrimaryActiveOutputNode());
jennyz 2015/12/17 22:50:21 When hotplug a new audio device, there are three c
hychao 2015/12/29 10:57:25 Done.
+}
+
TEST_F(CrasAudioHandlerTest, ChangeActiveNodesHotrodInit) {
AudioNodeList audio_nodes;
audio_nodes.push_back(kHDMIOutput);

Powered by Google App Engine
This is Rietveld 408576698