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