mediastreamaudiosourcenode-ctor.html (2705B)
1 <!DOCTYPE html> 2 3 <html class="a"> 4 <head> 5 <title>MediaStreamAudioSourceNode</title> 6 <script src="/resources/testharness.js"></script> 7 <script src="/resources/testharnessreport.js"></script> 8 </head> 9 <body class="a"> 10 <div id="log"></div> 11 <script> 12 setup({explicit_done: true}); 13 // Wait until the DOM is ready to be able to get a reference to the canvas 14 // element. 15 window.addEventListener("load", function() { 16 const ac = new AudioContext(); 17 const emptyStream = new MediaStream(); 18 19 test(function() { 20 assert_throws_dom( 21 "InvalidStateError", 22 function() { 23 ac.createMediaStreamSource(emptyStream); 24 }, 25 `A MediaStreamAudioSourceNode can only be constructed via the factory 26 method with a MediaStream that has at least one track of kind "audio"` 27 ); 28 }, "MediaStreamAudioSourceNode created with factory method and MediaStream with no tracks"); 29 30 test(function() { 31 assert_throws_dom( 32 "InvalidStateError", 33 function() { 34 new MediaStreamAudioSourceNode(ac, { mediaStream: emptyStream }); 35 }, 36 `A MediaStreamAudioSourceNode can only be constructed via the constructor 37 with a MediaStream that has at least one track of kind "audio"` 38 ); 39 }, "MediaStreamAudioSourceNode created with constructor and MediaStream with no tracks"); 40 41 const canvas = document.querySelector("canvas"); 42 const ctx = canvas.getContext("2d"); 43 const videoOnlyStream = canvas.captureStream(); 44 45 test(function() { 46 assert_throws_dom( 47 "InvalidStateError", 48 function() { 49 ac.createMediaStreamSource(videoOnlyStream); 50 }, 51 `A MediaStreamAudioSourceNode can only be constructed via the factory with a 52 MediaStream that has at least one track of kind "audio"` 53 ); 54 }, `MediaStreamAudioSourceNode created with the factory method and MediaStream with only a video track`); 55 56 test(function() { 57 assert_throws_dom( 58 "InvalidStateError", 59 function() { 60 new MediaStreamAudioSourceNode(ac, { 61 mediaStream: videoOnlyStream, 62 }); 63 }, 64 `A MediaStreamAudioSourceNode can only be constructed via the factory with a 65 MediaStream that has at least one track of kind "audio"` 66 ); 67 }, `MediaStreamAudioSourceNode created with constructor and MediaStream with only a video track`); 68 done(); 69 }); 70 </script> 71 </body> 72 <canvas></canvas> 73 </html>