| Index: LayoutTests/webaudio/audiocontext-suspend-resume.html
|
| diff --git a/LayoutTests/webaudio/audiocontext-suspend-resume.html b/LayoutTests/webaudio/audiocontext-suspend-resume.html
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..94836b5caf93b4df56333ae21add3232ff512069
|
| --- /dev/null
|
| +++ b/LayoutTests/webaudio/audiocontext-suspend-resume.html
|
| @@ -0,0 +1,93 @@
|
| +<!doctype html>
|
| +<html>
|
| + <head>
|
| + <title>Test audiocontext suspend/resume</title>
|
| + <script src="resources/compatibility.js"></script>
|
| + <script src="resources/audio-testing.js"></script>
|
| + <script src="../resources/js-test.js"></script>
|
| + </head>
|
| +
|
| + <body>
|
| + <script>
|
| + description("Test suspend/resume for an AudioContext");
|
| +
|
| + var context;
|
| + var osc;
|
| + var p1;
|
| + var p2;
|
| +
|
| + var sampleRate = 44100;
|
| + var durationInSeconds = 1;
|
| +
|
| + function passed () {
|
| + testPassed("Context resumed correctly.");
|
| + }
|
| +
|
| + function failed () {
|
| + testFailed("Context did not resume!.");
|
| + }
|
| +
|
| + function resolvedResumeWhenReleased () {
|
| + testFailed("resume() on a released context not rejected");
|
| + finishJSTest();
|
| + }
|
| +
|
| + function rejectedResumeWhenReleased () {
|
| + testPassed("resume() on a released context rejected as expected");
|
| + finishJSTest();
|
| + }
|
| +
|
| + function checkResult (event) {
|
| + // We don't care about the actual result of the offline rendering.
|
| + shouldBeEqualToString("context.state", "released");
|
| + shouldThrow("context.suspend()");
|
| + context.resume().then(resolvedResumeWhenReleased, rejectedResumeWhenReleased);
|
| + }
|
| +
|
| + function runTest() {
|
| + window.jsTestIsAsync = true;
|
| + // Test suspend/resume. Ideally this test is best with a online AudioContext, but content
|
| + // shell doesn't really have a working online AudioContext. Hence, use an
|
| + // OfflineAudioContext. Not all possible scenarios can be easily checked with an offline
|
| + // context instead of an online context.
|
| +
|
| + // Create an audio context with an oscillator.
|
| + context = new OfflineAudioContext(1, durationInSeconds * sampleRate, sampleRate);
|
| + osc = context.createOscillator();
|
| + osc.connect(context.destination);
|
| +
|
| + // Verify the state.
|
| + shouldBeEqualToString("context.state", "paused");
|
| +
|
| + // Multiple calls to suspend() should not be a problem. But these currently do nothing with
|
| + // an OfflineAudioContext.
|
| + shouldNotThrow("context.suspend()");
|
| + shouldNotThrow("context.suspend()");
|
| +
|
| + // Multiple calls to resume should not be a problem. But these currently do nothing with an
|
| + // OfflineAudioContext.
|
| + shouldNotThrow("p1 = context.resume()");
|
| + shouldBeType(p1, Promise);
|
| + p1.then(passed, failed);
|
| + shouldNotThrow("p2 = context.resume()");
|
| + shouldBeType(p2, Promise);
|
| + if (p1 === p2)
|
| + testFailed("Promises from resume should not be equal.");
|
| + else
|
| + testPassed("Promises from resume are not equal.");
|
| + p2.then(passed, failed);
|
| +
|
| + // Resume doesn't actually resume an offline context
|
| + shouldBeEqualToString("context.state", "paused");
|
| +
|
| + // Render the offline context.
|
| + osc.start();
|
| + context.oncomplete = checkResult;
|
| + context.startRendering();
|
| + }
|
| +
|
| + runTest();
|
| + successfullyParsed = true;
|
| + </script>
|
| + </body>
|
| +</html>
|
|
|