Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(105)

Unified Diff: LayoutTests/webaudio/audiocontext-suspend-resume.html

Issue 945023002: Refactoring layout tests for AudioContext.suspend() and resume() (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fixed to check 'event' object, not global context. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: LayoutTests/webaudio/audiocontext-suspend-resume.html
diff --git a/LayoutTests/webaudio/audiocontext-suspend-resume.html b/LayoutTests/webaudio/audiocontext-suspend-resume.html
index 7a93806bf9aa825f723793601b3d6e0fa21a1ee2..c7e4878d0a8f425c8b83b805b2589395b9dd8cb4 100644
--- a/LayoutTests/webaudio/audiocontext-suspend-resume.html
+++ b/LayoutTests/webaudio/audiocontext-suspend-resume.html
@@ -1,110 +1,122 @@
<!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 (offline) AudioContext");
-
- var context;
- var osc;
- var p1;
- var p2;
-
- var sampleRate = 44100;
- var durationInSeconds = 1;
-
- // Convenience function that returns a function that calls the |passFailMethod| with the given
- // |message|. The |passFailMethod| should be either |testPassed| or |testFailed|.
- function handlePromise(passFailMethod, message) {
- return function () {
- passFailMethod(message);
- };
- }
-
- function checkResult (event) {
- // We don't care about the actual result of the offline rendering.
+<head>
+ <title>Test AudioContext.suspend() and AudioContext.resume()</title>
+ <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 suspend/resume for an (offline) AudioContext");
+ window.jsTestIsAsync = true;
+
+ var context;
+ var osc;
+ var p1;
+ var p2;
+
+ var sampleRate = 44100;
+ var durationInSeconds = 1;
+
+ var audit = Audit.createTaskRunner();
+
+ // Convenience function that returns a function that calls the |passFailFunc|
+ // with the given |message|. The |passFailFunc| should be either |testPassed|
+ // or |testFailed|.
+ function handlePromise(passFailFunc, message) {
+ return function () {
+ passFailFunc(message);
+ };
+ }
+
+ // Task: test suspend().
+ audit.defineTask('test-suspend', function (done) {
+
+ // 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", "suspended");
+
+ // Multiple calls to suspend() should not be a problem. But we can't test
+ // that on an offline context. Thus, check that suspend() on an
+ // OfflineAudioContext rejects the promise.
+ shouldNotThrow("p1 = context.suspend()");
+ shouldBeType(p1, Promise);
+ p1.then(
+ handlePromise(testFailed, "context.suspend() should have been rejected for an offline context"),
+ handlePromise(testPassed, "context.suspend() was correctly rejected for an offline context")
+ ).then(done);
+ });
+
+
+ // Task: test resume().
+ audit.defineTask('test-resume', function (done) {
+
+ // Multiple calls to resume should not be a problem. But we can't test
+ // that on an offline context. Thus, check that resume() on an
+ // OfflineAudioContext rejects the promise.
+ shouldNotThrow("p2 = context.resume()");
+ shouldBeType(p2, Promise);
+
+ // Resume doesn't actually resume an offline context
+ shouldBeEqualToString("context.state", "suspended");
+
+ p2.then(
+ handlePromise(testFailed, "context.resume() should have been rejected for an offline context"),
+ handlePromise(testPassed, "context.resume() was correctly rejected for an offline context")
+ ).then(done);
+ });
+
+ // Task: test the state after context closed.
+ audit.defineTask('test-after-close', function (done) {
+
+ // Render the offline context.
+ osc.start();
+
+ // Test suspend/resume in tested promise pattern. We don't care about the
+ // actual result of the offline rendering.
+ context.startRendering().then(function () {
shouldBeEqualToString("context.state", "closed");
+
// suspend() should be rejected on a closed context.
- context.suspend()
- .then(handlePromise(
- testFailed,
- "context.suspend() on a closed context not rejected"),
- handlePromise(
- testPassed,
- "context.suspend() on a closed context rejected as expected"))
- .then(function () {
- // resume() should be rejected on closed context.
- return context.resume();
- })
- .then(handlePromise(
- testFailed,
- "context.resume() on a closed context not rejected"),
- handlePromise(
- testPassed,
- "context.resume() on a closed context rejected as expected"))
- .then(finishJSTest);
- }
-
- function runOfflineContextTest() {
- // Render the offline context.
- osc.start();
- context.oncomplete = checkResult;
- context.startRendering();
- }
-
- function runResumeTest () {
- // Multiple calls to resume should not be a problem. But we can't test that on an offline
- // context. Thus, check that resume() on an OfflineAudioContext rejects the promise.
- shouldNotThrow("p1 = context.resume()");
- shouldBeType(p1, Promise);
- // Resume doesn't actually resume an offline context
- shouldBeEqualToString("context.state", "suspended");
-
- p1.then(handlePromise(
- testFailed,
- "context.resume() should have been rejected for an offline context"),
- handlePromise(
- testPassed,
- "context.resume() was correctly rejected for an offline context"))
- .then(runOfflineContextTest);
- }
-
- 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", "suspended");
-
- // Multiple calls to suspend() should not be a problem. But we can't test that on an offline
- // context. Thus, check that suspend() on an OfflineAudioContext rejects the promise.
- shouldNotThrow("p1 = context.suspend()");
- shouldBeType(p1, Promise);
- p1.then(handlePromise(
- testFailed,
- "context.suspend() should have been rejected for an offline context"),
- handlePromise(
- testPassed,
- "context.suspend() was correctly rejected for an offline context"))
- .then(runResumeTest);
- }
-
- runTest();
- successfullyParsed = true;
- </script>
- </body>
+ context.suspend().then(
+ handlePromise(testFailed, "context.suspend() on a closed context not rejected"),
+ handlePromise(testPassed, "context.suspend() on a closed context rejected as expected")
+ ).then(function () {
+ // resume() should be rejected on closed context.
+ context.resume().then(
+ handlePromise(testFailed, "context.resume() on a closed context not rejected"),
+ handlePromise(testPassed, "context.resume() on a closed context rejected as expected")
+ ).then(done);
+ });
+
+ });
+ });
+
+ audit.defineTask('finish-test', function (done) {
+ done();
+ finishJSTest();
+ });
+
+ audit.runTasks(
+ 'test-suspend',
+ 'test-resume',
+ 'test-after-close',
+ 'finish-test'
+ );
+
+ successfullyParsed = true;
+ </script>
+</body>
</html>

Powered by Google App Engine
This is Rietveld 408576698