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

Unified Diff: LayoutTests/webaudio/scriptprocessornode-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: Patch for landing. 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
« no previous file with comments | « no previous file | LayoutTests/webaudio/scriptprocessornode-premature-death-expected.txt » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: LayoutTests/webaudio/scriptprocessornode-premature-death.html
diff --git a/LayoutTests/webaudio/scriptprocessornode-premature-death.html b/LayoutTests/webaudio/scriptprocessornode-premature-death.html
new file mode 100644
index 0000000000000000000000000000000000000000..d73d199384b689ce0f6a56395bbf650780021b57
--- /dev/null
+++ b/LayoutTests/webaudio/scriptprocessornode-premature-death.html
@@ -0,0 +1,88 @@
+<!DOCTYPE html>
+<script src="../fast/js/resources/js-test-pre.js"></script>
+<body>
+<script>
+description('Tests that a script processor node is not prematurely GCed');
+var jsTestIsAsync = true;
+
+if (!window.internals) {
+ testFailed('This test requires window.internals.');
+ finishJSTest();
+}
+
+var wasCalled, wasCollectedPrematurely, savedNode, savedCallback;
+
+function test(saveReference, nextStep) {
+ debug('Testing ' + (saveReference ? 'with' : 'without') + ' explicitly ' +
+ 'keeping a reference to the script processor node alive.');
+
+ // Create an audio context
+ var context = new webkitOfflineAudioContext(
+ 2, // channels
+ 4096, // length (frames)
+ 44100.0); // sample rate
+
+ // Set up a source, reading from an empty buffer
+ var source = context.createBufferSource();
+ source.buffer = context.createBuffer(
+ 2, // source channels
+ 4096, // length (frames)
+ 44100.0); // sample rate
+
+ // Set up a script processor node to generate something
+ var node = context.createScriptProcessor(
+ 512, // buffer size
+ 0, // input channels
+ 2); // output channels
+
+ // source -> script processor node -> destination
+ source.connect(node);
+ node.connect(context.destination);
+
+ // Set up something which indicates whether we're called to
+ // generate anything
+
+ wasCalled = false;
+ var callback = function () { wasCalled = true; };
+ node.onaudioprocess = callback;
+
+ if (saveReference) {
+ savedNode = node;
+ savedCallback = callback;
+ }
+
+ // Watch the callback; if it dies, we're obviously not generating anything
+
+ var observation = internals.observeGC(callback);
+ node = callback = null;
+ gc();
+ wasCollectedPrematurely = observation.wasCollected;
+
+ // Make some noise!
+
+ source.start(0);
+ context.oncomplete = check(nextStep);
+ context.startRendering();
+}
+
+function check(nextStep) {
+ return function () {
+ shouldBeFalse('wasCollectedPrematurely');
+ shouldBeTrue('wasCalled');
+ nextStep();
+ };
+}
+
+function step1() {
+ test(true, step2);
+}
+
+function step2() {
+ test(false, finishJSTest);
+}
+
+step1();
+
+var successfullyParsed = true;
+</script>
+<script src="../fast/js/resources/js-test-post.js"></script>
« no previous file with comments | « no previous file | LayoutTests/webaudio/scriptprocessornode-premature-death-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698