Refactoring: Pull all fullscreen code out of Document and into its own helper class
[WebKit-https.git] / LayoutTests / webaudio / audiobuffer-neuter.html
1 <!DOCTYPE html>
2 <head>
3     <script src="../resources/js-test.js"></script>
4     <script src="resources/audio-testing.js"></script>
5     <script src="resources/audiobuffersource-testing.js"></script>
6     <script>
7         var sampleRate = 44100.0;
8         var lengthInSeconds = 0.1;
9         var context;
10         var source;
11         var sourceBuffer;
12
13         function runTest()
14         {
15             jsTestIsAsync = true;
16
17             var numberOfFrames = sampleRate * lengthInSeconds;
18             context = new webkitOfflineAudioContext(1, numberOfFrames, sampleRate);
19             sourceBuffer = createConstantBuffer(context, numberOfFrames, 0.5);
20             var data = sourceBuffer.getChannelData(0).buffer;
21
22             var string = [
23                 "onmessage = function(e) {",
24                 "   var view = new Float32Array(e.data)",
25                 "   for (var i=0; i < view.length; i++)",
26                 "       view[i] = 100;",
27                 "    postMessage('done');",
28                 "};"
29             ].join('\n');
30             var blobURL = URL.createObjectURL(new Blob([string]));
31
32             var worker = new Worker(blobURL);
33             worker.onmessage = workerReply;
34             worker.postMessage(data, [data]);
35         }
36
37         function workerReply(event) {
38             source = context.createBufferSource();
39             source.buffer = sourceBuffer;
40             source.connect(context.destination);
41             source.start(0);
42             context.oncomplete = finishTest;
43             context.startRendering();
44         }
45
46         function finishTest(event) {
47             var renderedBuffer = event.renderedBuffer;
48             var numberOfFrames = sampleRate * lengthInSeconds;
49             var expectedBuffer = createConstantBuffer(context, numberOfFrames, 0.5);
50
51             var renderedData = renderedBuffer.getChannelData(0);
52             var expectedData = expectedBuffer.getChannelData(0);
53
54             for (var i = 0; i < numberOfFrames; ++i) {
55                 if (expectedData[i] != renderedData[i]) {
56                     testFailed('expected: ' + expectedData[i] + ' actual: ' + renderedData[i]);
57                     finishJSTest();
58                 }
59             }
60
61             testPassed('Output matches expectations.');
62             finishJSTest();
63         }
64
65     </script>
66 </head>
67 <body onload="runTest()">
68     <div>Tests that neutered AudioBuffers do not produce garbage</div>
69     <div id="console"></div>
70 </body>
71
72