OLD | NEW |
| (Empty) |
1 <!doctype html> | |
2 <html> | |
3 <head> | |
4 <title>Test premature GC upon OscillatorNode and AudioBufferSourceNode</titl
e> | |
5 <script src="../resources/js-test.js"></script> | |
6 <script src="resources/audit-util.js"></script> | |
7 <script src="resources/audio-testing.js"></script> | |
8 </head> | |
9 | |
10 <body> | |
11 <script type="text/javascript"> | |
12 description("Test premature GC upon OscillatorNode and AudioBufferSourceNo
de"); | |
13 window.jsTestIsAsync = true; | |
14 | |
15 var sampleRate = 44100; | |
16 var renderDuration = 1; | |
17 | |
18 var audit = Audit.createTaskRunner(); | |
19 | |
20 | |
21 // Create a graph for testing in an isolated scope. Returns |context|. | |
22 // Create two nodes and schedule only one of them. Then check if |onended| | |
23 // from the scheduled node is fired correctly. | |
24 function createGraphInIsolatedScope(sourceNodeType, done) { | |
25 | |
26 'use strict'; | |
27 | |
28 var context = new OfflineAudioContext(1, renderDuration * sampleRate, sa
mpleRate); | |
29 | |
30 { | |
31 let node = context['create' + sourceNodeType](); | |
32 node.connect(context.destination); | |
33 | |
34 if (sourceNodeType === 'BufferSource') { | |
35 let emptyBuffer = context.createBuffer(1, sampleRate, sampleRate); | |
36 node.buffer = emptyBuffer; | |
37 } | |
38 | |
39 // If the node is GCed, |onended| won't be fired. Then this test | |
40 // will be timed out because done() will not get called. | |
41 node.onended = function () { | |
42 testPassed(sourceNodeType + 'Node 1 survived GC and onended event fi
red.'); | |
43 done(); | |
44 }; | |
45 | |
46 node.start(); | |
47 node.stop(0.5 * renderDuration); | |
48 } | |
49 | |
50 // Suspend and GC before the render finishes. The time position is | |
51 // arbitrary. GC should collect |osc2| because it is not scheduled. | |
52 context.suspend(0.1 * renderDuration).then(function () { | |
53 gc(); | |
54 context.resume(); | |
55 }); | |
56 | |
57 context.startRendering(); | |
58 } | |
59 | |
60 audit.defineTask('oscillator-onended', function (done) { | |
61 createGraphInIsolatedScope('Oscillator', done); | |
62 }); | |
63 | |
64 audit.defineTask('buffersource-onended', function (done) { | |
65 createGraphInIsolatedScope('BufferSource', done); | |
66 }); | |
67 | |
68 audit.defineTask('finish', function (done) { | |
69 finishJSTest(); | |
70 done(); | |
71 }); | |
72 | |
73 | |
74 audit.runTasks( | |
75 'oscillator-onended', | |
76 'buffersource-onended', | |
77 'finish' | |
78 ); | |
79 | |
80 succesfullyParsed = true; | |
81 </script> | |
82 </body> | |
83 </html> | |
OLD | NEW |