| 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 promise resolution of OfflineAudioContext.resume() and O
fflineAudioContext.suspend().'); | |
| 13 window.jsTestIsAsync = true; | |
| 14 | |
| 15 var context; | |
| 16 | |
| 17 // The sample rate is multiple of the rendering quantum, so suspension | |
| 18 // times fall in to the render quantum boundary. | |
| 19 var renderQuantum = 128; | |
| 20 | |
| 21 var sampleRate = renderQuantum * 100; | |
| 22 var renderDuration = 2; | |
| 23 var scheduledSuspendTime = 0; | |
| 24 | |
| 25 // With the sample rate setting above, this ensures suspension time fall | |
| 26 // in to the render quantum boundary. | |
| 27 var suspendInterval = 0.25; | |
| 28 | |
| 29 context = new OfflineAudioContext(1, sampleRate * renderDuration, sampleRa
te); | |
| 30 | |
| 31 function onSuspended() { | |
| 32 if (context.state === 'suspended' && context.currentTime === scheduledSu
spendTime) { | |
| 33 | |
| 34 testPassed('suspend promise resolved: context is suspended at ' + | |
| 35 scheduledSuspendTime + ' second(s).'); | |
| 36 | |
| 37 scheduledSuspendTime = context.currentTime + suspendInterval; | |
| 38 | |
| 39 // Scheduling a suspend before the render duration should pass. | |
| 40 if (scheduledSuspendTime < renderDuration) { | |
| 41 context.suspend(scheduledSuspendTime).then(onSuspended); | |
| 42 testPassed('A new suspend has been scheduled at ' + | |
| 43 scheduledSuspendTime + ' second(s).'); | |
| 44 } | |
| 45 | |
| 46 // Scheduling a suspend exactly at the render duration should be | |
| 47 // rejected. | |
| 48 if (scheduledSuspendTime === renderDuration) { | |
| 49 Should('Scheduling at ' + renderDuration + ' seconds', | |
| 50 context.suspend(scheduledSuspendTime)).beRejected(); | |
| 51 } | |
| 52 | |
| 53 context.resume(); | |
| 54 } | |
| 55 } | |
| 56 | |
| 57 // Schedule the first suspension. | |
| 58 context.suspend(scheduledSuspendTime).then(onSuspended); | |
| 59 testPassed('A new suspend has been scheduled at ' + scheduledSuspendTime +
' second(s).'); | |
| 60 | |
| 61 context.startRendering().then(function () { | |
| 62 Should('Promise context.state', context.state).beEqualTo('closed'); | |
| 63 }).then(finishJSTest); | |
| 64 | |
| 65 successfullyParsed = true; | |
| 66 </script> | |
| 67 | |
| 68 </body> | |
| 69 </html> | |
| OLD | NEW |