Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(81)

Unified Diff: LayoutTests/webaudio/javascriptaudionode-premature-death.html

Issue 21216002: Demonstrate that Web Audio does not keep callbacks alive long enough. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: LayoutTests/webaudio/javascriptaudionode-premature-death.html
diff --git a/LayoutTests/webaudio/javascriptaudionode-premature-death.html b/LayoutTests/webaudio/javascriptaudionode-premature-death.html
new file mode 100644
index 0000000000000000000000000000000000000000..d597ebb4a1c3e35d9da44574c559b03fc7d772be
--- /dev/null
+++ b/LayoutTests/webaudio/javascriptaudionode-premature-death.html
@@ -0,0 +1,56 @@
+<!DOCTYPE html>
+<script src="../fast/js/resources/js-test-pre.js"></script>
+<body>
+<script>
+description('Tests that a JavaScriptAudioNode is not prematurely GCed');
+var jsTestIsAsync = true;
+
+if (!window.internals)
+ testFailed('This test requires window.internals.');
+
+// Create an audio context
+var context = new webkitOfflineAudioContext(
+ /* channels: */ 2, /* length, frames: */ 512, /* sample rate: */ 44100.0);
Chris Rogers 2013/07/30 18:55:54 Because of internal buffering used in the ScriptPr
dominicc (has gone to gerrit) 2013/07/31 00:45:59 I cribbed these values from LayoutTests/webaudio/r
+
+// Set up a source, reading from an empty buffer
+var source = context.createBufferSource();
+source.buffer = context.createBuffer(
+ /* source channels: */ 2, /* length, frames: */ 512,
Chris Rogers 2013/07/30 18:55:54 Similar to above comment - I'd increase 512 -> 409
+ /* sample rate: */ 44100.0);
+
+// Set up a JavaScript audio node to generate something
+var node = context.createJavaScriptNode(
Chris Rogers 2013/07/30 18:55:54 nit: the new method name is called "createScriptPr
+ /* buffer size: */ 512, /* input channels: */ 0, /* output channels: */ 2);
+
+// source -> JavaScript audio node -> destination
Chris Rogers 2013/07/30 18:55:54 "JavaScript audio node" -> "script processor node"
+source.connect(node);
+node.connect(context.destination);
+
+// Set up something which indicates whether we're called to generate anything
+
+var wasCalled = false;
+var callback = function () { wasCalled = true; };
+node.onaudioprocess = callback;
+
+// Watch the callback; if it dies, we're obviously not generating anything
+
+var observation = internals.observeGC(callback);
+node = callback = null;
+gc();
+var wasCollectedPrematurely = observation.wasCollected;
+
+// Make some noise!
+
+source.noteOn(0);
Chris Rogers 2013/07/30 18:55:54 new method name: noteOn() -> start()
+context.oncomplete = finishTest;
+context.startRendering();
+
+function finishTest() {
+ shouldBeFalse('wasCollectedPrematurely');
+ shouldBeTrue('wasCalled');
+ finishJSTest();
+}
+
+var successfullyParsed = true;
+</script>
+<script src="../fast/js/resources/js-test-post.js"></script>

Powered by Google App Engine
This is Rietveld 408576698