Add audionode.html and gain.html web audio layout tests
authorcrogers@google.com <crogers@google.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 1 Aug 2011 21:41:10 +0000 (21:41 +0000)
committercrogers@google.com <crogers@google.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 1 Aug 2011 21:41:10 +0000 (21:41 +0000)
https://bugs.webkit.org/show_bug.cgi?id=65276

Reviewed by Kenneth Russell.

* webaudio/audionode-expected.txt: Added.
* webaudio/audionode.html: Added.
* webaudio/gain-expected.wav: Added.
* webaudio/gain.html: Added.
* webaudio/resources/buffer-loader.js: Added.
(BufferLoader):
(BufferLoader.prototype.loadBuffer.request.onload):
(BufferLoader.prototype.loadBuffer.request.onerror):
(BufferLoader.prototype.loadBuffer):
(BufferLoader.prototype.load):

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

LayoutTests/ChangeLog
LayoutTests/webaudio/audionode-expected.txt [new file with mode: 0644]
LayoutTests/webaudio/audionode.html [new file with mode: 0644]
LayoutTests/webaudio/gain-expected.wav [new file with mode: 0644]
LayoutTests/webaudio/gain.html [new file with mode: 0644]
LayoutTests/webaudio/resources/buffer-loader.js [new file with mode: 0644]

index d126c98..aff4ccd 100644 (file)
@@ -1,3 +1,21 @@
+2011-08-01  Chris Rogers  <crogers@google.com>
+
+        Add audionode.html and gain.html web audio layout tests
+        https://bugs.webkit.org/show_bug.cgi?id=65276
+
+        Reviewed by Kenneth Russell.
+
+        * webaudio/audionode-expected.txt: Added.
+        * webaudio/audionode.html: Added.
+        * webaudio/gain-expected.wav: Added.
+        * webaudio/gain.html: Added.
+        * webaudio/resources/buffer-loader.js: Added.
+        (BufferLoader):
+        (BufferLoader.prototype.loadBuffer.request.onload):
+        (BufferLoader.prototype.loadBuffer.request.onerror):
+        (BufferLoader.prototype.loadBuffer):
+        (BufferLoader.prototype.load):
+
 2011-08-01  Scott Graham  <scottmg@chromium.org>
 
         https://bugs.webkit.org/show_bug.cgi?id=61006
 2011-08-01  Scott Graham  <scottmg@chromium.org>
 
         https://bugs.webkit.org/show_bug.cgi?id=61006
