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

Side by Side Diff: third_party/WebKit/LayoutTests/webaudio/internals/scriptprocessornode-premature-death.html

Issue 2895963003: Apply layout-test-tidy to LayoutTests/webaudio (Closed)
Patch Set: Created 3 years, 7 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
OLDNEW
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <script src="../../resources/js-test.js"></script> 2 <html>
3 <body> 3 <head>
4 <script> 4 <title>
5 description('Tests that a script processor node is not prematurely GCed'); 5 scriptprocessornode-premature-death.html
6 window.jsTestIsAsync = true; 6 </title>
7 <script src="../../resources/js-test.js"></script>
8 </head>
9 <body>
10 <script id="layout-test-code">
11 description('Tests that a script processor node is not prematurely GCed');
12 window.jsTestIsAsync = true;
7 13
8 if (!window.internals) { 14 if (!window.internals) {
9 testFailed('This test requires window.internals.'); 15 testFailed('This test requires window.internals.');
10 finishJSTest(); 16 finishJSTest();
11 } 17 }
12 18
13 let wasCalled, wasCollectedPrematurely, savedNode, savedCallback; 19 let wasCalled, wasCollectedPrematurely, savedNode, savedCallback;
14 20
15 function test(saveReference, nextStep) { 21 function test(saveReference, nextStep) {
16 debug('Testing ' + (saveReference ? 'with' : 'without') + ' explicitly ' + 22 debug(
17 'keeping a reference to the script processor node alive.'); 23 'Testing ' + (saveReference ? 'with' : 'without') + ' explicitly ' +
24 'keeping a reference to the script processor node alive.');
18 25
19 // Create an audio context 26 // Create an audio context
20 let context = new OfflineAudioContext( 27 let context = new OfflineAudioContext(
21 2, // channels 28 2, // channels
22 4096, // length (frames) 29 4096, // length (frames)
23 44100.0); // sample rate 30 44100.0); // sample rate
24 31
25 // Set up a source, reading from an empty buffer 32 // Set up a source, reading from an empty buffer
26 let source = context.createBufferSource(); 33 let source = context.createBufferSource();
27 source.buffer = context.createBuffer( 34 source.buffer = context.createBuffer(
28 2, // source channels 35 2, // source channels
29 4096, // length (frames) 36 4096, // length (frames)
30 44100.0); // sample rate 37 44100.0); // sample rate
31 38
32 // Set up a script processor node to generate something 39 // Set up a script processor node to generate something
33 let node = context.createScriptProcessor( 40 let node = context.createScriptProcessor(
34 512, // buffer size 41 512, // buffer size
35 0, // input channels 42 0, // input channels
36 2); // output channels 43 2); // output channels
37 44
38 // source -> script processor node -> destination 45 // source -> script processor node -> destination
39 source.connect(node); 46 source.connect(node);
40 node.connect(context.destination); 47 node.connect(context.destination);
41 48
42 // Set up something which indicates whether we're called to 49 // Set up something which indicates whether we're called to
43 // generate anything 50 // generate anything
44 51
45 wasCalled = false; 52 wasCalled = false;
46 let callback = function () { wasCalled = true; }; 53 let callback = function() {
47 node.onaudioprocess = callback; 54 wasCalled = true;
55 };
56 node.onaudioprocess = callback;
48 57
49 if (saveReference) { 58 if (saveReference) {
50 savedNode = node; 59 savedNode = node;
51 savedCallback = callback; 60 savedCallback = callback;
52 } 61 }
53 62
54 // Watch the callback; if it dies, we're obviously not generating anything 63 // Watch the callback; if it dies, we're obviously not generating
64 // anything
55 65
56 let observation = internals.observeGC(callback); 66 let observation = internals.observeGC(callback);
57 node = callback = null; 67 node = callback = null;
58 gc(); 68 gc();
59 wasCollectedPrematurely = observation.wasCollected; 69 wasCollectedPrematurely = observation.wasCollected;
60 70
61 // Make some noise! 71 // Make some noise!
62 72
63 source.start(0); 73 source.start(0);
64 context.oncomplete = check(nextStep); 74 context.oncomplete = check(nextStep);
65 context.startRendering(); 75 context.startRendering();
66 } 76 }
67 77
68 function check(nextStep) { 78 function check(nextStep) {
69 return function () { 79 return function() {
70 shouldBeFalse('wasCollectedPrematurely'); 80 shouldBeFalse('wasCollectedPrematurely');
71 shouldBeTrue('wasCalled'); 81 shouldBeTrue('wasCalled');
72 nextStep(); 82 nextStep();
73 }; 83 };
74 } 84 }
75 85
76 function step1() { 86 function step1() {
77 test(true, step2); 87 test(true, step2);
78 } 88 }
79 89
80 function step2() { 90 function step2() {
81 test(false, finishJSTest); 91 test(false, finishJSTest);
82 } 92 }
83 93
84 step1(); 94 step1();
85 95
86 window.successfullyParsed = true; 96 window.successfullyParsed = true;
87 </script> 97 </script>
98 </body>
99 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698