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