| OLD | NEW |
| (Empty) |
| 1 <!doctype html> | |
| 2 <html> | |
| 3 <head> | |
| 4 <title>Test Onended Event Listener</title> | |
| 5 <script src="../resources/js-test.js"></script> | |
| 6 <script src="resources/compatibility.js"></script> | |
| 7 <script src="resources/audit-util.js"></script> | |
| 8 <script src="resources/audio-testing.js"></script> | |
| 9 </head> | |
| 10 | |
| 11 <body> | |
| 12 <script> | |
| 13 description("Test onended event listener"); | |
| 14 window.jsTestIsAsync = true; | |
| 15 | |
| 16 var sampleRate = 44100; | |
| 17 var renderLengthSeconds = 1; | |
| 18 var renderLengthFrames = renderLengthSeconds * sampleRate; | |
| 19 | |
| 20 // Length of the source buffer. Anything less than the render length is f
ine. | |
| 21 var sourceBufferLengthFrames = renderLengthFrames / 8; | |
| 22 // When to stop the oscillator. Anything less than the render time is fin
e. | |
| 23 var stopTime = renderLengthSeconds / 8; | |
| 24 | |
| 25 var audit = Audit.createTaskRunner(); | |
| 26 | |
| 27 audit.defineTask("absn-set-onended", function (done) { | |
| 28 // Test that the onended event for an AudioBufferSourceNode is fired whe
n it is set | |
| 29 // directly. | |
| 30 var context = new OfflineAudioContext(1, renderLengthFrames, sampleRate)
; | |
| 31 var buffer = context.createBuffer(1, sourceBufferLengthFrames, context.s
ampleRate); | |
| 32 var source = context.createBufferSource(); | |
| 33 source.buffer = buffer; | |
| 34 source.connect(context.destination); | |
| 35 source.onended = function (e) { | |
| 36 testPassed("AudioBufferSource.onended called when ended set directly."
); | |
| 37 }; | |
| 38 source.start(); | |
| 39 context.startRendering().then(done); | |
| 40 }); | |
| 41 | |
| 42 audit.defineTask("absn-add-listener", function (done) { | |
| 43 // Test that the onended event for an AudioBufferSourceNode is fired whe
n | |
| 44 // addEventListener is used to set the handler. | |
| 45 var context = new OfflineAudioContext(1, renderLengthFrames, sampleRate)
; | |
| 46 var buffer = context.createBuffer(1, sourceBufferLengthFrames, context.s
ampleRate); | |
| 47 var source = context.createBufferSource(); | |
| 48 source.buffer = buffer; | |
| 49 source.connect(context.destination); | |
| 50 source.addEventListener("ended", function (e) { | |
| 51 testPassed("AudioBufferSource.onended called when using addEventListen
er."); | |
| 52 }); | |
| 53 source.start(); | |
| 54 context.startRendering().then(done); | |
| 55 }); | |
| 56 | |
| 57 audit.defineTask("osc-set-onended", function (done) { | |
| 58 // Test that the onended event for an OscillatorNode is fired when it is
set | |
| 59 // directly. | |
| 60 var context = new OfflineAudioContext(1, renderLengthFrames, sampleRate)
; | |
| 61 var source = context.createOscillator(); | |
| 62 source.connect(context.destination); | |
| 63 source.onended = function (e) { | |
| 64 testPassed("Oscillator.onended called when ended set directly."); | |
| 65 }; | |
| 66 source.start(); | |
| 67 source.stop(stopTime); | |
| 68 context.startRendering().then(done); | |
| 69 }); | |
| 70 | |
| 71 audit.defineTask("osc-add-listener", function (done) { | |
| 72 // Test that the onended event for an OscillatorNode is fired when | |
| 73 // addEventListener is used to set the handler. | |
| 74 var context = new OfflineAudioContext(1, renderLengthFrames, sampleRate)
; | |
| 75 var source = context.createOscillator(); | |
| 76 source.connect(context.destination); | |
| 77 source.addEventListener("ended", function (e) { | |
| 78 testPassed("Oscillator.onended called when using addEventListener."); | |
| 79 }); | |
| 80 source.start(); | |
| 81 source.stop(stopTime); | |
| 82 context.startRendering().then(done); | |
| 83 }); | |
| 84 | |
| 85 audit.defineTask("finish", function (done) { | |
| 86 finishJSTest(); | |
| 87 done(); | |
| 88 }); | |
| 89 | |
| 90 audit.runTasks(); | |
| 91 succesfullyParsed = true; | |
| 92 </script> | |
| 93 </body> | |
| 94 </html> | |
| OLD | NEW |