diff --git a/LayoutTests/webaudio/audionode-expected.txt b/LayoutTests/webaudio/audionode-expected.txt
new file mode 100644 (file)
index 0000000..9716f84
--- /dev/null
@@ -0,0 +1,14 @@
+Basic tests for AudioNode API.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+PASS Source AudioNode has no inputs.
+PASS Source AudioNode has one output.
+PASS connect() exception thrown for illegal destination AudioNode.
+PASS connect() exception thrown for illegal output index.
+PASS connect() exception thrown for illegal input index.
+PASS audioNode.connect(context.destination) succeeded.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/webaudio/audionode.html b/LayoutTests/webaudio/audionode.html
new file mode 100644 (file)
index 0000000..ff3cd90
--- /dev/null
@@ -0,0 +1,82 @@
+<!DOCTYPE html>
+
+<html>
+<head>
+<link rel="stylesheet" href="../fast/js/resources/js-test-style.css"/>
+<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("Basic tests for AudioNode API.");
+
+var context = 0;
+
+function runTest() {
+    if (window.layoutTestController) {
+        layoutTestController.dumpAsText();
+        layoutTestController.waitUntilDone();
+    }
+    
+    window.jsTestIsAsync = true;
+
+    context = new webkitAudioContext();
+    var audioNode = context.createBufferSource();
+
+    // Check number of inputs and outputs.
+    if (audioNode.numberOfInputs == 0)
+        testPassed("Source AudioNode has no inputs.");
+    else
+        testFailed("Source AudioNode should not have inputs.");
+    
+    if (audioNode.numberOfOutputs == 1)
+        testPassed("Source AudioNode has one output.");
+    else
+        testFailed("Source AudioNode should have one output.");
+
+    // Try calling connect() method with illegal values.
+
+    try {
+        audioNode.connect(0, 0, 0);
+        testFailed("connect() exception should be thrown for illegal destination AudioNode.");
+    } catch(e) {
+        testPassed("connect() exception thrown for illegal destination AudioNode.");
+    }
+
+    try {
+        audioNode.connect(context.destination, 5, 0);
+        testFailed("connect() exception should be thrown for illegal output index.");
+    } catch(e) {
+        testPassed("connect() exception thrown for illegal output index.");
+    }
+
+    try {
+        audioNode.connect(context.destination, 0, 5);
+        testFailed("connect() exception should be thrown for illegal input index.");
+    } catch(e) {
+        testPassed("connect() exception thrown for illegal input index.");
+    }
+
+    // Try calling connect() with proper values.
+    try {
+        audioNode.connect(context.destination, 0, 0);
+        testPassed("audioNode.connect(context.destination) succeeded.");
+    } catch(e) {
+        testFailed("audioNode.connect(context.destination) failed.");
+    }
+
+    finishJSTest();
+}
+
+runTest();
+successfullyParsed = true;
+
+</script>
+
+<script src="../fast/js/resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/webaudio/gain-expected.wav b/LayoutTests/webaudio/gain-expected.wav
new file mode 100644 (file)
index 0000000..67cb51e
Binary files /dev/null and b/LayoutTests/webaudio/gain-expected.wav differ
diff --git a/LayoutTests/webaudio/gain.html b/LayoutTests/webaudio/gain.html
new file mode 100644 (file)
index 0000000..1cfdb01
--- /dev/null
@@ -0,0 +1,84 @@
+<!DOCTYPE html>
+
+<!--
+Tests that AudioGainNode is properly scaling the gain.
+We'll render 11 notes, starting at a gain of 1.0, decreasing in gain by 0.1.
+The 11th note will be of gain 0.0, so it should be silent (at the end in the rendered output).
+-->
+
+<html>
+<head>
+<script type="text/javascript" src="resources/audio-testing.js"></script>
+
+</head>
+<body>
+
+<script>
+
+window.onload = init;
+
+var sampleRate = 44100.0;
+var bufferDurationSeconds = 0.125;
+var numberOfNotes = 11;
+var noteSpacing = bufferDurationSeconds + 0.020; // leave 20ms of silence between each "note"
+var lengthInSeconds = numberOfNotes * noteSpacing;
+
+var context = 0;
+var sinWaveBuffer = 0;
+
+function createSinWaveBuffer(lengthInSeconds, frequency) {
+    var audioBuffer = context.createBuffer(2, lengthInSeconds * sampleRate, sampleRate);
+
+    var n = audioBuffer.length;
+    var channelL = audioBuffer.getChannelData(0);
+    var channelR = audioBuffer.getChannelData(1);
+
+    for (var i = 0; i < n; ++i) {
+        channelL[i] = Math.sin(frequency * 2.0*Math.PI * i / sampleRate);
+        channelR[i] = channelL[i];
+    }
+
+    return audioBuffer;
+}
+
+function playNote(time, gain) {
+    var source = context.createBufferSource();
+    source.buffer = sinWaveBuffer;
+
+    var gainNode = context.createGainNode();
+    gainNode.gain.value = gain;
+
+    source.connect(gainNode);
+    gainNode.connect(context.destination);
+
+    source.noteOn(time);
+}
+
+function init() {
+    if (!window.layoutTestController)
+        return;
+
+    // Create offline audio context.
+    context = new webkitAudioContext(2, sampleRate * lengthInSeconds, sampleRate);
+
+    // Create a buffer for a short "note".
+    sinWaveBuffer = createSinWaveBuffer(bufferDurationSeconds, 880.0);
+
+    // Render 11 notes, starting at a gain of 1.0, decreasing in gain by 0.1.
+    // The last note will be of gain 0.0, so shouldn't be perceptible in the rendered output.
+    for (var i = 0; i < numberOfNotes; ++i) {
+        var time = i * noteSpacing;
+        var gain = 1.0 - i / (numberOfNotes - 1);
+        playNote(time, gain);
+    }
+
+    context.oncomplete = finishAudioTest;
+    context.startRendering();
+
+    layoutTestController.waitUntilDone();
+}
+
+</script>
+
+</body>
+</html>
diff --git a/LayoutTests/webaudio/resources/buffer-loader.js b/LayoutTests/webaudio/resources/buffer-loader.js
new file mode 100644 (file)
index 0000000..57f2015
--- /dev/null
@@ -0,0 +1,44 @@
+function BufferLoader(context, urlList, callback) {
+    this.context = context;
+    this.urlList = urlList;
+    this.onload = callback;
+    this.bufferList = new Array();
+    this.loadCount = 0;
+}
+
+BufferLoader.prototype.loadBuffer = function(url, index) {
+    // Load buffer asynchronously
+    var request = new XMLHttpRequest();
+    request.open("GET", url, true);
+    request.responseType = "arraybuffer";
+
+    var loader = this;
+
+    request.onload = function() {
+        var buffer;
+        try {
+            buffer = loader.context.createBuffer(request.response, false);
+        } catch(e) {
+            alert('error decoding file data: ' + url);
+        }
+
+        try {
+            loader.bufferList[index] = buffer;
+            if (++loader.loadCount == loader.urlList.length)
+                loader.onload(loader.bufferList);
+        } catch(e) {
+            alert('BufferLoader: callback problem');
+        }
+    }
+
+    request.onerror = function() {
+        alert('BufferLoader: XHR error');        
+    }
+
+    request.send();
+}
+
+BufferLoader.prototype.load = function() {
+    for (var i = 0; i < this.urlList.length; ++i)
+        this.loadBuffer(this.urlList[i], i);
+}