OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chromeos/audio/cras_audio_handler.h" | 5 #include "chromeos/audio/cras_audio_handler.h" |
6 | 6 |
7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 DBusThreadManager::Get()->GetCrasAudioClient()); | 257 DBusThreadManager::Get()->GetCrasAudioClient()); |
258 cras_audio_client_stub_->SetAudioNodesForTesting(audio_nodes); | 258 cras_audio_client_stub_->SetAudioNodesForTesting(audio_nodes); |
259 audio_pref_handler_ = new AudioDevicesPrefHandlerStub(); | 259 audio_pref_handler_ = new AudioDevicesPrefHandlerStub(); |
260 CrasAudioHandler::Initialize(audio_pref_handler_); | 260 CrasAudioHandler::Initialize(audio_pref_handler_); |
261 cras_audio_handler_ = CrasAudioHandler::Get(); | 261 cras_audio_handler_ = CrasAudioHandler::Get(); |
262 test_observer_.reset(new TestObserver); | 262 test_observer_.reset(new TestObserver); |
263 cras_audio_handler_->AddAudioObserver(test_observer_.get()); | 263 cras_audio_handler_->AddAudioObserver(test_observer_.get()); |
264 message_loop_.RunUntilIdle(); | 264 message_loop_.RunUntilIdle(); |
265 } | 265 } |
266 | 266 |
| 267 void SetUpCrasAudioHandlerWithPrimaryActiveNode( |
| 268 const AudioNodeList& audio_nodes, |
| 269 const AudioNode& primary_active_node) { |
| 270 DBusThreadManager::Initialize(); |
| 271 cras_audio_client_stub_ = static_cast<CrasAudioClientStubImpl*>( |
| 272 DBusThreadManager::Get()->GetCrasAudioClient()); |
| 273 cras_audio_client_stub_->SetAudioNodesForTesting(audio_nodes); |
| 274 cras_audio_client_stub_->SetActiveOutputNode(primary_active_node.id), |
| 275 audio_pref_handler_ = new AudioDevicesPrefHandlerStub(); |
| 276 CrasAudioHandler::Initialize(audio_pref_handler_); |
| 277 cras_audio_handler_ = CrasAudioHandler::Get(); |
| 278 test_observer_.reset(new TestObserver); |
| 279 cras_audio_handler_->AddAudioObserver(test_observer_.get()); |
| 280 message_loop_.RunUntilIdle(); |
| 281 } |
| 282 |
267 void ChangeAudioNodes(const AudioNodeList& audio_nodes) { | 283 void ChangeAudioNodes(const AudioNodeList& audio_nodes) { |
268 cras_audio_client_stub_->SetAudioNodesAndNotifyObserversForTesting( | 284 cras_audio_client_stub_->SetAudioNodesAndNotifyObserversForTesting( |
269 audio_nodes); | 285 audio_nodes); |
270 message_loop_.RunUntilIdle(); | 286 message_loop_.RunUntilIdle(); |
271 } | 287 } |
272 | 288 |
| 289 const AudioDevice* GetDeviceFromId(uint64 id) { |
| 290 return cras_audio_handler_->GetDeviceFromId(id); |
| 291 } |
| 292 |
273 protected: | 293 protected: |
274 base::MessageLoopForUI message_loop_; | 294 base::MessageLoopForUI message_loop_; |
275 CrasAudioHandler* cras_audio_handler_; // Not owned. | 295 CrasAudioHandler* cras_audio_handler_; // Not owned. |
276 CrasAudioClientStubImpl* cras_audio_client_stub_; // Not owned. | 296 CrasAudioClientStubImpl* cras_audio_client_stub_; // Not owned. |
277 scoped_ptr<TestObserver> test_observer_; | 297 scoped_ptr<TestObserver> test_observer_; |
278 scoped_refptr<AudioDevicesPrefHandlerStub> audio_pref_handler_; | 298 scoped_refptr<AudioDevicesPrefHandlerStub> audio_pref_handler_; |
279 | 299 |
280 private: | 300 private: |
281 DISALLOW_COPY_AND_ASSIGN(CrasAudioHandlerTest); | 301 DISALLOW_COPY_AND_ASSIGN(CrasAudioHandlerTest); |
282 }; | 302 }; |
283 | 303 |
284 TEST_F(CrasAudioHandlerTest, InitializeWithOnlyDefaultAudioDevices) { | 304 TEST_F(CrasAudioHandlerTest, InitializeWithOnlyDefaultAudioDevices) { |
285 AudioNodeList audio_nodes; | 305 AudioNodeList audio_nodes; |
286 audio_nodes.push_back(kInternalSpeaker); | 306 audio_nodes.push_back(kInternalSpeaker); |
287 audio_nodes.push_back(kInternalMic); | 307 audio_nodes.push_back(kInternalMic); |
288 SetUpCrasAudioHandler(audio_nodes); | 308 SetUpCrasAudioHandler(audio_nodes); |
289 | 309 |
290 // Verify the audio devices size. | 310 // Verify the audio devices size. |
291 AudioDeviceList audio_devices; | 311 AudioDeviceList audio_devices; |
292 cras_audio_handler_->GetAudioDevices(&audio_devices); | 312 cras_audio_handler_->GetAudioDevices(&audio_devices); |
293 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); | 313 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); |
294 | 314 |
295 // Verify the internal speaker has been selected as the active output. | 315 // Verify the internal speaker has been selected as the active output. |
296 AudioDevice active_output; | 316 AudioDevice active_output; |
297 EXPECT_TRUE(cras_audio_handler_->GetActiveOutputDevice(&active_output)); | 317 EXPECT_TRUE( |
| 318 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
298 EXPECT_EQ(kInternalSpeaker.id, active_output.id); | 319 EXPECT_EQ(kInternalSpeaker.id, active_output.id); |
299 EXPECT_EQ(kInternalSpeaker.id, cras_audio_handler_->GetActiveOutputNode()); | 320 EXPECT_EQ(kInternalSpeaker.id, |
| 321 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
300 EXPECT_FALSE(cras_audio_handler_->has_alternative_output()); | 322 EXPECT_FALSE(cras_audio_handler_->has_alternative_output()); |
301 | 323 |
302 // Ensure the internal microphone has been selected as the active input. | 324 // Ensure the internal microphone has been selected as the active input. |
303 AudioDevice active_input; | 325 AudioDevice active_input; |
304 EXPECT_EQ(kInternalMic.id, cras_audio_handler_->GetActiveInputNode()); | 326 EXPECT_EQ(kInternalMic.id, cras_audio_handler_->GetPrimaryActiveInputNode()); |
305 EXPECT_FALSE(cras_audio_handler_->has_alternative_input()); | 327 EXPECT_FALSE(cras_audio_handler_->has_alternative_input()); |
306 } | 328 } |
307 | 329 |
308 TEST_F(CrasAudioHandlerTest, InitializeWithAlternativeAudioDevices) { | 330 TEST_F(CrasAudioHandlerTest, InitializeWithAlternativeAudioDevices) { |
309 AudioNodeList audio_nodes; | 331 AudioNodeList audio_nodes; |
310 audio_nodes.push_back(kInternalSpeaker); | 332 audio_nodes.push_back(kInternalSpeaker); |
311 audio_nodes.push_back(kHeadphone); | 333 audio_nodes.push_back(kHeadphone); |
312 audio_nodes.push_back(kInternalMic); | 334 audio_nodes.push_back(kInternalMic); |
313 audio_nodes.push_back(kUSBMic); | 335 audio_nodes.push_back(kUSBMic); |
314 SetUpCrasAudioHandler(audio_nodes); | 336 SetUpCrasAudioHandler(audio_nodes); |
315 | 337 |
316 // Verify the audio devices size. | 338 // Verify the audio devices size. |
317 AudioDeviceList audio_devices; | 339 AudioDeviceList audio_devices; |
318 cras_audio_handler_->GetAudioDevices(&audio_devices); | 340 cras_audio_handler_->GetAudioDevices(&audio_devices); |
319 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); | 341 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); |
320 | 342 |
321 // Verify the headphone has been selected as the active output. | 343 // Verify the headphone has been selected as the active output. |
322 AudioDevice active_output; | 344 AudioDevice active_output; |
323 EXPECT_TRUE(cras_audio_handler_->GetActiveOutputDevice(&active_output)); | 345 EXPECT_TRUE( |
| 346 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
324 EXPECT_EQ(kHeadphone.id, active_output.id); | 347 EXPECT_EQ(kHeadphone.id, active_output.id); |
325 EXPECT_EQ(kHeadphone.id, cras_audio_handler_->GetActiveOutputNode()); | 348 EXPECT_EQ(kHeadphone.id, cras_audio_handler_->GetPrimaryActiveOutputNode()); |
326 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); | 349 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
327 | 350 |
328 // Ensure the USB microphone has been selected as the active input. | 351 // Ensure the USB microphone has been selected as the active input. |
329 AudioDevice active_input; | 352 AudioDevice active_input; |
330 EXPECT_EQ(kUSBMicId, cras_audio_handler_->GetActiveInputNode()); | 353 EXPECT_EQ(kUSBMicId, cras_audio_handler_->GetPrimaryActiveInputNode()); |
331 EXPECT_TRUE(cras_audio_handler_->has_alternative_input()); | 354 EXPECT_TRUE(cras_audio_handler_->has_alternative_input()); |
332 } | 355 } |
333 | 356 |
334 TEST_F(CrasAudioHandlerTest, InitializeWithKeyboardMic) { | 357 TEST_F(CrasAudioHandlerTest, InitializeWithKeyboardMic) { |
335 AudioNodeList audio_nodes; | 358 AudioNodeList audio_nodes; |
336 audio_nodes.push_back(kInternalSpeaker); | 359 audio_nodes.push_back(kInternalSpeaker); |
337 audio_nodes.push_back(kInternalMic); | 360 audio_nodes.push_back(kInternalMic); |
338 audio_nodes.push_back(kKeyboardMic); | 361 audio_nodes.push_back(kKeyboardMic); |
339 SetUpCrasAudioHandler(audio_nodes); | 362 SetUpCrasAudioHandler(audio_nodes); |
340 | 363 |
341 // Verify the audio devices size. | 364 // Verify the audio devices size. |
342 AudioDeviceList audio_devices; | 365 AudioDeviceList audio_devices; |
343 cras_audio_handler_->GetAudioDevices(&audio_devices); | 366 cras_audio_handler_->GetAudioDevices(&audio_devices); |
344 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); | 367 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); |
| 368 EXPECT_TRUE(cras_audio_handler_->HasKeyboardMic()); |
345 | 369 |
346 // Verify the internal speaker has been selected as the active output. | 370 // Verify the internal speaker has been selected as the active output. |
347 AudioDevice active_output; | 371 AudioDevice active_output; |
348 EXPECT_TRUE(cras_audio_handler_->GetActiveOutputDevice(&active_output)); | 372 EXPECT_TRUE( |
| 373 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
349 EXPECT_EQ(kInternalSpeaker.id, active_output.id); | 374 EXPECT_EQ(kInternalSpeaker.id, active_output.id); |
350 EXPECT_EQ(kInternalSpeaker.id, cras_audio_handler_->GetActiveOutputNode()); | 375 EXPECT_EQ(kInternalSpeaker.id, |
| 376 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
351 EXPECT_FALSE(cras_audio_handler_->has_alternative_output()); | 377 EXPECT_FALSE(cras_audio_handler_->has_alternative_output()); |
352 | 378 |
353 // Ensure the internal microphone has been selected as the active input, | 379 // Ensure the internal microphone has been selected as the active input, |
354 // not affected by keyboard mic. | 380 // not affected by keyboard mic. |
355 AudioDevice active_input; | 381 AudioDevice active_input; |
356 EXPECT_EQ(kInternalMic.id, cras_audio_handler_->GetActiveInputNode()); | 382 EXPECT_EQ(kInternalMic.id, cras_audio_handler_->GetPrimaryActiveInputNode()); |
357 EXPECT_FALSE(cras_audio_handler_->has_alternative_input()); | 383 EXPECT_FALSE(cras_audio_handler_->has_alternative_input()); |
| 384 const AudioDevice* keyboard_mic = GetDeviceFromId(kKeyboardMic.id); |
| 385 EXPECT_FALSE(keyboard_mic->active); |
| 386 } |
| 387 |
| 388 TEST_F(CrasAudioHandlerTest, SetKeyboardMicActive) { |
| 389 AudioNodeList audio_nodes; |
| 390 audio_nodes.push_back(kInternalMic); |
| 391 audio_nodes.push_back(kKeyboardMic); |
| 392 SetUpCrasAudioHandler(audio_nodes); |
| 393 |
| 394 // Verify the audio devices size. |
| 395 AudioDeviceList audio_devices; |
| 396 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 397 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); |
| 398 EXPECT_TRUE(cras_audio_handler_->HasKeyboardMic()); |
| 399 |
| 400 // Ensure the internal microphone has been selected as the active input, |
| 401 // not affected by keyboard mic. |
| 402 AudioDevice active_input; |
| 403 EXPECT_EQ(kInternalMic.id, cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 404 EXPECT_FALSE(cras_audio_handler_->has_alternative_input()); |
| 405 const AudioDevice* keyboard_mic = GetDeviceFromId(kKeyboardMic.id); |
| 406 EXPECT_FALSE(keyboard_mic->active); |
| 407 |
| 408 // Make keyboard mic active. |
| 409 cras_audio_handler_->SetKeyboardMicActive(true); |
| 410 EXPECT_EQ(kInternalMic.id, cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 411 const AudioDevice* active_keyboard_mic = GetDeviceFromId(kKeyboardMic.id); |
| 412 EXPECT_TRUE(active_keyboard_mic->active); |
| 413 |
| 414 // Make keyboard mic inactive. |
| 415 cras_audio_handler_->SetKeyboardMicActive(false); |
| 416 EXPECT_EQ(kInternalMic.id, cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 417 const AudioDevice* inactive_keyboard_mic = GetDeviceFromId(kKeyboardMic.id); |
| 418 EXPECT_FALSE(inactive_keyboard_mic->active); |
358 } | 419 } |
359 | 420 |
360 TEST_F(CrasAudioHandlerTest, SwitchActiveOutputDevice) { | 421 TEST_F(CrasAudioHandlerTest, SwitchActiveOutputDevice) { |
361 AudioNodeList audio_nodes; | 422 AudioNodeList audio_nodes; |
362 audio_nodes.push_back(kInternalSpeaker); | 423 audio_nodes.push_back(kInternalSpeaker); |
363 audio_nodes.push_back(kHeadphone); | 424 audio_nodes.push_back(kHeadphone); |
364 SetUpCrasAudioHandler(audio_nodes); | 425 SetUpCrasAudioHandler(audio_nodes); |
365 AudioDeviceList audio_devices; | 426 AudioDeviceList audio_devices; |
366 cras_audio_handler_->GetAudioDevices(&audio_devices); | 427 cras_audio_handler_->GetAudioDevices(&audio_devices); |
367 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); | 428 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); |
368 | 429 |
369 // Verify the initial active output device is headphone. | 430 // Verify the initial active output device is headphone. |
370 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); | 431 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); |
371 AudioDevice active_output; | 432 AudioDevice active_output; |
372 EXPECT_TRUE(cras_audio_handler_->GetActiveOutputDevice(&active_output)); | 433 EXPECT_TRUE( |
| 434 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
373 EXPECT_EQ(kHeadphone.id, active_output.id); | 435 EXPECT_EQ(kHeadphone.id, active_output.id); |
374 EXPECT_EQ(kHeadphone.id, cras_audio_handler_->GetActiveOutputNode()); | 436 EXPECT_EQ(kHeadphone.id, cras_audio_handler_->GetPrimaryActiveOutputNode()); |
375 | 437 |
376 // Switch the active output to internal speaker. | 438 // Switch the active output to internal speaker. |
377 AudioDevice internal_speaker(kInternalSpeaker); | 439 AudioDevice internal_speaker(kInternalSpeaker); |
378 cras_audio_handler_->SwitchToDevice(internal_speaker); | 440 cras_audio_handler_->SwitchToDevice(internal_speaker); |
379 | 441 |
380 // Verify the active output is switched to internal speaker, and the | 442 // Verify the active output is switched to internal speaker, and the |
381 // ActiveOutputNodeChanged event is fired. | 443 // ActiveOutputNodeChanged event is fired. |
382 EXPECT_EQ(1, test_observer_->active_output_node_changed_count()); | 444 EXPECT_EQ(1, test_observer_->active_output_node_changed_count()); |
383 EXPECT_TRUE(cras_audio_handler_->GetActiveOutputDevice(&active_output)); | 445 EXPECT_TRUE( |
| 446 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
384 EXPECT_EQ(kInternalSpeaker.id, active_output.id); | 447 EXPECT_EQ(kInternalSpeaker.id, active_output.id); |
385 EXPECT_EQ(kInternalSpeaker.id, cras_audio_handler_->GetActiveOutputNode()); | 448 EXPECT_EQ(kInternalSpeaker.id, |
| 449 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
386 } | 450 } |
387 | 451 |
388 TEST_F(CrasAudioHandlerTest, SwitchActiveInputDevice) { | 452 TEST_F(CrasAudioHandlerTest, SwitchActiveInputDevice) { |
389 AudioNodeList audio_nodes; | 453 AudioNodeList audio_nodes; |
390 audio_nodes.push_back(kInternalMic); | 454 audio_nodes.push_back(kInternalMic); |
391 audio_nodes.push_back(kUSBMic); | 455 audio_nodes.push_back(kUSBMic); |
392 SetUpCrasAudioHandler(audio_nodes); | 456 SetUpCrasAudioHandler(audio_nodes); |
393 AudioDeviceList audio_devices; | 457 AudioDeviceList audio_devices; |
394 cras_audio_handler_->GetAudioDevices(&audio_devices); | 458 cras_audio_handler_->GetAudioDevices(&audio_devices); |
395 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); | 459 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); |
396 | 460 |
397 // Verify the initial active input device is USB mic. | 461 // Verify the initial active input device is USB mic. |
398 EXPECT_EQ(0, test_observer_->active_input_node_changed_count()); | 462 EXPECT_EQ(0, test_observer_->active_input_node_changed_count()); |
399 EXPECT_EQ(kUSBMicId, cras_audio_handler_->GetActiveInputNode()); | 463 EXPECT_EQ(kUSBMicId, cras_audio_handler_->GetPrimaryActiveInputNode()); |
400 | 464 |
401 // Switch the active input to internal mic. | 465 // Switch the active input to internal mic. |
402 AudioDevice internal_mic(kInternalMic); | 466 AudioDevice internal_mic(kInternalMic); |
403 cras_audio_handler_->SwitchToDevice(internal_mic); | 467 cras_audio_handler_->SwitchToDevice(internal_mic); |
404 | 468 |
405 // Verify the active output is switched to internal speaker, and the active | 469 // Verify the active output is switched to internal speaker, and the active |
406 // ActiveInputNodeChanged event is fired. | 470 // ActiveInputNodeChanged event is fired. |
407 EXPECT_EQ(1, test_observer_->active_input_node_changed_count()); | 471 EXPECT_EQ(1, test_observer_->active_input_node_changed_count()); |
408 EXPECT_EQ(kInternalMic.id, cras_audio_handler_->GetActiveInputNode()); | 472 EXPECT_EQ(kInternalMic.id, cras_audio_handler_->GetPrimaryActiveInputNode()); |
409 } | 473 } |
410 | 474 |
411 TEST_F(CrasAudioHandlerTest, PlugHeadphone) { | 475 TEST_F(CrasAudioHandlerTest, PlugHeadphone) { |
412 // Set up initial audio devices, only with internal speaker. | 476 // Set up initial audio devices, only with internal speaker. |
413 AudioNodeList audio_nodes; | 477 AudioNodeList audio_nodes; |
414 audio_nodes.push_back(kInternalSpeaker); | 478 audio_nodes.push_back(kInternalSpeaker); |
415 SetUpCrasAudioHandler(audio_nodes); | 479 SetUpCrasAudioHandler(audio_nodes); |
416 const size_t init_nodes_size = audio_nodes.size(); | 480 const size_t init_nodes_size = audio_nodes.size(); |
417 | 481 |
418 // Verify the audio devices size. | 482 // Verify the audio devices size. |
419 AudioDeviceList audio_devices; | 483 AudioDeviceList audio_devices; |
420 cras_audio_handler_->GetAudioDevices(&audio_devices); | 484 cras_audio_handler_->GetAudioDevices(&audio_devices); |
421 EXPECT_EQ(init_nodes_size, audio_devices.size()); | 485 EXPECT_EQ(init_nodes_size, audio_devices.size()); |
422 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); | 486 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); |
423 | 487 |
424 // Verify the internal speaker has been selected as the active output. | 488 // Verify the internal speaker has been selected as the active output. |
425 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); | 489 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); |
426 AudioDevice active_output; | 490 AudioDevice active_output; |
427 EXPECT_TRUE(cras_audio_handler_->GetActiveOutputDevice(&active_output)); | 491 EXPECT_TRUE( |
| 492 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
428 EXPECT_EQ(kInternalSpeaker.id, active_output.id); | 493 EXPECT_EQ(kInternalSpeaker.id, active_output.id); |
429 EXPECT_EQ(kInternalSpeaker.id, cras_audio_handler_->GetActiveOutputNode()); | 494 EXPECT_EQ(kInternalSpeaker.id, |
| 495 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
430 EXPECT_FALSE(cras_audio_handler_->has_alternative_output()); | 496 EXPECT_FALSE(cras_audio_handler_->has_alternative_output()); |
431 | 497 |
432 // Plug the headphone. | 498 // Plug the headphone. |
433 audio_nodes.clear(); | 499 audio_nodes.clear(); |
434 AudioNode internal_speaker(kInternalSpeaker); | 500 AudioNode internal_speaker(kInternalSpeaker); |
435 internal_speaker.active = true; | 501 internal_speaker.active = true; |
436 audio_nodes.push_back(internal_speaker); | 502 audio_nodes.push_back(internal_speaker); |
437 audio_nodes.push_back(kHeadphone); | 503 audio_nodes.push_back(kHeadphone); |
438 ChangeAudioNodes(audio_nodes); | 504 ChangeAudioNodes(audio_nodes); |
439 | 505 |
440 // Verify the AudioNodesChanged event is fired and new audio device is added. | 506 // Verify the AudioNodesChanged event is fired and new audio device is added. |
441 EXPECT_EQ(1, test_observer_->audio_nodes_changed_count()); | 507 EXPECT_EQ(1, test_observer_->audio_nodes_changed_count()); |
442 cras_audio_handler_->GetAudioDevices(&audio_devices); | 508 cras_audio_handler_->GetAudioDevices(&audio_devices); |
443 EXPECT_EQ(init_nodes_size + 1, audio_devices.size()); | 509 EXPECT_EQ(init_nodes_size + 1, audio_devices.size()); |
444 | 510 |
445 // Verify the active output device is switched to headphone and | 511 // Verify the active output device is switched to headphone and |
446 // ActiveOutputChanged event is fired. | 512 // ActiveOutputChanged event is fired. |
447 EXPECT_EQ(1, test_observer_->active_output_node_changed_count()); | 513 EXPECT_EQ(1, test_observer_->active_output_node_changed_count()); |
448 EXPECT_TRUE(cras_audio_handler_->GetActiveOutputDevice(&active_output)); | 514 EXPECT_TRUE( |
| 515 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
449 EXPECT_EQ(kHeadphone.id, active_output.id); | 516 EXPECT_EQ(kHeadphone.id, active_output.id); |
450 EXPECT_EQ(kHeadphone.id, cras_audio_handler_->GetActiveOutputNode()); | 517 EXPECT_EQ(kHeadphone.id, cras_audio_handler_->GetPrimaryActiveOutputNode()); |
451 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); | 518 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
452 } | 519 } |
453 | 520 |
454 TEST_F(CrasAudioHandlerTest, UnplugHeadphone) { | 521 TEST_F(CrasAudioHandlerTest, UnplugHeadphone) { |
455 // Set up initial audio devices, with internal speaker and headphone. | 522 // Set up initial audio devices, with internal speaker and headphone. |
456 AudioNodeList audio_nodes; | 523 AudioNodeList audio_nodes; |
457 audio_nodes.push_back(kInternalSpeaker); | 524 audio_nodes.push_back(kInternalSpeaker); |
458 audio_nodes.push_back(kHeadphone); | 525 audio_nodes.push_back(kHeadphone); |
459 SetUpCrasAudioHandler(audio_nodes); | 526 SetUpCrasAudioHandler(audio_nodes); |
460 const size_t init_nodes_size = audio_nodes.size(); | 527 const size_t init_nodes_size = audio_nodes.size(); |
461 | 528 |
462 // Verify the audio devices size. | 529 // Verify the audio devices size. |
463 AudioDeviceList audio_devices; | 530 AudioDeviceList audio_devices; |
464 cras_audio_handler_->GetAudioDevices(&audio_devices); | 531 cras_audio_handler_->GetAudioDevices(&audio_devices); |
465 EXPECT_EQ(init_nodes_size, audio_devices.size()); | 532 EXPECT_EQ(init_nodes_size, audio_devices.size()); |
466 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); | 533 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); |
467 | 534 |
468 // Verify the headphone has been selected as the active output. | 535 // Verify the headphone has been selected as the active output. |
469 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); | 536 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); |
470 AudioDevice active_output; | 537 AudioDevice active_output; |
471 EXPECT_TRUE(cras_audio_handler_->GetActiveOutputDevice(&active_output)); | 538 EXPECT_TRUE( |
| 539 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
472 EXPECT_EQ(kHeadphone.id, active_output.id); | 540 EXPECT_EQ(kHeadphone.id, active_output.id); |
473 EXPECT_EQ(kHeadphone.id, cras_audio_handler_->GetActiveOutputNode()); | 541 EXPECT_EQ(kHeadphone.id, cras_audio_handler_->GetPrimaryActiveOutputNode()); |
474 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); | 542 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
475 | 543 |
476 // Unplug the headphone. | 544 // Unplug the headphone. |
477 audio_nodes.clear(); | 545 audio_nodes.clear(); |
478 audio_nodes.push_back(kInternalSpeaker); | 546 audio_nodes.push_back(kInternalSpeaker); |
479 ChangeAudioNodes(audio_nodes); | 547 ChangeAudioNodes(audio_nodes); |
480 | 548 |
481 // Verify the AudioNodesChanged event is fired and one audio device is | 549 // Verify the AudioNodesChanged event is fired and one audio device is |
482 // removed. | 550 // removed. |
483 EXPECT_EQ(1, test_observer_->audio_nodes_changed_count()); | 551 EXPECT_EQ(1, test_observer_->audio_nodes_changed_count()); |
484 cras_audio_handler_->GetAudioDevices(&audio_devices); | 552 cras_audio_handler_->GetAudioDevices(&audio_devices); |
485 EXPECT_EQ(init_nodes_size - 1, audio_devices.size()); | 553 EXPECT_EQ(init_nodes_size - 1, audio_devices.size()); |
486 | 554 |
487 // Verify the active output device is switched to internal speaker and | 555 // Verify the active output device is switched to internal speaker and |
488 // ActiveOutputChanged event is fired. | 556 // ActiveOutputChanged event is fired. |
489 EXPECT_EQ(1, test_observer_->active_output_node_changed_count()); | 557 EXPECT_EQ(1, test_observer_->active_output_node_changed_count()); |
490 EXPECT_TRUE(cras_audio_handler_->GetActiveOutputDevice(&active_output)); | 558 EXPECT_TRUE( |
| 559 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
491 EXPECT_EQ(kInternalSpeaker.id, active_output.id); | 560 EXPECT_EQ(kInternalSpeaker.id, active_output.id); |
492 EXPECT_EQ(kInternalSpeaker.id, cras_audio_handler_->GetActiveOutputNode()); | 561 EXPECT_EQ(kInternalSpeaker.id, |
| 562 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
493 EXPECT_FALSE(cras_audio_handler_->has_alternative_output()); | 563 EXPECT_FALSE(cras_audio_handler_->has_alternative_output()); |
494 } | 564 } |
495 | 565 |
496 TEST_F(CrasAudioHandlerTest, InitializeWithBluetoothHeadset) { | 566 TEST_F(CrasAudioHandlerTest, InitializeWithBluetoothHeadset) { |
497 AudioNodeList audio_nodes; | 567 AudioNodeList audio_nodes; |
498 audio_nodes.push_back(kInternalSpeaker); | 568 audio_nodes.push_back(kInternalSpeaker); |
499 audio_nodes.push_back(kBluetoothHeadset); | 569 audio_nodes.push_back(kBluetoothHeadset); |
500 SetUpCrasAudioHandler(audio_nodes); | 570 SetUpCrasAudioHandler(audio_nodes); |
501 | 571 |
502 // Verify the audio devices size. | 572 // Verify the audio devices size. |
503 AudioDeviceList audio_devices; | 573 AudioDeviceList audio_devices; |
504 cras_audio_handler_->GetAudioDevices(&audio_devices); | 574 cras_audio_handler_->GetAudioDevices(&audio_devices); |
505 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); | 575 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); |
506 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); | 576 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); |
507 | 577 |
508 // Verify the bluetooth headset has been selected as the active output. | 578 // Verify the bluetooth headset has been selected as the active output. |
509 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); | 579 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); |
510 AudioDevice active_output; | 580 AudioDevice active_output; |
511 EXPECT_TRUE(cras_audio_handler_->GetActiveOutputDevice(&active_output)); | 581 EXPECT_TRUE( |
| 582 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
512 EXPECT_EQ(kBluetoothHeadset.id, active_output.id); | 583 EXPECT_EQ(kBluetoothHeadset.id, active_output.id); |
513 EXPECT_EQ(kBluetoothHeadset.id, cras_audio_handler_->GetActiveOutputNode()); | 584 EXPECT_EQ(kBluetoothHeadset.id, |
| 585 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
514 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); | 586 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
515 } | 587 } |
516 | 588 |
517 TEST_F(CrasAudioHandlerTest, ConnectAndDisconnectBluetoothHeadset) { | 589 TEST_F(CrasAudioHandlerTest, ConnectAndDisconnectBluetoothHeadset) { |
518 // Initialize with internal speaker and headphone. | 590 // Initialize with internal speaker and headphone. |
519 AudioNodeList audio_nodes; | 591 AudioNodeList audio_nodes; |
520 audio_nodes.push_back(kInternalSpeaker); | 592 audio_nodes.push_back(kInternalSpeaker); |
521 audio_nodes.push_back(kHeadphone); | 593 audio_nodes.push_back(kHeadphone); |
522 SetUpCrasAudioHandler(audio_nodes); | 594 SetUpCrasAudioHandler(audio_nodes); |
523 const size_t init_nodes_size = audio_nodes.size(); | 595 const size_t init_nodes_size = audio_nodes.size(); |
524 | 596 |
525 // Verify the audio devices size. | 597 // Verify the audio devices size. |
526 AudioDeviceList audio_devices; | 598 AudioDeviceList audio_devices; |
527 cras_audio_handler_->GetAudioDevices(&audio_devices); | 599 cras_audio_handler_->GetAudioDevices(&audio_devices); |
528 EXPECT_EQ(init_nodes_size, audio_devices.size()); | 600 EXPECT_EQ(init_nodes_size, audio_devices.size()); |
529 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); | 601 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); |
530 | 602 |
531 // Verify the headphone is selected as the active output initially. | 603 // Verify the headphone is selected as the active output initially. |
532 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); | 604 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); |
533 AudioDevice active_output; | 605 AudioDevice active_output; |
534 EXPECT_TRUE(cras_audio_handler_->GetActiveOutputDevice(&active_output)); | 606 EXPECT_TRUE( |
| 607 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
535 EXPECT_EQ(kHeadphone.id, active_output.id); | 608 EXPECT_EQ(kHeadphone.id, active_output.id); |
536 EXPECT_EQ(kHeadphone.id, cras_audio_handler_->GetActiveOutputNode()); | 609 EXPECT_EQ(kHeadphone.id, cras_audio_handler_->GetPrimaryActiveOutputNode()); |
537 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); | 610 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
538 | 611 |
539 // Connect to bluetooth headset. Since it is plugged in later than | 612 // Connect to bluetooth headset. Since it is plugged in later than |
540 // headphone, active output should be switched to it. | 613 // headphone, active output should be switched to it. |
541 audio_nodes.clear(); | 614 audio_nodes.clear(); |
542 audio_nodes.push_back(kInternalSpeaker); | 615 audio_nodes.push_back(kInternalSpeaker); |
543 AudioNode headphone(kHeadphone); | 616 AudioNode headphone(kHeadphone); |
544 headphone.plugged_time = 80000000; | 617 headphone.plugged_time = 80000000; |
545 headphone.active = true; | 618 headphone.active = true; |
546 audio_nodes.push_back(headphone); | 619 audio_nodes.push_back(headphone); |
547 AudioNode bluetooth_headset(kBluetoothHeadset); | 620 AudioNode bluetooth_headset(kBluetoothHeadset); |
548 bluetooth_headset.plugged_time = 90000000; | 621 bluetooth_headset.plugged_time = 90000000; |
549 audio_nodes.push_back(bluetooth_headset); | 622 audio_nodes.push_back(bluetooth_headset); |
550 ChangeAudioNodes(audio_nodes); | 623 ChangeAudioNodes(audio_nodes); |
551 | 624 |
552 // Verify the AudioNodesChanged event is fired and new audio device is added. | 625 // Verify the AudioNodesChanged event is fired and new audio device is added. |
553 EXPECT_EQ(1, test_observer_->audio_nodes_changed_count()); | 626 EXPECT_EQ(1, test_observer_->audio_nodes_changed_count()); |
554 cras_audio_handler_->GetAudioDevices(&audio_devices); | 627 cras_audio_handler_->GetAudioDevices(&audio_devices); |
555 EXPECT_EQ(init_nodes_size + 1, audio_devices.size()); | 628 EXPECT_EQ(init_nodes_size + 1, audio_devices.size()); |
556 | 629 |
557 // Verify the active output device is switched to bluetooth headset, and | 630 // Verify the active output device is switched to bluetooth headset, and |
558 // ActiveOutputChanged event is fired. | 631 // ActiveOutputChanged event is fired. |
559 EXPECT_EQ(1, test_observer_->active_output_node_changed_count()); | 632 EXPECT_EQ(1, test_observer_->active_output_node_changed_count()); |
560 EXPECT_TRUE(cras_audio_handler_->GetActiveOutputDevice(&active_output)); | 633 EXPECT_TRUE( |
| 634 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
561 EXPECT_EQ(kBluetoothHeadset.id, active_output.id); | 635 EXPECT_EQ(kBluetoothHeadset.id, active_output.id); |
562 EXPECT_EQ(kBluetoothHeadset.id, cras_audio_handler_->GetActiveOutputNode()); | 636 EXPECT_EQ(kBluetoothHeadset.id, |
| 637 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
563 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); | 638 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
564 | 639 |
565 // Disconnect bluetooth headset. | 640 // Disconnect bluetooth headset. |
566 audio_nodes.clear(); | 641 audio_nodes.clear(); |
567 audio_nodes.push_back(kInternalSpeaker); | 642 audio_nodes.push_back(kInternalSpeaker); |
568 headphone.active = false; | 643 headphone.active = false; |
569 audio_nodes.push_back(headphone); | 644 audio_nodes.push_back(headphone); |
570 ChangeAudioNodes(audio_nodes); | 645 ChangeAudioNodes(audio_nodes); |
571 | 646 |
572 // Verify the AudioNodesChanged event is fired and one audio device is | 647 // Verify the AudioNodesChanged event is fired and one audio device is |
573 // removed. | 648 // removed. |
574 EXPECT_EQ(2, test_observer_->audio_nodes_changed_count()); | 649 EXPECT_EQ(2, test_observer_->audio_nodes_changed_count()); |
575 cras_audio_handler_->GetAudioDevices(&audio_devices); | 650 cras_audio_handler_->GetAudioDevices(&audio_devices); |
576 EXPECT_EQ(init_nodes_size, audio_devices.size()); | 651 EXPECT_EQ(init_nodes_size, audio_devices.size()); |
577 | 652 |
578 // Verify the active output device is switched to headphone, and | 653 // Verify the active output device is switched to headphone, and |
579 // ActiveOutputChanged event is fired. | 654 // ActiveOutputChanged event is fired. |
580 EXPECT_EQ(2, test_observer_->active_output_node_changed_count()); | 655 EXPECT_EQ(2, test_observer_->active_output_node_changed_count()); |
581 EXPECT_TRUE(cras_audio_handler_->GetActiveOutputDevice(&active_output)); | 656 EXPECT_TRUE( |
| 657 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
582 EXPECT_EQ(kHeadphone.id, active_output.id); | 658 EXPECT_EQ(kHeadphone.id, active_output.id); |
583 EXPECT_EQ(kHeadphone.id, cras_audio_handler_->GetActiveOutputNode()); | 659 EXPECT_EQ(kHeadphone.id, cras_audio_handler_->GetPrimaryActiveOutputNode()); |
584 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); | 660 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
585 } | 661 } |
586 | 662 |
587 TEST_F(CrasAudioHandlerTest, InitializeWithHDMIOutput) { | 663 TEST_F(CrasAudioHandlerTest, InitializeWithHDMIOutput) { |
588 AudioNodeList audio_nodes; | 664 AudioNodeList audio_nodes; |
589 audio_nodes.push_back(kInternalSpeaker); | 665 audio_nodes.push_back(kInternalSpeaker); |
590 audio_nodes.push_back(kHDMIOutput); | 666 audio_nodes.push_back(kHDMIOutput); |
591 SetUpCrasAudioHandler(audio_nodes); | 667 SetUpCrasAudioHandler(audio_nodes); |
592 | 668 |
593 // Verify the audio devices size. | 669 // Verify the audio devices size. |
594 AudioDeviceList audio_devices; | 670 AudioDeviceList audio_devices; |
595 cras_audio_handler_->GetAudioDevices(&audio_devices); | 671 cras_audio_handler_->GetAudioDevices(&audio_devices); |
596 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); | 672 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); |
597 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); | 673 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); |
598 | 674 |
599 // Verify the HDMI device has been selected as the active output. | 675 // Verify the HDMI device has been selected as the active output. |
600 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); | 676 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); |
601 AudioDevice active_output; | 677 AudioDevice active_output; |
602 EXPECT_TRUE(cras_audio_handler_->GetActiveOutputDevice(&active_output)); | 678 EXPECT_TRUE( |
| 679 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
603 EXPECT_EQ(kHDMIOutput.id, active_output.id); | 680 EXPECT_EQ(kHDMIOutput.id, active_output.id); |
604 EXPECT_EQ(kHDMIOutput.id, cras_audio_handler_->GetActiveOutputNode()); | 681 EXPECT_EQ(kHDMIOutput.id, cras_audio_handler_->GetPrimaryActiveOutputNode()); |
605 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); | 682 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
606 } | 683 } |
607 | 684 |
608 TEST_F(CrasAudioHandlerTest, ConnectAndDisconnectHDMIOutput) { | 685 TEST_F(CrasAudioHandlerTest, ConnectAndDisconnectHDMIOutput) { |
609 // Initialize with internal speaker. | 686 // Initialize with internal speaker. |
610 AudioNodeList audio_nodes; | 687 AudioNodeList audio_nodes; |
611 audio_nodes.push_back(kInternalSpeaker); | 688 audio_nodes.push_back(kInternalSpeaker); |
612 SetUpCrasAudioHandler(audio_nodes); | 689 SetUpCrasAudioHandler(audio_nodes); |
613 const size_t init_nodes_size = audio_nodes.size(); | 690 const size_t init_nodes_size = audio_nodes.size(); |
614 | 691 |
615 // Verify the audio devices size. | 692 // Verify the audio devices size. |
616 AudioDeviceList audio_devices; | 693 AudioDeviceList audio_devices; |
617 cras_audio_handler_->GetAudioDevices(&audio_devices); | 694 cras_audio_handler_->GetAudioDevices(&audio_devices); |
618 EXPECT_EQ(init_nodes_size, audio_devices.size()); | 695 EXPECT_EQ(init_nodes_size, audio_devices.size()); |
619 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); | 696 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); |
620 | 697 |
621 // Verify the internal speaker is selected as the active output initially. | 698 // Verify the internal speaker is selected as the active output initially. |
622 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); | 699 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); |
623 AudioDevice active_output; | 700 AudioDevice active_output; |
624 EXPECT_TRUE(cras_audio_handler_->GetActiveOutputDevice(&active_output)); | 701 EXPECT_TRUE( |
| 702 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
625 EXPECT_EQ(kInternalSpeaker.id, active_output.id); | 703 EXPECT_EQ(kInternalSpeaker.id, active_output.id); |
626 EXPECT_EQ(kInternalSpeaker.id, cras_audio_handler_->GetActiveOutputNode()); | 704 EXPECT_EQ(kInternalSpeaker.id, |
| 705 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
627 EXPECT_FALSE(cras_audio_handler_->has_alternative_output()); | 706 EXPECT_FALSE(cras_audio_handler_->has_alternative_output()); |
628 | 707 |
629 // Connect to HDMI output. | 708 // Connect to HDMI output. |
630 audio_nodes.clear(); | 709 audio_nodes.clear(); |
631 AudioNode internal_speaker(kInternalSpeaker); | 710 AudioNode internal_speaker(kInternalSpeaker); |
632 internal_speaker.active = true; | 711 internal_speaker.active = true; |
633 internal_speaker.plugged_time = 80000000; | 712 internal_speaker.plugged_time = 80000000; |
634 audio_nodes.push_back(internal_speaker); | 713 audio_nodes.push_back(internal_speaker); |
635 AudioNode hdmi(kHDMIOutput); | 714 AudioNode hdmi(kHDMIOutput); |
636 hdmi.plugged_time = 90000000; | 715 hdmi.plugged_time = 90000000; |
637 audio_nodes.push_back(hdmi); | 716 audio_nodes.push_back(hdmi); |
638 ChangeAudioNodes(audio_nodes); | 717 ChangeAudioNodes(audio_nodes); |
639 | 718 |
640 // Verify the AudioNodesChanged event is fired and new audio device is added. | 719 // Verify the AudioNodesChanged event is fired and new audio device is added. |
641 EXPECT_EQ(1, test_observer_->audio_nodes_changed_count()); | 720 EXPECT_EQ(1, test_observer_->audio_nodes_changed_count()); |
642 cras_audio_handler_->GetAudioDevices(&audio_devices); | 721 cras_audio_handler_->GetAudioDevices(&audio_devices); |
643 EXPECT_EQ(init_nodes_size + 1, audio_devices.size()); | 722 EXPECT_EQ(init_nodes_size + 1, audio_devices.size()); |
644 | 723 |
645 // Verify the active output device is switched to hdmi output, and | 724 // Verify the active output device is switched to hdmi output, and |
646 // ActiveOutputChanged event is fired. | 725 // ActiveOutputChanged event is fired. |
647 EXPECT_EQ(1, test_observer_->active_output_node_changed_count()); | 726 EXPECT_EQ(1, test_observer_->active_output_node_changed_count()); |
648 EXPECT_TRUE(cras_audio_handler_->GetActiveOutputDevice(&active_output)); | 727 EXPECT_TRUE( |
| 728 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
649 EXPECT_EQ(kHDMIOutput.id, active_output.id); | 729 EXPECT_EQ(kHDMIOutput.id, active_output.id); |
650 EXPECT_EQ(kHDMIOutput.id, cras_audio_handler_->GetActiveOutputNode()); | 730 EXPECT_EQ(kHDMIOutput.id, cras_audio_handler_->GetPrimaryActiveOutputNode()); |
651 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); | 731 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
652 | 732 |
653 // Disconnect hdmi headset. | 733 // Disconnect hdmi headset. |
654 audio_nodes.clear(); | 734 audio_nodes.clear(); |
655 audio_nodes.push_back(kInternalSpeaker); | 735 audio_nodes.push_back(kInternalSpeaker); |
656 ChangeAudioNodes(audio_nodes); | 736 ChangeAudioNodes(audio_nodes); |
657 | 737 |
658 // Verify the AudioNodesChanged event is fired and one audio device is | 738 // Verify the AudioNodesChanged event is fired and one audio device is |
659 // removed. | 739 // removed. |
660 EXPECT_EQ(2, test_observer_->audio_nodes_changed_count()); | 740 EXPECT_EQ(2, test_observer_->audio_nodes_changed_count()); |
661 cras_audio_handler_->GetAudioDevices(&audio_devices); | 741 cras_audio_handler_->GetAudioDevices(&audio_devices); |
662 EXPECT_EQ(init_nodes_size, audio_devices.size()); | 742 EXPECT_EQ(init_nodes_size, audio_devices.size()); |
663 | 743 |
664 // Verify the active output device is switched to internal speaker, and | 744 // Verify the active output device is switched to internal speaker, and |
665 // ActiveOutputChanged event is fired. | 745 // ActiveOutputChanged event is fired. |
666 EXPECT_EQ(2, test_observer_->active_output_node_changed_count()); | 746 EXPECT_EQ(2, test_observer_->active_output_node_changed_count()); |
667 EXPECT_TRUE(cras_audio_handler_->GetActiveOutputDevice(&active_output)); | 747 EXPECT_TRUE( |
| 748 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
668 EXPECT_EQ(kInternalSpeaker.id, active_output.id); | 749 EXPECT_EQ(kInternalSpeaker.id, active_output.id); |
669 EXPECT_EQ(kInternalSpeaker.id, cras_audio_handler_->GetActiveOutputNode()); | 750 EXPECT_EQ(kInternalSpeaker.id, |
| 751 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
670 EXPECT_FALSE(cras_audio_handler_->has_alternative_output()); | 752 EXPECT_FALSE(cras_audio_handler_->has_alternative_output()); |
671 } | 753 } |
672 | 754 |
673 TEST_F(CrasAudioHandlerTest, HandleHeadphoneAndHDMIOutput) { | 755 TEST_F(CrasAudioHandlerTest, HandleHeadphoneAndHDMIOutput) { |
674 // Initialize with internal speaker, headphone and HDMI output. | 756 // Initialize with internal speaker, headphone and HDMI output. |
675 AudioNodeList audio_nodes; | 757 AudioNodeList audio_nodes; |
676 audio_nodes.push_back(kInternalSpeaker); | 758 audio_nodes.push_back(kInternalSpeaker); |
677 audio_nodes.push_back(kHeadphone); | 759 audio_nodes.push_back(kHeadphone); |
678 audio_nodes.push_back(kHDMIOutput); | 760 audio_nodes.push_back(kHDMIOutput); |
679 SetUpCrasAudioHandler(audio_nodes); | 761 SetUpCrasAudioHandler(audio_nodes); |
680 const size_t init_nodes_size = audio_nodes.size(); | 762 const size_t init_nodes_size = audio_nodes.size(); |
681 | 763 |
682 // Verify the audio devices size. | 764 // Verify the audio devices size. |
683 AudioDeviceList audio_devices; | 765 AudioDeviceList audio_devices; |
684 cras_audio_handler_->GetAudioDevices(&audio_devices); | 766 cras_audio_handler_->GetAudioDevices(&audio_devices); |
685 EXPECT_EQ(init_nodes_size, audio_devices.size()); | 767 EXPECT_EQ(init_nodes_size, audio_devices.size()); |
686 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); | 768 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); |
687 | 769 |
688 // Verify the headphone is selected as the active output initially. | 770 // Verify the headphone is selected as the active output initially. |
689 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); | 771 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); |
690 AudioDevice active_output; | 772 AudioDevice active_output; |
691 EXPECT_TRUE(cras_audio_handler_->GetActiveOutputDevice(&active_output)); | 773 EXPECT_TRUE( |
| 774 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
692 EXPECT_EQ(kHeadphone.id, active_output.id); | 775 EXPECT_EQ(kHeadphone.id, active_output.id); |
693 EXPECT_EQ(kHeadphone.id, cras_audio_handler_->GetActiveOutputNode()); | 776 EXPECT_EQ(kHeadphone.id, cras_audio_handler_->GetPrimaryActiveOutputNode()); |
694 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); | 777 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
695 | 778 |
696 // Disconnect HDMI output. | 779 // Disconnect HDMI output. |
697 audio_nodes.clear(); | 780 audio_nodes.clear(); |
698 audio_nodes.push_back(kInternalSpeaker); | 781 audio_nodes.push_back(kInternalSpeaker); |
699 audio_nodes.push_back(kHDMIOutput); | 782 audio_nodes.push_back(kHDMIOutput); |
700 ChangeAudioNodes(audio_nodes); | 783 ChangeAudioNodes(audio_nodes); |
701 | 784 |
702 // Verify the AudioNodesChanged event is fired and one audio device is | 785 // Verify the AudioNodesChanged event is fired and one audio device is |
703 // removed. | 786 // removed. |
704 EXPECT_EQ(1, test_observer_->audio_nodes_changed_count()); | 787 EXPECT_EQ(1, test_observer_->audio_nodes_changed_count()); |
705 cras_audio_handler_->GetAudioDevices(&audio_devices); | 788 cras_audio_handler_->GetAudioDevices(&audio_devices); |
706 EXPECT_EQ(init_nodes_size - 1, audio_devices.size()); | 789 EXPECT_EQ(init_nodes_size - 1, audio_devices.size()); |
707 | 790 |
708 // Verify the active output device is switched to HDMI output, and | 791 // Verify the active output device is switched to HDMI output, and |
709 // ActiveOutputChanged event is fired. | 792 // ActiveOutputChanged event is fired. |
710 EXPECT_EQ(1, test_observer_->active_output_node_changed_count()); | 793 EXPECT_EQ(1, test_observer_->active_output_node_changed_count()); |
711 EXPECT_TRUE(cras_audio_handler_->GetActiveOutputDevice(&active_output)); | 794 EXPECT_TRUE( |
| 795 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
712 EXPECT_EQ(kHDMIOutput.id, active_output.id); | 796 EXPECT_EQ(kHDMIOutput.id, active_output.id); |
713 EXPECT_EQ(kHDMIOutput.id, cras_audio_handler_->GetActiveOutputNode()); | 797 EXPECT_EQ(kHDMIOutput.id, cras_audio_handler_->GetPrimaryActiveOutputNode()); |
714 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); | 798 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
715 } | 799 } |
716 | 800 |
717 TEST_F(CrasAudioHandlerTest, InitializeWithUSBHeadphone) { | 801 TEST_F(CrasAudioHandlerTest, InitializeWithUSBHeadphone) { |
718 AudioNodeList audio_nodes; | 802 AudioNodeList audio_nodes; |
719 audio_nodes.push_back(kInternalSpeaker); | 803 audio_nodes.push_back(kInternalSpeaker); |
720 audio_nodes.push_back(kUSBHeadphone1); | 804 audio_nodes.push_back(kUSBHeadphone1); |
721 SetUpCrasAudioHandler(audio_nodes); | 805 SetUpCrasAudioHandler(audio_nodes); |
722 | 806 |
723 // Verify the audio devices size. | 807 // Verify the audio devices size. |
724 AudioDeviceList audio_devices; | 808 AudioDeviceList audio_devices; |
725 cras_audio_handler_->GetAudioDevices(&audio_devices); | 809 cras_audio_handler_->GetAudioDevices(&audio_devices); |
726 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); | 810 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); |
727 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); | 811 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); |
728 | 812 |
729 // Verify the usb headphone has been selected as the active output. | 813 // Verify the usb headphone has been selected as the active output. |
730 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); | 814 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); |
731 AudioDevice active_output; | 815 AudioDevice active_output; |
732 EXPECT_TRUE(cras_audio_handler_->GetActiveOutputDevice(&active_output)); | 816 EXPECT_TRUE( |
| 817 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
733 EXPECT_EQ(kUSBHeadphone1.id, active_output.id); | 818 EXPECT_EQ(kUSBHeadphone1.id, active_output.id); |
734 EXPECT_EQ(kUSBHeadphone1.id, cras_audio_handler_->GetActiveOutputNode()); | 819 EXPECT_EQ(kUSBHeadphone1.id, |
| 820 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
735 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); | 821 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
736 } | 822 } |
737 | 823 |
738 TEST_F(CrasAudioHandlerTest, PlugAndUnplugUSBHeadphone) { | 824 TEST_F(CrasAudioHandlerTest, PlugAndUnplugUSBHeadphone) { |
739 // Initialize with internal speaker. | 825 // Initialize with internal speaker. |
740 AudioNodeList audio_nodes; | 826 AudioNodeList audio_nodes; |
741 audio_nodes.push_back(kInternalSpeaker); | 827 audio_nodes.push_back(kInternalSpeaker); |
742 SetUpCrasAudioHandler(audio_nodes); | 828 SetUpCrasAudioHandler(audio_nodes); |
743 const size_t init_nodes_size = audio_nodes.size(); | 829 const size_t init_nodes_size = audio_nodes.size(); |
744 | 830 |
745 // Verify the audio devices size. | 831 // Verify the audio devices size. |
746 AudioDeviceList audio_devices; | 832 AudioDeviceList audio_devices; |
747 cras_audio_handler_->GetAudioDevices(&audio_devices); | 833 cras_audio_handler_->GetAudioDevices(&audio_devices); |
748 EXPECT_EQ(init_nodes_size, audio_devices.size()); | 834 EXPECT_EQ(init_nodes_size, audio_devices.size()); |
749 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); | 835 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); |
750 | 836 |
751 // Verify the internal speaker is selected as the active output initially. | 837 // Verify the internal speaker is selected as the active output initially. |
752 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); | 838 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); |
753 AudioDevice active_output; | 839 AudioDevice active_output; |
754 EXPECT_TRUE(cras_audio_handler_->GetActiveOutputDevice(&active_output)); | 840 EXPECT_TRUE( |
| 841 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
755 EXPECT_EQ(kInternalSpeaker.id, active_output.id); | 842 EXPECT_EQ(kInternalSpeaker.id, active_output.id); |
756 EXPECT_EQ(kInternalSpeaker.id, cras_audio_handler_->GetActiveOutputNode()); | 843 EXPECT_EQ(kInternalSpeaker.id, |
| 844 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
757 EXPECT_FALSE(cras_audio_handler_->has_alternative_output()); | 845 EXPECT_FALSE(cras_audio_handler_->has_alternative_output()); |
758 | 846 |
759 // Plug in usb headphone | 847 // Plug in usb headphone |
760 audio_nodes.clear(); | 848 audio_nodes.clear(); |
761 AudioNode internal_speaker(kInternalSpeaker); | 849 AudioNode internal_speaker(kInternalSpeaker); |
762 internal_speaker.active = true; | 850 internal_speaker.active = true; |
763 internal_speaker.plugged_time = 80000000; | 851 internal_speaker.plugged_time = 80000000; |
764 audio_nodes.push_back(internal_speaker); | 852 audio_nodes.push_back(internal_speaker); |
765 AudioNode usb_headphone(kUSBHeadphone1); | 853 AudioNode usb_headphone(kUSBHeadphone1); |
766 usb_headphone.plugged_time = 90000000; | 854 usb_headphone.plugged_time = 90000000; |
767 audio_nodes.push_back(usb_headphone); | 855 audio_nodes.push_back(usb_headphone); |
768 ChangeAudioNodes(audio_nodes); | 856 ChangeAudioNodes(audio_nodes); |
769 | 857 |
770 // Verify the AudioNodesChanged event is fired and new audio device is added. | 858 // Verify the AudioNodesChanged event is fired and new audio device is added. |
771 EXPECT_EQ(1, test_observer_->audio_nodes_changed_count()); | 859 EXPECT_EQ(1, test_observer_->audio_nodes_changed_count()); |
772 cras_audio_handler_->GetAudioDevices(&audio_devices); | 860 cras_audio_handler_->GetAudioDevices(&audio_devices); |
773 EXPECT_EQ(init_nodes_size + 1, audio_devices.size()); | 861 EXPECT_EQ(init_nodes_size + 1, audio_devices.size()); |
774 | 862 |
775 // Verify the active output device is switched to usb headphone, and | 863 // Verify the active output device is switched to usb headphone, and |
776 // ActiveOutputChanged event is fired. | 864 // ActiveOutputChanged event is fired. |
777 EXPECT_EQ(1, test_observer_->active_output_node_changed_count()); | 865 EXPECT_EQ(1, test_observer_->active_output_node_changed_count()); |
778 EXPECT_TRUE(cras_audio_handler_->GetActiveOutputDevice(&active_output)); | 866 EXPECT_TRUE( |
| 867 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
779 EXPECT_EQ(kUSBHeadphone1.id, active_output.id); | 868 EXPECT_EQ(kUSBHeadphone1.id, active_output.id); |
780 EXPECT_EQ(kUSBHeadphone1.id, cras_audio_handler_->GetActiveOutputNode()); | 869 EXPECT_EQ(kUSBHeadphone1.id, |
| 870 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
781 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); | 871 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
782 | 872 |
783 // Unplug usb headphone. | 873 // Unplug usb headphone. |
784 audio_nodes.clear(); | 874 audio_nodes.clear(); |
785 audio_nodes.push_back(kInternalSpeaker); | 875 audio_nodes.push_back(kInternalSpeaker); |
786 ChangeAudioNodes(audio_nodes); | 876 ChangeAudioNodes(audio_nodes); |
787 | 877 |
788 // Verify the AudioNodesChanged event is fired and one audio device is | 878 // Verify the AudioNodesChanged event is fired and one audio device is |
789 // removed. | 879 // removed. |
790 EXPECT_EQ(2, test_observer_->audio_nodes_changed_count()); | 880 EXPECT_EQ(2, test_observer_->audio_nodes_changed_count()); |
791 cras_audio_handler_->GetAudioDevices(&audio_devices); | 881 cras_audio_handler_->GetAudioDevices(&audio_devices); |
792 EXPECT_EQ(init_nodes_size, audio_devices.size()); | 882 EXPECT_EQ(init_nodes_size, audio_devices.size()); |
793 | 883 |
794 // Verify the active output device is switched to internal speaker, and | 884 // Verify the active output device is switched to internal speaker, and |
795 // ActiveOutputChanged event is fired. | 885 // ActiveOutputChanged event is fired. |
796 EXPECT_EQ(2, test_observer_->active_output_node_changed_count()); | 886 EXPECT_EQ(2, test_observer_->active_output_node_changed_count()); |
797 EXPECT_TRUE(cras_audio_handler_->GetActiveOutputDevice(&active_output)); | 887 EXPECT_TRUE( |
| 888 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
798 EXPECT_EQ(kInternalSpeaker.id, active_output.id); | 889 EXPECT_EQ(kInternalSpeaker.id, active_output.id); |
799 EXPECT_EQ(kInternalSpeaker.id, cras_audio_handler_->GetActiveOutputNode()); | 890 EXPECT_EQ(kInternalSpeaker.id, |
| 891 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
800 EXPECT_FALSE(cras_audio_handler_->has_alternative_output()); | 892 EXPECT_FALSE(cras_audio_handler_->has_alternative_output()); |
801 } | 893 } |
802 | 894 |
803 TEST_F(CrasAudioHandlerTest, HandleMultipleUSBHeadphones) { | 895 TEST_F(CrasAudioHandlerTest, HandleMultipleUSBHeadphones) { |
804 // Initialize with internal speaker and one usb headphone. | 896 // Initialize with internal speaker and one usb headphone. |
805 AudioNodeList audio_nodes; | 897 AudioNodeList audio_nodes; |
806 audio_nodes.push_back(kInternalSpeaker); | 898 audio_nodes.push_back(kInternalSpeaker); |
807 audio_nodes.push_back(kUSBHeadphone1); | 899 audio_nodes.push_back(kUSBHeadphone1); |
808 SetUpCrasAudioHandler(audio_nodes); | 900 SetUpCrasAudioHandler(audio_nodes); |
809 const size_t init_nodes_size = audio_nodes.size(); | 901 const size_t init_nodes_size = audio_nodes.size(); |
810 | 902 |
811 // Verify the audio devices size. | 903 // Verify the audio devices size. |
812 AudioDeviceList audio_devices; | 904 AudioDeviceList audio_devices; |
813 cras_audio_handler_->GetAudioDevices(&audio_devices); | 905 cras_audio_handler_->GetAudioDevices(&audio_devices); |
814 EXPECT_EQ(init_nodes_size, audio_devices.size()); | 906 EXPECT_EQ(init_nodes_size, audio_devices.size()); |
815 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); | 907 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); |
816 | 908 |
817 // Verify the usb headphone is selected as the active output initially. | 909 // Verify the usb headphone is selected as the active output initially. |
818 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); | 910 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); |
819 AudioDevice active_output; | 911 AudioDevice active_output; |
820 EXPECT_TRUE(cras_audio_handler_->GetActiveOutputDevice(&active_output)); | 912 EXPECT_TRUE( |
| 913 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
821 EXPECT_EQ(kUSBHeadphone1.id, active_output.id); | 914 EXPECT_EQ(kUSBHeadphone1.id, active_output.id); |
822 EXPECT_EQ(kUSBHeadphone1.id, cras_audio_handler_->GetActiveOutputNode()); | 915 EXPECT_EQ(kUSBHeadphone1.id, |
| 916 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
823 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); | 917 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
824 | 918 |
825 // Plug in another usb headphone. | 919 // Plug in another usb headphone. |
826 audio_nodes.clear(); | 920 audio_nodes.clear(); |
827 audio_nodes.push_back(kInternalSpeaker); | 921 audio_nodes.push_back(kInternalSpeaker); |
828 AudioNode usb_headphone_1(kUSBHeadphone1); | 922 AudioNode usb_headphone_1(kUSBHeadphone1); |
829 usb_headphone_1.active = true; | 923 usb_headphone_1.active = true; |
830 usb_headphone_1.plugged_time = 80000000; | 924 usb_headphone_1.plugged_time = 80000000; |
831 audio_nodes.push_back(usb_headphone_1); | 925 audio_nodes.push_back(usb_headphone_1); |
832 AudioNode usb_headphone_2(kUSBHeadphone2); | 926 AudioNode usb_headphone_2(kUSBHeadphone2); |
833 usb_headphone_2.plugged_time = 90000000; | 927 usb_headphone_2.plugged_time = 90000000; |
834 audio_nodes.push_back(usb_headphone_2); | 928 audio_nodes.push_back(usb_headphone_2); |
835 ChangeAudioNodes(audio_nodes); | 929 ChangeAudioNodes(audio_nodes); |
836 | 930 |
837 // Verify the AudioNodesChanged event is fired and new audio device is added. | 931 // Verify the AudioNodesChanged event is fired and new audio device is added. |
838 EXPECT_EQ(1, test_observer_->audio_nodes_changed_count()); | 932 EXPECT_EQ(1, test_observer_->audio_nodes_changed_count()); |
839 cras_audio_handler_->GetAudioDevices(&audio_devices); | 933 cras_audio_handler_->GetAudioDevices(&audio_devices); |
840 EXPECT_EQ(init_nodes_size + 1, audio_devices.size()); | 934 EXPECT_EQ(init_nodes_size + 1, audio_devices.size()); |
841 | 935 |
842 // Verify the active output device is switched to the 2nd usb headphone, which | 936 // Verify the active output device is switched to the 2nd usb headphone, which |
843 // is plugged later, and ActiveOutputChanged event is fired. | 937 // is plugged later, and ActiveOutputChanged event is fired. |
844 EXPECT_EQ(1, test_observer_->active_output_node_changed_count()); | 938 EXPECT_EQ(1, test_observer_->active_output_node_changed_count()); |
845 EXPECT_TRUE(cras_audio_handler_->GetActiveOutputDevice(&active_output)); | 939 EXPECT_TRUE( |
| 940 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
846 EXPECT_EQ(kUSBHeadphone2.id, active_output.id); | 941 EXPECT_EQ(kUSBHeadphone2.id, active_output.id); |
847 EXPECT_EQ(kUSBHeadphone2.id, cras_audio_handler_->GetActiveOutputNode()); | 942 EXPECT_EQ(kUSBHeadphone2.id, |
| 943 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
848 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); | 944 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
849 | 945 |
850 // Unplug the 2nd usb headphone. | 946 // Unplug the 2nd usb headphone. |
851 audio_nodes.clear(); | 947 audio_nodes.clear(); |
852 audio_nodes.push_back(kInternalSpeaker); | 948 audio_nodes.push_back(kInternalSpeaker); |
853 audio_nodes.push_back(kUSBHeadphone1); | 949 audio_nodes.push_back(kUSBHeadphone1); |
854 ChangeAudioNodes(audio_nodes); | 950 ChangeAudioNodes(audio_nodes); |
855 | 951 |
856 // Verify the AudioNodesChanged event is fired and one audio device is | 952 // Verify the AudioNodesChanged event is fired and one audio device is |
857 // removed. | 953 // removed. |
858 EXPECT_EQ(2, test_observer_->audio_nodes_changed_count()); | 954 EXPECT_EQ(2, test_observer_->audio_nodes_changed_count()); |
859 cras_audio_handler_->GetAudioDevices(&audio_devices); | 955 cras_audio_handler_->GetAudioDevices(&audio_devices); |
860 EXPECT_EQ(init_nodes_size, audio_devices.size()); | 956 EXPECT_EQ(init_nodes_size, audio_devices.size()); |
861 | 957 |
862 // Verify the active output device is switched to the first usb headphone, and | 958 // Verify the active output device is switched to the first usb headphone, and |
863 // ActiveOutputChanged event is fired. | 959 // ActiveOutputChanged event is fired. |
864 EXPECT_EQ(2, test_observer_->active_output_node_changed_count()); | 960 EXPECT_EQ(2, test_observer_->active_output_node_changed_count()); |
865 EXPECT_TRUE(cras_audio_handler_->GetActiveOutputDevice(&active_output)); | 961 EXPECT_TRUE( |
| 962 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
866 EXPECT_EQ(kUSBHeadphone1.id, active_output.id); | 963 EXPECT_EQ(kUSBHeadphone1.id, active_output.id); |
867 EXPECT_EQ(kUSBHeadphone1.id, cras_audio_handler_->GetActiveOutputNode()); | 964 EXPECT_EQ(kUSBHeadphone1.id, |
| 965 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
868 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); | 966 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
869 } | 967 } |
870 | 968 |
871 TEST_F(CrasAudioHandlerTest, UnplugUSBHeadphonesWithActiveSpeaker) { | 969 TEST_F(CrasAudioHandlerTest, UnplugUSBHeadphonesWithActiveSpeaker) { |
872 // Initialize with internal speaker and one usb headphone. | 970 // Initialize with internal speaker and one usb headphone. |
873 AudioNodeList audio_nodes; | 971 AudioNodeList audio_nodes; |
874 audio_nodes.push_back(kInternalSpeaker); | 972 audio_nodes.push_back(kInternalSpeaker); |
875 audio_nodes.push_back(kUSBHeadphone1); | 973 audio_nodes.push_back(kUSBHeadphone1); |
876 SetUpCrasAudioHandler(audio_nodes); | 974 SetUpCrasAudioHandler(audio_nodes); |
877 const size_t init_nodes_size = audio_nodes.size(); | 975 const size_t init_nodes_size = audio_nodes.size(); |
878 | 976 |
879 // Verify the audio devices size. | 977 // Verify the audio devices size. |
880 AudioDeviceList audio_devices; | 978 AudioDeviceList audio_devices; |
881 cras_audio_handler_->GetAudioDevices(&audio_devices); | 979 cras_audio_handler_->GetAudioDevices(&audio_devices); |
882 EXPECT_EQ(init_nodes_size, audio_devices.size()); | 980 EXPECT_EQ(init_nodes_size, audio_devices.size()); |
883 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); | 981 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); |
884 | 982 |
885 // Verify the usb headphone is selected as the active output initially. | 983 // Verify the usb headphone is selected as the active output initially. |
886 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); | 984 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); |
887 AudioDevice active_output; | 985 AudioDevice active_output; |
888 EXPECT_TRUE(cras_audio_handler_->GetActiveOutputDevice(&active_output)); | 986 EXPECT_TRUE( |
| 987 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
889 EXPECT_EQ(kUSBHeadphone1.id, active_output.id); | 988 EXPECT_EQ(kUSBHeadphone1.id, active_output.id); |
890 EXPECT_EQ(kUSBHeadphone1.id, cras_audio_handler_->GetActiveOutputNode()); | 989 EXPECT_EQ(kUSBHeadphone1.id, |
| 990 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
891 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); | 991 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
892 | 992 |
893 // Plug in the headphone jack. | 993 // Plug in the headphone jack. |
894 audio_nodes.clear(); | 994 audio_nodes.clear(); |
895 audio_nodes.push_back(kInternalSpeaker); | 995 audio_nodes.push_back(kInternalSpeaker); |
896 AudioNode usb_headphone_1(kUSBHeadphone1); | 996 AudioNode usb_headphone_1(kUSBHeadphone1); |
897 usb_headphone_1.active = true; | 997 usb_headphone_1.active = true; |
898 usb_headphone_1.plugged_time = 80000000; | 998 usb_headphone_1.plugged_time = 80000000; |
899 audio_nodes.push_back(usb_headphone_1); | 999 audio_nodes.push_back(usb_headphone_1); |
900 AudioNode headphone_jack(kHeadphone); | 1000 AudioNode headphone_jack(kHeadphone); |
901 headphone_jack.plugged_time = 90000000; | 1001 headphone_jack.plugged_time = 90000000; |
902 audio_nodes.push_back(headphone_jack); | 1002 audio_nodes.push_back(headphone_jack); |
903 ChangeAudioNodes(audio_nodes); | 1003 ChangeAudioNodes(audio_nodes); |
904 | 1004 |
905 // Verify the AudioNodesChanged event is fired and new audio device is added. | 1005 // Verify the AudioNodesChanged event is fired and new audio device is added. |
906 EXPECT_EQ(1, test_observer_->audio_nodes_changed_count()); | 1006 EXPECT_EQ(1, test_observer_->audio_nodes_changed_count()); |
907 cras_audio_handler_->GetAudioDevices(&audio_devices); | 1007 cras_audio_handler_->GetAudioDevices(&audio_devices); |
908 EXPECT_EQ(init_nodes_size + 1, audio_devices.size()); | 1008 EXPECT_EQ(init_nodes_size + 1, audio_devices.size()); |
909 | 1009 |
910 // Verify the active output device is switched to the headphone jack, which | 1010 // Verify the active output device is switched to the headphone jack, which |
911 // is plugged later, and ActiveOutputChanged event is fired. | 1011 // is plugged later, and ActiveOutputChanged event is fired. |
912 EXPECT_EQ(1, test_observer_->active_output_node_changed_count()); | 1012 EXPECT_EQ(1, test_observer_->active_output_node_changed_count()); |
913 EXPECT_TRUE(cras_audio_handler_->GetActiveOutputDevice(&active_output)); | 1013 EXPECT_TRUE( |
| 1014 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
914 EXPECT_EQ(kHeadphone.id, active_output.id); | 1015 EXPECT_EQ(kHeadphone.id, active_output.id); |
915 EXPECT_EQ(kHeadphone.id, cras_audio_handler_->GetActiveOutputNode()); | 1016 EXPECT_EQ(kHeadphone.id, cras_audio_handler_->GetPrimaryActiveOutputNode()); |
916 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); | 1017 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
917 | 1018 |
918 // Select the speaker to be the active output device. | 1019 // Select the speaker to be the active output device. |
919 AudioDevice internal_speaker(kInternalSpeaker); | 1020 AudioDevice internal_speaker(kInternalSpeaker); |
920 cras_audio_handler_->SwitchToDevice(internal_speaker); | 1021 cras_audio_handler_->SwitchToDevice(internal_speaker); |
921 | 1022 |
922 // Verify the active output is switched to internal speaker, and the | 1023 // Verify the active output is switched to internal speaker, and the |
923 // ActiveOutputNodeChanged event is fired. | 1024 // ActiveOutputNodeChanged event is fired. |
924 EXPECT_EQ(2, test_observer_->active_output_node_changed_count()); | 1025 EXPECT_EQ(2, test_observer_->active_output_node_changed_count()); |
925 EXPECT_TRUE(cras_audio_handler_->GetActiveOutputDevice(&active_output)); | 1026 EXPECT_TRUE( |
| 1027 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
926 EXPECT_EQ(kInternalSpeaker.id, active_output.id); | 1028 EXPECT_EQ(kInternalSpeaker.id, active_output.id); |
927 EXPECT_EQ(kInternalSpeaker.id, cras_audio_handler_->GetActiveOutputNode()); | 1029 EXPECT_EQ(kInternalSpeaker.id, |
| 1030 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
928 | 1031 |
929 // Unplug the usb headphone. | 1032 // Unplug the usb headphone. |
930 audio_nodes.clear(); | 1033 audio_nodes.clear(); |
931 AudioNode internal_speaker_node(kInternalSpeaker); | 1034 AudioNode internal_speaker_node(kInternalSpeaker); |
932 internal_speaker_node.active = true; | 1035 internal_speaker_node.active = true; |
933 internal_speaker_node.plugged_time = 70000000; | 1036 internal_speaker_node.plugged_time = 70000000; |
934 audio_nodes.push_back(internal_speaker_node); | 1037 audio_nodes.push_back(internal_speaker_node); |
935 headphone_jack.active = false; | 1038 headphone_jack.active = false; |
936 audio_nodes.push_back(headphone_jack); | 1039 audio_nodes.push_back(headphone_jack); |
937 ChangeAudioNodes(audio_nodes); | 1040 ChangeAudioNodes(audio_nodes); |
938 | 1041 |
939 // Verify the AudioNodesChanged event is fired and one audio device is | 1042 // Verify the AudioNodesChanged event is fired and one audio device is |
940 // removed. | 1043 // removed. |
941 EXPECT_EQ(2, test_observer_->audio_nodes_changed_count()); | 1044 EXPECT_EQ(2, test_observer_->audio_nodes_changed_count()); |
942 cras_audio_handler_->GetAudioDevices(&audio_devices); | 1045 cras_audio_handler_->GetAudioDevices(&audio_devices); |
943 EXPECT_EQ(init_nodes_size, audio_devices.size()); | 1046 EXPECT_EQ(init_nodes_size, audio_devices.size()); |
944 | 1047 |
945 // Verify the active output device remains to be speaker. | 1048 // Verify the active output device remains to be speaker. |
946 EXPECT_EQ(2, test_observer_->active_output_node_changed_count()); | 1049 EXPECT_EQ(2, test_observer_->active_output_node_changed_count()); |
947 EXPECT_TRUE(cras_audio_handler_->GetActiveOutputDevice(&active_output)); | 1050 EXPECT_TRUE( |
| 1051 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
948 EXPECT_EQ(kInternalSpeaker.id, active_output.id); | 1052 EXPECT_EQ(kInternalSpeaker.id, active_output.id); |
949 EXPECT_EQ(kInternalSpeaker.id, cras_audio_handler_->GetActiveOutputNode()); | 1053 EXPECT_EQ(kInternalSpeaker.id, |
| 1054 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
950 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); | 1055 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
951 } | 1056 } |
952 | 1057 |
953 TEST_F(CrasAudioHandlerTest, OneActiveAudioOutputAfterLoginNewUserSession) { | 1058 TEST_F(CrasAudioHandlerTest, OneActiveAudioOutputAfterLoginNewUserSession) { |
954 // This tests the case found with crbug.com/273271. | 1059 // This tests the case found with crbug.com/273271. |
955 // Initialize with internal speaker, bluetooth headphone and headphone jack | 1060 // Initialize with internal speaker, bluetooth headphone and headphone jack |
956 // for a new chrome session after user signs out from the previous session. | 1061 // for a new chrome session after user signs out from the previous session. |
957 // Headphone jack is plugged in later than bluetooth headphone, but bluetooth | 1062 // Headphone jack is plugged in later than bluetooth headphone, but bluetooth |
958 // headphone is selected as the active output by user from previous user | 1063 // headphone is selected as the active output by user from previous user |
959 // session. | 1064 // session. |
960 AudioNodeList audio_nodes; | 1065 AudioNodeList audio_nodes; |
961 audio_nodes.push_back(kInternalSpeaker); | 1066 audio_nodes.push_back(kInternalSpeaker); |
962 AudioNode bluetooth_headphone(kBluetoothHeadset); | 1067 AudioNode bluetooth_headphone(kBluetoothHeadset); |
963 bluetooth_headphone.active = true; | 1068 bluetooth_headphone.active = true; |
964 bluetooth_headphone.plugged_time = 70000000; | 1069 bluetooth_headphone.plugged_time = 70000000; |
965 audio_nodes.push_back(bluetooth_headphone); | 1070 audio_nodes.push_back(bluetooth_headphone); |
966 AudioNode headphone_jack(kHeadphone); | 1071 AudioNode headphone_jack(kHeadphone); |
967 headphone_jack.plugged_time = 80000000; | 1072 headphone_jack.plugged_time = 80000000; |
968 audio_nodes.push_back(headphone_jack); | 1073 audio_nodes.push_back(headphone_jack); |
969 SetUpCrasAudioHandler(audio_nodes); | 1074 SetUpCrasAudioHandlerWithPrimaryActiveNode(audio_nodes, bluetooth_headphone); |
970 const size_t init_nodes_size = audio_nodes.size(); | 1075 const size_t init_nodes_size = audio_nodes.size(); |
971 | 1076 |
972 // Verify the audio devices size. | 1077 // Verify the audio devices size. |
973 AudioDeviceList audio_devices; | 1078 AudioDeviceList audio_devices; |
974 cras_audio_handler_->GetAudioDevices(&audio_devices); | 1079 cras_audio_handler_->GetAudioDevices(&audio_devices); |
975 EXPECT_EQ(init_nodes_size, audio_devices.size()); | 1080 EXPECT_EQ(init_nodes_size, audio_devices.size()); |
976 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); | 1081 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); |
977 | 1082 |
978 // Verify the headphone jack is selected as the active output and all other | 1083 // Verify the headphone jack is selected as the active output and all other |
979 // audio devices are not active. | 1084 // audio devices are not active. |
980 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); | 1085 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); |
981 AudioDevice active_output; | 1086 AudioDevice active_output; |
982 EXPECT_TRUE(cras_audio_handler_->GetActiveOutputDevice(&active_output)); | 1087 EXPECT_TRUE( |
| 1088 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
983 EXPECT_EQ(kHeadphone.id, active_output.id); | 1089 EXPECT_EQ(kHeadphone.id, active_output.id); |
984 EXPECT_EQ(kHeadphone.id, cras_audio_handler_->GetActiveOutputNode()); | 1090 EXPECT_EQ(kHeadphone.id, cras_audio_handler_->GetPrimaryActiveOutputNode()); |
985 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); | 1091 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
986 for (size_t i = 0; i < audio_devices.size(); ++i) { | 1092 for (size_t i = 0; i < audio_devices.size(); ++i) { |
987 if (audio_devices[i].id != kHeadphone.id) | 1093 if (audio_devices[i].id != kHeadphone.id) |
988 EXPECT_FALSE(audio_devices[i].active); | 1094 EXPECT_FALSE(audio_devices[i].active); |
989 } | 1095 } |
990 } | 1096 } |
991 | 1097 |
992 TEST_F(CrasAudioHandlerTest, BluetoothSpeakerIdChangedOnFly) { | 1098 TEST_F(CrasAudioHandlerTest, BluetoothSpeakerIdChangedOnFly) { |
993 // Initialize with internal speaker and bluetooth headset. | 1099 // Initialize with internal speaker and bluetooth headset. |
994 AudioNodeList audio_nodes; | 1100 AudioNodeList audio_nodes; |
995 audio_nodes.push_back(kInternalSpeaker); | 1101 audio_nodes.push_back(kInternalSpeaker); |
996 audio_nodes.push_back(kBluetoothHeadset); | 1102 audio_nodes.push_back(kBluetoothHeadset); |
997 SetUpCrasAudioHandler(audio_nodes); | 1103 SetUpCrasAudioHandler(audio_nodes); |
998 const size_t init_nodes_size = audio_nodes.size(); | 1104 const size_t init_nodes_size = audio_nodes.size(); |
999 | 1105 |
1000 // Verify the audio devices size. | 1106 // Verify the audio devices size. |
1001 AudioDeviceList audio_devices; | 1107 AudioDeviceList audio_devices; |
1002 cras_audio_handler_->GetAudioDevices(&audio_devices); | 1108 cras_audio_handler_->GetAudioDevices(&audio_devices); |
1003 EXPECT_EQ(init_nodes_size, audio_devices.size()); | 1109 EXPECT_EQ(init_nodes_size, audio_devices.size()); |
1004 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); | 1110 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); |
1005 | 1111 |
1006 // Verify the bluetooth headset is selected as the active output and all other | 1112 // Verify the bluetooth headset is selected as the active output and all other |
1007 // audio devices are not active. | 1113 // audio devices are not active. |
1008 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); | 1114 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); |
1009 AudioDevice active_output; | 1115 AudioDevice active_output; |
1010 EXPECT_TRUE(cras_audio_handler_->GetActiveOutputDevice(&active_output)); | 1116 EXPECT_TRUE( |
| 1117 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
1011 EXPECT_EQ(kBluetoothHeadset.id, active_output.id); | 1118 EXPECT_EQ(kBluetoothHeadset.id, active_output.id); |
1012 EXPECT_EQ(kBluetoothHeadset.id, cras_audio_handler_->GetActiveOutputNode()); | 1119 EXPECT_EQ(kBluetoothHeadset.id, |
| 1120 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
1013 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); | 1121 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
1014 | 1122 |
1015 // Cras changes the bluetooth headset's id on the fly. | 1123 // Cras changes the bluetooth headset's id on the fly. |
1016 audio_nodes.clear(); | 1124 audio_nodes.clear(); |
1017 AudioNode internal_speaker(kInternalSpeaker); | 1125 AudioNode internal_speaker(kInternalSpeaker); |
1018 internal_speaker.active = false; | 1126 internal_speaker.active = false; |
1019 audio_nodes.push_back(internal_speaker); | 1127 audio_nodes.push_back(internal_speaker); |
1020 AudioNode bluetooth_headphone(kBluetoothHeadset); | 1128 AudioNode bluetooth_headphone(kBluetoothHeadset); |
1021 // Change bluetooth headphone id. | 1129 // Change bluetooth headphone id. |
1022 bluetooth_headphone.id = kBluetoothHeadsetId + 20000; | 1130 bluetooth_headphone.id = kBluetoothHeadsetId + 20000; |
1023 bluetooth_headphone.active = false; | 1131 bluetooth_headphone.active = false; |
1024 audio_nodes.push_back(bluetooth_headphone); | 1132 audio_nodes.push_back(bluetooth_headphone); |
1025 ChangeAudioNodes(audio_nodes); | 1133 ChangeAudioNodes(audio_nodes); |
1026 | 1134 |
1027 // Verify NodesChanged event is fired, and the audio devices size is not | 1135 // Verify NodesChanged event is fired, and the audio devices size is not |
1028 // changed. | 1136 // changed. |
1029 audio_devices.clear(); | 1137 audio_devices.clear(); |
1030 cras_audio_handler_->GetAudioDevices(&audio_devices); | 1138 cras_audio_handler_->GetAudioDevices(&audio_devices); |
1031 EXPECT_EQ(init_nodes_size, audio_devices.size()); | 1139 EXPECT_EQ(init_nodes_size, audio_devices.size()); |
1032 EXPECT_EQ(1, test_observer_->audio_nodes_changed_count()); | 1140 EXPECT_EQ(1, test_observer_->audio_nodes_changed_count()); |
1033 | 1141 |
1034 // Verify ActiveOutputNodeChanged event is fired, and active device should be | 1142 // Verify ActiveOutputNodeChanged event is fired, and active device should be |
1035 // bluetooth headphone. | 1143 // bluetooth headphone. |
1036 EXPECT_EQ(1, test_observer_->active_output_node_changed_count()); | 1144 EXPECT_EQ(1, test_observer_->active_output_node_changed_count()); |
1037 EXPECT_TRUE(cras_audio_handler_->GetActiveOutputDevice(&active_output)); | 1145 EXPECT_TRUE( |
| 1146 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
1038 EXPECT_EQ(bluetooth_headphone.id, active_output.id); | 1147 EXPECT_EQ(bluetooth_headphone.id, active_output.id); |
1039 } | 1148 } |
1040 | 1149 |
1041 TEST_F(CrasAudioHandlerTest, PlugUSBMic) { | 1150 TEST_F(CrasAudioHandlerTest, PlugUSBMic) { |
1042 // Set up initial audio devices, only with internal mic. | 1151 // Set up initial audio devices, only with internal mic. |
1043 AudioNodeList audio_nodes; | 1152 AudioNodeList audio_nodes; |
1044 audio_nodes.push_back(kInternalMic); | 1153 audio_nodes.push_back(kInternalMic); |
1045 SetUpCrasAudioHandler(audio_nodes); | 1154 SetUpCrasAudioHandler(audio_nodes); |
1046 const size_t init_nodes_size = audio_nodes.size(); | 1155 const size_t init_nodes_size = audio_nodes.size(); |
1047 | 1156 |
1048 // Verify the audio devices size. | 1157 // Verify the audio devices size. |
1049 AudioDeviceList audio_devices; | 1158 AudioDeviceList audio_devices; |
1050 cras_audio_handler_->GetAudioDevices(&audio_devices); | 1159 cras_audio_handler_->GetAudioDevices(&audio_devices); |
1051 EXPECT_EQ(init_nodes_size, audio_devices.size()); | 1160 EXPECT_EQ(init_nodes_size, audio_devices.size()); |
1052 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); | 1161 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); |
1053 | 1162 |
1054 // Verify the internal mic is selected as the active input. | 1163 // Verify the internal mic is selected as the active input. |
1055 EXPECT_EQ(0, test_observer_->active_input_node_changed_count()); | 1164 EXPECT_EQ(0, test_observer_->active_input_node_changed_count()); |
1056 EXPECT_EQ(kInternalMic.id, cras_audio_handler_->GetActiveInputNode()); | 1165 EXPECT_EQ(kInternalMic.id, cras_audio_handler_->GetPrimaryActiveInputNode()); |
1057 EXPECT_FALSE(cras_audio_handler_->has_alternative_input()); | 1166 EXPECT_FALSE(cras_audio_handler_->has_alternative_input()); |
1058 | 1167 |
1059 // Plug the USB Mic. | 1168 // Plug the USB Mic. |
1060 audio_nodes.clear(); | 1169 audio_nodes.clear(); |
1061 AudioNode internal_mic(kInternalMic); | 1170 AudioNode internal_mic(kInternalMic); |
1062 internal_mic.active = true; | 1171 internal_mic.active = true; |
1063 audio_nodes.push_back(internal_mic); | 1172 audio_nodes.push_back(internal_mic); |
1064 audio_nodes.push_back(kUSBMic); | 1173 audio_nodes.push_back(kUSBMic); |
1065 ChangeAudioNodes(audio_nodes); | 1174 ChangeAudioNodes(audio_nodes); |
1066 | 1175 |
1067 // Verify the AudioNodesChanged event is fired and new audio device is added. | 1176 // Verify the AudioNodesChanged event is fired and new audio device is added. |
1068 EXPECT_EQ(1, test_observer_->audio_nodes_changed_count()); | 1177 EXPECT_EQ(1, test_observer_->audio_nodes_changed_count()); |
1069 cras_audio_handler_->GetAudioDevices(&audio_devices); | 1178 cras_audio_handler_->GetAudioDevices(&audio_devices); |
1070 EXPECT_EQ(init_nodes_size + 1, audio_devices.size()); | 1179 EXPECT_EQ(init_nodes_size + 1, audio_devices.size()); |
1071 | 1180 |
1072 // Verify the active input device is switched to USB mic and | 1181 // Verify the active input device is switched to USB mic and |
1073 // and ActiveInputChanged event is fired. | 1182 // and ActiveInputChanged event is fired. |
1074 EXPECT_EQ(1, test_observer_->active_input_node_changed_count()); | 1183 EXPECT_EQ(1, test_observer_->active_input_node_changed_count()); |
1075 EXPECT_EQ(kUSBMicId, cras_audio_handler_->GetActiveInputNode()); | 1184 EXPECT_EQ(kUSBMicId, cras_audio_handler_->GetPrimaryActiveInputNode()); |
1076 EXPECT_TRUE(cras_audio_handler_->has_alternative_input()); | 1185 EXPECT_TRUE(cras_audio_handler_->has_alternative_input()); |
1077 } | 1186 } |
1078 | 1187 |
1079 TEST_F(CrasAudioHandlerTest, UnplugUSBMic) { | 1188 TEST_F(CrasAudioHandlerTest, UnplugUSBMic) { |
1080 // Set up initial audio devices, with internal mic and USB Mic. | 1189 // Set up initial audio devices, with internal mic and USB Mic. |
1081 AudioNodeList audio_nodes; | 1190 AudioNodeList audio_nodes; |
1082 audio_nodes.push_back(kInternalMic); | 1191 audio_nodes.push_back(kInternalMic); |
1083 audio_nodes.push_back(kUSBMic); | 1192 audio_nodes.push_back(kUSBMic); |
1084 SetUpCrasAudioHandler(audio_nodes); | 1193 SetUpCrasAudioHandler(audio_nodes); |
1085 const size_t init_nodes_size = audio_nodes.size(); | 1194 const size_t init_nodes_size = audio_nodes.size(); |
1086 | 1195 |
1087 // Verify the audio devices size. | 1196 // Verify the audio devices size. |
1088 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); | 1197 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); |
1089 AudioDeviceList audio_devices; | 1198 AudioDeviceList audio_devices; |
1090 cras_audio_handler_->GetAudioDevices(&audio_devices); | 1199 cras_audio_handler_->GetAudioDevices(&audio_devices); |
1091 EXPECT_EQ(init_nodes_size, audio_devices.size()); | 1200 EXPECT_EQ(init_nodes_size, audio_devices.size()); |
1092 | 1201 |
1093 // Verify the USB mic is selected as the active output. | 1202 // Verify the USB mic is selected as the active output. |
1094 EXPECT_EQ(0, test_observer_->active_input_node_changed_count()); | 1203 EXPECT_EQ(0, test_observer_->active_input_node_changed_count()); |
1095 EXPECT_EQ(kUSBMicId, cras_audio_handler_->GetActiveInputNode()); | 1204 EXPECT_EQ(kUSBMicId, cras_audio_handler_->GetPrimaryActiveInputNode()); |
1096 EXPECT_TRUE(cras_audio_handler_->has_alternative_input()); | 1205 EXPECT_TRUE(cras_audio_handler_->has_alternative_input()); |
1097 | 1206 |
1098 // Unplug the USB Mic. | 1207 // Unplug the USB Mic. |
1099 audio_nodes.clear(); | 1208 audio_nodes.clear(); |
1100 audio_nodes.push_back(kInternalMic); | 1209 audio_nodes.push_back(kInternalMic); |
1101 ChangeAudioNodes(audio_nodes); | 1210 ChangeAudioNodes(audio_nodes); |
1102 | 1211 |
1103 // Verify the AudioNodesChanged event is fired, and one audio device is | 1212 // Verify the AudioNodesChanged event is fired, and one audio device is |
1104 // removed. | 1213 // removed. |
1105 EXPECT_EQ(1, test_observer_->audio_nodes_changed_count()); | 1214 EXPECT_EQ(1, test_observer_->audio_nodes_changed_count()); |
1106 cras_audio_handler_->GetAudioDevices(&audio_devices); | 1215 cras_audio_handler_->GetAudioDevices(&audio_devices); |
1107 EXPECT_EQ(init_nodes_size - 1, audio_devices.size()); | 1216 EXPECT_EQ(init_nodes_size - 1, audio_devices.size()); |
1108 | 1217 |
1109 // Verify the active input device is switched to internal mic, and | 1218 // Verify the active input device is switched to internal mic, and |
1110 // and ActiveInputChanged event is fired. | 1219 // and ActiveInputChanged event is fired. |
1111 EXPECT_EQ(1, test_observer_->active_input_node_changed_count()); | 1220 EXPECT_EQ(1, test_observer_->active_input_node_changed_count()); |
1112 EXPECT_EQ(kInternalMic.id, cras_audio_handler_->GetActiveInputNode()); | 1221 EXPECT_EQ(kInternalMic.id, cras_audio_handler_->GetPrimaryActiveInputNode()); |
1113 EXPECT_FALSE(cras_audio_handler_->has_alternative_input()); | 1222 EXPECT_FALSE(cras_audio_handler_->has_alternative_input()); |
1114 } | 1223 } |
1115 | 1224 |
1116 TEST_F(CrasAudioHandlerTest, PlugUSBMicNotAffectActiveOutput) { | 1225 TEST_F(CrasAudioHandlerTest, PlugUSBMicNotAffectActiveOutput) { |
1117 // Set up initial audio devices. | 1226 // Set up initial audio devices. |
1118 AudioNodeList audio_nodes; | 1227 AudioNodeList audio_nodes; |
1119 audio_nodes.push_back(kInternalSpeaker); | 1228 audio_nodes.push_back(kInternalSpeaker); |
1120 audio_nodes.push_back(kHeadphone); | 1229 audio_nodes.push_back(kHeadphone); |
1121 audio_nodes.push_back(kInternalMic); | 1230 audio_nodes.push_back(kInternalMic); |
1122 SetUpCrasAudioHandler(audio_nodes); | 1231 SetUpCrasAudioHandler(audio_nodes); |
1123 const size_t init_nodes_size = audio_nodes.size(); | 1232 const size_t init_nodes_size = audio_nodes.size(); |
1124 | 1233 |
1125 // Verify the audio devices size. | 1234 // Verify the audio devices size. |
1126 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); | 1235 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); |
1127 AudioDeviceList audio_devices; | 1236 AudioDeviceList audio_devices; |
1128 cras_audio_handler_->GetAudioDevices(&audio_devices); | 1237 cras_audio_handler_->GetAudioDevices(&audio_devices); |
1129 EXPECT_EQ(init_nodes_size, audio_devices.size()); | 1238 EXPECT_EQ(init_nodes_size, audio_devices.size()); |
1130 | 1239 |
1131 // Verify the internal mic is selected as the active input. | 1240 // Verify the internal mic is selected as the active input. |
1132 EXPECT_EQ(0, test_observer_->active_input_node_changed_count()); | 1241 EXPECT_EQ(0, test_observer_->active_input_node_changed_count()); |
1133 EXPECT_EQ(kInternalMicId, cras_audio_handler_->GetActiveInputNode()); | 1242 EXPECT_EQ(kInternalMicId, cras_audio_handler_->GetPrimaryActiveInputNode()); |
1134 EXPECT_FALSE(cras_audio_handler_->has_alternative_input()); | 1243 EXPECT_FALSE(cras_audio_handler_->has_alternative_input()); |
1135 | 1244 |
1136 // Verify the headphone is selected as the active output. | 1245 // Verify the headphone is selected as the active output. |
1137 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); | 1246 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); |
1138 EXPECT_EQ(kHeadphoneId, cras_audio_handler_->GetActiveOutputNode()); | 1247 EXPECT_EQ(kHeadphoneId, cras_audio_handler_->GetPrimaryActiveOutputNode()); |
1139 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); | 1248 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
1140 | 1249 |
1141 // Switch the active output to internal speaker. | 1250 // Switch the active output to internal speaker. |
1142 AudioDevice internal_speaker(kInternalSpeaker); | 1251 AudioDevice internal_speaker(kInternalSpeaker); |
1143 cras_audio_handler_->SwitchToDevice(internal_speaker); | 1252 cras_audio_handler_->SwitchToDevice(internal_speaker); |
1144 | 1253 |
1145 // Verify the active output is switched to internal speaker, and the | 1254 // Verify the active output is switched to internal speaker, and the |
1146 // ActiveOutputNodeChanged event is fired. | 1255 // ActiveOutputNodeChanged event is fired. |
1147 EXPECT_EQ(1, test_observer_->active_output_node_changed_count()); | 1256 EXPECT_EQ(1, test_observer_->active_output_node_changed_count()); |
1148 AudioDevice active_output; | 1257 AudioDevice active_output; |
1149 EXPECT_TRUE(cras_audio_handler_->GetActiveOutputDevice(&active_output)); | 1258 EXPECT_TRUE( |
| 1259 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
1150 EXPECT_EQ(kInternalSpeaker.id, active_output.id); | 1260 EXPECT_EQ(kInternalSpeaker.id, active_output.id); |
1151 EXPECT_EQ(kInternalSpeaker.id, cras_audio_handler_->GetActiveOutputNode()); | 1261 EXPECT_EQ(kInternalSpeaker.id, |
| 1262 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
1152 | 1263 |
1153 // Plug the USB Mic. | 1264 // Plug the USB Mic. |
1154 audio_nodes.clear(); | 1265 audio_nodes.clear(); |
1155 AudioNode internal_speaker_node(kInternalSpeaker); | 1266 AudioNode internal_speaker_node(kInternalSpeaker); |
1156 internal_speaker_node.active = true; | 1267 internal_speaker_node.active = true; |
1157 audio_nodes.push_back(internal_speaker_node); | 1268 audio_nodes.push_back(internal_speaker_node); |
1158 audio_nodes.push_back(kHeadphone); | 1269 audio_nodes.push_back(kHeadphone); |
1159 AudioNode internal_mic(kInternalMic); | 1270 AudioNode internal_mic(kInternalMic); |
1160 internal_mic.active = true; | 1271 internal_mic.active = true; |
1161 audio_nodes.push_back(internal_mic); | 1272 audio_nodes.push_back(internal_mic); |
1162 audio_nodes.push_back(kUSBMic); | 1273 audio_nodes.push_back(kUSBMic); |
1163 ChangeAudioNodes(audio_nodes); | 1274 ChangeAudioNodes(audio_nodes); |
1164 | 1275 |
1165 // Verify the AudioNodesChanged event is fired, one new device is added. | 1276 // Verify the AudioNodesChanged event is fired, one new device is added. |
1166 EXPECT_EQ(1, test_observer_->audio_nodes_changed_count()); | 1277 EXPECT_EQ(1, test_observer_->audio_nodes_changed_count()); |
1167 cras_audio_handler_->GetAudioDevices(&audio_devices); | 1278 cras_audio_handler_->GetAudioDevices(&audio_devices); |
1168 EXPECT_EQ(init_nodes_size + 1, audio_devices.size()); | 1279 EXPECT_EQ(init_nodes_size + 1, audio_devices.size()); |
1169 | 1280 |
1170 // Verify the active input device is switched to USB mic, and | 1281 // Verify the active input device is switched to USB mic, and |
1171 // and ActiveInputChanged event is fired. | 1282 // and ActiveInputChanged event is fired. |
1172 EXPECT_EQ(1, test_observer_->active_input_node_changed_count()); | 1283 EXPECT_EQ(1, test_observer_->active_input_node_changed_count()); |
1173 EXPECT_EQ(kUSBMic.id, cras_audio_handler_->GetActiveInputNode()); | 1284 EXPECT_EQ(kUSBMic.id, cras_audio_handler_->GetPrimaryActiveInputNode()); |
1174 EXPECT_TRUE(cras_audio_handler_->has_alternative_input()); | 1285 EXPECT_TRUE(cras_audio_handler_->has_alternative_input()); |
1175 | 1286 |
1176 // Verify the active output device is not changed. | 1287 // Verify the active output device is not changed. |
1177 EXPECT_EQ(1, test_observer_->active_output_node_changed_count()); | 1288 EXPECT_EQ(1, test_observer_->active_output_node_changed_count()); |
1178 EXPECT_TRUE(cras_audio_handler_->GetActiveOutputDevice(&active_output)); | 1289 EXPECT_TRUE( |
| 1290 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
1179 EXPECT_EQ(kInternalSpeaker.id, active_output.id); | 1291 EXPECT_EQ(kInternalSpeaker.id, active_output.id); |
1180 EXPECT_EQ(kInternalSpeaker.id, cras_audio_handler_->GetActiveOutputNode()); | 1292 EXPECT_EQ(kInternalSpeaker.id, |
| 1293 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
1181 } | 1294 } |
1182 | 1295 |
1183 TEST_F(CrasAudioHandlerTest, PlugHeadphoneAutoUnplugSpeakerWithActiveUSB) { | 1296 TEST_F(CrasAudioHandlerTest, PlugHeadphoneAutoUnplugSpeakerWithActiveUSB) { |
1184 // Set up initial audio devices. | 1297 // Set up initial audio devices. |
1185 AudioNodeList audio_nodes; | 1298 AudioNodeList audio_nodes; |
1186 audio_nodes.push_back(kUSBHeadphone1); | 1299 audio_nodes.push_back(kUSBHeadphone1); |
1187 audio_nodes.push_back(kInternalSpeaker); | 1300 audio_nodes.push_back(kInternalSpeaker); |
1188 audio_nodes.push_back(kInternalMic); | 1301 audio_nodes.push_back(kInternalMic); |
1189 SetUpCrasAudioHandler(audio_nodes); | 1302 SetUpCrasAudioHandler(audio_nodes); |
1190 const size_t init_nodes_size = audio_nodes.size(); | 1303 const size_t init_nodes_size = audio_nodes.size(); |
1191 | 1304 |
1192 // Verify the audio devices size. | 1305 // Verify the audio devices size. |
1193 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); | 1306 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); |
1194 AudioDeviceList audio_devices; | 1307 AudioDeviceList audio_devices; |
1195 cras_audio_handler_->GetAudioDevices(&audio_devices); | 1308 cras_audio_handler_->GetAudioDevices(&audio_devices); |
1196 EXPECT_EQ(init_nodes_size, audio_devices.size()); | 1309 EXPECT_EQ(init_nodes_size, audio_devices.size()); |
1197 | 1310 |
1198 // Verify the internal mic is selected as the active input. | 1311 // Verify the internal mic is selected as the active input. |
1199 EXPECT_EQ(0, test_observer_->active_input_node_changed_count()); | 1312 EXPECT_EQ(0, test_observer_->active_input_node_changed_count()); |
1200 EXPECT_EQ(kInternalMicId, cras_audio_handler_->GetActiveInputNode()); | 1313 EXPECT_EQ(kInternalMicId, cras_audio_handler_->GetPrimaryActiveInputNode()); |
1201 EXPECT_FALSE(cras_audio_handler_->has_alternative_input()); | 1314 EXPECT_FALSE(cras_audio_handler_->has_alternative_input()); |
1202 | 1315 |
1203 // Verify the USB headphone is selected as the active output. | 1316 // Verify the USB headphone is selected as the active output. |
1204 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); | 1317 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); |
1205 EXPECT_EQ(kUSBHeadphoneId1, cras_audio_handler_->GetActiveOutputNode()); | 1318 EXPECT_EQ(kUSBHeadphoneId1, |
| 1319 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
1206 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); | 1320 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
1207 | 1321 |
1208 // Plug the headphone and auto-unplug internal speaker. | 1322 // Plug the headphone and auto-unplug internal speaker. |
1209 audio_nodes.clear(); | 1323 audio_nodes.clear(); |
1210 AudioNode usb_headphone_node(kUSBHeadphone1); | 1324 AudioNode usb_headphone_node(kUSBHeadphone1); |
1211 usb_headphone_node.active = true; | 1325 usb_headphone_node.active = true; |
1212 audio_nodes.push_back(usb_headphone_node); | 1326 audio_nodes.push_back(usb_headphone_node); |
1213 AudioNode headphone_node(kHeadphone); | 1327 AudioNode headphone_node(kHeadphone); |
1214 headphone_node.plugged_time = 1000; | 1328 headphone_node.plugged_time = 1000; |
1215 audio_nodes.push_back(headphone_node); | 1329 audio_nodes.push_back(headphone_node); |
1216 AudioNode internal_mic(kInternalMic); | 1330 AudioNode internal_mic(kInternalMic); |
1217 internal_mic.active = true; | 1331 internal_mic.active = true; |
1218 audio_nodes.push_back(internal_mic); | 1332 audio_nodes.push_back(internal_mic); |
1219 ChangeAudioNodes(audio_nodes); | 1333 ChangeAudioNodes(audio_nodes); |
1220 | 1334 |
1221 // Verify the AudioNodesChanged event is fired, with nodes count unchanged. | 1335 // Verify the AudioNodesChanged event is fired, with nodes count unchanged. |
1222 EXPECT_EQ(1, test_observer_->audio_nodes_changed_count()); | 1336 EXPECT_EQ(1, test_observer_->audio_nodes_changed_count()); |
1223 cras_audio_handler_->GetAudioDevices(&audio_devices); | 1337 cras_audio_handler_->GetAudioDevices(&audio_devices); |
1224 EXPECT_EQ(init_nodes_size, audio_devices.size()); | 1338 EXPECT_EQ(init_nodes_size, audio_devices.size()); |
1225 | 1339 |
1226 // Verify the active output device is switched to headphone, and | 1340 // Verify the active output device is switched to headphone, and |
1227 // an ActiveOutputChanged event is fired. | 1341 // an ActiveOutputChanged event is fired. |
1228 EXPECT_EQ(1, test_observer_->active_output_node_changed_count()); | 1342 EXPECT_EQ(1, test_observer_->active_output_node_changed_count()); |
1229 EXPECT_EQ(kHeadphone.id, cras_audio_handler_->GetActiveOutputNode()); | 1343 EXPECT_EQ(kHeadphone.id, cras_audio_handler_->GetPrimaryActiveOutputNode()); |
1230 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); | 1344 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
1231 | 1345 |
1232 // Unplug the headphone and internal speaker auto-plugs back. | 1346 // Unplug the headphone and internal speaker auto-plugs back. |
1233 audio_nodes.clear(); | 1347 audio_nodes.clear(); |
1234 audio_nodes.push_back(kUSBHeadphone1); | 1348 audio_nodes.push_back(kUSBHeadphone1); |
1235 AudioNode internal_speaker_node(kInternalSpeaker); | 1349 AudioNode internal_speaker_node(kInternalSpeaker); |
1236 internal_speaker_node.plugged_time = 2000; | 1350 internal_speaker_node.plugged_time = 2000; |
1237 audio_nodes.push_back(internal_speaker_node); | 1351 audio_nodes.push_back(internal_speaker_node); |
1238 audio_nodes.push_back(internal_mic); | 1352 audio_nodes.push_back(internal_mic); |
1239 ChangeAudioNodes(audio_nodes); | 1353 ChangeAudioNodes(audio_nodes); |
1240 | 1354 |
1241 // Verify the AudioNodesChanged event is fired, with nodes count unchanged. | 1355 // Verify the AudioNodesChanged event is fired, with nodes count unchanged. |
1242 EXPECT_EQ(2, test_observer_->audio_nodes_changed_count()); | 1356 EXPECT_EQ(2, test_observer_->audio_nodes_changed_count()); |
1243 cras_audio_handler_->GetAudioDevices(&audio_devices); | 1357 cras_audio_handler_->GetAudioDevices(&audio_devices); |
1244 EXPECT_EQ(init_nodes_size, audio_devices.size()); | 1358 EXPECT_EQ(init_nodes_size, audio_devices.size()); |
1245 | 1359 |
1246 // Verify the active output device is switched back to USB, and | 1360 // Verify the active output device is switched back to USB, and |
1247 // an ActiveOutputChanged event is fired. | 1361 // an ActiveOutputChanged event is fired. |
1248 EXPECT_EQ(2, test_observer_->active_output_node_changed_count()); | 1362 EXPECT_EQ(2, test_observer_->active_output_node_changed_count()); |
1249 EXPECT_EQ(kUSBHeadphone1.id, cras_audio_handler_->GetActiveOutputNode()); | 1363 EXPECT_EQ(kUSBHeadphone1.id, |
| 1364 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
1250 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); | 1365 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
1251 | 1366 |
1252 // Verify the active input device is not changed. | 1367 // Verify the active input device is not changed. |
1253 EXPECT_EQ(0, test_observer_->active_input_node_changed_count()); | 1368 EXPECT_EQ(0, test_observer_->active_input_node_changed_count()); |
1254 EXPECT_EQ(kInternalMic.id, cras_audio_handler_->GetActiveInputNode()); | 1369 EXPECT_EQ(kInternalMic.id, cras_audio_handler_->GetPrimaryActiveInputNode()); |
1255 } | 1370 } |
1256 | 1371 |
1257 TEST_F(CrasAudioHandlerTest, PlugMicAutoUnplugInternalMicWithActiveUSB) { | 1372 TEST_F(CrasAudioHandlerTest, PlugMicAutoUnplugInternalMicWithActiveUSB) { |
1258 // Set up initial audio devices. | 1373 // Set up initial audio devices. |
1259 AudioNodeList audio_nodes; | 1374 AudioNodeList audio_nodes; |
1260 audio_nodes.push_back(kUSBHeadphone1); | 1375 audio_nodes.push_back(kUSBHeadphone1); |
1261 audio_nodes.push_back(kInternalSpeaker); | 1376 audio_nodes.push_back(kInternalSpeaker); |
1262 audio_nodes.push_back(kUSBMic); | 1377 audio_nodes.push_back(kUSBMic); |
1263 audio_nodes.push_back(kInternalMic); | 1378 audio_nodes.push_back(kInternalMic); |
1264 SetUpCrasAudioHandler(audio_nodes); | 1379 SetUpCrasAudioHandler(audio_nodes); |
1265 const size_t init_nodes_size = audio_nodes.size(); | 1380 const size_t init_nodes_size = audio_nodes.size(); |
1266 | 1381 |
1267 // Verify the audio devices size. | 1382 // Verify the audio devices size. |
1268 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); | 1383 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); |
1269 AudioDeviceList audio_devices; | 1384 AudioDeviceList audio_devices; |
1270 cras_audio_handler_->GetAudioDevices(&audio_devices); | 1385 cras_audio_handler_->GetAudioDevices(&audio_devices); |
1271 EXPECT_EQ(init_nodes_size, audio_devices.size()); | 1386 EXPECT_EQ(init_nodes_size, audio_devices.size()); |
1272 | 1387 |
1273 // Verify the internal mic is selected as the active input. | 1388 // Verify the internal mic is selected as the active input. |
1274 EXPECT_EQ(0, test_observer_->active_input_node_changed_count()); | 1389 EXPECT_EQ(0, test_observer_->active_input_node_changed_count()); |
1275 EXPECT_EQ(kUSBMicId, cras_audio_handler_->GetActiveInputNode()); | 1390 EXPECT_EQ(kUSBMicId, cras_audio_handler_->GetPrimaryActiveInputNode()); |
1276 EXPECT_TRUE(cras_audio_handler_->has_alternative_input()); | 1391 EXPECT_TRUE(cras_audio_handler_->has_alternative_input()); |
1277 | 1392 |
1278 // Verify the internal speaker is selected as the active output. | 1393 // Verify the internal speaker is selected as the active output. |
1279 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); | 1394 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); |
1280 EXPECT_EQ(kUSBHeadphoneId1, cras_audio_handler_->GetActiveOutputNode()); | 1395 EXPECT_EQ(kUSBHeadphoneId1, |
| 1396 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
1281 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); | 1397 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
1282 | 1398 |
1283 // Plug the headphone and mic, auto-unplug internal mic and speaker. | 1399 // Plug the headphone and mic, auto-unplug internal mic and speaker. |
1284 audio_nodes.clear(); | 1400 audio_nodes.clear(); |
1285 AudioNode usb_headphone_node(kUSBHeadphone1); | 1401 AudioNode usb_headphone_node(kUSBHeadphone1); |
1286 usb_headphone_node.active = true; | 1402 usb_headphone_node.active = true; |
1287 audio_nodes.push_back(usb_headphone_node); | 1403 audio_nodes.push_back(usb_headphone_node); |
1288 AudioNode headphone_node(kHeadphone); | 1404 AudioNode headphone_node(kHeadphone); |
1289 headphone_node.plugged_time = 1000; | 1405 headphone_node.plugged_time = 1000; |
1290 audio_nodes.push_back(headphone_node); | 1406 audio_nodes.push_back(headphone_node); |
1291 AudioNode usb_mic(kUSBMic); | 1407 AudioNode usb_mic(kUSBMic); |
1292 usb_mic.active = true; | 1408 usb_mic.active = true; |
1293 audio_nodes.push_back(usb_mic); | 1409 audio_nodes.push_back(usb_mic); |
1294 AudioNode mic_jack(kMicJack); | 1410 AudioNode mic_jack(kMicJack); |
1295 mic_jack.plugged_time = 1000; | 1411 mic_jack.plugged_time = 1000; |
1296 audio_nodes.push_back(mic_jack); | 1412 audio_nodes.push_back(mic_jack); |
1297 ChangeAudioNodes(audio_nodes); | 1413 ChangeAudioNodes(audio_nodes); |
1298 | 1414 |
1299 // Verify the AudioNodesChanged event is fired, with nodes count unchanged. | 1415 // Verify the AudioNodesChanged event is fired, with nodes count unchanged. |
1300 EXPECT_EQ(1, test_observer_->audio_nodes_changed_count()); | 1416 EXPECT_EQ(1, test_observer_->audio_nodes_changed_count()); |
1301 cras_audio_handler_->GetAudioDevices(&audio_devices); | 1417 cras_audio_handler_->GetAudioDevices(&audio_devices); |
1302 EXPECT_EQ(init_nodes_size, audio_devices.size()); | 1418 EXPECT_EQ(init_nodes_size, audio_devices.size()); |
1303 | 1419 |
1304 // Verify the active output device is switched to headphone, and | 1420 // Verify the active output device is switched to headphone, and |
1305 // an ActiveOutputChanged event is fired. | 1421 // an ActiveOutputChanged event is fired. |
1306 EXPECT_EQ(1, test_observer_->active_output_node_changed_count()); | 1422 EXPECT_EQ(1, test_observer_->active_output_node_changed_count()); |
1307 EXPECT_EQ(kHeadphone.id, cras_audio_handler_->GetActiveOutputNode()); | 1423 EXPECT_EQ(kHeadphone.id, cras_audio_handler_->GetPrimaryActiveOutputNode()); |
1308 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); | 1424 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
1309 | 1425 |
1310 // Verify the active input device is switched to mic jack, and | 1426 // Verify the active input device is switched to mic jack, and |
1311 // an ActiveInputChanged event is fired. | 1427 // an ActiveInputChanged event is fired. |
1312 EXPECT_EQ(1, test_observer_->active_input_node_changed_count()); | 1428 EXPECT_EQ(1, test_observer_->active_input_node_changed_count()); |
1313 EXPECT_EQ(kMicJack.id, cras_audio_handler_->GetActiveInputNode()); | 1429 EXPECT_EQ(kMicJack.id, cras_audio_handler_->GetPrimaryActiveInputNode()); |
1314 EXPECT_TRUE(cras_audio_handler_->has_alternative_input()); | 1430 EXPECT_TRUE(cras_audio_handler_->has_alternative_input()); |
1315 | 1431 |
1316 // Unplug the headphone and internal speaker auto-plugs back. | 1432 // Unplug the headphone and internal speaker auto-plugs back. |
1317 audio_nodes.clear(); | 1433 audio_nodes.clear(); |
1318 audio_nodes.push_back(kUSBHeadphone1); | 1434 audio_nodes.push_back(kUSBHeadphone1); |
1319 AudioNode internal_speaker_node(kInternalSpeaker); | 1435 AudioNode internal_speaker_node(kInternalSpeaker); |
1320 internal_speaker_node.plugged_time = 2000; | 1436 internal_speaker_node.plugged_time = 2000; |
1321 audio_nodes.push_back(internal_speaker_node); | 1437 audio_nodes.push_back(internal_speaker_node); |
1322 audio_nodes.push_back(kUSBMic); | 1438 audio_nodes.push_back(kUSBMic); |
1323 AudioNode internal_mic(kInternalMic); | 1439 AudioNode internal_mic(kInternalMic); |
1324 internal_mic.plugged_time = 2000; | 1440 internal_mic.plugged_time = 2000; |
1325 audio_nodes.push_back(internal_mic); | 1441 audio_nodes.push_back(internal_mic); |
1326 ChangeAudioNodes(audio_nodes); | 1442 ChangeAudioNodes(audio_nodes); |
1327 | 1443 |
1328 // Verify the AudioNodesChanged event is fired, with nodes count unchanged. | 1444 // Verify the AudioNodesChanged event is fired, with nodes count unchanged. |
1329 EXPECT_EQ(2, test_observer_->audio_nodes_changed_count()); | 1445 EXPECT_EQ(2, test_observer_->audio_nodes_changed_count()); |
1330 cras_audio_handler_->GetAudioDevices(&audio_devices); | 1446 cras_audio_handler_->GetAudioDevices(&audio_devices); |
1331 EXPECT_EQ(init_nodes_size, audio_devices.size()); | 1447 EXPECT_EQ(init_nodes_size, audio_devices.size()); |
1332 | 1448 |
1333 // Verify the active output device is switched back to USB, and | 1449 // Verify the active output device is switched back to USB, and |
1334 // an ActiveOutputChanged event is fired. | 1450 // an ActiveOutputChanged event is fired. |
1335 EXPECT_EQ(2, test_observer_->active_output_node_changed_count()); | 1451 EXPECT_EQ(2, test_observer_->active_output_node_changed_count()); |
1336 EXPECT_EQ(kUSBHeadphone1.id, cras_audio_handler_->GetActiveOutputNode()); | 1452 EXPECT_EQ(kUSBHeadphone1.id, |
| 1453 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
1337 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); | 1454 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
1338 | 1455 |
1339 // Verify the active input device is switched back to USB mic, and | 1456 // Verify the active input device is switched back to USB mic, and |
1340 // an ActiveInputChanged event is fired. | 1457 // an ActiveInputChanged event is fired. |
1341 EXPECT_EQ(2, test_observer_->active_input_node_changed_count()); | 1458 EXPECT_EQ(2, test_observer_->active_input_node_changed_count()); |
1342 EXPECT_EQ(kUSBMic.id, cras_audio_handler_->GetActiveInputNode()); | 1459 EXPECT_EQ(kUSBMic.id, cras_audio_handler_->GetPrimaryActiveInputNode()); |
1343 EXPECT_TRUE(cras_audio_handler_->has_alternative_input()); | 1460 EXPECT_TRUE(cras_audio_handler_->has_alternative_input()); |
1344 } | 1461 } |
1345 | 1462 |
1346 TEST_F(CrasAudioHandlerTest, MultipleNodesChangedSignalsOnPlugInHeadphone) { | 1463 TEST_F(CrasAudioHandlerTest, MultipleNodesChangedSignalsOnPlugInHeadphone) { |
1347 // Set up initial audio devices. | 1464 // Set up initial audio devices. |
1348 AudioNodeList audio_nodes; | 1465 AudioNodeList audio_nodes; |
1349 audio_nodes.push_back(kInternalSpeaker); | 1466 audio_nodes.push_back(kInternalSpeaker); |
1350 audio_nodes.push_back(kBluetoothHeadset); | 1467 audio_nodes.push_back(kBluetoothHeadset); |
1351 SetUpCrasAudioHandler(audio_nodes); | 1468 SetUpCrasAudioHandler(audio_nodes); |
1352 const size_t init_nodes_size = audio_nodes.size(); | 1469 const size_t init_nodes_size = audio_nodes.size(); |
1353 | 1470 |
1354 // Verify the audio devices size. | 1471 // Verify the audio devices size. |
1355 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); | 1472 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); |
1356 AudioDeviceList audio_devices; | 1473 AudioDeviceList audio_devices; |
1357 cras_audio_handler_->GetAudioDevices(&audio_devices); | 1474 cras_audio_handler_->GetAudioDevices(&audio_devices); |
1358 EXPECT_EQ(init_nodes_size, audio_devices.size()); | 1475 EXPECT_EQ(init_nodes_size, audio_devices.size()); |
1359 | 1476 |
1360 // Verify the bluetooth headset is selected as the active output. | 1477 // Verify the bluetooth headset is selected as the active output. |
1361 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); | 1478 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); |
1362 EXPECT_EQ(kBluetoothHeadsetId, cras_audio_handler_->GetActiveOutputNode()); | 1479 EXPECT_EQ(kBluetoothHeadsetId, |
| 1480 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
1363 AudioDevice active_output; | 1481 AudioDevice active_output; |
1364 EXPECT_TRUE(cras_audio_handler_->GetActiveOutputDevice(&active_output)); | 1482 EXPECT_TRUE( |
| 1483 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
1365 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); | 1484 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
1366 | 1485 |
1367 // Plug in headphone, but fire NodesChanged signal twice. | 1486 // Plug in headphone, but fire NodesChanged signal twice. |
1368 audio_nodes.clear(); | 1487 audio_nodes.clear(); |
1369 audio_nodes.push_back(kInternalSpeaker); | 1488 audio_nodes.push_back(kInternalSpeaker); |
1370 AudioNode bluetooth_headset(kBluetoothHeadset); | 1489 AudioNode bluetooth_headset(kBluetoothHeadset); |
1371 bluetooth_headset.plugged_time = 1000; | 1490 bluetooth_headset.plugged_time = 1000; |
1372 bluetooth_headset.active = true; | 1491 bluetooth_headset.active = true; |
1373 audio_nodes.push_back(bluetooth_headset); | 1492 audio_nodes.push_back(bluetooth_headset); |
1374 AudioNode headphone(kHeadphone); | 1493 AudioNode headphone(kHeadphone); |
1375 headphone.active = false; | 1494 headphone.active = false; |
1376 headphone.plugged_time = 2000; | 1495 headphone.plugged_time = 2000; |
1377 audio_nodes.push_back(headphone); | 1496 audio_nodes.push_back(headphone); |
1378 ChangeAudioNodes(audio_nodes); | 1497 ChangeAudioNodes(audio_nodes); |
1379 ChangeAudioNodes(audio_nodes); | 1498 ChangeAudioNodes(audio_nodes); |
1380 | 1499 |
1381 // Verify the active output device is set to headphone. | 1500 // Verify the active output device is set to headphone. |
1382 EXPECT_EQ(2, test_observer_->audio_nodes_changed_count()); | 1501 EXPECT_EQ(2, test_observer_->audio_nodes_changed_count()); |
1383 EXPECT_EQ(1, test_observer_->active_output_node_changed_count()); | 1502 EXPECT_LE(1, test_observer_->active_output_node_changed_count()); |
1384 EXPECT_EQ(headphone.id, cras_audio_handler_->GetActiveOutputNode()); | 1503 EXPECT_EQ(headphone.id, cras_audio_handler_->GetPrimaryActiveOutputNode()); |
1385 EXPECT_TRUE(cras_audio_handler_->GetActiveOutputDevice(&active_output)); | 1504 EXPECT_TRUE( |
| 1505 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
1386 EXPECT_EQ(headphone.id, active_output.id); | 1506 EXPECT_EQ(headphone.id, active_output.id); |
1387 | 1507 |
1388 // Verfiy the audio devices data is consistent, i.e., the active output device | 1508 // Verfiy the audio devices data is consistent, i.e., the active output device |
1389 // should be headphone. | 1509 // should be headphone. |
1390 cras_audio_handler_->GetAudioDevices(&audio_devices); | 1510 cras_audio_handler_->GetAudioDevices(&audio_devices); |
1391 EXPECT_EQ(init_nodes_size + 1, audio_devices.size()); | 1511 EXPECT_EQ(init_nodes_size + 1, audio_devices.size()); |
1392 for (size_t i = 0; i < audio_devices.size(); ++i) { | 1512 for (size_t i = 0; i < audio_devices.size(); ++i) { |
1393 if (audio_devices[i].id == kInternalSpeaker.id) | 1513 if (audio_devices[i].id == kInternalSpeaker.id) |
1394 EXPECT_FALSE(audio_devices[i].active); | 1514 EXPECT_FALSE(audio_devices[i].active); |
1395 else if (audio_devices[i].id == bluetooth_headset.id) | 1515 else if (audio_devices[i].id == bluetooth_headset.id) |
(...skipping 13 matching lines...) Expand all Loading... |
1409 const size_t init_nodes_size = audio_nodes.size(); | 1529 const size_t init_nodes_size = audio_nodes.size(); |
1410 | 1530 |
1411 // Verify the audio devices size. | 1531 // Verify the audio devices size. |
1412 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); | 1532 EXPECT_EQ(0, test_observer_->audio_nodes_changed_count()); |
1413 AudioDeviceList audio_devices; | 1533 AudioDeviceList audio_devices; |
1414 cras_audio_handler_->GetAudioDevices(&audio_devices); | 1534 cras_audio_handler_->GetAudioDevices(&audio_devices); |
1415 EXPECT_EQ(init_nodes_size, audio_devices.size()); | 1535 EXPECT_EQ(init_nodes_size, audio_devices.size()); |
1416 | 1536 |
1417 // Verify the internal mic is selected as the active output. | 1537 // Verify the internal mic is selected as the active output. |
1418 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); | 1538 EXPECT_EQ(0, test_observer_->active_output_node_changed_count()); |
1419 EXPECT_EQ(kInternalMic.id, cras_audio_handler_->GetActiveInputNode()); | 1539 EXPECT_EQ(kInternalMic.id, cras_audio_handler_->GetPrimaryActiveInputNode()); |
1420 EXPECT_FALSE(cras_audio_handler_->has_alternative_output()); | 1540 EXPECT_FALSE(cras_audio_handler_->has_alternative_output()); |
1421 EXPECT_TRUE(audio_devices[0].active); | 1541 EXPECT_TRUE(audio_devices[0].active); |
1422 | 1542 |
1423 // Plug in usb mic, but fire NodesChanged signal twice. | 1543 // Plug in usb mic, but fire NodesChanged signal twice. |
1424 audio_nodes.clear(); | 1544 audio_nodes.clear(); |
1425 AudioNode internal_mic(kInternalMic); | 1545 AudioNode internal_mic(kInternalMic); |
1426 internal_mic.active = true; | 1546 internal_mic.active = true; |
1427 internal_mic.plugged_time = 1000; | 1547 internal_mic.plugged_time = 1000; |
1428 audio_nodes.push_back(internal_mic); | 1548 audio_nodes.push_back(internal_mic); |
1429 AudioNode usb_mic(kUSBMic); | 1549 AudioNode usb_mic(kUSBMic); |
1430 usb_mic.active = false; | 1550 usb_mic.active = false; |
1431 usb_mic.plugged_time = 2000; | 1551 usb_mic.plugged_time = 2000; |
1432 audio_nodes.push_back(usb_mic); | 1552 audio_nodes.push_back(usb_mic); |
1433 ChangeAudioNodes(audio_nodes); | 1553 ChangeAudioNodes(audio_nodes); |
1434 ChangeAudioNodes(audio_nodes); | 1554 ChangeAudioNodes(audio_nodes); |
1435 | 1555 |
1436 // Verify the active output device is set to headphone. | 1556 // Verify the active output device is set to headphone. |
1437 EXPECT_EQ(2, test_observer_->audio_nodes_changed_count()); | 1557 EXPECT_EQ(2, test_observer_->audio_nodes_changed_count()); |
1438 EXPECT_EQ(1, test_observer_->active_input_node_changed_count()); | 1558 EXPECT_LE(1, test_observer_->active_input_node_changed_count()); |
1439 EXPECT_EQ(usb_mic.id, cras_audio_handler_->GetActiveInputNode()); | 1559 EXPECT_EQ(usb_mic.id, cras_audio_handler_->GetPrimaryActiveInputNode()); |
1440 EXPECT_TRUE(cras_audio_handler_->has_alternative_input()); | 1560 EXPECT_TRUE(cras_audio_handler_->has_alternative_input()); |
1441 | 1561 |
1442 // Verfiy the audio devices data is consistent, i.e., the active input device | 1562 // Verfiy the audio devices data is consistent, i.e., the active input device |
1443 // should be usb mic. | 1563 // should be usb mic. |
1444 cras_audio_handler_->GetAudioDevices(&audio_devices); | 1564 cras_audio_handler_->GetAudioDevices(&audio_devices); |
1445 EXPECT_EQ(init_nodes_size + 1, audio_devices.size()); | 1565 EXPECT_EQ(init_nodes_size + 1, audio_devices.size()); |
1446 for (size_t i = 0; i < audio_devices.size(); ++i) { | 1566 for (size_t i = 0; i < audio_devices.size(); ++i) { |
1447 if (audio_devices[i].id == kInternalMic.id) | 1567 if (audio_devices[i].id == kInternalMic.id) |
1448 EXPECT_FALSE(audio_devices[i].active); | 1568 EXPECT_FALSE(audio_devices[i].active); |
1449 else if (audio_devices[i].id == usb_mic.id) | 1569 else if (audio_devices[i].id == usb_mic.id) |
(...skipping 19 matching lines...) Expand all Loading... |
1469 audio_nodes.push_back(headphone); | 1589 audio_nodes.push_back(headphone); |
1470 audio_nodes.push_back(internal_mic); | 1590 audio_nodes.push_back(internal_mic); |
1471 const size_t init_nodes_size = audio_nodes.size(); | 1591 const size_t init_nodes_size = audio_nodes.size(); |
1472 | 1592 |
1473 // Simulate AudioNodesChanged signal being fired twice during system boot. | 1593 // Simulate AudioNodesChanged signal being fired twice during system boot. |
1474 ChangeAudioNodes(audio_nodes); | 1594 ChangeAudioNodes(audio_nodes); |
1475 ChangeAudioNodes(audio_nodes); | 1595 ChangeAudioNodes(audio_nodes); |
1476 | 1596 |
1477 // Verify the active output device is set to headphone. | 1597 // Verify the active output device is set to headphone. |
1478 EXPECT_EQ(2, test_observer_->audio_nodes_changed_count()); | 1598 EXPECT_EQ(2, test_observer_->audio_nodes_changed_count()); |
1479 EXPECT_EQ(1, test_observer_->active_output_node_changed_count()); | 1599 EXPECT_LE(1, test_observer_->active_output_node_changed_count()); |
1480 EXPECT_EQ(headphone.id, cras_audio_handler_->GetActiveOutputNode()); | 1600 EXPECT_EQ(headphone.id, cras_audio_handler_->GetPrimaryActiveOutputNode()); |
1481 AudioDevice active_output; | 1601 AudioDevice active_output; |
1482 EXPECT_TRUE(cras_audio_handler_->GetActiveOutputDevice(&active_output)); | 1602 EXPECT_TRUE( |
| 1603 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
1483 EXPECT_EQ(headphone.id, active_output.id); | 1604 EXPECT_EQ(headphone.id, active_output.id); |
1484 | 1605 |
1485 // Verify the active input device id is set to internal mic. | 1606 // Verify the active input device id is set to internal mic. |
1486 EXPECT_EQ(internal_mic.id, cras_audio_handler_->GetActiveInputNode()); | 1607 EXPECT_EQ(internal_mic.id, cras_audio_handler_->GetPrimaryActiveInputNode()); |
1487 | 1608 |
1488 // Verfiy the audio devices data is consistent, i.e., the active output device | 1609 // Verfiy the audio devices data is consistent, i.e., the active output device |
1489 // should be headphone, and the active input device should internal mic. | 1610 // should be headphone, and the active input device should internal mic. |
1490 AudioDeviceList audio_devices; | 1611 AudioDeviceList audio_devices; |
1491 cras_audio_handler_->GetAudioDevices(&audio_devices); | 1612 cras_audio_handler_->GetAudioDevices(&audio_devices); |
1492 EXPECT_EQ(init_nodes_size, audio_devices.size()); | 1613 EXPECT_EQ(init_nodes_size, audio_devices.size()); |
1493 for (size_t i = 0; i < audio_devices.size(); ++i) { | 1614 for (size_t i = 0; i < audio_devices.size(); ++i) { |
1494 if (audio_devices[i].id == internal_speaker.id) | 1615 if (audio_devices[i].id == internal_speaker.id) |
1495 EXPECT_FALSE(audio_devices[i].active); | 1616 EXPECT_FALSE(audio_devices[i].active); |
1496 else if (audio_devices[i].id == headphone.id) | 1617 else if (audio_devices[i].id == headphone.id) |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1557 | 1678 |
1558 cras_audio_handler_->SetOutputVolumePercent(60); | 1679 cras_audio_handler_->SetOutputVolumePercent(60); |
1559 | 1680 |
1560 // Verify the output volume is changed to the designated value, | 1681 // Verify the output volume is changed to the designated value, |
1561 // OnOutputVolumeChanged event is fired, and the device volume value | 1682 // OnOutputVolumeChanged event is fired, and the device volume value |
1562 // is saved the preferences. | 1683 // is saved the preferences. |
1563 const int kVolume = 60; | 1684 const int kVolume = 60; |
1564 EXPECT_EQ(kVolume, cras_audio_handler_->GetOutputVolumePercent()); | 1685 EXPECT_EQ(kVolume, cras_audio_handler_->GetOutputVolumePercent()); |
1565 EXPECT_EQ(1, test_observer_->output_volume_changed_count()); | 1686 EXPECT_EQ(1, test_observer_->output_volume_changed_count()); |
1566 AudioDevice device; | 1687 AudioDevice device; |
1567 EXPECT_TRUE(cras_audio_handler_->GetActiveOutputDevice(&device)); | 1688 EXPECT_TRUE(cras_audio_handler_->GetPrimaryActiveOutputDevice(&device)); |
1568 EXPECT_EQ(device.id, kInternalSpeaker.id); | 1689 EXPECT_EQ(device.id, kInternalSpeaker.id); |
1569 EXPECT_EQ(kVolume, audio_pref_handler_->GetOutputVolumeValue(&device)); | 1690 EXPECT_EQ(kVolume, audio_pref_handler_->GetOutputVolumeValue(&device)); |
1570 } | 1691 } |
1571 | 1692 |
1572 TEST_F(CrasAudioHandlerTest, SetInputGainPercent) { | 1693 TEST_F(CrasAudioHandlerTest, SetInputGainPercent) { |
1573 AudioNodeList audio_nodes; | 1694 AudioNodeList audio_nodes; |
1574 audio_nodes.push_back(kInternalMic); | 1695 audio_nodes.push_back(kInternalMic); |
1575 SetUpCrasAudioHandler(audio_nodes); | 1696 SetUpCrasAudioHandler(audio_nodes); |
1576 EXPECT_EQ(0, test_observer_->input_gain_changed_count()); | 1697 EXPECT_EQ(0, test_observer_->input_gain_changed_count()); |
1577 | 1698 |
(...skipping 11 matching lines...) Expand all Loading... |
1589 | 1710 |
1590 TEST_F(CrasAudioHandlerTest, SetMuteForDevice) { | 1711 TEST_F(CrasAudioHandlerTest, SetMuteForDevice) { |
1591 AudioNodeList audio_nodes; | 1712 AudioNodeList audio_nodes; |
1592 audio_nodes.push_back(kInternalSpeaker); | 1713 audio_nodes.push_back(kInternalSpeaker); |
1593 audio_nodes.push_back(kHeadphone); | 1714 audio_nodes.push_back(kHeadphone); |
1594 audio_nodes.push_back(kInternalMic); | 1715 audio_nodes.push_back(kInternalMic); |
1595 audio_nodes.push_back(kUSBMic); | 1716 audio_nodes.push_back(kUSBMic); |
1596 SetUpCrasAudioHandler(audio_nodes); | 1717 SetUpCrasAudioHandler(audio_nodes); |
1597 | 1718 |
1598 // Mute the active output device. | 1719 // Mute the active output device. |
1599 EXPECT_EQ(kHeadphone.id, cras_audio_handler_->GetActiveOutputNode()); | 1720 EXPECT_EQ(kHeadphone.id, cras_audio_handler_->GetPrimaryActiveOutputNode()); |
1600 cras_audio_handler_->SetMuteForDevice(kHeadphone.id, true); | 1721 cras_audio_handler_->SetMuteForDevice(kHeadphone.id, true); |
1601 | 1722 |
1602 // Verify the headphone is muted and mute value is saved in the preferences. | 1723 // Verify the headphone is muted and mute value is saved in the preferences. |
1603 EXPECT_TRUE(cras_audio_handler_->IsOutputMutedForDevice(kHeadphone.id)); | 1724 EXPECT_TRUE(cras_audio_handler_->IsOutputMutedForDevice(kHeadphone.id)); |
1604 AudioDevice headphone(kHeadphone); | 1725 AudioDevice headphone(kHeadphone); |
1605 EXPECT_TRUE(audio_pref_handler_->GetMuteValue(headphone)); | 1726 EXPECT_TRUE(audio_pref_handler_->GetMuteValue(headphone)); |
1606 | 1727 |
1607 // Mute the non-active output device. | 1728 // Mute the non-active output device. |
1608 cras_audio_handler_->SetMuteForDevice(kInternalSpeaker.id, true); | 1729 cras_audio_handler_->SetMuteForDevice(kInternalSpeaker.id, true); |
1609 | 1730 |
1610 // Verify the internal speaker is muted and mute value is saved in the | 1731 // Verify the internal speaker is muted and mute value is saved in the |
1611 // preferences. | 1732 // preferences. |
1612 EXPECT_TRUE(cras_audio_handler_->IsOutputMutedForDevice(kInternalSpeaker.id)); | 1733 EXPECT_TRUE(cras_audio_handler_->IsOutputMutedForDevice(kInternalSpeaker.id)); |
1613 AudioDevice internal_speaker(kInternalSpeaker); | 1734 AudioDevice internal_speaker(kInternalSpeaker); |
1614 EXPECT_TRUE(audio_pref_handler_->GetMuteValue(internal_speaker)); | 1735 EXPECT_TRUE(audio_pref_handler_->GetMuteValue(internal_speaker)); |
1615 | 1736 |
1616 // Mute the active input device. | 1737 // Mute the active input device. |
1617 EXPECT_EQ(kUSBMic.id, cras_audio_handler_->GetActiveInputNode()); | 1738 EXPECT_EQ(kUSBMic.id, cras_audio_handler_->GetPrimaryActiveInputNode()); |
1618 cras_audio_handler_->SetMuteForDevice(kUSBMic.id, true); | 1739 cras_audio_handler_->SetMuteForDevice(kUSBMic.id, true); |
1619 | 1740 |
1620 // Verify the USB Mic is muted. | 1741 // Verify the USB Mic is muted. |
1621 EXPECT_TRUE(cras_audio_handler_->IsInputMutedForDevice(kUSBMic.id)); | 1742 EXPECT_TRUE(cras_audio_handler_->IsInputMutedForDevice(kUSBMic.id)); |
1622 | 1743 |
1623 // Mute the non-active input device should be a no-op, see crbug.com/365050. | 1744 // Mute the non-active input device should be a no-op, see crbug.com/365050. |
1624 cras_audio_handler_->SetMuteForDevice(kInternalMic.id, true); | 1745 cras_audio_handler_->SetMuteForDevice(kInternalMic.id, true); |
1625 | 1746 |
1626 // Verify IsInputMutedForDevice returns false for non-active input device. | 1747 // Verify IsInputMutedForDevice returns false for non-active input device. |
1627 EXPECT_FALSE(cras_audio_handler_->IsInputMutedForDevice(kInternalMic.id)); | 1748 EXPECT_FALSE(cras_audio_handler_->IsInputMutedForDevice(kInternalMic.id)); |
1628 } | 1749 } |
1629 | 1750 |
1630 TEST_F(CrasAudioHandlerTest, SetVolumeGainPercentForDevice) { | 1751 TEST_F(CrasAudioHandlerTest, SetVolumeGainPercentForDevice) { |
1631 AudioNodeList audio_nodes; | 1752 AudioNodeList audio_nodes; |
1632 audio_nodes.push_back(kInternalSpeaker); | 1753 audio_nodes.push_back(kInternalSpeaker); |
1633 audio_nodes.push_back(kHeadphone); | 1754 audio_nodes.push_back(kHeadphone); |
1634 audio_nodes.push_back(kInternalMic); | 1755 audio_nodes.push_back(kInternalMic); |
1635 audio_nodes.push_back(kUSBMic); | 1756 audio_nodes.push_back(kUSBMic); |
1636 SetUpCrasAudioHandler(audio_nodes); | 1757 SetUpCrasAudioHandler(audio_nodes); |
1637 | 1758 |
1638 // Set volume percent for active output device. | 1759 // Set volume percent for active output device. |
1639 const int kHeadphoneVolume = 30; | 1760 const int kHeadphoneVolume = 30; |
1640 EXPECT_EQ(kHeadphone.id, cras_audio_handler_->GetActiveOutputNode()); | 1761 EXPECT_EQ(kHeadphone.id, cras_audio_handler_->GetPrimaryActiveOutputNode()); |
1641 cras_audio_handler_->SetVolumeGainPercentForDevice(kHeadphone.id, | 1762 cras_audio_handler_->SetVolumeGainPercentForDevice(kHeadphone.id, |
1642 kHeadphoneVolume); | 1763 kHeadphoneVolume); |
1643 | 1764 |
1644 // Verify the volume percent of headphone is set, and saved in preferences. | 1765 // Verify the volume percent of headphone is set, and saved in preferences. |
1645 EXPECT_EQ(kHeadphoneVolume, | 1766 EXPECT_EQ(kHeadphoneVolume, |
1646 cras_audio_handler_->GetOutputVolumePercentForDevice( | 1767 cras_audio_handler_->GetOutputVolumePercentForDevice( |
1647 kHeadphone.id)); | 1768 kHeadphone.id)); |
1648 AudioDevice headphone(kHeadphone); | 1769 AudioDevice headphone(kHeadphone); |
1649 EXPECT_EQ(kHeadphoneVolume, | 1770 EXPECT_EQ(kHeadphoneVolume, |
1650 audio_pref_handler_->GetOutputVolumeValue(&headphone)); | 1771 audio_pref_handler_->GetOutputVolumeValue(&headphone)); |
1651 | 1772 |
1652 // Set volume percent for non-active output device. | 1773 // Set volume percent for non-active output device. |
1653 const int kSpeakerVolume = 60; | 1774 const int kSpeakerVolume = 60; |
1654 cras_audio_handler_->SetVolumeGainPercentForDevice(kInternalSpeaker.id, | 1775 cras_audio_handler_->SetVolumeGainPercentForDevice(kInternalSpeaker.id, |
1655 kSpeakerVolume); | 1776 kSpeakerVolume); |
1656 | 1777 |
1657 // Verify the volume percent of speaker is set, and saved in preferences. | 1778 // Verify the volume percent of speaker is set, and saved in preferences. |
1658 EXPECT_EQ(kSpeakerVolume, | 1779 EXPECT_EQ(kSpeakerVolume, |
1659 cras_audio_handler_->GetOutputVolumePercentForDevice( | 1780 cras_audio_handler_->GetOutputVolumePercentForDevice( |
1660 kInternalSpeaker.id)); | 1781 kInternalSpeaker.id)); |
1661 AudioDevice speaker(kInternalSpeaker); | 1782 AudioDevice speaker(kInternalSpeaker); |
1662 EXPECT_EQ(kSpeakerVolume, | 1783 EXPECT_EQ(kSpeakerVolume, |
1663 audio_pref_handler_->GetOutputVolumeValue(&speaker)); | 1784 audio_pref_handler_->GetOutputVolumeValue(&speaker)); |
1664 | 1785 |
1665 // Set gain percent for active input device. | 1786 // Set gain percent for active input device. |
1666 const int kUSBMicGain = 30; | 1787 const int kUSBMicGain = 30; |
1667 EXPECT_EQ(kUSBMic.id, cras_audio_handler_->GetActiveInputNode()); | 1788 EXPECT_EQ(kUSBMic.id, cras_audio_handler_->GetPrimaryActiveInputNode()); |
1668 cras_audio_handler_->SetVolumeGainPercentForDevice(kUSBMic.id, | 1789 cras_audio_handler_->SetVolumeGainPercentForDevice(kUSBMic.id, |
1669 kUSBMicGain); | 1790 kUSBMicGain); |
1670 | 1791 |
1671 // Verify the gain percent of USB mic is set, and saved in preferences. | 1792 // Verify the gain percent of USB mic is set, and saved in preferences. |
1672 EXPECT_EQ(kUSBMicGain, | 1793 EXPECT_EQ(kUSBMicGain, |
1673 cras_audio_handler_->GetOutputVolumePercentForDevice(kUSBMic.id)); | 1794 cras_audio_handler_->GetOutputVolumePercentForDevice(kUSBMic.id)); |
1674 AudioDevice usb_mic(kHeadphone); | 1795 AudioDevice usb_mic(kHeadphone); |
1675 EXPECT_EQ(kUSBMicGain, | 1796 EXPECT_EQ(kUSBMicGain, |
1676 audio_pref_handler_->GetInputGainValue(&usb_mic)); | 1797 audio_pref_handler_->GetInputGainValue(&usb_mic)); |
1677 | 1798 |
(...skipping 21 matching lines...) Expand all Loading... |
1699 SetUpCrasAudioHandler(audio_nodes); | 1820 SetUpCrasAudioHandler(audio_nodes); |
1700 | 1821 |
1701 // Verify the audio devices size. | 1822 // Verify the audio devices size. |
1702 AudioDeviceList audio_devices; | 1823 AudioDeviceList audio_devices; |
1703 cras_audio_handler_->GetAudioDevices(&audio_devices); | 1824 cras_audio_handler_->GetAudioDevices(&audio_devices); |
1704 EXPECT_EQ(kNumValidAudioDevices, audio_devices.size()); | 1825 EXPECT_EQ(kNumValidAudioDevices, audio_devices.size()); |
1705 | 1826 |
1706 // Verify the internal speaker has been selected as the active output, | 1827 // Verify the internal speaker has been selected as the active output, |
1707 // and the output device with some randown unknown type is handled gracefully. | 1828 // and the output device with some randown unknown type is handled gracefully. |
1708 AudioDevice active_output; | 1829 AudioDevice active_output; |
1709 EXPECT_TRUE(cras_audio_handler_->GetActiveOutputDevice(&active_output)); | 1830 EXPECT_TRUE( |
| 1831 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
1710 EXPECT_EQ(kInternalSpeaker.id, active_output.id); | 1832 EXPECT_EQ(kInternalSpeaker.id, active_output.id); |
1711 EXPECT_EQ(kInternalSpeaker.id, cras_audio_handler_->GetActiveOutputNode()); | 1833 EXPECT_EQ(kInternalSpeaker.id, |
| 1834 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
1712 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); | 1835 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
1713 | 1836 |
1714 // Ensure the internal microphone has been selected as the active input, | 1837 // Ensure the internal microphone has been selected as the active input, |
1715 // and the input device with some random unknown type is handled gracefully. | 1838 // and the input device with some random unknown type is handled gracefully. |
1716 AudioDevice active_input; | 1839 AudioDevice active_input; |
1717 EXPECT_EQ(kInternalMic.id, cras_audio_handler_->GetActiveInputNode()); | 1840 EXPECT_EQ(kInternalMic.id, cras_audio_handler_->GetPrimaryActiveInputNode()); |
1718 EXPECT_TRUE(cras_audio_handler_->has_alternative_input()); | 1841 EXPECT_TRUE(cras_audio_handler_->has_alternative_input()); |
1719 } | 1842 } |
1720 | 1843 |
| 1844 TEST_F(CrasAudioHandlerTest, MultipleActiveNodes) { |
| 1845 AudioNodeList audio_nodes; |
| 1846 audio_nodes.push_back(kInternalSpeaker); |
| 1847 audio_nodes.push_back(kUSBHeadphone1); |
| 1848 audio_nodes.push_back(kUSBHeadphone2); |
| 1849 SetUpCrasAudioHandler(audio_nodes); |
| 1850 |
| 1851 // Verify the audio devices size. |
| 1852 AudioDeviceList audio_devices; |
| 1853 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 1854 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); |
| 1855 |
| 1856 // Verify only 1 node is selected as active node by CrasAudioHandler. |
| 1857 AudioDevice active_output; |
| 1858 EXPECT_TRUE( |
| 1859 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
| 1860 int num_active_nodes = 0; |
| 1861 for (size_t i = 0; i < audio_devices.size(); ++i) { |
| 1862 if (audio_devices[i].active) |
| 1863 ++num_active_nodes; |
| 1864 } |
| 1865 EXPECT_EQ(1, num_active_nodes); |
| 1866 |
| 1867 // Switch the active output to internal speaker and mute it. |
| 1868 const AudioDevice* internal_speaker = GetDeviceFromId(kInternalSpeaker.id); |
| 1869 cras_audio_handler_->SwitchToDevice(*internal_speaker); |
| 1870 cras_audio_handler_->SetOutputMute(true); |
| 1871 EXPECT_TRUE(cras_audio_handler_->IsOutputMutedForDevice(kInternalSpeaker.id)); |
| 1872 |
| 1873 // Remove all active nodes. |
| 1874 cras_audio_handler_->RemoveAllActiveNodes(); |
| 1875 |
| 1876 // Verify there is no active nodes. |
| 1877 num_active_nodes = 0; |
| 1878 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 1879 for (size_t i = 0; i < audio_devices.size(); ++i) { |
| 1880 if (audio_devices[i].active) |
| 1881 ++num_active_nodes; |
| 1882 } |
| 1883 EXPECT_EQ(0, num_active_nodes); |
| 1884 |
| 1885 // Adds both USB headphones to active nodes. |
| 1886 cras_audio_handler_->AddActiveNode(kUSBHeadphone1.id); |
| 1887 cras_audio_handler_->AddActiveNode(kUSBHeadphone2.id); |
| 1888 |
| 1889 // Verify both USB headphone nodes are made active. |
| 1890 num_active_nodes = 0; |
| 1891 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 1892 for (size_t i = 0; i < audio_devices.size(); ++i) { |
| 1893 if (audio_devices[i].active) |
| 1894 ++num_active_nodes; |
| 1895 } |
| 1896 EXPECT_EQ(2, num_active_nodes); |
| 1897 const AudioDevice* active_device_1 = GetDeviceFromId(kUSBHeadphone1.id); |
| 1898 EXPECT_TRUE(active_device_1->active); |
| 1899 const AudioDevice* active_device_2 = GetDeviceFromId(kUSBHeadphone2.id); |
| 1900 EXPECT_TRUE(active_device_2->active); |
| 1901 AudioDevice primary_active_device; |
| 1902 EXPECT_TRUE(cras_audio_handler_->GetPrimaryActiveOutputDevice( |
| 1903 &primary_active_device)); |
| 1904 EXPECT_EQ(kUSBHeadphone1.id, primary_active_device.id); |
| 1905 |
| 1906 // Verify all active devices are the not muted and their volume values are |
| 1907 // the same. |
| 1908 EXPECT_FALSE(cras_audio_handler_->IsOutputMuted()); |
| 1909 EXPECT_FALSE(cras_audio_handler_->IsOutputMutedForDevice(kUSBHeadphone1.id)); |
| 1910 EXPECT_FALSE(cras_audio_handler_->IsOutputMutedForDevice(kUSBHeadphone2.id)); |
| 1911 EXPECT_EQ( |
| 1912 cras_audio_handler_->GetOutputVolumePercent(), |
| 1913 cras_audio_handler_->GetOutputVolumePercentForDevice(kUSBHeadphone1.id)); |
| 1914 EXPECT_EQ( |
| 1915 cras_audio_handler_->GetOutputVolumePercent(), |
| 1916 cras_audio_handler_->GetOutputVolumePercentForDevice(kUSBHeadphone2.id)); |
| 1917 |
| 1918 // Adjust the volume of output devices, verify all active nodes are set to |
| 1919 // the same volume. |
| 1920 cras_audio_handler_->SetOutputVolumePercent(25); |
| 1921 EXPECT_EQ(25, cras_audio_handler_->GetOutputVolumePercent()); |
| 1922 EXPECT_EQ( |
| 1923 25, |
| 1924 cras_audio_handler_->GetOutputVolumePercentForDevice(kUSBHeadphone1.id)); |
| 1925 EXPECT_EQ( |
| 1926 25, |
| 1927 cras_audio_handler_->GetOutputVolumePercentForDevice(kUSBHeadphone2.id)); |
| 1928 |
| 1929 // Add one more active node that is previously muted, verify it is not muted |
| 1930 // after made active, and set to the same volume as the rest of the active |
| 1931 // nodes. |
| 1932 cras_audio_handler_->AddActiveNode(kInternalSpeaker.id); |
| 1933 EXPECT_FALSE( |
| 1934 cras_audio_handler_->IsOutputMutedForDevice(kInternalSpeaker.id)); |
| 1935 EXPECT_EQ(25, |
| 1936 cras_audio_handler_->GetOutputVolumePercentForDevice( |
| 1937 kInternalSpeaker.id)); |
| 1938 } |
| 1939 |
1721 } // namespace chromeos | 1940 } // namespace chromeos |
OLD | NEW |