Chromium Code Reviews| Index: LayoutTests/webaudio/offlineaudiocontext-suspend-resume-sequence.html |
| diff --git a/LayoutTests/webaudio/offlineaudiocontext-suspend-resume-sequence.html b/LayoutTests/webaudio/offlineaudiocontext-suspend-resume-sequence.html |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..323b39df3ea7073c4bdbb0709db41cbcd4c323fe |
| --- /dev/null |
| +++ b/LayoutTests/webaudio/offlineaudiocontext-suspend-resume-sequence.html |
| @@ -0,0 +1,77 @@ |
| +<!doctype html> |
| +<html> |
| + <head> |
| + <script src="../resources/js-test.js"></script> |
| + <script src="resources/compatibility.js"></script> |
| + <script src="resources/audio-testing.js"></script> |
| + </head> |
| + |
| + <body> |
| + <script> |
| + description('Test OfflineAudioContext.resume() and OfflineAudioContext.suspend() with the timed sequence.'); |
| + window.jsTestIsAsync = true; |
| + |
| + var context; |
| + |
| + // The sample rate is multiple of the rendering quantum, so suspension |
| + // times fall in to the render quantum boundary. |
| + var renderQuantum = 128; |
| + |
| + var sampleRate = renderQuantum * 100; |
| + var renderDuration = 2; |
| + |
| + // These numbers are in an arbitrary order, but not randomly generated in |
| + // runtime to avoid moving pieces. However, it is safe to arrange them |
| + // in a random order in runtime. |
| + // |
| + // Also these numbers are multiple of 0.25, so they are supposed to fall |
| + // in the render quantum boundary for easier and more intuitive |
| + // verification. |
| + var suspendTimes = [0.25, 0.75, 1.0, 0.5, 1.25, 0.0, 1.75]; |
| + |
| + // Sorted ascending suspend time is our expected result. |
| + var expectedSuspendTimes = suspendTimes.slice(0).sort(function (a, b) { |
| + return a - b; |
| + }); |
| + |
| + var actualSuspendTimes = []; |
| + |
| + context = new OfflineAudioContext(1, sampleRate * renderDuration, sampleRate); |
| + |
| + for (var i = 0; i < suspendTimes.length; i++) { |
| + |
| + // Schedule suspends in a random time order, but the actual suspend |
| + // must happen in ascending time order. |
| + scheduleSuspend(suspendTimes[i]); |
| + |
| + } |
| + |
| + function scheduleSuspend(suspendTime) { |
| + context.suspend(suspendTime).then(function () { |
| + actualSuspendTimes.push(suspendTime); |
| + context.resume(); |
| + }) |
| + } |
| + |
| + function verifyResult() { |
| + |
| + for (var i = 0; i < actualSuspendTimes.length; i++) { |
| + var scheduledOrder = suspendTimes.indexOf(actualSuspendTimes[i]) |
| + var expectedOrder = expectedSuspendTimes.indexOf(actualSuspendTimes[i]) |
| + |
| + Should('The actual resolution order of the suspend ' + scheduledOrder + |
| + ' (' + suspendTimes[scheduledOrder].toFixed(2) + ' sec.)', i) |
| + .beEqualTo(expectedOrder); |
| + } |
| + } |
| + |
| + context.startRendering().then(function () { |
| + verifyResult(); |
| + finishJSTest(); |
| + }); |
|
Raymond Toy
2015/07/15 20:59:13
Would it be nicer to write this as
startRendering
hongchan
2015/07/15 23:24:22
Done.
|
| + |
| + successfullyParsed = true; |
| + </script> |
| + |
| + </body> |
| +</html> |