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

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

Issue 2688773002: Restrict deprecated parts of audio API usage to whitelisted apps (Closed)
Patch Set: . Created 3 years, 9 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 | « extensions/test/data/api_test/audio/remove_nodes/background.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 59
60 /** 60 /**
61 * @param {Array.<Object>} devices List of devices returned by 61 * @param {Array.<Object>} devices List of devices returned by
62 * chrome.audio.getInfo or chrome.audio.getDevices. 62 * chrome.audio.getInfo or chrome.audio.getDevices.
63 * @return {Array.<string>} Sorted list devices IDs for devices in |devices|. 63 * @return {Array.<string>} Sorted list devices IDs for devices in |devices|.
64 */ 64 */
65 function getDeviceIds(devices) { 65 function getDeviceIds(devices) {
66 return devices.map(function(device) {return device.id;}).sort(); 66 return devices.map(function(device) {return device.id;}).sort();
67 } 67 }
68 68
69 function EventListener(targetEvent) {
70 this.targetEvent = targetEvent;
71 this.listener = this.handleEvent.bind(this);
72 this.targetEvent.addListener(this.listener);
73 this.eventCount = 0;
74 }
75
76 EventListener.prototype.handleEvent = function() {
77 ++this.eventCount;
78 }
79
80 EventListener.prototype.reset = function() {
81 this.targetEvent.removeListener(this.listener);
82 }
83
84 var deviceChangedListener = null;
85
69 chrome.test.runTests([ 86 chrome.test.runTests([
70 function getInfoTest() { 87 // Sets up a listener for audio.onDeviceChanged event -
71 // Test output devices. Maps device ID -> tested device properties. 88 // |verifyNoDeviceChangedEvents| test will later verify that no
72 var kTestOutputDevices = { 89 // onDeviceChanged events have been observed.
73 '30001': { 90 function startDeviceChangedListener() {
74 id: '30001', 91 deviceChangedListener = new EventListener(chrome.audio.onDeviceChanged);
75 name: 'Jabra Speaker: Jabra Speaker 1' 92 chrome.test.succeed();
76 },
77 '30002': {
78 id: '30002',
79 name: 'Jabra Speaker: Jabra Speaker 2'
80 },
81 '30003': {
82 id: '30003',
83 name: 'HDMI output: HDA Intel MID'
84 }
85 };
86
87 // Test input devices. Maps device ID -> tested device properties.
88 var kTestInputDevices = {
89 '40001': {
90 id: '40001',
91 name: 'Jabra Mic: Jabra Mic 1'
92 },
93 '40002': {
94 id: '40002',
95 name: 'Jabra Mic: Jabra Mic 2'
96 },
97 '40003': {
98 id: '40003',
99 name: 'Webcam Mic: Logitech Webcam'
100 }
101 };
102
103 chrome.audio.getInfo(chrome.test.callbackPass(
104 function(outputInfo, inputInfo) {
105 assertDevicesMatch(kTestOutputDevices, outputInfo);
106 assertDevicesMatch(kTestInputDevices, inputInfo);
107 }));
108 }, 93 },
109 94
110 function getDevicesTest() { 95 function getDevicesTest() {
111 // Test output devices. Maps device ID -> tested device properties. 96 // Test output devices. Maps device ID -> tested device properties.
112 var kTestDevices = { 97 var kTestDevices = {
113 '30001': { 98 '30001': {
114 id: '30001', 99 id: '30001',
115 stableDeviceId: '116606', 100 stableDeviceId: '116606',
116 displayName: 'Jabra Speaker 1', 101 displayName: 'Jabra Speaker 1',
117 deviceName: 'Jabra Speaker', 102 deviceName: 'Jabra Speaker',
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 chrome.audio.getDevices({ 297 chrome.audio.getDevices({
313 isActive: false 298 isActive: false
314 }, chrome.test.callbackPass(function(devices) { 299 }, chrome.test.callbackPass(function(devices) {
315 assertDevicesMatch( 300 assertDevicesMatch(
316 deviceListToExpectedDevicesMap(initialInactiveDevices), 301 deviceListToExpectedDevicesMap(initialInactiveDevices),
317 devices); 302 devices);
318 })); 303 }));
319 })); 304 }));
320 }, 305 },
321 306
322 function deprecatedSetActiveDevicesTest() {
323 //Test output devices. Maps device ID -> tested device properties.
324 var kTestDevices = {
325 '30001': {
326 id: '30001',
327 isActive: false
328 },
329 '30002': {
330 id: '30002',
331 isActive: false
332 },
333 '30003': {
334 id: '30003',
335 isActive: true
336 },
337 '40001': {
338 id: '40001',
339 isActive: false
340 },
341 '40002': {
342 id: '40002',
343 isActive: true
344 },
345 '40003': {
346 id: '40003',
347 isActive: false
348 }
349 };
350
351 chrome.audio.setActiveDevices([
352 '30003',
353 '40002'
354 ], chrome.test.callbackPass(function() {
355 chrome.audio.getDevices(chrome.test.callbackPass(function(devices) {
356 assertDevicesMatch(kTestDevices, devices);
357 }));
358 }));
359 },
360
361 function deprecatedSetPropertiesTest() {
362 chrome.audio.getDevices(chrome.test.callbackPass(function(initial) {
363 var expectedDevices = deviceListToExpectedDevicesMap(initial);
364
365 // Update expected input devices with values that should be changed in
366 // test.
367 var updatedInput = expectedDevices['40002'];
368 chrome.test.assertFalse(updatedInput.isMuted);
369 chrome.test.assertFalse(updatedInput.gain === 55);
370 updatedInput.isMuted = true;
371 updatedInput.level = 55;
372
373 // Update expected output devices with values that should be changed in
374 // test.
375 var updatedOutput = expectedDevices['30001'];
376 chrome.test.assertFalse(updatedOutput.volume === 35);
377 updatedOutput.level = 35;
378
379 chrome.audio.setProperties('30001', {
380 volume: 35
381 }, chrome.test.callbackPass(function() {
382 chrome.audio.setProperties('40002', {
383 isMuted: true,
384 gain: 55
385 }, chrome.test.callbackPass(function() {
386 chrome.audio.getDevices(chrome.test.callbackPass(function(devices) {
387 assertDevicesMatch(expectedDevices, devices);
388 }));
389 }));
390 }));
391 }));
392 },
393
394 function setPropertiesTest() { 307 function setPropertiesTest() {
395 chrome.audio.getDevices(chrome.test.callbackPass(function(initial) { 308 chrome.audio.getDevices(chrome.test.callbackPass(function(initial) {
396 var expectedDevices = deviceListToExpectedDevicesMap(initial); 309 var expectedDevices = deviceListToExpectedDevicesMap(initial);
397 310
398 // Update expected input devices with values that should be changed in 311 // Update expected input devices with values that should be changed in
399 // test. 312 // test.
400 var updatedInput = expectedDevices['40002']; 313 var updatedInput = expectedDevices['40002'];
401 chrome.test.assertFalse(updatedInput.gain === 65); 314 chrome.test.assertFalse(updatedInput.gain === 65);
402 updatedInput.level = 65; 315 updatedInput.level = 65;
403 316
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 getMute(function(originalValue) { 356 getMute(function(originalValue) {
444 chrome.audio.setMute( 357 chrome.audio.setMute(
445 'OUTPUT', !originalValue, chrome.test.callbackPass(function() { 358 'OUTPUT', !originalValue, chrome.test.callbackPass(function() {
446 getMute(function(value) { 359 getMute(function(value) {
447 chrome.test.assertEq(!originalValue, value); 360 chrome.test.assertEq(!originalValue, value);
448 }); 361 });
449 })); 362 }));
450 }); 363 });
451 }, 364 },
452 365
453 function setPropertiesInvalidValuesTest() {
454 chrome.audio.getDevices(chrome.test.callbackPass(function(initial) {
455 var expectedDevices = deviceListToExpectedDevicesMap(initial);
456 var expectedError = 'Could not set volume/gain properties';
457
458 chrome.audio.setProperties('30001', {
459 isMuted: true,
460 // Output device - should have volume set.
461 gain: 55
462 }, chrome.test.callbackFail(expectedError, function() {
463 chrome.audio.setProperties('40002', {
464 isMuted: true,
465 // Input device - should have gain set.
466 volume:55
467 }, chrome.test.callbackFail(expectedError, function() {
468 // Assert that device properties haven't changed.
469 chrome.audio.getDevices(chrome.test.callbackPass(function(devices) {
470 assertDevicesMatch(expectedDevices, devices);
471 }));
472 }));
473 }));
474 }));
475 },
476
477 function setActiveDevicesTest() { 366 function setActiveDevicesTest() {
478 chrome.audio.setActiveDevices({ 367 chrome.audio.setActiveDevices({
479 input: ['40002', '40003'], 368 input: ['40002', '40003'],
480 output: ['30001'] 369 output: ['30001']
481 }, chrome.test.callbackPass(function() { 370 }, chrome.test.callbackPass(function() {
482 chrome.audio.getDevices({ 371 chrome.audio.getDevices({
483 isActive: true 372 isActive: true
484 }, chrome.test.callbackPass(function(activeDevices) { 373 }, chrome.test.callbackPass(function(activeDevices) {
485 chrome.test.assertEq(['30001', '40002', '40003'], 374 chrome.test.assertEq(['30001', '40002', '40003'],
486 getDeviceIds(activeDevices)); 375 getDeviceIds(activeDevices));
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 output: [] 449 output: []
561 }, chrome.test.callbackPass(function() { 450 }, chrome.test.callbackPass(function() {
562 chrome.audio.getDevices({ 451 chrome.audio.getDevices({
563 isActive: true 452 isActive: true
564 }, chrome.test.callbackPass(function(devices) { 453 }, chrome.test.callbackPass(function(devices) {
565 chrome.test.assertEq([], devices); 454 chrome.test.assertEq([], devices);
566 })); 455 }));
567 })); 456 }));
568 })); 457 }));
569 }, 458 },
459
460 function verifyNoDeviceChangedEvents() {
461 chrome.test.assertTrue(!!deviceChangedListener);
462 chrome.test.assertEq(0, deviceChangedListener.eventCount);
463 deviceChangedListener.reset();
464 deviceChangedListener = null;
465 chrome.test.succeed();
466 },
467
468 // Tests verifying the app doesn't have access to deprecated part of the API:
469 function deprecated_GetInfoTest() {
470 chrome.audio.getInfo(chrome.test.callbackFail(
471 'audio.getInfo is deprecated, use audio.getDevices instead.'));
472 },
473
474 function deprecated_setProperties_isMuted() {
475 chrome.audio.getDevices(chrome.test.callbackPass(function(initial) {
476 var expectedDevices = deviceListToExpectedDevicesMap(initial);
477 var expectedError =
478 '|isMuted| property is deprecated, use |audio.setMute|.';
479
480 chrome.audio.setProperties('30001', {
481 isMuted: true,
482 // Output device - should have volume set.
483 level: 55
484 }, chrome.test.callbackFail(expectedError, function() {
485 // Assert that device properties haven't changed.
486 chrome.audio.getDevices(chrome.test.callbackPass(function(devices) {
487 assertDevicesMatch(expectedDevices, devices);
488 }));
489 }));
490 }));
491 },
492
493 function deprecated_setProperties_volume() {
494 chrome.audio.getDevices(chrome.test.callbackPass(function(initial) {
495 var expectedDevices = deviceListToExpectedDevicesMap(initial);
496 var expectedError = '|volume| property is deprecated, use |level|.';
497
498 chrome.audio.setProperties('30001', {
499 volume: 2,
500 // Output device - should have volume set.
501 level: 55
502 }, chrome.test.callbackFail(expectedError, function() {
503 // Assert that device properties haven't changed.
504 chrome.audio.getDevices(chrome.test.callbackPass(function(devices) {
505 assertDevicesMatch(expectedDevices, devices);
506 }));
507 }));
508 }));
509 },
510
511 function deprecated_setProperties_gain() {
512 chrome.audio.getDevices(chrome.test.callbackPass(function(initial) {
513 var expectedDevices = deviceListToExpectedDevicesMap(initial);
514 var expectedError = '|gain| property is deprecated, use |level|.';
515
516 chrome.audio.setProperties('40001', {
517 gain: 2,
518 // Output device - should have volume set.
519 level: 55
520 }, chrome.test.callbackFail(expectedError, function() {
521 // Assert that device properties haven't changed.
522 chrome.audio.getDevices(chrome.test.callbackPass(function(devices) {
523 assertDevicesMatch(expectedDevices, devices);
524 }));
525 }));
526 }));
527 },
528
529 function deprecated_SetActiveDevicesTest() {
530 var kExpectedError =
531 'String list |ids| is deprecated, use DeviceIdLists type.';
532 chrome.audio.setActiveDevices([
533 '30003',
534 '40002'
535 ], chrome.test.callbackFail(kExpectedError));
536 },
570 ]); 537 ]);
OLDNEW
« no previous file with comments | « extensions/test/data/api_test/audio/remove_nodes/background.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698