OLD | NEW |
(Empty) | |
| 1 <!doctype html> |
| 2 <html> |
| 3 <head> |
| 4 <script src="../resources/js-test.js"></script> |
| 5 <script src="resources/compatibility.js"></script> |
| 6 <script src="resources/audio-testing.js"></script> |
| 7 </head> |
| 8 |
| 9 <body> |
| 10 <script> |
| 11 description('Test event handler callback from OfflineAudioContext resume/s
uspend.'); |
| 12 window.jsTestIsAsync = true; |
| 13 |
| 14 var context; |
| 15 var sampleRate = 44100; |
| 16 var renderDuration = 2; |
| 17 var renderQuantum = 128; |
| 18 var scheduledSuspendTime = 0.1; |
| 19 |
| 20 // Get the time quantized by render quantum size. |
| 21 function quantizeTimeByRenderQuantum(time) { |
| 22 var samples = time * sampleRate; |
| 23 return (samples - (samples % renderQuantum)) / sampleRate; |
| 24 } |
| 25 |
| 26 // FIXME: this is a request from rtoy, but not sure how it should be |
| 27 // printed out on the result. |
| 28 function getRenderQuantumIndexFromTime(time) { |
| 29 return Math.floor(time * sampleRate / renderQuantum); |
| 30 } |
| 31 |
| 32 function runTest() { |
| 33 context = new OfflineAudioContext(1, sampleRate * renderDuration, sample
Rate); |
| 34 |
| 35 context.onstatechange = function () { |
| 36 if (context.state === 'suspended') { |
| 37 Should('context.currentTime', context.currentTime) |
| 38 .beEqualTo(quantizeTimeByRenderQuantum(scheduledSuspendTime)); |
| 39 |
| 40 // When |context.currentTime + 0.1 > renderDuration|, the promise |
| 41 // should be rejected and throw an exception. |
| 42 scheduledSuspendTime = context.currentTime + 0.1; |
| 43 if (context.currentTime + 0.1 > renderDuration) { |
| 44 Should('context.suspend(scheduledSuspendTime)', |
| 45 context.suspend(scheduledSuspendTime)).beRejected(); |
| 46 } else { |
| 47 context.suspend(scheduledSuspendTime); |
| 48 } |
| 49 context.resume(); |
| 50 } |
| 51 }; |
| 52 |
| 53 // This test is for verifying all the event handlers on OAC and that is |
| 54 // why 'oncomplete' is used here. |
| 55 context.oncomplete = function () { |
| 56 Should('context.state', context.state).beEqualTo('closed'); |
| 57 finishJSTest(); |
| 58 }; |
| 59 |
| 60 // Initiate the suspension loop. |
| 61 context.suspend(scheduledSuspendTime); |
| 62 context.startRendering(); |
| 63 } |
| 64 |
| 65 runTest(); |
| 66 successfullyParsed = true; |
| 67 </script> |
| 68 |
| 69 </body> |
| 70 </html> |
OLD | NEW |