Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
- This WPT test may be referenced by the following Test IDs:
- /webaudio/the-audio-api/the-mediastreamaudiosourcenode-interface/mediastreamaudiosourcenode-ctor.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<html class="a">
<head>
<title>MediaStreamAudioSourceNode</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body class="a">
<div id="log"></div>
<script>
setup({explicit_done: true});
// Wait until the DOM is ready to be able to get a reference to the canvas
// element.
window.addEventListener("load", function() {
const ac = new AudioContext();
const emptyStream = new MediaStream();
test(function() {
assert_throws_dom(
"InvalidStateError",
function() {
ac.createMediaStreamSource(emptyStream);
},
`A MediaStreamAudioSourceNode can only be constructed via the factory
method with a MediaStream that has at least one track of kind "audio"`
);
}, "MediaStreamAudioSourceNode created with factory method and MediaStream with no tracks");
test(function() {
assert_throws_dom(
"InvalidStateError",
function() {
new MediaStreamAudioSourceNode(ac, { mediaStream: emptyStream });
},
`A MediaStreamAudioSourceNode can only be constructed via the constructor
with a MediaStream that has at least one track of kind "audio"`
);
}, "MediaStreamAudioSourceNode created with constructor and MediaStream with no tracks");
const canvas = document.querySelector("canvas");
const ctx = canvas.getContext("2d");
const videoOnlyStream = canvas.captureStream();
test(function() {
assert_throws_dom(
"InvalidStateError",
function() {
ac.createMediaStreamSource(videoOnlyStream);
},
`A MediaStreamAudioSourceNode can only be constructed via the factory with a
MediaStream that has at least one track of kind "audio"`
);
}, `MediaStreamAudioSourceNode created with the factory method and MediaStream with only a video track`);
test(function() {
assert_throws_dom(
"InvalidStateError",
function() {
new MediaStreamAudioSourceNode(ac, {
mediaStream: videoOnlyStream,
});
},
`A MediaStreamAudioSourceNode can only be constructed via the factory with a
MediaStream that has at least one track of kind "audio"`
);
}, `MediaStreamAudioSourceNode created with constructor and MediaStream with only a video track`);
done();
});
</script>
</body>
<canvas></canvas>
</html>