| 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/testharness.js"></script> | |
| 6 <script src="../../resources/testharnessreport.js"></script> | |
| 7 <script src="../resources/audit-util.js"></script> | |
| 8 <script src="../resources/audit.js"></script> | |
| 9 </head> | |
| 10 | |
| 11 <body> | |
| 12 <script type="text/javascript"> | |
| 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, task, should) { | |
| 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 should(true, sourceNodeType + | |
| 42 'Node 1 survived GC and onended event fired') | |
| 43 .beEqualTo(true); | |
| 44 task.done(); | |
| 45 }; | |
| 46 | |
| 47 node.start(); | |
| 48 node.stop(0.5 * renderDuration); | |
| 49 } | |
| 50 | |
| 51 // Suspend and GC before the render finishes. The time position is | |
| 52 // arbitrary. GC should collect |osc2| because it is not scheduled. | |
| 53 context.suspend(0.1 * renderDuration).then(function () { | |
| 54 gc(); | |
| 55 context.resume(); | |
| 56 }); | |
| 57 | |
| 58 context.startRendering(); | |
| 59 } | |
| 60 | |
| 61 audit.define('oscillator-onended', (task, should) => { | |
| 62 createGraphInIsolatedScope('Oscillator', task, should); | |
| 63 }); | |
| 64 | |
| 65 audit.define('buffersource-onended', (task, should) => { | |
| 66 createGraphInIsolatedScope('BufferSource', task, should); | |
| 67 }); | |
| 68 | |
| 69 audit.run(); | |
| 70 </script> | |
| 71 </body> | |
| 72 </html> | |
| OLD | NEW |