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

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

Issue 2462833002: Refactor audio API tests (Closed)
Patch Set: Refactor audio API tests Created 4 years, 1 month 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/test/data/api_test/audio/add_nodes/background.js » ('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"
11 #include "extensions/shell/test/shell_apitest.h" 11 #include "extensions/shell/test/shell_apitest.h"
12 #include "extensions/test/extension_test_message_listener.h"
13 #include "extensions/test/result_catcher.h"
14
12 #if defined(OS_CHROMEOS) 15 #if defined(OS_CHROMEOS)
13 #include "chromeos/audio/audio_devices_pref_handler_stub.h" 16 #include "chromeos/audio/audio_devices_pref_handler_stub.h"
14 #include "chromeos/audio/cras_audio_handler.h" 17 #include "chromeos/audio/cras_audio_handler.h"
15 #include "chromeos/dbus/dbus_thread_manager.h" 18 #include "chromeos/dbus/dbus_thread_manager.h"
16 #include "chromeos/dbus/fake_cras_audio_client.h" 19 #include "chromeos/dbus/fake_cras_audio_client.h"
17 #endif 20 #endif
18 #include "extensions/test/extension_test_message_listener.h"
19 21
20 namespace extensions { 22 namespace extensions {
21 23
22 #if defined(OS_CHROMEOS) 24 #if defined(OS_CHROMEOS)
23 using chromeos::AudioDevice; 25 using chromeos::AudioDevice;
24 using chromeos::AudioDeviceList; 26 using chromeos::AudioDeviceList;
25 using chromeos::AudioNode; 27 using chromeos::AudioNode;
26 using chromeos::AudioNodeList; 28 using chromeos::AudioNodeList;
27 29
28 const uint64_t kJabraSpeaker1Id = 30001; 30 const uint64_t kJabraSpeaker1Id = 30001;
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 audio_nodes.push_back(kJabraSpeaker1); 144 audio_nodes.push_back(kJabraSpeaker1);
143 audio_nodes.push_back(kHDMIOutput); 145 audio_nodes.push_back(kHDMIOutput);
144 SetUpCrasAudioHandlerWithTestingNodes(audio_nodes); 146 SetUpCrasAudioHandlerWithTestingNodes(audio_nodes);
145 147
146 // Verify the jabra speaker is the active output device. 148 // Verify the jabra speaker is the active output device.
147 AudioDevice device; 149 AudioDevice device;
148 EXPECT_TRUE(cras_audio_handler_->GetPrimaryActiveOutputDevice(&device)); 150 EXPECT_TRUE(cras_audio_handler_->GetPrimaryActiveOutputDevice(&device));
149 EXPECT_EQ(device.id, kJabraSpeaker1.id); 151 EXPECT_EQ(device.id, kJabraSpeaker1.id);
150 152
151 // Loads background app. 153 // Loads background app.
154 ResultCatcher result_catcher;
152 ExtensionTestMessageListener load_listener("loaded", false); 155 ExtensionTestMessageListener load_listener("loaded", false);
153 ExtensionTestMessageListener result_listener("success", false);
154 result_listener.set_failure_message("failure");
155 ASSERT_TRUE(LoadApp("api_test/audio/volume_change")); 156 ASSERT_TRUE(LoadApp("api_test/audio/volume_change"));
156 ASSERT_TRUE(load_listener.WaitUntilSatisfied()); 157 ASSERT_TRUE(load_listener.WaitUntilSatisfied());
157 158
158 // Change output device volume. 159 // Change output device volume.
159 const int kVolume = 60; 160 const int kVolume = 60;
160 cras_audio_handler_->SetOutputVolumePercent(kVolume); 161 cras_audio_handler_->SetOutputVolumePercent(kVolume);
161 162
162 // Verify the output volume is changed to the designated value. 163 // Verify the output volume is changed to the designated value.
163 EXPECT_EQ(kVolume, cras_audio_handler_->GetOutputVolumePercent()); 164 EXPECT_EQ(kVolume, cras_audio_handler_->GetOutputVolumePercent());
164 EXPECT_EQ(kVolume, 165 EXPECT_EQ(kVolume,
165 cras_audio_handler_->GetOutputVolumePercentForDevice(device.id)); 166 cras_audio_handler_->GetOutputVolumePercentForDevice(device.id));
166 167
167 // Verify the background app got the OnOutputNodeVolumeChanged event 168 // Verify the background app got the OnOutputNodeVolumeChanged event
168 // with the expected node id and volume value. 169 // with the expected node id and volume value.
169 ASSERT_TRUE(result_listener.WaitUntilSatisfied()); 170 ASSERT_TRUE(result_catcher.GetNextResult()) << result_catcher.message();
170 EXPECT_EQ("success", result_listener.message());
171 } 171 }
172 172
173 IN_PROC_BROWSER_TEST_F(AudioApiTest, OnOutputMuteChanged) { 173 IN_PROC_BROWSER_TEST_F(AudioApiTest, OnOutputMuteChanged) {
174 AudioNodeList audio_nodes; 174 AudioNodeList audio_nodes;
175 audio_nodes.push_back(kJabraSpeaker1); 175 audio_nodes.push_back(kJabraSpeaker1);
176 audio_nodes.push_back(kHDMIOutput); 176 audio_nodes.push_back(kHDMIOutput);
177 SetUpCrasAudioHandlerWithTestingNodes(audio_nodes); 177 SetUpCrasAudioHandlerWithTestingNodes(audio_nodes);
178 178
179 // Verify the jabra speaker is the active output device. 179 // Verify the jabra speaker is the active output device.
180 AudioDevice device; 180 AudioDevice device;
181 EXPECT_TRUE(cras_audio_handler_->GetPrimaryActiveOutputDevice(&device)); 181 EXPECT_TRUE(cras_audio_handler_->GetPrimaryActiveOutputDevice(&device));
182 EXPECT_EQ(device.id, kJabraSpeaker1.id); 182 EXPECT_EQ(device.id, kJabraSpeaker1.id);
183 183
184 // Mute the output. 184 // Mute the output.
185 cras_audio_handler_->SetOutputMute(true); 185 cras_audio_handler_->SetOutputMute(true);
186 EXPECT_TRUE(cras_audio_handler_->IsOutputMuted()); 186 EXPECT_TRUE(cras_audio_handler_->IsOutputMuted());
187 187
188 // Loads background app. 188 // Loads background app.
189 ResultCatcher result_catcher;
189 ExtensionTestMessageListener load_listener("loaded", false); 190 ExtensionTestMessageListener load_listener("loaded", false);
190 ExtensionTestMessageListener result_listener("success", false);
191 result_listener.set_failure_message("failure");
192 ASSERT_TRUE(LoadApp("api_test/audio/output_mute_change")); 191 ASSERT_TRUE(LoadApp("api_test/audio/output_mute_change"));
193 ASSERT_TRUE(load_listener.WaitUntilSatisfied()); 192 ASSERT_TRUE(load_listener.WaitUntilSatisfied());
194 193
195 // Un-mute the output. 194 // Un-mute the output.
196 cras_audio_handler_->SetOutputMute(false); 195 cras_audio_handler_->SetOutputMute(false);
197 EXPECT_FALSE(cras_audio_handler_->IsOutputMuted()); 196 EXPECT_FALSE(cras_audio_handler_->IsOutputMuted());
198 197
199 // Verify the background app got the OnMuteChanged event 198 // Verify the background app got the OnMuteChanged event
200 // with the expected output un-muted state. 199 // with the expected output un-muted state.
201 ASSERT_TRUE(result_listener.WaitUntilSatisfied()); 200 EXPECT_TRUE(result_catcher.GetNextResult()) << result_catcher.message();
202 EXPECT_EQ("success", result_listener.message());
203 } 201 }
204 202
205 IN_PROC_BROWSER_TEST_F(AudioApiTest, OnInputMuteChanged) { 203 IN_PROC_BROWSER_TEST_F(AudioApiTest, OnInputMuteChanged) {
206 AudioNodeList audio_nodes; 204 AudioNodeList audio_nodes;
207 audio_nodes.push_back(kJabraMic1); 205 audio_nodes.push_back(kJabraMic1);
208 audio_nodes.push_back(kUSBCameraMic); 206 audio_nodes.push_back(kUSBCameraMic);
209 SetUpCrasAudioHandlerWithTestingNodes(audio_nodes); 207 SetUpCrasAudioHandlerWithTestingNodes(audio_nodes);
210 208
211 // Set the jabra mic to be the active input device. 209 // Set the jabra mic to be the active input device.
212 AudioDevice jabra_mic(kJabraMic1); 210 AudioDevice jabra_mic(kJabraMic1);
213 cras_audio_handler_->SwitchToDevice( 211 cras_audio_handler_->SwitchToDevice(
214 jabra_mic, true, chromeos::CrasAudioHandler::ACTIVATE_BY_USER); 212 jabra_mic, true, chromeos::CrasAudioHandler::ACTIVATE_BY_USER);
215 EXPECT_EQ(kJabraMic1.id, cras_audio_handler_->GetPrimaryActiveInputNode()); 213 EXPECT_EQ(kJabraMic1.id, cras_audio_handler_->GetPrimaryActiveInputNode());
216 214
217 // Un-mute the input. 215 // Un-mute the input.
218 cras_audio_handler_->SetInputMute(false); 216 cras_audio_handler_->SetInputMute(false);
219 EXPECT_FALSE(cras_audio_handler_->IsInputMuted()); 217 EXPECT_FALSE(cras_audio_handler_->IsInputMuted());
220 218
221 // Loads background app. 219 // Loads background app.
220 ResultCatcher result_catcher;
222 ExtensionTestMessageListener load_listener("loaded", false); 221 ExtensionTestMessageListener load_listener("loaded", false);
223 ExtensionTestMessageListener result_listener("success", false);
224 result_listener.set_failure_message("failure");
225 ASSERT_TRUE(LoadApp("api_test/audio/input_mute_change")); 222 ASSERT_TRUE(LoadApp("api_test/audio/input_mute_change"));
226 ASSERT_TRUE(load_listener.WaitUntilSatisfied()); 223 ASSERT_TRUE(load_listener.WaitUntilSatisfied());
227 224
228 // Mute the input. 225 // Mute the input.
229 cras_audio_handler_->SetInputMute(true); 226 cras_audio_handler_->SetInputMute(true);
230 EXPECT_TRUE(cras_audio_handler_->IsInputMuted()); 227 EXPECT_TRUE(cras_audio_handler_->IsInputMuted());
231 228
232 // Verify the background app got the OnMuteChanged event 229 // Verify the background app got the OnMuteChanged event
233 // with the expected input muted state. 230 // with the expected input muted state.
234 ASSERT_TRUE(result_listener.WaitUntilSatisfied()); 231 EXPECT_TRUE(result_catcher.GetNextResult()) << result_catcher.message();
235 EXPECT_EQ("success", result_listener.message());
236 } 232 }
237 233
238 IN_PROC_BROWSER_TEST_F(AudioApiTest, OnNodesChangedAddNodes) { 234 IN_PROC_BROWSER_TEST_F(AudioApiTest, OnNodesChangedAddNodes) {
239 AudioNodeList audio_nodes; 235 AudioNodeList audio_nodes;
240 audio_nodes.push_back(kJabraSpeaker1); 236 audio_nodes.push_back(kJabraSpeaker1);
241 audio_nodes.push_back(kJabraSpeaker2); 237 audio_nodes.push_back(kJabraSpeaker2);
242 SetUpCrasAudioHandlerWithTestingNodes(audio_nodes); 238 SetUpCrasAudioHandlerWithTestingNodes(audio_nodes);
243 const size_t init_device_size = audio_nodes.size(); 239 const size_t init_device_size = audio_nodes.size();
244 240
245 AudioDeviceList audio_devices; 241 AudioDeviceList audio_devices;
246 cras_audio_handler_->GetAudioDevices(&audio_devices); 242 cras_audio_handler_->GetAudioDevices(&audio_devices);
247 EXPECT_EQ(init_device_size, audio_devices.size()); 243 EXPECT_EQ(init_device_size, audio_devices.size());
248 244
249 // Load background app. 245 // Load background app.
246 ResultCatcher result_catcher;
250 ExtensionTestMessageListener load_listener("loaded", false); 247 ExtensionTestMessageListener load_listener("loaded", false);
251 ExtensionTestMessageListener result_listener("success", false);
252 result_listener.set_failure_message("failure");
253 ASSERT_TRUE(LoadApp("api_test/audio/add_nodes")); 248 ASSERT_TRUE(LoadApp("api_test/audio/add_nodes"));
254 ASSERT_TRUE(load_listener.WaitUntilSatisfied()); 249 ASSERT_TRUE(load_listener.WaitUntilSatisfied());
255 250
256 // Plug in HDMI output. 251 // Plug in HDMI output.
257 audio_nodes.push_back(kHDMIOutput); 252 audio_nodes.push_back(kHDMIOutput);
258 ChangeAudioNodes(audio_nodes); 253 ChangeAudioNodes(audio_nodes);
259 cras_audio_handler_->GetAudioDevices(&audio_devices); 254 cras_audio_handler_->GetAudioDevices(&audio_devices);
260 EXPECT_EQ(init_device_size + 1, audio_devices.size()); 255 EXPECT_EQ(init_device_size + 1, audio_devices.size());
261 256
262 // Verify the background app got the OnNodesChanged event 257 // Verify the background app got the OnNodesChanged event
263 // with the new node added. 258 // with the new node added.
264 ASSERT_TRUE(result_listener.WaitUntilSatisfied()); 259 EXPECT_TRUE(result_catcher.GetNextResult()) << result_catcher.message();
265 EXPECT_EQ("success", result_listener.message());
266 } 260 }
267 261
268 IN_PROC_BROWSER_TEST_F(AudioApiTest, OnNodesChangedRemoveNodes) { 262 IN_PROC_BROWSER_TEST_F(AudioApiTest, OnNodesChangedRemoveNodes) {
269 AudioNodeList audio_nodes; 263 AudioNodeList audio_nodes;
270 audio_nodes.push_back(kJabraMic1); 264 audio_nodes.push_back(kJabraMic1);
271 audio_nodes.push_back(kJabraMic2); 265 audio_nodes.push_back(kJabraMic2);
272 audio_nodes.push_back(kUSBCameraMic); 266 audio_nodes.push_back(kUSBCameraMic);
273 SetUpCrasAudioHandlerWithTestingNodes(audio_nodes); 267 SetUpCrasAudioHandlerWithTestingNodes(audio_nodes);
274 const size_t init_device_size = audio_nodes.size(); 268 const size_t init_device_size = audio_nodes.size();
275 269
276 AudioDeviceList audio_devices; 270 AudioDeviceList audio_devices;
277 cras_audio_handler_->GetAudioDevices(&audio_devices); 271 cras_audio_handler_->GetAudioDevices(&audio_devices);
278 EXPECT_EQ(init_device_size, audio_devices.size()); 272 EXPECT_EQ(init_device_size, audio_devices.size());
279 273
280 // Load background app. 274 // Load background app.
275 ResultCatcher result_catcher;
281 ExtensionTestMessageListener load_listener("loaded", false); 276 ExtensionTestMessageListener load_listener("loaded", false);
282 ExtensionTestMessageListener result_listener("success", false);
283 result_listener.set_failure_message("failure");
284 ASSERT_TRUE(LoadApp("api_test/audio/remove_nodes")); 277 ASSERT_TRUE(LoadApp("api_test/audio/remove_nodes"));
285 ASSERT_TRUE(load_listener.WaitUntilSatisfied()); 278 ASSERT_TRUE(load_listener.WaitUntilSatisfied());
286 279
287 // Remove camera mic. 280 // Remove camera mic.
288 audio_nodes.erase(audio_nodes.begin() + init_device_size - 1); 281 audio_nodes.erase(audio_nodes.begin() + init_device_size - 1);
289 ChangeAudioNodes(audio_nodes); 282 ChangeAudioNodes(audio_nodes);
290 cras_audio_handler_->GetAudioDevices(&audio_devices); 283 cras_audio_handler_->GetAudioDevices(&audio_devices);
291 EXPECT_EQ(init_device_size - 1, audio_devices.size()); 284 EXPECT_EQ(init_device_size - 1, audio_devices.size());
292 285
293 // Verify the background app got the onNodesChanged event 286 // Verify the background app got the onNodesChanged event
294 // with the last node removed. 287 // with the last node removed.
295 ASSERT_TRUE(result_listener.WaitUntilSatisfied()); 288 EXPECT_TRUE(result_catcher.GetNextResult()) << result_catcher.message();
296 EXPECT_EQ("success", result_listener.message());
297 } 289 }
298 290
299 #endif // OS_CHROMEOS 291 #endif // OS_CHROMEOS
300 292
301 } // namespace extensions 293 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | extensions/test/data/api_test/audio/add_nodes/background.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698