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 "base/message_loop/message_loop.h" |
5 #include "extensions/shell/test/shell_apitest.h" | 6 #include "extensions/shell/test/shell_apitest.h" |
| 7 #if defined(OS_CHROMEOS) |
| 8 #include "chromeos/audio/audio_devices_pref_handler_stub.h" |
| 9 #include "chromeos/audio/cras_audio_handler.h" |
| 10 #include "chromeos/dbus/dbus_thread_manager.h" |
| 11 #include "chromeos/dbus/fake_cras_audio_client.h" |
| 12 #endif |
| 13 #include "extensions/test/extension_test_message_listener.h" |
6 | 14 |
7 namespace extensions { | 15 namespace extensions { |
8 | 16 |
9 using AudioApiTest = ShellApiTest; | 17 #if defined(OS_CHROMEOS) |
| 18 using chromeos::AudioDevice; |
| 19 using chromeos::AudioDeviceList; |
| 20 using chromeos::AudioNode; |
| 21 using chromeos::AudioNodeList; |
10 | 22 |
11 #if defined(OS_CHROMEOS) | 23 const uint64 kJabraSpeaker1Id = 30001; |
| 24 const uint64 kJabraSpeaker2Id = 30002; |
| 25 const uint64 kHDMIOutputId = 30003; |
| 26 const uint64 kJabraMic1Id = 40001; |
| 27 const uint64 kJabraMic2Id = 40002; |
| 28 const uint64 kWebcamMicId = 40003; |
| 29 |
| 30 const AudioNode kJabraSpeaker1(false, |
| 31 kJabraSpeaker1Id, |
| 32 "Jabra Speaker", |
| 33 "USB", |
| 34 "Jabra Speaker 1", |
| 35 false, |
| 36 0); |
| 37 |
| 38 const AudioNode kJabraSpeaker2(false, |
| 39 kJabraSpeaker2Id, |
| 40 "Jabra Speaker", |
| 41 "USB", |
| 42 "Jabra Speaker 2", |
| 43 false, |
| 44 0); |
| 45 |
| 46 const AudioNode kHDMIOutput(false, |
| 47 kHDMIOutputId, |
| 48 "HDMI output", |
| 49 "HDMI", |
| 50 "HDA Intel MID", |
| 51 false, |
| 52 0); |
| 53 |
| 54 const AudioNode |
| 55 kJabraMic1(true, kJabraMic1Id, "Jabra Mic", "USB", "Jabra Mic 1", false, 0); |
| 56 |
| 57 const AudioNode |
| 58 kJabraMic2(true, kJabraMic2Id, "Jabra Mic", "USB", "Jabra Mic 2", false, 0); |
| 59 |
| 60 const AudioNode kUSBCameraMic(true, |
| 61 kWebcamMicId, |
| 62 "Webcam Mic", |
| 63 "USB", |
| 64 "Logitech Webcam", |
| 65 false, |
| 66 0); |
| 67 |
| 68 class AudioApiTest : public ShellApiTest { |
| 69 public: |
| 70 AudioApiTest() : cras_audio_handler_(NULL) {} |
| 71 ~AudioApiTest() override {} |
| 72 |
| 73 void SetUpCrasAudioHandlerWithTestingNodes(const AudioNodeList& audio_nodes) { |
| 74 chromeos::DBusThreadManager* dbus_manager = |
| 75 chromeos::DBusThreadManager::Get(); |
| 76 DCHECK(dbus_manager); |
| 77 chromeos::FakeCrasAudioClient* fake_cras_audio_client = |
| 78 static_cast<chromeos::FakeCrasAudioClient*>( |
| 79 dbus_manager->GetCrasAudioClient()); |
| 80 fake_cras_audio_client->SetAudioNodesAndNotifyObserversForTesting( |
| 81 audio_nodes); |
| 82 cras_audio_handler_ = chromeos::CrasAudioHandler::Get(); |
| 83 DCHECK(cras_audio_handler_); |
| 84 message_loop_.RunUntilIdle(); |
| 85 } |
| 86 |
| 87 protected: |
| 88 base::MessageLoopForUI message_loop_; |
| 89 chromeos::CrasAudioHandler* cras_audio_handler_; // Not owned. |
| 90 }; |
| 91 |
12 IN_PROC_BROWSER_TEST_F(AudioApiTest, Audio) { | 92 IN_PROC_BROWSER_TEST_F(AudioApiTest, Audio) { |
| 93 // Set up the audio nodes for testing. |
| 94 AudioNodeList audio_nodes; |
| 95 audio_nodes.push_back(kJabraSpeaker1); |
| 96 audio_nodes.push_back(kJabraSpeaker2); |
| 97 audio_nodes.push_back(kHDMIOutput); |
| 98 audio_nodes.push_back(kJabraMic1); |
| 99 audio_nodes.push_back(kJabraMic2); |
| 100 audio_nodes.push_back(kUSBCameraMic); |
| 101 SetUpCrasAudioHandlerWithTestingNodes(audio_nodes); |
| 102 |
13 EXPECT_TRUE(RunAppTest("api_test/audio")) << message_; | 103 EXPECT_TRUE(RunAppTest("api_test/audio")) << message_; |
14 } | 104 } |
15 #endif | 105 |
| 106 IN_PROC_BROWSER_TEST_F(AudioApiTest, OnOutputNodeVolumeChanged) { |
| 107 AudioNodeList audio_nodes; |
| 108 audio_nodes.push_back(kJabraSpeaker1); |
| 109 audio_nodes.push_back(kHDMIOutput); |
| 110 SetUpCrasAudioHandlerWithTestingNodes(audio_nodes); |
| 111 |
| 112 // Verify the jabra speaker is the active output device. |
| 113 AudioDevice device; |
| 114 EXPECT_TRUE(cras_audio_handler_->GetPrimaryActiveOutputDevice(&device)); |
| 115 EXPECT_EQ(device.id, kJabraSpeaker1.id); |
| 116 |
| 117 // Loads background app. |
| 118 ExtensionTestMessageListener load_listener("loaded", false); |
| 119 ExtensionTestMessageListener result_listener("success", false); |
| 120 result_listener.set_failure_message("failure"); |
| 121 ASSERT_TRUE(LoadApp("api_test/audio/volume_change")); |
| 122 ASSERT_TRUE(load_listener.WaitUntilSatisfied()); |
| 123 |
| 124 // Change output device volume. |
| 125 const int kVolume = 60; |
| 126 cras_audio_handler_->SetOutputVolumePercent(kVolume); |
| 127 |
| 128 // Verify the output volume is changed to the designated value. |
| 129 EXPECT_EQ(kVolume, cras_audio_handler_->GetOutputVolumePercent()); |
| 130 EXPECT_EQ(kVolume, |
| 131 cras_audio_handler_->GetOutputVolumePercentForDevice(device.id)); |
| 132 |
| 133 // Verify the background app got the OnOutputNodeVolumeChanged event |
| 134 // with the expected node id and volume value. |
| 135 ASSERT_TRUE(result_listener.WaitUntilSatisfied()); |
| 136 EXPECT_EQ("success", result_listener.message()); |
| 137 } |
| 138 #endif // OS_CHROMEOS |
16 | 139 |
17 } // namespace extensions | 140 } // namespace extensions |
OLD | NEW |