Chromium Code Reviews| Index: third_party/WebKit/LayoutTests/webaudio/offlineaudiocontext-suspend-resume-basic.html |
| diff --git a/third_party/WebKit/LayoutTests/webaudio/offlineaudiocontext-suspend-resume-basic.html b/third_party/WebKit/LayoutTests/webaudio/offlineaudiocontext-suspend-resume-basic.html |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b1d8de6a759c0d0c25343c0e05f8ab168e08ba4a |
| --- /dev/null |
| +++ b/third_party/WebKit/LayoutTests/webaudio/offlineaudiocontext-suspend-resume-basic.html |
| @@ -0,0 +1,118 @@ |
| +<!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('Basic test for OfflineAudioContext.suspend() and OfflineAudioContext.resume().'); |
| + window.jsTestIsAsync = true; |
| + |
| + var sampleRate = 44100; |
| + var renderDuration = 1; |
| + var renderQuantum = 128; |
| + |
| + var audit = Audit.createTaskRunner(); |
| + |
| + // Task: Calling suspend with no argument or negative time should |
| + // reject the promise. |
| + audit.defineTask('suspend-invalid-argument', function (done) { |
| + var context = new OfflineAudioContext(1, sampleRate * renderDuration, sampleRate); |
| + |
| + Should('context.suspend()', context.suspend()).beRejected(); |
| + Should('context.suspend(-1.0)', context.suspend(-1.0)).beRejected(); |
| + Should('context.suspend(2.0)', context.suspend(2.0)).beRejected(); |
| + |
| + context.startRendering().then(done); |
| + }); |
| + |
| + // Task: Scheduling a suspend in the past should be rejected. |
| + audit.defineTask('suspend-in-the-past', function (done) { |
| + var context = new OfflineAudioContext(1, sampleRate * renderDuration, sampleRate); |
| + |
| + context.suspend(0.5).then(function () { |
| + |
| + Should('Scheduling a suspend in the past', |
| + context.suspend(context.currentTime - 0.1)).beRejected(); |
| + |
| + Should('Scheduling a suspend in the future', |
| + context.suspend(context.currentTime + 0.1).then(function () { |
| + context.resume(); |
| + })).beResolved(); |
| + |
| + context.resume(); |
| + }); |
| + |
| + context.startRendering().then(done); |
| + }); |
| + |
| + // Task: Calling multiple suspends at the same rendering quantum should |
| + // reject the promise. |
| + audit.defineTask('identical-suspend-time', function (done) { |
| + var context = new OfflineAudioContext(1, sampleRate * renderDuration, sampleRate); |
| + |
| + // |suspendTime1| and |suspendTime2| are identical when quantized to |
| + // the render quantum size. |
| + var suspendTime1 = renderQuantum / sampleRate; |
| + var suspendTime2 = renderQuantum * 1.5 / sampleRate; |
|
Raymond Toy
2015/10/21 18:22:45
1.5 * renderQuantum seems more typical and obvious
hongchan
2015/10/22 18:23:48
Done.
|
| + |
| + context.suspend(suspendTime1).then(function () { |
| + context.resume(); |
| + }); |
| + |
| + // Printing out the pass message to be more informative here. |
| + testPassed('Scheduling a suspend at frame ' + suspendTime1 * sampleRate + ' was successful.'); |
| + |
| + Should('Scheduling another suspend at the same rendering quantum', |
| + context.suspend(suspendTime2)).beRejected(); |
| + |
| + context.startRendering().then(done); |
| + }); |
| + |
| + // Task: Resuming the context before the actual suspension happens. |
| + audit.defineTask('resume-before-suspend', function (done) { |
| + var context = new OfflineAudioContext(1, sampleRate * renderDuration, sampleRate); |
| + |
| + // A suspend is scheduled at 0.5 second... |
| + context.suspend(renderDuration * 0.5).then(done); |
|
Raymond Toy
2015/10/21 18:22:45
Comment and code don't quite match. It's 0.5 sec
hongchan
2015/10/22 18:23:48
Done.
|
| + |
| + testPassed('Scheduling a suspend at 0.5 second.'); |
| + |
| + // We have to start rendering to get the time running. |
| + context.startRendering(); |
| + |
| + // Then call resume() immediately after the rendering starts. This |
| + // resume() will be performed before the actual suspension happens. |
| + Should('Resuming at 0 second (before the actual suspend happens)', context.resume()).beRejected(); |
|
Raymond Toy
2015/10/21 18:22:45
Is there a potential race here? You've started re
hongchan
2015/10/22 18:23:48
Ack. I will make a note about it.
|
| + }); |
| + |
| + // Task: Calling resume on non-suspended context should reject the promise. |
| + audit.defineTask('resume-without-suspend', function (done) { |
| + var context = new OfflineAudioContext(1, sampleRate * renderDuration, sampleRate); |
| + |
| + Should('Calling resume on context without any previous suspend', context.resume()) |
| + .beRejected().then(done); |
| + }); |
| + |
| + audit.defineTask('finish', function (done) { |
| + finishJSTest(); |
| + done(); |
| + }); |
| + |
| + audit.runTasks( |
| + 'suspend-invalid-argument', |
|
Raymond Toy
2015/10/21 18:22:45
I wouldn't list the individual tasks.
hongchan
2015/10/22 18:23:48
To be honest, I prefer to keep individual tasks, s
Raymond Toy
2015/10/22 18:41:44
Ok. It goes both ways: If I add a new test, it wo
hongchan
2015/10/22 20:17:04
Acknowledged.
|
| + 'suspend-in-the-past', |
| + 'identical-suspend-time', |
| + 'resume-before-suspend', |
| + 'resume-without-suspend', |
| + 'finish' |
| + ); |
| + |
| + successfullyParsed = true; |
| + </script> |
| + |
| + </body> |
| +</html> |