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

Side by Side Diff: chromeos/audio/cras_audio_handler_unittest.cc

Issue 2605983002: Simplify logic behind chrome.audio.setActiveDevices (Closed)
Patch Set: . Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chromeos/audio/cras_audio_handler.cc ('k') | extensions/browser/api/audio/audio_api.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chromeos/audio/cras_audio_handler.h" 5 #include "chromeos/audio/cras_audio_handler.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
(...skipping 2502 matching lines...) Expand 10 before | Expand all | Expand 10 after
2513 ChangeAudioNodes(audio_nodes); 2513 ChangeAudioNodes(audio_nodes);
2514 2514
2515 // Verify the active output remains as internal speaker. 2515 // Verify the active output remains as internal speaker.
2516 cras_audio_handler_->GetAudioDevices(&audio_devices); 2516 cras_audio_handler_->GetAudioDevices(&audio_devices);
2517 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); 2517 EXPECT_EQ(audio_nodes.size(), audio_devices.size());
2518 EXPECT_EQ(kInternalSpeaker->id, 2518 EXPECT_EQ(kInternalSpeaker->id,
2519 cras_audio_handler_->GetPrimaryActiveOutputNode()); 2519 cras_audio_handler_->GetPrimaryActiveOutputNode());
2520 } 2520 }
2521 2521
2522 TEST_P(CrasAudioHandlerTest, ChangeActiveNodesHotrodInit) { 2522 TEST_P(CrasAudioHandlerTest, ChangeActiveNodesHotrodInit) {
2523 // This simulates a typical hotrod audio device configuration.
2523 AudioNodeList audio_nodes = GenerateAudioNodeList( 2524 AudioNodeList audio_nodes = GenerateAudioNodeList(
2524 {kHDMIOutput, kUSBJabraSpeakerOutput1, kUSBJabraSpeakerOutput2, 2525 {kHDMIOutput, kUSBJabraSpeakerOutput1, kUSBJabraSpeakerOutput2,
2525 kUSBJabraSpeakerInput1, kUSBJabraSpeakerInput2, kUSBCameraInput}); 2526 kUSBJabraSpeakerInput1, kUSBJabraSpeakerInput2, kUSBCameraInput});
2526 SetUpCrasAudioHandler(audio_nodes); 2527 SetUpCrasAudioHandler(audio_nodes);
2527 2528
2528 // Verify the audio devices size. 2529 // Verify the audio devices size.
2529 AudioDeviceList audio_devices; 2530 AudioDeviceList audio_devices;
2530 cras_audio_handler_->GetAudioDevices(&audio_devices); 2531 cras_audio_handler_->GetAudioDevices(&audio_devices);
2531 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); 2532 EXPECT_EQ(audio_nodes.size(), audio_devices.size());
2532 2533
2533 // Verify only the 1st jabra speaker's output and input are selected as active 2534 // Verify only the 1st jabra speaker's output and input are selected as active
2534 // nodes by CrasAudioHandler. 2535 // nodes by CrasAudioHandler.
2535 AudioDevice active_output; 2536 AudioDevice active_output;
2536 EXPECT_TRUE( 2537 EXPECT_TRUE(
2537 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); 2538 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output));
2538 EXPECT_EQ(2, GetActiveDeviceCount()); 2539 EXPECT_EQ(2, GetActiveDeviceCount());
2539 AudioDevice primary_active_device; 2540 AudioDevice primary_active_device;
2540 EXPECT_TRUE(cras_audio_handler_->GetPrimaryActiveOutputDevice( 2541 EXPECT_TRUE(cras_audio_handler_->GetPrimaryActiveOutputDevice(
2541 &primary_active_device)); 2542 &primary_active_device));
2542 EXPECT_EQ(kUSBJabraSpeakerOutput1->id, primary_active_device.id); 2543 EXPECT_EQ(kUSBJabraSpeakerOutput1->id, primary_active_device.id);
2543 EXPECT_EQ(kUSBJabraSpeakerInput1->id, 2544 EXPECT_EQ(kUSBJabraSpeakerInput1->id,
2544 cras_audio_handler_->GetPrimaryActiveInputNode()); 2545 cras_audio_handler_->GetPrimaryActiveInputNode());
2545 2546
2546 // Set both jabra speakers's input and output nodes to active, this simulate 2547 // Set both jabra speakers's input and output nodes to active, this simulate
2547 // the call sent by hotrod initialization process. 2548 // the call sent by hotrod initialization process.
2548 test_observer_->reset_active_output_node_changed_count(); 2549 test_observer_->reset_active_output_node_changed_count();
2549 test_observer_->reset_active_input_node_changed_count(); 2550 test_observer_->reset_active_input_node_changed_count();
2550 CrasAudioHandler::NodeIdList active_nodes; 2551 cras_audio_handler_->ChangeActiveNodes(
2551 active_nodes.push_back(kUSBJabraSpeakerOutput1->id); 2552 {kUSBJabraSpeakerOutput1->id, kUSBJabraSpeakerOutput2->id,
2552 active_nodes.push_back(kUSBJabraSpeakerOutput2->id); 2553 kUSBJabraSpeakerInput1->id, kUSBJabraSpeakerInput2->id});
2553 active_nodes.push_back(kUSBJabraSpeakerInput1->id);
2554 active_nodes.push_back(kUSBJabraSpeakerInput2->id);
2555 cras_audio_handler_->ChangeActiveNodes(active_nodes);
2556 2554
2557 // Verify both jabra speakers' input/output nodes are made active. 2555 // Verify both jabra speakers' input/output nodes are made active.
2558 // num_active_nodes = GetActiveDeviceCount(); 2556 // num_active_nodes = GetActiveDeviceCount();
2559 EXPECT_EQ(4, GetActiveDeviceCount()); 2557 EXPECT_EQ(4, GetActiveDeviceCount());
2560 const AudioDevice* active_output_1 = 2558 const AudioDevice* active_output_1 =
2561 GetDeviceFromId(kUSBJabraSpeakerOutput1->id); 2559 GetDeviceFromId(kUSBJabraSpeakerOutput1->id);
2562 EXPECT_TRUE(active_output_1->active); 2560 EXPECT_TRUE(active_output_1->active);
2563 const AudioDevice* active_output_2 = 2561 const AudioDevice* active_output_2 =
2564 GetDeviceFromId(kUSBJabraSpeakerOutput2->id); 2562 GetDeviceFromId(kUSBJabraSpeakerOutput2->id);
2565 EXPECT_TRUE(active_output_2->active); 2563 EXPECT_TRUE(active_output_2->active);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
2597 // Adjust the volume of output devices, verify all active nodes are set to 2595 // Adjust the volume of output devices, verify all active nodes are set to
2598 // the same volume. 2596 // the same volume.
2599 cras_audio_handler_->SetOutputVolumePercent(25); 2597 cras_audio_handler_->SetOutputVolumePercent(25);
2600 EXPECT_EQ(25, cras_audio_handler_->GetOutputVolumePercent()); 2598 EXPECT_EQ(25, cras_audio_handler_->GetOutputVolumePercent());
2601 EXPECT_EQ(25, cras_audio_handler_->GetOutputVolumePercentForDevice( 2599 EXPECT_EQ(25, cras_audio_handler_->GetOutputVolumePercentForDevice(
2602 kUSBJabraSpeakerOutput1->id)); 2600 kUSBJabraSpeakerOutput1->id));
2603 EXPECT_EQ(25, cras_audio_handler_->GetOutputVolumePercentForDevice( 2601 EXPECT_EQ(25, cras_audio_handler_->GetOutputVolumePercentForDevice(
2604 kUSBJabraSpeakerOutput2->id)); 2602 kUSBJabraSpeakerOutput2->id));
2605 } 2603 }
2606 2604
2605 TEST_P(CrasAudioHandlerTest, SetActiveNodesHotrodInit) {
2606 // This simulates a typical hotrod audio device configuration.
2607 AudioNodeList audio_nodes = GenerateAudioNodeList(
2608 {kHDMIOutput, kUSBJabraSpeakerOutput1, kUSBJabraSpeakerOutput2,
2609 kUSBJabraSpeakerInput1, kUSBJabraSpeakerInput2, kUSBCameraInput});
2610 SetUpCrasAudioHandler(audio_nodes);
2611
2612 // Verify the audio devices size.
2613 AudioDeviceList audio_devices;
2614 cras_audio_handler_->GetAudioDevices(&audio_devices);
2615 EXPECT_EQ(audio_nodes.size(), audio_devices.size());
2616
2617 // Verify only the 1st jabra speaker's output and input are selected as active
2618 // nodes by CrasAudioHandler.
2619 AudioDevice active_output;
2620 EXPECT_TRUE(
2621 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output));
2622 EXPECT_EQ(2, GetActiveDeviceCount());
2623 AudioDevice primary_active_device;
2624 EXPECT_TRUE(cras_audio_handler_->GetPrimaryActiveOutputDevice(
2625 &primary_active_device));
2626 EXPECT_EQ(kUSBJabraSpeakerOutput1->id, primary_active_device.id);
2627 EXPECT_EQ(kUSBJabraSpeakerInput1->id,
2628 cras_audio_handler_->GetPrimaryActiveInputNode());
2629
2630 // Set both jabra speakers's input and output nodes to active, this simulate
2631 // the call sent by hotrod initialization process.
2632 test_observer_->reset_active_output_node_changed_count();
2633 test_observer_->reset_active_input_node_changed_count();
2634
2635 cras_audio_handler_->SetActiveInputNodes(
2636 {kUSBJabraSpeakerInput1->id, kUSBJabraSpeakerInput2->id});
2637
2638 cras_audio_handler_->SetActiveOutputNodes(
2639 {kUSBJabraSpeakerOutput1->id, kUSBJabraSpeakerOutput2->id});
2640
2641 // Verify both jabra speakers' input/output nodes are made active.
2642 // num_active_nodes = GetActiveDeviceCount();
2643 EXPECT_EQ(4, GetActiveDeviceCount());
2644 const AudioDevice* active_output_1 =
2645 GetDeviceFromId(kUSBJabraSpeakerOutput1->id);
2646 EXPECT_TRUE(active_output_1->active);
2647 const AudioDevice* active_output_2 =
2648 GetDeviceFromId(kUSBJabraSpeakerOutput2->id);
2649 EXPECT_TRUE(active_output_2->active);
2650 EXPECT_TRUE(cras_audio_handler_->GetPrimaryActiveOutputDevice(
2651 &primary_active_device));
2652 EXPECT_EQ(kUSBJabraSpeakerOutput1->id, primary_active_device.id);
2653 const AudioDevice* active_input_1 =
2654 GetDeviceFromId(kUSBJabraSpeakerInput1->id);
2655 EXPECT_TRUE(active_input_1->active);
2656 const AudioDevice* active_input_2 =
2657 GetDeviceFromId(kUSBJabraSpeakerInput2->id);
2658 EXPECT_TRUE(active_input_2->active);
2659 EXPECT_EQ(kUSBJabraSpeakerInput1->id,
2660 cras_audio_handler_->GetPrimaryActiveInputNode());
2661
2662 // Verify only 1 ActiveOutputNodeChanged notification has been sent out
2663 // by calling SetActiveNodes.
2664 EXPECT_EQ(1, test_observer_->active_output_node_changed_count());
2665 EXPECT_EQ(1, test_observer_->active_input_node_changed_count());
2666
2667 // Verify all active devices are the not muted and their volume values are
2668 // the same.
2669 EXPECT_FALSE(cras_audio_handler_->IsOutputMuted());
2670 EXPECT_FALSE(
2671 cras_audio_handler_->IsOutputMutedForDevice(kUSBJabraSpeakerOutput1->id));
2672 EXPECT_FALSE(
2673 cras_audio_handler_->IsOutputMutedForDevice(kUSBJabraSpeakerOutput2->id));
2674 EXPECT_EQ(cras_audio_handler_->GetOutputVolumePercent(),
2675 cras_audio_handler_->GetOutputVolumePercentForDevice(
2676 kUSBJabraSpeakerOutput1->id));
2677 EXPECT_EQ(cras_audio_handler_->GetOutputVolumePercent(),
2678 cras_audio_handler_->GetOutputVolumePercentForDevice(
2679 kUSBJabraSpeakerOutput2->id));
2680
2681 // Adjust the volume of output devices, verify all active nodes are set to
2682 // the same volume.
2683 cras_audio_handler_->SetOutputVolumePercent(25);
2684 EXPECT_EQ(25, cras_audio_handler_->GetOutputVolumePercent());
2685 EXPECT_EQ(25, cras_audio_handler_->GetOutputVolumePercentForDevice(
2686 kUSBJabraSpeakerOutput1->id));
2687 EXPECT_EQ(25, cras_audio_handler_->GetOutputVolumePercentForDevice(
2688 kUSBJabraSpeakerOutput2->id));
2689 }
2690
2607 TEST_P(CrasAudioHandlerTest, ChangeVolumeHotrodDualSpeakersWithDelayedSignals) { 2691 TEST_P(CrasAudioHandlerTest, ChangeVolumeHotrodDualSpeakersWithDelayedSignals) {
2608 AudioNodeList audio_nodes = GenerateAudioNodeList( 2692 AudioNodeList audio_nodes = GenerateAudioNodeList(
2609 {kHDMIOutput, kUSBJabraSpeakerOutput1, kUSBJabraSpeakerOutput2}); 2693 {kHDMIOutput, kUSBJabraSpeakerOutput1, kUSBJabraSpeakerOutput2});
2610 SetUpCrasAudioHandler(audio_nodes); 2694 SetUpCrasAudioHandler(audio_nodes);
2611 2695
2612 // Verify the audio devices size. 2696 // Verify the audio devices size.
2613 AudioDeviceList audio_devices; 2697 AudioDeviceList audio_devices;
2614 cras_audio_handler_->GetAudioDevices(&audio_devices); 2698 cras_audio_handler_->GetAudioDevices(&audio_devices);
2615 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); 2699 EXPECT_EQ(audio_nodes.size(), audio_devices.size());
2616 2700
2617 // Set both jabra speakers nodes to active, this simulate 2701 // Set both jabra speakers nodes to active, this simulate
2618 // the call sent by hotrod initialization process. 2702 // the call sent by hotrod initialization process.
2619 test_observer_->reset_active_output_node_changed_count(); 2703 test_observer_->reset_active_output_node_changed_count();
2620 CrasAudioHandler::NodeIdList active_nodes; 2704 cras_audio_handler_->ChangeActiveNodes(
2621 active_nodes.push_back(kUSBJabraSpeakerOutput1->id); 2705 {kUSBJabraSpeakerOutput1->id, kUSBJabraSpeakerOutput2->id});
2622 active_nodes.push_back(kUSBJabraSpeakerOutput2->id);
2623 cras_audio_handler_->ChangeActiveNodes(active_nodes);
2624 2706
2625 // Verify both jabra speakers are made active. 2707 // Verify both jabra speakers are made active.
2626 EXPECT_EQ(2, GetActiveDeviceCount()); 2708 EXPECT_EQ(2, GetActiveDeviceCount());
2627 const AudioDevice* active_output_1 = 2709 const AudioDevice* active_output_1 =
2628 GetDeviceFromId(kUSBJabraSpeakerOutput1->id); 2710 GetDeviceFromId(kUSBJabraSpeakerOutput1->id);
2629 EXPECT_TRUE(active_output_1->active); 2711 EXPECT_TRUE(active_output_1->active);
2630 const AudioDevice* active_output_2 = 2712 const AudioDevice* active_output_2 =
2631 GetDeviceFromId(kUSBJabraSpeakerOutput2->id); 2713 GetDeviceFromId(kUSBJabraSpeakerOutput2->id);
2632 EXPECT_TRUE(active_output_2->active); 2714 EXPECT_TRUE(active_output_2->active);
2633 2715
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
2695 EXPECT_EQ(2, GetActiveDeviceCount()); 2777 EXPECT_EQ(2, GetActiveDeviceCount());
2696 EXPECT_EQ(kUSBJabraSpeakerOutput1->id, 2778 EXPECT_EQ(kUSBJabraSpeakerOutput1->id,
2697 cras_audio_handler_->GetPrimaryActiveOutputNode()); 2779 cras_audio_handler_->GetPrimaryActiveOutputNode());
2698 EXPECT_EQ(kUSBCameraInput->id, 2780 EXPECT_EQ(kUSBCameraInput->id,
2699 cras_audio_handler_->GetPrimaryActiveInputNode()); 2781 cras_audio_handler_->GetPrimaryActiveInputNode());
2700 2782
2701 // Set both jabra speakers's input and output nodes to active, this simulates 2783 // Set both jabra speakers's input and output nodes to active, this simulates
2702 // the call sent by hotrod initialization process. 2784 // the call sent by hotrod initialization process.
2703 test_observer_->reset_active_output_node_changed_count(); 2785 test_observer_->reset_active_output_node_changed_count();
2704 test_observer_->reset_active_input_node_changed_count(); 2786 test_observer_->reset_active_input_node_changed_count();
2705 CrasAudioHandler::NodeIdList active_nodes; 2787 cras_audio_handler_->ChangeActiveNodes(
2706 active_nodes.push_back(kUSBJabraSpeakerOutput1->id); 2788 {kUSBJabraSpeakerOutput1->id, kUSBJabraSpeakerOutput2->id,
2707 active_nodes.push_back(kUSBJabraSpeakerOutput2->id); 2789 kUSBJabraSpeakerInput1->id, kUSBJabraSpeakerInput2->id});
2708 active_nodes.push_back(kUSBJabraSpeakerInput1->id);
2709 active_nodes.push_back(kUSBJabraSpeakerInput2->id);
2710 cras_audio_handler_->ChangeActiveNodes(active_nodes);
2711 2790
2712 // Verify both jabra speakers' input/output nodes are made active. 2791 // Verify both jabra speakers' input/output nodes are made active.
2713 // num_active_nodes = GetActiveDeviceCount(); 2792 // num_active_nodes = GetActiveDeviceCount();
2793 EXPECT_EQ(4, GetActiveDeviceCount());
2794 const AudioDevice* active_output_1 =
2795 GetDeviceFromId(kUSBJabraSpeakerOutput1->id);
2796 EXPECT_TRUE(active_output_1->active);
2797 const AudioDevice* active_output_2 =
2798 GetDeviceFromId(kUSBJabraSpeakerOutput2->id);
2799 EXPECT_TRUE(active_output_2->active);
2800 EXPECT_EQ(kUSBJabraSpeakerOutput1->id,
2801 cras_audio_handler_->GetPrimaryActiveOutputNode());
2802 const AudioDevice* active_input_1 =
2803 GetDeviceFromId(kUSBJabraSpeakerInput1->id);
2804 EXPECT_TRUE(active_input_1->active);
2805 const AudioDevice* active_input_2 =
2806 GetDeviceFromId(kUSBJabraSpeakerInput2->id);
2807 EXPECT_TRUE(active_input_2->active);
2808 EXPECT_EQ(kUSBJabraSpeakerInput1->id,
2809 cras_audio_handler_->GetPrimaryActiveInputNode());
2810
2811 // Verify only 1 ActiveOutputNodeChanged notification has been sent out
2812 // by calling ChangeActiveNodes.
2813 EXPECT_EQ(1, test_observer_->active_output_node_changed_count());
2814 EXPECT_EQ(1, test_observer_->active_input_node_changed_count());
2815 }
2816
2817 TEST_P(CrasAudioHandlerTest, SetActiveNodesHotrodInitWithCameraInputActive) {
2818 AudioNodeList audio_nodes = GenerateAudioNodeList(
2819 {kHDMIOutput, kUSBJabraSpeakerOutput1, kUSBJabraSpeakerOutput2,
2820 kUSBJabraSpeakerInput1, kUSBJabraSpeakerInput2});
2821 // Make the camera input to be plugged in later than jabra's input.
2822 AudioNode usb_camera = GenerateAudioNode(kUSBCameraInput);
2823 usb_camera.plugged_time = 10000000;
2824 audio_nodes.push_back(usb_camera);
2825 SetUpCrasAudioHandler(audio_nodes);
2826
2827 // Verify the audio devices size.
2828 AudioDeviceList audio_devices;
2829 cras_audio_handler_->GetAudioDevices(&audio_devices);
2830 EXPECT_EQ(audio_nodes.size(), audio_devices.size());
2831
2832 // Verify the 1st jabra speaker's output is selected as active output
2833 // node and camera's input is selected active input by CrasAudioHandler.
2834 EXPECT_EQ(2, GetActiveDeviceCount());
2835 EXPECT_EQ(kUSBJabraSpeakerOutput1->id,
2836 cras_audio_handler_->GetPrimaryActiveOutputNode());
2837 EXPECT_EQ(kUSBCameraInput->id,
2838 cras_audio_handler_->GetPrimaryActiveInputNode());
2839
2840 // Set both jabra speakers's input and output nodes to active, this simulates
2841 // the call sent by hotrod initialization process.
2842 test_observer_->reset_active_output_node_changed_count();
2843 test_observer_->reset_active_input_node_changed_count();
2844
2845 cras_audio_handler_->SetActiveOutputNodes(
2846 {kUSBJabraSpeakerOutput1->id, kUSBJabraSpeakerOutput2->id});
2847
2848 cras_audio_handler_->SetActiveInputNodes(
2849 {kUSBJabraSpeakerInput1->id, kUSBJabraSpeakerInput2->id});
2850
2851 // Verify both jabra speakers' input/output nodes are made active.
2852 // num_active_nodes = GetActiveDeviceCount();
2714 EXPECT_EQ(4, GetActiveDeviceCount()); 2853 EXPECT_EQ(4, GetActiveDeviceCount());
2715 const AudioDevice* active_output_1 = 2854 const AudioDevice* active_output_1 =
2716 GetDeviceFromId(kUSBJabraSpeakerOutput1->id); 2855 GetDeviceFromId(kUSBJabraSpeakerOutput1->id);
2717 EXPECT_TRUE(active_output_1->active); 2856 EXPECT_TRUE(active_output_1->active);
2718 const AudioDevice* active_output_2 = 2857 const AudioDevice* active_output_2 =
2719 GetDeviceFromId(kUSBJabraSpeakerOutput2->id); 2858 GetDeviceFromId(kUSBJabraSpeakerOutput2->id);
2720 EXPECT_TRUE(active_output_2->active); 2859 EXPECT_TRUE(active_output_2->active);
2721 EXPECT_EQ(kUSBJabraSpeakerOutput1->id, 2860 EXPECT_EQ(kUSBJabraSpeakerOutput1->id,
2722 cras_audio_handler_->GetPrimaryActiveOutputNode()); 2861 cras_audio_handler_->GetPrimaryActiveOutputNode());
2723 const AudioDevice* active_input_1 = 2862 const AudioDevice* active_input_1 =
(...skipping 15 matching lines...) Expand all
2739 AudioNodeList audio_nodes = GenerateAudioNodeList( 2878 AudioNodeList audio_nodes = GenerateAudioNodeList(
2740 {kHDMIOutput, kUSBJabraSpeakerOutput1, kUSBJabraSpeakerOutput2}); 2879 {kHDMIOutput, kUSBJabraSpeakerOutput1, kUSBJabraSpeakerOutput2});
2741 SetUpCrasAudioHandler(audio_nodes); 2880 SetUpCrasAudioHandler(audio_nodes);
2742 2881
2743 // Verify the audio devices size. 2882 // Verify the audio devices size.
2744 AudioDeviceList audio_devices; 2883 AudioDeviceList audio_devices;
2745 cras_audio_handler_->GetAudioDevices(&audio_devices); 2884 cras_audio_handler_->GetAudioDevices(&audio_devices);
2746 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); 2885 EXPECT_EQ(audio_nodes.size(), audio_devices.size());
2747 2886
2748 // Set all three nodes to be active. 2887 // Set all three nodes to be active.
2749 CrasAudioHandler::NodeIdList active_nodes; 2888 cras_audio_handler_->ChangeActiveNodes({kHDMIOutput->id,
2750 active_nodes.push_back(kHDMIOutput->id); 2889 kUSBJabraSpeakerOutput1->id,
2751 active_nodes.push_back(kUSBJabraSpeakerOutput1->id); 2890 kUSBJabraSpeakerOutput2->id});
2752 active_nodes.push_back(kUSBJabraSpeakerOutput2->id);
2753 cras_audio_handler_->ChangeActiveNodes(active_nodes);
2754 2891
2755 // Verify all three nodes are active. 2892 // Verify all three nodes are active.
2756 EXPECT_EQ(3, GetActiveDeviceCount()); 2893 EXPECT_EQ(3, GetActiveDeviceCount());
2757 const AudioDevice* active_output_1 = GetDeviceFromId(kHDMIOutput->id); 2894 const AudioDevice* active_output_1 = GetDeviceFromId(kHDMIOutput->id);
2758 EXPECT_TRUE(active_output_1->active); 2895 EXPECT_TRUE(active_output_1->active);
2759 const AudioDevice* active_output_2 = 2896 const AudioDevice* active_output_2 =
2760 GetDeviceFromId(kUSBJabraSpeakerOutput1->id); 2897 GetDeviceFromId(kUSBJabraSpeakerOutput1->id);
2761 EXPECT_TRUE(active_output_2->active); 2898 EXPECT_TRUE(active_output_2->active);
2762 const AudioDevice* active_output_3 = 2899 const AudioDevice* active_output_3 =
2763 GetDeviceFromId(kUSBJabraSpeakerOutput2->id); 2900 GetDeviceFromId(kUSBJabraSpeakerOutput2->id);
2764 EXPECT_TRUE(active_output_3->active); 2901 EXPECT_TRUE(active_output_3->active);
2765 2902
2766 // Now call ChangeActiveDevices with only 2 nodes. 2903 // Now call ChangeActiveDevices with only 2 nodes.
2767 active_nodes.clear(); 2904 cras_audio_handler_->ChangeActiveNodes(
2768 active_nodes.push_back(kUSBJabraSpeakerOutput1->id); 2905 {kUSBJabraSpeakerOutput1->id, kUSBJabraSpeakerOutput2->id});
2769 active_nodes.push_back(kUSBJabraSpeakerOutput2->id);
2770 cras_audio_handler_->ChangeActiveNodes(active_nodes);
2771 2906
2772 // Verify only 2 nodes are active. 2907 // Verify only 2 nodes are active.
2773 EXPECT_EQ(2, GetActiveDeviceCount()); 2908 EXPECT_EQ(2, GetActiveDeviceCount());
2909 const AudioDevice* output_1 = GetDeviceFromId(kHDMIOutput->id);
2910 EXPECT_FALSE(output_1->active);
2911 const AudioDevice* output_2 = GetDeviceFromId(kUSBJabraSpeakerOutput1->id);
2912 EXPECT_TRUE(output_2->active);
2913 const AudioDevice* output_3 = GetDeviceFromId(kUSBJabraSpeakerOutput2->id);
2914 EXPECT_TRUE(output_3->active);
2915 }
2916
2917 TEST_P(CrasAudioHandlerTest, SetActiveNodesWithFewerActives) {
2918 AudioNodeList audio_nodes = GenerateAudioNodeList(
2919 {kHDMIOutput, kUSBJabraSpeakerOutput1, kUSBJabraSpeakerOutput2});
2920 SetUpCrasAudioHandler(audio_nodes);
2921
2922 // Verify the audio devices size.
2923 AudioDeviceList audio_devices;
2924 cras_audio_handler_->GetAudioDevices(&audio_devices);
2925 EXPECT_EQ(audio_nodes.size(), audio_devices.size());
2926
2927 // Set all three nodes to be active.
2928 cras_audio_handler_->SetActiveOutputNodes({kHDMIOutput->id,
2929 kUSBJabraSpeakerOutput1->id,
2930 kUSBJabraSpeakerOutput2->id});
2931
2932 // Verify all three nodes are active.
2933 EXPECT_EQ(3, GetActiveDeviceCount());
2934 const AudioDevice* active_output_1 = GetDeviceFromId(kHDMIOutput->id);
2935 EXPECT_TRUE(active_output_1->active);
2936 const AudioDevice* active_output_2 =
2937 GetDeviceFromId(kUSBJabraSpeakerOutput1->id);
2938 EXPECT_TRUE(active_output_2->active);
2939 const AudioDevice* active_output_3 =
2940 GetDeviceFromId(kUSBJabraSpeakerOutput2->id);
2941 EXPECT_TRUE(active_output_3->active);
2942
2943 // Now call SetActiveOutputNodes with only 2 nodes.
2944 cras_audio_handler_->SetActiveOutputNodes(
2945 {kUSBJabraSpeakerOutput1->id, kUSBJabraSpeakerOutput2->id});
2946
2947 // Verify only 2 nodes are active.
2948 EXPECT_EQ(2, GetActiveDeviceCount());
2774 const AudioDevice* output_1 = GetDeviceFromId(kHDMIOutput->id); 2949 const AudioDevice* output_1 = GetDeviceFromId(kHDMIOutput->id);
2775 EXPECT_FALSE(output_1->active); 2950 EXPECT_FALSE(output_1->active);
2776 const AudioDevice* output_2 = GetDeviceFromId(kUSBJabraSpeakerOutput1->id); 2951 const AudioDevice* output_2 = GetDeviceFromId(kUSBJabraSpeakerOutput1->id);
2777 EXPECT_TRUE(output_2->active); 2952 EXPECT_TRUE(output_2->active);
2778 const AudioDevice* output_3 = GetDeviceFromId(kUSBJabraSpeakerOutput2->id); 2953 const AudioDevice* output_3 = GetDeviceFromId(kUSBJabraSpeakerOutput2->id);
2779 EXPECT_TRUE(output_3->active); 2954 EXPECT_TRUE(output_3->active);
2780 } 2955 }
2781 2956
2782 TEST_P(CrasAudioHandlerTest, HotrodInitWithSingleJabra) { 2957 TEST_P(CrasAudioHandlerTest, HotrodInitWithSingleJabra) {
2783 // Simulates the hotrod initializated with a single jabra device and 2958 // Simulates the hotrod initializated with a single jabra device and
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
2820 EXPECT_EQ(2, GetActiveDeviceCount()); 2995 EXPECT_EQ(2, GetActiveDeviceCount());
2821 EXPECT_EQ(kUSBJabraSpeakerOutput1->id, 2996 EXPECT_EQ(kUSBJabraSpeakerOutput1->id,
2822 cras_audio_handler_->GetPrimaryActiveOutputNode()); 2997 cras_audio_handler_->GetPrimaryActiveOutputNode());
2823 EXPECT_EQ(kUSBCameraInput->id, 2998 EXPECT_EQ(kUSBCameraInput->id,
2824 cras_audio_handler_->GetPrimaryActiveInputNode()); 2999 cras_audio_handler_->GetPrimaryActiveInputNode());
2825 3000
2826 // Simulate hotrod app call to set jabra input as active device with only 3001 // Simulate hotrod app call to set jabra input as active device with only
2827 // jabra input node in the active node list, which does not conform to the 3002 // jabra input node in the active node list, which does not conform to the
2828 // new SetActiveDevices protocol, but just show we can still handle it if 3003 // new SetActiveDevices protocol, but just show we can still handle it if
2829 // this happens. 3004 // this happens.
2830 CrasAudioHandler::NodeIdList active_nodes; 3005 cras_audio_handler_->ChangeActiveNodes(
2831 active_nodes.push_back(kUSBJabraSpeakerOutput1->id); 3006 {kUSBJabraSpeakerOutput1->id, kUSBJabraSpeakerInput1->id});
2832 active_nodes.push_back(kUSBJabraSpeakerInput1->id);
2833 cras_audio_handler_->ChangeActiveNodes(active_nodes);
2834 3007
2835 // Verify the jabra speaker's output is selected as active output, and 3008 // Verify the jabra speaker's output is selected as active output, and
2836 // jabra's input is selected as active input. 3009 // jabra's input is selected as active input.
3010 EXPECT_EQ(2, GetActiveDeviceCount());
3011 EXPECT_EQ(kUSBJabraSpeakerOutput1->id,
3012 cras_audio_handler_->GetPrimaryActiveOutputNode());
3013 EXPECT_EQ(kUSBJabraSpeakerInput1->id,
3014 cras_audio_handler_->GetPrimaryActiveInputNode());
3015 }
3016
3017 TEST_P(CrasAudioHandlerTest,
3018 SetActiveNodesHotrodInitWithSingleJabraCameraPlugInLater) {
3019 AudioNodeList audio_nodes = GenerateAudioNodeList(
3020 {kHDMIOutput, kUSBJabraSpeakerOutput1, kUSBJabraSpeakerInput1});
3021 AudioNode usb_camera = GenerateAudioNode(kUSBCameraInput);
3022 usb_camera.plugged_time = 10000000;
3023 audio_nodes.push_back(usb_camera);
3024 SetUpCrasAudioHandler(audio_nodes);
3025
3026 // Verify the audio devices size.
3027 AudioDeviceList audio_devices;
3028 cras_audio_handler_->GetAudioDevices(&audio_devices);
3029 EXPECT_EQ(audio_nodes.size(), audio_devices.size());
3030
3031 // Verify the jabra speaker's output is selected as active output, and
3032 // camera's input is selected as active input by CrasAudioHandler
3033 EXPECT_EQ(2, GetActiveDeviceCount());
3034 EXPECT_EQ(kUSBJabraSpeakerOutput1->id,
3035 cras_audio_handler_->GetPrimaryActiveOutputNode());
3036 EXPECT_EQ(kUSBCameraInput->id,
3037 cras_audio_handler_->GetPrimaryActiveInputNode());
3038
3039 // Simulate hotrod app call to set jabra input as active device with only
3040 // jabra input node in the active node list, which does not conform to the
3041 // new SetActiveDevices protocol, but just show we can still handle it if
3042 // this happens.
3043 cras_audio_handler_->SetActiveOutputNodes({kUSBJabraSpeakerOutput1->id});
3044
3045 cras_audio_handler_->SetActiveInputNodes({kUSBJabraSpeakerInput1->id});
3046
3047 // Verify the jabra speaker's output is selected as active output, and
3048 // jabra's input is selected as active input.
2837 EXPECT_EQ(2, GetActiveDeviceCount()); 3049 EXPECT_EQ(2, GetActiveDeviceCount());
2838 EXPECT_EQ(kUSBJabraSpeakerOutput1->id, 3050 EXPECT_EQ(kUSBJabraSpeakerOutput1->id,
2839 cras_audio_handler_->GetPrimaryActiveOutputNode()); 3051 cras_audio_handler_->GetPrimaryActiveOutputNode());
2840 EXPECT_EQ(kUSBJabraSpeakerInput1->id, 3052 EXPECT_EQ(kUSBJabraSpeakerInput1->id,
2841 cras_audio_handler_->GetPrimaryActiveInputNode()); 3053 cras_audio_handler_->GetPrimaryActiveInputNode());
2842 } 3054 }
2843 3055
2844 TEST_P(CrasAudioHandlerTest, ChangeActiveNodesDeactivatePrimaryActiveNode) { 3056 TEST_P(CrasAudioHandlerTest, ChangeActiveNodesDeactivatePrimaryActiveNode) {
2845 AudioNodeList audio_nodes = 3057 AudioNodeList audio_nodes =
2846 GenerateAudioNodeList({kUSBJabraSpeakerInput1, kUSBJabraSpeakerInput2}); 3058 GenerateAudioNodeList({kUSBJabraSpeakerInput1, kUSBJabraSpeakerInput2});
2847 AudioNode usb_camera = GenerateAudioNode(kUSBCameraInput); 3059 AudioNode usb_camera = GenerateAudioNode(kUSBCameraInput);
2848 usb_camera.plugged_time = 10000000; 3060 usb_camera.plugged_time = 10000000;
2849 audio_nodes.push_back(usb_camera); 3061 audio_nodes.push_back(usb_camera);
2850 SetUpCrasAudioHandler(audio_nodes); 3062 SetUpCrasAudioHandler(audio_nodes);
2851 3063
2852 // Verify the audio devices size. 3064 // Verify the audio devices size.
2853 AudioDeviceList audio_devices; 3065 AudioDeviceList audio_devices;
2854 cras_audio_handler_->GetAudioDevices(&audio_devices); 3066 cras_audio_handler_->GetAudioDevices(&audio_devices);
2855 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); 3067 EXPECT_EQ(audio_nodes.size(), audio_devices.size());
2856 3068
2857 // Verify the camera's input is selected as active input by CrasAudioHandler 3069 // Verify the camera's input is selected as active input by CrasAudioHandler
2858 EXPECT_EQ(1, GetActiveDeviceCount()); 3070 EXPECT_EQ(1, GetActiveDeviceCount());
2859 EXPECT_EQ(kUSBCameraInput->id, 3071 EXPECT_EQ(kUSBCameraInput->id,
2860 cras_audio_handler_->GetPrimaryActiveInputNode()); 3072 cras_audio_handler_->GetPrimaryActiveInputNode());
2861 3073
2862 // Simulate hotrod app call to set jabra input as active device with only 3074 // Simulate hotrod app call to set jabra input as active device with only
2863 // jabra input node in the active node list, which does not conform to the 3075 // jabra input node in the active node list, which does not conform to the
2864 // new SetActiveDevices protocol, but just show we can still handle it if 3076 // new SetActiveDevices protocol, but just show we can still handle it if
2865 // this happens. 3077 // this happens.
2866 { 3078 cras_audio_handler_->ChangeActiveNodes(
2867 CrasAudioHandler::NodeIdList active_nodes; 3079 {kUSBJabraSpeakerInput1->id, kUSBCameraInput->id});
2868 active_nodes.push_back(kUSBJabraSpeakerInput1->id);
2869 active_nodes.push_back(kUSBCameraInput->id);
2870 cras_audio_handler_->ChangeActiveNodes(active_nodes);
2871 }
2872 3080
2873 // Verify the jabra speaker's output is selected as active output, and 3081 // Verify active input devices are set as expected, with primary active input
2874 // jabra's input is selected as active input. 3082 // staying the same.
2875 EXPECT_EQ(2, GetActiveDeviceCount()); 3083 EXPECT_EQ(2, GetActiveDeviceCount());
2876 EXPECT_EQ(kUSBCameraInput->id, 3084 EXPECT_EQ(kUSBCameraInput->id,
2877 cras_audio_handler_->GetPrimaryActiveInputNode()); 3085 cras_audio_handler_->GetPrimaryActiveInputNode());
2878 3086
2879 const AudioDevice* additional_speaker = 3087 const AudioDevice* additional_speaker =
2880 cras_audio_handler_->GetDeviceFromId(kUSBJabraSpeakerInput1->id); 3088 cras_audio_handler_->GetDeviceFromId(kUSBJabraSpeakerInput1->id);
2881 ASSERT_TRUE(additional_speaker); 3089 ASSERT_TRUE(additional_speaker);
2882 EXPECT_TRUE(additional_speaker->active); 3090 EXPECT_TRUE(additional_speaker->active);
2883 3091
2884 { 3092 // Update active device list so previously primary active device is not
2885 CrasAudioHandler::NodeIdList active_nodes; 3093 // active anymore.
2886 active_nodes.push_back(kUSBJabraSpeakerInput1->id); 3094 cras_audio_handler_->ChangeActiveNodes(
2887 active_nodes.push_back(kUSBJabraSpeakerInput2->id); 3095 {kUSBJabraSpeakerInput1->id, kUSBJabraSpeakerInput2->id});
2888 cras_audio_handler_->ChangeActiveNodes(active_nodes);
2889 }
2890 3096
3097 // Verify that list of active devices is correctly set, and that a new primary
3098 // active input is selected.
2891 EXPECT_EQ(2, GetActiveDeviceCount()); 3099 EXPECT_EQ(2, GetActiveDeviceCount());
2892 EXPECT_EQ(kUSBJabraSpeakerInput1->id, 3100 EXPECT_EQ(kUSBJabraSpeakerInput1->id,
2893 cras_audio_handler_->GetPrimaryActiveInputNode()); 3101 cras_audio_handler_->GetPrimaryActiveInputNode());
3102
3103 additional_speaker =
3104 cras_audio_handler_->GetDeviceFromId(kUSBJabraSpeakerInput2->id);
3105 ASSERT_TRUE(additional_speaker);
3106 EXPECT_TRUE(additional_speaker->active);
3107 }
3108
3109 TEST_P(CrasAudioHandlerTest, SetActiveNodesDeactivatePrimaryActiveNode) {
3110 AudioNodeList audio_nodes =
3111 GenerateAudioNodeList({kUSBJabraSpeakerInput1, kUSBJabraSpeakerInput2});
3112 AudioNode usb_camera = GenerateAudioNode(kUSBCameraInput);
3113 usb_camera.plugged_time = 10000000;
3114 audio_nodes.push_back(usb_camera);
3115 SetUpCrasAudioHandler(audio_nodes);
3116
3117 // Verify the audio devices size.
3118 AudioDeviceList audio_devices;
3119 cras_audio_handler_->GetAudioDevices(&audio_devices);
3120 EXPECT_EQ(audio_nodes.size(), audio_devices.size());
3121
3122 // Verify the camera's input is selected as active input by CrasAudioHandler.
3123 EXPECT_EQ(1, GetActiveDeviceCount());
3124 EXPECT_EQ(kUSBCameraInput->id,
3125 cras_audio_handler_->GetPrimaryActiveInputNode());
3126
3127 // Add another device to active input device list.
3128 cras_audio_handler_->SetActiveInputNodes(
3129 {kUSBJabraSpeakerInput1->id, kUSBCameraInput->id});
3130
3131 // Verify active input devices are set as expected, with primary active input
3132 // staying the same.
3133 EXPECT_EQ(2, GetActiveDeviceCount());
3134 EXPECT_EQ(kUSBCameraInput->id,
3135 cras_audio_handler_->GetPrimaryActiveInputNode());
3136
3137 const AudioDevice* additional_speaker =
3138 cras_audio_handler_->GetDeviceFromId(kUSBJabraSpeakerInput1->id);
3139 ASSERT_TRUE(additional_speaker);
3140 EXPECT_TRUE(additional_speaker->active);
3141
3142 // Update active device list so previously primary active device is not
3143 // active anymore.
3144 cras_audio_handler_->SetActiveInputNodes(
3145 {kUSBJabraSpeakerInput1->id, kUSBJabraSpeakerInput2->id});
3146
3147 // Verify that list of active devices is correctly set, and that a new primary
3148 // active input is selected.
3149 EXPECT_EQ(2, GetActiveDeviceCount());
3150 EXPECT_EQ(kUSBJabraSpeakerInput1->id,
3151 cras_audio_handler_->GetPrimaryActiveInputNode());
2894 3152
2895 additional_speaker = 3153 additional_speaker =
2896 cras_audio_handler_->GetDeviceFromId(kUSBJabraSpeakerInput2->id); 3154 cras_audio_handler_->GetDeviceFromId(kUSBJabraSpeakerInput2->id);
2897 ASSERT_TRUE(additional_speaker); 3155 ASSERT_TRUE(additional_speaker);
2898 EXPECT_TRUE(additional_speaker->active); 3156 EXPECT_TRUE(additional_speaker->active);
2899 } 3157 }
2900 3158
2901 TEST_P(CrasAudioHandlerTest, 3159 TEST_P(CrasAudioHandlerTest,
2902 ChangeActiveNodesHotrodInitWithSingleJabraCameraPlugInLaterOldCall) { 3160 ChangeActiveNodesHotrodInitWithSingleJabraCameraPlugInLaterOldCall) {
2903 AudioNodeList audio_nodes = GenerateAudioNodeList( 3161 AudioNodeList audio_nodes = GenerateAudioNodeList(
(...skipping 13 matching lines...) Expand all
2917 EXPECT_EQ(2, GetActiveDeviceCount()); 3175 EXPECT_EQ(2, GetActiveDeviceCount());
2918 EXPECT_EQ(kUSBJabraSpeakerOutput1->id, 3176 EXPECT_EQ(kUSBJabraSpeakerOutput1->id,
2919 cras_audio_handler_->GetPrimaryActiveOutputNode()); 3177 cras_audio_handler_->GetPrimaryActiveOutputNode());
2920 EXPECT_EQ(kUSBCameraInput->id, 3178 EXPECT_EQ(kUSBCameraInput->id,
2921 cras_audio_handler_->GetPrimaryActiveInputNode()); 3179 cras_audio_handler_->GetPrimaryActiveInputNode());
2922 3180
2923 // Simulate hotrod app call to set jabra input as active device with only 3181 // Simulate hotrod app call to set jabra input as active device with only
2924 // jabra input node in the active node list, which does not conform to the 3182 // jabra input node in the active node list, which does not conform to the
2925 // new SetActiveDevices protocol, but just show we can still handle it if 3183 // new SetActiveDevices protocol, but just show we can still handle it if
2926 // this happens. 3184 // this happens.
2927 CrasAudioHandler::NodeIdList active_nodes; 3185 cras_audio_handler_->ChangeActiveNodes({kUSBJabraSpeakerInput1->id});
2928 active_nodes.push_back(kUSBJabraSpeakerInput1->id);
2929 cras_audio_handler_->ChangeActiveNodes(active_nodes);
2930 3186
2931 // Verify the jabra speaker's output is selected as active output, and 3187 // Verify the jabra speaker's output is selected as active output, and
2932 // jabra's input is selected as active input. 3188 // jabra's input is selected as active input.
3189 EXPECT_EQ(2, GetActiveDeviceCount());
3190 EXPECT_EQ(kUSBJabraSpeakerOutput1->id,
3191 cras_audio_handler_->GetPrimaryActiveOutputNode());
3192 EXPECT_EQ(kUSBJabraSpeakerInput1->id,
3193 cras_audio_handler_->GetPrimaryActiveInputNode());
3194 }
3195
3196 TEST_P(CrasAudioHandlerTest,
3197 SetActiveNodesHotrodInitWithSingleJabraCameraPlugInLaterOldCall) {
3198 AudioNodeList audio_nodes = GenerateAudioNodeList(
3199 {kHDMIOutput, kUSBJabraSpeakerOutput1, kUSBJabraSpeakerInput1});
3200 AudioNode usb_camera = GenerateAudioNode(kUSBCameraInput);
3201 usb_camera.plugged_time = 10000000;
3202 audio_nodes.push_back(usb_camera);
3203 SetUpCrasAudioHandler(audio_nodes);
3204
3205 // Verify the audio devices size.
3206 AudioDeviceList audio_devices;
3207 cras_audio_handler_->GetAudioDevices(&audio_devices);
3208 EXPECT_EQ(audio_nodes.size(), audio_devices.size());
3209
3210 // Verify the jabra speaker's output is selected as active output, and
3211 // camera's input is selected as active input by CrasAudioHandler
3212 EXPECT_EQ(2, GetActiveDeviceCount());
3213 EXPECT_EQ(kUSBJabraSpeakerOutput1->id,
3214 cras_audio_handler_->GetPrimaryActiveOutputNode());
3215 EXPECT_EQ(kUSBCameraInput->id,
3216 cras_audio_handler_->GetPrimaryActiveInputNode());
3217
3218 // Simulate hotrod app call to set jabra input as active device with only
3219 // jabra input node in the active node list, which does not conform to the
3220 // new SetActiveDevices protocol, but just show we can still handle it if
3221 // this happens.
3222 cras_audio_handler_->SetActiveInputNodes({kUSBJabraSpeakerInput1->id});
3223
3224 // Verify the jabra speaker's output is selected as active output, and
3225 // jabra's input is selected as active input.
2933 EXPECT_EQ(2, GetActiveDeviceCount()); 3226 EXPECT_EQ(2, GetActiveDeviceCount());
2934 EXPECT_EQ(kUSBJabraSpeakerOutput1->id, 3227 EXPECT_EQ(kUSBJabraSpeakerOutput1->id,
2935 cras_audio_handler_->GetPrimaryActiveOutputNode()); 3228 cras_audio_handler_->GetPrimaryActiveOutputNode());
2936 EXPECT_EQ(kUSBJabraSpeakerInput1->id, 3229 EXPECT_EQ(kUSBJabraSpeakerInput1->id,
2937 cras_audio_handler_->GetPrimaryActiveInputNode()); 3230 cras_audio_handler_->GetPrimaryActiveInputNode());
2938 } 3231 }
2939 3232
2940 TEST_P(CrasAudioHandlerTest, 3233 TEST_P(CrasAudioHandlerTest,
2941 ChangeActiveNodesHotrodInitWithSingleJabraChangeOutput) { 3234 ChangeActiveNodesHotrodInitWithSingleJabraChangeOutput) {
2942 AudioNodeList audio_nodes = 3235 AudioNodeList audio_nodes =
(...skipping 10 matching lines...) Expand all
2953 // by CrasAudioHandler. 3246 // by CrasAudioHandler.
2954 EXPECT_EQ(2, GetActiveDeviceCount()); 3247 EXPECT_EQ(2, GetActiveDeviceCount());
2955 EXPECT_EQ(kUSBJabraSpeakerOutput1->id, 3248 EXPECT_EQ(kUSBJabraSpeakerOutput1->id,
2956 cras_audio_handler_->GetPrimaryActiveOutputNode()); 3249 cras_audio_handler_->GetPrimaryActiveOutputNode());
2957 EXPECT_EQ(kUSBJabraSpeakerInput1->id, 3250 EXPECT_EQ(kUSBJabraSpeakerInput1->id,
2958 cras_audio_handler_->GetPrimaryActiveInputNode()); 3251 cras_audio_handler_->GetPrimaryActiveInputNode());
2959 3252
2960 // Simulate hotrod app call SetActiveDevices to change active output 3253 // Simulate hotrod app call SetActiveDevices to change active output
2961 // with only complete list of active nodes passed in, which is the new 3254 // with only complete list of active nodes passed in, which is the new
2962 // way of hotrod app. 3255 // way of hotrod app.
2963 CrasAudioHandler::NodeIdList active_nodes; 3256 cras_audio_handler_->ChangeActiveNodes(
2964 active_nodes.push_back(kHDMIOutput->id); 3257 {kHDMIOutput->id, kUSBJabraSpeakerInput1->id});
2965 active_nodes.push_back(kUSBJabraSpeakerInput1->id);
2966 cras_audio_handler_->ChangeActiveNodes(active_nodes);
2967 3258
2968 // Verify the jabra speaker's output is selected as active output, and 3259 // Verify the jabra speaker's output is selected as active output, and
2969 // jabra's input is selected as active input. 3260 // jabra's input is selected as active input.
3261 EXPECT_EQ(2, GetActiveDeviceCount());
3262 EXPECT_EQ(kHDMIOutput->id, cras_audio_handler_->GetPrimaryActiveOutputNode());
3263 EXPECT_EQ(kUSBJabraSpeakerInput1->id,
3264 cras_audio_handler_->GetPrimaryActiveInputNode());
3265 }
3266
3267 TEST_P(CrasAudioHandlerTest,
3268 SetActiveNodesHotrodInitWithSingleJabraChangeOutput) {
3269 AudioNodeList audio_nodes =
3270 GenerateAudioNodeList({kHDMIOutput, kUSBJabraSpeakerOutput1,
3271 kUSBJabraSpeakerInput1, kUSBCameraInput});
3272 SetUpCrasAudioHandler(audio_nodes);
3273
3274 // Verify the audio devices size.
3275 AudioDeviceList audio_devices;
3276 cras_audio_handler_->GetAudioDevices(&audio_devices);
3277 EXPECT_EQ(audio_nodes.size(), audio_devices.size());
3278
3279 // Verify the jabra speaker's output and input are selected as active output
3280 // by CrasAudioHandler.
3281 EXPECT_EQ(2, GetActiveDeviceCount());
3282 EXPECT_EQ(kUSBJabraSpeakerOutput1->id,
3283 cras_audio_handler_->GetPrimaryActiveOutputNode());
3284 EXPECT_EQ(kUSBJabraSpeakerInput1->id,
3285 cras_audio_handler_->GetPrimaryActiveInputNode());
3286
3287 // Simulate hotrod app calling SetActiveDeviceLists to change active input
3288 // and output with complete list of active nodes passed in.
3289 cras_audio_handler_->SetActiveOutputNodes({kHDMIOutput->id});
3290 cras_audio_handler_->SetActiveInputNodes({kUSBJabraSpeakerInput1->id});
3291
3292 // Verify the jabra speaker's output is selected as active output, and
3293 // jabra's input is selected as active input.
2970 EXPECT_EQ(2, GetActiveDeviceCount()); 3294 EXPECT_EQ(2, GetActiveDeviceCount());
2971 EXPECT_EQ(kHDMIOutput->id, cras_audio_handler_->GetPrimaryActiveOutputNode()); 3295 EXPECT_EQ(kHDMIOutput->id, cras_audio_handler_->GetPrimaryActiveOutputNode());
2972 EXPECT_EQ(kUSBJabraSpeakerInput1->id, 3296 EXPECT_EQ(kUSBJabraSpeakerInput1->id,
2973 cras_audio_handler_->GetPrimaryActiveInputNode()); 3297 cras_audio_handler_->GetPrimaryActiveInputNode());
2974 } 3298 }
2975 3299
2976 TEST_P(CrasAudioHandlerTest, 3300 TEST_P(CrasAudioHandlerTest,
2977 ChangeActiveNodesHotrodInitWithSingleJabraChangeOutputOldCall) { 3301 ChangeActiveNodesHotrodInitWithSingleJabraChangeOutputOldCall) {
2978 AudioNodeList audio_nodes = 3302 AudioNodeList audio_nodes =
2979 GenerateAudioNodeList({kHDMIOutput, kUSBJabraSpeakerOutput1, 3303 GenerateAudioNodeList({kHDMIOutput, kUSBJabraSpeakerOutput1,
2980 kUSBJabraSpeakerInput1, kUSBCameraInput}); 3304 kUSBJabraSpeakerInput1, kUSBCameraInput});
2981 SetUpCrasAudioHandler(audio_nodes); 3305 SetUpCrasAudioHandler(audio_nodes);
2982 3306
2983 // Verify the audio devices size. 3307 // Verify the audio devices size.
2984 AudioDeviceList audio_devices; 3308 AudioDeviceList audio_devices;
2985 cras_audio_handler_->GetAudioDevices(&audio_devices); 3309 cras_audio_handler_->GetAudioDevices(&audio_devices);
2986 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); 3310 EXPECT_EQ(audio_nodes.size(), audio_devices.size());
2987 3311
2988 // Verify the jabra speaker's output and input are selected as active output 3312 // Verify the jabra speaker's output and input are selected as active output
2989 // by CrasAudioHandler. 3313 // by CrasAudioHandler.
2990 EXPECT_EQ(2, GetActiveDeviceCount()); 3314 EXPECT_EQ(2, GetActiveDeviceCount());
2991 EXPECT_EQ(kUSBJabraSpeakerOutput1->id, 3315 EXPECT_EQ(kUSBJabraSpeakerOutput1->id,
2992 cras_audio_handler_->GetPrimaryActiveOutputNode()); 3316 cras_audio_handler_->GetPrimaryActiveOutputNode());
2993 EXPECT_EQ(kUSBJabraSpeakerInput1->id, 3317 EXPECT_EQ(kUSBJabraSpeakerInput1->id,
2994 cras_audio_handler_->GetPrimaryActiveInputNode()); 3318 cras_audio_handler_->GetPrimaryActiveInputNode());
2995 3319
2996 // Simulate hotrod app call SetActiveDevices to change active output 3320 // Simulate hotrod app call SetActiveDevices to change active output
2997 // with only a single active output nodes passed in, which is the old 3321 // with only a single active output nodes passed in, which is the old
2998 // way of hotrod app. 3322 // way of hotrod app.
2999 CrasAudioHandler::NodeIdList active_nodes; 3323 cras_audio_handler_->ChangeActiveNodes({kHDMIOutput->id});
3000 active_nodes.push_back(kHDMIOutput->id);
3001 cras_audio_handler_->ChangeActiveNodes(active_nodes);
3002 3324
3003 // Verify the jabra speaker's output is selected as active output, and 3325 // Verify the jabra speaker's output is selected as active output, and
3004 // jabra's input is selected as active input. 3326 // jabra's input is selected as active input.
3005 EXPECT_EQ(2, GetActiveDeviceCount()); 3327 EXPECT_EQ(2, GetActiveDeviceCount());
3006 EXPECT_EQ(kHDMIOutput->id, cras_audio_handler_->GetPrimaryActiveOutputNode()); 3328 EXPECT_EQ(kHDMIOutput->id, cras_audio_handler_->GetPrimaryActiveOutputNode());
3007 EXPECT_EQ(kUSBJabraSpeakerInput1->id, 3329 EXPECT_EQ(kUSBJabraSpeakerInput1->id,
3008 cras_audio_handler_->GetPrimaryActiveInputNode()); 3330 cras_audio_handler_->GetPrimaryActiveInputNode());
3009 } 3331 }
3010 3332
3333 TEST_P(CrasAudioHandlerTest, SetEmptyActiveOutputNodes) {
3334 AudioNodeList audio_nodes =
3335 GenerateAudioNodeList({kHDMIOutput, kUSBJabraSpeakerOutput1,
3336 kUSBJabraSpeakerInput1, kUSBCameraInput});
3337 SetUpCrasAudioHandler(audio_nodes);
3338
3339 // Verify the audio devices size.
3340 AudioDeviceList audio_devices;
3341 cras_audio_handler_->GetAudioDevices(&audio_devices);
3342 EXPECT_EQ(audio_nodes.size(), audio_devices.size());
3343
3344 // Verify the jabra speaker's output and input are selected as active output
3345 // by CrasAudioHandler.
3346 EXPECT_EQ(2, GetActiveDeviceCount());
3347 EXPECT_EQ(kUSBJabraSpeakerOutput1->id,
3348 cras_audio_handler_->GetPrimaryActiveOutputNode());
3349 EXPECT_EQ(kUSBJabraSpeakerInput1->id,
3350 cras_audio_handler_->GetPrimaryActiveInputNode());
3351
3352 cras_audio_handler_->SetActiveOutputNodes(CrasAudioHandler::NodeIdList());
3353
3354 // Verify the jabra's input is selected as active input, and that there are
3355 // no active outputs.
3356 EXPECT_EQ(1, GetActiveDeviceCount());
3357 EXPECT_EQ(kUSBJabraSpeakerInput1->id,
3358 cras_audio_handler_->GetPrimaryActiveInputNode());
3359 EXPECT_EQ(0u, cras_audio_handler_->GetPrimaryActiveOutputNode());
3360 }
3361
3362 TEST_P(CrasAudioHandlerTest, SetEmptyActiveInputNodes) {
3363 AudioNodeList audio_nodes =
3364 GenerateAudioNodeList({kHDMIOutput, kUSBJabraSpeakerOutput1,
3365 kUSBJabraSpeakerInput1, kUSBCameraInput});
3366 SetUpCrasAudioHandler(audio_nodes);
3367
3368 // Verify the audio devices size.
3369 AudioDeviceList audio_devices;
3370 cras_audio_handler_->GetAudioDevices(&audio_devices);
3371 EXPECT_EQ(audio_nodes.size(), audio_devices.size());
3372
3373 // Verify the jabra speaker's output and input are selected as active output
3374 // by CrasAudioHandler.
3375 EXPECT_EQ(2, GetActiveDeviceCount());
3376 EXPECT_EQ(kUSBJabraSpeakerOutput1->id,
3377 cras_audio_handler_->GetPrimaryActiveOutputNode());
3378 EXPECT_EQ(kUSBJabraSpeakerInput1->id,
3379 cras_audio_handler_->GetPrimaryActiveInputNode());
3380
3381 cras_audio_handler_->SetActiveInputNodes(CrasAudioHandler::NodeIdList());
3382
3383 // Verify the jabra speaker's output is selected as active output, and
3384 // there are no active inputs..
3385 EXPECT_EQ(1, GetActiveDeviceCount());
3386 EXPECT_EQ(kUSBJabraSpeakerOutput1->id,
3387 cras_audio_handler_->GetPrimaryActiveOutputNode());
3388 EXPECT_EQ(0u, cras_audio_handler_->GetPrimaryActiveInputNode());
3389 }
3390
3011 TEST_P(CrasAudioHandlerTest, NoMoreAudioInputDevices) { 3391 TEST_P(CrasAudioHandlerTest, NoMoreAudioInputDevices) {
3012 // Some device like chromebox does not have the internal input device. The 3392 // Some device like chromebox does not have the internal input device. The
3013 // active devices should be reset when the user plugs a device and then 3393 // active devices should be reset when the user plugs a device and then
3014 // unplugs it to such device. 3394 // unplugs it to such device.
3015 AudioNodeList audio_nodes = GenerateAudioNodeList({kInternalSpeaker}); 3395 AudioNodeList audio_nodes = GenerateAudioNodeList({kInternalSpeaker});
3016 SetUpCrasAudioHandler(audio_nodes); 3396 SetUpCrasAudioHandler(audio_nodes);
3017 3397
3018 EXPECT_EQ(0ULL, cras_audio_handler_->GetPrimaryActiveInputNode()); 3398 EXPECT_EQ(0ULL, cras_audio_handler_->GetPrimaryActiveInputNode());
3019 3399
3020 audio_nodes.push_back(GenerateAudioNode(kMicJack)); 3400 audio_nodes.push_back(GenerateAudioNode(kMicJack));
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
3294 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); 3674 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output));
3295 EXPECT_EQ(kInternalSpeaker->id, active_output.id); 3675 EXPECT_EQ(kInternalSpeaker->id, active_output.id);
3296 EXPECT_EQ(kInternalSpeaker->id, 3676 EXPECT_EQ(kInternalSpeaker->id,
3297 cras_audio_handler_->GetPrimaryActiveOutputNode()); 3677 cras_audio_handler_->GetPrimaryActiveOutputNode());
3298 EXPECT_FALSE(cras_audio_handler_->IsOutputMuted()); 3678 EXPECT_FALSE(cras_audio_handler_->IsOutputMuted());
3299 EXPECT_EQ(1, test_observer_->output_mute_changed_count()); 3679 EXPECT_EQ(1, test_observer_->output_mute_changed_count());
3300 EXPECT_TRUE(test_observer_->output_mute_by_system()); 3680 EXPECT_TRUE(test_observer_->output_mute_by_system());
3301 } 3681 }
3302 3682
3303 } // namespace chromeos 3683 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/audio/cras_audio_handler.cc ('k') | extensions/browser/api/audio/audio_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698