OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <html> |
| 3 <head> |
| 4 <title>Audio Output Devices</title> |
| 5 <script src="../../resources/testharness.js"></script> |
| 6 <script src="../../resources/testharnessreport.js"></script> |
| 7 </head> |
| 8 <body> |
| 9 <audio id="testAudio" src="../resources/media-source/webm/test-a-128k-44100H
z-1ch.webm"></audio> |
| 10 <script> |
| 11 var audio = document.getElementById('testAudio'); |
| 12 |
| 13 // Tests that the API is available. |
| 14 test(function() { |
| 15 assert_not_equals(audio, null); |
| 16 assert_idl_attribute(audio, 'setSinkId'); |
| 17 assert_equals(typeof audio.setSinkId, 'function'); |
| 18 assert_idl_attribute(audio, 'sinkId'); |
| 19 assert_equals(audio.sinkId, ''); |
| 20 }, 'Basic API test'); |
| 21 |
| 22 // Tests that setting the sink to the default device succeeds |
| 23 promise_test(function() { |
| 24 return audio.setSinkId('') |
| 25 .then(function() { |
| 26 // do nothing |
| 27 }).catch(function() { |
| 28 assert_unreached('setSinkId() should have succeeded'); |
| 29 }); |
| 30 }, 'setSinkId("")'); |
| 31 |
| 32 // Tests that setting the sink to a valid device without permission fails |
| 33 // Note: 'default' is the hashed name Chrome always provides for the default |
| 34 // device. It is treated like any other hashed device ID, so it is not |
| 35 // automatically authorized like ''. |
| 36 promise_test(function() { |
| 37 return audio.setSinkId('default') |
| 38 .then(function() { |
| 39 assert_unreached('setSinkId() should have failed'); |
| 40 }).catch(function(error) { |
| 41 assert_equals(error.name, 'SecurityError'); |
| 42 return Promise.resolve(); |
| 43 }); |
| 44 }, 'setSinkId("default") without permission' ); |
| 45 |
| 46 // Test that setting the sink to an invalid device fails |
| 47 promise_test(function() { |
| 48 return audio.setSinkId('invalid') |
| 49 .then(function() { |
| 50 assert_unreached('setSinkId() should have failed'); |
| 51 }).catch(function(error) { |
| 52 assert_equals(error.name, 'NotFoundError'); |
| 53 return Promise.resolve(); |
| 54 }); |
| 55 }, 'setSinkId("invalid")'); |
| 56 |
| 57 // Test that setting the sink on an element without src succeeds |
| 58 promise_test(function() { |
| 59 audio.src="" |
| 60 return audio.setSinkId('') |
| 61 .then(function() { |
| 62 // do nothing |
| 63 }).catch(function() { |
| 64 assert_unreached('setSinkId() should have succeeded'); |
| 65 }); |
| 66 }, 'empty src setSinkId("")'); |
| 67 |
| 68 // Test that setting the src of an element, and then changing the sink |
| 69 // both succeed. |
| 70 promise_test(function() { |
| 71 audio.src="../resources/media-source/webm/test-a-192k-44100Hz-1ch.webm" |
| 72 return audio.setSinkId('') |
| 73 .then(function() { |
| 74 // do nothing |
| 75 }).catch(function() { |
| 76 assert_unreached('setSinkId() should have succeeded'); |
| 77 }); |
| 78 }, 'new src setSinkId("")'); |
| 79 |
| 80 // Tests that setting the sink to the default device a second time succeeds |
| 81 promise_test(function() { |
| 82 return audio.setSinkId('') |
| 83 .then(function() { |
| 84 // do nothing |
| 85 }).catch(function() { |
| 86 assert_unreached('setSinkId() should have succeeded'); |
| 87 }); |
| 88 }, 'setSinkId("") 2'); |
| 89 </script> |
| 90 </body> |
| 91 </html> |
| 92 |
OLD | NEW |