Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / webaudio / audiocontext-suspend-resume.html
blob8c16380b9a6cc867460b063fafd397231b770ddd
1 <!doctype html>
2 <html>
3 <head>
4 <title>Test AudioContext.suspend() and AudioContext.resume()</title>
5 <script src="../resources/js-test.js"></script>
6 <script src="resources/compatibility.js"></script>
7 <script src="resources/audio-testing.js"></script>
8 </head>
10 <body>
11 <script>
12 description("Test suspend/resume for an (offline) AudioContext");
13 window.jsTestIsAsync = true;
15 var offlineContext;
16 var osc;
17 var p1;
18 var p2;
19 var p3;
21 var sampleRate = 44100;
22 var durationInSeconds = 1;
24 var audit = Audit.createTaskRunner();
26 // Convenience function that returns a function that calls the |passFailFunc|
27 // with the given |message|. The |passFailFunc| should be either |testPassed|
28 // or |testFailed|.
29 function handlePromise(passFailFunc, message) {
30 return function () {
31 passFailFunc(message);
35 // Task: test suspend().
36 audit.defineTask('test-suspend', function (done) {
38 // Test suspend/resume. Ideally this test is best with a online
39 // AudioContext, but content shell doesn't really have a working online
40 // AudioContext. Hence, use an OfflineAudioContext. Not all possible
41 // scenarios can be easily checked with an offline context instead of an
42 // online context.
44 // Create an audio context with an oscillator.
45 shouldNotThrow("offlineContext = new OfflineAudioContext(1, durationInSeconds * sampleRate, sampleRate)");
46 osc = offlineContext.createOscillator();
47 osc.connect(offlineContext.destination);
49 // Verify the state.
50 shouldBeEqualToString("offlineContext.state", "suspended");
52 // Multiple calls to suspend() should not be a problem. But we can't test
53 // that on an offline context. Thus, check that suspend() on an
54 // OfflineAudioContext rejects the promise.
55 shouldNotThrow("p1 = offlineContext.suspend()");
56 shouldBeType("p1", "Promise");
57 p1.then(
58 handlePromise(testFailed, "offlineContext.suspend() should have been rejected for an offline context"),
59 function (e) {
60 if (e.name === "InvalidAccessError") {
61 testPassed(
62 "offlineContext.suspend() was correctly rejected: " + e);
63 } else {
64 testFailed(
65 "offlineContext.suspend() was correctly rejected but expected InvalidAccessError, not: " + e);
68 ).then(done);
69 });
72 // Task: test resume().
73 audit.defineTask('test-resume', function (done) {
75 // Multiple calls to resume should not be a problem. But we can't test
76 // that on an offline context. Thus, check that resume() on an
77 // OfflineAudioContext rejects the promise.
78 shouldNotThrow("p2 = offlineContext.resume()");
79 shouldBeType("p2", "Promise");
81 // Resume doesn't actually resume an offline context
82 shouldBeEqualToString("offlineContext.state", "suspended");
83 p2.then(
84 handlePromise(testFailed, "offlineContext.resume() should have been rejected for an offline context"),
85 function (e) {
86 if (e.name === "InvalidAccessError") {
87 testPassed(
88 "offlineContext.resume() was correctly rejected: " + e);
89 } else {
90 testFailed(
91 "offlineContext.resume() was correctly rejected but expected InvalidAccessError, not: " + e);
94 ).then(done);
95 });
97 // Task: test the state after context closed.
98 audit.defineTask('test-after-close', function (done) {
100 // Render the offline context.
101 osc.start();
103 // Test suspend/resume in tested promise pattern. We don't care about the
104 // actual result of the offline rendering.
105 shouldNotThrow("p3 = offlineContext.startRendering()");
106 p3.then(function () {
107 shouldBeEqualToString("offlineContext.state", "closed");
109 // suspend() should be rejected on a closed context.
110 offlineContext.suspend().then(
111 handlePromise(testFailed, "offlineContext.suspend() on a closed context not rejected"),
112 function (e) {
113 if (e.name === "InvalidAccessError") {
114 testPassed("offlineContext.suspend() on a closed context rejected: " + e);
115 } else {
116 testFailed("offlineContext.suspend() on a closed context rejected but expected InvalidAccessError, not: " + e);
119 ).then(function () {
120 // resume() should be rejected on closed context.
121 offlineContext.resume().then(
122 handlePromise(testFailed, "offlineContext.resume() on a closed context not rejected"),
123 function (e) {
124 if (e.name === "InvalidAccessError") {
125 testPassed("offlineContext.resume() on a closed context rejected: " + e);
126 } else {
127 testFailed("offlineContext.resume() on a closed context rejected but expected InvalidAccessError, not: " + e);
130 ).then(done);
136 audit.defineTask('finish-test', function (done) {
137 done();
138 finishJSTest();
141 audit.runTasks(
142 'test-suspend',
143 'test-resume',
144 'test-after-close',
145 'finish-test'
148 successfullyParsed = true;
149 </script>
150 </body>
151 </html>