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

Side by Side 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, 4 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | LayoutTests/webaudio/scriptprocessornode-premature-death-expected.txt » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <script src="../fast/js/resources/js-test-pre.js"></script>
3 <body>
4 <script>
5 description('Tests that a script processor node is not prematurely GCed');
6 var jsTestIsAsync = true;
7
8 if (!window.internals) {
9 testFailed('This test requires window.internals.');
10 finishJSTest();
11 }
12
13 var wasCalled, wasCollectedPrematurely, savedNode, savedCallback;
14
15 function test(saveReference, nextStep) {
16 debug('Testing ' + (saveReference ? 'with' : 'without') + ' explicitly ' +
17 'keeping a reference to the script processor node alive.');
18
19 // Create an audio context
20 var context = new webkitOfflineAudioContext(
21 2, // channels
22 4096, // length (frames)
23 44100.0); // sample rate
24
25 // Set up a source, reading from an empty buffer
26 var source = context.createBufferSource();
27 source.buffer = context.createBuffer(
28 2, // source channels
29 4096, // length (frames)
30 44100.0); // sample rate
31
32 // Set up a script processor node to generate something
33 var node = context.createScriptProcessor(
34 512, // buffer size
35 0, // input channels
36 2); // output channels
37
38 // source -> script processor node -> destination
39 source.connect(node);
40 node.connect(context.destination);
41
42 // Set up something which indicates whether we're called to
43 // generate anything
44
45 wasCalled = false;
46 var callback = function () { wasCalled = true; };
47 node.onaudioprocess = callback;
48
49 if (saveReference) {
50 savedNode = node;
51 savedCallback = callback;
52 }
53
54 // Watch the callback; if it dies, we're obviously not generating anything
55
56 var observation = internals.observeGC(callback);
57 node = callback = null;
58 gc();
59 wasCollectedPrematurely = observation.wasCollected;
60
61 // Make some noise!
62
63 source.start(0);
64 context.oncomplete = check(nextStep);
65 context.startRendering();
66 }
67
68 function check(nextStep) {
69 return function () {
70 shouldBeFalse('wasCollectedPrematurely');
71 shouldBeTrue('wasCalled');
72 nextStep();
73 };
74 }
75
76 function step1() {
77 test(true, step2);
78 }
79
80 function step2() {
81 test(false, finishJSTest);
82 }
83
84 step1();
85
86 var successfullyParsed = true;
87 </script>
88 <script src="../fast/js/resources/js-test-post.js"></script>
OLDNEW
« 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