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 OfflineAudioContext.resume() and OfflineAudioContext.sus
pend() with the timed sequence.'); |
| 12 window.jsTestIsAsync = true; |
| 13 |
| 14 var context; |
| 15 |
| 16 // The sample rate is multiple of the rendering quantum, so suspension |
| 17 // times fall in to the render quantum boundary. |
| 18 var renderQuantum = 128; |
| 19 |
| 20 var sampleRate = renderQuantum * 100; |
| 21 var renderDuration = 2; |
| 22 |
| 23 // These numbers are in an arbitrary order, but not randomly generated in |
| 24 // runtime to avoid moving pieces. However, it is safe to arrange them |
| 25 // in a random order in runtime. |
| 26 // |
| 27 // Also these numbers are multiple of 0.25, so they are supposed to fall |
| 28 // in the render quantum boundary for easier and more intuitive |
| 29 // verification. |
| 30 var suspendTimes = [0.25, 0.75, 1.0, 0.5, 1.25, 0.0, 1.75]; |
| 31 |
| 32 // Sorted ascending suspend time is our expected result. |
| 33 var expectedSuspendTimes = suspendTimes.slice(0).sort(function (a, b) { |
| 34 return a - b; |
| 35 }); |
| 36 |
| 37 var actualSuspendTimes = []; |
| 38 |
| 39 context = new OfflineAudioContext(1, sampleRate * renderDuration, sampleRa
te); |
| 40 |
| 41 for (var i = 0; i < suspendTimes.length; i++) { |
| 42 |
| 43 // Schedule suspends in a random time order, but the actual suspend |
| 44 // must happen in ascending time order. |
| 45 scheduleSuspend(i, suspendTimes[i]); |
| 46 |
| 47 } |
| 48 |
| 49 function scheduleSuspend(index, suspendTime) { |
| 50 testPassed('Scheduling suspend #' + index + ' at ' + suspendTime + ' sec
ond(s).'); |
| 51 context.suspend(suspendTime).then(function () { |
| 52 actualSuspendTimes.push(suspendTime); |
| 53 context.resume(); |
| 54 }) |
| 55 } |
| 56 |
| 57 function verifyResult() { |
| 58 |
| 59 for (var i = 0; i < actualSuspendTimes.length; i++) { |
| 60 var scheduledOrder = suspendTimes.indexOf(actualSuspendTimes[i]); |
| 61 var expectedOrder = expectedSuspendTimes.indexOf(actualSuspendTimes[i]
); |
| 62 |
| 63 if (i === expectedOrder) { |
| 64 testPassed('The resolution order of suspend #' + scheduledOrder + |
| 65 ' is ' + i + ' at ' + suspendTimes[scheduledOrder].toFixed(2) + |
| 66 ' second(s).'); |
| 67 } |
| 68 } |
| 69 } |
| 70 |
| 71 context.startRendering().then(verifyResult).then(finishJSTest); |
| 72 |
| 73 successfullyParsed = true; |
| 74 </script> |
| 75 |
| 76 </body> |
| 77 </html> |
OLD | NEW |