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

Side by Side Diff: extensions/test/data/api_test/audio/test.js

Issue 2635983006: Final cleanup pass over audio device API (Closed)
Patch Set: . Created 3 years, 10 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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 /** 5 /**
6 * Asserts that device property values match properties in |expectedProperties|. 6 * Asserts that device property values match properties in |expectedProperties|.
7 * The method will *not* assert that the device contains *only* properties 7 * The method will *not* assert that the device contains *only* properties
8 * specified in expected properties. 8 * specified in expected properties.
9 * @param {Object} expectedProperties Expected device properties. 9 * @param {Object} expectedProperties Expected device properties.
10 * @param {Object} device Device object to test. 10 * @param {Object} device Device object to test.
(...skipping 26 matching lines...) Expand all
37 } 37 }
38 chrome.test.assertEq(sortedKeys(expectedDevices), sortedKeys(deviceIds)); 38 chrome.test.assertEq(sortedKeys(expectedDevices), sortedKeys(deviceIds));
39 39
40 devices.forEach(function(device) { 40 devices.forEach(function(device) {
41 assertDeviceMatches(expectedDevices[device.id], device); 41 assertDeviceMatches(expectedDevices[device.id], device);
42 }); 42 });
43 } 43 }
44 44
45 /** 45 /**
46 * 46 *
47 * @param {Array.<Object>} devices List of devices returned by getInfo 47 * @param {Array.<Object>} devices List of devices returned by
48 * @returns {Object.<string, Object>} List of devices formatted as map of 48 * chrome.audio.getInfo or chrome.audio.getDevices.
49 * @return {Object.<string, Object>} List of devices formatted as map of
49 * expected devices used to assert devices match expectation. 50 * expected devices used to assert devices match expectation.
50 */ 51 */
51 function deviceListToExpectedDevicesMap(devices) { 52 function deviceListToExpectedDevicesMap(devices) {
52 var expectedDevicesMap = {}; 53 var expectedDevicesMap = {};
53 devices.forEach(function(device) { 54 devices.forEach(function(device) {
54 expectedDevicesMap[device.id] = device; 55 expectedDevicesMap[device.id] = device;
55 }); 56 });
56 return expectedDevicesMap; 57 return expectedDevicesMap;
57 } 58 }
58 59
59 function getActiveDeviceIds(deviceList) { 60 /**
60 return deviceList 61 * @param {Array.<Object>} devices List of devices returned by
61 .filter(function(device) {return device.isActive;}) 62 * chrome.audio.getInfo or chrome.audio.getDevices.
62 .map(function(device) {return device.id}); 63 * @return {Array.<string>} Sorted list devices IDs for devices in |devices|.
63 } 64 */
64 65 function getDeviceIds(devices) {
65 function getDevices(callback) { 66 return devices.map(function(device) {return device.id;}).sort();
66 chrome.audio.getInfo(chrome.test.callbackPass(callback));
67 } 67 }
68 68
69 chrome.test.runTests([ 69 chrome.test.runTests([
70 function getInfoTest() { 70 function getInfoTest() {
71 // Test output devices. Maps device ID -> tested device properties. 71 // Test output devices. Maps device ID -> tested device properties.
72 var kTestOutputDevices = { 72 var kTestOutputDevices = {
73 '30001': { 73 '30001': {
74 id: '30001', 74 id: '30001',
75 name: 'Jabra Speaker: Jabra Speaker 1' 75 name: 'Jabra Speaker: Jabra Speaker 1'
76 }, 76 },
(...skipping 16 matching lines...) Expand all
93 '40002': { 93 '40002': {
94 id: '40002', 94 id: '40002',
95 name: 'Jabra Mic: Jabra Mic 2' 95 name: 'Jabra Mic: Jabra Mic 2'
96 }, 96 },
97 '40003': { 97 '40003': {
98 id: '40003', 98 id: '40003',
99 name: 'Webcam Mic: Logitech Webcam' 99 name: 'Webcam Mic: Logitech Webcam'
100 } 100 }
101 }; 101 };
102 102
103 getDevices(function(outputInfo, inputInfo) { 103 chrome.audio.getInfo(chrome.test.callbackPass(
104 assertDevicesMatch(kTestOutputDevices, outputInfo); 104 function(outputInfo, inputInfo) {
105 assertDevicesMatch(kTestInputDevices, inputInfo); 105 assertDevicesMatch(kTestOutputDevices, outputInfo);
106 }); 106 assertDevicesMatch(kTestInputDevices, inputInfo);
107 }));
108 },
109
110 function getDevicesTest() {
111 // Test output devices. Maps device ID -> tested device properties.
112 var kTestDevices = {
113 '30001': {
114 id: '30001',
115 stableDeviceId: '116606',
116 displayName: 'Jabra Speaker 1',
117 deviceName: 'Jabra Speaker',
118 streamType: 'OUTPUT'
119 },
120 '30002': {
121 id: '30002',
122 stableDeviceId: '116605',
123 displayName: 'Jabra Speaker 2',
124 deviceName: 'Jabra Speaker',
125 streamType: 'OUTPUT'
126 },
127 '30003': {
128 id: '30003',
129 stableDeviceId: '116604',
130 displayName: 'HDA Intel MID',
131 deviceName: 'HDMI output',
132 streamType: 'OUTPUT'
133 },
134 '40001': {
135 id: '40001',
136 stableDeviceId: '106606',
137 displayName: 'Jabra Mic 1',
138 deviceName: 'Jabra Mic',
139 streamType: 'INPUT'
140 },
141 '40002': {
142 id: '40002',
143 stableDeviceId: '106605',
144 displayName: 'Jabra Mic 2',
145 deviceName: 'Jabra Mic',
146 streamType: 'INPUT'
147 },
148 '40003': {
149 id: '40003',
150 stableDeviceId: '106604',
151 displayName: 'Logitech Webcam',
152 deviceName: 'Webcam Mic',
153 streamType: 'INPUT'
154 }
155 };
156
157 chrome.audio.getDevices(chrome.test.callbackPass(function(devices) {
158 assertDevicesMatch(kTestDevices, devices);
159 }));
160 },
161
162 function getDevicesWithEmptyFilterTest() {
163 // Test output devices. Maps device ID -> tested device properties.
164 var kTestDevices = {
165 '30001': {
166 id: '30001',
167 stableDeviceId: '116606',
168 displayName: 'Jabra Speaker 1',
169 deviceName: 'Jabra Speaker',
170 streamType: 'OUTPUT'
171 },
172 '30002': {
173 id: '30002',
174 stableDeviceId: '116605',
175 displayName: 'Jabra Speaker 2',
176 deviceName: 'Jabra Speaker',
177 streamType: 'OUTPUT'
178 },
179 '30003': {
180 id: '30003',
181 stableDeviceId: '116604',
182 displayName: 'HDA Intel MID',
183 deviceName: 'HDMI output',
184 streamType: 'OUTPUT'
185 },
186 '40001': {
187 id: '40001',
188 stableDeviceId: '106606',
189 displayName: 'Jabra Mic 1',
190 deviceName: 'Jabra Mic',
191 streamType: 'INPUT'
192 },
193 '40002': {
194 id: '40002',
195 stableDeviceId: '106605',
196 displayName: 'Jabra Mic 2',
197 deviceName: 'Jabra Mic',
198 streamType: 'INPUT'
199 },
200 '40003': {
201 id: '40003',
202 stableDeviceId: '106604',
203 displayName: 'Logitech Webcam',
204 deviceName: 'Webcam Mic',
205 streamType: 'INPUT'
206 }
207 };
208
209 chrome.audio.getDevices({}, chrome.test.callbackPass(function(devices) {
210 assertDevicesMatch(kTestDevices, devices);
211 }));
212 },
213
214 function getInputDevicesTest() {
215 var kTestDevices = {
216 '40001': {
217 id: '40001',
218 streamType: 'INPUT'
219 },
220 '40002': {
221 id: '40002',
222 streamType: 'INPUT'
223 },
224 '40003': {
225 id: '40003',
226 streamType: 'INPUT'
227 }
228 };
229
230 chrome.audio.getDevices({
231 streamTypes: ['INPUT']
232 }, chrome.test.callbackPass(function(devices) {
233 assertDevicesMatch(kTestDevices, devices);
234 }));
235 },
236
237 function getOutputDevicesTest() {
238 var kTestDevices = {
239 '30001': {
240 id: '30001',
241 streamType: 'OUTPUT'
242 },
243 '30002': {
244 id: '30002',
245 streamType: 'OUTPUT'
246 },
247 '30003': {
248 id: '30003',
249 streamType: 'OUTPUT'
250 },
251 };
252
253 chrome.audio.getDevices({
254 streamTypes: ['OUTPUT']
255 }, chrome.test.callbackPass(function(devices) {
256 assertDevicesMatch(kTestDevices, devices);
257 }));
258 },
259
260 function getActiveDevicesTest() {
261 chrome.audio.getDevices(chrome.test.callbackPass(function(initial) {
262 var initialActiveDevices = initial.filter(function(device) {
263 return device.isActive;
264 });
265 chrome.test.assertTrue(initialActiveDevices.length > 0);
266
267 chrome.audio.getDevices({
268 isActive: true
269 }, chrome.test.callbackPass(function(devices) {
270 assertDevicesMatch(
271 deviceListToExpectedDevicesMap(initialActiveDevices),
272 devices);
273 }));
274
275 var initialActiveInputs = initialActiveDevices.filter(function(device) {
276 return device.streamType === 'INPUT';
277 });
278 chrome.test.assertTrue(initialActiveInputs.length > 0);
279
280 chrome.audio.getDevices({
281 isActive: true,
282 streamTypes: ['INPUT']
283 }, chrome.test.callbackPass(function(devices) {
284 assertDevicesMatch(
285 deviceListToExpectedDevicesMap(initialActiveInputs),
286 devices);
287 }));
288
289 var initialActiveOutputs = initialActiveDevices.filter(function(device) {
290 return device.streamType === 'OUTPUT';
291 });
292 chrome.test.assertTrue(initialActiveOutputs.length > 0);
293
294 chrome.audio.getDevices({
295 isActive: true,
296 streamTypes: ['OUTPUT']
297 }, chrome.test.callbackPass(function(devices) {
298 assertDevicesMatch(
299 deviceListToExpectedDevicesMap(initialActiveOutputs),
300 devices);
301 }));
302 }));
303 },
304
305 function getInactiveDevicesTest() {
306 chrome.audio.getDevices(chrome.test.callbackPass(function(initial) {
307 var initialInactiveDevices = initial.filter(function(device) {
308 return !device.isActive;
309 });
310 chrome.test.assertTrue(initialInactiveDevices.length > 0);
311
312 chrome.audio.getDevices({
313 isActive: false
314 }, chrome.test.callbackPass(function(devices) {
315 assertDevicesMatch(
316 deviceListToExpectedDevicesMap(initialInactiveDevices),
317 devices);
318 }));
319 }));
107 }, 320 },
108 321
109 function deprecatedSetActiveDevicesTest() { 322 function deprecatedSetActiveDevicesTest() {
110 //Test output devices. Maps device ID -> tested device properties. 323 //Test output devices. Maps device ID -> tested device properties.
111 var kTestOutputDevices = { 324 var kTestDevices = {
112 '30001': { 325 '30001': {
113 id: '30001', 326 id: '30001',
114 isActive: false 327 isActive: false
115 }, 328 },
116 '30002': { 329 '30002': {
117 id: '30002', 330 id: '30002',
118 isActive: false 331 isActive: false
119 }, 332 },
120 '30003': { 333 '30003': {
121 id: '30003', 334 id: '30003',
122 isActive: true 335 isActive: true
123 } 336 },
124 };
125
126 // Test input devices. Maps device ID -> tested device properties.
127 var kTestInputDevices = {
128 '40001': { 337 '40001': {
129 id: '40001', 338 id: '40001',
130 isActive: false 339 isActive: false
131 }, 340 },
132 '40002': { 341 '40002': {
133 id: '40002', 342 id: '40002',
134 isActive: true 343 isActive: true
135 }, 344 },
136 '40003': { 345 '40003': {
137 id: '40003', 346 id: '40003',
138 isActive: false 347 isActive: false
139 } 348 }
140 }; 349 };
141 350
142 chrome.audio.setActiveDevices([ 351 chrome.audio.setActiveDevices([
143 '30003', 352 '30003',
144 '40002' 353 '40002'
145 ], chrome.test.callbackPass(function() { 354 ], chrome.test.callbackPass(function() {
146 getDevices(function(outputInfo, inputInfo) { 355 chrome.audio.getDevices(chrome.test.callbackPass(function(devices) {
147 assertDevicesMatch(kTestOutputDevices, outputInfo); 356 assertDevicesMatch(kTestDevices, devices);
148 assertDevicesMatch(kTestInputDevices, inputInfo); 357 }));
149 });
150 })); 358 }));
151 }, 359 },
152 360
153 function setPropertiesTest() { 361 function deprecatedSetPropertiesTest() {
154 getDevices(function(originalOutputInfo, originalInputInfo) { 362 chrome.audio.getDevices(chrome.test.callbackPass(function(initial) {
155 var expectedInput = deviceListToExpectedDevicesMap(originalInputInfo); 363 var expectedDevices = deviceListToExpectedDevicesMap(initial);
364
156 // Update expected input devices with values that should be changed in 365 // Update expected input devices with values that should be changed in
157 // test. 366 // test.
158 var updatedInput = expectedInput['40002']; 367 var updatedInput = expectedDevices['40002'];
159 chrome.test.assertFalse(updatedInput.isMuted); 368 chrome.test.assertFalse(updatedInput.isMuted);
160 chrome.test.assertFalse(updatedInput.gain === 55); 369 chrome.test.assertFalse(updatedInput.gain === 55);
161 updatedInput.isMuted = true; 370 updatedInput.isMuted = true;
162 updatedInput.gain = 55; 371 updatedInput.level = 55;
163 372
164 var expectedOutput = deviceListToExpectedDevicesMap(originalOutputInfo);
165 // Update expected output devices with values that should be changed in 373 // Update expected output devices with values that should be changed in
166 // test. 374 // test.
167 var updatedOutput = expectedOutput['30001']; 375 var updatedOutput = expectedDevices['30001'];
168 chrome.test.assertFalse(updatedOutput.isMuted);
169 chrome.test.assertFalse(updatedOutput.volume === 35); 376 chrome.test.assertFalse(updatedOutput.volume === 35);
170 updatedOutput.volume = 35; 377 updatedOutput.level = 35;
171 378
172 chrome.audio.setProperties('30001', { 379 chrome.audio.setProperties('30001', {
173 volume: 35 380 volume: 35
174 }, chrome.test.callbackPass(function() { 381 }, chrome.test.callbackPass(function() {
175 chrome.audio.setProperties('40002', { 382 chrome.audio.setProperties('40002', {
176 isMuted: true, 383 isMuted: true,
177 gain: 55 384 gain: 55
178 }, chrome.test.callbackPass(function() { 385 }, chrome.test.callbackPass(function() {
179 getDevices( 386 chrome.audio.getDevices(chrome.test.callbackPass(function(devices) {
180 chrome.test.callbackPass(function(outputInfo, inputInfo) { 387 assertDevicesMatch(expectedDevices, devices);
181 assertDevicesMatch(expectedInput, inputInfo); 388 }));
182 assertDevicesMatch(expectedOutput, outputInfo);
183 }));
184 })); 389 }));
185 })); 390 }));
186 }); 391 }));
187 }, 392 },
188 393
394 function setPropertiesTest() {
395 chrome.audio.getDevices(chrome.test.callbackPass(function(initial) {
396 var expectedDevices = deviceListToExpectedDevicesMap(initial);
397
398 // Update expected input devices with values that should be changed in
399 // test.
400 var updatedInput = expectedDevices['40002'];
401 chrome.test.assertFalse(updatedInput.gain === 65);
402 updatedInput.level = 65;
403
404 // Update expected output devices with values that should be changed in
405 // test.
406 var updatedOutput = expectedDevices['30001'];
407 chrome.test.assertFalse(updatedOutput.volume === 45);
408 updatedOutput.level = 45;
409
410 chrome.audio.setProperties('30001', {
411 level: 45
412 }, chrome.test.callbackPass(function() {
413 chrome.audio.setProperties('40002', {
414 level: 65
415 }, chrome.test.callbackPass(function() {
416 chrome.audio.getDevices(chrome.test.callbackPass(function(devices) {
417 assertDevicesMatch(expectedDevices, devices);
418 }));
419 }));
420 }));
421 }));
422 },
423
424
189 function inputMuteTest() { 425 function inputMuteTest() {
190 var getMute = function(callback) { 426 var getMute = function(callback) {
191 chrome.audio.getMute('INPUT', chrome.test.callbackPass(callback)); 427 chrome.audio.getMute('INPUT', chrome.test.callbackPass(callback));
192 }; 428 };
193 getMute(function(originalValue) { 429 getMute(function(originalValue) {
194 chrome.audio.setMute( 430 chrome.audio.setMute(
195 'INPUT', !originalValue, chrome.test.callbackPass(function() { 431 'INPUT', !originalValue, chrome.test.callbackPass(function() {
196 getMute(function(value) { 432 getMute(function(value) {
197 chrome.test.assertEq(!originalValue, value); 433 chrome.test.assertEq(!originalValue, value);
198 }); 434 });
199 })); 435 }));
200 }); 436 });
201 }, 437 },
202 438
203 function outputMuteTest() { 439 function outputMuteTest() {
204 var getMute = function(callback) { 440 var getMute = function(callback) {
205 chrome.audio.getMute('OUTPUT', chrome.test.callbackPass(callback)); 441 chrome.audio.getMute('OUTPUT', chrome.test.callbackPass(callback));
206 }; 442 };
207 getMute(function(originalValue) { 443 getMute(function(originalValue) {
208 chrome.audio.setMute( 444 chrome.audio.setMute(
209 'OUTPUT', !originalValue, chrome.test.callbackPass(function() { 445 'OUTPUT', !originalValue, chrome.test.callbackPass(function() {
210 getMute(function(value) { 446 getMute(function(value) {
211 chrome.test.assertEq(!originalValue, value); 447 chrome.test.assertEq(!originalValue, value);
212 }); 448 });
213 })); 449 }));
214 }); 450 });
215 }, 451 },
216 452
217 function setPropertiesInvalidValuesTest() { 453 function setPropertiesInvalidValuesTest() {
218 getDevices(function(originalOutputInfo, originalInputInfo) { 454 chrome.audio.getDevices(chrome.test.callbackPass(function(initial) {
219 var expectedInput = deviceListToExpectedDevicesMap(originalInputInfo); 455 var expectedDevices = deviceListToExpectedDevicesMap(initial);
220 var expectedOutput = deviceListToExpectedDevicesMap(originalOutputInfo);
221 var expectedError = 'Could not set volume/gain properties'; 456 var expectedError = 'Could not set volume/gain properties';
222 457
223 chrome.audio.setProperties( 458 chrome.audio.setProperties('30001', {
224 '30001', { 459 isMuted: true,
225 isMuted: true, 460 // Output device - should have volume set.
226 // Output device - should have volume set. 461 gain: 55
227 gain: 55 462 }, chrome.test.callbackFail(expectedError, function() {
228 }, 463 chrome.audio.setProperties('40002', {
229 chrome.test.callbackFail(expectedError, function() { 464 isMuted: true,
230 chrome.audio.setProperties( 465 // Input device - should have gain set.
231 '40002', { 466 volume:55
232 isMuted: true, 467 }, chrome.test.callbackFail(expectedError, function() {
233 // Input device - should have gain set. 468 // Assert that device properties haven't changed.
234 volume: 55 469 chrome.audio.getDevices(chrome.test.callbackPass(function(devices) {
235 }, 470 assertDevicesMatch(expectedDevices, devices);
236 chrome.test.callbackFail(expectedError, function() {
237 // Assert that device properties haven't changed.
238 getDevices(function(outputInfo, inputInfo) {
239 assertDevicesMatch(expectedOutput, outputInfo);
240 assertDevicesMatch(expectedInput, inputInfo);
241 });
242 }));
243 })); 471 }));
244 }); 472 }));
473 }));
474 }));
245 }, 475 },
246 476
247 function setActiveDevicesTest() { 477 function setActiveDevicesTest() {
248 chrome.audio.setActiveDevices({ 478 chrome.audio.setActiveDevices({
249 input: ['40002', '40003'], 479 input: ['40002', '40003'],
250 output: ['30001'] 480 output: ['30001']
251 }, chrome.test.callbackPass(function() { 481 }, chrome.test.callbackPass(function() {
252 getDevices(function(outputs, inputs) { 482 chrome.audio.getDevices({
253 chrome.test.assertEq( 483 isActive: true
254 ['40002', '40003'], getActiveDeviceIds(inputs).sort()); 484 }, chrome.test.callbackPass(function(activeDevices) {
255 chrome.test.assertEq(['30001'], getActiveDeviceIds(outputs)); 485 chrome.test.assertEq(['30001', '40002', '40003'],
256 }); 486 getDeviceIds(activeDevices));
487 }));
257 })); 488 }));
258 }, 489 },
259 490
260 function setActiveDevicesOutputOnlyTest() { 491 function setActiveDevicesOutputOnlyTest() {
261 getDevices(function(originalOutputs, originalInputs) { 492 chrome.audio.getDevices({
262 var originalActiveInputs = getActiveDeviceIds(originalInputs); 493 streamTypes: ['INPUT'],
263 chrome.test.assertTrue(originalActiveInputs.length > 0); 494 isActive: true
495 }, chrome.test.callbackPass(function(initial) {
496 var initialActiveInputs = getDeviceIds(initial);
497 chrome.test.assertTrue(initialActiveInputs.length > 0);
264 498
265 chrome.audio.setActiveDevices({ 499 chrome.audio.setActiveDevices({
266 output: ['30003'] 500 output: ['30003']
267 }, chrome.test.callbackPass(function() { 501 }, chrome.test.callbackPass(function() {
268 getDevices(function(outputs, inputs) { 502 chrome.audio.getDevices({
269 chrome.test.assertEq( 503 isActive: true
270 originalActiveInputs.sort(), getActiveDeviceIds(inputs).sort()); 504 }, chrome.test.callbackPass(function(devices) {
271 chrome.test.assertEq(['30003'], getActiveDeviceIds(outputs)); 505 var expected = ['30003'].concat(initialActiveInputs).sort();
272 }); 506 chrome.test.assertEq(expected, getDeviceIds(devices));
507 }));
273 })); 508 }));
274 }); 509 }));
275 }, 510 },
276 511
277 function setActiveDevicesFailInputTest() { 512 function setActiveDevicesFailInputTest() {
278 getDevices(function(originalOutputs, originalInputs) { 513 chrome.audio.getDevices({
279 var originalActiveInputs = getActiveDeviceIds(originalInputs).sort(); 514 isActive: true
280 chrome.test.assertTrue(originalActiveInputs.length > 0); 515 }, chrome.test.callbackPass(function(initial) {
281 516 var initialActiveIds = getDeviceIds(initial);
282 var originalActiveOutputs = getActiveDeviceIds(originalOutputs).sort(); 517 chrome.test.assertTrue(initialActiveIds.length > 0);
283 chrome.test.assertTrue(originalActiveOutputs.length > 0);
284 518
285 chrome.audio.setActiveDevices({ 519 chrome.audio.setActiveDevices({
286 input: ['0000000'], /* does not exist */ 520 input: ['0000000'], /* does not exist */
287 output: [] 521 output: []
288 }, chrome.test.callbackFail('Failed to set active devices.', function() { 522 }, chrome.test.callbackFail('Failed to set active devices.', function() {
289 getDevices(function(outputs, inputs) { 523 chrome.audio.getDevices({
290 chrome.test.assertEq( 524 isActive: true
291 originalActiveInputs, getActiveDeviceIds(inputs).sort()); 525 }, chrome.test.callbackPass(function(devices) {
292 chrome.test.assertEq( 526 chrome.test.assertEq(initialActiveIds, getDeviceIds(devices));
293 originalActiveOutputs, getActiveDeviceIds(outputs).sort()); 527 }));
294 });
295 })); 528 }));
296 }); 529 }));
297 }, 530 },
298 531
299 function setActiveDevicesFailOutputTest() { 532 function setActiveDevicesFailOutputTest() {
300 getDevices(function(originalOutputs, originalInputs) { 533 chrome.audio.getDevices({
301 var originalActiveInputs = getActiveDeviceIds(originalInputs).sort(); 534 isActive: true
302 chrome.test.assertTrue(originalActiveInputs.length > 0); 535 }, chrome.test.callbackPass(function(initial) {
303 536 var initialActiveIds = getDeviceIds(initial);
304 var originalActiveOutputs = getActiveDeviceIds(originalOutputs).sort(); 537 chrome.test.assertTrue(initialActiveIds.length > 0);
305 chrome.test.assertTrue(originalActiveOutputs.length > 0);
306 538
307 chrome.audio.setActiveDevices({ 539 chrome.audio.setActiveDevices({
308 input: [], 540 input: [],
309 output: ['40001'] /* id is input node ID */ 541 output: ['40001'] /* id is input node ID */
310 }, chrome.test.callbackFail('Failed to set active devices.', function() { 542 }, chrome.test.callbackFail('Failed to set active devices.', function() {
311 getDevices(function(outputs, inputs) { 543 chrome.audio.getDevices({
312 chrome.test.assertEq( 544 isActive: true
313 originalActiveInputs, getActiveDeviceIds(inputs).sort()); 545 }, chrome.test.callbackPass(function(devices) {
314 chrome.test.assertEq( 546 chrome.test.assertEq(initialActiveIds, getDeviceIds(devices));
315 originalActiveOutputs, getActiveDeviceIds(outputs).sort()); 547 }));
316 });
317 })); 548 }));
318 }); 549 }));
319 }, 550 },
320 551
321 function clearActiveDevicesTest() { 552 function clearActiveDevicesTest() {
322 getDevices(function(originalOutputs, originalInputs) { 553 chrome.audio.getDevices({
323 chrome.test.assertTrue(getActiveDeviceIds(originalInputs).length > 0); 554 isActive: true
324 chrome.test.assertTrue(getActiveDeviceIds(originalOutputs).length > 0); 555 }, chrome.test.callbackPass(function(initial) {
556 chrome.test.assertTrue(getDeviceIds(initial).length > 0);
325 557
326 chrome.audio.setActiveDevices({ 558 chrome.audio.setActiveDevices({
327 input: [], 559 input: [],
328 output: [] 560 output: []
329 }, chrome.test.callbackPass(function() { 561 }, chrome.test.callbackPass(function() {
330 getDevices(function(outputs, inputs) { 562 chrome.audio.getDevices({
331 chrome.test.assertEq([], getActiveDeviceIds(inputs)); 563 isActive: true
332 chrome.test.assertEq([], getActiveDeviceIds(outputs)); 564 }, chrome.test.callbackPass(function(devices) {
333 }); 565 chrome.test.assertEq([], devices);
566 }));
334 })); 567 }));
335 }); 568 }));
336 }, 569 },
337 ]); 570 ]);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698