Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / webaudio / scriptprocessornode.html
blob4883400c986f766a763d60405166abca9403cfec
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="../resources/js-test.js"></script>
5 <script src="resources/compatibility.js"></script>
6 <script type="text/javascript" src="resources/audio-testing.js"></script>
7 </head>
9 <body>
11 <div id="description"></div>
12 <div id="console"></div>
14 <script>
15 description("Tests ScriptProcessorNode.");
17 var sampleRate = 44100.0;
18 var outputChannels = 6;
19 var playbackTime = 0.0;
21 // For the current implementation of ScriptProcessorNode, when it works with OfflineAudioContext (which runs much faster
22 // than real-time) the event.inputBuffer might be overwrite again before onaudioprocess ever get chance to be called.
23 // We carefully arrange the renderLengthInFrames and bufferSize to have exactly the same value to avoid this issue.
24 var renderLengthInFrames = 512;
25 var bufferSize = 512;
27 var context;
29 function createBuffer(context, length) {
30 var audioBuffer = context.createBuffer(2, length, sampleRate);
31 var n = audioBuffer.length;
32 var dataL = audioBuffer.getChannelData(0);
33 var dataR = audioBuffer.getChannelData(1);
35 for (var i = 0; i < n; ++i) {
36 dataL[i] = -1;
37 dataR[i] = 1;
40 return audioBuffer;
43 function processAudioData(event) {
44 playbackTime = event.playbackTime;
45 var expectedTime = context.currentTime + (bufferSize / context.sampleRate);
46 var allowedTimeGap = 0.0000001;
48 // There may be a little time gap which is from different thread operation
49 // between currentTime when main thread fires onaudioprocess() and currentTime when read in JS
50 // since currentTime is continuously increasing on audio thread.
52 shouldBeCloseTo("playbackTime", expectedTime, allowedTimeGap, true);
54 buffer = event.outputBuffer;
55 if (buffer.numberOfChannels != outputChannels)
56 testFailed("numberOfOutputChannels doesn't match!");
58 if (buffer.length != bufferSize)
59 testFailed("numberOfOutputChannels doesn't match!");
61 buffer = event.inputBuffer;
62 var bufferDataL = buffer.getChannelData(0);
63 var bufferDataR = buffer.getChannelData(1);
65 var success = true;
66 // Go through every sample and make sure it's all -1 for the left-channel, and all +1 for the right-channel.
67 for (var i = 0; i < buffer.length; ++i) {
68 if (bufferDataL[i] != -1 || bufferDataR[i] != 1) {
69 success = false;
70 break;
74 if (success) {
75 testPassed("onaudioprocess was called with correct data.");
76 } else {
77 testFailed("onaudioprocess was called with wrong data.");
81 function doBufferSizeTest(size) {
82 try {
83 var jsnode = context.createScriptProcessor(size, 1, 1);
84 testPassed("Successfully created ScriptProcessorNode with bufferSize = " + size + ".");
85 } catch(e) {
86 testFailed("Failed to create ScriptProcessorNode with bufferSize = " + size + ".");
90 function runTest() {
91 if (window.testRunner) {
92 testRunner.dumpAsText();
93 testRunner.waitUntilDone();
96 window.jsTestIsAsync = true;
98 // Create offline audio context.
99 context = new OfflineAudioContext(2, renderLengthInFrames, sampleRate);
101 try {
102 var jsnode = context.createScriptProcessor(512, 0, 0);
103 testFailed("Exception should be thrown when both numberOfInputChannels and numberOfOutputChannels are zero.");
104 } catch(e) {
105 testPassed("Exception was thrown when both numberOfInputChannels and numberOfOutputChannels are zero.");
108 try {
109 var jsnode = context.createScriptProcessor(512, 1, 0);
110 testPassed("Successfully created ScriptProcessorNode with numberOfInputChannels = 1 and numberOfOutputChannels = 0.");
111 } catch(e) {
112 testFailed("Exception should not be thrown when numberOfInputChannels = 1 and numberOfOutputChannels = 0.");
115 try {
116 var jsnode = context.createScriptProcessor(512, 2, 0);
117 testPassed("Successfully created ScriptProcessorNode with numberOfInputChannels = 2 and numberOfOutputChannels = 0.");
118 } catch(e) {
119 testFailed("Exception should not be thrown when numberOfInputChannels = 2 and numberOfOutputChannels = 0.");
122 try {
123 var jsnode = context.createScriptProcessor(512, 0, 1);
124 testPassed("Successfully created ScriptProcessorNode with numberOfInputChannels = 0 and numberOfOutputChannels = 1.");
125 } catch(e) {
126 testFailed("Exception should not be thrown when numberOfInputChannels = 0 and numberOfOutputChannels = 1.");
129 try {
130 var jsnode = context.createScriptProcessor(512, 0, 2);
131 testPassed("Successfully created ScriptProcessorNode with numberOfInputChannels = 0 and numberOfOutputChannels = 2.");
132 } catch(e) {
133 testFailed("Exception should not be thrown when numberOfInputChannels = 0 and numberOfOutputChannels = 2.");
136 try {
137 var jsnode = context.createScriptProcessor(511, 1, 1);
138 testFailed("Exception should be thrown for illegal bufferSize.");
139 } catch(e) {
140 testPassed("Exception was thrown for illegal bufferSize.");
143 doBufferSizeTest(256);
144 doBufferSizeTest(512);
145 doBufferSizeTest(1024);
146 doBufferSizeTest(2048);
147 doBufferSizeTest(4096);
148 doBufferSizeTest(8192);
149 doBufferSizeTest(16384);
151 var sourceBuffer = createBuffer(context, renderLengthInFrames);
153 var bufferSource = context.createBufferSource();
154 bufferSource.buffer = sourceBuffer;
156 var jsnode = context.createScriptProcessor(bufferSize, 2, outputChannels);
158 bufferSource.connect(jsnode);
159 jsnode.connect(context.destination);
160 jsnode.onaudioprocess = processAudioData;
162 bufferSource.start(0);
163 context.oncomplete = finishJSTest;
164 context.startRendering();
167 runTest();
169 </script>
171 </body>
172 </html>