| 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/audit-util.js"></script> | |
| 7 <script src="resources/audio-testing.js"></script> | |
| 8 </head> | |
| 9 | |
| 10 <body> | |
| 11 <script> | |
| 12 description('Test event handler callback from OfflineAudioContext.resume()
and OfflineAudioContext.suspend().'); | |
| 13 window.jsTestIsAsync = true; | |
| 14 | |
| 15 var context; | |
| 16 var renderQuantum = 128; | |
| 17 | |
| 18 // The sample rate is multiple of the rendering quantum, so suspension | |
| 19 // times in the test will fall on the render quantum boundary. Although | |
| 20 // this is not necessary, it is easier to understand the test. | |
| 21 var sampleRate = renderQuantum * 100; | |
| 22 | |
| 23 var renderDuration = 2; | |
| 24 var scheduledSuspendTime = 0; | |
| 25 | |
| 26 // With the sample rate setting above, this ensures suspension time fall | |
| 27 // in to the render quantum boundary. | |
| 28 var suspendInterval = 0.25; | |
| 29 | |
| 30 function runTest() { | |
| 31 context = new OfflineAudioContext(1, sampleRate * renderDuration, sample
Rate); | |
| 32 | |
| 33 context.onstatechange = function () { | |
| 34 if (context.state === 'suspended' && context.currentTime === scheduled
SuspendTime) { | |
| 35 | |
| 36 testPassed('onstatechange event handler: context is suspended at ' + | |
| 37 scheduledSuspendTime + ' second(s).'); | |
| 38 | |
| 39 scheduledSuspendTime = context.currentTime + suspendInterval; | |
| 40 | |
| 41 // Scheduling a suspend before the render duration should pass. | |
| 42 if (scheduledSuspendTime < renderDuration) { | |
| 43 context.suspend(scheduledSuspendTime); | |
| 44 testPassed('A new suspend has been scheduled at ' + | |
| 45 scheduledSuspendTime + ' second(s).'); | |
| 46 } | |
| 47 | |
| 48 // Scheduling a suspend exactly at the render duration should be | |
| 49 // rejected. | |
| 50 if (scheduledSuspendTime === renderDuration) { | |
| 51 Should('Scheduling at ' + renderDuration + ' seconds', | |
| 52 context.suspend(scheduledSuspendTime)).beRejected(); | |
| 53 } | |
| 54 | |
| 55 context.resume(); | |
| 56 } | |
| 57 }; | |
| 58 | |
| 59 // This test is for verifying all the event handlers on OAC and that is | |
| 60 // why 'oncomplete' is used here. | |
| 61 context.oncomplete = function () { | |
| 62 Should('oncomplete event handler: context.state', context.state).beEqu
alTo('closed'); | |
| 63 finishJSTest(); | |
| 64 }; | |
| 65 | |
| 66 // Schedule the first suspension. | |
| 67 context.suspend(scheduledSuspendTime); | |
| 68 testPassed('A new suspend has been scheduled at ' + scheduledSuspendTime
+ ' second(s).'); | |
| 69 | |
| 70 context.startRendering(); | |
| 71 } | |
| 72 | |
| 73 runTest(); | |
| 74 successfullyParsed = true; | |
| 75 </script> | |
| 76 | |
| 77 </body> | |
| 78 </html> | |
| OLD | NEW |