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