summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webaudio/the-audio-api/the-mediastreamaudiosourcenode-interface/mediastreamaudiosourcenode-ctor.html
blob: a711419656979bccaca95e08f26035ebd2a0c4c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<!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>