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

Side by Side Diff: extensions/browser/api/audio/audio_apitest.cc

Issue 2585413002: Update audio api to use v2 stable device ID (Closed)
Patch Set: rebase 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 | « no previous file | extensions/browser/api/audio/audio_service_chromeos.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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 const AudioNodeInfo kJabraMic2 = { 68 const AudioNodeInfo kJabraMic2 = {
69 true, kJabraMic2Id, kJabraMic2StableDeviceId, 69 true, kJabraMic2Id, kJabraMic2StableDeviceId,
70 "Jabra Mic", "USB", "Jabra Mic 2"}; 70 "Jabra Mic", "USB", "Jabra Mic 2"};
71 71
72 const AudioNodeInfo kUSBCameraMic = { 72 const AudioNodeInfo kUSBCameraMic = {
73 true, kWebcamMicId, kWebcamMicStableDeviceId, 73 true, kWebcamMicId, kWebcamMicStableDeviceId,
74 "Webcam Mic", "USB", "Logitech Webcam"}; 74 "Webcam Mic", "USB", "Logitech Webcam"};
75 75
76 AudioNode CreateAudioNode(const AudioNodeInfo& info, int version) { 76 AudioNode CreateAudioNode(const AudioNodeInfo& info, int version) {
77 return AudioNode(info.is_input, info.id, version == 2, 77 return AudioNode(info.is_input, info.id, version == 2,
78 // stable_device_id: 78 // stable_device_id_v1:
79 info.stable_id ^ (version == 1 ? 0 : 0xFFFF), 79 info.stable_id,
80 // stable_device_id_old: 80 // stable_device_id_v2:
81 version == 1 ? 0 : info.stable_id, info.device_name, 81 version == 2 ? info.stable_id ^ 0xFFFF : 0, info.device_name,
82 info.type, info.name, false, 0); 82 info.type, info.name, false, 0);
83 } 83 }
84 84
85 class AudioApiTest : public ShellApiTest { 85 class AudioApiTest : public ShellApiTest {
86 public: 86 public:
87 AudioApiTest() : cras_audio_handler_(NULL), fake_cras_audio_client_(NULL) {} 87 AudioApiTest() : cras_audio_handler_(NULL), fake_cras_audio_client_(NULL) {}
88 ~AudioApiTest() override {} 88 ~AudioApiTest() override {}
89 89
90 void SetUpCrasAudioHandlerWithTestingNodes(const AudioNodeList& audio_nodes) { 90 void SetUpCrasAudioHandlerWithTestingNodes(const AudioNodeList& audio_nodes) {
91 chromeos::DBusThreadManager* dbus_manager = 91 chromeos::DBusThreadManager* dbus_manager =
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 CreateAudioNode(kJabraSpeaker1, 2), CreateAudioNode(kJabraSpeaker2, 2), 131 CreateAudioNode(kJabraSpeaker1, 2), CreateAudioNode(kJabraSpeaker2, 2),
132 CreateAudioNode(kHDMIOutput, 2), CreateAudioNode(kJabraMic1, 2), 132 CreateAudioNode(kHDMIOutput, 2), CreateAudioNode(kJabraMic1, 2),
133 CreateAudioNode(kJabraMic2, 2), CreateAudioNode(kUSBCameraMic, 2)}; 133 CreateAudioNode(kJabraMic2, 2), CreateAudioNode(kUSBCameraMic, 2)};
134 134
135 SetUpCrasAudioHandlerWithTestingNodes(audio_nodes); 135 SetUpCrasAudioHandlerWithTestingNodes(audio_nodes);
136 136
137 EXPECT_TRUE(RunAppTest("api_test/audio")) << message_; 137 EXPECT_TRUE(RunAppTest("api_test/audio")) << message_;
138 } 138 }
139 139
140 IN_PROC_BROWSER_TEST_F(AudioApiTest, OnLevelChangedOutputDevice) { 140 IN_PROC_BROWSER_TEST_F(AudioApiTest, OnLevelChangedOutputDevice) {
141 AudioNodeList audio_nodes = {CreateAudioNode(kJabraSpeaker1, 1), 141 AudioNodeList audio_nodes = {CreateAudioNode(kJabraSpeaker1, 2),
142 CreateAudioNode(kHDMIOutput, 1)}; 142 CreateAudioNode(kHDMIOutput, 2)};
143 SetUpCrasAudioHandlerWithTestingNodes(audio_nodes); 143 SetUpCrasAudioHandlerWithTestingNodes(audio_nodes);
144 144
145 // Verify the jabra speaker is the active output device. 145 // Verify the jabra speaker is the active output device.
146 AudioDevice device; 146 AudioDevice device;
147 EXPECT_TRUE(cras_audio_handler_->GetPrimaryActiveOutputDevice(&device)); 147 EXPECT_TRUE(cras_audio_handler_->GetPrimaryActiveOutputDevice(&device));
148 EXPECT_EQ(device.id, kJabraSpeaker1.id); 148 EXPECT_EQ(device.id, kJabraSpeaker1.id);
149 149
150 // Loads background app. 150 // Loads background app.
151 ResultCatcher result_catcher; 151 ResultCatcher result_catcher;
152 ExtensionTestMessageListener load_listener("loaded", false); 152 ExtensionTestMessageListener load_listener("loaded", false);
153 ASSERT_TRUE(LoadApp("api_test/audio/volume_change")); 153 ASSERT_TRUE(LoadApp("api_test/audio/volume_change"));
154 ASSERT_TRUE(load_listener.WaitUntilSatisfied()); 154 ASSERT_TRUE(load_listener.WaitUntilSatisfied());
155 155
156 // Change output device volume. 156 // Change output device volume.
157 const int kVolume = 60; 157 const int kVolume = 60;
158 cras_audio_handler_->SetOutputVolumePercent(kVolume); 158 cras_audio_handler_->SetOutputVolumePercent(kVolume);
159 159
160 // Verify the output volume is changed to the designated value. 160 // Verify the output volume is changed to the designated value.
161 EXPECT_EQ(kVolume, cras_audio_handler_->GetOutputVolumePercent()); 161 EXPECT_EQ(kVolume, cras_audio_handler_->GetOutputVolumePercent());
162 EXPECT_EQ(kVolume, 162 EXPECT_EQ(kVolume,
163 cras_audio_handler_->GetOutputVolumePercentForDevice(device.id)); 163 cras_audio_handler_->GetOutputVolumePercentForDevice(device.id));
164 164
165 // Verify the background app got the OnOutputNodeVolumeChanged event 165 // Verify the background app got the OnOutputNodeVolumeChanged event
166 // with the expected node id and volume value. 166 // with the expected node id and volume value.
167 ASSERT_TRUE(result_catcher.GetNextResult()) << result_catcher.message(); 167 ASSERT_TRUE(result_catcher.GetNextResult()) << result_catcher.message();
168 } 168 }
169 169
170 IN_PROC_BROWSER_TEST_F(AudioApiTest, OnOutputMuteChanged) { 170 IN_PROC_BROWSER_TEST_F(AudioApiTest, OnOutputMuteChanged) {
171 AudioNodeList audio_nodes = {CreateAudioNode(kJabraSpeaker1, 1), 171 AudioNodeList audio_nodes = {CreateAudioNode(kJabraSpeaker1, 2),
172 CreateAudioNode(kHDMIOutput, 1)}; 172 CreateAudioNode(kHDMIOutput, 2)};
173 SetUpCrasAudioHandlerWithTestingNodes(audio_nodes); 173 SetUpCrasAudioHandlerWithTestingNodes(audio_nodes);
174 174
175 // Verify the jabra speaker is the active output device. 175 // Verify the jabra speaker is the active output device.
176 AudioDevice device; 176 AudioDevice device;
177 EXPECT_TRUE(cras_audio_handler_->GetPrimaryActiveOutputDevice(&device)); 177 EXPECT_TRUE(cras_audio_handler_->GetPrimaryActiveOutputDevice(&device));
178 EXPECT_EQ(device.id, kJabraSpeaker1.id); 178 EXPECT_EQ(device.id, kJabraSpeaker1.id);
179 179
180 // Mute the output. 180 // Mute the output.
181 cras_audio_handler_->SetOutputMute(true); 181 cras_audio_handler_->SetOutputMute(true);
182 EXPECT_TRUE(cras_audio_handler_->IsOutputMuted()); 182 EXPECT_TRUE(cras_audio_handler_->IsOutputMuted());
183 183
184 // Loads background app. 184 // Loads background app.
185 ResultCatcher result_catcher; 185 ResultCatcher result_catcher;
186 ExtensionTestMessageListener load_listener("loaded", false); 186 ExtensionTestMessageListener load_listener("loaded", false);
187 ASSERT_TRUE(LoadApp("api_test/audio/output_mute_change")); 187 ASSERT_TRUE(LoadApp("api_test/audio/output_mute_change"));
188 ASSERT_TRUE(load_listener.WaitUntilSatisfied()); 188 ASSERT_TRUE(load_listener.WaitUntilSatisfied());
189 189
190 // Un-mute the output. 190 // Un-mute the output.
191 cras_audio_handler_->SetOutputMute(false); 191 cras_audio_handler_->SetOutputMute(false);
192 EXPECT_FALSE(cras_audio_handler_->IsOutputMuted()); 192 EXPECT_FALSE(cras_audio_handler_->IsOutputMuted());
193 193
194 // Verify the background app got the OnMuteChanged event 194 // Verify the background app got the OnMuteChanged event
195 // with the expected output un-muted state. 195 // with the expected output un-muted state.
196 EXPECT_TRUE(result_catcher.GetNextResult()) << result_catcher.message(); 196 EXPECT_TRUE(result_catcher.GetNextResult()) << result_catcher.message();
197 } 197 }
198 198
199 IN_PROC_BROWSER_TEST_F(AudioApiTest, OnInputMuteChanged) { 199 IN_PROC_BROWSER_TEST_F(AudioApiTest, OnInputMuteChanged) {
200 AudioNodeList audio_nodes = {CreateAudioNode(kJabraMic1, 1), 200 AudioNodeList audio_nodes = {CreateAudioNode(kJabraMic1, 2),
201 CreateAudioNode(kUSBCameraMic, 1)}; 201 CreateAudioNode(kUSBCameraMic, 2)};
202 SetUpCrasAudioHandlerWithTestingNodes(audio_nodes); 202 SetUpCrasAudioHandlerWithTestingNodes(audio_nodes);
203 203
204 // Set the jabra mic to be the active input device. 204 // Set the jabra mic to be the active input device.
205 AudioDevice jabra_mic(CreateAudioNode(kJabraMic1, 1)); 205 AudioDevice jabra_mic(CreateAudioNode(kJabraMic1, 2));
206 cras_audio_handler_->SwitchToDevice( 206 cras_audio_handler_->SwitchToDevice(
207 jabra_mic, true, chromeos::CrasAudioHandler::ACTIVATE_BY_USER); 207 jabra_mic, true, chromeos::CrasAudioHandler::ACTIVATE_BY_USER);
208 EXPECT_EQ(kJabraMic1.id, cras_audio_handler_->GetPrimaryActiveInputNode()); 208 EXPECT_EQ(kJabraMic1.id, cras_audio_handler_->GetPrimaryActiveInputNode());
209 209
210 // Un-mute the input. 210 // Un-mute the input.
211 cras_audio_handler_->SetInputMute(false); 211 cras_audio_handler_->SetInputMute(false);
212 EXPECT_FALSE(cras_audio_handler_->IsInputMuted()); 212 EXPECT_FALSE(cras_audio_handler_->IsInputMuted());
213 213
214 // Loads background app. 214 // Loads background app.
215 ResultCatcher result_catcher; 215 ResultCatcher result_catcher;
216 ExtensionTestMessageListener load_listener("loaded", false); 216 ExtensionTestMessageListener load_listener("loaded", false);
217 ASSERT_TRUE(LoadApp("api_test/audio/input_mute_change")); 217 ASSERT_TRUE(LoadApp("api_test/audio/input_mute_change"));
218 ASSERT_TRUE(load_listener.WaitUntilSatisfied()); 218 ASSERT_TRUE(load_listener.WaitUntilSatisfied());
219 219
220 // Mute the input. 220 // Mute the input.
221 cras_audio_handler_->SetInputMute(true); 221 cras_audio_handler_->SetInputMute(true);
222 EXPECT_TRUE(cras_audio_handler_->IsInputMuted()); 222 EXPECT_TRUE(cras_audio_handler_->IsInputMuted());
223 223
224 // Verify the background app got the OnMuteChanged event 224 // Verify the background app got the OnMuteChanged event
225 // with the expected input muted state. 225 // with the expected input muted state.
226 EXPECT_TRUE(result_catcher.GetNextResult()) << result_catcher.message(); 226 EXPECT_TRUE(result_catcher.GetNextResult()) << result_catcher.message();
227 } 227 }
228 228
229 IN_PROC_BROWSER_TEST_F(AudioApiTest, OnNodesChangedAddNodes) { 229 IN_PROC_BROWSER_TEST_F(AudioApiTest, OnNodesChangedAddNodes) {
230 AudioNodeList audio_nodes = {CreateAudioNode(kJabraSpeaker1, 1), 230 AudioNodeList audio_nodes = {CreateAudioNode(kJabraSpeaker1, 2),
231 CreateAudioNode(kJabraSpeaker2, 1)}; 231 CreateAudioNode(kJabraSpeaker2, 2)};
232 SetUpCrasAudioHandlerWithTestingNodes(audio_nodes); 232 SetUpCrasAudioHandlerWithTestingNodes(audio_nodes);
233 const size_t init_device_size = audio_nodes.size(); 233 const size_t init_device_size = audio_nodes.size();
234 234
235 AudioDeviceList audio_devices; 235 AudioDeviceList audio_devices;
236 cras_audio_handler_->GetAudioDevices(&audio_devices); 236 cras_audio_handler_->GetAudioDevices(&audio_devices);
237 EXPECT_EQ(init_device_size, audio_devices.size()); 237 EXPECT_EQ(init_device_size, audio_devices.size());
238 238
239 // Load background app. 239 // Load background app.
240 ResultCatcher result_catcher; 240 ResultCatcher result_catcher;
241 ExtensionTestMessageListener load_listener("loaded", false); 241 ExtensionTestMessageListener load_listener("loaded", false);
242 ASSERT_TRUE(LoadApp("api_test/audio/add_nodes")); 242 ASSERT_TRUE(LoadApp("api_test/audio/add_nodes"));
243 ASSERT_TRUE(load_listener.WaitUntilSatisfied()); 243 ASSERT_TRUE(load_listener.WaitUntilSatisfied());
244 244
245 // Plug in HDMI output. 245 // Plug in HDMI output.
246 audio_nodes.push_back(CreateAudioNode(kHDMIOutput, 1)); 246 audio_nodes.push_back(CreateAudioNode(kHDMIOutput, 2));
247 ChangeAudioNodes(audio_nodes); 247 ChangeAudioNodes(audio_nodes);
248 cras_audio_handler_->GetAudioDevices(&audio_devices); 248 cras_audio_handler_->GetAudioDevices(&audio_devices);
249 EXPECT_EQ(init_device_size + 1, audio_devices.size()); 249 EXPECT_EQ(init_device_size + 1, audio_devices.size());
250 250
251 // Verify the background app got the OnNodesChanged event 251 // Verify the background app got the OnNodesChanged event
252 // with the new node added. 252 // with the new node added.
253 EXPECT_TRUE(result_catcher.GetNextResult()) << result_catcher.message(); 253 EXPECT_TRUE(result_catcher.GetNextResult()) << result_catcher.message();
254 } 254 }
255 255
256 IN_PROC_BROWSER_TEST_F(AudioApiTest, OnNodesChangedRemoveNodes) { 256 IN_PROC_BROWSER_TEST_F(AudioApiTest, OnNodesChangedRemoveNodes) {
257 AudioNodeList audio_nodes = {CreateAudioNode(kJabraMic1, 1), 257 AudioNodeList audio_nodes = {CreateAudioNode(kJabraMic1, 2),
258 CreateAudioNode(kJabraMic2, 1), 258 CreateAudioNode(kJabraMic2, 2),
259 CreateAudioNode(kUSBCameraMic, 1)}; 259 CreateAudioNode(kUSBCameraMic, 2)};
260 SetUpCrasAudioHandlerWithTestingNodes(audio_nodes); 260 SetUpCrasAudioHandlerWithTestingNodes(audio_nodes);
261 const size_t init_device_size = audio_nodes.size(); 261 const size_t init_device_size = audio_nodes.size();
262 262
263 AudioDeviceList audio_devices; 263 AudioDeviceList audio_devices;
264 cras_audio_handler_->GetAudioDevices(&audio_devices); 264 cras_audio_handler_->GetAudioDevices(&audio_devices);
265 EXPECT_EQ(init_device_size, audio_devices.size()); 265 EXPECT_EQ(init_device_size, audio_devices.size());
266 266
267 // Load background app. 267 // Load background app.
268 ResultCatcher result_catcher; 268 ResultCatcher result_catcher;
269 ExtensionTestMessageListener load_listener("loaded", false); 269 ExtensionTestMessageListener load_listener("loaded", false);
270 ASSERT_TRUE(LoadApp("api_test/audio/remove_nodes")); 270 ASSERT_TRUE(LoadApp("api_test/audio/remove_nodes"));
271 ASSERT_TRUE(load_listener.WaitUntilSatisfied()); 271 ASSERT_TRUE(load_listener.WaitUntilSatisfied());
272 272
273 // Remove camera mic. 273 // Remove camera mic.
274 audio_nodes.erase(audio_nodes.begin() + init_device_size - 1); 274 audio_nodes.erase(audio_nodes.begin() + init_device_size - 1);
275 ChangeAudioNodes(audio_nodes); 275 ChangeAudioNodes(audio_nodes);
276 cras_audio_handler_->GetAudioDevices(&audio_devices); 276 cras_audio_handler_->GetAudioDevices(&audio_devices);
277 EXPECT_EQ(init_device_size - 1, audio_devices.size()); 277 EXPECT_EQ(init_device_size - 1, audio_devices.size());
278 278
279 // Verify the background app got the onNodesChanged event 279 // Verify the background app got the onNodesChanged event
280 // with the last node removed. 280 // with the last node removed.
281 EXPECT_TRUE(result_catcher.GetNextResult()) << result_catcher.message(); 281 EXPECT_TRUE(result_catcher.GetNextResult()) << result_catcher.message();
282 } 282 }
283 283
284 #endif // OS_CHROMEOS 284 #endif // OS_CHROMEOS
285 285
286 } // namespace extensions 286 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | extensions/browser/api/audio/audio_service_chromeos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698