Commit 34c7f54d authored by hongchan@chromium.org's avatar hongchan@chromium.org

This patch includes a fix and refactoring on several layout tests for promise...

This patch includes a fix and refactoring on several layout tests for promise from AudioContext.suspend() and .resume().

|Audit| task runner handles the sequential execution of asynchrous test tasks.

BUG=460504

Review URL: https://codereview.chromium.org/945023002

git-svn-id: svn://svn.chromium.org/blink/trunk@190694 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent f482d402
...@@ -28,13 +28,13 @@ PASS context.createWaveShaper() threw exception InvalidStateError: Failed to exe ...@@ -28,13 +28,13 @@ PASS context.createWaveShaper() threw exception InvalidStateError: Failed to exe
PASS osc.connect(gain) threw exception InvalidStateError: Failed to execute 'connect' on 'AudioNode': Cannot connect after the context has been closed.. PASS osc.connect(gain) threw exception InvalidStateError: Failed to execute 'connect' on 'AudioNode': Cannot connect after the context has been closed..
PASS gain.disconnect() did not throw exception. PASS gain.disconnect() did not throw exception.
PASS Attempt to resume a closed context was correctly rejected PASS Attempt to resume a closed context was correctly rejected
PASS Closing context again correctly rejected promise.
PASS offline = new OfflineAudioContext(1, 1000, 48000) did not throw exception. PASS offline = new OfflineAudioContext(1, 1000, 48000) did not throw exception.
PASS offline.state is "suspended" PASS offline.state is "suspended"
PASS Closing offline context correctly rejected PASS Closing offline context correctly rejected
PASS Closing context again correctly rejected promise.
PASS Closing offline context again correctly rejected PASS Closing offline context again correctly rejected
PASS offline.startRendering() did not throw exception. PASS offline.startRendering() did not throw exception.
PASS offline.state is "closed" PASS event.target.state is "closed"
PASS successfullyParsed is true PASS successfullyParsed is true
TEST COMPLETE TEST COMPLETE
......
...@@ -7,7 +7,7 @@ PASS context.state is "suspended" ...@@ -7,7 +7,7 @@ PASS context.state is "suspended"
PASS p1 = context.suspend() did not throw exception. PASS p1 = context.suspend() did not throw exception.
PASS [object Object] is an instance of function Promise() { [native code] } PASS [object Object] is an instance of function Promise() { [native code] }
PASS context.suspend() was correctly rejected for an offline context PASS context.suspend() was correctly rejected for an offline context
PASS p1 = context.resume() did not throw exception. PASS p2 = context.resume() did not throw exception.
PASS [object Object] is an instance of function Promise() { [native code] } PASS [object Object] is an instance of function Promise() { [native code] }
PASS context.state is "suspended" PASS context.state is "suspended"
PASS context.resume() was correctly rejected for an offline context PASS context.resume() was correctly rejected for an offline context
......
<!doctype html> <!doctype html>
<html> <html>
<head> <head>
<title>Test audiocontext suspend/resume</title> <title>Test AudioContext.suspend() and AudioContext.resume()</title>
<script src="resources/compatibility.js"></script> <script src="../resources/js-test.js"></script>
<script src="resources/audio-testing.js"></script> <script src="resources/compatibility.js"></script>
<script src="../resources/js-test.js"></script> <script src="resources/audio-testing.js"></script>
</head> </head>
<body> <body>
<script> <script>
description("Test suspend/resume for an (offline) AudioContext"); description("Test suspend/resume for an (offline) AudioContext");
window.jsTestIsAsync = true;
var context;
var osc; var context;
var p1; var osc;
var p2; var p1;
var p2;
var sampleRate = 44100;
var durationInSeconds = 1; 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|. var audit = Audit.createTaskRunner();
function handlePromise(passFailMethod, message) {
return function () { // Convenience function that returns a function that calls the |passFailFunc|
passFailMethod(message); // with the given |message|. The |passFailFunc| should be either |testPassed|
}; // or |testFailed|.
} function handlePromise(passFailFunc, message) {
return function () {
function checkResult (event) { passFailFunc(message);
// We don't care about the actual result of the offline rendering. };
}
// 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"); shouldBeEqualToString("context.state", "closed");
// suspend() should be rejected on a closed context. // suspend() should be rejected on a closed context.
context.suspend() context.suspend().then(
.then(handlePromise( handlePromise(testFailed, "context.suspend() on a closed context not rejected"),
testFailed, handlePromise(testPassed, "context.suspend() on a closed context rejected as expected")
"context.suspend() on a closed context not rejected"), ).then(function () {
handlePromise( // resume() should be rejected on closed context.
testPassed, context.resume().then(
"context.suspend() on a closed context rejected as expected")) handlePromise(testFailed, "context.resume() on a closed context not rejected"),
.then(function () { handlePromise(testPassed, "context.resume() on a closed context rejected as expected")
// resume() should be rejected on closed context. ).then(done);
return context.resume(); });
})
.then(handlePromise( });
testFailed, });
"context.resume() on a closed context not rejected"),
handlePromise( audit.defineTask('finish-test', function (done) {
testPassed, done();
"context.resume() on a closed context rejected as expected")) finishJSTest();
.then(finishJSTest); });
}
audit.runTasks(
function runOfflineContextTest() { 'test-suspend',
// Render the offline context. 'test-resume',
osc.start(); 'test-after-close',
context.oncomplete = checkResult; 'finish-test'
context.startRendering(); );
}
successfullyParsed = true;
function runResumeTest () { </script>
// Multiple calls to resume should not be a problem. But we can't test that on an offline </body>
// 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>
</html> </html>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment