Refactoring: Pull all fullscreen code out of Document and into its own helper class
[WebKit-https.git] / LayoutTests / webaudio / mediastreamaudiosourcenode.html
1 <!DOCTYPE html>
2 <html>
3     <head>
4         <script src="../resources/js-test-pre.js"></script>
5     </head>
6
7     <body>
8         <div id="description"></div>
9         <div id="console"></div>
10
11         <script>
12             description("Basic tests for MediaStreamAudioSourceNode API.");
13
14             let context;
15             let stream;
16             let finished = false;
17             const numberOfOutputChannels = 2;
18             const numberOfInputChannels = 2;
19             const bufferSize = 512;
20
21             function processAudioData(event) 
22             {
23                 if (finished)
24                     return;
25
26                 if (event.inputBuffer.numberOfChannels != numberOfInputChannels)
27                     testFailed(`numberOfInputChannels doesn't match: have ${event.inputBuffer.numberOfChannels}, expect ${numberOfInputChannels}!`);
28
29                 if (event.outputBuffer.numberOfChannels != numberOfOutputChannels)
30                     testFailed(`numberOfOutputChannels doesn't match: have ${event.outputBuffer.numberOfChannels}, expect ${numberOfOutputChannels}!`);
31
32                 stream.getAudioTracks()[0].stop();
33                 testPassed("onaudioprocess was called");
34                 finishJSTest();
35                 finished = true;
36             }
37
38             function gotStream(s)
39             {
40                 stream = s;
41                 testPassed('{audio:true} generated stream');
42                 shouldBe('stream.getAudioTracks().length', '1');
43                 shouldBe('stream.getVideoTracks().length', '0');
44
45                 context = new webkitAudioContext();
46
47                 // Create an AudioNode from the stream.
48                 let mediaStreamSource = context.createMediaStreamSource(stream);
49
50                 // Check number of inputs and outputs.
51                 if (mediaStreamSource.numberOfInputs == 0)
52                     testPassed("Source AudioNode has no inputs.");
53                 else
54                     testFailed("Source AudioNode should not have inputs.");
55
56                 if (mediaStreamSource.numberOfOutputs == 1)
57                     testPassed("Source AudioNode has one output.");
58                 else
59                     testFailed("Source AudioNode should have one output.");
60
61                 // Try calling connect() method with illegal values.
62                 try {
63                     mediaStreamSource.connect(0, 0, 0);
64                     testFailed("connect() exception should be thrown for illegal destination AudioNode.");
65                 } catch(err) {
66                     testPassed(`connect() exception {"${err.name}", "${err.message}"} thrown for illegal destination AudioNode`);
67                 }
68
69                 try {
70                     mediaStreamSource.connect(context.destination, 5, 0);
71                     testFailed("connect() exception should be thrown for illegal output index.");
72                 } catch(err) {
73                     testPassed(`connect() exception {"${err.name}", "${err.message}"} thrown for illegal output index`);
74                 }
75
76                 try {
77                     mediaStreamSource.connect(context.destination, 0, 5);
78                     testFailed("connect() exception should be thrown for illegal input index.");
79                 } catch(err) {
80                     testPassed(`connect() exception {"${err.name}", "${err.message}"} thrown for illegal input index`);
81                 }
82
83                 // Try calling connect() with legal values.
84                 try {
85                     mediaStreamSource.connect(context.destination, 0, 0);
86                     testPassed("mediaStreamSource.connect(context.destination) succeeded.");
87                 } catch(err) {
88                     testFailed(`mediaStreamSource.connect(context.destination) failed with "${err.name}": "${err.message}"`);
89                 }
90
91                 let scriptProcessorNode = context.createScriptProcessor(bufferSize, numberOfInputChannels, numberOfOutputChannels);
92                 scriptProcessorNode.onaudioprocess = processAudioData;
93
94                 mediaStreamSource.connect(scriptProcessorNode);
95                 scriptProcessorNode.connect(context.destination);
96             }
97
98             if (window.testRunner)
99                 testRunner.setUserMediaPermission(true);
100
101             navigator.mediaDevices.getUserMedia({audio:true})
102                 .then(stream => gotStream(stream))
103                 .catch(function(err) {
104                     testFailed(`mediaDevices.getUserMedia() failed with "${err.name}": "${err.message}"`);
105                     finishJSTest();
106                 });
107
108             window.jsTestIsAsync = true;
109             window.successfullyParsed = true;
110         </script>
111         <script src="../resources/js-test-post.js"></script>
112
113     </body>
114 </html>