Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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() { | |
|
Devlin
2017/02/22 14:13:14
These were all just cut-and-pasted, right?
tbarzic
2017/02/22 19:35:19
yes, to audio/deprecated_api/test.js
| |
| 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 Loading... | |
| 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 Loading... | |
| 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("Not allowed.")); | |
| 471 }, | |
| 472 | |
| 473 function deprecated_setProperties_isMuted() { | |
| 474 chrome.audio.getDevices(chrome.test.callbackPass(function(initial) { | |
| 475 var expectedDevices = deviceListToExpectedDevicesMap(initial); | |
| 476 var expectedError = | |
| 477 '|isMuted| property not allowed - use |audio.setMute|.'; | |
| 478 | |
| 479 chrome.audio.setProperties('30001', { | |
| 480 isMuted: true, | |
| 481 // Output device - should have volume set. | |
| 482 level: 55 | |
| 483 }, chrome.test.callbackFail(expectedError, function() { | |
| 484 // Assert that device properties haven't changed. | |
| 485 chrome.audio.getDevices(chrome.test.callbackPass(function(devices) { | |
| 486 assertDevicesMatch(expectedDevices, devices); | |
| 487 })); | |
| 488 })); | |
| 489 })); | |
| 490 }, | |
| 491 | |
| 492 function deprecated_setProperties_volume() { | |
| 493 chrome.audio.getDevices(chrome.test.callbackPass(function(initial) { | |
| 494 var expectedDevices = deviceListToExpectedDevicesMap(initial); | |
| 495 var expectedError = '|volume| property not allowed - use |level|.'; | |
| 496 | |
| 497 chrome.audio.setProperties('30001', { | |
| 498 volume: 2, | |
| 499 // Output device - should have volume set. | |
| 500 level: 55 | |
| 501 }, chrome.test.callbackFail(expectedError, function() { | |
| 502 // Assert that device properties haven't changed. | |
| 503 chrome.audio.getDevices(chrome.test.callbackPass(function(devices) { | |
| 504 assertDevicesMatch(expectedDevices, devices); | |
| 505 })); | |
| 506 })); | |
| 507 })); | |
| 508 }, | |
| 509 | |
| 510 function deprecated_setProperties_gain() { | |
| 511 chrome.audio.getDevices(chrome.test.callbackPass(function(initial) { | |
| 512 var expectedDevices = deviceListToExpectedDevicesMap(initial); | |
| 513 var expectedError = '|gain| property not allowed - use |level|.'; | |
| 514 | |
| 515 chrome.audio.setProperties('40001', { | |
| 516 gain: 2, | |
| 517 // Output device - should have volume set. | |
| 518 level: 55 | |
| 519 }, chrome.test.callbackFail(expectedError, function() { | |
| 520 // Assert that device properties haven't changed. | |
| 521 chrome.audio.getDevices(chrome.test.callbackPass(function(devices) { | |
| 522 assertDevicesMatch(expectedDevices, devices); | |
| 523 })); | |
| 524 })); | |
| 525 })); | |
| 526 }, | |
| 527 | |
| 528 function deprecated_SetActiveDevicesTest() { | |
| 529 var kExpectedError = '|ids| should have DeviceIdLists type.'; | |
| 530 chrome.audio.setActiveDevices([ | |
| 531 '30003', | |
| 532 '40002' | |
| 533 ], chrome.test.callbackFail(kExpectedError)); | |
| 534 }, | |
| 570 ]); | 535 ]); |
| OLD | NEW |