| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 const uint64_t kMicJackId = 10009; | 37 const uint64_t kMicJackId = 10009; |
| 38 const uint64_t kKeyboardMicId = 10010; | 38 const uint64_t kKeyboardMicId = 10010; |
| 39 const uint64_t kOtherTypeOutputId = 90001; | 39 const uint64_t kOtherTypeOutputId = 90001; |
| 40 const uint64_t kOtherTypeInputId = 90002; | 40 const uint64_t kOtherTypeInputId = 90002; |
| 41 const uint64_t kUSBJabraSpeakerOutputId1 = 90003; | 41 const uint64_t kUSBJabraSpeakerOutputId1 = 90003; |
| 42 const uint64_t kUSBJabraSpeakerOutputId2 = 90004; | 42 const uint64_t kUSBJabraSpeakerOutputId2 = 90004; |
| 43 const uint64_t kUSBJabraSpeakerInputId1 = 90005; | 43 const uint64_t kUSBJabraSpeakerInputId1 = 90005; |
| 44 const uint64_t kUSBJabraSpeakerInputId2 = 90006; | 44 const uint64_t kUSBJabraSpeakerInputId2 = 90006; |
| 45 const uint64_t kUSBCameraInputId = 90007; | 45 const uint64_t kUSBCameraInputId = 90007; |
| 46 | 46 |
| 47 const AudioNode kInternalSpeaker(false, | 47 struct AudioNodeInfo { |
| 48 kInternalSpeakerId, | 48 bool is_input; |
| 49 kInternalSpeakerId, | 49 uint64_t id; |
| 50 "Fake Speaker", | 50 const char* const device_name; |
| 51 "INTERNAL_SPEAKER", | 51 const char* const type; |
| 52 "Speaker", | 52 const char* const name; |
| 53 false, | 53 }; |
| 54 0); | |
| 55 | 54 |
| 56 const AudioNode kHeadphone(false, | 55 const AudioNodeInfo kInternalSpeaker[] = { |
| 57 kHeadphoneId, | 56 {false, kInternalSpeakerId, "Fake Speaker", "INTERNAL_SPEAKER", "Speaker"}}; |
| 58 kHeadphoneId, | |
| 59 "Fake Headphone", | |
| 60 "HEADPHONE", | |
| 61 "Headphone", | |
| 62 false, | |
| 63 0); | |
| 64 | 57 |
| 65 const AudioNode kInternalMic(true, | 58 const AudioNodeInfo kHeadphone[] = { |
| 66 kInternalMicId, | 59 {false, kHeadphoneId, "Fake Headphone", "HEADPHONE", "Headphone"}}; |
| 67 kInternalMicId, | |
| 68 "Fake Mic", | |
| 69 "INTERNAL_MIC", | |
| 70 "Internal Mic", | |
| 71 false, | |
| 72 0); | |
| 73 | 60 |
| 74 const AudioNode kMicJack(true, | 61 const AudioNodeInfo kInternalMic[] = { |
| 75 kMicJackId, | 62 {true, kInternalMicId, "Fake Mic", "INTERNAL_MIC", "Internal Mic"}}; |
| 76 kMicJackId, | |
| 77 "Fake Mic Jack", | |
| 78 "MIC", | |
| 79 "Mic Jack", | |
| 80 false, | |
| 81 0); | |
| 82 | 63 |
| 83 const AudioNode kUSBMic(true, | 64 const AudioNodeInfo kMicJack[] = { |
| 84 kUSBMicId, | 65 {true, kMicJackId, "Fake Mic Jack", "MIC", "Mic Jack"}}; |
| 85 kUSBMicId, | |
| 86 "Fake USB Mic", | |
| 87 "USB", | |
| 88 "USB Microphone", | |
| 89 false, | |
| 90 0); | |
| 91 | 66 |
| 92 const AudioNode kKeyboardMic(true, | 67 const AudioNodeInfo kUSBMic[] = { |
| 93 kKeyboardMicId, | 68 {true, kUSBMicId, "Fake USB Mic", "USB", "USB Microphone"}}; |
| 94 kKeyboardMicId, | |
| 95 "Fake Keyboard Mic", | |
| 96 "KEYBOARD_MIC", | |
| 97 "Keyboard Mic", | |
| 98 false, | |
| 99 0); | |
| 100 | 69 |
| 101 const AudioNode kOtherTypeOutput(false, | 70 const AudioNodeInfo kKeyboardMic[] = {{true, kKeyboardMicId, |
| 102 kOtherTypeOutputId, | 71 "Fake Keyboard Mic", "KEYBOARD_MIC", |
| 103 kOtherTypeOutputId, | 72 "Keyboard Mic"}}; |
| 104 "Output Device", | |
| 105 "SOME_OTHER_TYPE", | |
| 106 "Other Type Output Device", | |
| 107 false, | |
| 108 0); | |
| 109 | 73 |
| 110 const AudioNode kOtherTypeInput(true, | 74 const AudioNodeInfo kOtherTypeOutput[] = {{false, kOtherTypeOutputId, |
| 111 kOtherTypeInputId, | 75 "Output Device", "SOME_OTHER_TYPE", |
| 112 kOtherTypeInputId, | 76 "Other Type Output Device"}}; |
| 113 "Input Device", | |
| 114 "SOME_OTHER_TYPE", | |
| 115 "Other Type Input Device", | |
| 116 false, | |
| 117 0); | |
| 118 | 77 |
| 119 const AudioNode kBluetoothHeadset(false, | 78 const AudioNodeInfo kOtherTypeInput[] = {{true, kOtherTypeInputId, |
| 120 kBluetoothHeadsetId, | 79 "Input Device", "SOME_OTHER_TYPE", |
| 121 kBluetoothHeadsetId, | 80 "Other Type Input Device"}}; |
| 122 "Bluetooth Headset", | |
| 123 "BLUETOOTH", | |
| 124 "Bluetooth Headset 1", | |
| 125 false, | |
| 126 0); | |
| 127 | 81 |
| 128 const AudioNode kHDMIOutput(false, | 82 const AudioNodeInfo kBluetoothHeadset[] = {{false, kBluetoothHeadsetId, |
| 129 kHDMIOutputId, | 83 "Bluetooth Headset", "BLUETOOTH", |
| 130 kHDMIOutputId, | 84 "Bluetooth Headset 1"}}; |
| 131 "HDMI output", | |
| 132 "HDMI", | |
| 133 "HDMI output", | |
| 134 false, | |
| 135 0); | |
| 136 | 85 |
| 137 const AudioNode kUSBHeadphone1(false, | 86 const AudioNodeInfo kHDMIOutput[] = { |
| 138 kUSBHeadphoneId1, | 87 {false, kHDMIOutputId, "HDMI output", "HDMI", "HDMI output"}}; |
| 139 kUSBHeadphoneId1, | |
| 140 "USB Headphone", | |
| 141 "USB", | |
| 142 "USB Headphone 1", | |
| 143 false, | |
| 144 0); | |
| 145 | 88 |
| 146 const AudioNode kUSBHeadphone2(false, | 89 const AudioNodeInfo kUSBHeadphone1[] = { |
| 147 kUSBHeadphoneId2, | 90 {false, kUSBHeadphoneId1, "USB Headphone", "USB", "USB Headphone 1"}}; |
| 148 kUSBHeadphoneId2, | |
| 149 "USB Headphone", | |
| 150 "USB", | |
| 151 "USB Headphone 1", | |
| 152 false, | |
| 153 0); | |
| 154 | 91 |
| 155 const AudioNode kUSBJabraSpeakerOutput1(false, | 92 const AudioNodeInfo kUSBHeadphone2[] = { |
| 156 kUSBJabraSpeakerOutputId1, | 93 {false, kUSBHeadphoneId2, "USB Headphone", "USB", "USB Headphone 1"}}; |
| 157 kUSBJabraSpeakerOutputId1, | |
| 158 "Jabra Speaker 1", | |
| 159 "USB", | |
| 160 "Jabra Speaker 1", | |
| 161 false, | |
| 162 0); | |
| 163 | 94 |
| 164 const AudioNode kUSBJabraSpeakerOutput2(false, | 95 const AudioNodeInfo kUSBJabraSpeakerOutput1[] = { |
| 165 kUSBJabraSpeakerOutputId2, | 96 {false, kUSBJabraSpeakerOutputId1, "Jabra Speaker 1", "USB", |
| 166 kUSBJabraSpeakerOutputId2, | 97 "Jabra Speaker 1"}}; |
| 167 "Jabra Speaker 2", | |
| 168 "USB", | |
| 169 "Jabra Speaker 2", | |
| 170 false, | |
| 171 0); | |
| 172 | 98 |
| 173 const AudioNode kUSBJabraSpeakerInput1(true, | 99 const AudioNodeInfo kUSBJabraSpeakerOutput2[] = { |
| 174 kUSBJabraSpeakerInputId1, | 100 {false, kUSBJabraSpeakerOutputId2, "Jabra Speaker 2", "USB", |
| 175 kUSBJabraSpeakerInputId1, | 101 "Jabra Speaker 2"}}; |
| 176 "Jabra Speaker 1", | |
| 177 "USB", | |
| 178 "Jabra Speaker", | |
| 179 false, | |
| 180 0); | |
| 181 | 102 |
| 182 const AudioNode kUSBJabraSpeakerInput2(true, | 103 const AudioNodeInfo kUSBJabraSpeakerInput1[] = {{true, kUSBJabraSpeakerInputId1, |
| 183 kUSBJabraSpeakerInputId2, | 104 "Jabra Speaker 1", "USB", |
| 184 kUSBJabraSpeakerInputId2, | 105 "Jabra Speaker"}}; |
| 185 "Jabra Speaker 2", | |
| 186 "USB", | |
| 187 "Jabra Speaker 2", | |
| 188 false, | |
| 189 0); | |
| 190 | 106 |
| 191 const AudioNode kUSBCameraInput(true, | 107 const AudioNodeInfo kUSBJabraSpeakerInput2[] = {{true, kUSBJabraSpeakerInputId2, |
| 192 kUSBCameraInputId, | 108 "Jabra Speaker 2", "USB", |
| 193 kUSBCameraInputId, | 109 "Jabra Speaker 2"}}; |
| 194 "USB Camera", | 110 |
| 195 "USB", | 111 const AudioNodeInfo kUSBCameraInput[] = { |
| 196 "USB Camera", | 112 {true, kUSBCameraInputId, "USB Camera", "USB", "USB Camera"}}; |
| 197 false, | |
| 198 0); | |
| 199 | 113 |
| 200 class TestObserver : public chromeos::CrasAudioHandler::AudioObserver { | 114 class TestObserver : public chromeos::CrasAudioHandler::AudioObserver { |
| 201 public: | 115 public: |
| 202 TestObserver() | 116 TestObserver() {} |
| 203 : active_output_node_changed_count_(0), | |
| 204 active_input_node_changed_count_(0), | |
| 205 audio_nodes_changed_count_(0), | |
| 206 output_mute_changed_count_(0), | |
| 207 input_mute_changed_count_(0), | |
| 208 output_volume_changed_count_(0), | |
| 209 input_gain_changed_count_(0), | |
| 210 output_mute_by_system_(false), | |
| 211 output_channel_remixing_changed_count_(0) {} | |
| 212 | 117 |
| 213 int active_output_node_changed_count() const { | 118 int active_output_node_changed_count() const { |
| 214 return active_output_node_changed_count_; | 119 return active_output_node_changed_count_; |
| 215 } | 120 } |
| 216 | 121 |
| 217 void reset_active_output_node_changed_count() { | 122 void reset_active_output_node_changed_count() { |
| 218 active_output_node_changed_count_ = 0; | 123 active_output_node_changed_count_ = 0; |
| 219 } | 124 } |
| 220 | 125 |
| 221 int active_input_node_changed_count() const { | 126 int active_input_node_changed_count() const { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 | 191 |
| 287 void OnInputNodeGainChanged(uint64_t /* node_id */, int /* gain */) override { | 192 void OnInputNodeGainChanged(uint64_t /* node_id */, int /* gain */) override { |
| 288 ++input_gain_changed_count_; | 193 ++input_gain_changed_count_; |
| 289 } | 194 } |
| 290 | 195 |
| 291 void OnOuputChannelRemixingChanged(bool /* mono_on */) override { | 196 void OnOuputChannelRemixingChanged(bool /* mono_on */) override { |
| 292 ++output_channel_remixing_changed_count_; | 197 ++output_channel_remixing_changed_count_; |
| 293 } | 198 } |
| 294 | 199 |
| 295 private: | 200 private: |
| 296 int active_output_node_changed_count_; | 201 int active_output_node_changed_count_ = 0; |
| 297 int active_input_node_changed_count_; | 202 int active_input_node_changed_count_ = 0; |
| 298 int audio_nodes_changed_count_; | 203 int audio_nodes_changed_count_ = 0; |
| 299 int output_mute_changed_count_; | 204 int output_mute_changed_count_ = 0; |
| 300 int input_mute_changed_count_; | 205 int input_mute_changed_count_ = 0; |
| 301 int output_volume_changed_count_; | 206 int output_volume_changed_count_ = 0; |
| 302 int input_gain_changed_count_; | 207 int input_gain_changed_count_ = 0; |
| 303 bool output_mute_by_system_; // output mute state adjusted by system. | 208 bool output_mute_by_system_ = false; // output mute state adjusted by system. |
| 304 int output_channel_remixing_changed_count_; | 209 int output_channel_remixing_changed_count_ = 0; |
| 305 | 210 |
| 306 DISALLOW_COPY_AND_ASSIGN(TestObserver); | 211 DISALLOW_COPY_AND_ASSIGN(TestObserver); |
| 307 }; | 212 }; |
| 308 | 213 |
| 309 } // namespace | 214 } // namespace |
| 310 | 215 |
| 311 class CrasAudioHandlerTest : public testing::Test { | 216 // Test param is the version of stabel device id used by audio node. |
| 217 class CrasAudioHandlerTest : public testing::TestWithParam<int> { |
| 312 public: | 218 public: |
| 313 CrasAudioHandlerTest() : cras_audio_handler_(NULL), | 219 CrasAudioHandlerTest() {} |
| 314 fake_cras_audio_client_(NULL) { | |
| 315 } | |
| 316 ~CrasAudioHandlerTest() override {} | 220 ~CrasAudioHandlerTest() override {} |
| 317 | 221 |
| 318 void SetUp() override {} | 222 void SetUp() override {} |
| 319 | 223 |
| 320 void TearDown() override { | 224 void TearDown() override { |
| 321 cras_audio_handler_->RemoveAudioObserver(test_observer_.get()); | 225 cras_audio_handler_->RemoveAudioObserver(test_observer_.get()); |
| 322 test_observer_.reset(); | 226 test_observer_.reset(); |
| 323 CrasAudioHandler::Shutdown(); | 227 CrasAudioHandler::Shutdown(); |
| 324 audio_pref_handler_ = NULL; | 228 audio_pref_handler_ = nullptr; |
| 325 DBusThreadManager::Shutdown(); | 229 DBusThreadManager::Shutdown(); |
| 326 } | 230 } |
| 327 | 231 |
| 232 AudioNode GenerateAudioNode(const AudioNodeInfo* node_info) { |
| 233 uint64_t stable_device_id_v2 = GetParam() == 1 ? 0 : (node_info->id ^ 0xFF); |
| 234 uint64_t stable_device_id_v1 = node_info->id; |
| 235 return AudioNode(node_info->is_input, node_info->id, GetParam() == 2, |
| 236 stable_device_id_v1, stable_device_id_v2, |
| 237 node_info->device_name, node_info->type, node_info->name, |
| 238 false /* is_active*/, 0 /* pluged_time */); |
| 239 } |
| 240 |
| 241 AudioNodeList GenerateAudioNodeList( |
| 242 const std::vector<const AudioNodeInfo*> nodes) { |
| 243 AudioNodeList node_list; |
| 244 for (auto node_info : nodes) { |
| 245 node_list.push_back(GenerateAudioNode(node_info)); |
| 246 } |
| 247 return node_list; |
| 248 } |
| 249 |
| 328 void SetUpCrasAudioHandler(const AudioNodeList& audio_nodes) { | 250 void SetUpCrasAudioHandler(const AudioNodeList& audio_nodes) { |
| 329 DBusThreadManager::Initialize(); | 251 DBusThreadManager::Initialize(); |
| 330 fake_cras_audio_client_ = static_cast<FakeCrasAudioClient*>( | 252 fake_cras_audio_client_ = static_cast<FakeCrasAudioClient*>( |
| 331 DBusThreadManager::Get()->GetCrasAudioClient()); | 253 DBusThreadManager::Get()->GetCrasAudioClient()); |
| 332 fake_cras_audio_client_->SetAudioNodesForTesting(audio_nodes); | 254 fake_cras_audio_client_->SetAudioNodesForTesting(audio_nodes); |
| 333 audio_pref_handler_ = new AudioDevicesPrefHandlerStub(); | 255 audio_pref_handler_ = new AudioDevicesPrefHandlerStub(); |
| 334 CrasAudioHandler::Initialize(audio_pref_handler_); | 256 CrasAudioHandler::Initialize(audio_pref_handler_); |
| 335 cras_audio_handler_ = CrasAudioHandler::Get(); | 257 cras_audio_handler_ = CrasAudioHandler::Get(); |
| 336 test_observer_.reset(new TestObserver); | 258 test_observer_.reset(new TestObserver); |
| 337 cras_audio_handler_->AddAudioObserver(test_observer_.get()); | 259 cras_audio_handler_->AddAudioObserver(test_observer_.get()); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 return cras_audio_handler_->hdmi_rediscovering(); | 343 return cras_audio_handler_->hdmi_rediscovering(); |
| 422 } | 344 } |
| 423 | 345 |
| 424 void RestartAudioClient() { | 346 void RestartAudioClient() { |
| 425 cras_audio_handler_->AudioClientRestarted(); | 347 cras_audio_handler_->AudioClientRestarted(); |
| 426 base::RunLoop().RunUntilIdle(); | 348 base::RunLoop().RunUntilIdle(); |
| 427 } | 349 } |
| 428 | 350 |
| 429 protected: | 351 protected: |
| 430 base::MessageLoopForUI message_loop_; | 352 base::MessageLoopForUI message_loop_; |
| 431 CrasAudioHandler* cras_audio_handler_; // Not owned. | 353 CrasAudioHandler* cras_audio_handler_ = nullptr; // Not owned. |
| 432 FakeCrasAudioClient* fake_cras_audio_client_; // Not owned. | 354 FakeCrasAudioClient* fake_cras_audio_client_ = nullptr; // Not owned. |
| 433 std::unique_ptr<TestObserver> test_observer_; | 355 std::unique_ptr<TestObserver> test_observer_; |
| 434 scoped_refptr<AudioDevicesPrefHandlerStub> audio_pref_handler_; | 356 scoped_refptr<AudioDevicesPrefHandlerStub> audio_pref_handler_; |
| 435 | 357 |
| 436 private: | 358 private: |
| 437 DISALLOW_COPY_AND_ASSIGN(CrasAudioHandlerTest); | 359 DISALLOW_COPY_AND_ASSIGN(CrasAudioHandlerTest); |
| 438 }; | 360 }; |
| 439 | 361 |
| 440 class HDMIRediscoverWaiter { | 362 class HDMIRediscoverWaiter { |
| 441 public: | 363 public: |
| 442 HDMIRediscoverWaiter(CrasAudioHandlerTest* cras_audio_handler_test, | 364 HDMIRediscoverWaiter(CrasAudioHandlerTest* cras_audio_handler_test, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 470 run_loop.Run(); | 392 run_loop.Run(); |
| 471 } | 393 } |
| 472 | 394 |
| 473 private: | 395 private: |
| 474 CrasAudioHandlerTest* cras_audio_handler_test_; // not owned | 396 CrasAudioHandlerTest* cras_audio_handler_test_; // not owned |
| 475 int grace_period_duration_in_ms_; | 397 int grace_period_duration_in_ms_; |
| 476 | 398 |
| 477 DISALLOW_COPY_AND_ASSIGN(HDMIRediscoverWaiter); | 399 DISALLOW_COPY_AND_ASSIGN(HDMIRediscoverWaiter); |
| 478 }; | 400 }; |
| 479 | 401 |
| 480 TEST_F(CrasAudioHandlerTest, InitializeWithOnlyDefaultAudioDevices) { | 402 INSTANTIATE_TEST_CASE_P(StableIdV1, CrasAudioHandlerTest, testing::Values(1)); |
| 481 AudioNodeList audio_nodes; | 403 INSTANTIATE_TEST_CASE_P(StabelIdV2, CrasAudioHandlerTest, testing::Values(2)); |
| 482 audio_nodes.push_back(kInternalSpeaker); | 404 |
| 483 audio_nodes.push_back(kInternalMic); | 405 TEST_P(CrasAudioHandlerTest, InitializeWithOnlyDefaultAudioDevices) { |
| 406 AudioNodeList audio_nodes = |
| 407 GenerateAudioNodeList({kInternalSpeaker, kInternalMic}); |
| 484 SetUpCrasAudioHandler(audio_nodes); | 408 SetUpCrasAudioHandler(audio_nodes); |
| 485 | 409 |
| 486 // Verify the audio devices size. | 410 // Verify the audio devices size. |
| 487 AudioDeviceList audio_devices; | 411 AudioDeviceList audio_devices; |
| 488 cras_audio_handler_->GetAudioDevices(&audio_devices); | 412 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 489 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); | 413 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); |
| 490 | 414 |
| 491 // Verify the internal speaker has been selected as the active output. | 415 // Verify the internal speaker has been selected as the active output. |
| 492 AudioDevice active_output; | 416 AudioDevice active_output; |
| 493 EXPECT_TRUE( | 417 EXPECT_TRUE( |
| 494 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); | 418 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
| 495 EXPECT_EQ(kInternalSpeaker.id, active_output.id); | 419 EXPECT_EQ(kInternalSpeaker->id, active_output.id); |
| 496 EXPECT_EQ(kInternalSpeaker.id, | 420 EXPECT_EQ(kInternalSpeaker->id, |
| 497 cras_audio_handler_->GetPrimaryActiveOutputNode()); | 421 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 498 EXPECT_FALSE(cras_audio_handler_->has_alternative_output()); | 422 EXPECT_FALSE(cras_audio_handler_->has_alternative_output()); |
| 499 | 423 |
| 500 // Ensure the internal microphone has been selected as the active input. | 424 // Ensure the internal microphone has been selected as the active input. |
| 501 AudioDevice active_input; | 425 AudioDevice active_input; |
| 502 EXPECT_EQ(kInternalMic.id, cras_audio_handler_->GetPrimaryActiveInputNode()); | 426 EXPECT_EQ(kInternalMic->id, cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 503 EXPECT_FALSE(cras_audio_handler_->has_alternative_input()); | 427 EXPECT_FALSE(cras_audio_handler_->has_alternative_input()); |
| 504 } | 428 } |
| 505 | 429 |
| 506 TEST_F(CrasAudioHandlerTest, InitializeWithAlternativeAudioDevices) { | 430 TEST_P(CrasAudioHandlerTest, InitializeWithAlternativeAudioDevices) { |
| 507 AudioNodeList audio_nodes; | 431 AudioNodeList audio_nodes = GenerateAudioNodeList( |
| 508 audio_nodes.push_back(kInternalSpeaker); | 432 {kInternalSpeaker, kHeadphone, kInternalMic, kUSBMic}); |
| 509 audio_nodes.push_back(kHeadphone); | |
| 510 audio_nodes.push_back(kInternalMic); | |
| 511 audio_nodes.push_back(kUSBMic); | |
| 512 SetUpCrasAudioHandler(audio_nodes); | 433 SetUpCrasAudioHandler(audio_nodes); |
| 513 | 434 |
| 514 // Verify the audio devices size. | 435 // Verify the audio devices size. |
| 515 AudioDeviceList audio_devices; | 436 AudioDeviceList audio_devices; |
| 516 cras_audio_handler_->GetAudioDevices(&audio_devices); | 437 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 517 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); | 438 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); |
| 518 | 439 |
| 519 // Verify the headphone has been selected as the active output. | 440 // Verify the headphone has been selected as the active output. |
| 520 AudioDevice active_output; | 441 AudioDevice active_output; |
| 521 EXPECT_TRUE( | 442 EXPECT_TRUE( |
| 522 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); | 443 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
| 523 EXPECT_EQ(kHeadphone.id, active_output.id); | 444 EXPECT_EQ(kHeadphone->id, active_output.id); |
| 524 EXPECT_EQ(kHeadphone.id, cras_audio_handler_->GetPrimaryActiveOutputNode()); | 445 EXPECT_EQ(kHeadphone->id, cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 525 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); | 446 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
| 526 | 447 |
| 527 // Ensure the USB microphone has been selected as the active input. | 448 // Ensure the USB microphone has been selected as the active input. |
| 528 EXPECT_EQ(kUSBMicId, cras_audio_handler_->GetPrimaryActiveInputNode()); | 449 EXPECT_EQ(kUSBMicId, cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 529 EXPECT_TRUE(cras_audio_handler_->has_alternative_input()); | 450 EXPECT_TRUE(cras_audio_handler_->has_alternative_input()); |
| 530 } | 451 } |
| 531 | 452 |
| 532 TEST_F(CrasAudioHandlerTest, InitializeWithKeyboardMic) { | 453 TEST_P(CrasAudioHandlerTest, InitializeWithKeyboardMic) { |
| 533 AudioNodeList audio_nodes; | 454 AudioNodeList audio_nodes = |
| 534 audio_nodes.push_back(kInternalSpeaker); | 455 GenerateAudioNodeList({kInternalSpeaker, kInternalMic, kKeyboardMic}); |
| 535 audio_nodes.push_back(kInternalMic); | |
| 536 audio_nodes.push_back(kKeyboardMic); | |
| 537 SetUpCrasAudioHandler(audio_nodes); | 456 SetUpCrasAudioHandler(audio_nodes); |
| 538 | 457 |
| 539 // Verify the audio devices size. | 458 // Verify the audio devices size. |
| 540 AudioDeviceList audio_devices; | 459 AudioDeviceList audio_devices; |
| 541 cras_audio_handler_->GetAudioDevices(&audio_devices); | 460 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 542 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); | 461 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); |
| 543 EXPECT_TRUE(cras_audio_handler_->HasKeyboardMic()); | 462 EXPECT_TRUE(cras_audio_handler_->HasKeyboardMic()); |
| 544 | 463 |
| 545 // Verify the internal speaker has been selected as the active output. | 464 // Verify the internal speaker has been selected as the active output. |
| 546 AudioDevice active_output; | 465 AudioDevice active_output; |
| 547 EXPECT_TRUE( | 466 EXPECT_TRUE( |
| 548 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); | 467 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
| 549 EXPECT_EQ(kInternalSpeaker.id, active_output.id); | 468 EXPECT_EQ(kInternalSpeaker->id, active_output.id); |
| 550 EXPECT_EQ(kInternalSpeaker.id, | 469 EXPECT_EQ(kInternalSpeaker->id, |
| 551 cras_audio_handler_->GetPrimaryActiveOutputNode()); | 470 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 552 EXPECT_FALSE(cras_audio_handler_->has_alternative_output()); | 471 EXPECT_FALSE(cras_audio_handler_->has_alternative_output()); |
| 553 | 472 |
| 554 // Ensure the internal microphone has been selected as the active input, | 473 // Ensure the internal microphone has been selected as the active input, |
| 555 // not affected by keyboard mic. | 474 // not affected by keyboard mic. |
| 556 AudioDevice active_input; | 475 AudioDevice active_input; |
| 557 EXPECT_EQ(kInternalMic.id, cras_audio_handler_->GetPrimaryActiveInputNode()); | 476 EXPECT_EQ(kInternalMic->id, cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 558 EXPECT_FALSE(cras_audio_handler_->has_alternative_input()); | 477 EXPECT_FALSE(cras_audio_handler_->has_alternative_input()); |
| 559 const AudioDevice* keyboard_mic = GetDeviceFromId(kKeyboardMic.id); | 478 const AudioDevice* keyboard_mic = GetDeviceFromId(kKeyboardMic->id); |
| 560 EXPECT_FALSE(keyboard_mic->active); | 479 EXPECT_FALSE(keyboard_mic->active); |
| 561 } | 480 } |
| 562 | 481 |
| 563 TEST_F(CrasAudioHandlerTest, SetKeyboardMicActive) { | 482 TEST_P(CrasAudioHandlerTest, SetKeyboardMicActive) { |
| 564 AudioNodeList audio_nodes; | 483 AudioNodeList audio_nodes = |
| 565 audio_nodes.push_back(kInternalMic); | 484 GenerateAudioNodeList({kInternalMic, kKeyboardMic}); |
| 566 audio_nodes.push_back(kKeyboardMic); | |
| 567 SetUpCrasAudioHandler(audio_nodes); | 485 SetUpCrasAudioHandler(audio_nodes); |
| 568 | 486 |
| 569 // Verify the audio devices size. | 487 // Verify the audio devices size. |
| 570 AudioDeviceList audio_devices; | 488 AudioDeviceList audio_devices; |
| 571 cras_audio_handler_->GetAudioDevices(&audio_devices); | 489 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 572 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); | 490 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); |
| 573 EXPECT_TRUE(cras_audio_handler_->HasKeyboardMic()); | 491 EXPECT_TRUE(cras_audio_handler_->HasKeyboardMic()); |
| 574 | 492 |
| 575 // Ensure the internal microphone has been selected as the active input, | 493 // Ensure the internal microphone has been selected as the active input, |
| 576 // not affected by keyboard mic. | 494 // not affected by keyboard mic. |
| 577 AudioDevice active_input; | 495 AudioDevice active_input; |
| 578 EXPECT_EQ(kInternalMic.id, cras_audio_handler_->GetPrimaryActiveInputNode()); | 496 EXPECT_EQ(kInternalMic->id, cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 579 EXPECT_FALSE(cras_audio_handler_->has_alternative_input()); | 497 EXPECT_FALSE(cras_audio_handler_->has_alternative_input()); |
| 580 const AudioDevice* keyboard_mic = GetDeviceFromId(kKeyboardMic.id); | 498 const AudioDevice* keyboard_mic = GetDeviceFromId(kKeyboardMic->id); |
| 581 EXPECT_FALSE(keyboard_mic->active); | 499 EXPECT_FALSE(keyboard_mic->active); |
| 582 | 500 |
| 583 // Make keyboard mic active. | 501 // Make keyboard mic active. |
| 584 cras_audio_handler_->SetKeyboardMicActive(true); | 502 cras_audio_handler_->SetKeyboardMicActive(true); |
| 585 EXPECT_EQ(kInternalMic.id, cras_audio_handler_->GetPrimaryActiveInputNode()); | 503 EXPECT_EQ(kInternalMic->id, cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 586 const AudioDevice* active_keyboard_mic = GetDeviceFromId(kKeyboardMic.id); | 504 const AudioDevice* active_keyboard_mic = GetDeviceFromId(kKeyboardMic->id); |
| 587 EXPECT_TRUE(active_keyboard_mic->active); | 505 EXPECT_TRUE(active_keyboard_mic->active); |
| 588 | 506 |
| 589 // Make keyboard mic inactive. | 507 // Make keyboard mic inactive. |
| 590 cras_audio_handler_->SetKeyboardMicActive(false); | 508 cras_audio_handler_->SetKeyboardMicActive(false); |
| 591 EXPECT_EQ(kInternalMic.id, cras_audio_handler_->GetPrimaryActiveInputNode()); | 509 EXPECT_EQ(kInternalMic->id, cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 592 const AudioDevice* inactive_keyboard_mic = GetDeviceFromId(kKeyboardMic.id); | 510 const AudioDevice* inactive_keyboard_mic = GetDeviceFromId(kKeyboardMic->id); |
| 593 EXPECT_FALSE(inactive_keyboard_mic->active); | 511 EXPECT_FALSE(inactive_keyboard_mic->active); |
| 594 } | 512 } |
| 595 | 513 |
| 596 TEST_F(CrasAudioHandlerTest, KeyboardMicNotSetAsPrimaryActive) { | 514 TEST_P(CrasAudioHandlerTest, KeyboardMicNotSetAsPrimaryActive) { |
| 597 AudioNodeList audio_nodes; | 515 AudioNodeList audio_nodes = GenerateAudioNodeList({kKeyboardMic}); |
| 598 audio_nodes.push_back(kKeyboardMic); | |
| 599 SetUpCrasAudioHandler(audio_nodes); | 516 SetUpCrasAudioHandler(audio_nodes); |
| 600 | 517 |
| 601 // Verify keyboard mic is not set as primary active input. | 518 // Verify keyboard mic is not set as primary active input. |
| 602 AudioDeviceList audio_devices; | 519 AudioDeviceList audio_devices; |
| 603 cras_audio_handler_->GetAudioDevices(&audio_devices); | 520 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 604 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); | 521 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); |
| 605 EXPECT_TRUE(cras_audio_handler_->HasKeyboardMic()); | 522 EXPECT_TRUE(cras_audio_handler_->HasKeyboardMic()); |
| 606 EXPECT_EQ(0u, cras_audio_handler_->GetPrimaryActiveInputNode()); | 523 EXPECT_EQ(0u, cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 607 | 524 |
| 608 // Verify the internal mic is set as primary input. | 525 // Verify the internal mic is set as primary input. |
| 609 audio_nodes.push_back(kInternalMic); | 526 audio_nodes.push_back(GenerateAudioNode(kInternalMic)); |
| 610 ChangeAudioNodes(audio_nodes); | 527 ChangeAudioNodes(audio_nodes); |
| 611 cras_audio_handler_->GetAudioDevices(&audio_devices); | 528 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 612 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); | 529 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); |
| 613 EXPECT_TRUE(cras_audio_handler_->HasKeyboardMic()); | 530 EXPECT_TRUE(cras_audio_handler_->HasKeyboardMic()); |
| 614 EXPECT_EQ(kInternalMic.id, cras_audio_handler_->GetPrimaryActiveInputNode()); | 531 EXPECT_EQ(kInternalMic->id, cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 615 } | 532 } |
| 616 | 533 |
| 617 TEST_F(CrasAudioHandlerTest, SwitchActiveOutputDevice) { | 534 TEST_P(CrasAudioHandlerTest, SwitchActiveOutputDevice) { |
| 618 AudioNodeList audio_nodes; | 535 AudioNodeList audio_nodes = |
| 619 audio_nodes.push_back(kInternalSpeaker); | 536 GenerateAudioNodeList({kInternalSpeaker, kHeadphone}); |
| 620 audio_nodes.push_back(kHeadphone); | |
| 621 SetUpCrasAudioHandler(audio_nodes); | 537 SetUpCrasAudioHandler(audio_nodes); |
| 538 |
| 622 AudioDeviceList audio_devices; | 539 AudioDeviceList audio_devices; |
| 623 cras_audio_handler_->GetAudioDevices(&audio_devices); | 540 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 624 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); | 541 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); |
| 625 | 542 |
| 626 // Verify the initial active output device is headphone. | 543 // Verify the initial active output device is headphone. |
| 627 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); | 544 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); |
| 628 AudioDevice active_output; | 545 AudioDevice active_output; |
| 629 EXPECT_TRUE( | 546 EXPECT_TRUE( |
| 630 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); | 547 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
| 631 EXPECT_EQ(kHeadphone.id, active_output.id); | 548 EXPECT_EQ(kHeadphone->id, active_output.id); |
| 632 EXPECT_EQ(kHeadphone.id, cras_audio_handler_->GetPrimaryActiveOutputNode()); | 549 EXPECT_EQ(kHeadphone->id, cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 633 | 550 |
| 634 // Switch the active output to internal speaker. | 551 // Switch the active output to internal speaker. |
| 635 AudioDevice internal_speaker(kInternalSpeaker); | 552 AudioDevice internal_speaker(GenerateAudioNode(kInternalSpeaker)); |
| 636 cras_audio_handler_->SwitchToDevice(internal_speaker, true, | 553 cras_audio_handler_->SwitchToDevice(internal_speaker, true, |
| 637 CrasAudioHandler::ACTIVATE_BY_USER); | 554 CrasAudioHandler::ACTIVATE_BY_USER); |
| 638 | 555 |
| 639 // Verify the active output is switched to internal speaker, and the | 556 // Verify the active output is switched to internal speaker, and the |
| 640 // ActiveOutputNodeChanged event is fired. | 557 // ActiveOutputNodeChanged event is fired. |
| 641 EXPECT_EQ(1, test_observer_->active_output_node_changed_count()); | 558 EXPECT_EQ(1, test_observer_->active_output_node_changed_count()); |
| 642 EXPECT_TRUE( | 559 EXPECT_TRUE( |
| 643 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); | 560 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
| 644 EXPECT_EQ(kInternalSpeaker.id, active_output.id); | 561 EXPECT_EQ(kInternalSpeaker->id, active_output.id); |
| 645 EXPECT_EQ(kInternalSpeaker.id, | 562 EXPECT_EQ(kInternalSpeaker->id, |
| 646 cras_audio_handler_->GetPrimaryActiveOutputNode()); | 563 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 647 } | 564 } |
| 648 | 565 |
| 649 TEST_F(CrasAudioHandlerTest, SwitchActiveInputDevice) { | 566 TEST_P(CrasAudioHandlerTest, SwitchActiveInputDevice) { |
| 650 AudioNodeList audio_nodes; | 567 AudioNodeList audio_nodes = GenerateAudioNodeList({kInternalMic, kUSBMic}); |
| 651 audio_nodes.push_back(kInternalMic); | |
| 652 audio_nodes.push_back(kUSBMic); | |
| 653 SetUpCrasAudioHandler(audio_nodes); | 568 SetUpCrasAudioHandler(audio_nodes); |
| 569 |
| 654 AudioDeviceList audio_devices; | 570 AudioDeviceList audio_devices; |
| 655 cras_audio_handler_->GetAudioDevices(&audio_devices); | 571 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 656 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); | 572 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); |
| 657 | 573 |
| 658 // Verify the initial active input device is USB mic. | 574 // Verify the initial active input device is USB mic. |
| 659 EXPECT_EQ(0, test_observer_->active_input_node_changed_count()); | 575 EXPECT_EQ(0, test_observer_->active_input_node_changed_count()); |
| 660 EXPECT_EQ(kUSBMicId, cras_audio_handler_->GetPrimaryActiveInputNode()); | 576 EXPECT_EQ(kUSBMicId, cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 661 | 577 |
| 662 // Switch the active input to internal mic. | 578 // Switch the active input to internal mic. |
| 663 AudioDevice internal_mic(kInternalMic); | 579 AudioDevice internal_mic(GenerateAudioNode(kInternalMic)); |
| 664 cras_audio_handler_->SwitchToDevice(internal_mic, true, | 580 cras_audio_handler_->SwitchToDevice(internal_mic, true, |
| 665 CrasAudioHandler::ACTIVATE_BY_USER); | 581 CrasAudioHandler::ACTIVATE_BY_USER); |
| 666 | 582 |
| 667 // Verify the active output is switched to internal speaker, and the active | 583 // Verify the active output is switched to internal speaker, and the active |
| 668 // ActiveInputNodeChanged event is fired. | 584 // ActiveInputNodeChanged event is fired. |
| 669 EXPECT_EQ(1, test_observer_->active_input_node_changed_count()); | 585 EXPECT_EQ(1, test_observer_->active_input_node_changed_count()); |
| 670 EXPECT_EQ(kInternalMic.id, cras_audio_handler_->GetPrimaryActiveInputNode()); | 586 EXPECT_EQ(kInternalMic->id, cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 671 } | 587 } |
| 672 | 588 |
| 673 TEST_F(CrasAudioHandlerTest, PlugHeadphone) { | 589 TEST_P(CrasAudioHandlerTest, PlugHeadphone) { |
| 674 // Set up initial audio devices, only with internal speaker. | 590 // Set up initial audio devices, only with internal speaker. |
| 675 AudioNodeList audio_nodes; | 591 AudioNodeList audio_nodes = GenerateAudioNodeList({kInternalSpeaker}); |
| 676 audio_nodes.push_back(kInternalSpeaker); | |
| 677 SetUpCrasAudioHandler(audio_nodes); | 592 SetUpCrasAudioHandler(audio_nodes); |
| 678 const size_t init_nodes_size = audio_nodes.size(); | 593 const size_t init_nodes_size = audio_nodes.size(); |
| 679 | 594 |
| 680 // Verify the audio devices size. | 595 // Verify the audio devices size. |
| 681 AudioDeviceList audio_devices; | 596 AudioDeviceList audio_devices; |
| 682 cras_audio_handler_->GetAudioDevices(&audio_devices); | 597 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 683 EXPECT_EQ(init_nodes_size, audio_devices.size()); | 598 EXPECT_EQ(init_nodes_size, audio_devices.size()); |
| 684 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); | 599 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); |
| 685 | 600 |
| 686 // Verify the internal speaker has been selected as the active output. | 601 // Verify the internal speaker has been selected as the active output. |
| 687 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); | 602 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); |
| 688 AudioDevice active_output; | 603 AudioDevice active_output; |
| 689 EXPECT_TRUE( | 604 EXPECT_TRUE( |
| 690 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); | 605 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
| 691 EXPECT_EQ(kInternalSpeaker.id, active_output.id); | 606 EXPECT_EQ(kInternalSpeaker->id, active_output.id); |
| 692 EXPECT_EQ(kInternalSpeaker.id, | 607 EXPECT_EQ(kInternalSpeaker->id, |
| 693 cras_audio_handler_->GetPrimaryActiveOutputNode()); | 608 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 694 EXPECT_FALSE(cras_audio_handler_->has_alternative_output()); | 609 EXPECT_FALSE(cras_audio_handler_->has_alternative_output()); |
| 695 | 610 |
| 696 // Plug the headphone. | 611 // Plug the headphone. |
| 697 audio_nodes.clear(); | 612 audio_nodes.clear(); |
| 698 AudioNode internal_speaker(kInternalSpeaker); | 613 AudioNode internal_speaker = GenerateAudioNode(kInternalSpeaker); |
| 699 internal_speaker.active = true; | 614 internal_speaker.active = true; |
| 700 audio_nodes.push_back(internal_speaker); | 615 audio_nodes.push_back(internal_speaker); |
| 701 audio_nodes.push_back(kHeadphone); | 616 audio_nodes.push_back(GenerateAudioNode(kHeadphone)); |
| 702 ChangeAudioNodes(audio_nodes); | 617 ChangeAudioNodes(audio_nodes); |
| 703 | 618 |
| 704 // Verify the AudioNodesChanged event is fired and new audio device is added. | 619 // Verify the AudioNodesChanged event is fired and new audio device is added. |
| 705 EXPECT_EQ(1, test_observer_->audio_nodes_changed_count()); | 620 EXPECT_EQ(1, test_observer_->audio_nodes_changed_count()); |
| 706 cras_audio_handler_->GetAudioDevices(&audio_devices); | 621 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 707 EXPECT_EQ(init_nodes_size + 1, audio_devices.size()); | 622 EXPECT_EQ(init_nodes_size + 1, audio_devices.size()); |
| 708 | 623 |
| 709 // Verify the active output device is switched to headphone and | 624 // Verify the active output device is switched to headphone and |
| 710 // ActiveOutputChanged event is fired. | 625 // ActiveOutputChanged event is fired. |
| 711 EXPECT_EQ(1, test_observer_->active_output_node_changed_count()); | 626 EXPECT_EQ(1, test_observer_->active_output_node_changed_count()); |
| 712 EXPECT_TRUE( | 627 EXPECT_TRUE( |
| 713 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); | 628 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
| 714 EXPECT_EQ(kHeadphone.id, active_output.id); | 629 EXPECT_EQ(kHeadphone->id, active_output.id); |
| 715 EXPECT_EQ(kHeadphone.id, cras_audio_handler_->GetPrimaryActiveOutputNode()); | 630 EXPECT_EQ(kHeadphone->id, cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 716 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); | 631 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
| 717 } | 632 } |
| 718 | 633 |
| 719 TEST_F(CrasAudioHandlerTest, UnplugHeadphone) { | 634 TEST_P(CrasAudioHandlerTest, UnplugHeadphone) { |
| 720 // Set up initial audio devices, with internal speaker and headphone. | 635 // Set up initial audio devices, with internal speaker and headphone. |
| 721 AudioNodeList audio_nodes; | 636 AudioNodeList audio_nodes = |
| 722 audio_nodes.push_back(kInternalSpeaker); | 637 GenerateAudioNodeList({kInternalSpeaker, kHeadphone}); |
| 723 audio_nodes.push_back(kHeadphone); | |
| 724 SetUpCrasAudioHandler(audio_nodes); | 638 SetUpCrasAudioHandler(audio_nodes); |
| 725 const size_t init_nodes_size = audio_nodes.size(); | 639 const size_t init_nodes_size = audio_nodes.size(); |
| 726 | 640 |
| 727 // Verify the audio devices size. | 641 // Verify the audio devices size. |
| 728 AudioDeviceList audio_devices; | 642 AudioDeviceList audio_devices; |
| 729 cras_audio_handler_->GetAudioDevices(&audio_devices); | 643 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 730 EXPECT_EQ(init_nodes_size, audio_devices.size()); | 644 EXPECT_EQ(init_nodes_size, audio_devices.size()); |
| 731 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); | 645 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); |
| 732 | 646 |
| 733 // Verify the headphone has been selected as the active output. | 647 // Verify the headphone has been selected as the active output. |
| 734 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); | 648 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); |
| 735 AudioDevice active_output; | 649 AudioDevice active_output; |
| 736 EXPECT_TRUE( | 650 EXPECT_TRUE( |
| 737 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); | 651 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
| 738 EXPECT_EQ(kHeadphone.id, active_output.id); | 652 EXPECT_EQ(kHeadphone->id, active_output.id); |
| 739 EXPECT_EQ(kHeadphone.id, cras_audio_handler_->GetPrimaryActiveOutputNode()); | 653 EXPECT_EQ(kHeadphone->id, cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 740 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); | 654 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
| 741 | 655 |
| 742 // Unplug the headphone. | 656 // Unplug the headphone. |
| 743 audio_nodes.clear(); | 657 audio_nodes.clear(); |
| 744 audio_nodes.push_back(kInternalSpeaker); | 658 audio_nodes.push_back(GenerateAudioNode(kInternalSpeaker)); |
| 745 ChangeAudioNodes(audio_nodes); | 659 ChangeAudioNodes(audio_nodes); |
| 746 | 660 |
| 747 // Verify the AudioNodesChanged event is fired and one audio device is | 661 // Verify the AudioNodesChanged event is fired and one audio device is |
| 748 // removed. | 662 // removed. |
| 749 EXPECT_EQ(1, test_observer_->audio_nodes_changed_count()); | 663 EXPECT_EQ(1, test_observer_->audio_nodes_changed_count()); |
| 750 cras_audio_handler_->GetAudioDevices(&audio_devices); | 664 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 751 EXPECT_EQ(init_nodes_size - 1, audio_devices.size()); | 665 EXPECT_EQ(init_nodes_size - 1, audio_devices.size()); |
| 752 | 666 |
| 753 // Verify the active output device is switched to internal speaker and | 667 // Verify the active output device is switched to internal speaker and |
| 754 // ActiveOutputChanged event is fired. | 668 // ActiveOutputChanged event is fired. |
| 755 EXPECT_EQ(1, test_observer_->active_output_node_changed_count()); | 669 EXPECT_EQ(1, test_observer_->active_output_node_changed_count()); |
| 756 EXPECT_TRUE( | 670 EXPECT_TRUE( |
| 757 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); | 671 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
| 758 EXPECT_EQ(kInternalSpeaker.id, active_output.id); | 672 EXPECT_EQ(kInternalSpeaker->id, active_output.id); |
| 759 EXPECT_EQ(kInternalSpeaker.id, | 673 EXPECT_EQ(kInternalSpeaker->id, |
| 760 cras_audio_handler_->GetPrimaryActiveOutputNode()); | 674 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 761 EXPECT_FALSE(cras_audio_handler_->has_alternative_output()); | 675 EXPECT_FALSE(cras_audio_handler_->has_alternative_output()); |
| 762 } | 676 } |
| 763 | 677 |
| 764 TEST_F(CrasAudioHandlerTest, InitializeWithBluetoothHeadset) { | 678 TEST_P(CrasAudioHandlerTest, InitializeWithBluetoothHeadset) { |
| 765 AudioNodeList audio_nodes; | 679 AudioNodeList audio_nodes = |
| 766 audio_nodes.push_back(kInternalSpeaker); | 680 GenerateAudioNodeList({kInternalSpeaker, kBluetoothHeadset}); |
| 767 audio_nodes.push_back(kBluetoothHeadset); | |
| 768 SetUpCrasAudioHandler(audio_nodes); | 681 SetUpCrasAudioHandler(audio_nodes); |
| 769 | 682 |
| 770 // Verify the audio devices size. | 683 // Verify the audio devices size. |
| 771 AudioDeviceList audio_devices; | 684 AudioDeviceList audio_devices; |
| 772 cras_audio_handler_->GetAudioDevices(&audio_devices); | 685 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 773 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); | 686 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); |
| 774 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); | 687 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); |
| 775 | 688 |
| 776 // Verify the bluetooth headset has been selected as the active output. | 689 // Verify the bluetooth headset has been selected as the active output. |
| 777 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); | 690 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); |
| 778 AudioDevice active_output; | 691 AudioDevice active_output; |
| 779 EXPECT_TRUE( | 692 EXPECT_TRUE( |
| 780 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); | 693 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
| 781 EXPECT_EQ(kBluetoothHeadset.id, active_output.id); | 694 EXPECT_EQ(kBluetoothHeadset->id, active_output.id); |
| 782 EXPECT_EQ(kBluetoothHeadset.id, | 695 EXPECT_EQ(kBluetoothHeadset->id, |
| 783 cras_audio_handler_->GetPrimaryActiveOutputNode()); | 696 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 784 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); | 697 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
| 785 } | 698 } |
| 786 | 699 |
| 787 TEST_F(CrasAudioHandlerTest, ConnectAndDisconnectBluetoothHeadset) { | 700 TEST_P(CrasAudioHandlerTest, ConnectAndDisconnectBluetoothHeadset) { |
| 788 // Initialize with internal speaker and headphone. | 701 // Initialize with internal speaker and headphone. |
| 789 AudioNodeList audio_nodes; | 702 AudioNodeList audio_nodes = |
| 790 audio_nodes.push_back(kInternalSpeaker); | 703 GenerateAudioNodeList({kInternalSpeaker, kHeadphone}); |
| 791 audio_nodes.push_back(kHeadphone); | |
| 792 SetUpCrasAudioHandler(audio_nodes); | 704 SetUpCrasAudioHandler(audio_nodes); |
| 793 const size_t init_nodes_size = audio_nodes.size(); | 705 const size_t init_nodes_size = audio_nodes.size(); |
| 794 | 706 |
| 795 // Verify the audio devices size. | 707 // Verify the audio devices size. |
| 796 AudioDeviceList audio_devices; | 708 AudioDeviceList audio_devices; |
| 797 cras_audio_handler_->GetAudioDevices(&audio_devices); | 709 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 798 EXPECT_EQ(init_nodes_size, audio_devices.size()); | 710 EXPECT_EQ(init_nodes_size, audio_devices.size()); |
| 799 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); | 711 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); |
| 800 | 712 |
| 801 // Verify the headphone is selected as the active output initially. | 713 // Verify the headphone is selected as the active output initially. |
| 802 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); | 714 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); |
| 803 AudioDevice active_output; | 715 AudioDevice active_output; |
| 804 EXPECT_TRUE( | 716 EXPECT_TRUE( |
| 805 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); | 717 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
| 806 EXPECT_EQ(kHeadphone.id, active_output.id); | 718 EXPECT_EQ(kHeadphone->id, active_output.id); |
| 807 EXPECT_EQ(kHeadphone.id, cras_audio_handler_->GetPrimaryActiveOutputNode()); | 719 EXPECT_EQ(kHeadphone->id, cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 808 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); | 720 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
| 809 | 721 |
| 810 // Connect to bluetooth headset. Since it is plugged in later than | 722 // Connect to bluetooth headset. Since it is plugged in later than |
| 811 // headphone, active output should be switched to it. | 723 // headphone, active output should be switched to it. |
| 812 audio_nodes.clear(); | 724 audio_nodes.clear(); |
| 813 audio_nodes.push_back(kInternalSpeaker); | 725 audio_nodes.push_back(GenerateAudioNode(kInternalSpeaker)); |
| 814 AudioNode headphone(kHeadphone); | 726 AudioNode headphone = GenerateAudioNode(kHeadphone); |
| 815 headphone.plugged_time = 80000000; | 727 headphone.plugged_time = 80000000; |
| 816 headphone.active = true; | 728 headphone.active = true; |
| 817 audio_nodes.push_back(headphone); | 729 audio_nodes.push_back(headphone); |
| 818 AudioNode bluetooth_headset(kBluetoothHeadset); | 730 AudioNode bluetooth_headset = GenerateAudioNode(kBluetoothHeadset); |
| 819 bluetooth_headset.plugged_time = 90000000; | 731 bluetooth_headset.plugged_time = 90000000; |
| 820 audio_nodes.push_back(bluetooth_headset); | 732 audio_nodes.push_back(bluetooth_headset); |
| 821 ChangeAudioNodes(audio_nodes); | 733 ChangeAudioNodes(audio_nodes); |
| 822 | 734 |
| 823 // Verify the AudioNodesChanged event is fired and new audio device is added. | 735 // Verify the AudioNodesChanged event is fired and new audio device is added. |
| 824 EXPECT_EQ(1, test_observer_->audio_nodes_changed_count()); | 736 EXPECT_EQ(1, test_observer_->audio_nodes_changed_count()); |
| 825 cras_audio_handler_->GetAudioDevices(&audio_devices); | 737 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 826 EXPECT_EQ(init_nodes_size + 1, audio_devices.size()); | 738 EXPECT_EQ(init_nodes_size + 1, audio_devices.size()); |
| 827 | 739 |
| 828 // Verify the active output device is switched to bluetooth headset, and | 740 // Verify the active output device is switched to bluetooth headset, and |
| 829 // ActiveOutputChanged event is fired. | 741 // ActiveOutputChanged event is fired. |
| 830 EXPECT_EQ(1, test_observer_->active_output_node_changed_count()); | 742 EXPECT_EQ(1, test_observer_->active_output_node_changed_count()); |
| 831 EXPECT_TRUE( | 743 EXPECT_TRUE( |
| 832 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); | 744 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
| 833 EXPECT_EQ(kBluetoothHeadset.id, active_output.id); | 745 EXPECT_EQ(kBluetoothHeadset->id, active_output.id); |
| 834 EXPECT_EQ(kBluetoothHeadset.id, | 746 EXPECT_EQ(kBluetoothHeadset->id, |
| 835 cras_audio_handler_->GetPrimaryActiveOutputNode()); | 747 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 836 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); | 748 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
| 837 | 749 |
| 838 // Disconnect bluetooth headset. | 750 // Disconnect bluetooth headset. |
| 839 audio_nodes.clear(); | 751 audio_nodes.clear(); |
| 840 audio_nodes.push_back(kInternalSpeaker); | 752 audio_nodes.push_back(GenerateAudioNode(kInternalSpeaker)); |
| 841 headphone.active = false; | 753 headphone.active = false; |
| 842 audio_nodes.push_back(headphone); | 754 audio_nodes.push_back(headphone); |
| 843 ChangeAudioNodes(audio_nodes); | 755 ChangeAudioNodes(audio_nodes); |
| 844 | 756 |
| 845 // Verify the AudioNodesChanged event is fired and one audio device is | 757 // Verify the AudioNodesChanged event is fired and one audio device is |
| 846 // removed. | 758 // removed. |
| 847 EXPECT_EQ(2, test_observer_->audio_nodes_changed_count()); | 759 EXPECT_EQ(2, test_observer_->audio_nodes_changed_count()); |
| 848 cras_audio_handler_->GetAudioDevices(&audio_devices); | 760 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 849 EXPECT_EQ(init_nodes_size, audio_devices.size()); | 761 EXPECT_EQ(init_nodes_size, audio_devices.size()); |
| 850 | 762 |
| 851 // Verify the active output device is switched to headphone, and | 763 // Verify the active output device is switched to headphone, and |
| 852 // ActiveOutputChanged event is fired. | 764 // ActiveOutputChanged event is fired. |
| 853 EXPECT_EQ(2, test_observer_->active_output_node_changed_count()); | 765 EXPECT_EQ(2, test_observer_->active_output_node_changed_count()); |
| 854 EXPECT_TRUE( | 766 EXPECT_TRUE( |
| 855 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); | 767 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
| 856 EXPECT_EQ(kHeadphone.id, active_output.id); | 768 EXPECT_EQ(kHeadphone->id, active_output.id); |
| 857 EXPECT_EQ(kHeadphone.id, cras_audio_handler_->GetPrimaryActiveOutputNode()); | 769 EXPECT_EQ(kHeadphone->id, cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 858 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); | 770 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
| 859 } | 771 } |
| 860 | 772 |
| 861 TEST_F(CrasAudioHandlerTest, InitializeWithHDMIOutput) { | 773 TEST_P(CrasAudioHandlerTest, InitializeWithHDMIOutput) { |
| 862 AudioNodeList audio_nodes; | 774 AudioNodeList audio_nodes = |
| 863 audio_nodes.push_back(kInternalSpeaker); | 775 GenerateAudioNodeList({kInternalSpeaker, kHDMIOutput}); |
| 864 audio_nodes.push_back(kHDMIOutput); | |
| 865 SetUpCrasAudioHandler(audio_nodes); | 776 SetUpCrasAudioHandler(audio_nodes); |
| 866 | 777 |
| 867 // Verify the audio devices size. | 778 // Verify the audio devices size. |
| 868 AudioDeviceList audio_devices; | 779 AudioDeviceList audio_devices; |
| 869 cras_audio_handler_->GetAudioDevices(&audio_devices); | 780 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 870 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); | 781 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); |
| 871 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); | 782 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); |
| 872 | 783 |
| 873 // Verify the HDMI device has been selected as the active output. | 784 // Verify the HDMI device has been selected as the active output. |
| 874 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); | 785 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); |
| 875 AudioDevice active_output; | 786 AudioDevice active_output; |
| 876 EXPECT_TRUE( | 787 EXPECT_TRUE( |
| 877 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); | 788 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
| 878 EXPECT_EQ(kHDMIOutput.id, active_output.id); | 789 EXPECT_EQ(kHDMIOutput->id, active_output.id); |
| 879 EXPECT_EQ(kHDMIOutput.id, cras_audio_handler_->GetPrimaryActiveOutputNode()); | 790 EXPECT_EQ(kHDMIOutput->id, cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 880 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); | 791 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
| 881 } | 792 } |
| 882 | 793 |
| 883 TEST_F(CrasAudioHandlerTest, ConnectAndDisconnectHDMIOutput) { | 794 TEST_P(CrasAudioHandlerTest, ConnectAndDisconnectHDMIOutput) { |
| 884 // Initialize with internal speaker. | 795 // Initialize with internal speaker. |
| 885 AudioNodeList audio_nodes; | 796 AudioNodeList audio_nodes = GenerateAudioNodeList({kInternalSpeaker}); |
| 886 audio_nodes.push_back(kInternalSpeaker); | |
| 887 SetUpCrasAudioHandler(audio_nodes); | 797 SetUpCrasAudioHandler(audio_nodes); |
| 888 const size_t init_nodes_size = audio_nodes.size(); | 798 const size_t init_nodes_size = audio_nodes.size(); |
| 889 | 799 |
| 890 // Verify the audio devices size. | 800 // Verify the audio devices size. |
| 891 AudioDeviceList audio_devices; | 801 AudioDeviceList audio_devices; |
| 892 cras_audio_handler_->GetAudioDevices(&audio_devices); | 802 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 893 EXPECT_EQ(init_nodes_size, audio_devices.size()); | 803 EXPECT_EQ(init_nodes_size, audio_devices.size()); |
| 894 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); | 804 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); |
| 895 | 805 |
| 896 // Verify the internal speaker is selected as the active output initially. | 806 // Verify the internal speaker is selected as the active output initially. |
| 897 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); | 807 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); |
| 898 AudioDevice active_output; | 808 AudioDevice active_output; |
| 899 EXPECT_TRUE( | 809 EXPECT_TRUE( |
| 900 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); | 810 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
| 901 EXPECT_EQ(kInternalSpeaker.id, active_output.id); | 811 EXPECT_EQ(kInternalSpeaker->id, active_output.id); |
| 902 EXPECT_EQ(kInternalSpeaker.id, | 812 EXPECT_EQ(kInternalSpeaker->id, |
| 903 cras_audio_handler_->GetPrimaryActiveOutputNode()); | 813 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 904 EXPECT_FALSE(cras_audio_handler_->has_alternative_output()); | 814 EXPECT_FALSE(cras_audio_handler_->has_alternative_output()); |
| 905 | 815 |
| 906 // Connect to HDMI output. | 816 // Connect to HDMI output. |
| 907 audio_nodes.clear(); | 817 audio_nodes.clear(); |
| 908 AudioNode internal_speaker(kInternalSpeaker); | 818 AudioNode internal_speaker = GenerateAudioNode(kInternalSpeaker); |
| 909 internal_speaker.active = true; | 819 internal_speaker.active = true; |
| 910 internal_speaker.plugged_time = 80000000; | 820 internal_speaker.plugged_time = 80000000; |
| 911 audio_nodes.push_back(internal_speaker); | 821 audio_nodes.push_back(internal_speaker); |
| 912 AudioNode hdmi(kHDMIOutput); | 822 AudioNode hdmi = GenerateAudioNode(kHDMIOutput); |
| 913 hdmi.plugged_time = 90000000; | 823 hdmi.plugged_time = 90000000; |
| 914 audio_nodes.push_back(hdmi); | 824 audio_nodes.push_back(hdmi); |
| 915 ChangeAudioNodes(audio_nodes); | 825 ChangeAudioNodes(audio_nodes); |
| 916 | 826 |
| 917 // Verify the AudioNodesChanged event is fired and new audio device is added. | 827 // Verify the AudioNodesChanged event is fired and new audio device is added. |
| 918 EXPECT_EQ(1, test_observer_->audio_nodes_changed_count()); | 828 EXPECT_EQ(1, test_observer_->audio_nodes_changed_count()); |
| 919 cras_audio_handler_->GetAudioDevices(&audio_devices); | 829 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 920 EXPECT_EQ(init_nodes_size + 1, audio_devices.size()); | 830 EXPECT_EQ(init_nodes_size + 1, audio_devices.size()); |
| 921 | 831 |
| 922 // Verify the active output device is switched to hdmi output, and | 832 // Verify the active output device is switched to hdmi output, and |
| 923 // ActiveOutputChanged event is fired. | 833 // ActiveOutputChanged event is fired. |
| 924 EXPECT_EQ(1, test_observer_->active_output_node_changed_count()); | 834 EXPECT_EQ(1, test_observer_->active_output_node_changed_count()); |
| 925 EXPECT_TRUE( | 835 EXPECT_TRUE( |
| 926 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); | 836 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
| 927 EXPECT_EQ(kHDMIOutput.id, active_output.id); | 837 EXPECT_EQ(kHDMIOutput->id, active_output.id); |
| 928 EXPECT_EQ(kHDMIOutput.id, cras_audio_handler_->GetPrimaryActiveOutputNode()); | 838 EXPECT_EQ(kHDMIOutput->id, cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 929 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); | 839 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
| 930 | 840 |
| 931 // Disconnect hdmi headset. | 841 // Disconnect hdmi headset. |
| 932 audio_nodes.clear(); | 842 audio_nodes.clear(); |
| 933 audio_nodes.push_back(kInternalSpeaker); | 843 audio_nodes.push_back(GenerateAudioNode(kInternalSpeaker)); |
| 934 ChangeAudioNodes(audio_nodes); | 844 ChangeAudioNodes(audio_nodes); |
| 935 | 845 |
| 936 // Verify the AudioNodesChanged event is fired and one audio device is | 846 // Verify the AudioNodesChanged event is fired and one audio device is |
| 937 // removed. | 847 // removed. |
| 938 EXPECT_EQ(2, test_observer_->audio_nodes_changed_count()); | 848 EXPECT_EQ(2, test_observer_->audio_nodes_changed_count()); |
| 939 cras_audio_handler_->GetAudioDevices(&audio_devices); | 849 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 940 EXPECT_EQ(init_nodes_size, audio_devices.size()); | 850 EXPECT_EQ(init_nodes_size, audio_devices.size()); |
| 941 | 851 |
| 942 // Verify the active output device is switched to internal speaker, and | 852 // Verify the active output device is switched to internal speaker, and |
| 943 // ActiveOutputChanged event is fired. | 853 // ActiveOutputChanged event is fired. |
| 944 EXPECT_EQ(2, test_observer_->active_output_node_changed_count()); | 854 EXPECT_EQ(2, test_observer_->active_output_node_changed_count()); |
| 945 EXPECT_TRUE( | 855 EXPECT_TRUE( |
| 946 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); | 856 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
| 947 EXPECT_EQ(kInternalSpeaker.id, active_output.id); | 857 EXPECT_EQ(kInternalSpeaker->id, active_output.id); |
| 948 EXPECT_EQ(kInternalSpeaker.id, | 858 EXPECT_EQ(kInternalSpeaker->id, |
| 949 cras_audio_handler_->GetPrimaryActiveOutputNode()); | 859 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 950 EXPECT_FALSE(cras_audio_handler_->has_alternative_output()); | 860 EXPECT_FALSE(cras_audio_handler_->has_alternative_output()); |
| 951 } | 861 } |
| 952 | 862 |
| 953 TEST_F(CrasAudioHandlerTest, HandleHeadphoneAndHDMIOutput) { | 863 TEST_P(CrasAudioHandlerTest, HandleHeadphoneAndHDMIOutput) { |
| 954 // Initialize with internal speaker, headphone and HDMI output. | 864 // Initialize with internal speaker, headphone and HDMI output. |
| 955 AudioNodeList audio_nodes; | 865 AudioNodeList audio_nodes = |
| 956 audio_nodes.push_back(kInternalSpeaker); | 866 GenerateAudioNodeList({kInternalSpeaker, kHeadphone, kHDMIOutput}); |
| 957 audio_nodes.push_back(kHeadphone); | |
| 958 audio_nodes.push_back(kHDMIOutput); | |
| 959 SetUpCrasAudioHandler(audio_nodes); | 867 SetUpCrasAudioHandler(audio_nodes); |
| 960 const size_t init_nodes_size = audio_nodes.size(); | 868 const size_t init_nodes_size = audio_nodes.size(); |
| 961 | 869 |
| 962 // Verify the audio devices size. | 870 // Verify the audio devices size. |
| 963 AudioDeviceList audio_devices; | 871 AudioDeviceList audio_devices; |
| 964 cras_audio_handler_->GetAudioDevices(&audio_devices); | 872 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 965 EXPECT_EQ(init_nodes_size, audio_devices.size()); | 873 EXPECT_EQ(init_nodes_size, audio_devices.size()); |
| 966 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); | 874 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); |
| 967 | 875 |
| 968 // Verify the headphone is selected as the active output initially. | 876 // Verify the headphone is selected as the active output initially. |
| 969 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); | 877 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); |
| 970 AudioDevice active_output; | 878 AudioDevice active_output; |
| 971 EXPECT_TRUE( | 879 EXPECT_TRUE( |
| 972 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); | 880 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
| 973 EXPECT_EQ(kHeadphone.id, active_output.id); | 881 EXPECT_EQ(kHeadphone->id, active_output.id); |
| 974 EXPECT_EQ(kHeadphone.id, cras_audio_handler_->GetPrimaryActiveOutputNode()); | 882 EXPECT_EQ(kHeadphone->id, cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 975 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); | 883 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
| 976 | 884 |
| 977 // Disconnect HDMI output. | 885 // Disconnect HDMI output. |
| 978 audio_nodes.clear(); | 886 audio_nodes.clear(); |
| 979 audio_nodes.push_back(kInternalSpeaker); | 887 audio_nodes.push_back(GenerateAudioNode(kInternalSpeaker)); |
| 980 audio_nodes.push_back(kHDMIOutput); | 888 audio_nodes.push_back(GenerateAudioNode(kHDMIOutput)); |
| 981 ChangeAudioNodes(audio_nodes); | 889 ChangeAudioNodes(audio_nodes); |
| 982 | 890 |
| 983 // Verify the AudioNodesChanged event is fired and one audio device is | 891 // Verify the AudioNodesChanged event is fired and one audio device is |
| 984 // removed. | 892 // removed. |
| 985 EXPECT_EQ(1, test_observer_->audio_nodes_changed_count()); | 893 EXPECT_EQ(1, test_observer_->audio_nodes_changed_count()); |
| 986 cras_audio_handler_->GetAudioDevices(&audio_devices); | 894 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 987 EXPECT_EQ(init_nodes_size - 1, audio_devices.size()); | 895 EXPECT_EQ(init_nodes_size - 1, audio_devices.size()); |
| 988 | 896 |
| 989 // Verify the active output device is switched to HDMI output, and | 897 // Verify the active output device is switched to HDMI output, and |
| 990 // ActiveOutputChanged event is fired. | 898 // ActiveOutputChanged event is fired. |
| 991 EXPECT_EQ(1, test_observer_->active_output_node_changed_count()); | 899 EXPECT_EQ(1, test_observer_->active_output_node_changed_count()); |
| 992 EXPECT_TRUE( | 900 EXPECT_TRUE( |
| 993 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); | 901 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
| 994 EXPECT_EQ(kHDMIOutput.id, active_output.id); | 902 EXPECT_EQ(kHDMIOutput->id, active_output.id); |
| 995 EXPECT_EQ(kHDMIOutput.id, cras_audio_handler_->GetPrimaryActiveOutputNode()); | 903 EXPECT_EQ(kHDMIOutput->id, cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 996 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); | 904 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
| 997 } | 905 } |
| 998 | 906 |
| 999 TEST_F(CrasAudioHandlerTest, InitializeWithUSBHeadphone) { | 907 TEST_P(CrasAudioHandlerTest, InitializeWithUSBHeadphone) { |
| 1000 AudioNodeList audio_nodes; | 908 AudioNodeList audio_nodes = |
| 1001 audio_nodes.push_back(kInternalSpeaker); | 909 GenerateAudioNodeList({kInternalSpeaker, kUSBHeadphone1}); |
| 1002 audio_nodes.push_back(kUSBHeadphone1); | |
| 1003 SetUpCrasAudioHandler(audio_nodes); | 910 SetUpCrasAudioHandler(audio_nodes); |
| 1004 | 911 |
| 1005 // Verify the audio devices size. | 912 // Verify the audio devices size. |
| 1006 AudioDeviceList audio_devices; | 913 AudioDeviceList audio_devices; |
| 1007 cras_audio_handler_->GetAudioDevices(&audio_devices); | 914 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 1008 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); | 915 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); |
| 1009 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); | 916 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); |
| 1010 | 917 |
| 1011 // Verify the usb headphone has been selected as the active output. | 918 // Verify the usb headphone has been selected as the active output. |
| 1012 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); | 919 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); |
| 1013 AudioDevice active_output; | 920 AudioDevice active_output; |
| 1014 EXPECT_TRUE( | 921 EXPECT_TRUE( |
| 1015 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); | 922 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
| 1016 EXPECT_EQ(kUSBHeadphone1.id, active_output.id); | 923 EXPECT_EQ(kUSBHeadphone1->id, active_output.id); |
| 1017 EXPECT_EQ(kUSBHeadphone1.id, | 924 EXPECT_EQ(kUSBHeadphone1->id, |
| 1018 cras_audio_handler_->GetPrimaryActiveOutputNode()); | 925 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 1019 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); | 926 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
| 1020 } | 927 } |
| 1021 | 928 |
| 1022 TEST_F(CrasAudioHandlerTest, PlugAndUnplugUSBHeadphone) { | 929 TEST_P(CrasAudioHandlerTest, PlugAndUnplugUSBHeadphone) { |
| 1023 // Initialize with internal speaker. | 930 // Initialize with internal speaker. |
| 1024 AudioNodeList audio_nodes; | 931 AudioNodeList audio_nodes = GenerateAudioNodeList({kInternalSpeaker}); |
| 1025 audio_nodes.push_back(kInternalSpeaker); | |
| 1026 SetUpCrasAudioHandler(audio_nodes); | 932 SetUpCrasAudioHandler(audio_nodes); |
| 1027 const size_t init_nodes_size = audio_nodes.size(); | 933 const size_t init_nodes_size = audio_nodes.size(); |
| 1028 | 934 |
| 1029 // Verify the audio devices size. | 935 // Verify the audio devices size. |
| 1030 AudioDeviceList audio_devices; | 936 AudioDeviceList audio_devices; |
| 1031 cras_audio_handler_->GetAudioDevices(&audio_devices); | 937 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 1032 EXPECT_EQ(init_nodes_size, audio_devices.size()); | 938 EXPECT_EQ(init_nodes_size, audio_devices.size()); |
| 1033 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); | 939 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); |
| 1034 | 940 |
| 1035 // Verify the internal speaker is selected as the active output initially. | 941 // Verify the internal speaker is selected as the active output initially. |
| 1036 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); | 942 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); |
| 1037 AudioDevice active_output; | 943 AudioDevice active_output; |
| 1038 EXPECT_TRUE( | 944 EXPECT_TRUE( |
| 1039 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); | 945 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
| 1040 EXPECT_EQ(kInternalSpeaker.id, active_output.id); | 946 EXPECT_EQ(kInternalSpeaker->id, active_output.id); |
| 1041 EXPECT_EQ(kInternalSpeaker.id, | 947 EXPECT_EQ(kInternalSpeaker->id, |
| 1042 cras_audio_handler_->GetPrimaryActiveOutputNode()); | 948 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 1043 EXPECT_FALSE(cras_audio_handler_->has_alternative_output()); | 949 EXPECT_FALSE(cras_audio_handler_->has_alternative_output()); |
| 1044 | 950 |
| 1045 // Plug in usb headphone | 951 // Plug in usb headphone |
| 1046 audio_nodes.clear(); | 952 audio_nodes.clear(); |
| 1047 AudioNode internal_speaker(kInternalSpeaker); | 953 AudioNode internal_speaker = GenerateAudioNode(kInternalSpeaker); |
| 1048 internal_speaker.active = true; | 954 internal_speaker.active = true; |
| 1049 internal_speaker.plugged_time = 80000000; | 955 internal_speaker.plugged_time = 80000000; |
| 1050 audio_nodes.push_back(internal_speaker); | 956 audio_nodes.push_back(internal_speaker); |
| 1051 AudioNode usb_headphone(kUSBHeadphone1); | 957 AudioNode usb_headphone = GenerateAudioNode(kUSBHeadphone1); |
| 1052 usb_headphone.plugged_time = 90000000; | 958 usb_headphone.plugged_time = 90000000; |
| 1053 audio_nodes.push_back(usb_headphone); | 959 audio_nodes.push_back(usb_headphone); |
| 1054 ChangeAudioNodes(audio_nodes); | 960 ChangeAudioNodes(audio_nodes); |
| 1055 | 961 |
| 1056 // Verify the AudioNodesChanged event is fired and new audio device is added. | 962 // Verify the AudioNodesChanged event is fired and new audio device is added. |
| 1057 EXPECT_EQ(1, test_observer_->audio_nodes_changed_count()); | 963 EXPECT_EQ(1, test_observer_->audio_nodes_changed_count()); |
| 1058 cras_audio_handler_->GetAudioDevices(&audio_devices); | 964 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 1059 EXPECT_EQ(init_nodes_size + 1, audio_devices.size()); | 965 EXPECT_EQ(init_nodes_size + 1, audio_devices.size()); |
| 1060 | 966 |
| 1061 // Verify the active output device is switched to usb headphone, and | 967 // Verify the active output device is switched to usb headphone, and |
| 1062 // ActiveOutputChanged event is fired. | 968 // ActiveOutputChanged event is fired. |
| 1063 EXPECT_EQ(1, test_observer_->active_output_node_changed_count()); | 969 EXPECT_EQ(1, test_observer_->active_output_node_changed_count()); |
| 1064 EXPECT_TRUE( | 970 EXPECT_TRUE( |
| 1065 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); | 971 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
| 1066 EXPECT_EQ(kUSBHeadphone1.id, active_output.id); | 972 EXPECT_EQ(kUSBHeadphone1->id, active_output.id); |
| 1067 EXPECT_EQ(kUSBHeadphone1.id, | 973 EXPECT_EQ(kUSBHeadphone1->id, |
| 1068 cras_audio_handler_->GetPrimaryActiveOutputNode()); | 974 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 1069 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); | 975 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
| 1070 | 976 |
| 1071 // Unplug usb headphone. | 977 // Unplug usb headphone. |
| 1072 audio_nodes.clear(); | 978 audio_nodes.clear(); |
| 1073 audio_nodes.push_back(kInternalSpeaker); | 979 audio_nodes.push_back(GenerateAudioNode(kInternalSpeaker)); |
| 1074 ChangeAudioNodes(audio_nodes); | 980 ChangeAudioNodes(audio_nodes); |
| 1075 | 981 |
| 1076 // Verify the AudioNodesChanged event is fired and one audio device is | 982 // Verify the AudioNodesChanged event is fired and one audio device is |
| 1077 // removed. | 983 // removed. |
| 1078 EXPECT_EQ(2, test_observer_->audio_nodes_changed_count()); | 984 EXPECT_EQ(2, test_observer_->audio_nodes_changed_count()); |
| 1079 cras_audio_handler_->GetAudioDevices(&audio_devices); | 985 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 1080 EXPECT_EQ(init_nodes_size, audio_devices.size()); | 986 EXPECT_EQ(init_nodes_size, audio_devices.size()); |
| 1081 | 987 |
| 1082 // Verify the active output device is switched to internal speaker, and | 988 // Verify the active output device is switched to internal speaker, and |
| 1083 // ActiveOutputChanged event is fired. | 989 // ActiveOutputChanged event is fired. |
| 1084 EXPECT_EQ(2, test_observer_->active_output_node_changed_count()); | 990 EXPECT_EQ(2, test_observer_->active_output_node_changed_count()); |
| 1085 EXPECT_TRUE( | 991 EXPECT_TRUE( |
| 1086 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); | 992 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
| 1087 EXPECT_EQ(kInternalSpeaker.id, active_output.id); | 993 EXPECT_EQ(kInternalSpeaker->id, active_output.id); |
| 1088 EXPECT_EQ(kInternalSpeaker.id, | 994 EXPECT_EQ(kInternalSpeaker->id, |
| 1089 cras_audio_handler_->GetPrimaryActiveOutputNode()); | 995 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 1090 EXPECT_FALSE(cras_audio_handler_->has_alternative_output()); | 996 EXPECT_FALSE(cras_audio_handler_->has_alternative_output()); |
| 1091 } | 997 } |
| 1092 | 998 |
| 1093 TEST_F(CrasAudioHandlerTest, HandleMultipleUSBHeadphones) { | 999 TEST_P(CrasAudioHandlerTest, HandleMultipleUSBHeadphones) { |
| 1094 // Initialize with internal speaker and one usb headphone. | 1000 // Initialize with internal speaker and one usb headphone. |
| 1095 AudioNodeList audio_nodes; | 1001 AudioNodeList audio_nodes = |
| 1096 audio_nodes.push_back(kInternalSpeaker); | 1002 GenerateAudioNodeList({kInternalSpeaker, kUSBHeadphone1}); |
| 1097 audio_nodes.push_back(kUSBHeadphone1); | |
| 1098 SetUpCrasAudioHandler(audio_nodes); | 1003 SetUpCrasAudioHandler(audio_nodes); |
| 1099 const size_t init_nodes_size = audio_nodes.size(); | 1004 const size_t init_nodes_size = audio_nodes.size(); |
| 1100 | 1005 |
| 1101 // Verify the audio devices size. | 1006 // Verify the audio devices size. |
| 1102 AudioDeviceList audio_devices; | 1007 AudioDeviceList audio_devices; |
| 1103 cras_audio_handler_->GetAudioDevices(&audio_devices); | 1008 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 1104 EXPECT_EQ(init_nodes_size, audio_devices.size()); | 1009 EXPECT_EQ(init_nodes_size, audio_devices.size()); |
| 1105 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); | 1010 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); |
| 1106 | 1011 |
| 1107 // Verify the usb headphone is selected as the active output initially. | 1012 // Verify the usb headphone is selected as the active output initially. |
| 1108 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); | 1013 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); |
| 1109 AudioDevice active_output; | 1014 AudioDevice active_output; |
| 1110 EXPECT_TRUE( | 1015 EXPECT_TRUE( |
| 1111 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); | 1016 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
| 1112 EXPECT_EQ(kUSBHeadphone1.id, active_output.id); | 1017 EXPECT_EQ(kUSBHeadphone1->id, active_output.id); |
| 1113 EXPECT_EQ(kUSBHeadphone1.id, | 1018 EXPECT_EQ(kUSBHeadphone1->id, |
| 1114 cras_audio_handler_->GetPrimaryActiveOutputNode()); | 1019 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 1115 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); | 1020 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
| 1116 | 1021 |
| 1117 // Plug in another usb headphone. | 1022 // Plug in another usb headphone. |
| 1118 audio_nodes.clear(); | 1023 audio_nodes.clear(); |
| 1119 audio_nodes.push_back(kInternalSpeaker); | 1024 audio_nodes.push_back(GenerateAudioNode(kInternalSpeaker)); |
| 1120 AudioNode usb_headphone_1(kUSBHeadphone1); | 1025 AudioNode usb_headphone_1 = GenerateAudioNode(kUSBHeadphone1); |
| 1121 usb_headphone_1.active = true; | 1026 usb_headphone_1.active = true; |
| 1122 usb_headphone_1.plugged_time = 80000000; | 1027 usb_headphone_1.plugged_time = 80000000; |
| 1123 audio_nodes.push_back(usb_headphone_1); | 1028 audio_nodes.push_back(usb_headphone_1); |
| 1124 AudioNode usb_headphone_2(kUSBHeadphone2); | 1029 AudioNode usb_headphone_2 = GenerateAudioNode(kUSBHeadphone2); |
| 1125 usb_headphone_2.plugged_time = 90000000; | 1030 usb_headphone_2.plugged_time = 90000000; |
| 1126 audio_nodes.push_back(usb_headphone_2); | 1031 audio_nodes.push_back(usb_headphone_2); |
| 1127 ChangeAudioNodes(audio_nodes); | 1032 ChangeAudioNodes(audio_nodes); |
| 1128 | 1033 |
| 1129 // Verify the AudioNodesChanged event is fired and new audio device is added. | 1034 // Verify the AudioNodesChanged event is fired and new audio device is added. |
| 1130 EXPECT_EQ(1, test_observer_->audio_nodes_changed_count()); | 1035 EXPECT_EQ(1, test_observer_->audio_nodes_changed_count()); |
| 1131 cras_audio_handler_->GetAudioDevices(&audio_devices); | 1036 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 1132 EXPECT_EQ(init_nodes_size + 1, audio_devices.size()); | 1037 EXPECT_EQ(init_nodes_size + 1, audio_devices.size()); |
| 1133 | 1038 |
| 1134 // Verify the active output device is switched to the 2nd usb headphone, which | 1039 // Verify the active output device is switched to the 2nd usb headphone, which |
| 1135 // is plugged later, and ActiveOutputChanged event is fired. | 1040 // is plugged later, and ActiveOutputChanged event is fired. |
| 1136 EXPECT_EQ(1, test_observer_->active_output_node_changed_count()); | 1041 EXPECT_EQ(1, test_observer_->active_output_node_changed_count()); |
| 1137 EXPECT_TRUE( | 1042 EXPECT_TRUE( |
| 1138 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); | 1043 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
| 1139 EXPECT_EQ(kUSBHeadphone2.id, active_output.id); | 1044 EXPECT_EQ(kUSBHeadphone2->id, active_output.id); |
| 1140 EXPECT_EQ(kUSBHeadphone2.id, | 1045 EXPECT_EQ(kUSBHeadphone2->id, |
| 1141 cras_audio_handler_->GetPrimaryActiveOutputNode()); | 1046 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 1142 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); | 1047 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
| 1143 | 1048 |
| 1144 // Unplug the 2nd usb headphone. | 1049 // Unplug the 2nd usb headphone. |
| 1145 audio_nodes.clear(); | 1050 audio_nodes.clear(); |
| 1146 audio_nodes.push_back(kInternalSpeaker); | 1051 audio_nodes.push_back(GenerateAudioNode(kInternalSpeaker)); |
| 1147 audio_nodes.push_back(kUSBHeadphone1); | 1052 audio_nodes.push_back(GenerateAudioNode(kUSBHeadphone1)); |
| 1148 ChangeAudioNodes(audio_nodes); | 1053 ChangeAudioNodes(audio_nodes); |
| 1149 | 1054 |
| 1150 // Verify the AudioNodesChanged event is fired and one audio device is | 1055 // Verify the AudioNodesChanged event is fired and one audio device is |
| 1151 // removed. | 1056 // removed. |
| 1152 EXPECT_EQ(2, test_observer_->audio_nodes_changed_count()); | 1057 EXPECT_EQ(2, test_observer_->audio_nodes_changed_count()); |
| 1153 cras_audio_handler_->GetAudioDevices(&audio_devices); | 1058 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 1154 EXPECT_EQ(init_nodes_size, audio_devices.size()); | 1059 EXPECT_EQ(init_nodes_size, audio_devices.size()); |
| 1155 | 1060 |
| 1156 // Verify the active output device is switched to the first usb headphone, and | 1061 // Verify the active output device is switched to the first usb headphone, and |
| 1157 // ActiveOutputChanged event is fired. | 1062 // ActiveOutputChanged event is fired. |
| 1158 EXPECT_EQ(2, test_observer_->active_output_node_changed_count()); | 1063 EXPECT_EQ(2, test_observer_->active_output_node_changed_count()); |
| 1159 EXPECT_TRUE( | 1064 EXPECT_TRUE( |
| 1160 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); | 1065 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
| 1161 EXPECT_EQ(kUSBHeadphone1.id, active_output.id); | 1066 EXPECT_EQ(kUSBHeadphone1->id, active_output.id); |
| 1162 EXPECT_EQ(kUSBHeadphone1.id, | 1067 EXPECT_EQ(kUSBHeadphone1->id, |
| 1163 cras_audio_handler_->GetPrimaryActiveOutputNode()); | 1068 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 1164 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); | 1069 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
| 1165 } | 1070 } |
| 1166 | 1071 |
| 1167 TEST_F(CrasAudioHandlerTest, UnplugUSBHeadphonesWithActiveSpeaker) { | 1072 TEST_P(CrasAudioHandlerTest, UnplugUSBHeadphonesWithActiveSpeaker) { |
| 1168 // Initialize with internal speaker and one usb headphone. | 1073 // Initialize with internal speaker and one usb headphone. |
| 1169 AudioNodeList audio_nodes; | 1074 AudioNodeList audio_nodes = |
| 1170 audio_nodes.push_back(kInternalSpeaker); | 1075 GenerateAudioNodeList({kInternalSpeaker, kUSBHeadphone1}); |
| 1171 audio_nodes.push_back(kUSBHeadphone1); | |
| 1172 SetUpCrasAudioHandler(audio_nodes); | 1076 SetUpCrasAudioHandler(audio_nodes); |
| 1173 const size_t init_nodes_size = audio_nodes.size(); | 1077 const size_t init_nodes_size = audio_nodes.size(); |
| 1174 | 1078 |
| 1175 // Verify the audio devices size. | 1079 // Verify the audio devices size. |
| 1176 AudioDeviceList audio_devices; | 1080 AudioDeviceList audio_devices; |
| 1177 cras_audio_handler_->GetAudioDevices(&audio_devices); | 1081 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 1178 EXPECT_EQ(init_nodes_size, audio_devices.size()); | 1082 EXPECT_EQ(init_nodes_size, audio_devices.size()); |
| 1179 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); | 1083 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); |
| 1180 | 1084 |
| 1181 // Verify the usb headphone is selected as the active output initially. | 1085 // Verify the usb headphone is selected as the active output initially. |
| 1182 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); | 1086 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); |
| 1183 AudioDevice active_output; | 1087 AudioDevice active_output; |
| 1184 EXPECT_TRUE( | 1088 EXPECT_TRUE( |
| 1185 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); | 1089 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
| 1186 EXPECT_EQ(kUSBHeadphone1.id, active_output.id); | 1090 EXPECT_EQ(kUSBHeadphone1->id, active_output.id); |
| 1187 EXPECT_EQ(kUSBHeadphone1.id, | 1091 EXPECT_EQ(kUSBHeadphone1->id, |
| 1188 cras_audio_handler_->GetPrimaryActiveOutputNode()); | 1092 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 1189 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); | 1093 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
| 1190 | 1094 |
| 1191 // Plug in the headphone jack. | 1095 // Plug in the headphone jack. |
| 1192 audio_nodes.clear(); | 1096 audio_nodes.clear(); |
| 1193 audio_nodes.push_back(kInternalSpeaker); | 1097 audio_nodes.push_back(GenerateAudioNode(kInternalSpeaker)); |
| 1194 AudioNode usb_headphone_1(kUSBHeadphone1); | 1098 AudioNode usb_headphone_1 = GenerateAudioNode(kUSBHeadphone1); |
| 1195 usb_headphone_1.active = true; | 1099 usb_headphone_1.active = true; |
| 1196 usb_headphone_1.plugged_time = 80000000; | 1100 usb_headphone_1.plugged_time = 80000000; |
| 1197 audio_nodes.push_back(usb_headphone_1); | 1101 audio_nodes.push_back(usb_headphone_1); |
| 1198 AudioNode headphone_jack(kHeadphone); | 1102 AudioNode headphone_jack = GenerateAudioNode(kHeadphone); |
| 1199 headphone_jack.plugged_time = 90000000; | 1103 headphone_jack.plugged_time = 90000000; |
| 1200 audio_nodes.push_back(headphone_jack); | 1104 audio_nodes.push_back(headphone_jack); |
| 1201 ChangeAudioNodes(audio_nodes); | 1105 ChangeAudioNodes(audio_nodes); |
| 1202 | 1106 |
| 1203 // Verify the AudioNodesChanged event is fired and new audio device is added. | 1107 // Verify the AudioNodesChanged event is fired and new audio device is added. |
| 1204 EXPECT_EQ(1, test_observer_->audio_nodes_changed_count()); | 1108 EXPECT_EQ(1, test_observer_->audio_nodes_changed_count()); |
| 1205 cras_audio_handler_->GetAudioDevices(&audio_devices); | 1109 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 1206 EXPECT_EQ(init_nodes_size + 1, audio_devices.size()); | 1110 EXPECT_EQ(init_nodes_size + 1, audio_devices.size()); |
| 1207 | 1111 |
| 1208 // Verify the active output device is switched to the headphone jack, which | 1112 // Verify the active output device is switched to the headphone jack, which |
| 1209 // is plugged later, and ActiveOutputChanged event is fired. | 1113 // is plugged later, and ActiveOutputChanged event is fired. |
| 1210 EXPECT_EQ(1, test_observer_->active_output_node_changed_count()); | 1114 EXPECT_EQ(1, test_observer_->active_output_node_changed_count()); |
| 1211 EXPECT_TRUE( | 1115 EXPECT_TRUE( |
| 1212 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); | 1116 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
| 1213 EXPECT_EQ(kHeadphone.id, active_output.id); | 1117 EXPECT_EQ(kHeadphone->id, active_output.id); |
| 1214 EXPECT_EQ(kHeadphone.id, cras_audio_handler_->GetPrimaryActiveOutputNode()); | 1118 EXPECT_EQ(kHeadphone->id, cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 1215 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); | 1119 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
| 1216 | 1120 |
| 1217 // Select the speaker to be the active output device. | 1121 // Select the speaker to be the active output device. |
| 1218 AudioDevice internal_speaker(kInternalSpeaker); | 1122 AudioDevice internal_speaker(GenerateAudioNode(kInternalSpeaker)); |
| 1219 cras_audio_handler_->SwitchToDevice(internal_speaker, true, | 1123 cras_audio_handler_->SwitchToDevice(internal_speaker, true, |
| 1220 CrasAudioHandler::ACTIVATE_BY_USER); | 1124 CrasAudioHandler::ACTIVATE_BY_USER); |
| 1221 | 1125 |
| 1222 // Verify the active output is switched to internal speaker, and the | 1126 // Verify the active output is switched to internal speaker, and the |
| 1223 // ActiveOutputNodeChanged event is fired. | 1127 // ActiveOutputNodeChanged event is fired. |
| 1224 EXPECT_EQ(2, test_observer_->active_output_node_changed_count()); | 1128 EXPECT_EQ(2, test_observer_->active_output_node_changed_count()); |
| 1225 EXPECT_TRUE( | 1129 EXPECT_TRUE( |
| 1226 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); | 1130 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
| 1227 EXPECT_EQ(kInternalSpeaker.id, active_output.id); | 1131 EXPECT_EQ(kInternalSpeaker->id, active_output.id); |
| 1228 EXPECT_EQ(kInternalSpeaker.id, | 1132 EXPECT_EQ(kInternalSpeaker->id, |
| 1229 cras_audio_handler_->GetPrimaryActiveOutputNode()); | 1133 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 1230 | 1134 |
| 1231 // Unplug the usb headphone. | 1135 // Unplug the usb headphone. |
| 1232 audio_nodes.clear(); | 1136 audio_nodes.clear(); |
| 1233 AudioNode internal_speaker_node(kInternalSpeaker); | 1137 AudioNode internal_speaker_node(GenerateAudioNode(kInternalSpeaker)); |
| 1234 internal_speaker_node.active = true; | 1138 internal_speaker_node.active = true; |
| 1235 internal_speaker_node.plugged_time = 70000000; | 1139 internal_speaker_node.plugged_time = 70000000; |
| 1236 audio_nodes.push_back(internal_speaker_node); | 1140 audio_nodes.push_back(internal_speaker_node); |
| 1237 headphone_jack.active = false; | 1141 headphone_jack.active = false; |
| 1238 audio_nodes.push_back(headphone_jack); | 1142 audio_nodes.push_back(headphone_jack); |
| 1239 ChangeAudioNodes(audio_nodes); | 1143 ChangeAudioNodes(audio_nodes); |
| 1240 | 1144 |
| 1241 // Verify the AudioNodesChanged event is fired and one audio device is | 1145 // Verify the AudioNodesChanged event is fired and one audio device is |
| 1242 // removed. | 1146 // removed. |
| 1243 EXPECT_EQ(2, test_observer_->audio_nodes_changed_count()); | 1147 EXPECT_EQ(2, test_observer_->audio_nodes_changed_count()); |
| 1244 cras_audio_handler_->GetAudioDevices(&audio_devices); | 1148 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 1245 EXPECT_EQ(init_nodes_size, audio_devices.size()); | 1149 EXPECT_EQ(init_nodes_size, audio_devices.size()); |
| 1246 | 1150 |
| 1247 // Verify the active output device remains to be speaker. | 1151 // Verify the active output device remains to be speaker. |
| 1248 EXPECT_EQ(2, test_observer_->active_output_node_changed_count()); | 1152 EXPECT_EQ(2, test_observer_->active_output_node_changed_count()); |
| 1249 EXPECT_TRUE( | 1153 EXPECT_TRUE( |
| 1250 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); | 1154 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
| 1251 EXPECT_EQ(kInternalSpeaker.id, active_output.id); | 1155 EXPECT_EQ(kInternalSpeaker->id, active_output.id); |
| 1252 EXPECT_EQ(kInternalSpeaker.id, | 1156 EXPECT_EQ(kInternalSpeaker->id, |
| 1253 cras_audio_handler_->GetPrimaryActiveOutputNode()); | 1157 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 1254 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); | 1158 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
| 1255 } | 1159 } |
| 1256 | 1160 |
| 1257 TEST_F(CrasAudioHandlerTest, OneActiveAudioOutputAfterLoginNewUserSession) { | 1161 TEST_P(CrasAudioHandlerTest, OneActiveAudioOutputAfterLoginNewUserSession) { |
| 1258 // This tests the case found with crbug.com/273271. | 1162 // This tests the case found with crbug.com/273271. |
| 1259 // Initialize with internal speaker, bluetooth headphone and headphone jack | 1163 // Initialize with internal speaker, bluetooth headphone and headphone jack |
| 1260 // for a new chrome session after user signs out from the previous session. | 1164 // for a new chrome session after user signs out from the previous session. |
| 1261 // Headphone jack is plugged in later than bluetooth headphone, but bluetooth | 1165 // Headphone jack is plugged in later than bluetooth headphone, but bluetooth |
| 1262 // headphone is selected as the active output by user from previous user | 1166 // headphone is selected as the active output by user from previous user |
| 1263 // session. | 1167 // session. |
| 1264 AudioNodeList audio_nodes; | 1168 AudioNodeList audio_nodes = GenerateAudioNodeList({kInternalSpeaker}); |
| 1265 audio_nodes.push_back(kInternalSpeaker); | 1169 AudioNode bluetooth_headphone = GenerateAudioNode(kBluetoothHeadset); |
| 1266 AudioNode bluetooth_headphone(kBluetoothHeadset); | |
| 1267 bluetooth_headphone.active = true; | 1170 bluetooth_headphone.active = true; |
| 1268 bluetooth_headphone.plugged_time = 70000000; | 1171 bluetooth_headphone.plugged_time = 70000000; |
| 1269 audio_nodes.push_back(bluetooth_headphone); | 1172 audio_nodes.push_back(bluetooth_headphone); |
| 1270 AudioNode headphone_jack(kHeadphone); | 1173 AudioNode headphone_jack = GenerateAudioNode(kHeadphone); |
| 1271 headphone_jack.plugged_time = 80000000; | 1174 headphone_jack.plugged_time = 80000000; |
| 1272 audio_nodes.push_back(headphone_jack); | 1175 audio_nodes.push_back(headphone_jack); |
| 1273 SetUpCrasAudioHandlerWithPrimaryActiveNode(audio_nodes, bluetooth_headphone); | 1176 SetUpCrasAudioHandlerWithPrimaryActiveNode(audio_nodes, bluetooth_headphone); |
| 1274 const size_t init_nodes_size = audio_nodes.size(); | 1177 const size_t init_nodes_size = audio_nodes.size(); |
| 1275 | 1178 |
| 1276 // Verify the audio devices size. | 1179 // Verify the audio devices size. |
| 1277 AudioDeviceList audio_devices; | 1180 AudioDeviceList audio_devices; |
| 1278 cras_audio_handler_->GetAudioDevices(&audio_devices); | 1181 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 1279 EXPECT_EQ(init_nodes_size, audio_devices.size()); | 1182 EXPECT_EQ(init_nodes_size, audio_devices.size()); |
| 1280 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); | 1183 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); |
| 1281 | 1184 |
| 1282 // Verify the headphone jack is selected as the active output and all other | 1185 // Verify the headphone jack is selected as the active output and all other |
| 1283 // audio devices are not active. | 1186 // audio devices are not active. |
| 1284 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); | 1187 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); |
| 1285 AudioDevice active_output; | 1188 AudioDevice active_output; |
| 1286 EXPECT_TRUE( | 1189 EXPECT_TRUE( |
| 1287 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); | 1190 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
| 1288 EXPECT_EQ(kHeadphone.id, active_output.id); | 1191 EXPECT_EQ(kHeadphone->id, active_output.id); |
| 1289 EXPECT_EQ(kHeadphone.id, cras_audio_handler_->GetPrimaryActiveOutputNode()); | 1192 EXPECT_EQ(kHeadphone->id, cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 1290 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); | 1193 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
| 1291 for (size_t i = 0; i < audio_devices.size(); ++i) { | 1194 for (size_t i = 0; i < audio_devices.size(); ++i) { |
| 1292 if (audio_devices[i].id != kHeadphone.id) | 1195 if (audio_devices[i].id != kHeadphone->id) |
| 1293 EXPECT_FALSE(audio_devices[i].active); | 1196 EXPECT_FALSE(audio_devices[i].active); |
| 1294 } | 1197 } |
| 1295 } | 1198 } |
| 1296 | 1199 |
| 1297 TEST_F(CrasAudioHandlerTest, BluetoothSpeakerIdChangedOnFly) { | 1200 TEST_P(CrasAudioHandlerTest, BluetoothSpeakerIdChangedOnFly) { |
| 1298 // Initialize with internal speaker and bluetooth headset. | 1201 // Initialize with internal speaker and bluetooth headset. |
| 1299 AudioNodeList audio_nodes; | 1202 AudioNodeList audio_nodes = |
| 1300 audio_nodes.push_back(kInternalSpeaker); | 1203 GenerateAudioNodeList({kInternalSpeaker, kBluetoothHeadset}); |
| 1301 audio_nodes.push_back(kBluetoothHeadset); | |
| 1302 SetUpCrasAudioHandler(audio_nodes); | 1204 SetUpCrasAudioHandler(audio_nodes); |
| 1303 const size_t init_nodes_size = audio_nodes.size(); | 1205 const size_t init_nodes_size = audio_nodes.size(); |
| 1304 | 1206 |
| 1305 // Verify the audio devices size. | 1207 // Verify the audio devices size. |
| 1306 AudioDeviceList audio_devices; | 1208 AudioDeviceList audio_devices; |
| 1307 cras_audio_handler_->GetAudioDevices(&audio_devices); | 1209 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 1308 EXPECT_EQ(init_nodes_size, audio_devices.size()); | 1210 EXPECT_EQ(init_nodes_size, audio_devices.size()); |
| 1309 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); | 1211 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); |
| 1310 | 1212 |
| 1311 // Verify the bluetooth headset is selected as the active output and all other | 1213 // Verify the bluetooth headset is selected as the active output and all other |
| 1312 // audio devices are not active. | 1214 // audio devices are not active. |
| 1313 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); | 1215 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); |
| 1314 AudioDevice active_output; | 1216 AudioDevice active_output; |
| 1315 EXPECT_TRUE( | 1217 EXPECT_TRUE( |
| 1316 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); | 1218 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
| 1317 EXPECT_EQ(kBluetoothHeadset.id, active_output.id); | 1219 EXPECT_EQ(kBluetoothHeadset->id, active_output.id); |
| 1318 EXPECT_EQ(kBluetoothHeadset.id, | 1220 EXPECT_EQ(kBluetoothHeadset->id, |
| 1319 cras_audio_handler_->GetPrimaryActiveOutputNode()); | 1221 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 1320 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); | 1222 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
| 1321 | 1223 |
| 1322 // Cras changes the bluetooth headset's id on the fly. | 1224 // Cras changes the bluetooth headset's id on the fly. |
| 1323 audio_nodes.clear(); | 1225 audio_nodes.clear(); |
| 1324 AudioNode internal_speaker(kInternalSpeaker); | 1226 AudioNode internal_speaker(GenerateAudioNode(kInternalSpeaker)); |
| 1325 internal_speaker.active = false; | 1227 internal_speaker.active = false; |
| 1326 audio_nodes.push_back(internal_speaker); | 1228 audio_nodes.push_back(internal_speaker); |
| 1327 AudioNode bluetooth_headphone(kBluetoothHeadset); | 1229 AudioNode bluetooth_headphone = GenerateAudioNode(kBluetoothHeadset); |
| 1328 // Change bluetooth headphone id. | 1230 // Change bluetooth headphone id. |
| 1329 bluetooth_headphone.id = kBluetoothHeadsetId + 20000; | 1231 bluetooth_headphone.id = kBluetoothHeadsetId + 20000; |
| 1330 bluetooth_headphone.active = false; | 1232 bluetooth_headphone.active = false; |
| 1331 audio_nodes.push_back(bluetooth_headphone); | 1233 audio_nodes.push_back(bluetooth_headphone); |
| 1332 ChangeAudioNodes(audio_nodes); | 1234 ChangeAudioNodes(audio_nodes); |
| 1333 | 1235 |
| 1334 // Verify NodesChanged event is fired, and the audio devices size is not | 1236 // Verify NodesChanged event is fired, and the audio devices size is not |
| 1335 // changed. | 1237 // changed. |
| 1336 audio_devices.clear(); | 1238 audio_devices.clear(); |
| 1337 cras_audio_handler_->GetAudioDevices(&audio_devices); | 1239 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 1338 EXPECT_EQ(init_nodes_size, audio_devices.size()); | 1240 EXPECT_EQ(init_nodes_size, audio_devices.size()); |
| 1339 EXPECT_EQ(1, test_observer_->audio_nodes_changed_count()); | 1241 EXPECT_EQ(1, test_observer_->audio_nodes_changed_count()); |
| 1340 | 1242 |
| 1341 // Verify ActiveOutputNodeChanged event is fired, and active device should be | 1243 // Verify ActiveOutputNodeChanged event is fired, and active device should be |
| 1342 // bluetooth headphone. | 1244 // bluetooth headphone. |
| 1343 EXPECT_EQ(1, test_observer_->active_output_node_changed_count()); | 1245 EXPECT_EQ(1, test_observer_->active_output_node_changed_count()); |
| 1344 EXPECT_TRUE( | 1246 EXPECT_TRUE( |
| 1345 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); | 1247 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
| 1346 EXPECT_EQ(bluetooth_headphone.id, active_output.id); | 1248 EXPECT_EQ(bluetooth_headphone.id, active_output.id); |
| 1347 } | 1249 } |
| 1348 | 1250 |
| 1349 TEST_F(CrasAudioHandlerTest, PlugUSBMic) { | 1251 TEST_P(CrasAudioHandlerTest, PlugUSBMic) { |
| 1350 // Set up initial audio devices, only with internal mic. | 1252 // Set up initial audio devices, only with internal mic. |
| 1351 AudioNodeList audio_nodes; | 1253 AudioNodeList audio_nodes = GenerateAudioNodeList({kInternalMic}); |
| 1352 audio_nodes.push_back(kInternalMic); | |
| 1353 SetUpCrasAudioHandler(audio_nodes); | 1254 SetUpCrasAudioHandler(audio_nodes); |
| 1354 const size_t init_nodes_size = audio_nodes.size(); | 1255 const size_t init_nodes_size = audio_nodes.size(); |
| 1355 | 1256 |
| 1356 // Verify the audio devices size. | 1257 // Verify the audio devices size. |
| 1357 AudioDeviceList audio_devices; | 1258 AudioDeviceList audio_devices; |
| 1358 cras_audio_handler_->GetAudioDevices(&audio_devices); | 1259 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 1359 EXPECT_EQ(init_nodes_size, audio_devices.size()); | 1260 EXPECT_EQ(init_nodes_size, audio_devices.size()); |
| 1360 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); | 1261 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); |
| 1361 | 1262 |
| 1362 // Verify the internal mic is selected as the active input. | 1263 // Verify the internal mic is selected as the active input. |
| 1363 EXPECT_EQ(0, test_observer_->active_input_node_changed_count()); | 1264 EXPECT_EQ(0, test_observer_->active_input_node_changed_count()); |
| 1364 EXPECT_EQ(kInternalMic.id, cras_audio_handler_->GetPrimaryActiveInputNode()); | 1265 EXPECT_EQ(kInternalMic->id, cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 1365 EXPECT_FALSE(cras_audio_handler_->has_alternative_input()); | 1266 EXPECT_FALSE(cras_audio_handler_->has_alternative_input()); |
| 1366 | 1267 |
| 1367 // Plug the USB Mic. | 1268 // Plug the USB Mic. |
| 1368 audio_nodes.clear(); | 1269 audio_nodes.clear(); |
| 1369 AudioNode internal_mic(kInternalMic); | 1270 AudioNode internal_mic(GenerateAudioNode(kInternalMic)); |
| 1370 internal_mic.active = true; | 1271 internal_mic.active = true; |
| 1371 audio_nodes.push_back(internal_mic); | 1272 audio_nodes.push_back(internal_mic); |
| 1372 audio_nodes.push_back(kUSBMic); | 1273 audio_nodes.push_back(GenerateAudioNode(kUSBMic)); |
| 1373 ChangeAudioNodes(audio_nodes); | 1274 ChangeAudioNodes(audio_nodes); |
| 1374 | 1275 |
| 1375 // Verify the AudioNodesChanged event is fired and new audio device is added. | 1276 // Verify the AudioNodesChanged event is fired and new audio device is added. |
| 1376 EXPECT_EQ(1, test_observer_->audio_nodes_changed_count()); | 1277 EXPECT_EQ(1, test_observer_->audio_nodes_changed_count()); |
| 1377 cras_audio_handler_->GetAudioDevices(&audio_devices); | 1278 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 1378 EXPECT_EQ(init_nodes_size + 1, audio_devices.size()); | 1279 EXPECT_EQ(init_nodes_size + 1, audio_devices.size()); |
| 1379 | 1280 |
| 1380 // Verify the active input device is switched to USB mic and | 1281 // Verify the active input device is switched to USB mic and |
| 1381 // and ActiveInputChanged event is fired. | 1282 // and ActiveInputChanged event is fired. |
| 1382 EXPECT_EQ(1, test_observer_->active_input_node_changed_count()); | 1283 EXPECT_EQ(1, test_observer_->active_input_node_changed_count()); |
| 1383 EXPECT_EQ(kUSBMicId, cras_audio_handler_->GetPrimaryActiveInputNode()); | 1284 EXPECT_EQ(kUSBMicId, cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 1384 EXPECT_TRUE(cras_audio_handler_->has_alternative_input()); | 1285 EXPECT_TRUE(cras_audio_handler_->has_alternative_input()); |
| 1385 } | 1286 } |
| 1386 | 1287 |
| 1387 TEST_F(CrasAudioHandlerTest, UnplugUSBMic) { | 1288 TEST_P(CrasAudioHandlerTest, UnplugUSBMic) { |
| 1388 // Set up initial audio devices, with internal mic and USB Mic. | 1289 // Set up initial audio devices, with internal mic and USB Mic. |
| 1389 AudioNodeList audio_nodes; | 1290 AudioNodeList audio_nodes = GenerateAudioNodeList({kInternalMic, kUSBMic}); |
| 1390 audio_nodes.push_back(kInternalMic); | |
| 1391 audio_nodes.push_back(kUSBMic); | |
| 1392 SetUpCrasAudioHandler(audio_nodes); | 1291 SetUpCrasAudioHandler(audio_nodes); |
| 1393 const size_t init_nodes_size = audio_nodes.size(); | 1292 const size_t init_nodes_size = audio_nodes.size(); |
| 1394 | 1293 |
| 1395 // Verify the audio devices size. | 1294 // Verify the audio devices size. |
| 1396 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); | 1295 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); |
| 1397 AudioDeviceList audio_devices; | 1296 AudioDeviceList audio_devices; |
| 1398 cras_audio_handler_->GetAudioDevices(&audio_devices); | 1297 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 1399 EXPECT_EQ(init_nodes_size, audio_devices.size()); | 1298 EXPECT_EQ(init_nodes_size, audio_devices.size()); |
| 1400 | 1299 |
| 1401 // Verify the USB mic is selected as the active output. | 1300 // Verify the USB mic is selected as the active output. |
| 1402 EXPECT_EQ(0, test_observer_->active_input_node_changed_count()); | 1301 EXPECT_EQ(0, test_observer_->active_input_node_changed_count()); |
| 1403 EXPECT_EQ(kUSBMicId, cras_audio_handler_->GetPrimaryActiveInputNode()); | 1302 EXPECT_EQ(kUSBMicId, cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 1404 EXPECT_TRUE(cras_audio_handler_->has_alternative_input()); | 1303 EXPECT_TRUE(cras_audio_handler_->has_alternative_input()); |
| 1405 | 1304 |
| 1406 // Unplug the USB Mic. | 1305 // Unplug the USB Mic. |
| 1407 audio_nodes.clear(); | 1306 audio_nodes.clear(); |
| 1408 audio_nodes.push_back(kInternalMic); | 1307 audio_nodes.push_back(GenerateAudioNode(kInternalMic)); |
| 1409 ChangeAudioNodes(audio_nodes); | 1308 ChangeAudioNodes(audio_nodes); |
| 1410 | 1309 |
| 1411 // Verify the AudioNodesChanged event is fired, and one audio device is | 1310 // Verify the AudioNodesChanged event is fired, and one audio device is |
| 1412 // removed. | 1311 // removed. |
| 1413 EXPECT_EQ(1, test_observer_->audio_nodes_changed_count()); | 1312 EXPECT_EQ(1, test_observer_->audio_nodes_changed_count()); |
| 1414 cras_audio_handler_->GetAudioDevices(&audio_devices); | 1313 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 1415 EXPECT_EQ(init_nodes_size - 1, audio_devices.size()); | 1314 EXPECT_EQ(init_nodes_size - 1, audio_devices.size()); |
| 1416 | 1315 |
| 1417 // Verify the active input device is switched to internal mic, and | 1316 // Verify the active input device is switched to internal mic, and |
| 1418 // and ActiveInputChanged event is fired. | 1317 // and ActiveInputChanged event is fired. |
| 1419 EXPECT_EQ(1, test_observer_->active_input_node_changed_count()); | 1318 EXPECT_EQ(1, test_observer_->active_input_node_changed_count()); |
| 1420 EXPECT_EQ(kInternalMic.id, cras_audio_handler_->GetPrimaryActiveInputNode()); | 1319 EXPECT_EQ(kInternalMic->id, cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 1421 EXPECT_FALSE(cras_audio_handler_->has_alternative_input()); | 1320 EXPECT_FALSE(cras_audio_handler_->has_alternative_input()); |
| 1422 } | 1321 } |
| 1423 | 1322 |
| 1424 TEST_F(CrasAudioHandlerTest, PlugUSBMicNotAffectActiveOutput) { | 1323 TEST_P(CrasAudioHandlerTest, PlugUSBMicNotAffectActiveOutput) { |
| 1425 // Set up initial audio devices. | 1324 // Set up initial audio devices. |
| 1426 AudioNodeList audio_nodes; | 1325 AudioNodeList audio_nodes = |
| 1427 audio_nodes.push_back(kInternalSpeaker); | 1326 GenerateAudioNodeList({kInternalSpeaker, kHeadphone, kInternalMic}); |
| 1428 audio_nodes.push_back(kHeadphone); | |
| 1429 audio_nodes.push_back(kInternalMic); | |
| 1430 SetUpCrasAudioHandler(audio_nodes); | 1327 SetUpCrasAudioHandler(audio_nodes); |
| 1431 const size_t init_nodes_size = audio_nodes.size(); | 1328 const size_t init_nodes_size = audio_nodes.size(); |
| 1432 | 1329 |
| 1433 // Verify the audio devices size. | 1330 // Verify the audio devices size. |
| 1434 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); | 1331 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); |
| 1435 AudioDeviceList audio_devices; | 1332 AudioDeviceList audio_devices; |
| 1436 cras_audio_handler_->GetAudioDevices(&audio_devices); | 1333 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 1437 EXPECT_EQ(init_nodes_size, audio_devices.size()); | 1334 EXPECT_EQ(init_nodes_size, audio_devices.size()); |
| 1438 | 1335 |
| 1439 // Verify the internal mic is selected as the active input. | 1336 // Verify the internal mic is selected as the active input. |
| 1440 EXPECT_EQ(0, test_observer_->active_input_node_changed_count()); | 1337 EXPECT_EQ(0, test_observer_->active_input_node_changed_count()); |
| 1441 EXPECT_EQ(kInternalMicId, cras_audio_handler_->GetPrimaryActiveInputNode()); | 1338 EXPECT_EQ(kInternalMicId, cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 1442 EXPECT_FALSE(cras_audio_handler_->has_alternative_input()); | 1339 EXPECT_FALSE(cras_audio_handler_->has_alternative_input()); |
| 1443 | 1340 |
| 1444 // Verify the headphone is selected as the active output. | 1341 // Verify the headphone is selected as the active output. |
| 1445 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); | 1342 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); |
| 1446 EXPECT_EQ(kHeadphoneId, cras_audio_handler_->GetPrimaryActiveOutputNode()); | 1343 EXPECT_EQ(kHeadphoneId, cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 1447 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); | 1344 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
| 1448 | 1345 |
| 1449 // Switch the active output to internal speaker. | 1346 // Switch the active output to internal speaker. |
| 1450 AudioDevice internal_speaker(kInternalSpeaker); | 1347 AudioDevice internal_speaker(GenerateAudioNode(kInternalSpeaker)); |
| 1451 cras_audio_handler_->SwitchToDevice(internal_speaker, true, | 1348 cras_audio_handler_->SwitchToDevice(internal_speaker, true, |
| 1452 CrasAudioHandler::ACTIVATE_BY_USER); | 1349 CrasAudioHandler::ACTIVATE_BY_USER); |
| 1453 | 1350 |
| 1454 // Verify the active output is switched to internal speaker, and the | 1351 // Verify the active output is switched to internal speaker, and the |
| 1455 // ActiveOutputNodeChanged event is fired. | 1352 // ActiveOutputNodeChanged event is fired. |
| 1456 EXPECT_EQ(1, test_observer_->active_output_node_changed_count()); | 1353 EXPECT_EQ(1, test_observer_->active_output_node_changed_count()); |
| 1457 AudioDevice active_output; | 1354 AudioDevice active_output; |
| 1458 EXPECT_TRUE( | 1355 EXPECT_TRUE( |
| 1459 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); | 1356 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
| 1460 EXPECT_EQ(kInternalSpeaker.id, active_output.id); | 1357 EXPECT_EQ(kInternalSpeaker->id, active_output.id); |
| 1461 EXPECT_EQ(kInternalSpeaker.id, | 1358 EXPECT_EQ(kInternalSpeaker->id, |
| 1462 cras_audio_handler_->GetPrimaryActiveOutputNode()); | 1359 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 1463 | 1360 |
| 1464 // Plug the USB Mic. | 1361 // Plug the USB Mic. |
| 1465 audio_nodes.clear(); | 1362 audio_nodes.clear(); |
| 1466 AudioNode internal_speaker_node(kInternalSpeaker); | 1363 AudioNode internal_speaker_node = GenerateAudioNode(kInternalSpeaker); |
| 1467 internal_speaker_node.active = true; | 1364 internal_speaker_node.active = true; |
| 1468 audio_nodes.push_back(internal_speaker_node); | 1365 audio_nodes.push_back(internal_speaker_node); |
| 1469 audio_nodes.push_back(kHeadphone); | 1366 audio_nodes.push_back(GenerateAudioNode(kHeadphone)); |
| 1470 AudioNode internal_mic(kInternalMic); | 1367 AudioNode internal_mic = GenerateAudioNode(kInternalMic); |
| 1471 internal_mic.active = true; | 1368 internal_mic.active = true; |
| 1472 audio_nodes.push_back(internal_mic); | 1369 audio_nodes.push_back(internal_mic); |
| 1473 audio_nodes.push_back(kUSBMic); | 1370 audio_nodes.push_back(GenerateAudioNode(kUSBMic)); |
| 1474 ChangeAudioNodes(audio_nodes); | 1371 ChangeAudioNodes(audio_nodes); |
| 1475 | 1372 |
| 1476 // Verify the AudioNodesChanged event is fired, one new device is added. | 1373 // Verify the AudioNodesChanged event is fired, one new device is added. |
| 1477 EXPECT_EQ(1, test_observer_->audio_nodes_changed_count()); | 1374 EXPECT_EQ(1, test_observer_->audio_nodes_changed_count()); |
| 1478 cras_audio_handler_->GetAudioDevices(&audio_devices); | 1375 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 1479 EXPECT_EQ(init_nodes_size + 1, audio_devices.size()); | 1376 EXPECT_EQ(init_nodes_size + 1, audio_devices.size()); |
| 1480 | 1377 |
| 1481 // Verify the active input device is switched to USB mic, and | 1378 // Verify the active input device is switched to USB mic, and |
| 1482 // and ActiveInputChanged event is fired. | 1379 // and ActiveInputChanged event is fired. |
| 1483 EXPECT_EQ(1, test_observer_->active_input_node_changed_count()); | 1380 EXPECT_EQ(1, test_observer_->active_input_node_changed_count()); |
| 1484 EXPECT_EQ(kUSBMic.id, cras_audio_handler_->GetPrimaryActiveInputNode()); | 1381 EXPECT_EQ(kUSBMic->id, cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 1485 EXPECT_TRUE(cras_audio_handler_->has_alternative_input()); | 1382 EXPECT_TRUE(cras_audio_handler_->has_alternative_input()); |
| 1486 | 1383 |
| 1487 // Verify the active output device is not changed. | 1384 // Verify the active output device is not changed. |
| 1488 EXPECT_EQ(1, test_observer_->active_output_node_changed_count()); | 1385 EXPECT_EQ(1, test_observer_->active_output_node_changed_count()); |
| 1489 EXPECT_TRUE( | 1386 EXPECT_TRUE( |
| 1490 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); | 1387 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
| 1491 EXPECT_EQ(kInternalSpeaker.id, active_output.id); | 1388 EXPECT_EQ(kInternalSpeaker->id, active_output.id); |
| 1492 EXPECT_EQ(kInternalSpeaker.id, | 1389 EXPECT_EQ(kInternalSpeaker->id, |
| 1493 cras_audio_handler_->GetPrimaryActiveOutputNode()); | 1390 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 1494 } | 1391 } |
| 1495 | 1392 |
| 1496 TEST_F(CrasAudioHandlerTest, PlugHeadphoneAutoUnplugSpeakerWithActiveUSB) { | 1393 TEST_P(CrasAudioHandlerTest, PlugHeadphoneAutoUnplugSpeakerWithActiveUSB) { |
| 1497 // Set up initial audio devices. | 1394 // Set up initial audio devices. |
| 1498 AudioNodeList audio_nodes; | 1395 AudioNodeList audio_nodes = |
| 1499 audio_nodes.push_back(kUSBHeadphone1); | 1396 GenerateAudioNodeList({kUSBHeadphone1, kInternalSpeaker, kInternalMic}); |
| 1500 audio_nodes.push_back(kInternalSpeaker); | |
| 1501 audio_nodes.push_back(kInternalMic); | |
| 1502 SetUpCrasAudioHandler(audio_nodes); | 1397 SetUpCrasAudioHandler(audio_nodes); |
| 1503 const size_t init_nodes_size = audio_nodes.size(); | 1398 const size_t init_nodes_size = audio_nodes.size(); |
| 1504 | 1399 |
| 1505 // Verify the audio devices size. | 1400 // Verify the audio devices size. |
| 1506 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); | 1401 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); |
| 1507 AudioDeviceList audio_devices; | 1402 AudioDeviceList audio_devices; |
| 1508 cras_audio_handler_->GetAudioDevices(&audio_devices); | 1403 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 1509 EXPECT_EQ(init_nodes_size, audio_devices.size()); | 1404 EXPECT_EQ(init_nodes_size, audio_devices.size()); |
| 1510 | 1405 |
| 1511 // Verify the internal mic is selected as the active input. | 1406 // Verify the internal mic is selected as the active input. |
| 1512 EXPECT_EQ(0, test_observer_->active_input_node_changed_count()); | 1407 EXPECT_EQ(0, test_observer_->active_input_node_changed_count()); |
| 1513 EXPECT_EQ(kInternalMicId, cras_audio_handler_->GetPrimaryActiveInputNode()); | 1408 EXPECT_EQ(kInternalMicId, cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 1514 EXPECT_FALSE(cras_audio_handler_->has_alternative_input()); | 1409 EXPECT_FALSE(cras_audio_handler_->has_alternative_input()); |
| 1515 | 1410 |
| 1516 // Verify the USB headphone is selected as the active output. | 1411 // Verify the USB headphone is selected as the active output. |
| 1517 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); | 1412 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); |
| 1518 EXPECT_EQ(kUSBHeadphoneId1, | 1413 EXPECT_EQ(kUSBHeadphoneId1, |
| 1519 cras_audio_handler_->GetPrimaryActiveOutputNode()); | 1414 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 1520 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); | 1415 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
| 1521 | 1416 |
| 1522 // Plug the headphone and auto-unplug internal speaker. | 1417 // Plug the headphone and auto-unplug internal speaker. |
| 1523 audio_nodes.clear(); | 1418 audio_nodes.clear(); |
| 1524 AudioNode usb_headphone_node(kUSBHeadphone1); | 1419 AudioNode usb_headphone_node = GenerateAudioNode(kUSBHeadphone1); |
| 1525 usb_headphone_node.active = true; | 1420 usb_headphone_node.active = true; |
| 1526 audio_nodes.push_back(usb_headphone_node); | 1421 audio_nodes.push_back(usb_headphone_node); |
| 1527 AudioNode headphone_node(kHeadphone); | 1422 AudioNode headphone_node = GenerateAudioNode(kHeadphone); |
| 1528 headphone_node.plugged_time = 1000; | 1423 headphone_node.plugged_time = 1000; |
| 1529 audio_nodes.push_back(headphone_node); | 1424 audio_nodes.push_back(headphone_node); |
| 1530 AudioNode internal_mic(kInternalMic); | 1425 AudioNode internal_mic = GenerateAudioNode(kInternalMic); |
| 1531 internal_mic.active = true; | 1426 internal_mic.active = true; |
| 1532 audio_nodes.push_back(internal_mic); | 1427 audio_nodes.push_back(internal_mic); |
| 1533 ChangeAudioNodes(audio_nodes); | 1428 ChangeAudioNodes(audio_nodes); |
| 1534 | 1429 |
| 1535 // Verify the AudioNodesChanged event is fired, with nodes count unchanged. | 1430 // Verify the AudioNodesChanged event is fired, with nodes count unchanged. |
| 1536 EXPECT_EQ(1, test_observer_->audio_nodes_changed_count()); | 1431 EXPECT_EQ(1, test_observer_->audio_nodes_changed_count()); |
| 1537 cras_audio_handler_->GetAudioDevices(&audio_devices); | 1432 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 1538 EXPECT_EQ(init_nodes_size, audio_devices.size()); | 1433 EXPECT_EQ(init_nodes_size, audio_devices.size()); |
| 1539 | 1434 |
| 1540 // Verify the active output device is switched to headphone, and | 1435 // Verify the active output device is switched to headphone, and |
| 1541 // an ActiveOutputChanged event is fired. | 1436 // an ActiveOutputChanged event is fired. |
| 1542 EXPECT_EQ(1, test_observer_->active_output_node_changed_count()); | 1437 EXPECT_EQ(1, test_observer_->active_output_node_changed_count()); |
| 1543 EXPECT_EQ(kHeadphone.id, cras_audio_handler_->GetPrimaryActiveOutputNode()); | 1438 EXPECT_EQ(kHeadphone->id, cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 1544 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); | 1439 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
| 1545 | 1440 |
| 1546 // Unplug the headphone and internal speaker auto-plugs back. | 1441 // Unplug the headphone and internal speaker auto-plugs back. |
| 1547 audio_nodes.clear(); | 1442 audio_nodes.clear(); |
| 1548 audio_nodes.push_back(kUSBHeadphone1); | 1443 audio_nodes.push_back(GenerateAudioNode(kUSBHeadphone1)); |
| 1549 AudioNode internal_speaker_node(kInternalSpeaker); | 1444 AudioNode internal_speaker_node = GenerateAudioNode(kInternalSpeaker); |
| 1550 internal_speaker_node.plugged_time = 2000; | 1445 internal_speaker_node.plugged_time = 2000; |
| 1551 audio_nodes.push_back(internal_speaker_node); | 1446 audio_nodes.push_back(internal_speaker_node); |
| 1552 audio_nodes.push_back(internal_mic); | 1447 audio_nodes.push_back(internal_mic); |
| 1553 ChangeAudioNodes(audio_nodes); | 1448 ChangeAudioNodes(audio_nodes); |
| 1554 | 1449 |
| 1555 // Verify the AudioNodesChanged event is fired, with nodes count unchanged. | 1450 // Verify the AudioNodesChanged event is fired, with nodes count unchanged. |
| 1556 EXPECT_EQ(2, test_observer_->audio_nodes_changed_count()); | 1451 EXPECT_EQ(2, test_observer_->audio_nodes_changed_count()); |
| 1557 cras_audio_handler_->GetAudioDevices(&audio_devices); | 1452 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 1558 EXPECT_EQ(init_nodes_size, audio_devices.size()); | 1453 EXPECT_EQ(init_nodes_size, audio_devices.size()); |
| 1559 | 1454 |
| 1560 // Verify the active output device is switched back to USB, and | 1455 // Verify the active output device is switched back to USB, and |
| 1561 // an ActiveOutputChanged event is fired. | 1456 // an ActiveOutputChanged event is fired. |
| 1562 EXPECT_EQ(2, test_observer_->active_output_node_changed_count()); | 1457 EXPECT_EQ(2, test_observer_->active_output_node_changed_count()); |
| 1563 EXPECT_EQ(kUSBHeadphone1.id, | 1458 EXPECT_EQ(kUSBHeadphone1->id, |
| 1564 cras_audio_handler_->GetPrimaryActiveOutputNode()); | 1459 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 1565 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); | 1460 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
| 1566 | 1461 |
| 1567 // Verify the active input device is not changed. | 1462 // Verify the active input device is not changed. |
| 1568 EXPECT_EQ(0, test_observer_->active_input_node_changed_count()); | 1463 EXPECT_EQ(0, test_observer_->active_input_node_changed_count()); |
| 1569 EXPECT_EQ(kInternalMic.id, cras_audio_handler_->GetPrimaryActiveInputNode()); | 1464 EXPECT_EQ(kInternalMic->id, cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 1570 } | 1465 } |
| 1571 | 1466 |
| 1572 TEST_F(CrasAudioHandlerTest, PlugMicAutoUnplugInternalMicWithActiveUSB) { | 1467 TEST_P(CrasAudioHandlerTest, PlugMicAutoUnplugInternalMicWithActiveUSB) { |
| 1573 // Set up initial audio devices. | 1468 // Set up initial audio devices. |
| 1574 AudioNodeList audio_nodes; | 1469 AudioNodeList audio_nodes = GenerateAudioNodeList( |
| 1575 audio_nodes.push_back(kUSBHeadphone1); | 1470 {kUSBHeadphone1, kInternalSpeaker, kUSBMic, kInternalMic}); |
| 1576 audio_nodes.push_back(kInternalSpeaker); | |
| 1577 audio_nodes.push_back(kUSBMic); | |
| 1578 audio_nodes.push_back(kInternalMic); | |
| 1579 SetUpCrasAudioHandler(audio_nodes); | 1471 SetUpCrasAudioHandler(audio_nodes); |
| 1580 const size_t init_nodes_size = audio_nodes.size(); | 1472 const size_t init_nodes_size = audio_nodes.size(); |
| 1581 | 1473 |
| 1582 // Verify the audio devices size. | 1474 // Verify the audio devices size. |
| 1583 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); | 1475 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); |
| 1584 AudioDeviceList audio_devices; | 1476 AudioDeviceList audio_devices; |
| 1585 cras_audio_handler_->GetAudioDevices(&audio_devices); | 1477 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 1586 EXPECT_EQ(init_nodes_size, audio_devices.size()); | 1478 EXPECT_EQ(init_nodes_size, audio_devices.size()); |
| 1587 | 1479 |
| 1588 // Verify the internal mic is selected as the active input. | 1480 // Verify the internal mic is selected as the active input. |
| 1589 EXPECT_EQ(0, test_observer_->active_input_node_changed_count()); | 1481 EXPECT_EQ(0, test_observer_->active_input_node_changed_count()); |
| 1590 EXPECT_EQ(kUSBMicId, cras_audio_handler_->GetPrimaryActiveInputNode()); | 1482 EXPECT_EQ(kUSBMicId, cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 1591 EXPECT_TRUE(cras_audio_handler_->has_alternative_input()); | 1483 EXPECT_TRUE(cras_audio_handler_->has_alternative_input()); |
| 1592 | 1484 |
| 1593 // Verify the internal speaker is selected as the active output. | 1485 // Verify the internal speaker is selected as the active output. |
| 1594 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); | 1486 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); |
| 1595 EXPECT_EQ(kUSBHeadphoneId1, | 1487 EXPECT_EQ(kUSBHeadphoneId1, |
| 1596 cras_audio_handler_->GetPrimaryActiveOutputNode()); | 1488 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 1597 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); | 1489 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
| 1598 | 1490 |
| 1599 // Plug the headphone and mic, auto-unplug internal mic and speaker. | 1491 // Plug the headphone and mic, auto-unplug internal mic and speaker. |
| 1600 audio_nodes.clear(); | 1492 audio_nodes.clear(); |
| 1601 AudioNode usb_headphone_node(kUSBHeadphone1); | 1493 AudioNode usb_headphone_node = GenerateAudioNode(kUSBHeadphone1); |
| 1602 usb_headphone_node.active = true; | 1494 usb_headphone_node.active = true; |
| 1603 audio_nodes.push_back(usb_headphone_node); | 1495 audio_nodes.push_back(usb_headphone_node); |
| 1604 AudioNode headphone_node(kHeadphone); | 1496 AudioNode headphone_node = GenerateAudioNode(kHeadphone); |
| 1605 headphone_node.plugged_time = 1000; | 1497 headphone_node.plugged_time = 1000; |
| 1606 audio_nodes.push_back(headphone_node); | 1498 audio_nodes.push_back(headphone_node); |
| 1607 AudioNode usb_mic(kUSBMic); | 1499 AudioNode usb_mic = GenerateAudioNode(kUSBMic); |
| 1608 usb_mic.active = true; | 1500 usb_mic.active = true; |
| 1609 audio_nodes.push_back(usb_mic); | 1501 audio_nodes.push_back(usb_mic); |
| 1610 AudioNode mic_jack(kMicJack); | 1502 AudioNode mic_jack = GenerateAudioNode(kMicJack); |
| 1611 mic_jack.plugged_time = 1000; | 1503 mic_jack.plugged_time = 1000; |
| 1612 audio_nodes.push_back(mic_jack); | 1504 audio_nodes.push_back(mic_jack); |
| 1613 ChangeAudioNodes(audio_nodes); | 1505 ChangeAudioNodes(audio_nodes); |
| 1614 | 1506 |
| 1615 // Verify the AudioNodesChanged event is fired, with nodes count unchanged. | 1507 // Verify the AudioNodesChanged event is fired, with nodes count unchanged. |
| 1616 EXPECT_EQ(1, test_observer_->audio_nodes_changed_count()); | 1508 EXPECT_EQ(1, test_observer_->audio_nodes_changed_count()); |
| 1617 cras_audio_handler_->GetAudioDevices(&audio_devices); | 1509 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 1618 EXPECT_EQ(init_nodes_size, audio_devices.size()); | 1510 EXPECT_EQ(init_nodes_size, audio_devices.size()); |
| 1619 | 1511 |
| 1620 // Verify the active output device is switched to headphone, and | 1512 // Verify the active output device is switched to headphone, and |
| 1621 // an ActiveOutputChanged event is fired. | 1513 // an ActiveOutputChanged event is fired. |
| 1622 EXPECT_EQ(1, test_observer_->active_output_node_changed_count()); | 1514 EXPECT_EQ(1, test_observer_->active_output_node_changed_count()); |
| 1623 EXPECT_EQ(kHeadphone.id, cras_audio_handler_->GetPrimaryActiveOutputNode()); | 1515 EXPECT_EQ(kHeadphone->id, cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 1624 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); | 1516 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
| 1625 | 1517 |
| 1626 // Verify the active input device is switched to mic jack, and | 1518 // Verify the active input device is switched to mic jack, and |
| 1627 // an ActiveInputChanged event is fired. | 1519 // an ActiveInputChanged event is fired. |
| 1628 EXPECT_EQ(1, test_observer_->active_input_node_changed_count()); | 1520 EXPECT_EQ(1, test_observer_->active_input_node_changed_count()); |
| 1629 EXPECT_EQ(kMicJack.id, cras_audio_handler_->GetPrimaryActiveInputNode()); | 1521 EXPECT_EQ(kMicJack->id, cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 1630 EXPECT_TRUE(cras_audio_handler_->has_alternative_input()); | 1522 EXPECT_TRUE(cras_audio_handler_->has_alternative_input()); |
| 1631 | 1523 |
| 1632 // Unplug the headphone and internal speaker auto-plugs back. | 1524 // Unplug the headphone and internal speaker auto-plugs back. |
| 1633 audio_nodes.clear(); | 1525 audio_nodes.clear(); |
| 1634 audio_nodes.push_back(kUSBHeadphone1); | 1526 audio_nodes.push_back(GenerateAudioNode(kUSBHeadphone1)); |
| 1635 AudioNode internal_speaker_node(kInternalSpeaker); | 1527 AudioNode internal_speaker_node = GenerateAudioNode(kInternalSpeaker); |
| 1636 internal_speaker_node.plugged_time = 2000; | 1528 internal_speaker_node.plugged_time = 2000; |
| 1637 audio_nodes.push_back(internal_speaker_node); | 1529 audio_nodes.push_back(internal_speaker_node); |
| 1638 audio_nodes.push_back(kUSBMic); | 1530 audio_nodes.push_back(GenerateAudioNode(kUSBMic)); |
| 1639 AudioNode internal_mic(kInternalMic); | 1531 AudioNode internal_mic = GenerateAudioNode(kInternalMic); |
| 1640 internal_mic.plugged_time = 2000; | 1532 internal_mic.plugged_time = 2000; |
| 1641 audio_nodes.push_back(internal_mic); | 1533 audio_nodes.push_back(internal_mic); |
| 1642 ChangeAudioNodes(audio_nodes); | 1534 ChangeAudioNodes(audio_nodes); |
| 1643 | 1535 |
| 1644 // Verify the AudioNodesChanged event is fired, with nodes count unchanged. | 1536 // Verify the AudioNodesChanged event is fired, with nodes count unchanged. |
| 1645 EXPECT_EQ(2, test_observer_->audio_nodes_changed_count()); | 1537 EXPECT_EQ(2, test_observer_->audio_nodes_changed_count()); |
| 1646 cras_audio_handler_->GetAudioDevices(&audio_devices); | 1538 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 1647 EXPECT_EQ(init_nodes_size, audio_devices.size()); | 1539 EXPECT_EQ(init_nodes_size, audio_devices.size()); |
| 1648 | 1540 |
| 1649 // Verify the active output device is switched back to USB, and | 1541 // Verify the active output device is switched back to USB, and |
| 1650 // an ActiveOutputChanged event is fired. | 1542 // an ActiveOutputChanged event is fired. |
| 1651 EXPECT_EQ(2, test_observer_->active_output_node_changed_count()); | 1543 EXPECT_EQ(2, test_observer_->active_output_node_changed_count()); |
| 1652 EXPECT_EQ(kUSBHeadphone1.id, | 1544 EXPECT_EQ(kUSBHeadphone1->id, |
| 1653 cras_audio_handler_->GetPrimaryActiveOutputNode()); | 1545 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 1654 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); | 1546 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
| 1655 | 1547 |
| 1656 // Verify the active input device is switched back to USB mic, and | 1548 // Verify the active input device is switched back to USB mic, and |
| 1657 // an ActiveInputChanged event is fired. | 1549 // an ActiveInputChanged event is fired. |
| 1658 EXPECT_EQ(2, test_observer_->active_input_node_changed_count()); | 1550 EXPECT_EQ(2, test_observer_->active_input_node_changed_count()); |
| 1659 EXPECT_EQ(kUSBMic.id, cras_audio_handler_->GetPrimaryActiveInputNode()); | 1551 EXPECT_EQ(kUSBMic->id, cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 1660 EXPECT_TRUE(cras_audio_handler_->has_alternative_input()); | 1552 EXPECT_TRUE(cras_audio_handler_->has_alternative_input()); |
| 1661 } | 1553 } |
| 1662 | 1554 |
| 1663 TEST_F(CrasAudioHandlerTest, MultipleNodesChangedSignalsOnPlugInHeadphone) { | 1555 TEST_P(CrasAudioHandlerTest, MultipleNodesChangedSignalsOnPlugInHeadphone) { |
| 1664 // Set up initial audio devices. | 1556 // Set up initial audio devices. |
| 1665 AudioNodeList audio_nodes; | 1557 AudioNodeList audio_nodes = |
| 1666 audio_nodes.push_back(kInternalSpeaker); | 1558 GenerateAudioNodeList({kInternalSpeaker, kBluetoothHeadset}); |
| 1667 audio_nodes.push_back(kBluetoothHeadset); | |
| 1668 SetUpCrasAudioHandler(audio_nodes); | 1559 SetUpCrasAudioHandler(audio_nodes); |
| 1669 const size_t init_nodes_size = audio_nodes.size(); | 1560 const size_t init_nodes_size = audio_nodes.size(); |
| 1670 | 1561 |
| 1671 // Verify the audio devices size. | 1562 // Verify the audio devices size. |
| 1672 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); | 1563 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); |
| 1673 AudioDeviceList audio_devices; | 1564 AudioDeviceList audio_devices; |
| 1674 cras_audio_handler_->GetAudioDevices(&audio_devices); | 1565 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 1675 EXPECT_EQ(init_nodes_size, audio_devices.size()); | 1566 EXPECT_EQ(init_nodes_size, audio_devices.size()); |
| 1676 | 1567 |
| 1677 // Verify the bluetooth headset is selected as the active output. | 1568 // Verify the bluetooth headset is selected as the active output. |
| 1678 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); | 1569 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); |
| 1679 EXPECT_EQ(kBluetoothHeadsetId, | 1570 EXPECT_EQ(kBluetoothHeadsetId, |
| 1680 cras_audio_handler_->GetPrimaryActiveOutputNode()); | 1571 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 1681 AudioDevice active_output; | 1572 AudioDevice active_output; |
| 1682 EXPECT_TRUE( | 1573 EXPECT_TRUE( |
| 1683 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); | 1574 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
| 1684 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); | 1575 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
| 1685 | 1576 |
| 1686 // Plug in headphone, but fire NodesChanged signal twice. | 1577 // Plug in headphone, but fire NodesChanged signal twice. |
| 1687 audio_nodes.clear(); | 1578 audio_nodes.clear(); |
| 1688 audio_nodes.push_back(kInternalSpeaker); | 1579 audio_nodes.push_back(GenerateAudioNode(kInternalSpeaker)); |
| 1689 AudioNode bluetooth_headset(kBluetoothHeadset); | 1580 AudioNode bluetooth_headset = GenerateAudioNode(kBluetoothHeadset); |
| 1690 bluetooth_headset.plugged_time = 1000; | 1581 bluetooth_headset.plugged_time = 1000; |
| 1691 bluetooth_headset.active = true; | 1582 bluetooth_headset.active = true; |
| 1692 audio_nodes.push_back(bluetooth_headset); | 1583 audio_nodes.push_back(bluetooth_headset); |
| 1693 AudioNode headphone(kHeadphone); | 1584 AudioNode headphone = GenerateAudioNode(kHeadphone); |
| 1694 headphone.active = false; | 1585 headphone.active = false; |
| 1695 headphone.plugged_time = 2000; | 1586 headphone.plugged_time = 2000; |
| 1696 audio_nodes.push_back(headphone); | 1587 audio_nodes.push_back(headphone); |
| 1697 ChangeAudioNodes(audio_nodes); | 1588 ChangeAudioNodes(audio_nodes); |
| 1698 ChangeAudioNodes(audio_nodes); | 1589 ChangeAudioNodes(audio_nodes); |
| 1699 | 1590 |
| 1700 // Verify the active output device is set to headphone. | 1591 // Verify the active output device is set to headphone. |
| 1701 EXPECT_EQ(2, test_observer_->audio_nodes_changed_count()); | 1592 EXPECT_EQ(2, test_observer_->audio_nodes_changed_count()); |
| 1702 EXPECT_LE(1, test_observer_->active_output_node_changed_count()); | 1593 EXPECT_LE(1, test_observer_->active_output_node_changed_count()); |
| 1703 EXPECT_EQ(headphone.id, cras_audio_handler_->GetPrimaryActiveOutputNode()); | 1594 EXPECT_EQ(headphone.id, cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 1704 EXPECT_TRUE( | 1595 EXPECT_TRUE( |
| 1705 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); | 1596 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
| 1706 EXPECT_EQ(headphone.id, active_output.id); | 1597 EXPECT_EQ(headphone.id, active_output.id); |
| 1707 | 1598 |
| 1708 // Verfiy the audio devices data is consistent, i.e., the active output device | 1599 // Verfiy the audio devices data is consistent, i.e., the active output device |
| 1709 // should be headphone. | 1600 // should be headphone. |
| 1710 cras_audio_handler_->GetAudioDevices(&audio_devices); | 1601 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 1711 EXPECT_EQ(init_nodes_size + 1, audio_devices.size()); | 1602 EXPECT_EQ(init_nodes_size + 1, audio_devices.size()); |
| 1712 for (size_t i = 0; i < audio_devices.size(); ++i) { | 1603 for (size_t i = 0; i < audio_devices.size(); ++i) { |
| 1713 if (audio_devices[i].id == kInternalSpeaker.id) | 1604 if (audio_devices[i].id == kInternalSpeaker->id) |
| 1714 EXPECT_FALSE(audio_devices[i].active); | 1605 EXPECT_FALSE(audio_devices[i].active); |
| 1715 else if (audio_devices[i].id == bluetooth_headset.id) | 1606 else if (audio_devices[i].id == bluetooth_headset.id) |
| 1716 EXPECT_FALSE(audio_devices[i].active); | 1607 EXPECT_FALSE(audio_devices[i].active); |
| 1717 else if (audio_devices[i].id == headphone.id) | 1608 else if (audio_devices[i].id == headphone.id) |
| 1718 EXPECT_TRUE(audio_devices[i].active); | 1609 EXPECT_TRUE(audio_devices[i].active); |
| 1719 else | 1610 else |
| 1720 NOTREACHED(); | 1611 NOTREACHED(); |
| 1721 } | 1612 } |
| 1722 } | 1613 } |
| 1723 | 1614 |
| 1724 TEST_F(CrasAudioHandlerTest, MultipleNodesChangedSignalsOnPlugInUSBMic) { | 1615 TEST_P(CrasAudioHandlerTest, MultipleNodesChangedSignalsOnPlugInUSBMic) { |
| 1725 // Set up initial audio devices. | 1616 // Set up initial audio devices. |
| 1726 AudioNodeList audio_nodes; | 1617 AudioNodeList audio_nodes = GenerateAudioNodeList({kInternalMic}); |
| 1727 audio_nodes.push_back(kInternalMic); | |
| 1728 SetUpCrasAudioHandler(audio_nodes); | 1618 SetUpCrasAudioHandler(audio_nodes); |
| 1729 const size_t init_nodes_size = audio_nodes.size(); | 1619 const size_t init_nodes_size = audio_nodes.size(); |
| 1730 | 1620 |
| 1731 // Verify the audio devices size. | 1621 // Verify the audio devices size. |
| 1732 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); | 1622 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); |
| 1733 AudioDeviceList audio_devices; | 1623 AudioDeviceList audio_devices; |
| 1734 cras_audio_handler_->GetAudioDevices(&audio_devices); | 1624 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 1735 EXPECT_EQ(init_nodes_size, audio_devices.size()); | 1625 EXPECT_EQ(init_nodes_size, audio_devices.size()); |
| 1736 | 1626 |
| 1737 // Verify the internal mic is selected as the active output. | 1627 // Verify the internal mic is selected as the active output. |
| 1738 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); | 1628 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); |
| 1739 EXPECT_EQ(kInternalMic.id, cras_audio_handler_->GetPrimaryActiveInputNode()); | 1629 EXPECT_EQ(kInternalMic->id, cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 1740 EXPECT_FALSE(cras_audio_handler_->has_alternative_output()); | 1630 EXPECT_FALSE(cras_audio_handler_->has_alternative_output()); |
| 1741 EXPECT_TRUE(audio_devices[0].active); | 1631 EXPECT_TRUE(audio_devices[0].active); |
| 1742 | 1632 |
| 1743 // Plug in usb mic, but fire NodesChanged signal twice. | 1633 // Plug in usb mic, but fire NodesChanged signal twice. |
| 1744 audio_nodes.clear(); | 1634 audio_nodes.clear(); |
| 1745 AudioNode internal_mic(kInternalMic); | 1635 AudioNode internal_mic = GenerateAudioNode(kInternalMic); |
| 1746 internal_mic.active = true; | 1636 internal_mic.active = true; |
| 1747 internal_mic.plugged_time = 1000; | 1637 internal_mic.plugged_time = 1000; |
| 1748 audio_nodes.push_back(internal_mic); | 1638 audio_nodes.push_back(internal_mic); |
| 1749 AudioNode usb_mic(kUSBMic); | 1639 AudioNode usb_mic = GenerateAudioNode(kUSBMic); |
| 1750 usb_mic.active = false; | 1640 usb_mic.active = false; |
| 1751 usb_mic.plugged_time = 2000; | 1641 usb_mic.plugged_time = 2000; |
| 1752 audio_nodes.push_back(usb_mic); | 1642 audio_nodes.push_back(usb_mic); |
| 1753 ChangeAudioNodes(audio_nodes); | 1643 ChangeAudioNodes(audio_nodes); |
| 1754 ChangeAudioNodes(audio_nodes); | 1644 ChangeAudioNodes(audio_nodes); |
| 1755 | 1645 |
| 1756 // Verify the active output device is set to headphone. | 1646 // Verify the active output device is set to headphone. |
| 1757 EXPECT_EQ(2, test_observer_->audio_nodes_changed_count()); | 1647 EXPECT_EQ(2, test_observer_->audio_nodes_changed_count()); |
| 1758 EXPECT_LE(1, test_observer_->active_input_node_changed_count()); | 1648 EXPECT_LE(1, test_observer_->active_input_node_changed_count()); |
| 1759 EXPECT_EQ(usb_mic.id, cras_audio_handler_->GetPrimaryActiveInputNode()); | 1649 EXPECT_EQ(usb_mic.id, cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 1760 EXPECT_TRUE(cras_audio_handler_->has_alternative_input()); | 1650 EXPECT_TRUE(cras_audio_handler_->has_alternative_input()); |
| 1761 | 1651 |
| 1762 // Verfiy the audio devices data is consistent, i.e., the active input device | 1652 // Verfiy the audio devices data is consistent, i.e., the active input device |
| 1763 // should be usb mic. | 1653 // should be usb mic. |
| 1764 cras_audio_handler_->GetAudioDevices(&audio_devices); | 1654 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 1765 EXPECT_EQ(init_nodes_size + 1, audio_devices.size()); | 1655 EXPECT_EQ(init_nodes_size + 1, audio_devices.size()); |
| 1766 for (size_t i = 0; i < audio_devices.size(); ++i) { | 1656 for (size_t i = 0; i < audio_devices.size(); ++i) { |
| 1767 if (audio_devices[i].id == kInternalMic.id) | 1657 if (audio_devices[i].id == kInternalMic->id) |
| 1768 EXPECT_FALSE(audio_devices[i].active); | 1658 EXPECT_FALSE(audio_devices[i].active); |
| 1769 else if (audio_devices[i].id == usb_mic.id) | 1659 else if (audio_devices[i].id == usb_mic.id) |
| 1770 EXPECT_TRUE(audio_devices[i].active); | 1660 EXPECT_TRUE(audio_devices[i].active); |
| 1771 else | 1661 else |
| 1772 NOTREACHED(); | 1662 NOTREACHED(); |
| 1773 } | 1663 } |
| 1774 } | 1664 } |
| 1775 | 1665 |
| 1776 // This is the case of crbug.com/291303. | 1666 // This is the case of crbug.com/291303. |
| 1777 TEST_F(CrasAudioHandlerTest, MultipleNodesChangedSignalsOnSystemBoot) { | 1667 TEST_P(CrasAudioHandlerTest, MultipleNodesChangedSignalsOnSystemBoot) { |
| 1778 // Set up audio handler with empty audio_nodes. | 1668 // Set up audio handler with empty audio_nodes. |
| 1779 AudioNodeList audio_nodes; | 1669 AudioNodeList audio_nodes; |
| 1780 SetUpCrasAudioHandler(audio_nodes); | 1670 SetUpCrasAudioHandler(audio_nodes); |
| 1781 | 1671 |
| 1782 AudioNode internal_speaker(kInternalSpeaker); | 1672 AudioNode internal_speaker = GenerateAudioNode(kInternalSpeaker); |
| 1783 internal_speaker.active = false; | 1673 internal_speaker.active = false; |
| 1784 AudioNode headphone(kHeadphone); | 1674 AudioNode headphone = GenerateAudioNode(kHeadphone); |
| 1785 headphone.active = false; | 1675 headphone.active = false; |
| 1786 AudioNode internal_mic(kInternalMic); | 1676 AudioNode internal_mic = GenerateAudioNode(kInternalMic); |
| 1787 internal_mic.active = false; | 1677 internal_mic.active = false; |
| 1788 audio_nodes.push_back(internal_speaker); | 1678 audio_nodes.push_back(internal_speaker); |
| 1789 audio_nodes.push_back(headphone); | 1679 audio_nodes.push_back(headphone); |
| 1790 audio_nodes.push_back(internal_mic); | 1680 audio_nodes.push_back(internal_mic); |
| 1791 const size_t init_nodes_size = audio_nodes.size(); | 1681 const size_t init_nodes_size = audio_nodes.size(); |
| 1792 | 1682 |
| 1793 // Simulate AudioNodesChanged signal being fired twice during system boot. | 1683 // Simulate AudioNodesChanged signal being fired twice during system boot. |
| 1794 ChangeAudioNodes(audio_nodes); | 1684 ChangeAudioNodes(audio_nodes); |
| 1795 ChangeAudioNodes(audio_nodes); | 1685 ChangeAudioNodes(audio_nodes); |
| 1796 | 1686 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1817 else if (audio_devices[i].id == headphone.id) | 1707 else if (audio_devices[i].id == headphone.id) |
| 1818 EXPECT_TRUE(audio_devices[i].active); | 1708 EXPECT_TRUE(audio_devices[i].active); |
| 1819 else if (audio_devices[i].id == internal_mic.id) | 1709 else if (audio_devices[i].id == internal_mic.id) |
| 1820 EXPECT_TRUE(audio_devices[i].active); | 1710 EXPECT_TRUE(audio_devices[i].active); |
| 1821 else | 1711 else |
| 1822 NOTREACHED(); | 1712 NOTREACHED(); |
| 1823 } | 1713 } |
| 1824 } | 1714 } |
| 1825 | 1715 |
| 1826 // This is the case of crbug.com/448924. | 1716 // This is the case of crbug.com/448924. |
| 1827 TEST_F(CrasAudioHandlerTest, | 1717 TEST_P(CrasAudioHandlerTest, |
| 1828 TwoNodesChangedSignalsForLosingTowNodesOnOneUnplug) { | 1718 TwoNodesChangedSignalsForLosingTowNodesOnOneUnplug) { |
| 1829 // Set up audio handler with 4 audio_nodes. | 1719 // Set up audio handler with 4 audio_nodes. |
| 1830 AudioNodeList audio_nodes; | 1720 AudioNodeList audio_nodes; |
| 1831 AudioNode internal_speaker(kInternalSpeaker); | 1721 AudioNode internal_speaker = GenerateAudioNode(kInternalSpeaker); |
| 1832 internal_speaker.active = false; | 1722 internal_speaker.active = false; |
| 1833 AudioNode headphone(kHeadphone); | 1723 AudioNode headphone = GenerateAudioNode(kHeadphone); |
| 1834 headphone.active = false; | 1724 headphone.active = false; |
| 1835 AudioNode internal_mic(kInternalMic); | 1725 AudioNode internal_mic = GenerateAudioNode(kInternalMic); |
| 1836 internal_mic.active = false; | 1726 internal_mic.active = false; |
| 1837 AudioNode micJack(kMicJack); | 1727 AudioNode micJack = GenerateAudioNode(kMicJack); |
| 1838 micJack.active = false; | 1728 micJack.active = false; |
| 1839 audio_nodes.push_back(internal_speaker); | 1729 audio_nodes.push_back(internal_speaker); |
| 1840 audio_nodes.push_back(headphone); | 1730 audio_nodes.push_back(headphone); |
| 1841 audio_nodes.push_back(internal_mic); | 1731 audio_nodes.push_back(internal_mic); |
| 1842 audio_nodes.push_back(micJack); | 1732 audio_nodes.push_back(micJack); |
| 1843 SetUpCrasAudioHandler(audio_nodes); | 1733 SetUpCrasAudioHandler(audio_nodes); |
| 1844 | 1734 |
| 1845 // Verify the audio devices size. | 1735 // Verify the audio devices size. |
| 1846 AudioDeviceList audio_devices; | 1736 AudioDeviceList audio_devices; |
| 1847 cras_audio_handler_->GetAudioDevices(&audio_devices); | 1737 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 1848 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); | 1738 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); |
| 1849 | 1739 |
| 1850 // Verify the headphone has been selected as the active output. | 1740 // Verify the headphone has been selected as the active output. |
| 1851 AudioDevice active_output; | 1741 AudioDevice active_output; |
| 1852 EXPECT_TRUE( | 1742 EXPECT_TRUE( |
| 1853 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); | 1743 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
| 1854 EXPECT_EQ(kHeadphone.id, active_output.id); | 1744 EXPECT_EQ(kHeadphone->id, active_output.id); |
| 1855 EXPECT_EQ(kHeadphone.id, cras_audio_handler_->GetPrimaryActiveOutputNode()); | 1745 EXPECT_EQ(kHeadphone->id, cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 1856 EXPECT_TRUE(active_output.active); | 1746 EXPECT_TRUE(active_output.active); |
| 1857 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); | 1747 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
| 1858 | 1748 |
| 1859 // Verify the mic Jack has been selected as the active input. | 1749 // Verify the mic Jack has been selected as the active input. |
| 1860 EXPECT_EQ(micJack.id, cras_audio_handler_->GetPrimaryActiveInputNode()); | 1750 EXPECT_EQ(micJack.id, cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 1861 const AudioDevice* active_input = GetDeviceFromId(micJack.id); | 1751 const AudioDevice* active_input = GetDeviceFromId(micJack.id); |
| 1862 EXPECT_TRUE(active_input->active); | 1752 EXPECT_TRUE(active_input->active); |
| 1863 EXPECT_TRUE(cras_audio_handler_->has_alternative_input()); | 1753 EXPECT_TRUE(cras_audio_handler_->has_alternative_input()); |
| 1864 | 1754 |
| 1865 // Simulate the nodes list in first NodesChanged signal, only headphone is | 1755 // Simulate the nodes list in first NodesChanged signal, only headphone is |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1897 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); | 1787 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
| 1898 EXPECT_EQ(internal_speaker.id, active_output.id); | 1788 EXPECT_EQ(internal_speaker.id, active_output.id); |
| 1899 EXPECT_TRUE(active_output.active); | 1789 EXPECT_TRUE(active_output.active); |
| 1900 | 1790 |
| 1901 // Verify the active input device id is set to internal mic. | 1791 // Verify the active input device id is set to internal mic. |
| 1902 EXPECT_EQ(internal_mic.id, cras_audio_handler_->GetPrimaryActiveInputNode()); | 1792 EXPECT_EQ(internal_mic.id, cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 1903 const AudioDevice* changed_active_input = GetDeviceFromId(internal_mic.id); | 1793 const AudioDevice* changed_active_input = GetDeviceFromId(internal_mic.id); |
| 1904 EXPECT_TRUE(changed_active_input->active); | 1794 EXPECT_TRUE(changed_active_input->active); |
| 1905 } | 1795 } |
| 1906 | 1796 |
| 1907 TEST_F(CrasAudioHandlerTest, SetOutputMono) { | 1797 TEST_P(CrasAudioHandlerTest, SetOutputMono) { |
| 1908 AudioNodeList audio_nodes; | 1798 AudioNodeList audio_nodes = GenerateAudioNodeList({kHeadphone}); |
| 1909 audio_nodes.push_back(kHeadphone); | |
| 1910 SetUpCrasAudioHandler(audio_nodes); | 1799 SetUpCrasAudioHandler(audio_nodes); |
| 1911 EXPECT_EQ(0, test_observer_->output_channel_remixing_changed_count()); | 1800 EXPECT_EQ(0, test_observer_->output_channel_remixing_changed_count()); |
| 1912 | 1801 |
| 1913 // Set output mono | 1802 // Set output mono |
| 1914 cras_audio_handler_->SetOutputMono(true); | 1803 cras_audio_handler_->SetOutputMono(true); |
| 1915 | 1804 |
| 1916 // Verify the output is in mono mode, OnOuputChannelRemixingChanged event | 1805 // Verify the output is in mono mode, OnOuputChannelRemixingChanged event |
| 1917 // is fired. | 1806 // is fired. |
| 1918 EXPECT_TRUE(cras_audio_handler_->IsOutputMonoEnabled()); | 1807 EXPECT_TRUE(cras_audio_handler_->IsOutputMonoEnabled()); |
| 1919 EXPECT_EQ(1, test_observer_->output_channel_remixing_changed_count()); | 1808 EXPECT_EQ(1, test_observer_->output_channel_remixing_changed_count()); |
| 1920 | 1809 |
| 1921 // Set output stereo | 1810 // Set output stereo |
| 1922 cras_audio_handler_->SetOutputMono(false); | 1811 cras_audio_handler_->SetOutputMono(false); |
| 1923 EXPECT_FALSE(cras_audio_handler_->IsOutputMonoEnabled()); | 1812 EXPECT_FALSE(cras_audio_handler_->IsOutputMonoEnabled()); |
| 1924 EXPECT_EQ(2, test_observer_->output_channel_remixing_changed_count()); | 1813 EXPECT_EQ(2, test_observer_->output_channel_remixing_changed_count()); |
| 1925 } | 1814 } |
| 1926 | 1815 |
| 1927 TEST_F(CrasAudioHandlerTest, SetOutputMute) { | 1816 TEST_P(CrasAudioHandlerTest, SetOutputMute) { |
| 1928 AudioNodeList audio_nodes; | 1817 AudioNodeList audio_nodes = GenerateAudioNodeList({kInternalSpeaker}); |
| 1929 audio_nodes.push_back(kInternalSpeaker); | |
| 1930 SetUpCrasAudioHandler(audio_nodes); | 1818 SetUpCrasAudioHandler(audio_nodes); |
| 1931 EXPECT_EQ(0, test_observer_->output_mute_changed_count()); | 1819 EXPECT_EQ(0, test_observer_->output_mute_changed_count()); |
| 1932 | 1820 |
| 1933 // Mute the device. | 1821 // Mute the device. |
| 1934 cras_audio_handler_->SetOutputMute(true); | 1822 cras_audio_handler_->SetOutputMute(true); |
| 1935 | 1823 |
| 1936 // Verify the output is muted, OnOutputMuteChanged event is fired, | 1824 // Verify the output is muted, OnOutputMuteChanged event is fired, |
| 1937 // and mute value is saved in the preferences. | 1825 // and mute value is saved in the preferences. |
| 1938 EXPECT_TRUE(cras_audio_handler_->IsOutputMuted()); | 1826 EXPECT_TRUE(cras_audio_handler_->IsOutputMuted()); |
| 1939 EXPECT_EQ(1, test_observer_->output_mute_changed_count()); | 1827 EXPECT_EQ(1, test_observer_->output_mute_changed_count()); |
| 1940 AudioDevice speaker(kInternalSpeaker); | 1828 AudioDevice speaker(GenerateAudioNode(kInternalSpeaker)); |
| 1941 EXPECT_TRUE(audio_pref_handler_->GetMuteValue(speaker)); | 1829 EXPECT_TRUE(audio_pref_handler_->GetMuteValue(speaker)); |
| 1942 | 1830 |
| 1943 // Unmute the device. | 1831 // Unmute the device. |
| 1944 cras_audio_handler_->SetOutputMute(false); | 1832 cras_audio_handler_->SetOutputMute(false); |
| 1945 | 1833 |
| 1946 // Verify the output is unmuted, OnOutputMuteChanged event is fired, | 1834 // Verify the output is unmuted, OnOutputMuteChanged event is fired, |
| 1947 // and mute value is saved in the preferences. | 1835 // and mute value is saved in the preferences. |
| 1948 EXPECT_FALSE(cras_audio_handler_->IsOutputMuted()); | 1836 EXPECT_FALSE(cras_audio_handler_->IsOutputMuted()); |
| 1949 EXPECT_EQ(2, test_observer_->output_mute_changed_count()); | 1837 EXPECT_EQ(2, test_observer_->output_mute_changed_count()); |
| 1950 EXPECT_FALSE(audio_pref_handler_->GetMuteValue(speaker)); | 1838 EXPECT_FALSE(audio_pref_handler_->GetMuteValue(speaker)); |
| 1951 } | 1839 } |
| 1952 | 1840 |
| 1953 TEST_F(CrasAudioHandlerTest, SetInputMute) { | 1841 TEST_P(CrasAudioHandlerTest, SetInputMute) { |
| 1954 AudioNodeList audio_nodes; | 1842 AudioNodeList audio_nodes = GenerateAudioNodeList({kInternalMic}); |
| 1955 audio_nodes.push_back(kInternalMic); | |
| 1956 SetUpCrasAudioHandler(audio_nodes); | 1843 SetUpCrasAudioHandler(audio_nodes); |
| 1957 EXPECT_EQ(0, test_observer_->input_mute_changed_count()); | 1844 EXPECT_EQ(0, test_observer_->input_mute_changed_count()); |
| 1958 | 1845 |
| 1959 // Mute the device. | 1846 // Mute the device. |
| 1960 cras_audio_handler_->SetInputMute(true); | 1847 cras_audio_handler_->SetInputMute(true); |
| 1961 | 1848 |
| 1962 // Verify the input is muted, OnInputMuteChanged event is fired. | 1849 // Verify the input is muted, OnInputMuteChanged event is fired. |
| 1963 EXPECT_TRUE(cras_audio_handler_->IsInputMuted()); | 1850 EXPECT_TRUE(cras_audio_handler_->IsInputMuted()); |
| 1964 EXPECT_EQ(1, test_observer_->input_mute_changed_count()); | 1851 EXPECT_EQ(1, test_observer_->input_mute_changed_count()); |
| 1965 | 1852 |
| 1966 // Unmute the device. | 1853 // Unmute the device. |
| 1967 cras_audio_handler_->SetInputMute(false); | 1854 cras_audio_handler_->SetInputMute(false); |
| 1968 | 1855 |
| 1969 // Verify the input is unmuted, OnInputMuteChanged event is fired. | 1856 // Verify the input is unmuted, OnInputMuteChanged event is fired. |
| 1970 EXPECT_FALSE(cras_audio_handler_->IsInputMuted()); | 1857 EXPECT_FALSE(cras_audio_handler_->IsInputMuted()); |
| 1971 EXPECT_EQ(2, test_observer_->input_mute_changed_count()); | 1858 EXPECT_EQ(2, test_observer_->input_mute_changed_count()); |
| 1972 } | 1859 } |
| 1973 | 1860 |
| 1974 TEST_F(CrasAudioHandlerTest, SetOutputVolumePercent) { | 1861 TEST_P(CrasAudioHandlerTest, SetOutputVolumePercent) { |
| 1975 AudioNodeList audio_nodes; | 1862 AudioNodeList audio_nodes = GenerateAudioNodeList({kInternalSpeaker}); |
| 1976 audio_nodes.push_back(kInternalSpeaker); | |
| 1977 SetUpCrasAudioHandler(audio_nodes); | 1863 SetUpCrasAudioHandler(audio_nodes); |
| 1978 EXPECT_EQ(0, test_observer_->output_volume_changed_count()); | 1864 EXPECT_EQ(0, test_observer_->output_volume_changed_count()); |
| 1979 | 1865 |
| 1980 const int kVolume = 60; | 1866 const int kVolume = 60; |
| 1981 cras_audio_handler_->SetOutputVolumePercent(kVolume); | 1867 cras_audio_handler_->SetOutputVolumePercent(kVolume); |
| 1982 | 1868 |
| 1983 // Verify the output volume is changed to the designated value, | 1869 // Verify the output volume is changed to the designated value, |
| 1984 // OnOutputNodeVolumeChanged event is fired, and the device volume value | 1870 // OnOutputNodeVolumeChanged event is fired, and the device volume value |
| 1985 // is saved in the preferences. | 1871 // is saved in the preferences. |
| 1986 EXPECT_EQ(kVolume, cras_audio_handler_->GetOutputVolumePercent()); | 1872 EXPECT_EQ(kVolume, cras_audio_handler_->GetOutputVolumePercent()); |
| 1987 EXPECT_EQ(1, test_observer_->output_volume_changed_count()); | 1873 EXPECT_EQ(1, test_observer_->output_volume_changed_count()); |
| 1988 AudioDevice device; | 1874 AudioDevice device; |
| 1989 EXPECT_TRUE(cras_audio_handler_->GetPrimaryActiveOutputDevice(&device)); | 1875 EXPECT_TRUE(cras_audio_handler_->GetPrimaryActiveOutputDevice(&device)); |
| 1990 EXPECT_EQ(device.id, kInternalSpeaker.id); | 1876 EXPECT_EQ(device.id, kInternalSpeaker->id); |
| 1991 EXPECT_EQ(kVolume, audio_pref_handler_->GetOutputVolumeValue(&device)); | 1877 EXPECT_EQ(kVolume, audio_pref_handler_->GetOutputVolumeValue(&device)); |
| 1992 } | 1878 } |
| 1993 | 1879 |
| 1994 TEST_F(CrasAudioHandlerTest, SetOutputVolumePercentWithoutNotifyingObservers) { | 1880 TEST_P(CrasAudioHandlerTest, SetOutputVolumePercentWithoutNotifyingObservers) { |
| 1995 AudioNodeList audio_nodes; | 1881 AudioNodeList audio_nodes = GenerateAudioNodeList({kInternalSpeaker}); |
| 1996 audio_nodes.push_back(kInternalSpeaker); | |
| 1997 SetUpCrasAudioHandler(audio_nodes); | 1882 SetUpCrasAudioHandler(audio_nodes); |
| 1998 EXPECT_EQ(0, test_observer_->output_volume_changed_count()); | 1883 EXPECT_EQ(0, test_observer_->output_volume_changed_count()); |
| 1999 | 1884 |
| 2000 const int kVolume1 = 60; | 1885 const int kVolume1 = 60; |
| 2001 const int kVolume2 = 80; | 1886 const int kVolume2 = 80; |
| 2002 cras_audio_handler_->SetOutputVolumePercentWithoutNotifyingObservers( | 1887 cras_audio_handler_->SetOutputVolumePercentWithoutNotifyingObservers( |
| 2003 kVolume1, CrasAudioHandler::VOLUME_CHANGE_MAXIMIZE_MODE_SCREENSHOT); | 1888 kVolume1, CrasAudioHandler::VOLUME_CHANGE_MAXIMIZE_MODE_SCREENSHOT); |
| 2004 // Verify the output volume is changed to the designated value, | 1889 // Verify the output volume is changed to the designated value, |
| 2005 // OnOutputNodeVolumeChanged event is not fired, and the device volume value | 1890 // OnOutputNodeVolumeChanged event is not fired, and the device volume value |
| 2006 // is saved in the preferences. | 1891 // is saved in the preferences. |
| 2007 EXPECT_EQ(kVolume1, cras_audio_handler_->GetOutputVolumePercent()); | 1892 EXPECT_EQ(kVolume1, cras_audio_handler_->GetOutputVolumePercent()); |
| 2008 EXPECT_EQ(0, test_observer_->output_volume_changed_count()); | 1893 EXPECT_EQ(0, test_observer_->output_volume_changed_count()); |
| 2009 AudioDevice device; | 1894 AudioDevice device; |
| 2010 EXPECT_TRUE(cras_audio_handler_->GetPrimaryActiveOutputDevice(&device)); | 1895 EXPECT_TRUE(cras_audio_handler_->GetPrimaryActiveOutputDevice(&device)); |
| 2011 EXPECT_EQ(device.id, kInternalSpeaker.id); | 1896 EXPECT_EQ(device.id, kInternalSpeaker->id); |
| 2012 EXPECT_EQ(kVolume1, audio_pref_handler_->GetOutputVolumeValue(&device)); | 1897 EXPECT_EQ(kVolume1, audio_pref_handler_->GetOutputVolumeValue(&device)); |
| 2013 | 1898 |
| 2014 // Make another SetOutputVolumePercentWithoutNotifyingObservers call to make | 1899 // Make another SetOutputVolumePercentWithoutNotifyingObservers call to make |
| 2015 // sure everything is right. | 1900 // sure everything is right. |
| 2016 cras_audio_handler_->SetOutputVolumePercentWithoutNotifyingObservers( | 1901 cras_audio_handler_->SetOutputVolumePercentWithoutNotifyingObservers( |
| 2017 kVolume2, CrasAudioHandler::VOLUME_CHANGE_MAXIMIZE_MODE_SCREENSHOT); | 1902 kVolume2, CrasAudioHandler::VOLUME_CHANGE_MAXIMIZE_MODE_SCREENSHOT); |
| 2018 EXPECT_EQ(kVolume2, cras_audio_handler_->GetOutputVolumePercent()); | 1903 EXPECT_EQ(kVolume2, cras_audio_handler_->GetOutputVolumePercent()); |
| 2019 EXPECT_EQ(0, test_observer_->output_volume_changed_count()); | 1904 EXPECT_EQ(0, test_observer_->output_volume_changed_count()); |
| 2020 EXPECT_TRUE(cras_audio_handler_->GetPrimaryActiveOutputDevice(&device)); | 1905 EXPECT_TRUE(cras_audio_handler_->GetPrimaryActiveOutputDevice(&device)); |
| 2021 EXPECT_EQ(device.id, kInternalSpeaker.id); | 1906 EXPECT_EQ(device.id, kInternalSpeaker->id); |
| 2022 EXPECT_EQ(kVolume2, audio_pref_handler_->GetOutputVolumeValue(&device)); | 1907 EXPECT_EQ(kVolume2, audio_pref_handler_->GetOutputVolumeValue(&device)); |
| 2023 | 1908 |
| 2024 // Make a final SetOutputVolumePercent call to check if | 1909 // Make a final SetOutputVolumePercent call to check if |
| 2025 // SetOutputVolumePercentWithoutNotifyingObservers may block subsequent | 1910 // SetOutputVolumePercentWithoutNotifyingObservers may block subsequent |
| 2026 // notifying observers. | 1911 // notifying observers. |
| 2027 cras_audio_handler_->SetOutputVolumePercent(kVolume1); | 1912 cras_audio_handler_->SetOutputVolumePercent(kVolume1); |
| 2028 EXPECT_EQ(kVolume1, cras_audio_handler_->GetOutputVolumePercent()); | 1913 EXPECT_EQ(kVolume1, cras_audio_handler_->GetOutputVolumePercent()); |
| 2029 EXPECT_EQ(1, test_observer_->output_volume_changed_count()); | 1914 EXPECT_EQ(1, test_observer_->output_volume_changed_count()); |
| 2030 EXPECT_TRUE(cras_audio_handler_->GetPrimaryActiveOutputDevice(&device)); | 1915 EXPECT_TRUE(cras_audio_handler_->GetPrimaryActiveOutputDevice(&device)); |
| 2031 EXPECT_EQ(device.id, kInternalSpeaker.id); | 1916 EXPECT_EQ(device.id, kInternalSpeaker->id); |
| 2032 EXPECT_EQ(kVolume1, audio_pref_handler_->GetOutputVolumeValue(&device)); | 1917 EXPECT_EQ(kVolume1, audio_pref_handler_->GetOutputVolumeValue(&device)); |
| 2033 } | 1918 } |
| 2034 | 1919 |
| 2035 TEST_F(CrasAudioHandlerTest, RestartAudioClientWithCrasReady) { | 1920 TEST_P(CrasAudioHandlerTest, RestartAudioClientWithCrasReady) { |
| 2036 AudioNodeList audio_nodes; | 1921 AudioNodeList audio_nodes = GenerateAudioNodeList({kInternalSpeaker}); |
| 2037 audio_nodes.push_back(kInternalSpeaker); | |
| 2038 SetUpCrasAudioHandler(audio_nodes); | 1922 SetUpCrasAudioHandler(audio_nodes); |
| 2039 EXPECT_EQ(0, test_observer_->output_volume_changed_count()); | 1923 EXPECT_EQ(0, test_observer_->output_volume_changed_count()); |
| 2040 | 1924 |
| 2041 const int kDefaultVolume = cras_audio_handler_->GetOutputVolumePercent(); | 1925 const int kDefaultVolume = cras_audio_handler_->GetOutputVolumePercent(); |
| 2042 // Disable the auto OutputNodeVolumeChanged signal. | 1926 // Disable the auto OutputNodeVolumeChanged signal. |
| 2043 fake_cras_audio_client_->set_notify_volume_change_with_delay(true); | 1927 fake_cras_audio_client_->set_notify_volume_change_with_delay(true); |
| 2044 | 1928 |
| 2045 fake_cras_audio_client_->SetAudioNodesForTesting(audio_nodes); | 1929 fake_cras_audio_client_->SetAudioNodesForTesting(audio_nodes); |
| 2046 RestartAudioClient(); | 1930 RestartAudioClient(); |
| 2047 EXPECT_EQ(0, test_observer_->output_volume_changed_count()); | 1931 EXPECT_EQ(0, test_observer_->output_volume_changed_count()); |
| 2048 EXPECT_EQ(kDefaultVolume, cras_audio_handler_->GetOutputVolumePercent()); | 1932 EXPECT_EQ(kDefaultVolume, cras_audio_handler_->GetOutputVolumePercent()); |
| 2049 | 1933 |
| 2050 // The correct initialization OutputNodeVolumeChanged event is fired. We | 1934 // The correct initialization OutputNodeVolumeChanged event is fired. We |
| 2051 // should avoid notifying observers. | 1935 // should avoid notifying observers. |
| 2052 fake_cras_audio_client_->NotifyOutputNodeVolumeChangedForTesting( | 1936 fake_cras_audio_client_->NotifyOutputNodeVolumeChangedForTesting( |
| 2053 kInternalSpeaker.id, kDefaultVolume); | 1937 kInternalSpeaker->id, kDefaultVolume); |
| 2054 EXPECT_EQ(0, test_observer_->output_volume_changed_count()); | 1938 EXPECT_EQ(0, test_observer_->output_volume_changed_count()); |
| 2055 EXPECT_EQ(kDefaultVolume, cras_audio_handler_->GetOutputVolumePercent()); | 1939 EXPECT_EQ(kDefaultVolume, cras_audio_handler_->GetOutputVolumePercent()); |
| 2056 | 1940 |
| 2057 // The later OutputNodeVolumeChanged event after initialization should notify | 1941 // The later OutputNodeVolumeChanged event after initialization should notify |
| 2058 // observers. | 1942 // observers. |
| 2059 const int kVolume = 60; | 1943 const int kVolume = 60; |
| 2060 fake_cras_audio_client_->NotifyOutputNodeVolumeChangedForTesting( | 1944 fake_cras_audio_client_->NotifyOutputNodeVolumeChangedForTesting( |
| 2061 kInternalSpeaker.id, kVolume); | 1945 kInternalSpeaker->id, kVolume); |
| 2062 EXPECT_EQ(1, test_observer_->output_volume_changed_count()); | 1946 EXPECT_EQ(1, test_observer_->output_volume_changed_count()); |
| 2063 EXPECT_EQ(kVolume, cras_audio_handler_->GetOutputVolumePercent()); | 1947 EXPECT_EQ(kVolume, cras_audio_handler_->GetOutputVolumePercent()); |
| 2064 } | 1948 } |
| 2065 | 1949 |
| 2066 TEST_F(CrasAudioHandlerTest, RestartAudioClientWithCrasDropRequest) { | 1950 TEST_P(CrasAudioHandlerTest, RestartAudioClientWithCrasDropRequest) { |
| 2067 AudioNodeList audio_nodes; | 1951 AudioNodeList audio_nodes = GenerateAudioNodeList({kInternalSpeaker}); |
| 2068 audio_nodes.push_back(kInternalSpeaker); | |
| 2069 SetUpCrasAudioHandler(audio_nodes); | 1952 SetUpCrasAudioHandler(audio_nodes); |
| 2070 EXPECT_EQ(0, test_observer_->output_volume_changed_count()); | 1953 EXPECT_EQ(0, test_observer_->output_volume_changed_count()); |
| 2071 | 1954 |
| 2072 const int kDefaultVolume = cras_audio_handler_->GetOutputVolumePercent(); | 1955 const int kDefaultVolume = cras_audio_handler_->GetOutputVolumePercent(); |
| 2073 // Disable the auto OutputNodeVolumeChanged signal. | 1956 // Disable the auto OutputNodeVolumeChanged signal. |
| 2074 fake_cras_audio_client_->set_notify_volume_change_with_delay(true); | 1957 fake_cras_audio_client_->set_notify_volume_change_with_delay(true); |
| 2075 | 1958 |
| 2076 fake_cras_audio_client_->SetAudioNodesForTesting(audio_nodes); | 1959 fake_cras_audio_client_->SetAudioNodesForTesting(audio_nodes); |
| 2077 RestartAudioClient(); | 1960 RestartAudioClient(); |
| 2078 EXPECT_EQ(0, test_observer_->output_volume_changed_count()); | 1961 EXPECT_EQ(0, test_observer_->output_volume_changed_count()); |
| 2079 EXPECT_EQ(kDefaultVolume, cras_audio_handler_->GetOutputVolumePercent()); | 1962 EXPECT_EQ(kDefaultVolume, cras_audio_handler_->GetOutputVolumePercent()); |
| 2080 | 1963 |
| 2081 // A wrong initialization OutputNodeVolumeChanged event is fired. This may | 1964 // A wrong initialization OutputNodeVolumeChanged event is fired. This may |
| 2082 // happen when Cras is not ready and drops request. The approach we use is | 1965 // happen when Cras is not ready and drops request. The approach we use is |
| 2083 // to log warning message, clear the pending automated volume change reasons, | 1966 // to log warning message, clear the pending automated volume change reasons, |
| 2084 // and notify observers about this change. | 1967 // and notify observers about this change. |
| 2085 const int kVolume1 = 30; | 1968 const int kVolume1 = 30; |
| 2086 fake_cras_audio_client_->NotifyOutputNodeVolumeChangedForTesting( | 1969 fake_cras_audio_client_->NotifyOutputNodeVolumeChangedForTesting( |
| 2087 kInternalSpeaker.id, kVolume1); | 1970 kInternalSpeaker->id, kVolume1); |
| 2088 EXPECT_EQ(1, test_observer_->output_volume_changed_count()); | 1971 EXPECT_EQ(1, test_observer_->output_volume_changed_count()); |
| 2089 EXPECT_EQ(kVolume1, cras_audio_handler_->GetOutputVolumePercent()); | 1972 EXPECT_EQ(kVolume1, cras_audio_handler_->GetOutputVolumePercent()); |
| 2090 | 1973 |
| 2091 // The later OutputNodeVolumeChanged event should notify observers. | 1974 // The later OutputNodeVolumeChanged event should notify observers. |
| 2092 const int kVolume2 = 60; | 1975 const int kVolume2 = 60; |
| 2093 fake_cras_audio_client_->NotifyOutputNodeVolumeChangedForTesting( | 1976 fake_cras_audio_client_->NotifyOutputNodeVolumeChangedForTesting( |
| 2094 kInternalSpeaker.id, kVolume2); | 1977 kInternalSpeaker->id, kVolume2); |
| 2095 EXPECT_EQ(2, test_observer_->output_volume_changed_count()); | 1978 EXPECT_EQ(2, test_observer_->output_volume_changed_count()); |
| 2096 EXPECT_EQ(kVolume2, cras_audio_handler_->GetOutputVolumePercent()); | 1979 EXPECT_EQ(kVolume2, cras_audio_handler_->GetOutputVolumePercent()); |
| 2097 } | 1980 } |
| 2098 | 1981 |
| 2099 TEST_F(CrasAudioHandlerTest, SetOutputVolumeWithDelayedSignal) { | 1982 TEST_P(CrasAudioHandlerTest, SetOutputVolumeWithDelayedSignal) { |
| 2100 AudioNodeList audio_nodes; | 1983 AudioNodeList audio_nodes = GenerateAudioNodeList({kInternalSpeaker}); |
| 2101 audio_nodes.push_back(kInternalSpeaker); | |
| 2102 SetUpCrasAudioHandler(audio_nodes); | 1984 SetUpCrasAudioHandler(audio_nodes); |
| 2103 EXPECT_EQ(0, test_observer_->output_volume_changed_count()); | 1985 EXPECT_EQ(0, test_observer_->output_volume_changed_count()); |
| 2104 | 1986 |
| 2105 const int kDefaultVolume = 75; | 1987 const int kDefaultVolume = 75; |
| 2106 EXPECT_EQ(kDefaultVolume, cras_audio_handler_->GetOutputVolumePercent()); | 1988 EXPECT_EQ(kDefaultVolume, cras_audio_handler_->GetOutputVolumePercent()); |
| 2107 | 1989 |
| 2108 // Disable the auto OutputNodeVolumeChanged signal. | 1990 // Disable the auto OutputNodeVolumeChanged signal. |
| 2109 fake_cras_audio_client_->set_notify_volume_change_with_delay(true); | 1991 fake_cras_audio_client_->set_notify_volume_change_with_delay(true); |
| 2110 | 1992 |
| 2111 // Verify the volume state is not changed before OutputNodeVolumeChanged | 1993 // Verify the volume state is not changed before OutputNodeVolumeChanged |
| 2112 // signal fires. | 1994 // signal fires. |
| 2113 const int kVolume = 60; | 1995 const int kVolume = 60; |
| 2114 cras_audio_handler_->SetOutputVolumePercent(kVolume); | 1996 cras_audio_handler_->SetOutputVolumePercent(kVolume); |
| 2115 EXPECT_EQ(0, test_observer_->output_volume_changed_count()); | 1997 EXPECT_EQ(0, test_observer_->output_volume_changed_count()); |
| 2116 EXPECT_EQ(kDefaultVolume, cras_audio_handler_->GetOutputVolumePercent()); | 1998 EXPECT_EQ(kDefaultVolume, cras_audio_handler_->GetOutputVolumePercent()); |
| 2117 | 1999 |
| 2118 // Verify the output volume is changed to the designated value after | 2000 // Verify the output volume is changed to the designated value after |
| 2119 // OnOutputNodeVolumeChanged cras signal fires, and the volume change event | 2001 // OnOutputNodeVolumeChanged cras signal fires, and the volume change event |
| 2120 // has been fired to notify the observers. | 2002 // has been fired to notify the observers. |
| 2121 fake_cras_audio_client_->NotifyOutputNodeVolumeChangedForTesting( | 2003 fake_cras_audio_client_->NotifyOutputNodeVolumeChangedForTesting( |
| 2122 kInternalSpeaker.id, kVolume); | 2004 kInternalSpeaker->id, kVolume); |
| 2123 EXPECT_EQ(1, test_observer_->output_volume_changed_count()); | 2005 EXPECT_EQ(1, test_observer_->output_volume_changed_count()); |
| 2124 EXPECT_EQ(kVolume, cras_audio_handler_->GetOutputVolumePercent()); | 2006 EXPECT_EQ(kVolume, cras_audio_handler_->GetOutputVolumePercent()); |
| 2125 AudioDevice device; | 2007 AudioDevice device; |
| 2126 EXPECT_TRUE(cras_audio_handler_->GetPrimaryActiveOutputDevice(&device)); | 2008 EXPECT_TRUE(cras_audio_handler_->GetPrimaryActiveOutputDevice(&device)); |
| 2127 EXPECT_EQ(device.id, kInternalSpeaker.id); | 2009 EXPECT_EQ(device.id, kInternalSpeaker->id); |
| 2128 EXPECT_EQ(kVolume, audio_pref_handler_->GetOutputVolumeValue(&device)); | 2010 EXPECT_EQ(kVolume, audio_pref_handler_->GetOutputVolumeValue(&device)); |
| 2129 } | 2011 } |
| 2130 | 2012 |
| 2131 TEST_F(CrasAudioHandlerTest, | 2013 TEST_P(CrasAudioHandlerTest, |
| 2132 ChangeOutputVolumesWithDelayedSignalForSingleActiveDevice) { | 2014 ChangeOutputVolumesWithDelayedSignalForSingleActiveDevice) { |
| 2133 AudioNodeList audio_nodes; | 2015 AudioNodeList audio_nodes = GenerateAudioNodeList({kInternalSpeaker}); |
| 2134 audio_nodes.push_back(kInternalSpeaker); | |
| 2135 SetUpCrasAudioHandler(audio_nodes); | 2016 SetUpCrasAudioHandler(audio_nodes); |
| 2136 EXPECT_EQ(0, test_observer_->output_volume_changed_count()); | 2017 EXPECT_EQ(0, test_observer_->output_volume_changed_count()); |
| 2137 | 2018 |
| 2138 const int kDefaultVolume = 75; | 2019 const int kDefaultVolume = 75; |
| 2139 EXPECT_EQ(kDefaultVolume, cras_audio_handler_->GetOutputVolumePercent()); | 2020 EXPECT_EQ(kDefaultVolume, cras_audio_handler_->GetOutputVolumePercent()); |
| 2140 | 2021 |
| 2141 // Disable the auto OutputNodeVolumeChanged signal. | 2022 // Disable the auto OutputNodeVolumeChanged signal. |
| 2142 fake_cras_audio_client_->set_notify_volume_change_with_delay(true); | 2023 fake_cras_audio_client_->set_notify_volume_change_with_delay(true); |
| 2143 | 2024 |
| 2144 // Verify the volume state is not changed before OutputNodeVolumeChanged | 2025 // Verify the volume state is not changed before OutputNodeVolumeChanged |
| 2145 // signal fires. | 2026 // signal fires. |
| 2146 const int kVolume1 = 50; | 2027 const int kVolume1 = 50; |
| 2147 const int kVolume2 = 60; | 2028 const int kVolume2 = 60; |
| 2148 cras_audio_handler_->SetOutputVolumePercent(kVolume1); | 2029 cras_audio_handler_->SetOutputVolumePercent(kVolume1); |
| 2149 cras_audio_handler_->SetOutputVolumePercent(kVolume2); | 2030 cras_audio_handler_->SetOutputVolumePercent(kVolume2); |
| 2150 EXPECT_EQ(0, test_observer_->output_volume_changed_count()); | 2031 EXPECT_EQ(0, test_observer_->output_volume_changed_count()); |
| 2151 EXPECT_EQ(kDefaultVolume, cras_audio_handler_->GetOutputVolumePercent()); | 2032 EXPECT_EQ(kDefaultVolume, cras_audio_handler_->GetOutputVolumePercent()); |
| 2152 | 2033 |
| 2153 // Simulate OutputNodeVolumeChanged signal fired with big latency that | 2034 // Simulate OutputNodeVolumeChanged signal fired with big latency that |
| 2154 // it lags behind the SetOutputNodeVolume requests. Chrome sets the volume | 2035 // it lags behind the SetOutputNodeVolume requests. Chrome sets the volume |
| 2155 // to 50 then 60, but the volume changed signal for 50 comes back after | 2036 // to 50 then 60, but the volume changed signal for 50 comes back after |
| 2156 // chrome sets the volume to 60. Verify chrome will sync to the designated | 2037 // chrome sets the volume to 60. Verify chrome will sync to the designated |
| 2157 // volume level after all signals arrive. | 2038 // volume level after all signals arrive. |
| 2158 fake_cras_audio_client_->NotifyOutputNodeVolumeChangedForTesting( | 2039 fake_cras_audio_client_->NotifyOutputNodeVolumeChangedForTesting( |
| 2159 kInternalSpeaker.id, kVolume1); | 2040 kInternalSpeaker->id, kVolume1); |
| 2160 EXPECT_EQ(1, test_observer_->output_volume_changed_count()); | 2041 EXPECT_EQ(1, test_observer_->output_volume_changed_count()); |
| 2161 EXPECT_EQ(kVolume1, cras_audio_handler_->GetOutputVolumePercent()); | 2042 EXPECT_EQ(kVolume1, cras_audio_handler_->GetOutputVolumePercent()); |
| 2162 | 2043 |
| 2163 fake_cras_audio_client_->NotifyOutputNodeVolumeChangedForTesting( | 2044 fake_cras_audio_client_->NotifyOutputNodeVolumeChangedForTesting( |
| 2164 kInternalSpeaker.id, kVolume2); | 2045 kInternalSpeaker->id, kVolume2); |
| 2165 EXPECT_EQ(2, test_observer_->output_volume_changed_count()); | 2046 EXPECT_EQ(2, test_observer_->output_volume_changed_count()); |
| 2166 EXPECT_EQ(kVolume2, cras_audio_handler_->GetOutputVolumePercent()); | 2047 EXPECT_EQ(kVolume2, cras_audio_handler_->GetOutputVolumePercent()); |
| 2167 } | 2048 } |
| 2168 | 2049 |
| 2169 TEST_F(CrasAudioHandlerTest, | 2050 TEST_P(CrasAudioHandlerTest, |
| 2170 ChangeOutputVolumeFromNonChromeSourceSingleActiveDevice) { | 2051 ChangeOutputVolumeFromNonChromeSourceSingleActiveDevice) { |
| 2171 AudioNodeList audio_nodes; | 2052 AudioNodeList audio_nodes = GenerateAudioNodeList({kInternalSpeaker}); |
| 2172 audio_nodes.push_back(kInternalSpeaker); | |
| 2173 SetUpCrasAudioHandler(audio_nodes); | 2053 SetUpCrasAudioHandler(audio_nodes); |
| 2174 EXPECT_EQ(0, test_observer_->output_volume_changed_count()); | 2054 EXPECT_EQ(0, test_observer_->output_volume_changed_count()); |
| 2175 | 2055 |
| 2176 const int kDefaultVolume = 75; | 2056 const int kDefaultVolume = 75; |
| 2177 EXPECT_EQ(0, test_observer_->output_volume_changed_count()); | 2057 EXPECT_EQ(0, test_observer_->output_volume_changed_count()); |
| 2178 EXPECT_EQ(kDefaultVolume, cras_audio_handler_->GetOutputVolumePercent()); | 2058 EXPECT_EQ(kDefaultVolume, cras_audio_handler_->GetOutputVolumePercent()); |
| 2179 | 2059 |
| 2180 // Simulate OutputNodeVolumeChanged signal fired by a non-chrome source. | 2060 // Simulate OutputNodeVolumeChanged signal fired by a non-chrome source. |
| 2181 // Verify chrome will sync its volume state to the volume from the signal, | 2061 // Verify chrome will sync its volume state to the volume from the signal, |
| 2182 // and notify its observers for the volume change event. | 2062 // and notify its observers for the volume change event. |
| 2183 const int kVolume = 20; | 2063 const int kVolume = 20; |
| 2184 fake_cras_audio_client_->NotifyOutputNodeVolumeChangedForTesting( | 2064 fake_cras_audio_client_->NotifyOutputNodeVolumeChangedForTesting( |
| 2185 kInternalSpeaker.id, kVolume); | 2065 kInternalSpeaker->id, kVolume); |
| 2186 EXPECT_EQ(1, test_observer_->output_volume_changed_count()); | 2066 EXPECT_EQ(1, test_observer_->output_volume_changed_count()); |
| 2187 EXPECT_EQ(kVolume, cras_audio_handler_->GetOutputVolumePercent()); | 2067 EXPECT_EQ(kVolume, cras_audio_handler_->GetOutputVolumePercent()); |
| 2188 AudioDevice device; | 2068 AudioDevice device; |
| 2189 EXPECT_TRUE(cras_audio_handler_->GetPrimaryActiveOutputDevice(&device)); | 2069 EXPECT_TRUE(cras_audio_handler_->GetPrimaryActiveOutputDevice(&device)); |
| 2190 EXPECT_EQ(device.id, kInternalSpeaker.id); | 2070 EXPECT_EQ(device.id, kInternalSpeaker->id); |
| 2191 EXPECT_EQ(kVolume, audio_pref_handler_->GetOutputVolumeValue(&device)); | 2071 EXPECT_EQ(kVolume, audio_pref_handler_->GetOutputVolumeValue(&device)); |
| 2192 } | 2072 } |
| 2193 | 2073 |
| 2194 TEST_F(CrasAudioHandlerTest, SetInputGainPercent) { | 2074 TEST_P(CrasAudioHandlerTest, SetInputGainPercent) { |
| 2195 AudioNodeList audio_nodes; | 2075 AudioNodeList audio_nodes = GenerateAudioNodeList({kInternalMic}); |
| 2196 audio_nodes.push_back(kInternalMic); | |
| 2197 SetUpCrasAudioHandler(audio_nodes); | 2076 SetUpCrasAudioHandler(audio_nodes); |
| 2198 EXPECT_EQ(0, test_observer_->input_gain_changed_count()); | 2077 EXPECT_EQ(0, test_observer_->input_gain_changed_count()); |
| 2199 | 2078 |
| 2200 cras_audio_handler_->SetInputGainPercent(60); | 2079 cras_audio_handler_->SetInputGainPercent(60); |
| 2201 | 2080 |
| 2202 // Verify the input gain changed to the designated value, | 2081 // Verify the input gain changed to the designated value, |
| 2203 // OnInputNodeGainChanged event is fired, and the device gain value | 2082 // OnInputNodeGainChanged event is fired, and the device gain value |
| 2204 // is saved in the preferences. | 2083 // is saved in the preferences. |
| 2205 const int kGain = 60; | 2084 const int kGain = 60; |
| 2206 EXPECT_EQ(kGain, cras_audio_handler_->GetInputGainPercent()); | 2085 EXPECT_EQ(kGain, cras_audio_handler_->GetInputGainPercent()); |
| 2207 EXPECT_EQ(1, test_observer_->input_gain_changed_count()); | 2086 EXPECT_EQ(1, test_observer_->input_gain_changed_count()); |
| 2208 AudioDevice internal_mic(kInternalMic); | 2087 AudioDevice internal_mic(GenerateAudioNode(kInternalMic)); |
| 2209 EXPECT_EQ(kGain, audio_pref_handler_->GetInputGainValue(&internal_mic)); | 2088 EXPECT_EQ(kGain, audio_pref_handler_->GetInputGainValue(&internal_mic)); |
| 2210 } | 2089 } |
| 2211 | 2090 |
| 2212 TEST_F(CrasAudioHandlerTest, SetMuteForDevice) { | 2091 TEST_P(CrasAudioHandlerTest, SetMuteForDevice) { |
| 2213 AudioNodeList audio_nodes; | 2092 AudioNodeList audio_nodes = GenerateAudioNodeList( |
| 2214 audio_nodes.push_back(kInternalSpeaker); | 2093 {kInternalSpeaker, kHeadphone, kInternalMic, kUSBMic}); |
| 2215 audio_nodes.push_back(kHeadphone); | |
| 2216 audio_nodes.push_back(kInternalMic); | |
| 2217 audio_nodes.push_back(kUSBMic); | |
| 2218 SetUpCrasAudioHandler(audio_nodes); | 2094 SetUpCrasAudioHandler(audio_nodes); |
| 2219 | 2095 |
| 2220 // Mute the active output device. | 2096 // Mute the active output device. |
| 2221 EXPECT_EQ(kHeadphone.id, cras_audio_handler_->GetPrimaryActiveOutputNode()); | 2097 EXPECT_EQ(kHeadphone->id, cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 2222 cras_audio_handler_->SetMuteForDevice(kHeadphone.id, true); | 2098 cras_audio_handler_->SetMuteForDevice(kHeadphone->id, true); |
| 2223 | 2099 |
| 2224 // Verify the headphone is muted and mute value is saved in the preferences. | 2100 // Verify the headphone is muted and mute value is saved in the preferences. |
| 2225 EXPECT_TRUE(cras_audio_handler_->IsOutputMutedForDevice(kHeadphone.id)); | 2101 EXPECT_TRUE(cras_audio_handler_->IsOutputMutedForDevice(kHeadphone->id)); |
| 2226 AudioDevice headphone(kHeadphone); | 2102 AudioDevice headphone(GenerateAudioNode(kHeadphone)); |
| 2227 EXPECT_TRUE(audio_pref_handler_->GetMuteValue(headphone)); | 2103 EXPECT_TRUE(audio_pref_handler_->GetMuteValue(headphone)); |
| 2228 | 2104 |
| 2229 // Mute the non-active output device. | 2105 // Mute the non-active output device. |
| 2230 cras_audio_handler_->SetMuteForDevice(kInternalSpeaker.id, true); | 2106 cras_audio_handler_->SetMuteForDevice(kInternalSpeaker->id, true); |
| 2231 | 2107 |
| 2232 // Verify the internal speaker is muted and mute value is saved in the | 2108 // Verify the internal speaker is muted and mute value is saved in the |
| 2233 // preferences. | 2109 // preferences. |
| 2234 EXPECT_TRUE(cras_audio_handler_->IsOutputMutedForDevice(kInternalSpeaker.id)); | 2110 EXPECT_TRUE( |
| 2235 AudioDevice internal_speaker(kInternalSpeaker); | 2111 cras_audio_handler_->IsOutputMutedForDevice(kInternalSpeaker->id)); |
| 2112 AudioDevice internal_speaker(GenerateAudioNode(kInternalSpeaker)); |
| 2236 EXPECT_TRUE(audio_pref_handler_->GetMuteValue(internal_speaker)); | 2113 EXPECT_TRUE(audio_pref_handler_->GetMuteValue(internal_speaker)); |
| 2237 | 2114 |
| 2238 // Mute the active input device. | 2115 // Mute the active input device. |
| 2239 EXPECT_EQ(kUSBMic.id, cras_audio_handler_->GetPrimaryActiveInputNode()); | 2116 EXPECT_EQ(kUSBMic->id, cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 2240 cras_audio_handler_->SetMuteForDevice(kUSBMic.id, true); | 2117 cras_audio_handler_->SetMuteForDevice(kUSBMic->id, true); |
| 2241 | 2118 |
| 2242 // Verify the USB Mic is muted. | 2119 // Verify the USB Mic is muted. |
| 2243 EXPECT_TRUE(cras_audio_handler_->IsInputMutedForDevice(kUSBMic.id)); | 2120 EXPECT_TRUE(cras_audio_handler_->IsInputMutedForDevice(kUSBMic->id)); |
| 2244 | 2121 |
| 2245 // Mute the non-active input device should be a no-op, see crbug.com/365050. | 2122 // Mute the non-active input device should be a no-op, see crbug.com/365050. |
| 2246 cras_audio_handler_->SetMuteForDevice(kInternalMic.id, true); | 2123 cras_audio_handler_->SetMuteForDevice(kInternalMic->id, true); |
| 2247 | 2124 |
| 2248 // Verify IsInputMutedForDevice returns false for non-active input device. | 2125 // Verify IsInputMutedForDevice returns false for non-active input device. |
| 2249 EXPECT_FALSE(cras_audio_handler_->IsInputMutedForDevice(kInternalMic.id)); | 2126 EXPECT_FALSE(cras_audio_handler_->IsInputMutedForDevice(kInternalMic->id)); |
| 2250 } | 2127 } |
| 2251 | 2128 |
| 2252 TEST_F(CrasAudioHandlerTest, SetVolumeGainPercentForDevice) { | 2129 TEST_P(CrasAudioHandlerTest, SetVolumeGainPercentForDevice) { |
| 2253 AudioNodeList audio_nodes; | 2130 AudioNodeList audio_nodes = GenerateAudioNodeList( |
| 2254 audio_nodes.push_back(kInternalSpeaker); | 2131 {kInternalSpeaker, kHeadphone, kInternalMic, kUSBMic}); |
| 2255 audio_nodes.push_back(kHeadphone); | |
| 2256 audio_nodes.push_back(kInternalMic); | |
| 2257 audio_nodes.push_back(kUSBMic); | |
| 2258 SetUpCrasAudioHandler(audio_nodes); | 2132 SetUpCrasAudioHandler(audio_nodes); |
| 2259 | 2133 |
| 2260 // Set volume percent for active output device. | 2134 // Set volume percent for active output device. |
| 2261 const int kHeadphoneVolume = 30; | 2135 const int kHeadphoneVolume = 30; |
| 2262 EXPECT_EQ(kHeadphone.id, cras_audio_handler_->GetPrimaryActiveOutputNode()); | 2136 EXPECT_EQ(kHeadphone->id, cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 2263 cras_audio_handler_->SetVolumeGainPercentForDevice(kHeadphone.id, | 2137 cras_audio_handler_->SetVolumeGainPercentForDevice(kHeadphone->id, |
| 2264 kHeadphoneVolume); | 2138 kHeadphoneVolume); |
| 2265 | 2139 |
| 2266 // Verify the volume percent of headphone is set, and saved in preferences. | 2140 // Verify the volume percent of headphone is set, and saved in preferences. |
| 2267 EXPECT_EQ(kHeadphoneVolume, | 2141 EXPECT_EQ( |
| 2268 cras_audio_handler_->GetOutputVolumePercentForDevice( | 2142 kHeadphoneVolume, |
| 2269 kHeadphone.id)); | 2143 cras_audio_handler_->GetOutputVolumePercentForDevice(kHeadphone->id)); |
| 2270 AudioDevice headphone(kHeadphone); | 2144 AudioDevice headphone(GenerateAudioNode(kHeadphone)); |
| 2271 EXPECT_EQ(kHeadphoneVolume, | 2145 EXPECT_EQ(kHeadphoneVolume, |
| 2272 audio_pref_handler_->GetOutputVolumeValue(&headphone)); | 2146 audio_pref_handler_->GetOutputVolumeValue(&headphone)); |
| 2273 | 2147 |
| 2274 // Set volume percent for non-active output device. | 2148 // Set volume percent for non-active output device. |
| 2275 const int kSpeakerVolume = 60; | 2149 const int kSpeakerVolume = 60; |
| 2276 cras_audio_handler_->SetVolumeGainPercentForDevice(kInternalSpeaker.id, | 2150 cras_audio_handler_->SetVolumeGainPercentForDevice(kInternalSpeaker->id, |
| 2277 kSpeakerVolume); | 2151 kSpeakerVolume); |
| 2278 | 2152 |
| 2279 // Verify the volume percent of speaker is set, and saved in preferences. | 2153 // Verify the volume percent of speaker is set, and saved in preferences. |
| 2280 EXPECT_EQ(kSpeakerVolume, | 2154 EXPECT_EQ(kSpeakerVolume, |
| 2281 cras_audio_handler_->GetOutputVolumePercentForDevice( | 2155 cras_audio_handler_->GetOutputVolumePercentForDevice( |
| 2282 kInternalSpeaker.id)); | 2156 kInternalSpeaker->id)); |
| 2283 AudioDevice speaker(kInternalSpeaker); | 2157 AudioDevice speaker(GenerateAudioNode(kInternalSpeaker)); |
| 2284 EXPECT_EQ(kSpeakerVolume, | 2158 EXPECT_EQ(kSpeakerVolume, |
| 2285 audio_pref_handler_->GetOutputVolumeValue(&speaker)); | 2159 audio_pref_handler_->GetOutputVolumeValue(&speaker)); |
| 2286 | 2160 |
| 2287 // Set gain percent for active input device. | 2161 // Set gain percent for active input device. |
| 2288 const int kUSBMicGain = 30; | 2162 const int kUSBMicGain = 30; |
| 2289 EXPECT_EQ(kUSBMic.id, cras_audio_handler_->GetPrimaryActiveInputNode()); | 2163 EXPECT_EQ(kUSBMic->id, cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 2290 cras_audio_handler_->SetVolumeGainPercentForDevice(kUSBMic.id, | 2164 cras_audio_handler_->SetVolumeGainPercentForDevice(kUSBMic->id, kUSBMicGain); |
| 2291 kUSBMicGain); | |
| 2292 | 2165 |
| 2293 // Verify the gain percent of USB mic is set, and saved in preferences. | 2166 // Verify the gain percent of USB mic is set, and saved in preferences. |
| 2294 EXPECT_EQ(kUSBMicGain, | 2167 EXPECT_EQ(kUSBMicGain, |
| 2295 cras_audio_handler_->GetOutputVolumePercentForDevice(kUSBMic.id)); | 2168 cras_audio_handler_->GetOutputVolumePercentForDevice(kUSBMic->id)); |
| 2296 AudioDevice usb_mic(kHeadphone); | 2169 AudioDevice usb_mic(GenerateAudioNode(kHeadphone)); |
| 2297 EXPECT_EQ(kUSBMicGain, | 2170 EXPECT_EQ(kUSBMicGain, |
| 2298 audio_pref_handler_->GetInputGainValue(&usb_mic)); | 2171 audio_pref_handler_->GetInputGainValue(&usb_mic)); |
| 2299 | 2172 |
| 2300 // Set gain percent for non-active input device. | 2173 // Set gain percent for non-active input device. |
| 2301 const int kInternalMicGain = 60; | 2174 const int kInternalMicGain = 60; |
| 2302 cras_audio_handler_->SetVolumeGainPercentForDevice(kInternalMic.id, | 2175 cras_audio_handler_->SetVolumeGainPercentForDevice(kInternalMic->id, |
| 2303 kInternalMicGain); | 2176 kInternalMicGain); |
| 2304 | 2177 |
| 2305 // Verify the gain percent of internal mic is set, and saved in preferences. | 2178 // Verify the gain percent of internal mic is set, and saved in preferences. |
| 2306 EXPECT_EQ(kInternalMicGain, | 2179 EXPECT_EQ( |
| 2307 cras_audio_handler_->GetOutputVolumePercentForDevice( | 2180 kInternalMicGain, |
| 2308 kInternalMic.id)); | 2181 cras_audio_handler_->GetOutputVolumePercentForDevice(kInternalMic->id)); |
| 2309 AudioDevice internal_mic(kInternalMic); | 2182 AudioDevice internal_mic(GenerateAudioNode(kInternalMic)); |
| 2310 EXPECT_EQ(kInternalMicGain, | 2183 EXPECT_EQ(kInternalMicGain, |
| 2311 audio_pref_handler_->GetInputGainValue(&internal_mic)); | 2184 audio_pref_handler_->GetInputGainValue(&internal_mic)); |
| 2312 } | 2185 } |
| 2313 | 2186 |
| 2314 TEST_F(CrasAudioHandlerTest, HandleOtherDeviceType) { | 2187 TEST_P(CrasAudioHandlerTest, HandleOtherDeviceType) { |
| 2315 const size_t kNumValidAudioDevices = 4; | 2188 const size_t kNumValidAudioDevices = 4; |
| 2316 AudioNodeList audio_nodes; | 2189 AudioNodeList audio_nodes = GenerateAudioNodeList( |
| 2317 audio_nodes.push_back(kInternalSpeaker); | 2190 {kInternalSpeaker, kOtherTypeOutput, kInternalMic, kOtherTypeInput}); |
| 2318 audio_nodes.push_back(kOtherTypeOutput); | |
| 2319 audio_nodes.push_back(kInternalMic); | |
| 2320 audio_nodes.push_back(kOtherTypeInput); | |
| 2321 SetUpCrasAudioHandler(audio_nodes); | 2191 SetUpCrasAudioHandler(audio_nodes); |
| 2322 | 2192 |
| 2323 // Verify the audio devices size. | 2193 // Verify the audio devices size. |
| 2324 AudioDeviceList audio_devices; | 2194 AudioDeviceList audio_devices; |
| 2325 cras_audio_handler_->GetAudioDevices(&audio_devices); | 2195 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 2326 EXPECT_EQ(kNumValidAudioDevices, audio_devices.size()); | 2196 EXPECT_EQ(kNumValidAudioDevices, audio_devices.size()); |
| 2327 | 2197 |
| 2328 // Verify the internal speaker has been selected as the active output, | 2198 // Verify the internal speaker has been selected as the active output, |
| 2329 // and the output device with some randown unknown type is handled gracefully. | 2199 // and the output device with some randown unknown type is handled gracefully. |
| 2330 AudioDevice active_output; | 2200 AudioDevice active_output; |
| 2331 EXPECT_TRUE( | 2201 EXPECT_TRUE( |
| 2332 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); | 2202 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
| 2333 EXPECT_EQ(kInternalSpeaker.id, active_output.id); | 2203 EXPECT_EQ(kInternalSpeaker->id, active_output.id); |
| 2334 EXPECT_EQ(kInternalSpeaker.id, | 2204 EXPECT_EQ(kInternalSpeaker->id, |
| 2335 cras_audio_handler_->GetPrimaryActiveOutputNode()); | 2205 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 2336 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); | 2206 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
| 2337 | 2207 |
| 2338 // Ensure the internal microphone has been selected as the active input, | 2208 // Ensure the internal microphone has been selected as the active input, |
| 2339 // and the input device with some random unknown type is handled gracefully. | 2209 // and the input device with some random unknown type is handled gracefully. |
| 2340 AudioDevice active_input; | 2210 AudioDevice active_input; |
| 2341 EXPECT_EQ(kInternalMic.id, cras_audio_handler_->GetPrimaryActiveInputNode()); | 2211 EXPECT_EQ(kInternalMic->id, cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 2342 EXPECT_TRUE(cras_audio_handler_->has_alternative_input()); | 2212 EXPECT_TRUE(cras_audio_handler_->has_alternative_input()); |
| 2343 } | 2213 } |
| 2344 | 2214 |
| 2345 TEST_F(CrasAudioHandlerTest, ActiveDeviceSelectionWithStableDeviceId) { | 2215 TEST_P(CrasAudioHandlerTest, ActiveDeviceSelectionWithStableDeviceId) { |
| 2346 AudioNodeList audio_nodes; | 2216 AudioNodeList audio_nodes; |
| 2347 AudioNode internal_speaker(kInternalSpeaker); | 2217 AudioNode internal_speaker = GenerateAudioNode(kInternalSpeaker); |
| 2348 audio_nodes.push_back(internal_speaker); | 2218 audio_nodes.push_back(internal_speaker); |
| 2349 AudioNode usb_headset(kUSBHeadphone1); | 2219 AudioNode usb_headset = GenerateAudioNode(kUSBHeadphone1); |
| 2350 usb_headset.plugged_time = 80000000; | 2220 usb_headset.plugged_time = 80000000; |
| 2351 audio_nodes.push_back(usb_headset); | 2221 audio_nodes.push_back(usb_headset); |
| 2352 SetUpCrasAudioHandler(audio_nodes); | 2222 SetUpCrasAudioHandler(audio_nodes); |
| 2353 | 2223 |
| 2354 // Verify the audio devices size. | 2224 // Verify the audio devices size. |
| 2355 AudioDeviceList audio_devices; | 2225 AudioDeviceList audio_devices; |
| 2356 cras_audio_handler_->GetAudioDevices(&audio_devices); | 2226 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 2357 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); | 2227 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); |
| 2358 | 2228 |
| 2359 // Initially active node is selected base on priority, so USB headphone | 2229 // Initially active node is selected base on priority, so USB headphone |
| 2360 // is selected. | 2230 // is selected. |
| 2361 EXPECT_EQ(kUSBHeadphone1.id, | 2231 EXPECT_EQ(kUSBHeadphone1->id, |
| 2362 cras_audio_handler_->GetPrimaryActiveOutputNode()); | 2232 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 2363 | 2233 |
| 2364 // Change the active device to internal speaker, now USB headphone becomes | 2234 // Change the active device to internal speaker, now USB headphone becomes |
| 2365 // inactive. | 2235 // inactive. |
| 2366 AudioDevice speaker(kInternalSpeaker); | 2236 AudioDevice speaker(GenerateAudioNode(kInternalSpeaker)); |
| 2367 cras_audio_handler_->SwitchToDevice(speaker, true, | 2237 cras_audio_handler_->SwitchToDevice(speaker, true, |
| 2368 CrasAudioHandler::ACTIVATE_BY_USER); | 2238 CrasAudioHandler::ACTIVATE_BY_USER); |
| 2369 EXPECT_NE(kUSBHeadphone1.id, | 2239 EXPECT_NE(kUSBHeadphone1->id, |
| 2370 cras_audio_handler_->GetPrimaryActiveOutputNode()); | 2240 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 2371 | 2241 |
| 2372 // Unplug USB headset. | 2242 // Unplug USB headset. |
| 2373 audio_nodes.clear(); | 2243 audio_nodes.clear(); |
| 2374 internal_speaker.active = true; | 2244 internal_speaker.active = true; |
| 2375 audio_nodes.push_back(internal_speaker); | 2245 audio_nodes.push_back(internal_speaker); |
| 2376 ChangeAudioNodes(audio_nodes); | 2246 ChangeAudioNodes(audio_nodes); |
| 2377 EXPECT_EQ(kInternalSpeaker.id, | 2247 EXPECT_EQ(kInternalSpeaker->id, |
| 2378 cras_audio_handler_->GetPrimaryActiveOutputNode()); | 2248 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 2379 | 2249 |
| 2380 // Plug the same USB headset back, id is different, but stable_device_id | 2250 // Plug the same USB headset back, id is different, but stable_device_id |
| 2381 // remains the same. | 2251 // remains the same. |
| 2382 usb_headset.active = false; | 2252 usb_headset.active = false; |
| 2383 usb_headset.id = 98765; | 2253 usb_headset.id = 98765; |
| 2384 audio_nodes.push_back(usb_headset); | 2254 audio_nodes.push_back(usb_headset); |
| 2385 ChangeAudioNodes(audio_nodes); | 2255 ChangeAudioNodes(audio_nodes); |
| 2386 | 2256 |
| 2387 // Since USB headset was inactive before it was unplugged, it won't be | 2257 // Since USB headset was inactive before it was unplugged, it won't be |
| 2388 // selected as active after it's plugged in again. | 2258 // selected as active after it's plugged in again. |
| 2389 EXPECT_EQ(kInternalSpeaker.id, | 2259 EXPECT_EQ(kInternalSpeaker->id, |
| 2390 cras_audio_handler_->GetPrimaryActiveOutputNode()); | 2260 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 2391 | 2261 |
| 2392 // Plug the second USB headset. | 2262 // Plug the second USB headset. |
| 2393 AudioNode usb_headset2(kUSBHeadphone2); | 2263 AudioNode usb_headset2 = GenerateAudioNode(kUSBHeadphone2); |
| 2394 usb_headset2.plugged_time = 80000001; | 2264 usb_headset2.plugged_time = 80000001; |
| 2395 audio_nodes.push_back(usb_headset2); | 2265 audio_nodes.push_back(usb_headset2); |
| 2396 ChangeAudioNodes(audio_nodes); | 2266 ChangeAudioNodes(audio_nodes); |
| 2397 | 2267 |
| 2398 // Since the second USB device is new, it's selected as the active device | 2268 // Since the second USB device is new, it's selected as the active device |
| 2399 // by its priority. | 2269 // by its priority. |
| 2400 EXPECT_EQ(kUSBHeadphone2.id, | 2270 EXPECT_EQ(kUSBHeadphone2->id, |
| 2401 cras_audio_handler_->GetPrimaryActiveOutputNode()); | 2271 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 2402 | 2272 |
| 2403 // Unplug the second USB headset. | 2273 // Unplug the second USB headset. |
| 2404 audio_nodes.clear(); | 2274 audio_nodes.clear(); |
| 2405 internal_speaker.active = false; | 2275 internal_speaker.active = false; |
| 2406 audio_nodes.push_back(internal_speaker); | 2276 audio_nodes.push_back(internal_speaker); |
| 2407 audio_nodes.push_back(usb_headset); | 2277 audio_nodes.push_back(usb_headset); |
| 2408 ChangeAudioNodes(audio_nodes); | 2278 ChangeAudioNodes(audio_nodes); |
| 2409 | 2279 |
| 2410 // There is no active node after USB2 unplugged, the 1st USB got selected | 2280 // There is no active node after USB2 unplugged, the 1st USB got selected |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2422 ChangeAudioNodes(audio_nodes); | 2292 ChangeAudioNodes(audio_nodes); |
| 2423 | 2293 |
| 2424 // Plug the second USB again. Since it was the active node before it got | 2294 // Plug the second USB again. Since it was the active node before it got |
| 2425 // unplugged, it is now selected as the active node. | 2295 // unplugged, it is now selected as the active node. |
| 2426 EXPECT_EQ(usb_headset2.id, cras_audio_handler_->GetPrimaryActiveOutputNode()); | 2296 EXPECT_EQ(usb_headset2.id, cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 2427 } | 2297 } |
| 2428 | 2298 |
| 2429 // Test the device new session case, either via reboot or logout, if there | 2299 // Test the device new session case, either via reboot or logout, if there |
| 2430 // is an active device in the previous session, that device should still | 2300 // is an active device in the previous session, that device should still |
| 2431 // be set as active after the new session starts. | 2301 // be set as active after the new session starts. |
| 2432 TEST_F(CrasAudioHandlerTest, PersistActiveDeviceAcrossSession) { | 2302 TEST_P(CrasAudioHandlerTest, PersistActiveDeviceAcrossSession) { |
| 2433 // Set the active device to internal speaker before the session starts. | 2303 // Set the active device to internal speaker before the session starts. |
| 2434 AudioNodeList audio_nodes; | 2304 AudioNodeList audio_nodes = |
| 2435 audio_nodes.push_back(kInternalSpeaker); | 2305 GenerateAudioNodeList({kInternalSpeaker, kHeadphone}); |
| 2436 audio_nodes.push_back(kHeadphone); | |
| 2437 SetupCrasAudioHandlerWithActiveNodeInPref( | 2306 SetupCrasAudioHandlerWithActiveNodeInPref( |
| 2438 audio_nodes, audio_nodes, AudioDevice(kInternalSpeaker), true); | 2307 audio_nodes, audio_nodes, |
| 2308 AudioDevice(GenerateAudioNode(kInternalSpeaker)), true); |
| 2439 | 2309 |
| 2440 // Verify the audio devices size. | 2310 // Verify the audio devices size. |
| 2441 AudioDeviceList audio_devices; | 2311 AudioDeviceList audio_devices; |
| 2442 cras_audio_handler_->GetAudioDevices(&audio_devices); | 2312 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 2443 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); | 2313 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); |
| 2444 | 2314 |
| 2445 // Verify the active device is the internal speaker, which is of a lower | 2315 // Verify the active device is the internal speaker, which is of a lower |
| 2446 // priority, but selected as active since it was the active device previously. | 2316 // priority, but selected as active since it was the active device previously. |
| 2447 EXPECT_EQ(kInternalSpeaker.id, | 2317 EXPECT_EQ(kInternalSpeaker->id, |
| 2448 cras_audio_handler_->GetPrimaryActiveOutputNode()); | 2318 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 2449 } | 2319 } |
| 2450 | 2320 |
| 2451 TEST_F(CrasAudioHandlerTest, PersistActiveSpeakerAcrossReboot) { | 2321 TEST_P(CrasAudioHandlerTest, PersistActiveSpeakerAcrossReboot) { |
| 2452 // Simulates the device was shut down with three audio devices, and | 2322 // Simulates the device was shut down with three audio devices, and |
| 2453 // internal speaker being the active one selected by user. | 2323 // internal speaker being the active one selected by user. |
| 2454 AudioNodeList audio_nodes_in_pref; | 2324 AudioNodeList audio_nodes_in_pref = |
| 2455 audio_nodes_in_pref.push_back(kInternalSpeaker); | 2325 GenerateAudioNodeList({kInternalSpeaker, kHeadphone, kUSBHeadphone1}); |
| 2456 audio_nodes_in_pref.push_back(kHeadphone); | |
| 2457 audio_nodes_in_pref.push_back(kUSBHeadphone1); | |
| 2458 | 2326 |
| 2459 // Simulate the first NodesChanged signal coming with only one node. | 2327 // Simulate the first NodesChanged signal coming with only one node. |
| 2460 AudioNodeList audio_nodes; | 2328 AudioNodeList audio_nodes = GenerateAudioNodeList({kUSBHeadphone1}); |
| 2461 audio_nodes.push_back(kUSBHeadphone1); | |
| 2462 | 2329 |
| 2463 SetupCrasAudioHandlerWithActiveNodeInPref( | 2330 SetupCrasAudioHandlerWithActiveNodeInPref( |
| 2464 audio_nodes, audio_nodes_in_pref, AudioDevice(kInternalSpeaker), true); | 2331 audio_nodes, audio_nodes_in_pref, |
| 2332 AudioDevice(GenerateAudioNode(kInternalSpeaker)), true); |
| 2465 | 2333 |
| 2466 // Verify the usb headphone has been made active. | 2334 // Verify the usb headphone has been made active. |
| 2467 AudioDeviceList audio_devices; | 2335 AudioDeviceList audio_devices; |
| 2468 cras_audio_handler_->GetAudioDevices(&audio_devices); | 2336 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 2469 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); | 2337 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); |
| 2470 EXPECT_EQ(kUSBHeadphone1.id, | 2338 EXPECT_EQ(kUSBHeadphone1->id, |
| 2471 cras_audio_handler_->GetPrimaryActiveOutputNode()); | 2339 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 2472 | 2340 |
| 2473 // Simulate another NodesChanged signal coming later with all ndoes. | 2341 // Simulate another NodesChanged signal coming later with all ndoes. |
| 2474 audio_nodes.push_back(kInternalSpeaker); | 2342 audio_nodes.push_back(GenerateAudioNode(kInternalSpeaker)); |
| 2475 audio_nodes.push_back(kHeadphone); | 2343 audio_nodes.push_back(GenerateAudioNode(kHeadphone)); |
| 2476 ChangeAudioNodes(audio_nodes); | 2344 ChangeAudioNodes(audio_nodes); |
| 2477 | 2345 |
| 2478 // Verify the active output has been restored to internal speaker. | 2346 // Verify the active output has been restored to internal speaker. |
| 2479 cras_audio_handler_->GetAudioDevices(&audio_devices); | 2347 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 2480 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); | 2348 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); |
| 2481 EXPECT_EQ(kInternalSpeaker.id, | 2349 EXPECT_EQ(kInternalSpeaker->id, |
| 2482 cras_audio_handler_->GetPrimaryActiveOutputNode()); | 2350 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 2483 } | 2351 } |
| 2484 | 2352 |
| 2485 // Test the corner case that headphone is plugged in for the first time on | 2353 // Test the corner case that headphone is plugged in for the first time on |
| 2486 // a cros device after the device is shutdown. | 2354 // a cros device after the device is shutdown. |
| 2487 // crbug.com/622045. | 2355 // crbug.com/622045. |
| 2488 TEST_F(CrasAudioHandlerTest, PlugInHeadphoneFirstTimeAfterPowerDown) { | 2356 TEST_P(CrasAudioHandlerTest, PlugInHeadphoneFirstTimeAfterPowerDown) { |
| 2489 // Simulate plugging headphone for the first on a cros device after it is | 2357 // Simulate plugging headphone for the first on a cros device after it is |
| 2490 // powered down. Internal speaker is set up in audio prefs as active | 2358 // powered down. Internal speaker is set up in audio prefs as active |
| 2491 // before the new cros session starts. | 2359 // before the new cros session starts. |
| 2492 AudioNodeList audio_nodes_in_pref; | 2360 AudioNodeList audio_nodes_in_pref = GenerateAudioNodeList({kInternalSpeaker}); |
| 2493 audio_nodes_in_pref.push_back(kInternalSpeaker); | |
| 2494 | 2361 |
| 2495 AudioNodeList audio_nodes; | 2362 AudioNodeList audio_nodes = |
| 2496 audio_nodes.push_back(kInternalSpeaker); | 2363 GenerateAudioNodeList({kInternalSpeaker, kHeadphone}); |
| 2497 audio_nodes.push_back(kHeadphone); | |
| 2498 | 2364 |
| 2499 SetupCrasAudioHandlerWithActiveNodeInPref( | 2365 SetupCrasAudioHandlerWithActiveNodeInPref( |
| 2500 audio_nodes, audio_nodes_in_pref, AudioDevice(kInternalSpeaker), false); | 2366 audio_nodes, audio_nodes_in_pref, |
| 2367 AudioDevice(GenerateAudioNode(kInternalSpeaker)), false); |
| 2501 | 2368 |
| 2502 // Verify the audio devices size. | 2369 // Verify the audio devices size. |
| 2503 AudioDeviceList audio_devices; | 2370 AudioDeviceList audio_devices; |
| 2504 cras_audio_handler_->GetAudioDevices(&audio_devices); | 2371 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 2505 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); | 2372 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); |
| 2506 | 2373 |
| 2507 // Verify headphone becomes the active output. | 2374 // Verify headphone becomes the active output. |
| 2508 EXPECT_EQ(kHeadphone.id, cras_audio_handler_->GetPrimaryActiveOutputNode()); | 2375 EXPECT_EQ(kHeadphone->id, cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 2509 } | 2376 } |
| 2510 | 2377 |
| 2511 TEST_F(CrasAudioHandlerTest, | 2378 TEST_P(CrasAudioHandlerTest, |
| 2512 PersistActiveUsbHeadphoneAcrossRebootUsbComeLater) { | 2379 PersistActiveUsbHeadphoneAcrossRebootUsbComeLater) { |
| 2513 // Simulates the device was shut down with three audio devices, and | 2380 // Simulates the device was shut down with three audio devices, and |
| 2514 // usb headphone being the active one selected by priority. | 2381 // usb headphone being the active one selected by priority. |
| 2515 AudioNodeList audio_nodes_in_pref; | 2382 AudioNodeList audio_nodes_in_pref = |
| 2516 audio_nodes_in_pref.push_back(kInternalSpeaker); | 2383 GenerateAudioNodeList({kInternalSpeaker, kHeadphone, kUSBHeadphone1}); |
| 2517 audio_nodes_in_pref.push_back(kHeadphone); | |
| 2518 audio_nodes_in_pref.push_back(kUSBHeadphone1); | |
| 2519 | 2384 |
| 2520 // Simulate the first NodesChanged signal coming with only internal speaker | 2385 // Simulate the first NodesChanged signal coming with only internal speaker |
| 2521 // and the headphone. | 2386 // and the headphone. |
| 2522 AudioNodeList audio_nodes; | 2387 AudioNodeList audio_nodes = |
| 2523 audio_nodes.push_back(kInternalSpeaker); | 2388 GenerateAudioNodeList({kInternalSpeaker, kHeadphone}); |
| 2524 audio_nodes.push_back(kHeadphone); | |
| 2525 | 2389 |
| 2526 SetupCrasAudioHandlerWithActiveNodeInPref(audio_nodes, audio_nodes_in_pref, | 2390 SetupCrasAudioHandlerWithActiveNodeInPref( |
| 2527 AudioDevice(kUSBHeadphone1), false); | 2391 audio_nodes, audio_nodes_in_pref, |
| 2392 AudioDevice(GenerateAudioNode(kUSBHeadphone1)), false); |
| 2528 | 2393 |
| 2529 // Verify the headphone has been made active. | 2394 // Verify the headphone has been made active. |
| 2530 AudioDeviceList audio_devices; | 2395 AudioDeviceList audio_devices; |
| 2531 cras_audio_handler_->GetAudioDevices(&audio_devices); | 2396 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 2532 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); | 2397 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); |
| 2533 EXPECT_EQ(kHeadphone.id, cras_audio_handler_->GetPrimaryActiveOutputNode()); | 2398 EXPECT_EQ(kHeadphone->id, cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 2534 | 2399 |
| 2535 // Simulate USB node comes later with all ndoes. | 2400 // Simulate USB node comes later with all ndoes. |
| 2536 AudioNode usb_node(kUSBHeadphone1); | 2401 AudioNode usb_node = GenerateAudioNode(kUSBHeadphone1); |
| 2537 usb_node.plugged_time = 80000000; | 2402 usb_node.plugged_time = 80000000; |
| 2538 audio_nodes.push_back(usb_node); | 2403 audio_nodes.push_back(usb_node); |
| 2539 ChangeAudioNodes(audio_nodes); | 2404 ChangeAudioNodes(audio_nodes); |
| 2540 | 2405 |
| 2541 // Verify the active output has been restored to usb headphone. | 2406 // Verify the active output has been restored to usb headphone. |
| 2542 cras_audio_handler_->GetAudioDevices(&audio_devices); | 2407 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 2543 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); | 2408 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); |
| 2544 EXPECT_EQ(kUSBHeadphone1.id, | 2409 EXPECT_EQ(kUSBHeadphone1->id, |
| 2545 cras_audio_handler_->GetPrimaryActiveOutputNode()); | 2410 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 2546 } | 2411 } |
| 2547 | 2412 |
| 2548 TEST_F(CrasAudioHandlerTest, | 2413 TEST_P(CrasAudioHandlerTest, |
| 2549 PersistActiveUsbHeadphoneAcrossRebootUsbComeFirst) { | 2414 PersistActiveUsbHeadphoneAcrossRebootUsbComeFirst) { |
| 2550 // Simulates the device was shut down with three audio devices, and | 2415 // Simulates the device was shut down with three audio devices, and |
| 2551 // usb headphone being the active one selected by priority. | 2416 // usb headphone being the active one selected by priority. |
| 2552 AudioNodeList audio_nodes_in_pref; | 2417 AudioNodeList audio_nodes_in_pref = |
| 2553 audio_nodes_in_pref.push_back(kInternalSpeaker); | 2418 GenerateAudioNodeList({kInternalSpeaker, kHeadphone, kUSBHeadphone1}); |
| 2554 audio_nodes_in_pref.push_back(kHeadphone); | |
| 2555 audio_nodes_in_pref.push_back(kUSBHeadphone1); | |
| 2556 | 2419 |
| 2557 // Simulate the first NodesChanged signal coming with only internal speaker | 2420 // Simulate the first NodesChanged signal coming with only internal speaker |
| 2558 // and the USB headphone. | 2421 // and the USB headphone. |
| 2559 AudioNodeList audio_nodes; | 2422 AudioNodeList audio_nodes = |
| 2560 audio_nodes.push_back(kInternalSpeaker); | 2423 GenerateAudioNodeList({kInternalSpeaker, kUSBHeadphone1}); |
| 2561 audio_nodes.push_back(kUSBHeadphone1); | |
| 2562 | 2424 |
| 2563 SetupCrasAudioHandlerWithActiveNodeInPref(audio_nodes, audio_nodes_in_pref, | 2425 SetupCrasAudioHandlerWithActiveNodeInPref( |
| 2564 AudioDevice(kUSBHeadphone1), false); | 2426 audio_nodes, audio_nodes_in_pref, |
| 2427 AudioDevice(GenerateAudioNode(kUSBHeadphone1)), false); |
| 2565 | 2428 |
| 2566 // Verify the USB headphone has been made active. | 2429 // Verify the USB headphone has been made active. |
| 2567 AudioDeviceList audio_devices; | 2430 AudioDeviceList audio_devices; |
| 2568 cras_audio_handler_->GetAudioDevices(&audio_devices); | 2431 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 2569 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); | 2432 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); |
| 2570 EXPECT_EQ(kUSBHeadphone1.id, | 2433 EXPECT_EQ(kUSBHeadphone1->id, |
| 2571 cras_audio_handler_->GetPrimaryActiveOutputNode()); | 2434 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 2572 | 2435 |
| 2573 // Simulate another NodesChanged signal coming later with all ndoes. | 2436 // Simulate another NodesChanged signal coming later with all ndoes. |
| 2574 AudioNode headphone_node(kHeadphone); | 2437 AudioNode headphone_node = GenerateAudioNode(kHeadphone); |
| 2575 headphone_node.plugged_time = 80000000; | 2438 headphone_node.plugged_time = 80000000; |
| 2576 audio_nodes.push_back(headphone_node); | 2439 audio_nodes.push_back(headphone_node); |
| 2577 ChangeAudioNodes(audio_nodes); | 2440 ChangeAudioNodes(audio_nodes); |
| 2578 | 2441 |
| 2579 // Verify the active output has been restored to USB headphone. | 2442 // Verify the active output has been restored to USB headphone. |
| 2580 cras_audio_handler_->GetAudioDevices(&audio_devices); | 2443 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 2581 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); | 2444 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); |
| 2582 EXPECT_EQ(kUSBHeadphone1.id, | 2445 EXPECT_EQ(kUSBHeadphone1->id, |
| 2583 cras_audio_handler_->GetPrimaryActiveOutputNode()); | 2446 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 2584 } | 2447 } |
| 2585 | 2448 |
| 2586 // This covers the crbug.com/586026. Cras lost the active state of the internal | 2449 // This covers the crbug.com/586026. Cras lost the active state of the internal |
| 2587 // speaker when user unplugs the headphone, which is a bug in cras. However, | 2450 // speaker when user unplugs the headphone, which is a bug in cras. However, |
| 2588 // chrome code is still resilient and set the internal speaker back to active. | 2451 // chrome code is still resilient and set the internal speaker back to active. |
| 2589 TEST_F(CrasAudioHandlerTest, UnplugHeadphoneLostActiveInternalSpeakerByCras) { | 2452 TEST_P(CrasAudioHandlerTest, UnplugHeadphoneLostActiveInternalSpeakerByCras) { |
| 2590 // Set up with three nodes. | 2453 // Set up with three nodes. |
| 2591 AudioNodeList audio_nodes; | 2454 AudioNodeList audio_nodes = |
| 2592 audio_nodes.push_back(kInternalSpeaker); | 2455 GenerateAudioNodeList({kInternalSpeaker, kHeadphone, kUSBHeadphone1}); |
| 2593 audio_nodes.push_back(kHeadphone); | |
| 2594 audio_nodes.push_back(kUSBHeadphone1); | |
| 2595 SetUpCrasAudioHandler(audio_nodes); | 2456 SetUpCrasAudioHandler(audio_nodes); |
| 2596 | 2457 |
| 2597 // Switch the active output to internal speaker. | 2458 // Switch the active output to internal speaker. |
| 2598 cras_audio_handler_->SwitchToDevice(AudioDevice(kInternalSpeaker), true, | 2459 cras_audio_handler_->SwitchToDevice( |
| 2599 CrasAudioHandler::ACTIVATE_BY_USER); | 2460 AudioDevice(GenerateAudioNode(kInternalSpeaker)), true, |
| 2461 CrasAudioHandler::ACTIVATE_BY_USER); |
| 2600 | 2462 |
| 2601 // Verify internal speaker has been made active. | 2463 // Verify internal speaker has been made active. |
| 2602 AudioDeviceList audio_devices; | 2464 AudioDeviceList audio_devices; |
| 2603 cras_audio_handler_->GetAudioDevices(&audio_devices); | 2465 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 2604 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); | 2466 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); |
| 2605 EXPECT_EQ(kInternalSpeaker.id, | 2467 EXPECT_EQ(kInternalSpeaker->id, |
| 2606 cras_audio_handler_->GetPrimaryActiveOutputNode()); | 2468 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 2607 | 2469 |
| 2608 // Simulate unplug the headphone. Cras sends NodesChanged signal with | 2470 // Simulate unplug the headphone. Cras sends NodesChanged signal with |
| 2609 // both internal speaker and usb headphone being inactive. | 2471 // both internal speaker and usb headphone being inactive. |
| 2610 audio_nodes.clear(); | 2472 audio_nodes.clear(); |
| 2611 audio_nodes.push_back(kInternalSpeaker); | 2473 audio_nodes.push_back(GenerateAudioNode(kInternalSpeaker)); |
| 2612 audio_nodes.push_back(kUSBHeadphone1); | 2474 audio_nodes.push_back(GenerateAudioNode(kUSBHeadphone1)); |
| 2613 EXPECT_FALSE(kInternalSpeaker.active); | 2475 for (const auto& node : audio_nodes) |
| 2614 EXPECT_FALSE(kUSBHeadphone1.active); | 2476 ASSERT_FALSE(node.active) << node.id << " expexted to be inactive"; |
| 2615 ChangeAudioNodes(audio_nodes); | 2477 ChangeAudioNodes(audio_nodes); |
| 2616 | 2478 |
| 2617 // Verify the active output is set back to internal speaker. | 2479 // Verify the active output is set back to internal speaker. |
| 2618 cras_audio_handler_->GetAudioDevices(&audio_devices); | 2480 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 2619 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); | 2481 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); |
| 2620 EXPECT_EQ(kInternalSpeaker.id, | 2482 EXPECT_EQ(kInternalSpeaker->id, |
| 2621 cras_audio_handler_->GetPrimaryActiveOutputNode()); | 2483 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 2622 } | 2484 } |
| 2623 | 2485 |
| 2624 TEST_F(CrasAudioHandlerTest, RemoveNonActiveDevice) { | 2486 TEST_P(CrasAudioHandlerTest, RemoveNonActiveDevice) { |
| 2625 // Set up with three nodes. | 2487 // Set up with three nodes. |
| 2626 AudioNodeList audio_nodes; | 2488 AudioNodeList audio_nodes = |
| 2627 audio_nodes.push_back(kInternalSpeaker); | 2489 GenerateAudioNodeList({kInternalSpeaker, kHeadphone, kUSBHeadphone1}); |
| 2628 audio_nodes.push_back(kHeadphone); | |
| 2629 audio_nodes.push_back(kUSBHeadphone1); | |
| 2630 SetUpCrasAudioHandler(audio_nodes); | 2490 SetUpCrasAudioHandler(audio_nodes); |
| 2631 | 2491 |
| 2632 // Switch the active output to internal speaker. | 2492 // Switch the active output to internal speaker. |
| 2633 cras_audio_handler_->SwitchToDevice(AudioDevice(kInternalSpeaker), true, | 2493 cras_audio_handler_->SwitchToDevice( |
| 2634 CrasAudioHandler::ACTIVATE_BY_USER); | 2494 AudioDevice(GenerateAudioNode(kInternalSpeaker)), true, |
| 2495 CrasAudioHandler::ACTIVATE_BY_USER); |
| 2635 | 2496 |
| 2636 // Verify internal speaker has been made active. | 2497 // Verify internal speaker has been made active. |
| 2637 AudioDeviceList audio_devices; | 2498 AudioDeviceList audio_devices; |
| 2638 cras_audio_handler_->GetAudioDevices(&audio_devices); | 2499 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 2639 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); | 2500 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); |
| 2640 EXPECT_EQ(kInternalSpeaker.id, | 2501 EXPECT_EQ(kInternalSpeaker->id, |
| 2641 cras_audio_handler_->GetPrimaryActiveOutputNode()); | 2502 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 2642 | 2503 |
| 2643 // Remove headphone, which is an non-active device. | 2504 // Remove headphone, which is an non-active device. |
| 2644 audio_nodes.clear(); | 2505 audio_nodes.clear(); |
| 2645 AudioNode speaker(kInternalSpeaker); | 2506 AudioNode speaker = GenerateAudioNode(kInternalSpeaker); |
| 2646 speaker.active = true; | 2507 speaker.active = true; |
| 2647 audio_nodes.push_back(speaker); | 2508 audio_nodes.push_back(speaker); |
| 2648 AudioNode usb_headphone(kUSBHeadphone1); | 2509 AudioNode usb_headphone = GenerateAudioNode(kUSBHeadphone1); |
| 2649 usb_headphone.active = false; | 2510 usb_headphone.active = false; |
| 2650 audio_nodes.push_back(usb_headphone); | 2511 audio_nodes.push_back(usb_headphone); |
| 2651 | 2512 |
| 2652 ChangeAudioNodes(audio_nodes); | 2513 ChangeAudioNodes(audio_nodes); |
| 2653 | 2514 |
| 2654 // Verify the active output remains as internal speaker. | 2515 // Verify the active output remains as internal speaker. |
| 2655 cras_audio_handler_->GetAudioDevices(&audio_devices); | 2516 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 2656 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); | 2517 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); |
| 2657 EXPECT_EQ(kInternalSpeaker.id, | 2518 EXPECT_EQ(kInternalSpeaker->id, |
| 2658 cras_audio_handler_->GetPrimaryActiveOutputNode()); | 2519 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 2659 } | 2520 } |
| 2660 | 2521 |
| 2661 TEST_F(CrasAudioHandlerTest, ChangeActiveNodesHotrodInit) { | 2522 TEST_P(CrasAudioHandlerTest, ChangeActiveNodesHotrodInit) { |
| 2662 AudioNodeList audio_nodes; | 2523 AudioNodeList audio_nodes = GenerateAudioNodeList( |
| 2663 audio_nodes.push_back(kHDMIOutput); | 2524 {kHDMIOutput, kUSBJabraSpeakerOutput1, kUSBJabraSpeakerOutput2, |
| 2664 audio_nodes.push_back(kUSBJabraSpeakerOutput1); | 2525 kUSBJabraSpeakerInput1, kUSBJabraSpeakerInput2, kUSBCameraInput}); |
| 2665 audio_nodes.push_back(kUSBJabraSpeakerOutput2); | |
| 2666 audio_nodes.push_back(kUSBJabraSpeakerInput1); | |
| 2667 audio_nodes.push_back(kUSBJabraSpeakerInput2); | |
| 2668 audio_nodes.push_back(kUSBCameraInput); | |
| 2669 SetUpCrasAudioHandler(audio_nodes); | 2526 SetUpCrasAudioHandler(audio_nodes); |
| 2670 | 2527 |
| 2671 // Verify the audio devices size. | 2528 // Verify the audio devices size. |
| 2672 AudioDeviceList audio_devices; | 2529 AudioDeviceList audio_devices; |
| 2673 cras_audio_handler_->GetAudioDevices(&audio_devices); | 2530 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 2674 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); | 2531 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); |
| 2675 | 2532 |
| 2676 // Verify only the 1st jabra speaker's output and input are selected as active | 2533 // Verify only the 1st jabra speaker's output and input are selected as active |
| 2677 // nodes by CrasAudioHandler. | 2534 // nodes by CrasAudioHandler. |
| 2678 AudioDevice active_output; | 2535 AudioDevice active_output; |
| 2679 EXPECT_TRUE( | 2536 EXPECT_TRUE( |
| 2680 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); | 2537 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
| 2681 EXPECT_EQ(2, GetActiveDeviceCount()); | 2538 EXPECT_EQ(2, GetActiveDeviceCount()); |
| 2682 AudioDevice primary_active_device; | 2539 AudioDevice primary_active_device; |
| 2683 EXPECT_TRUE(cras_audio_handler_->GetPrimaryActiveOutputDevice( | 2540 EXPECT_TRUE(cras_audio_handler_->GetPrimaryActiveOutputDevice( |
| 2684 &primary_active_device)); | 2541 &primary_active_device)); |
| 2685 EXPECT_EQ(kUSBJabraSpeakerOutput1.id, primary_active_device.id); | 2542 EXPECT_EQ(kUSBJabraSpeakerOutput1->id, primary_active_device.id); |
| 2686 EXPECT_EQ(kUSBJabraSpeakerInput1.id, | 2543 EXPECT_EQ(kUSBJabraSpeakerInput1->id, |
| 2687 cras_audio_handler_->GetPrimaryActiveInputNode()); | 2544 cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 2688 | 2545 |
| 2689 // Set both jabra speakers's input and output nodes to active, this simulate | 2546 // Set both jabra speakers's input and output nodes to active, this simulate |
| 2690 // the call sent by hotrod initialization process. | 2547 // the call sent by hotrod initialization process. |
| 2691 test_observer_->reset_active_output_node_changed_count(); | 2548 test_observer_->reset_active_output_node_changed_count(); |
| 2692 test_observer_->reset_active_input_node_changed_count(); | 2549 test_observer_->reset_active_input_node_changed_count(); |
| 2693 CrasAudioHandler::NodeIdList active_nodes; | 2550 CrasAudioHandler::NodeIdList active_nodes; |
| 2694 active_nodes.push_back(kUSBJabraSpeakerOutput1.id); | 2551 active_nodes.push_back(kUSBJabraSpeakerOutput1->id); |
| 2695 active_nodes.push_back(kUSBJabraSpeakerOutput2.id); | 2552 active_nodes.push_back(kUSBJabraSpeakerOutput2->id); |
| 2696 active_nodes.push_back(kUSBJabraSpeakerInput1.id); | 2553 active_nodes.push_back(kUSBJabraSpeakerInput1->id); |
| 2697 active_nodes.push_back(kUSBJabraSpeakerInput2.id); | 2554 active_nodes.push_back(kUSBJabraSpeakerInput2->id); |
| 2698 cras_audio_handler_->ChangeActiveNodes(active_nodes); | 2555 cras_audio_handler_->ChangeActiveNodes(active_nodes); |
| 2699 | 2556 |
| 2700 // Verify both jabra speakers' input/output nodes are made active. | 2557 // Verify both jabra speakers' input/output nodes are made active. |
| 2701 // num_active_nodes = GetActiveDeviceCount(); | 2558 // num_active_nodes = GetActiveDeviceCount(); |
| 2702 EXPECT_EQ(4, GetActiveDeviceCount()); | 2559 EXPECT_EQ(4, GetActiveDeviceCount()); |
| 2703 const AudioDevice* active_output_1 = | 2560 const AudioDevice* active_output_1 = |
| 2704 GetDeviceFromId(kUSBJabraSpeakerOutput1.id); | 2561 GetDeviceFromId(kUSBJabraSpeakerOutput1->id); |
| 2705 EXPECT_TRUE(active_output_1->active); | 2562 EXPECT_TRUE(active_output_1->active); |
| 2706 const AudioDevice* active_output_2 = | 2563 const AudioDevice* active_output_2 = |
| 2707 GetDeviceFromId(kUSBJabraSpeakerOutput2.id); | 2564 GetDeviceFromId(kUSBJabraSpeakerOutput2->id); |
| 2708 EXPECT_TRUE(active_output_2->active); | 2565 EXPECT_TRUE(active_output_2->active); |
| 2709 EXPECT_TRUE(cras_audio_handler_->GetPrimaryActiveOutputDevice( | 2566 EXPECT_TRUE(cras_audio_handler_->GetPrimaryActiveOutputDevice( |
| 2710 &primary_active_device)); | 2567 &primary_active_device)); |
| 2711 EXPECT_EQ(kUSBJabraSpeakerOutput1.id, primary_active_device.id); | 2568 EXPECT_EQ(kUSBJabraSpeakerOutput1->id, primary_active_device.id); |
| 2712 const AudioDevice* active_input_1 = | 2569 const AudioDevice* active_input_1 = |
| 2713 GetDeviceFromId(kUSBJabraSpeakerInput1.id); | 2570 GetDeviceFromId(kUSBJabraSpeakerInput1->id); |
| 2714 EXPECT_TRUE(active_input_1->active); | 2571 EXPECT_TRUE(active_input_1->active); |
| 2715 const AudioDevice* active_input_2 = | 2572 const AudioDevice* active_input_2 = |
| 2716 GetDeviceFromId(kUSBJabraSpeakerInput2.id); | 2573 GetDeviceFromId(kUSBJabraSpeakerInput2->id); |
| 2717 EXPECT_TRUE(active_input_2->active); | 2574 EXPECT_TRUE(active_input_2->active); |
| 2718 EXPECT_EQ(kUSBJabraSpeakerInput1.id, | 2575 EXPECT_EQ(kUSBJabraSpeakerInput1->id, |
| 2719 cras_audio_handler_->GetPrimaryActiveInputNode()); | 2576 cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 2720 | 2577 |
| 2721 // Verify only 1 ActiveOutputNodeChanged notification has been sent out | 2578 // Verify only 1 ActiveOutputNodeChanged notification has been sent out |
| 2722 // by calling ChangeActiveNodes. | 2579 // by calling ChangeActiveNodes. |
| 2723 EXPECT_EQ(1, test_observer_->active_output_node_changed_count()); | 2580 EXPECT_EQ(1, test_observer_->active_output_node_changed_count()); |
| 2724 EXPECT_EQ(1, test_observer_->active_input_node_changed_count()); | 2581 EXPECT_EQ(1, test_observer_->active_input_node_changed_count()); |
| 2725 | 2582 |
| 2726 // Verify all active devices are the not muted and their volume values are | 2583 // Verify all active devices are the not muted and their volume values are |
| 2727 // the same. | 2584 // the same. |
| 2728 EXPECT_FALSE(cras_audio_handler_->IsOutputMuted()); | 2585 EXPECT_FALSE(cras_audio_handler_->IsOutputMuted()); |
| 2729 EXPECT_FALSE( | 2586 EXPECT_FALSE( |
| 2730 cras_audio_handler_->IsOutputMutedForDevice(kUSBJabraSpeakerOutput1.id)); | 2587 cras_audio_handler_->IsOutputMutedForDevice(kUSBJabraSpeakerOutput1->id)); |
| 2731 EXPECT_FALSE( | 2588 EXPECT_FALSE( |
| 2732 cras_audio_handler_->IsOutputMutedForDevice(kUSBJabraSpeakerOutput2.id)); | 2589 cras_audio_handler_->IsOutputMutedForDevice(kUSBJabraSpeakerOutput2->id)); |
| 2733 EXPECT_EQ(cras_audio_handler_->GetOutputVolumePercent(), | 2590 EXPECT_EQ(cras_audio_handler_->GetOutputVolumePercent(), |
| 2734 cras_audio_handler_->GetOutputVolumePercentForDevice( | 2591 cras_audio_handler_->GetOutputVolumePercentForDevice( |
| 2735 kUSBJabraSpeakerOutput1.id)); | 2592 kUSBJabraSpeakerOutput1->id)); |
| 2736 EXPECT_EQ(cras_audio_handler_->GetOutputVolumePercent(), | 2593 EXPECT_EQ(cras_audio_handler_->GetOutputVolumePercent(), |
| 2737 cras_audio_handler_->GetOutputVolumePercentForDevice( | 2594 cras_audio_handler_->GetOutputVolumePercentForDevice( |
| 2738 kUSBJabraSpeakerOutput2.id)); | 2595 kUSBJabraSpeakerOutput2->id)); |
| 2739 | 2596 |
| 2740 // Adjust the volume of output devices, verify all active nodes are set to | 2597 // Adjust the volume of output devices, verify all active nodes are set to |
| 2741 // the same volume. | 2598 // the same volume. |
| 2742 cras_audio_handler_->SetOutputVolumePercent(25); | 2599 cras_audio_handler_->SetOutputVolumePercent(25); |
| 2743 EXPECT_EQ(25, cras_audio_handler_->GetOutputVolumePercent()); | 2600 EXPECT_EQ(25, cras_audio_handler_->GetOutputVolumePercent()); |
| 2744 EXPECT_EQ(25, cras_audio_handler_->GetOutputVolumePercentForDevice( | 2601 EXPECT_EQ(25, cras_audio_handler_->GetOutputVolumePercentForDevice( |
| 2745 kUSBJabraSpeakerOutput1.id)); | 2602 kUSBJabraSpeakerOutput1->id)); |
| 2746 EXPECT_EQ(25, cras_audio_handler_->GetOutputVolumePercentForDevice( | 2603 EXPECT_EQ(25, cras_audio_handler_->GetOutputVolumePercentForDevice( |
| 2747 kUSBJabraSpeakerOutput2.id)); | 2604 kUSBJabraSpeakerOutput2->id)); |
| 2748 } | 2605 } |
| 2749 | 2606 |
| 2750 TEST_F(CrasAudioHandlerTest, ChangeVolumeHotrodDualSpeakersWithDelayedSignals) { | 2607 TEST_P(CrasAudioHandlerTest, ChangeVolumeHotrodDualSpeakersWithDelayedSignals) { |
| 2751 AudioNodeList audio_nodes; | 2608 AudioNodeList audio_nodes = GenerateAudioNodeList( |
| 2752 audio_nodes.push_back(kHDMIOutput); | 2609 {kHDMIOutput, kUSBJabraSpeakerOutput1, kUSBJabraSpeakerOutput2}); |
| 2753 audio_nodes.push_back(kUSBJabraSpeakerOutput1); | |
| 2754 audio_nodes.push_back(kUSBJabraSpeakerOutput2); | |
| 2755 SetUpCrasAudioHandler(audio_nodes); | 2610 SetUpCrasAudioHandler(audio_nodes); |
| 2756 | 2611 |
| 2757 // Verify the audio devices size. | 2612 // Verify the audio devices size. |
| 2758 AudioDeviceList audio_devices; | 2613 AudioDeviceList audio_devices; |
| 2759 cras_audio_handler_->GetAudioDevices(&audio_devices); | 2614 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 2760 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); | 2615 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); |
| 2761 | 2616 |
| 2762 // Set both jabra speakers nodes to active, this simulate | 2617 // Set both jabra speakers nodes to active, this simulate |
| 2763 // the call sent by hotrod initialization process. | 2618 // the call sent by hotrod initialization process. |
| 2764 test_observer_->reset_active_output_node_changed_count(); | 2619 test_observer_->reset_active_output_node_changed_count(); |
| 2765 CrasAudioHandler::NodeIdList active_nodes; | 2620 CrasAudioHandler::NodeIdList active_nodes; |
| 2766 active_nodes.push_back(kUSBJabraSpeakerOutput1.id); | 2621 active_nodes.push_back(kUSBJabraSpeakerOutput1->id); |
| 2767 active_nodes.push_back(kUSBJabraSpeakerOutput2.id); | 2622 active_nodes.push_back(kUSBJabraSpeakerOutput2->id); |
| 2768 cras_audio_handler_->ChangeActiveNodes(active_nodes); | 2623 cras_audio_handler_->ChangeActiveNodes(active_nodes); |
| 2769 | 2624 |
| 2770 // Verify both jabra speakers are made active. | 2625 // Verify both jabra speakers are made active. |
| 2771 EXPECT_EQ(2, GetActiveDeviceCount()); | 2626 EXPECT_EQ(2, GetActiveDeviceCount()); |
| 2772 const AudioDevice* active_output_1 = | 2627 const AudioDevice* active_output_1 = |
| 2773 GetDeviceFromId(kUSBJabraSpeakerOutput1.id); | 2628 GetDeviceFromId(kUSBJabraSpeakerOutput1->id); |
| 2774 EXPECT_TRUE(active_output_1->active); | 2629 EXPECT_TRUE(active_output_1->active); |
| 2775 const AudioDevice* active_output_2 = | 2630 const AudioDevice* active_output_2 = |
| 2776 GetDeviceFromId(kUSBJabraSpeakerOutput2.id); | 2631 GetDeviceFromId(kUSBJabraSpeakerOutput2->id); |
| 2777 EXPECT_TRUE(active_output_2->active); | 2632 EXPECT_TRUE(active_output_2->active); |
| 2778 | 2633 |
| 2779 // Verify all active devices are the not muted and their volume values are | 2634 // Verify all active devices are the not muted and their volume values are |
| 2780 // the same. | 2635 // the same. |
| 2781 EXPECT_FALSE(cras_audio_handler_->IsOutputMuted()); | 2636 EXPECT_FALSE(cras_audio_handler_->IsOutputMuted()); |
| 2782 EXPECT_FALSE( | 2637 EXPECT_FALSE( |
| 2783 cras_audio_handler_->IsOutputMutedForDevice(kUSBJabraSpeakerOutput1.id)); | 2638 cras_audio_handler_->IsOutputMutedForDevice(kUSBJabraSpeakerOutput1->id)); |
| 2784 EXPECT_FALSE( | 2639 EXPECT_FALSE( |
| 2785 cras_audio_handler_->IsOutputMutedForDevice(kUSBJabraSpeakerOutput2.id)); | 2640 cras_audio_handler_->IsOutputMutedForDevice(kUSBJabraSpeakerOutput2->id)); |
| 2786 EXPECT_EQ(cras_audio_handler_->GetOutputVolumePercent(), | 2641 EXPECT_EQ(cras_audio_handler_->GetOutputVolumePercent(), |
| 2787 cras_audio_handler_->GetOutputVolumePercentForDevice( | 2642 cras_audio_handler_->GetOutputVolumePercentForDevice( |
| 2788 kUSBJabraSpeakerOutput1.id)); | 2643 kUSBJabraSpeakerOutput1->id)); |
| 2789 EXPECT_EQ(cras_audio_handler_->GetOutputVolumePercent(), | 2644 EXPECT_EQ(cras_audio_handler_->GetOutputVolumePercent(), |
| 2790 cras_audio_handler_->GetOutputVolumePercentForDevice( | 2645 cras_audio_handler_->GetOutputVolumePercentForDevice( |
| 2791 kUSBJabraSpeakerOutput2.id)); | 2646 kUSBJabraSpeakerOutput2->id)); |
| 2792 const int kDefaultVolume = 75; | 2647 const int kDefaultVolume = 75; |
| 2793 EXPECT_EQ(kDefaultVolume, cras_audio_handler_->GetOutputVolumePercent()); | 2648 EXPECT_EQ(kDefaultVolume, cras_audio_handler_->GetOutputVolumePercent()); |
| 2794 | 2649 |
| 2795 // Disable the auto OutputNodeVolumeChanged signal. | 2650 // Disable the auto OutputNodeVolumeChanged signal. |
| 2796 fake_cras_audio_client_->set_notify_volume_change_with_delay(true); | 2651 fake_cras_audio_client_->set_notify_volume_change_with_delay(true); |
| 2797 test_observer_->reset_output_volume_changed_count(); | 2652 test_observer_->reset_output_volume_changed_count(); |
| 2798 | 2653 |
| 2799 // Adjust the volume of output devices continuously. | 2654 // Adjust the volume of output devices continuously. |
| 2800 cras_audio_handler_->SetOutputVolumePercent(20); | 2655 cras_audio_handler_->SetOutputVolumePercent(20); |
| 2801 cras_audio_handler_->SetOutputVolumePercent(30); | 2656 cras_audio_handler_->SetOutputVolumePercent(30); |
| 2802 | 2657 |
| 2803 // Sends delayed OutputNodeVolumeChanged signals. | 2658 // Sends delayed OutputNodeVolumeChanged signals. |
| 2804 fake_cras_audio_client_->NotifyOutputNodeVolumeChangedForTesting( | 2659 fake_cras_audio_client_->NotifyOutputNodeVolumeChangedForTesting( |
| 2805 kUSBJabraSpeakerOutput2.id, 20); | 2660 kUSBJabraSpeakerOutput2->id, 20); |
| 2806 fake_cras_audio_client_->NotifyOutputNodeVolumeChangedForTesting( | 2661 fake_cras_audio_client_->NotifyOutputNodeVolumeChangedForTesting( |
| 2807 kUSBJabraSpeakerOutput1.id, 20); | 2662 kUSBJabraSpeakerOutput1->id, 20); |
| 2808 fake_cras_audio_client_->NotifyOutputNodeVolumeChangedForTesting( | 2663 fake_cras_audio_client_->NotifyOutputNodeVolumeChangedForTesting( |
| 2809 kUSBJabraSpeakerOutput2.id, 30); | 2664 kUSBJabraSpeakerOutput2->id, 30); |
| 2810 fake_cras_audio_client_->NotifyOutputNodeVolumeChangedForTesting( | 2665 fake_cras_audio_client_->NotifyOutputNodeVolumeChangedForTesting( |
| 2811 kUSBJabraSpeakerOutput1.id, 30); | 2666 kUSBJabraSpeakerOutput1->id, 30); |
| 2812 | 2667 |
| 2813 // Verify that both speakers are set to the designated volume level after | 2668 // Verify that both speakers are set to the designated volume level after |
| 2814 // receiving all delayed signals. | 2669 // receiving all delayed signals. |
| 2815 EXPECT_EQ(4, test_observer_->output_volume_changed_count()); | 2670 EXPECT_EQ(4, test_observer_->output_volume_changed_count()); |
| 2816 EXPECT_EQ(30, cras_audio_handler_->GetOutputVolumePercent()); | 2671 EXPECT_EQ(30, cras_audio_handler_->GetOutputVolumePercent()); |
| 2817 EXPECT_EQ(30, cras_audio_handler_->GetOutputVolumePercentForDevice( | 2672 EXPECT_EQ(30, cras_audio_handler_->GetOutputVolumePercentForDevice( |
| 2818 kUSBJabraSpeakerOutput1.id)); | 2673 kUSBJabraSpeakerOutput1->id)); |
| 2819 EXPECT_EQ(30, cras_audio_handler_->GetOutputVolumePercentForDevice( | 2674 EXPECT_EQ(30, cras_audio_handler_->GetOutputVolumePercentForDevice( |
| 2820 kUSBJabraSpeakerOutput2.id)); | 2675 kUSBJabraSpeakerOutput2->id)); |
| 2821 } | 2676 } |
| 2822 | 2677 |
| 2823 TEST_F(CrasAudioHandlerTest, ChangeActiveNodesHotrodInitWithCameraInputActive) { | 2678 TEST_P(CrasAudioHandlerTest, ChangeActiveNodesHotrodInitWithCameraInputActive) { |
| 2824 AudioNodeList audio_nodes; | 2679 AudioNodeList audio_nodes = GenerateAudioNodeList( |
| 2825 audio_nodes.push_back(kHDMIOutput); | 2680 {kHDMIOutput, kUSBJabraSpeakerOutput1, kUSBJabraSpeakerOutput2, |
| 2826 audio_nodes.push_back(kUSBJabraSpeakerOutput1); | 2681 kUSBJabraSpeakerInput1, kUSBJabraSpeakerInput2}); |
| 2827 audio_nodes.push_back(kUSBJabraSpeakerOutput2); | |
| 2828 audio_nodes.push_back(kUSBJabraSpeakerInput1); | |
| 2829 audio_nodes.push_back(kUSBJabraSpeakerInput2); | |
| 2830 // Make the camera input to be plugged in later than jabra's input. | 2682 // Make the camera input to be plugged in later than jabra's input. |
| 2831 AudioNode usb_camera(kUSBCameraInput); | 2683 AudioNode usb_camera = GenerateAudioNode(kUSBCameraInput); |
| 2832 usb_camera.plugged_time = 10000000; | 2684 usb_camera.plugged_time = 10000000; |
| 2833 audio_nodes.push_back(usb_camera); | 2685 audio_nodes.push_back(usb_camera); |
| 2834 SetUpCrasAudioHandler(audio_nodes); | 2686 SetUpCrasAudioHandler(audio_nodes); |
| 2835 | 2687 |
| 2836 // Verify the audio devices size. | 2688 // Verify the audio devices size. |
| 2837 AudioDeviceList audio_devices; | 2689 AudioDeviceList audio_devices; |
| 2838 cras_audio_handler_->GetAudioDevices(&audio_devices); | 2690 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 2839 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); | 2691 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); |
| 2840 | 2692 |
| 2841 // Verify the 1st jabra speaker's output is selected as active output | 2693 // Verify the 1st jabra speaker's output is selected as active output |
| 2842 // node and camera's input is selected active input by CrasAudioHandler. | 2694 // node and camera's input is selected active input by CrasAudioHandler. |
| 2843 EXPECT_EQ(2, GetActiveDeviceCount()); | 2695 EXPECT_EQ(2, GetActiveDeviceCount()); |
| 2844 EXPECT_EQ(kUSBJabraSpeakerOutput1.id, | 2696 EXPECT_EQ(kUSBJabraSpeakerOutput1->id, |
| 2845 cras_audio_handler_->GetPrimaryActiveOutputNode()); | 2697 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 2846 EXPECT_EQ(kUSBCameraInput.id, | 2698 EXPECT_EQ(kUSBCameraInput->id, |
| 2847 cras_audio_handler_->GetPrimaryActiveInputNode()); | 2699 cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 2848 | 2700 |
| 2849 // Set both jabra speakers's input and output nodes to active, this simulates | 2701 // Set both jabra speakers's input and output nodes to active, this simulates |
| 2850 // the call sent by hotrod initialization process. | 2702 // the call sent by hotrod initialization process. |
| 2851 test_observer_->reset_active_output_node_changed_count(); | 2703 test_observer_->reset_active_output_node_changed_count(); |
| 2852 test_observer_->reset_active_input_node_changed_count(); | 2704 test_observer_->reset_active_input_node_changed_count(); |
| 2853 CrasAudioHandler::NodeIdList active_nodes; | 2705 CrasAudioHandler::NodeIdList active_nodes; |
| 2854 active_nodes.push_back(kUSBJabraSpeakerOutput1.id); | 2706 active_nodes.push_back(kUSBJabraSpeakerOutput1->id); |
| 2855 active_nodes.push_back(kUSBJabraSpeakerOutput2.id); | 2707 active_nodes.push_back(kUSBJabraSpeakerOutput2->id); |
| 2856 active_nodes.push_back(kUSBJabraSpeakerInput1.id); | 2708 active_nodes.push_back(kUSBJabraSpeakerInput1->id); |
| 2857 active_nodes.push_back(kUSBJabraSpeakerInput2.id); | 2709 active_nodes.push_back(kUSBJabraSpeakerInput2->id); |
| 2858 cras_audio_handler_->ChangeActiveNodes(active_nodes); | 2710 cras_audio_handler_->ChangeActiveNodes(active_nodes); |
| 2859 | 2711 |
| 2860 // Verify both jabra speakers' input/output nodes are made active. | 2712 // Verify both jabra speakers' input/output nodes are made active. |
| 2861 // num_active_nodes = GetActiveDeviceCount(); | 2713 // num_active_nodes = GetActiveDeviceCount(); |
| 2862 EXPECT_EQ(4, GetActiveDeviceCount()); | 2714 EXPECT_EQ(4, GetActiveDeviceCount()); |
| 2863 const AudioDevice* active_output_1 = | 2715 const AudioDevice* active_output_1 = |
| 2864 GetDeviceFromId(kUSBJabraSpeakerOutput1.id); | 2716 GetDeviceFromId(kUSBJabraSpeakerOutput1->id); |
| 2865 EXPECT_TRUE(active_output_1->active); | 2717 EXPECT_TRUE(active_output_1->active); |
| 2866 const AudioDevice* active_output_2 = | 2718 const AudioDevice* active_output_2 = |
| 2867 GetDeviceFromId(kUSBJabraSpeakerOutput2.id); | 2719 GetDeviceFromId(kUSBJabraSpeakerOutput2->id); |
| 2868 EXPECT_TRUE(active_output_2->active); | 2720 EXPECT_TRUE(active_output_2->active); |
| 2869 EXPECT_EQ(kUSBJabraSpeakerOutput1.id, | 2721 EXPECT_EQ(kUSBJabraSpeakerOutput1->id, |
| 2870 cras_audio_handler_->GetPrimaryActiveOutputNode()); | 2722 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 2871 const AudioDevice* active_input_1 = | 2723 const AudioDevice* active_input_1 = |
| 2872 GetDeviceFromId(kUSBJabraSpeakerInput1.id); | 2724 GetDeviceFromId(kUSBJabraSpeakerInput1->id); |
| 2873 EXPECT_TRUE(active_input_1->active); | 2725 EXPECT_TRUE(active_input_1->active); |
| 2874 const AudioDevice* active_input_2 = | 2726 const AudioDevice* active_input_2 = |
| 2875 GetDeviceFromId(kUSBJabraSpeakerInput2.id); | 2727 GetDeviceFromId(kUSBJabraSpeakerInput2->id); |
| 2876 EXPECT_TRUE(active_input_2->active); | 2728 EXPECT_TRUE(active_input_2->active); |
| 2877 EXPECT_EQ(kUSBJabraSpeakerInput1.id, | 2729 EXPECT_EQ(kUSBJabraSpeakerInput1->id, |
| 2878 cras_audio_handler_->GetPrimaryActiveInputNode()); | 2730 cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 2879 | 2731 |
| 2880 // Verify only 1 ActiveOutputNodeChanged notification has been sent out | 2732 // Verify only 1 ActiveOutputNodeChanged notification has been sent out |
| 2881 // by calling ChangeActiveNodes. | 2733 // by calling ChangeActiveNodes. |
| 2882 EXPECT_EQ(1, test_observer_->active_output_node_changed_count()); | 2734 EXPECT_EQ(1, test_observer_->active_output_node_changed_count()); |
| 2883 EXPECT_EQ(1, test_observer_->active_input_node_changed_count()); | 2735 EXPECT_EQ(1, test_observer_->active_input_node_changed_count()); |
| 2884 } | 2736 } |
| 2885 | 2737 |
| 2886 TEST_F(CrasAudioHandlerTest, ChangeActiveNodesWithFewerActives) { | 2738 TEST_P(CrasAudioHandlerTest, ChangeActiveNodesWithFewerActives) { |
| 2887 AudioNodeList audio_nodes; | 2739 AudioNodeList audio_nodes = GenerateAudioNodeList( |
| 2888 audio_nodes.push_back(kHDMIOutput); | 2740 {kHDMIOutput, kUSBJabraSpeakerOutput1, kUSBJabraSpeakerOutput2}); |
| 2889 audio_nodes.push_back(kUSBJabraSpeakerOutput1); | |
| 2890 audio_nodes.push_back(kUSBJabraSpeakerOutput2); | |
| 2891 SetUpCrasAudioHandler(audio_nodes); | 2741 SetUpCrasAudioHandler(audio_nodes); |
| 2892 | 2742 |
| 2893 // Verify the audio devices size. | 2743 // Verify the audio devices size. |
| 2894 AudioDeviceList audio_devices; | 2744 AudioDeviceList audio_devices; |
| 2895 cras_audio_handler_->GetAudioDevices(&audio_devices); | 2745 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 2896 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); | 2746 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); |
| 2897 | 2747 |
| 2898 // Set all three nodes to be active. | 2748 // Set all three nodes to be active. |
| 2899 CrasAudioHandler::NodeIdList active_nodes; | 2749 CrasAudioHandler::NodeIdList active_nodes; |
| 2900 active_nodes.push_back(kHDMIOutput.id); | 2750 active_nodes.push_back(kHDMIOutput->id); |
| 2901 active_nodes.push_back(kUSBJabraSpeakerOutput1.id); | 2751 active_nodes.push_back(kUSBJabraSpeakerOutput1->id); |
| 2902 active_nodes.push_back(kUSBJabraSpeakerOutput2.id); | 2752 active_nodes.push_back(kUSBJabraSpeakerOutput2->id); |
| 2903 cras_audio_handler_->ChangeActiveNodes(active_nodes); | 2753 cras_audio_handler_->ChangeActiveNodes(active_nodes); |
| 2904 | 2754 |
| 2905 // Verify all three nodes are active. | 2755 // Verify all three nodes are active. |
| 2906 EXPECT_EQ(3, GetActiveDeviceCount()); | 2756 EXPECT_EQ(3, GetActiveDeviceCount()); |
| 2907 const AudioDevice* active_output_1 = GetDeviceFromId(kHDMIOutput.id); | 2757 const AudioDevice* active_output_1 = GetDeviceFromId(kHDMIOutput->id); |
| 2908 EXPECT_TRUE(active_output_1->active); | 2758 EXPECT_TRUE(active_output_1->active); |
| 2909 const AudioDevice* active_output_2 = | 2759 const AudioDevice* active_output_2 = |
| 2910 GetDeviceFromId(kUSBJabraSpeakerOutput1.id); | 2760 GetDeviceFromId(kUSBJabraSpeakerOutput1->id); |
| 2911 EXPECT_TRUE(active_output_2->active); | 2761 EXPECT_TRUE(active_output_2->active); |
| 2912 const AudioDevice* active_output_3 = | 2762 const AudioDevice* active_output_3 = |
| 2913 GetDeviceFromId(kUSBJabraSpeakerOutput2.id); | 2763 GetDeviceFromId(kUSBJabraSpeakerOutput2->id); |
| 2914 EXPECT_TRUE(active_output_3->active); | 2764 EXPECT_TRUE(active_output_3->active); |
| 2915 | 2765 |
| 2916 // Now call ChangeActiveDevices with only 2 nodes. | 2766 // Now call ChangeActiveDevices with only 2 nodes. |
| 2917 active_nodes.clear(); | 2767 active_nodes.clear(); |
| 2918 active_nodes.push_back(kUSBJabraSpeakerOutput1.id); | 2768 active_nodes.push_back(kUSBJabraSpeakerOutput1->id); |
| 2919 active_nodes.push_back(kUSBJabraSpeakerOutput2.id); | 2769 active_nodes.push_back(kUSBJabraSpeakerOutput2->id); |
| 2920 cras_audio_handler_->ChangeActiveNodes(active_nodes); | 2770 cras_audio_handler_->ChangeActiveNodes(active_nodes); |
| 2921 | 2771 |
| 2922 // Verify only 2 nodes are active. | 2772 // Verify only 2 nodes are active. |
| 2923 EXPECT_EQ(2, GetActiveDeviceCount()); | 2773 EXPECT_EQ(2, GetActiveDeviceCount()); |
| 2924 const AudioDevice* output_1 = GetDeviceFromId(kHDMIOutput.id); | 2774 const AudioDevice* output_1 = GetDeviceFromId(kHDMIOutput->id); |
| 2925 EXPECT_FALSE(output_1->active); | 2775 EXPECT_FALSE(output_1->active); |
| 2926 const AudioDevice* output_2 = GetDeviceFromId(kUSBJabraSpeakerOutput1.id); | 2776 const AudioDevice* output_2 = GetDeviceFromId(kUSBJabraSpeakerOutput1->id); |
| 2927 EXPECT_TRUE(output_2->active); | 2777 EXPECT_TRUE(output_2->active); |
| 2928 const AudioDevice* output_3 = GetDeviceFromId(kUSBJabraSpeakerOutput2.id); | 2778 const AudioDevice* output_3 = GetDeviceFromId(kUSBJabraSpeakerOutput2->id); |
| 2929 EXPECT_TRUE(output_3->active); | 2779 EXPECT_TRUE(output_3->active); |
| 2930 } | 2780 } |
| 2931 | 2781 |
| 2932 TEST_F(CrasAudioHandlerTest, HotrodInitWithSingleJabra) { | 2782 TEST_P(CrasAudioHandlerTest, HotrodInitWithSingleJabra) { |
| 2933 // Simulates the hotrod initializated with a single jabra device and | 2783 // Simulates the hotrod initializated with a single jabra device and |
| 2934 // CrasAudioHandler selected jabra input/output as active devices. | 2784 // CrasAudioHandler selected jabra input/output as active devices. |
| 2935 AudioNodeList audio_nodes; | 2785 AudioNodeList audio_nodes = |
| 2936 audio_nodes.push_back(kHDMIOutput); | 2786 GenerateAudioNodeList({kHDMIOutput, kUSBJabraSpeakerOutput1, |
| 2937 audio_nodes.push_back(kUSBJabraSpeakerOutput1); | 2787 kUSBJabraSpeakerInput1, kUSBCameraInput}); |
| 2938 audio_nodes.push_back(kUSBJabraSpeakerInput1); | |
| 2939 audio_nodes.push_back(kUSBCameraInput); | |
| 2940 SetUpCrasAudioHandler(audio_nodes); | 2788 SetUpCrasAudioHandler(audio_nodes); |
| 2941 | 2789 |
| 2942 // Verify the audio devices size. | 2790 // Verify the audio devices size. |
| 2943 AudioDeviceList audio_devices; | 2791 AudioDeviceList audio_devices; |
| 2944 cras_audio_handler_->GetAudioDevices(&audio_devices); | 2792 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 2945 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); | 2793 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); |
| 2946 | 2794 |
| 2947 // Verify the jabra speaker's output and input are selected as active nodes | 2795 // Verify the jabra speaker's output and input are selected as active nodes |
| 2948 // by CrasAudioHandler. | 2796 // by CrasAudioHandler. |
| 2949 EXPECT_EQ(2, GetActiveDeviceCount()); | 2797 EXPECT_EQ(2, GetActiveDeviceCount()); |
| 2950 EXPECT_EQ(kUSBJabraSpeakerOutput1.id, | 2798 EXPECT_EQ(kUSBJabraSpeakerOutput1->id, |
| 2951 cras_audio_handler_->GetPrimaryActiveOutputNode()); | 2799 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 2952 EXPECT_EQ(kUSBJabraSpeakerInput1.id, | 2800 EXPECT_EQ(kUSBJabraSpeakerInput1->id, |
| 2953 cras_audio_handler_->GetPrimaryActiveInputNode()); | 2801 cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 2954 } | 2802 } |
| 2955 | 2803 |
| 2956 TEST_F(CrasAudioHandlerTest, | 2804 TEST_P(CrasAudioHandlerTest, |
| 2957 ChangeActiveNodesHotrodInitWithSingleJabraCameraPlugInLater) { | 2805 ChangeActiveNodesHotrodInitWithSingleJabraCameraPlugInLater) { |
| 2958 AudioNodeList audio_nodes; | 2806 AudioNodeList audio_nodes = GenerateAudioNodeList( |
| 2959 audio_nodes.push_back(kHDMIOutput); | 2807 {kHDMIOutput, kUSBJabraSpeakerOutput1, kUSBJabraSpeakerInput1}); |
| 2960 audio_nodes.push_back(kUSBJabraSpeakerOutput1); | 2808 AudioNode usb_camera = GenerateAudioNode(kUSBCameraInput); |
| 2961 audio_nodes.push_back(kUSBJabraSpeakerInput1); | |
| 2962 AudioNode usb_camera(kUSBCameraInput); | |
| 2963 usb_camera.plugged_time = 10000000; | 2809 usb_camera.plugged_time = 10000000; |
| 2964 audio_nodes.push_back(usb_camera); | 2810 audio_nodes.push_back(usb_camera); |
| 2965 SetUpCrasAudioHandler(audio_nodes); | 2811 SetUpCrasAudioHandler(audio_nodes); |
| 2966 | 2812 |
| 2967 // Verify the audio devices size. | 2813 // Verify the audio devices size. |
| 2968 AudioDeviceList audio_devices; | 2814 AudioDeviceList audio_devices; |
| 2969 cras_audio_handler_->GetAudioDevices(&audio_devices); | 2815 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 2970 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); | 2816 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); |
| 2971 | 2817 |
| 2972 // Verify the jabra speaker's output is selected as active output, and | 2818 // Verify the jabra speaker's output is selected as active output, and |
| 2973 // camera's input is selected as active input by CrasAudioHandler | 2819 // camera's input is selected as active input by CrasAudioHandler |
| 2974 EXPECT_EQ(2, GetActiveDeviceCount()); | 2820 EXPECT_EQ(2, GetActiveDeviceCount()); |
| 2975 EXPECT_EQ(kUSBJabraSpeakerOutput1.id, | 2821 EXPECT_EQ(kUSBJabraSpeakerOutput1->id, |
| 2976 cras_audio_handler_->GetPrimaryActiveOutputNode()); | 2822 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 2977 EXPECT_EQ(kUSBCameraInput.id, | 2823 EXPECT_EQ(kUSBCameraInput->id, |
| 2978 cras_audio_handler_->GetPrimaryActiveInputNode()); | 2824 cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 2979 | 2825 |
| 2980 // Simulate hotrod app call to set jabra input as active device with only | 2826 // Simulate hotrod app call to set jabra input as active device with only |
| 2981 // jabra input node in the active node list, which does not conform to the | 2827 // jabra input node in the active node list, which does not conform to the |
| 2982 // new SetActiveDevices protocol, but just show we can still handle it if | 2828 // new SetActiveDevices protocol, but just show we can still handle it if |
| 2983 // this happens. | 2829 // this happens. |
| 2984 CrasAudioHandler::NodeIdList active_nodes; | 2830 CrasAudioHandler::NodeIdList active_nodes; |
| 2985 active_nodes.push_back(kUSBJabraSpeakerOutput1.id); | 2831 active_nodes.push_back(kUSBJabraSpeakerOutput1->id); |
| 2986 active_nodes.push_back(kUSBJabraSpeakerInput1.id); | 2832 active_nodes.push_back(kUSBJabraSpeakerInput1->id); |
| 2987 cras_audio_handler_->ChangeActiveNodes(active_nodes); | 2833 cras_audio_handler_->ChangeActiveNodes(active_nodes); |
| 2988 | 2834 |
| 2989 // Verify the jabra speaker's output is selected as active output, and | 2835 // Verify the jabra speaker's output is selected as active output, and |
| 2990 // jabra's input is selected as active input. | 2836 // jabra's input is selected as active input. |
| 2991 EXPECT_EQ(2, GetActiveDeviceCount()); | 2837 EXPECT_EQ(2, GetActiveDeviceCount()); |
| 2992 EXPECT_EQ(kUSBJabraSpeakerOutput1.id, | 2838 EXPECT_EQ(kUSBJabraSpeakerOutput1->id, |
| 2993 cras_audio_handler_->GetPrimaryActiveOutputNode()); | 2839 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 2994 EXPECT_EQ(kUSBJabraSpeakerInput1.id, | 2840 EXPECT_EQ(kUSBJabraSpeakerInput1->id, |
| 2995 cras_audio_handler_->GetPrimaryActiveInputNode()); | 2841 cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 2996 } | 2842 } |
| 2997 | 2843 |
| 2998 TEST_F(CrasAudioHandlerTest, ChangeActiveNodesDeactivatePrimaryActiveNode) { | 2844 TEST_P(CrasAudioHandlerTest, ChangeActiveNodesDeactivatePrimaryActiveNode) { |
| 2999 AudioNodeList audio_nodes; | 2845 AudioNodeList audio_nodes = |
| 3000 audio_nodes.push_back(kUSBJabraSpeakerInput1); | 2846 GenerateAudioNodeList({kUSBJabraSpeakerInput1, kUSBJabraSpeakerInput2}); |
| 3001 audio_nodes.push_back(kUSBJabraSpeakerInput2); | 2847 AudioNode usb_camera = GenerateAudioNode(kUSBCameraInput); |
| 3002 AudioNode usb_camera(kUSBCameraInput); | |
| 3003 usb_camera.plugged_time = 10000000; | 2848 usb_camera.plugged_time = 10000000; |
| 3004 audio_nodes.push_back(usb_camera); | 2849 audio_nodes.push_back(usb_camera); |
| 3005 SetUpCrasAudioHandler(audio_nodes); | 2850 SetUpCrasAudioHandler(audio_nodes); |
| 3006 | 2851 |
| 3007 // Verify the audio devices size. | 2852 // Verify the audio devices size. |
| 3008 AudioDeviceList audio_devices; | 2853 AudioDeviceList audio_devices; |
| 3009 cras_audio_handler_->GetAudioDevices(&audio_devices); | 2854 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 3010 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); | 2855 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); |
| 3011 | 2856 |
| 3012 // Verify the camera's input is selected as active input by CrasAudioHandler | 2857 // Verify the camera's input is selected as active input by CrasAudioHandler |
| 3013 EXPECT_EQ(1, GetActiveDeviceCount()); | 2858 EXPECT_EQ(1, GetActiveDeviceCount()); |
| 3014 EXPECT_EQ(kUSBCameraInput.id, | 2859 EXPECT_EQ(kUSBCameraInput->id, |
| 3015 cras_audio_handler_->GetPrimaryActiveInputNode()); | 2860 cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 3016 | 2861 |
| 3017 // Simulate hotrod app call to set jabra input as active device with only | 2862 // Simulate hotrod app call to set jabra input as active device with only |
| 3018 // jabra input node in the active node list, which does not conform to the | 2863 // jabra input node in the active node list, which does not conform to the |
| 3019 // new SetActiveDevices protocol, but just show we can still handle it if | 2864 // new SetActiveDevices protocol, but just show we can still handle it if |
| 3020 // this happens. | 2865 // this happens. |
| 3021 { | 2866 { |
| 3022 CrasAudioHandler::NodeIdList active_nodes; | 2867 CrasAudioHandler::NodeIdList active_nodes; |
| 3023 active_nodes.push_back(kUSBJabraSpeakerInput1.id); | 2868 active_nodes.push_back(kUSBJabraSpeakerInput1->id); |
| 3024 active_nodes.push_back(kUSBCameraInput.id); | 2869 active_nodes.push_back(kUSBCameraInput->id); |
| 3025 cras_audio_handler_->ChangeActiveNodes(active_nodes); | 2870 cras_audio_handler_->ChangeActiveNodes(active_nodes); |
| 3026 } | 2871 } |
| 3027 | 2872 |
| 3028 // Verify the jabra speaker's output is selected as active output, and | 2873 // Verify the jabra speaker's output is selected as active output, and |
| 3029 // jabra's input is selected as active input. | 2874 // jabra's input is selected as active input. |
| 3030 EXPECT_EQ(2, GetActiveDeviceCount()); | 2875 EXPECT_EQ(2, GetActiveDeviceCount()); |
| 3031 EXPECT_EQ(kUSBCameraInput.id, | 2876 EXPECT_EQ(kUSBCameraInput->id, |
| 3032 cras_audio_handler_->GetPrimaryActiveInputNode()); | 2877 cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 3033 | 2878 |
| 3034 const AudioDevice* additional_speaker = | 2879 const AudioDevice* additional_speaker = |
| 3035 cras_audio_handler_->GetDeviceFromId(kUSBJabraSpeakerInput1.id); | 2880 cras_audio_handler_->GetDeviceFromId(kUSBJabraSpeakerInput1->id); |
| 3036 ASSERT_TRUE(additional_speaker); | 2881 ASSERT_TRUE(additional_speaker); |
| 3037 EXPECT_TRUE(additional_speaker->active); | 2882 EXPECT_TRUE(additional_speaker->active); |
| 3038 | 2883 |
| 3039 { | 2884 { |
| 3040 CrasAudioHandler::NodeIdList active_nodes; | 2885 CrasAudioHandler::NodeIdList active_nodes; |
| 3041 active_nodes.push_back(kUSBJabraSpeakerInput1.id); | 2886 active_nodes.push_back(kUSBJabraSpeakerInput1->id); |
| 3042 active_nodes.push_back(kUSBJabraSpeakerInput2.id); | 2887 active_nodes.push_back(kUSBJabraSpeakerInput2->id); |
| 3043 cras_audio_handler_->ChangeActiveNodes(active_nodes); | 2888 cras_audio_handler_->ChangeActiveNodes(active_nodes); |
| 3044 } | 2889 } |
| 3045 | 2890 |
| 3046 EXPECT_EQ(2, GetActiveDeviceCount()); | 2891 EXPECT_EQ(2, GetActiveDeviceCount()); |
| 3047 EXPECT_EQ(kUSBJabraSpeakerInput1.id, | 2892 EXPECT_EQ(kUSBJabraSpeakerInput1->id, |
| 3048 cras_audio_handler_->GetPrimaryActiveInputNode()); | 2893 cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 3049 | 2894 |
| 3050 additional_speaker = | 2895 additional_speaker = |
| 3051 cras_audio_handler_->GetDeviceFromId(kUSBJabraSpeakerInput2.id); | 2896 cras_audio_handler_->GetDeviceFromId(kUSBJabraSpeakerInput2->id); |
| 3052 ASSERT_TRUE(additional_speaker); | 2897 ASSERT_TRUE(additional_speaker); |
| 3053 EXPECT_TRUE(additional_speaker->active); | 2898 EXPECT_TRUE(additional_speaker->active); |
| 3054 } | 2899 } |
| 3055 | 2900 |
| 3056 TEST_F(CrasAudioHandlerTest, | 2901 TEST_P(CrasAudioHandlerTest, |
| 3057 ChangeActiveNodesHotrodInitWithSingleJabraCameraPlugInLaterOldCall) { | 2902 ChangeActiveNodesHotrodInitWithSingleJabraCameraPlugInLaterOldCall) { |
| 3058 AudioNodeList audio_nodes; | 2903 AudioNodeList audio_nodes = GenerateAudioNodeList( |
| 3059 audio_nodes.push_back(kHDMIOutput); | 2904 {kHDMIOutput, kUSBJabraSpeakerOutput1, kUSBJabraSpeakerInput1}); |
| 3060 audio_nodes.push_back(kUSBJabraSpeakerOutput1); | 2905 AudioNode usb_camera = GenerateAudioNode(kUSBCameraInput); |
| 3061 audio_nodes.push_back(kUSBJabraSpeakerInput1); | |
| 3062 AudioNode usb_camera(kUSBCameraInput); | |
| 3063 usb_camera.plugged_time = 10000000; | 2906 usb_camera.plugged_time = 10000000; |
| 3064 audio_nodes.push_back(usb_camera); | 2907 audio_nodes.push_back(usb_camera); |
| 3065 SetUpCrasAudioHandler(audio_nodes); | 2908 SetUpCrasAudioHandler(audio_nodes); |
| 3066 | 2909 |
| 3067 // Verify the audio devices size. | 2910 // Verify the audio devices size. |
| 3068 AudioDeviceList audio_devices; | 2911 AudioDeviceList audio_devices; |
| 3069 cras_audio_handler_->GetAudioDevices(&audio_devices); | 2912 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 3070 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); | 2913 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); |
| 3071 | 2914 |
| 3072 // Verify the jabra speaker's output is selected as active output, and | 2915 // Verify the jabra speaker's output is selected as active output, and |
| 3073 // camera's input is selected as active input by CrasAudioHandler | 2916 // camera's input is selected as active input by CrasAudioHandler |
| 3074 EXPECT_EQ(2, GetActiveDeviceCount()); | 2917 EXPECT_EQ(2, GetActiveDeviceCount()); |
| 3075 EXPECT_EQ(kUSBJabraSpeakerOutput1.id, | 2918 EXPECT_EQ(kUSBJabraSpeakerOutput1->id, |
| 3076 cras_audio_handler_->GetPrimaryActiveOutputNode()); | 2919 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 3077 EXPECT_EQ(kUSBCameraInput.id, | 2920 EXPECT_EQ(kUSBCameraInput->id, |
| 3078 cras_audio_handler_->GetPrimaryActiveInputNode()); | 2921 cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 3079 | 2922 |
| 3080 // Simulate hotrod app call to set jabra input as active device with only | 2923 // Simulate hotrod app call to set jabra input as active device with only |
| 3081 // jabra input node in the active node list, which does not conform to the | 2924 // jabra input node in the active node list, which does not conform to the |
| 3082 // new SetActiveDevices protocol, but just show we can still handle it if | 2925 // new SetActiveDevices protocol, but just show we can still handle it if |
| 3083 // this happens. | 2926 // this happens. |
| 3084 CrasAudioHandler::NodeIdList active_nodes; | 2927 CrasAudioHandler::NodeIdList active_nodes; |
| 3085 active_nodes.push_back(kUSBJabraSpeakerInput1.id); | 2928 active_nodes.push_back(kUSBJabraSpeakerInput1->id); |
| 3086 cras_audio_handler_->ChangeActiveNodes(active_nodes); | 2929 cras_audio_handler_->ChangeActiveNodes(active_nodes); |
| 3087 | 2930 |
| 3088 // Verify the jabra speaker's output is selected as active output, and | 2931 // Verify the jabra speaker's output is selected as active output, and |
| 3089 // jabra's input is selected as active input. | 2932 // jabra's input is selected as active input. |
| 3090 EXPECT_EQ(2, GetActiveDeviceCount()); | 2933 EXPECT_EQ(2, GetActiveDeviceCount()); |
| 3091 EXPECT_EQ(kUSBJabraSpeakerOutput1.id, | 2934 EXPECT_EQ(kUSBJabraSpeakerOutput1->id, |
| 3092 cras_audio_handler_->GetPrimaryActiveOutputNode()); | 2935 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 3093 EXPECT_EQ(kUSBJabraSpeakerInput1.id, | 2936 EXPECT_EQ(kUSBJabraSpeakerInput1->id, |
| 3094 cras_audio_handler_->GetPrimaryActiveInputNode()); | 2937 cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 3095 } | 2938 } |
| 3096 | 2939 |
| 3097 TEST_F(CrasAudioHandlerTest, | 2940 TEST_P(CrasAudioHandlerTest, |
| 3098 ChangeActiveNodesHotrodInitWithSingleJabraChangeOutput) { | 2941 ChangeActiveNodesHotrodInitWithSingleJabraChangeOutput) { |
| 3099 AudioNodeList audio_nodes; | 2942 AudioNodeList audio_nodes = |
| 3100 audio_nodes.push_back(kHDMIOutput); | 2943 GenerateAudioNodeList({kHDMIOutput, kUSBJabraSpeakerOutput1, |
| 3101 audio_nodes.push_back(kUSBJabraSpeakerOutput1); | 2944 kUSBJabraSpeakerInput1, kUSBCameraInput}); |
| 3102 audio_nodes.push_back(kUSBJabraSpeakerInput1); | |
| 3103 audio_nodes.push_back(kUSBCameraInput); | |
| 3104 SetUpCrasAudioHandler(audio_nodes); | 2945 SetUpCrasAudioHandler(audio_nodes); |
| 3105 | 2946 |
| 3106 // Verify the audio devices size. | 2947 // Verify the audio devices size. |
| 3107 AudioDeviceList audio_devices; | 2948 AudioDeviceList audio_devices; |
| 3108 cras_audio_handler_->GetAudioDevices(&audio_devices); | 2949 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 3109 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); | 2950 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); |
| 3110 | 2951 |
| 3111 // Verify the jabra speaker's output and input are selected as active output | 2952 // Verify the jabra speaker's output and input are selected as active output |
| 3112 // by CrasAudioHandler. | 2953 // by CrasAudioHandler. |
| 3113 EXPECT_EQ(2, GetActiveDeviceCount()); | 2954 EXPECT_EQ(2, GetActiveDeviceCount()); |
| 3114 EXPECT_EQ(kUSBJabraSpeakerOutput1.id, | 2955 EXPECT_EQ(kUSBJabraSpeakerOutput1->id, |
| 3115 cras_audio_handler_->GetPrimaryActiveOutputNode()); | 2956 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 3116 EXPECT_EQ(kUSBJabraSpeakerInput1.id, | 2957 EXPECT_EQ(kUSBJabraSpeakerInput1->id, |
| 3117 cras_audio_handler_->GetPrimaryActiveInputNode()); | 2958 cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 3118 | 2959 |
| 3119 // Simulate hotrod app call SetActiveDevices to change active output | 2960 // Simulate hotrod app call SetActiveDevices to change active output |
| 3120 // with only complete list of active nodes passed in, which is the new | 2961 // with only complete list of active nodes passed in, which is the new |
| 3121 // way of hotrod app. | 2962 // way of hotrod app. |
| 3122 CrasAudioHandler::NodeIdList active_nodes; | 2963 CrasAudioHandler::NodeIdList active_nodes; |
| 3123 active_nodes.push_back(kHDMIOutput.id); | 2964 active_nodes.push_back(kHDMIOutput->id); |
| 3124 active_nodes.push_back(kUSBJabraSpeakerInput1.id); | 2965 active_nodes.push_back(kUSBJabraSpeakerInput1->id); |
| 3125 cras_audio_handler_->ChangeActiveNodes(active_nodes); | 2966 cras_audio_handler_->ChangeActiveNodes(active_nodes); |
| 3126 | 2967 |
| 3127 // Verify the jabra speaker's output is selected as active output, and | 2968 // Verify the jabra speaker's output is selected as active output, and |
| 3128 // jabra's input is selected as active input. | 2969 // jabra's input is selected as active input. |
| 3129 EXPECT_EQ(2, GetActiveDeviceCount()); | 2970 EXPECT_EQ(2, GetActiveDeviceCount()); |
| 3130 EXPECT_EQ(kHDMIOutput.id, cras_audio_handler_->GetPrimaryActiveOutputNode()); | 2971 EXPECT_EQ(kHDMIOutput->id, cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 3131 EXPECT_EQ(kUSBJabraSpeakerInput1.id, | 2972 EXPECT_EQ(kUSBJabraSpeakerInput1->id, |
| 3132 cras_audio_handler_->GetPrimaryActiveInputNode()); | 2973 cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 3133 } | 2974 } |
| 3134 | 2975 |
| 3135 TEST_F(CrasAudioHandlerTest, | 2976 TEST_P(CrasAudioHandlerTest, |
| 3136 ChangeActiveNodesHotrodInitWithSingleJabraChangeOutputOldCall) { | 2977 ChangeActiveNodesHotrodInitWithSingleJabraChangeOutputOldCall) { |
| 3137 AudioNodeList audio_nodes; | 2978 AudioNodeList audio_nodes = |
| 3138 audio_nodes.push_back(kHDMIOutput); | 2979 GenerateAudioNodeList({kHDMIOutput, kUSBJabraSpeakerOutput1, |
| 3139 audio_nodes.push_back(kUSBJabraSpeakerOutput1); | 2980 kUSBJabraSpeakerInput1, kUSBCameraInput}); |
| 3140 audio_nodes.push_back(kUSBJabraSpeakerInput1); | |
| 3141 audio_nodes.push_back(kUSBCameraInput); | |
| 3142 SetUpCrasAudioHandler(audio_nodes); | 2981 SetUpCrasAudioHandler(audio_nodes); |
| 3143 | 2982 |
| 3144 // Verify the audio devices size. | 2983 // Verify the audio devices size. |
| 3145 AudioDeviceList audio_devices; | 2984 AudioDeviceList audio_devices; |
| 3146 cras_audio_handler_->GetAudioDevices(&audio_devices); | 2985 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 3147 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); | 2986 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); |
| 3148 | 2987 |
| 3149 // Verify the jabra speaker's output and input are selected as active output | 2988 // Verify the jabra speaker's output and input are selected as active output |
| 3150 // by CrasAudioHandler. | 2989 // by CrasAudioHandler. |
| 3151 EXPECT_EQ(2, GetActiveDeviceCount()); | 2990 EXPECT_EQ(2, GetActiveDeviceCount()); |
| 3152 EXPECT_EQ(kUSBJabraSpeakerOutput1.id, | 2991 EXPECT_EQ(kUSBJabraSpeakerOutput1->id, |
| 3153 cras_audio_handler_->GetPrimaryActiveOutputNode()); | 2992 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 3154 EXPECT_EQ(kUSBJabraSpeakerInput1.id, | 2993 EXPECT_EQ(kUSBJabraSpeakerInput1->id, |
| 3155 cras_audio_handler_->GetPrimaryActiveInputNode()); | 2994 cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 3156 | 2995 |
| 3157 // Simulate hotrod app call SetActiveDevices to change active output | 2996 // Simulate hotrod app call SetActiveDevices to change active output |
| 3158 // with only a single active output nodes passed in, which is the old | 2997 // with only a single active output nodes passed in, which is the old |
| 3159 // way of hotrod app. | 2998 // way of hotrod app. |
| 3160 CrasAudioHandler::NodeIdList active_nodes; | 2999 CrasAudioHandler::NodeIdList active_nodes; |
| 3161 active_nodes.push_back(kHDMIOutput.id); | 3000 active_nodes.push_back(kHDMIOutput->id); |
| 3162 cras_audio_handler_->ChangeActiveNodes(active_nodes); | 3001 cras_audio_handler_->ChangeActiveNodes(active_nodes); |
| 3163 | 3002 |
| 3164 // Verify the jabra speaker's output is selected as active output, and | 3003 // Verify the jabra speaker's output is selected as active output, and |
| 3165 // jabra's input is selected as active input. | 3004 // jabra's input is selected as active input. |
| 3166 EXPECT_EQ(2, GetActiveDeviceCount()); | 3005 EXPECT_EQ(2, GetActiveDeviceCount()); |
| 3167 EXPECT_EQ(kHDMIOutput.id, cras_audio_handler_->GetPrimaryActiveOutputNode()); | 3006 EXPECT_EQ(kHDMIOutput->id, cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 3168 EXPECT_EQ(kUSBJabraSpeakerInput1.id, | 3007 EXPECT_EQ(kUSBJabraSpeakerInput1->id, |
| 3169 cras_audio_handler_->GetPrimaryActiveInputNode()); | 3008 cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 3170 } | 3009 } |
| 3171 | 3010 |
| 3172 TEST_F(CrasAudioHandlerTest, NoMoreAudioInputDevices) { | 3011 TEST_P(CrasAudioHandlerTest, NoMoreAudioInputDevices) { |
| 3173 // Some device like chromebox does not have the internal input device. The | 3012 // Some device like chromebox does not have the internal input device. The |
| 3174 // active devices should be reset when the user plugs a device and then | 3013 // active devices should be reset when the user plugs a device and then |
| 3175 // unplugs it to such device. | 3014 // unplugs it to such device. |
| 3176 | 3015 AudioNodeList audio_nodes = GenerateAudioNodeList({kInternalSpeaker}); |
| 3177 AudioNodeList audio_nodes; | |
| 3178 audio_nodes.push_back(kInternalSpeaker); | |
| 3179 SetUpCrasAudioHandler(audio_nodes); | 3016 SetUpCrasAudioHandler(audio_nodes); |
| 3180 | 3017 |
| 3181 EXPECT_EQ(0ULL, cras_audio_handler_->GetPrimaryActiveInputNode()); | 3018 EXPECT_EQ(0ULL, cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 3182 | 3019 |
| 3183 audio_nodes.push_back(kMicJack); | 3020 audio_nodes.push_back(GenerateAudioNode(kMicJack)); |
| 3184 ChangeAudioNodes(audio_nodes); | 3021 ChangeAudioNodes(audio_nodes); |
| 3185 | 3022 |
| 3186 EXPECT_EQ(kMicJack.id, cras_audio_handler_->GetPrimaryActiveInputNode()); | 3023 EXPECT_EQ(kMicJack->id, cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 3187 EXPECT_EQ(1, test_observer_->active_input_node_changed_count()); | 3024 EXPECT_EQ(1, test_observer_->active_input_node_changed_count()); |
| 3188 test_observer_->reset_active_input_node_changed_count(); | 3025 test_observer_->reset_active_input_node_changed_count(); |
| 3189 | 3026 |
| 3190 audio_nodes.pop_back(); | 3027 audio_nodes.pop_back(); |
| 3191 ChangeAudioNodes(audio_nodes); | 3028 ChangeAudioNodes(audio_nodes); |
| 3192 EXPECT_EQ(0ULL, cras_audio_handler_->GetPrimaryActiveInputNode()); | 3029 EXPECT_EQ(0ULL, cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 3193 EXPECT_EQ(1, test_observer_->active_input_node_changed_count()); | 3030 EXPECT_EQ(1, test_observer_->active_input_node_changed_count()); |
| 3194 } | 3031 } |
| 3195 | 3032 |
| 3196 // Test the case in which an HDMI output is plugged in with other higher | 3033 // Test the case in which an HDMI output is plugged in with other higher |
| 3197 // priority | 3034 // priority |
| 3198 // output devices already plugged and user has manually selected an active | 3035 // output devices already plugged and user has manually selected an active |
| 3199 // output. | 3036 // output. |
| 3200 // The hotplug of hdmi output should not change user's selection of active | 3037 // The hotplug of hdmi output should not change user's selection of active |
| 3201 // device. | 3038 // device. |
| 3202 // crbug.com/447826. | 3039 // crbug.com/447826. |
| 3203 TEST_F(CrasAudioHandlerTest, HotPlugHDMINotChangeActiveOutput) { | 3040 TEST_P(CrasAudioHandlerTest, HotPlugHDMINotChangeActiveOutput) { |
| 3204 AudioNodeList audio_nodes; | 3041 AudioNodeList audio_nodes; |
| 3205 AudioNode internal_speaker(kInternalSpeaker); | 3042 AudioNode internal_speaker = GenerateAudioNode(kInternalSpeaker); |
| 3206 audio_nodes.push_back(internal_speaker); | 3043 audio_nodes.push_back(internal_speaker); |
| 3207 AudioNode usb_headset(kUSBHeadphone1); | 3044 AudioNode usb_headset = GenerateAudioNode(kUSBHeadphone1); |
| 3208 usb_headset.plugged_time = 80000000; | 3045 usb_headset.plugged_time = 80000000; |
| 3209 audio_nodes.push_back(usb_headset); | 3046 audio_nodes.push_back(usb_headset); |
| 3210 SetUpCrasAudioHandler(audio_nodes); | 3047 SetUpCrasAudioHandler(audio_nodes); |
| 3211 | 3048 |
| 3212 // Verify the audio devices size. | 3049 // Verify the audio devices size. |
| 3213 AudioDeviceList audio_devices; | 3050 AudioDeviceList audio_devices; |
| 3214 cras_audio_handler_->GetAudioDevices(&audio_devices); | 3051 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 3215 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); | 3052 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); |
| 3216 | 3053 |
| 3217 // Verify the USB headset is selected as active output by default. | 3054 // Verify the USB headset is selected as active output by default. |
| 3218 EXPECT_EQ(usb_headset.id, cras_audio_handler_->GetPrimaryActiveOutputNode()); | 3055 EXPECT_EQ(usb_headset.id, cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 3219 | 3056 |
| 3220 // Manually set the active output to internal speaker. | 3057 // Manually set the active output to internal speaker. |
| 3221 AudioDevice internal_output(kInternalSpeaker); | 3058 AudioDevice internal_output(GenerateAudioNode(kInternalSpeaker)); |
| 3222 cras_audio_handler_->SwitchToDevice(internal_output, true, | 3059 cras_audio_handler_->SwitchToDevice(internal_output, true, |
| 3223 CrasAudioHandler::ACTIVATE_BY_USER); | 3060 CrasAudioHandler::ACTIVATE_BY_USER); |
| 3224 | 3061 |
| 3225 // Verify the active output is switched to internal speaker. | 3062 // Verify the active output is switched to internal speaker. |
| 3226 EXPECT_EQ(internal_speaker.id, | 3063 EXPECT_EQ(internal_speaker.id, |
| 3227 cras_audio_handler_->GetPrimaryActiveOutputNode()); | 3064 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 3228 EXPECT_LT(kInternalSpeaker.plugged_time, usb_headset.plugged_time); | 3065 EXPECT_LT(internal_speaker.plugged_time, usb_headset.plugged_time); |
| 3229 const AudioDevice* usb_device = GetDeviceFromId(usb_headset.id); | 3066 const AudioDevice* usb_device = GetDeviceFromId(usb_headset.id); |
| 3230 EXPECT_FALSE(usb_device->active); | 3067 EXPECT_FALSE(usb_device->active); |
| 3231 | 3068 |
| 3232 // Plug in HDMI output. | 3069 // Plug in HDMI output. |
| 3233 audio_nodes.clear(); | 3070 audio_nodes.clear(); |
| 3234 internal_speaker.active = true; | 3071 internal_speaker.active = true; |
| 3235 audio_nodes.push_back(internal_speaker); | 3072 audio_nodes.push_back(internal_speaker); |
| 3236 usb_headset.active = false; | 3073 usb_headset.active = false; |
| 3237 audio_nodes.push_back(usb_headset); | 3074 audio_nodes.push_back(usb_headset); |
| 3238 AudioNode hdmi(kHDMIOutput); | 3075 AudioNode hdmi = GenerateAudioNode(kHDMIOutput); |
| 3239 hdmi.plugged_time = 90000000; | 3076 hdmi.plugged_time = 90000000; |
| 3240 audio_nodes.push_back(hdmi); | 3077 audio_nodes.push_back(hdmi); |
| 3241 ChangeAudioNodes(audio_nodes); | 3078 ChangeAudioNodes(audio_nodes); |
| 3242 | 3079 |
| 3243 // The active output should not change. | 3080 // The active output should not change. |
| 3244 EXPECT_EQ(kInternalSpeaker.id, | 3081 EXPECT_EQ(kInternalSpeaker->id, |
| 3245 cras_audio_handler_->GetPrimaryActiveOutputNode()); | 3082 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 3246 } | 3083 } |
| 3247 | 3084 |
| 3248 // Test the case in which the active device was set to inactive from cras after | 3085 // Test the case in which the active device was set to inactive from cras after |
| 3249 // resuming from suspension state. See crbug.com/478968. | 3086 // resuming from suspension state. See crbug.com/478968. |
| 3250 TEST_F(CrasAudioHandlerTest, ActiveNodeLostAfterResume) { | 3087 TEST_P(CrasAudioHandlerTest, ActiveNodeLostAfterResume) { |
| 3251 AudioNodeList audio_nodes; | 3088 AudioNodeList audio_nodes = GenerateAudioNodeList({kHeadphone, kHDMIOutput}); |
| 3252 EXPECT_FALSE(kHeadphone.active); | 3089 for (const auto& node : audio_nodes) |
| 3253 audio_nodes.push_back(kHeadphone); | 3090 ASSERT_FALSE(node.active) << node.id << " expected to be inactive"; |
| 3254 EXPECT_FALSE(kHDMIOutput.active); | |
| 3255 audio_nodes.push_back(kHDMIOutput); | |
| 3256 SetUpCrasAudioHandler(audio_nodes); | 3091 SetUpCrasAudioHandler(audio_nodes); |
| 3257 | 3092 |
| 3258 // Verify the headphone is selected as the active output. | 3093 // Verify the headphone is selected as the active output. |
| 3259 AudioDeviceList audio_devices; | 3094 AudioDeviceList audio_devices; |
| 3260 cras_audio_handler_->GetAudioDevices(&audio_devices); | 3095 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 3261 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); | 3096 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); |
| 3262 EXPECT_EQ(kHeadphone.id, cras_audio_handler_->GetPrimaryActiveOutputNode()); | 3097 EXPECT_EQ(kHeadphone->id, cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 3263 const AudioDevice* active_headphone = GetDeviceFromId(kHeadphone.id); | 3098 const AudioDevice* active_headphone = GetDeviceFromId(kHeadphone->id); |
| 3264 EXPECT_EQ(kHeadphone.id, active_headphone->id); | 3099 EXPECT_EQ(kHeadphone->id, active_headphone->id); |
| 3265 EXPECT_TRUE(active_headphone->active); | 3100 EXPECT_TRUE(active_headphone->active); |
| 3266 | 3101 |
| 3267 // Simulate NodesChanged signal with headphone turning into inactive state, | 3102 // Simulate NodesChanged signal with headphone turning into inactive state, |
| 3268 // and HDMI node removed. | 3103 // and HDMI node removed. |
| 3269 audio_nodes.clear(); | 3104 audio_nodes.clear(); |
| 3270 audio_nodes.push_back(kHeadphone); | 3105 audio_nodes.push_back(GenerateAudioNode(kHeadphone)); |
| 3271 ChangeAudioNodes(audio_nodes); | 3106 ChangeAudioNodes(audio_nodes); |
| 3272 | 3107 |
| 3273 // Verify the headphone is set to active again. | 3108 // Verify the headphone is set to active again. |
| 3274 EXPECT_EQ(kHeadphone.id, cras_audio_handler_->GetPrimaryActiveOutputNode()); | 3109 EXPECT_EQ(kHeadphone->id, cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 3275 const AudioDevice* headphone_resumed = GetDeviceFromId(kHeadphone.id); | 3110 const AudioDevice* headphone_resumed = GetDeviceFromId(kHeadphone->id); |
| 3276 EXPECT_EQ(kHeadphone.id, headphone_resumed->id); | 3111 EXPECT_EQ(kHeadphone->id, headphone_resumed->id); |
| 3277 EXPECT_TRUE(headphone_resumed->active); | 3112 EXPECT_TRUE(headphone_resumed->active); |
| 3278 } | 3113 } |
| 3279 | 3114 |
| 3280 // In the mirror mode, when the device resumes after being suspended, the hmdi | 3115 // In the mirror mode, when the device resumes after being suspended, the hmdi |
| 3281 // node will be lost first, then re-appear with a different node id, but with | 3116 // node will be lost first, then re-appear with a different node id, but with |
| 3282 // the same stable id. If it is set as the non-active node by user before | 3117 // the same stable id. If it is set as the non-active node by user before |
| 3283 // suspend/resume, it should remain inactive after the device resumes even | 3118 // suspend/resume, it should remain inactive after the device resumes even |
| 3284 // if it has a higher priority than the current active node. | 3119 // if it has a higher priority than the current active node. |
| 3285 // crbug.com/443014. | 3120 // crbug.com/443014. |
| 3286 TEST_F(CrasAudioHandlerTest, HDMIRemainInactiveAfterSuspendResume) { | 3121 TEST_P(CrasAudioHandlerTest, HDMIRemainInactiveAfterSuspendResume) { |
| 3287 AudioNodeList audio_nodes; | 3122 AudioNodeList audio_nodes; |
| 3288 AudioNode internal_speaker(kInternalSpeaker); | 3123 AudioNode internal_speaker = GenerateAudioNode(kInternalSpeaker); |
| 3289 audio_nodes.push_back(internal_speaker); | 3124 audio_nodes.push_back(internal_speaker); |
| 3290 AudioNode hdmi_output(kHDMIOutput); | 3125 AudioNode hdmi_output = GenerateAudioNode(kHDMIOutput); |
| 3291 audio_nodes.push_back(hdmi_output); | 3126 audio_nodes.push_back(hdmi_output); |
| 3292 SetUpCrasAudioHandler(audio_nodes); | 3127 SetUpCrasAudioHandler(audio_nodes); |
| 3293 | 3128 |
| 3294 // Verify the hdmi is selected as the active output since it has a higher | 3129 // Verify the hdmi is selected as the active output since it has a higher |
| 3295 // priority. | 3130 // priority. |
| 3296 AudioDeviceList audio_devices; | 3131 AudioDeviceList audio_devices; |
| 3297 cras_audio_handler_->GetAudioDevices(&audio_devices); | 3132 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 3298 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); | 3133 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); |
| 3299 EXPECT_EQ(hdmi_output.id, cras_audio_handler_->GetPrimaryActiveOutputNode()); | 3134 EXPECT_EQ(hdmi_output.id, cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 3300 | 3135 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 3317 EXPECT_EQ(1u, audio_devices.size()); | 3152 EXPECT_EQ(1u, audio_devices.size()); |
| 3318 EXPECT_EQ(internal_speaker.id, | 3153 EXPECT_EQ(internal_speaker.id, |
| 3319 cras_audio_handler_->GetPrimaryActiveOutputNode()); | 3154 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 3320 | 3155 |
| 3321 // Simulate the re-appearing of the hdmi node, which comes with a new id, | 3156 // Simulate the re-appearing of the hdmi node, which comes with a new id, |
| 3322 // but the same stable device id. | 3157 // but the same stable device id. |
| 3323 AudioNode hdmi_output_2(hdmi_output); | 3158 AudioNode hdmi_output_2(hdmi_output); |
| 3324 hdmi_output_2.id = 20006; | 3159 hdmi_output_2.id = 20006; |
| 3325 hdmi_output_2.plugged_time = internal_speaker.plugged_time + 100; | 3160 hdmi_output_2.plugged_time = internal_speaker.plugged_time + 100; |
| 3326 audio_nodes.push_back(hdmi_output_2); | 3161 audio_nodes.push_back(hdmi_output_2); |
| 3327 EXPECT_NE(hdmi_output.id, hdmi_output_2.id); | 3162 ASSERT_NE(hdmi_output.id, hdmi_output_2.id); |
| 3328 EXPECT_EQ(hdmi_output.stable_device_id, hdmi_output_2.stable_device_id); | 3163 ASSERT_EQ(hdmi_output.StableDeviceId(), hdmi_output_2.StableDeviceId()); |
| 3329 ChangeAudioNodes(audio_nodes); | 3164 ChangeAudioNodes(audio_nodes); |
| 3330 | 3165 |
| 3331 // Verify the hdmi node is not set the active, and the current active node | 3166 // Verify the hdmi node is not set the active, and the current active node |
| 3332 // , the internal speaker, remains active. | 3167 // , the internal speaker, remains active. |
| 3333 cras_audio_handler_->GetAudioDevices(&audio_devices); | 3168 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 3334 EXPECT_EQ(2u, audio_devices.size()); | 3169 EXPECT_EQ(2u, audio_devices.size()); |
| 3335 EXPECT_EQ(internal_speaker.id, | 3170 EXPECT_EQ(internal_speaker.id, |
| 3336 cras_audio_handler_->GetPrimaryActiveOutputNode()); | 3171 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 3337 } | 3172 } |
| 3338 | 3173 |
| 3339 // Test the case in which there are two NodesChanged signal for discovering | 3174 // Test the case in which there are two NodesChanged signal for discovering |
| 3340 // output devices, and there is race between NodesChange and SetActiveOutput | 3175 // output devices, and there is race between NodesChange and SetActiveOutput |
| 3341 // during this process. See crbug.com/478968. | 3176 // during this process. See crbug.com/478968. |
| 3342 TEST_F(CrasAudioHandlerTest, ActiveNodeLostDuringLoginSession) { | 3177 TEST_P(CrasAudioHandlerTest, ActiveNodeLostDuringLoginSession) { |
| 3343 AudioNodeList audio_nodes; | 3178 AudioNodeList audio_nodes = GenerateAudioNodeList({kHeadphone}); |
| 3344 EXPECT_FALSE(kHeadphone.active); | 3179 for (const auto& node : audio_nodes) |
| 3345 audio_nodes.push_back(kHeadphone); | 3180 ASSERT_FALSE(node.active) << node.id << " expected to be inactive"; |
| 3346 SetUpCrasAudioHandler(audio_nodes); | 3181 SetUpCrasAudioHandler(audio_nodes); |
| 3347 | 3182 |
| 3348 // Verify the headphone is selected as the active output. | 3183 // Verify the headphone is selected as the active output. |
| 3349 AudioDeviceList audio_devices; | 3184 AudioDeviceList audio_devices; |
| 3350 cras_audio_handler_->GetAudioDevices(&audio_devices); | 3185 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 3351 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); | 3186 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); |
| 3352 EXPECT_EQ(kHeadphone.id, cras_audio_handler_->GetPrimaryActiveOutputNode()); | 3187 EXPECT_EQ(kHeadphone->id, cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 3353 const AudioDevice* active_headphone = GetDeviceFromId(kHeadphone.id); | 3188 const AudioDevice* active_headphone = GetDeviceFromId(kHeadphone->id); |
| 3354 EXPECT_EQ(kHeadphone.id, active_headphone->id); | 3189 EXPECT_EQ(kHeadphone->id, active_headphone->id); |
| 3355 EXPECT_TRUE(active_headphone->active); | 3190 EXPECT_TRUE(active_headphone->active); |
| 3356 | 3191 |
| 3357 // Simulate NodesChanged signal with headphone turning into inactive state, | 3192 // Simulate NodesChanged signal with headphone turning into inactive state, |
| 3358 // and add a new HDMI output node. | 3193 // and add a new HDMI output node. |
| 3359 audio_nodes.clear(); | 3194 audio_nodes.clear(); |
| 3360 audio_nodes.push_back(kHeadphone); | 3195 audio_nodes.push_back(GenerateAudioNode(kHeadphone)); |
| 3361 audio_nodes.push_back(kHDMIOutput); | 3196 audio_nodes.push_back(GenerateAudioNode(kHDMIOutput)); |
| 3362 ChangeAudioNodes(audio_nodes); | 3197 ChangeAudioNodes(audio_nodes); |
| 3363 | 3198 |
| 3364 // Verify the headphone is set to active again. | 3199 // Verify the headphone is set to active again. |
| 3365 EXPECT_EQ(kHeadphone.id, cras_audio_handler_->GetPrimaryActiveOutputNode()); | 3200 EXPECT_EQ(kHeadphone->id, cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 3366 const AudioDevice* headphone_resumed = GetDeviceFromId(kHeadphone.id); | 3201 const AudioDevice* headphone_resumed = GetDeviceFromId(kHeadphone->id); |
| 3367 EXPECT_EQ(kHeadphone.id, headphone_resumed->id); | 3202 EXPECT_EQ(kHeadphone->id, headphone_resumed->id); |
| 3368 EXPECT_TRUE(headphone_resumed->active); | 3203 EXPECT_TRUE(headphone_resumed->active); |
| 3369 } | 3204 } |
| 3370 | 3205 |
| 3371 // This test HDMI output rediscovering case in crbug.com/503667. | 3206 // This test HDMI output rediscovering case in crbug.com/503667. |
| 3372 TEST_F(CrasAudioHandlerTest, HDMIOutputRediscover) { | 3207 TEST_P(CrasAudioHandlerTest, HDMIOutputRediscover) { |
| 3373 AudioNodeList audio_nodes; | 3208 AudioNodeList audio_nodes = |
| 3374 audio_nodes.push_back(kInternalSpeaker); | 3209 GenerateAudioNodeList({kInternalSpeaker, kHDMIOutput}); |
| 3375 audio_nodes.push_back(kHDMIOutput); | |
| 3376 SetUpCrasAudioHandler(audio_nodes); | 3210 SetUpCrasAudioHandler(audio_nodes); |
| 3377 | 3211 |
| 3378 // Verify the HDMI device has been selected as the active output, and audio | 3212 // Verify the HDMI device has been selected as the active output, and audio |
| 3379 // output is not muted. | 3213 // output is not muted. |
| 3380 AudioDevice active_output; | 3214 AudioDevice active_output; |
| 3381 EXPECT_TRUE( | 3215 EXPECT_TRUE( |
| 3382 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); | 3216 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
| 3383 EXPECT_EQ(kHDMIOutput.id, active_output.id); | 3217 EXPECT_EQ(kHDMIOutput->id, active_output.id); |
| 3384 EXPECT_EQ(kHDMIOutput.id, cras_audio_handler_->GetPrimaryActiveOutputNode()); | 3218 EXPECT_EQ(kHDMIOutput->id, cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 3385 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); | 3219 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
| 3386 EXPECT_FALSE(cras_audio_handler_->IsOutputMuted()); | 3220 EXPECT_FALSE(cras_audio_handler_->IsOutputMuted()); |
| 3387 | 3221 |
| 3388 // Trigger HDMI rediscovering grace period, and remove the HDMI node. | 3222 // Trigger HDMI rediscovering grace period, and remove the HDMI node. |
| 3389 const int grace_period_in_ms = 200; | 3223 const int grace_period_in_ms = 200; |
| 3390 SetHDMIRediscoverGracePeriodDuration(grace_period_in_ms); | 3224 SetHDMIRediscoverGracePeriodDuration(grace_period_in_ms); |
| 3391 SetActiveHDMIRediscover(); | 3225 SetActiveHDMIRediscover(); |
| 3392 AudioNodeList audio_nodes_lost_hdmi; | 3226 AudioNodeList audio_nodes_lost_hdmi = |
| 3393 audio_nodes_lost_hdmi.push_back(kInternalSpeaker); | 3227 GenerateAudioNodeList({kInternalSpeaker}); |
| 3394 ChangeAudioNodes(audio_nodes_lost_hdmi); | 3228 ChangeAudioNodes(audio_nodes_lost_hdmi); |
| 3395 | 3229 |
| 3396 // Verify the active output is switched to internal speaker, it is not muted | 3230 // Verify the active output is switched to internal speaker, it is not muted |
| 3397 // by preference, but the system output is muted during the grace period. | 3231 // by preference, but the system output is muted during the grace period. |
| 3398 EXPECT_TRUE( | 3232 EXPECT_TRUE( |
| 3399 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); | 3233 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
| 3400 EXPECT_EQ(kInternalSpeaker.id, active_output.id); | 3234 EXPECT_EQ(kInternalSpeaker->id, active_output.id); |
| 3401 EXPECT_FALSE( | 3235 EXPECT_FALSE( |
| 3402 cras_audio_handler_->IsOutputMutedForDevice(kInternalSpeaker.id)); | 3236 cras_audio_handler_->IsOutputMutedForDevice(kInternalSpeaker->id)); |
| 3403 EXPECT_TRUE(cras_audio_handler_->IsOutputMuted()); | 3237 EXPECT_TRUE(cras_audio_handler_->IsOutputMuted()); |
| 3404 | 3238 |
| 3405 // Re-attach the HDMI device after a little delay. | 3239 // Re-attach the HDMI device after a little delay. |
| 3406 HDMIRediscoverWaiter waiter(this, grace_period_in_ms); | 3240 HDMIRediscoverWaiter waiter(this, grace_period_in_ms); |
| 3407 waiter.WaitUntilTimeOut(grace_period_in_ms / 4); | 3241 waiter.WaitUntilTimeOut(grace_period_in_ms / 4); |
| 3408 ChangeAudioNodes(audio_nodes); | 3242 ChangeAudioNodes(audio_nodes); |
| 3409 | 3243 |
| 3410 // After HDMI re-discover grace period, verify HDMI output is selected as the | 3244 // After HDMI re-discover grace period, verify HDMI output is selected as the |
| 3411 // active device and not muted. | 3245 // active device and not muted. |
| 3412 waiter.WaitUntilHDMIRediscoverGracePeriodEnd(); | 3246 waiter.WaitUntilHDMIRediscoverGracePeriodEnd(); |
| 3413 EXPECT_TRUE( | 3247 EXPECT_TRUE( |
| 3414 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); | 3248 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
| 3415 EXPECT_EQ(kHDMIOutput.id, active_output.id); | 3249 EXPECT_EQ(kHDMIOutput->id, active_output.id); |
| 3416 EXPECT_EQ(kHDMIOutput.id, cras_audio_handler_->GetPrimaryActiveOutputNode()); | 3250 EXPECT_EQ(kHDMIOutput->id, cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 3417 EXPECT_FALSE(cras_audio_handler_->IsOutputMuted()); | 3251 EXPECT_FALSE(cras_audio_handler_->IsOutputMuted()); |
| 3418 } | 3252 } |
| 3419 | 3253 |
| 3420 // This tests the case of output unmuting event is notified after the hdmi | 3254 // This tests the case of output unmuting event is notified after the hdmi |
| 3421 // output re-discover grace period ends, see crbug.com/512601. | 3255 // output re-discover grace period ends, see crbug.com/512601. |
| 3422 TEST_F(CrasAudioHandlerTest, HDMIOutputUnplugDuringSuspension) { | 3256 TEST_P(CrasAudioHandlerTest, HDMIOutputUnplugDuringSuspension) { |
| 3423 AudioNodeList audio_nodes; | 3257 AudioNodeList audio_nodes = |
| 3424 audio_nodes.push_back(kInternalSpeaker); | 3258 GenerateAudioNodeList({kInternalSpeaker, kHDMIOutput}); |
| 3425 audio_nodes.push_back(kHDMIOutput); | |
| 3426 SetUpCrasAudioHandler(audio_nodes); | 3259 SetUpCrasAudioHandler(audio_nodes); |
| 3427 | 3260 |
| 3428 // Verify the HDMI device has been selected as the active output, and audio | 3261 // Verify the HDMI device has been selected as the active output, and audio |
| 3429 // output is not muted. | 3262 // output is not muted. |
| 3430 AudioDevice active_output; | 3263 AudioDevice active_output; |
| 3431 EXPECT_TRUE( | 3264 EXPECT_TRUE( |
| 3432 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); | 3265 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
| 3433 EXPECT_EQ(kHDMIOutput.id, active_output.id); | 3266 EXPECT_EQ(kHDMIOutput->id, active_output.id); |
| 3434 EXPECT_EQ(kHDMIOutput.id, cras_audio_handler_->GetPrimaryActiveOutputNode()); | 3267 EXPECT_EQ(kHDMIOutput->id, cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 3435 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); | 3268 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
| 3436 EXPECT_FALSE(cras_audio_handler_->IsOutputMuted()); | 3269 EXPECT_FALSE(cras_audio_handler_->IsOutputMuted()); |
| 3437 | 3270 |
| 3438 // Trigger HDMI rediscovering grace period, and remove the HDMI node. | 3271 // Trigger HDMI rediscovering grace period, and remove the HDMI node. |
| 3439 const int grace_period_in_ms = 200; | 3272 const int grace_period_in_ms = 200; |
| 3440 SetHDMIRediscoverGracePeriodDuration(grace_period_in_ms); | 3273 SetHDMIRediscoverGracePeriodDuration(grace_period_in_ms); |
| 3441 SetActiveHDMIRediscover(); | 3274 SetActiveHDMIRediscover(); |
| 3442 AudioNodeList audio_nodes_lost_hdmi; | 3275 AudioNodeList audio_nodes_lost_hdmi = |
| 3443 audio_nodes_lost_hdmi.push_back(kInternalSpeaker); | 3276 GenerateAudioNodeList({kInternalSpeaker}); |
| 3444 ChangeAudioNodes(audio_nodes_lost_hdmi); | 3277 ChangeAudioNodes(audio_nodes_lost_hdmi); |
| 3445 | 3278 |
| 3446 // Verify the active output is switched to internal speaker, it is not muted | 3279 // Verify the active output is switched to internal speaker, it is not muted |
| 3447 // by preference, but the system output is muted during the grace period. | 3280 // by preference, but the system output is muted during the grace period. |
| 3448 EXPECT_TRUE( | 3281 EXPECT_TRUE( |
| 3449 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); | 3282 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
| 3450 EXPECT_EQ(kInternalSpeaker.id, active_output.id); | 3283 EXPECT_EQ(kInternalSpeaker->id, active_output.id); |
| 3451 EXPECT_FALSE( | 3284 EXPECT_FALSE( |
| 3452 cras_audio_handler_->IsOutputMutedForDevice(kInternalSpeaker.id)); | 3285 cras_audio_handler_->IsOutputMutedForDevice(kInternalSpeaker->id)); |
| 3453 EXPECT_TRUE(cras_audio_handler_->IsOutputMuted()); | 3286 EXPECT_TRUE(cras_audio_handler_->IsOutputMuted()); |
| 3454 | 3287 |
| 3455 // After HDMI re-discover grace period, verify internal speaker is still the | 3288 // After HDMI re-discover grace period, verify internal speaker is still the |
| 3456 // active output and not muted, and unmute event by system is notified. | 3289 // active output and not muted, and unmute event by system is notified. |
| 3457 test_observer_->reset_output_mute_changed_count(); | 3290 test_observer_->reset_output_mute_changed_count(); |
| 3458 HDMIRediscoverWaiter waiter(this, grace_period_in_ms); | 3291 HDMIRediscoverWaiter waiter(this, grace_period_in_ms); |
| 3459 waiter.WaitUntilHDMIRediscoverGracePeriodEnd(); | 3292 waiter.WaitUntilHDMIRediscoverGracePeriodEnd(); |
| 3460 EXPECT_TRUE( | 3293 EXPECT_TRUE( |
| 3461 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); | 3294 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
| 3462 EXPECT_EQ(kInternalSpeaker.id, active_output.id); | 3295 EXPECT_EQ(kInternalSpeaker->id, active_output.id); |
| 3463 EXPECT_EQ(kInternalSpeaker.id, | 3296 EXPECT_EQ(kInternalSpeaker->id, |
| 3464 cras_audio_handler_->GetPrimaryActiveOutputNode()); | 3297 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 3465 EXPECT_FALSE(cras_audio_handler_->IsOutputMuted()); | 3298 EXPECT_FALSE(cras_audio_handler_->IsOutputMuted()); |
| 3466 EXPECT_EQ(1, test_observer_->output_mute_changed_count()); | 3299 EXPECT_EQ(1, test_observer_->output_mute_changed_count()); |
| 3467 EXPECT_TRUE(test_observer_->output_mute_by_system()); | 3300 EXPECT_TRUE(test_observer_->output_mute_by_system()); |
| 3468 } | 3301 } |
| 3469 | 3302 |
| 3470 } // namespace chromeos | 3303 } // namespace chromeos |
| OLD | NEW |