Title: [92144] trunk/LayoutTests
Revision
92144
Author
crog...@google.com
Date
2011-08-01 14:41:10 -0700 (Mon, 01 Aug 2011)

Log Message

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):

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (92143 => 92144)


--- trunk/LayoutTests/ChangeLog	2011-08-01 21:22:08 UTC (rev 92143)
+++ trunk/LayoutTests/ChangeLog	2011-08-01 21:41:10 UTC (rev 92144)
@@ -1,3 +1,21 @@
+2011-08-01  Chris Rogers  <crog...@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  <scot...@chromium.org>
 
         https://bugs.webkit.org/show_bug.cgi?id=61006

Added: trunk/LayoutTests/webaudio/audionode-expected.txt (0 => 92144)


--- trunk/LayoutTests/webaudio/audionode-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/webaudio/audionode-expected.txt	2011-08-01 21:41:10 UTC (rev 92144)
@@ -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
+

Added: trunk/LayoutTests/webaudio/audionode.html (0 => 92144)


--- trunk/LayoutTests/webaudio/audionode.html	                        (rev 0)
+++ trunk/LayoutTests/webaudio/audionode.html	2011-08-01 21:41:10 UTC (rev 92144)
@@ -0,0 +1,82 @@
+<!DOCTYPE html>
+
+<html>
+<head>
+<link rel="stylesheet" href=""
+<script src=""
+<script type="text/_javascript_" src=""
+</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=""
+</body>
+</html>

Added: trunk/LayoutTests/webaudio/gain-expected.wav


(Binary files differ)
Property changes on: trunk/LayoutTests/webaudio/gain-expected.wav ___________________________________________________________________

Added: svn:mime-type

Added: trunk/LayoutTests/webaudio/gain.html (0 => 92144)


--- trunk/LayoutTests/webaudio/gain.html	                        (rev 0)
+++ trunk/LayoutTests/webaudio/gain.html	2011-08-01 21:41:10 UTC (rev 92144)
@@ -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=""
+
+</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>

Added: trunk/LayoutTests/webaudio/resources/buffer-loader.js (0 => 92144)


--- trunk/LayoutTests/webaudio/resources/buffer-loader.js	                        (rev 0)
+++ trunk/LayoutTests/webaudio/resources/buffer-loader.js	2011-08-01 21:41:10 UTC (rev 92144)
@@ -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);
+}
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to