Add layout test case for JavaScriptAudioNode.
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 14 Apr 2012 01:30:36 +0000 (01:30 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 14 Apr 2012 01:30:36 +0000 (01:30 +0000)
https://bugs.webkit.org/show_bug.cgi?id=83747

Patch by Raymond Liu <raymond.liu@intel.com> on 2012-04-13
Reviewed by Chris Rogers.

* webaudio/javascriptaudionode-expected.txt: Added.
* webaudio/javascriptaudionode.html: Added.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@114196 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/webaudio/javascriptaudionode-expected.txt [new file with mode: 0644]
LayoutTests/webaudio/javascriptaudionode.html [new file with mode: 0644]

index d1ec69e..b23ca4e 100644 (file)
@@ -1,3 +1,13 @@
+2012-04-13  Raymond Liu  <raymond.liu@intel.com>
+
+        Add layout test case for JavaScriptAudioNode.
+        https://bugs.webkit.org/show_bug.cgi?id=83747
+
+        Reviewed by Chris Rogers.
+
+        * webaudio/javascriptaudionode-expected.txt: Added.
+        * webaudio/javascriptaudionode.html: Added.
+
 2012-04-13  Raymond Toy  <rtoy@google.com>
 
         convolution-mono-mono test passes now
diff --git a/LayoutTests/webaudio/javascriptaudionode-expected.txt b/LayoutTests/webaudio/javascriptaudionode-expected.txt
new file mode 100644 (file)
index 0000000..81e1a05
--- /dev/null
@@ -0,0 +1,18 @@
+Tests JavaScriptAudioNode.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+PASS Exception was thrown for illegal numberOfOutputChannels.
+PASS Exception was thrown for illegal bufferSize.
+PASS Successfully created JavaScriptAudioNode with bufferSize = 256.
+PASS Successfully created JavaScriptAudioNode with bufferSize = 512.
+PASS Successfully created JavaScriptAudioNode with bufferSize = 1024.
+PASS Successfully created JavaScriptAudioNode with bufferSize = 2048.
+PASS Successfully created JavaScriptAudioNode with bufferSize = 4096.
+PASS Successfully created JavaScriptAudioNode with bufferSize = 8192.
+PASS Successfully created JavaScriptAudioNode with bufferSize = 16384.
+PASS onaudioprocess was called with correct data.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/webaudio/javascriptaudionode.html b/LayoutTests/webaudio/javascriptaudionode.html
new file mode 100644 (file)
index 0000000..31a6172
--- /dev/null
@@ -0,0 +1,134 @@
+<!DOCTYPE html>
+
+<html>
+<head>
+<script src="../fast/js/resources/js-test-pre.js"></script>
+<script type="text/javascript" src="resources/audio-testing.js"></script>
+</head>
+
+<body>
+
+<div id="description"></div>
+<div id="console"></div>
+
+<script>
+description("Tests JavaScriptAudioNode.");
+
+var sampleRate = 44100.0;
+var outputChannels = 6;
+
+// For the current implementation of JavaScriptAudioNode, when it works with OfflineAudioContext (which runs much faster
+// than real-time) the event.inputBuffer might be overwrite again before onaudioprocess ever get chance to be called.
+// We carefully arrange the renderLengthInFrames and bufferSize to have exactly the same value to avoid this issue.
+var renderLengthInFrames = 512;
+var bufferSize = 512;
+
+var context;
+
+function createBuffer(context, length) {
+    var audioBuffer = context.createBuffer(2, length, sampleRate);
+    var n = audioBuffer.length;
+    var dataL = audioBuffer.getChannelData(0);
+    var dataR = audioBuffer.getChannelData(1);
+
+    for (var i = 0; i < n; ++i) {
+        dataL[i] = -1;
+        dataR[i] = 1;
+    }
+
+    return audioBuffer;
+}
+
+function processAudioData(event) {
+    buffer = event.outputBuffer;
+    if (buffer.numberOfChannels != outputChannels)
+        testFailed("numberOfOutputChannels doesn't match!");
+
+    if (buffer.length != bufferSize)
+        testFailed("numberOfOutputChannels doesn't match!");
+
+    buffer = event.inputBuffer;
+    var bufferDataL = buffer.getChannelData(0);
+    var bufferDataR = buffer.getChannelData(1);
+    
+    var success = true;
+    // Go through every sample and make sure it's all -1 for the left-channel, and all +1 for the right-channel.
+    for (var i = 0; i < buffer.length; ++i) {
+        if (bufferDataL[i] != -1 || bufferDataR[i] != 1) {
+            success = false;
+            break;
+        }
+    }
+
+    if (success) {
+        testPassed("onaudioprocess was called with correct data.");
+    } else {
+        testFailed("onaudioprocess was called with wrong data.");
+    }
+}
+
+function doBufferSizeTest(size) {
+    try {
+        var jsnode = context.createJavaScriptNode(size, 1, 1);
+        testPassed("Successfully created JavaScriptAudioNode with bufferSize = " + size + ".");
+    } catch(e) {
+        testFailed("Failed to create JavaScriptAudioNode with bufferSize = " + size + ".");
+    }
+}
+
+function runTest() {
+    if (window.layoutTestController) {
+        layoutTestController.dumpAsText();
+        layoutTestController.waitUntilDone();
+    }
+
+    window.jsTestIsAsync = true;
+
+    // Create offline audio context.
+    context = new webkitAudioContext(2, renderLengthInFrames, sampleRate);
+
+    try {
+        var jsnode = context.createJavaScriptNode(512, 1, 0);
+        testFailed("Exception should be thrown for illegal numberOfOutputChannels.");
+    } catch(e) {
+        testPassed("Exception was thrown for illegal numberOfOutputChannels.");
+    }
+
+    try {
+        var jsnode = context.createJavaScriptNode(511, 1, 1);
+        testFailed("Exception should be thrown for illegal bufferSize.");
+    } catch(e) {
+        testPassed("Exception was thrown for illegal bufferSize.");
+    }
+
+    doBufferSizeTest(256);
+    doBufferSizeTest(512);
+    doBufferSizeTest(1024);
+    doBufferSizeTest(2048);
+    doBufferSizeTest(4096);
+    doBufferSizeTest(8192);
+    doBufferSizeTest(16384);
+    var sourceBuffer = createBuffer(context, renderLengthInFrames);
+
+    var bufferSource = context.createBufferSource();
+    bufferSource.buffer = sourceBuffer;
+
+    var jsnode = context.createJavaScriptNode(bufferSize, 2, outputChannels);
+
+    bufferSource.connect(jsnode);
+    jsnode.connect(context.destination);
+    jsnode.onaudioprocess = processAudioData;
+
+    bufferSource.noteOn(0);
+    context.oncomplete = finishJSTest;
+    context.startRendering();
+}
+
+runTest();
+
+</script>
+
+<script src="../fast/js/resources/js-test-post.js"></script>
+</body>
+</html>