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 917 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
928 EXPECT_TRUE(cras_audio_handler_->GetActiveOutputDevice(&active_output)); | 928 EXPECT_TRUE(cras_audio_handler_->GetActiveOutputDevice(&active_output)); |
929 EXPECT_EQ(kHeadphone.id, active_output.id); | 929 EXPECT_EQ(kHeadphone.id, active_output.id); |
930 EXPECT_EQ(kHeadphone.id, cras_audio_handler_->GetActiveOutputNode()); | 930 EXPECT_EQ(kHeadphone.id, cras_audio_handler_->GetActiveOutputNode()); |
931 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); | 931 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
932 for (size_t i = 0; i < audio_devices.size(); ++i) { | 932 for (size_t i = 0; i < audio_devices.size(); ++i) { |
933 if (audio_devices[i].id != kHeadphone.id) | 933 if (audio_devices[i].id != kHeadphone.id) |
934 EXPECT_FALSE(audio_devices[i].active); | 934 EXPECT_FALSE(audio_devices[i].active); |
935 } | 935 } |
936 } | 936 } |
937 | 937 |
| 938 TEST_F(CrasAudioHandlerTest, BluetoothSpeakerIdChangedOnFly) { |
| 939 // Initialize with internal speaker and bluetooth headset. |
| 940 AudioNodeList audio_nodes; |
| 941 audio_nodes.push_back(kInternalSpeaker); |
| 942 audio_nodes.push_back(kBluetoothHeadset); |
| 943 SetUpCrasAudioHandler(audio_nodes); |
| 944 const size_t init_nodes_size = audio_nodes.size(); |
| 945 |
| 946 // Verify the audio devices size. |
| 947 AudioDeviceList audio_devices; |
| 948 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 949 EXPECT_EQ(init_nodes_size, audio_devices.size()); |
| 950 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); |
| 951 |
| 952 // Verify the bluetooth headset is selected as the active output and all other |
| 953 // audio devices are not active. |
| 954 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); |
| 955 AudioDevice active_output; |
| 956 EXPECT_TRUE(cras_audio_handler_->GetActiveOutputDevice(&active_output)); |
| 957 EXPECT_EQ(kBluetoothHeadset.id, active_output.id); |
| 958 EXPECT_EQ(kBluetoothHeadset.id, cras_audio_handler_->GetActiveOutputNode()); |
| 959 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
| 960 |
| 961 // Cras changes the bluetooth headset's id on the fly. |
| 962 audio_nodes.clear(); |
| 963 AudioNode internal_speaker(kInternalSpeaker); |
| 964 internal_speaker.active = false; |
| 965 audio_nodes.push_back(internal_speaker); |
| 966 AudioNode bluetooth_headphone(kBluetoothHeadset); |
| 967 // Change bluetooth headphone id. |
| 968 bluetooth_headphone.id = kBluetoothHeadsetId + 20000; |
| 969 bluetooth_headphone.active = false; |
| 970 audio_nodes.push_back(bluetooth_headphone); |
| 971 ChangeAudioNodes(audio_nodes); |
| 972 |
| 973 // Verify NodesChanged event is fired, and the audio devices size is not |
| 974 // changed. |
| 975 audio_devices.clear(); |
| 976 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 977 EXPECT_EQ(init_nodes_size, audio_devices.size()); |
| 978 EXPECT_EQ(1, test_observer_->audio_nodes_changed_count()); |
| 979 |
| 980 // Verify ActiveOutputNodeChanged event is fired, and active device should be |
| 981 // bluetooth headphone. |
| 982 EXPECT_EQ(1, test_observer_->active_output_node_changed_count()); |
| 983 EXPECT_TRUE(cras_audio_handler_->GetActiveOutputDevice(&active_output)); |
| 984 EXPECT_EQ(bluetooth_headphone.id, active_output.id); |
| 985 } |
| 986 |
938 TEST_F(CrasAudioHandlerTest, PlugUSBMic) { | 987 TEST_F(CrasAudioHandlerTest, PlugUSBMic) { |
939 // Set up initial audio devices, only with internal mic. | 988 // Set up initial audio devices, only with internal mic. |
940 AudioNodeList audio_nodes; | 989 AudioNodeList audio_nodes; |
941 audio_nodes.push_back(kInternalMic); | 990 audio_nodes.push_back(kInternalMic); |
942 SetUpCrasAudioHandler(audio_nodes); | 991 SetUpCrasAudioHandler(audio_nodes); |
943 const size_t init_nodes_size = audio_nodes.size(); | 992 const size_t init_nodes_size = audio_nodes.size(); |
944 | 993 |
945 // Verify the audio devices size. | 994 // Verify the audio devices size. |
946 AudioDeviceList audio_devices; | 995 AudioDeviceList audio_devices; |
947 cras_audio_handler_->GetAudioDevices(&audio_devices); | 996 cras_audio_handler_->GetAudioDevices(&audio_devices); |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1285 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); | 1334 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
1286 | 1335 |
1287 // Ensure the internal microphone has been selected as the active input, | 1336 // Ensure the internal microphone has been selected as the active input, |
1288 // and the input device with some random unknown type is handled gracefully. | 1337 // and the input device with some random unknown type is handled gracefully. |
1289 AudioDevice active_input; | 1338 AudioDevice active_input; |
1290 EXPECT_EQ(kInternalMic.id, cras_audio_handler_->GetActiveInputNode()); | 1339 EXPECT_EQ(kInternalMic.id, cras_audio_handler_->GetActiveInputNode()); |
1291 EXPECT_TRUE(cras_audio_handler_->has_alternative_input()); | 1340 EXPECT_TRUE(cras_audio_handler_->has_alternative_input()); |
1292 } | 1341 } |
1293 | 1342 |
1294 } // namespace chromeos | 1343 } // namespace chromeos |
OLD | NEW |