OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chromeos/audio/cras_audio_handler.h" | 5 #include "chromeos/audio/cras_audio_handler.h" |
6 | 6 |
7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 930 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
941 audio_nodes.push_back(kInternalMic); | 941 audio_nodes.push_back(kInternalMic); |
942 SetUpCrasAudioHandler(audio_nodes); | 942 SetUpCrasAudioHandler(audio_nodes); |
943 const size_t init_nodes_size = audio_nodes.size(); | 943 const size_t init_nodes_size = audio_nodes.size(); |
944 | 944 |
945 // Verify the audio devices size. | 945 // Verify the audio devices size. |
946 AudioDeviceList audio_devices; | 946 AudioDeviceList audio_devices; |
947 cras_audio_handler_->GetAudioDevices(&audio_devices); | 947 cras_audio_handler_->GetAudioDevices(&audio_devices); |
948 EXPECT_EQ(init_nodes_size, audio_devices.size()); | 948 EXPECT_EQ(init_nodes_size, audio_devices.size()); |
949 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); | 949 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); |
950 | 950 |
951 // Verify the internal mic is selected as the active output. | 951 // Verify the internal mic is selected as the active input. |
952 EXPECT_EQ(0, test_observer_->active_input_node_changed_count()); | 952 EXPECT_EQ(0, test_observer_->active_input_node_changed_count()); |
953 EXPECT_EQ(kInternalMic.id, cras_audio_handler_->GetActiveInputNode()); | 953 EXPECT_EQ(kInternalMic.id, cras_audio_handler_->GetActiveInputNode()); |
954 EXPECT_FALSE(cras_audio_handler_->has_alternative_input()); | 954 EXPECT_FALSE(cras_audio_handler_->has_alternative_input()); |
955 | 955 |
956 // Plug the USB Mic. | 956 // Plug the USB Mic. |
957 audio_nodes.push_back(kUSBMic); | 957 audio_nodes.push_back(kUSBMic); |
958 ChangeAudioNodes(audio_nodes); | 958 ChangeAudioNodes(audio_nodes); |
959 | 959 |
960 // Verify the AudioNodesChanged event is fired and new audio device is added. | 960 // Verify the AudioNodesChanged event is fired and new audio device is added. |
961 EXPECT_EQ(1, test_observer_->audio_nodes_changed_count()); | 961 EXPECT_EQ(1, test_observer_->audio_nodes_changed_count()); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
999 cras_audio_handler_->GetAudioDevices(&audio_devices); | 999 cras_audio_handler_->GetAudioDevices(&audio_devices); |
1000 EXPECT_EQ(init_nodes_size - 1, audio_devices.size()); | 1000 EXPECT_EQ(init_nodes_size - 1, audio_devices.size()); |
1001 | 1001 |
1002 // Verify the active input device is switched to internal mic, and | 1002 // Verify the active input device is switched to internal mic, and |
1003 // and ActiveInputChanged event is fired. | 1003 // and ActiveInputChanged event is fired. |
1004 EXPECT_EQ(1, test_observer_->active_input_node_changed_count()); | 1004 EXPECT_EQ(1, test_observer_->active_input_node_changed_count()); |
1005 EXPECT_EQ(kInternalMic.id, cras_audio_handler_->GetActiveInputNode()); | 1005 EXPECT_EQ(kInternalMic.id, cras_audio_handler_->GetActiveInputNode()); |
1006 EXPECT_FALSE(cras_audio_handler_->has_alternative_input()); | 1006 EXPECT_FALSE(cras_audio_handler_->has_alternative_input()); |
1007 } | 1007 } |
1008 | 1008 |
| 1009 TEST_F(CrasAudioHandlerTest, PlugUSBMicNotAffectActiveOutput) { |
| 1010 // Set up initial audio devices. |
| 1011 AudioNodeList audio_nodes; |
| 1012 audio_nodes.push_back(kInternalSpeaker); |
| 1013 audio_nodes.push_back(kHeadphone); |
| 1014 audio_nodes.push_back(kInternalMic); |
| 1015 SetUpCrasAudioHandler(audio_nodes); |
| 1016 const size_t init_nodes_size = audio_nodes.size(); |
| 1017 |
| 1018 // Verify the audio devices size. |
| 1019 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); |
| 1020 AudioDeviceList audio_devices; |
| 1021 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 1022 EXPECT_EQ(init_nodes_size, audio_devices.size()); |
| 1023 |
| 1024 // Verify the internal mic is selected as the active input. |
| 1025 EXPECT_EQ(0, test_observer_->active_input_node_changed_count()); |
| 1026 EXPECT_EQ(kInternalMicId, cras_audio_handler_->GetActiveInputNode()); |
| 1027 EXPECT_FALSE(cras_audio_handler_->has_alternative_input()); |
| 1028 |
| 1029 // Verify the headphone is selected as the active output. |
| 1030 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); |
| 1031 EXPECT_EQ(kHeadphoneId, cras_audio_handler_->GetActiveOutputNode()); |
| 1032 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
| 1033 |
| 1034 // Switch the active output to internal speaker. |
| 1035 AudioDevice internal_speaker(kInternalSpeaker); |
| 1036 cras_audio_handler_->SwitchToDevice(internal_speaker); |
| 1037 |
| 1038 // Verify the active output is switched to internal speaker, and the |
| 1039 // ActiveOutputNodeChanged event is fired. |
| 1040 EXPECT_EQ(1, test_observer_->active_output_node_changed_count()); |
| 1041 AudioDevice active_output; |
| 1042 EXPECT_TRUE(cras_audio_handler_->GetActiveOutputDevice(&active_output)); |
| 1043 EXPECT_EQ(kInternalSpeaker.id, active_output.id); |
| 1044 EXPECT_EQ(kInternalSpeaker.id, cras_audio_handler_->GetActiveOutputNode()); |
| 1045 |
| 1046 // Plug the USB Mic. |
| 1047 audio_nodes.push_back(kUSBMic); |
| 1048 ChangeAudioNodes(audio_nodes); |
| 1049 |
| 1050 // Verify the AudioNodesChanged event is fired, one new device is added. |
| 1051 EXPECT_EQ(1, test_observer_->audio_nodes_changed_count()); |
| 1052 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 1053 EXPECT_EQ(init_nodes_size + 1, audio_devices.size()); |
| 1054 |
| 1055 // Verify the active input device is switched to USB mic, and |
| 1056 // and ActiveInputChanged event is fired. |
| 1057 EXPECT_EQ(1, test_observer_->active_input_node_changed_count()); |
| 1058 EXPECT_EQ(kUSBMic.id, cras_audio_handler_->GetActiveInputNode()); |
| 1059 EXPECT_TRUE(cras_audio_handler_->has_alternative_input()); |
| 1060 |
| 1061 // Verify the active output device is not changed. |
| 1062 EXPECT_EQ(1, test_observer_->active_output_node_changed_count()); |
| 1063 EXPECT_TRUE(cras_audio_handler_->GetActiveOutputDevice(&active_output)); |
| 1064 EXPECT_EQ(kInternalSpeaker.id, active_output.id); |
| 1065 EXPECT_EQ(kInternalSpeaker.id, cras_audio_handler_->GetActiveOutputNode()); |
| 1066 } |
| 1067 |
1009 TEST_F(CrasAudioHandlerTest, SetOutputMute) { | 1068 TEST_F(CrasAudioHandlerTest, SetOutputMute) { |
1010 AudioNodeList audio_nodes; | 1069 AudioNodeList audio_nodes; |
1011 audio_nodes.push_back(kInternalSpeaker); | 1070 audio_nodes.push_back(kInternalSpeaker); |
1012 SetUpCrasAudioHandler(audio_nodes); | 1071 SetUpCrasAudioHandler(audio_nodes); |
1013 EXPECT_EQ(0, test_observer_->output_mute_changed_count()); | 1072 EXPECT_EQ(0, test_observer_->output_mute_changed_count()); |
1014 | 1073 |
1015 // Mute the device. | 1074 // Mute the device. |
1016 cras_audio_handler_->SetOutputMute(true); | 1075 cras_audio_handler_->SetOutputMute(true); |
1017 | 1076 |
1018 // Verify the output is muted, OnOutputMuteChanged event is fired, | 1077 // Verify the output is muted, OnOutputMuteChanged event is fired, |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1226 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); | 1285 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
1227 | 1286 |
1228 // Ensure the internal microphone has been selected as the active input, | 1287 // Ensure the internal microphone has been selected as the active input, |
1229 // and the input device with some random unknown type is handled gracefully. | 1288 // and the input device with some random unknown type is handled gracefully. |
1230 AudioDevice active_input; | 1289 AudioDevice active_input; |
1231 EXPECT_EQ(kInternalMic.id, cras_audio_handler_->GetActiveInputNode()); | 1290 EXPECT_EQ(kInternalMic.id, cras_audio_handler_->GetActiveInputNode()); |
1232 EXPECT_TRUE(cras_audio_handler_->has_alternative_input()); | 1291 EXPECT_TRUE(cras_audio_handler_->has_alternative_input()); |
1233 } | 1292 } |
1234 | 1293 |
1235 } // namespace chromeos | 1294 } // namespace chromeos |
OLD | NEW |