Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / webaudio / audiocontext-close.html
bloba0831dd4679fec7198f95d5103fc9c4b13670cd1
1 <!doctype html>
2 <html>
3 <head>
4 <title>Test AudioContext.close()</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("Basic functionality test of closing an AudioContext");
13 window.jsTestIsAsync = true;
15 var context;
16 var destination;
17 var offline;
18 var osc;
19 var gain;
20 var promise1;
21 var promise2;
22 var offlinePromise;
23 var wave = new Float32Array(1);
25 var audit = Audit.createTaskRunner();
27 // Task: test online context (1).
28 audit.defineTask('test-online-context-1', function (done) {
30 // Create a context and verify that the various states are correct and
31 // that close() exists.
32 shouldNotThrow("context = new AudioContext()");
33 shouldBeEqualToString("context.state", "running");
35 // Create gain and oscillator for testing later.
36 shouldNotThrow("osc = context.createOscillator()");
37 shouldNotThrow("gain = context.createGain()");
38 destination = context.destination;
39 shouldNotThrow("gain.connect(context.destination)");
41 // Close the context. When the promise is resolved, continue the next
42 // test task.
43 context.close().then(
44 function () {
45 testPassed("context.close() was correctly resolved");
46 shouldNotThrow("gain.disconnect(destination)");
48 function () {
49 testFailed("context.close() was erroneously rejected");
51 ).then(done);
53 });
55 // Task: test online context (2).
56 audit.defineTask('test-online-context-2', function (done) {
58 // Context is closed, so verify that we cannot create any more nodes,
59 // nor connect any.
60 shouldThrow("context.createAnalyser()");
61 shouldThrow("context.createBiquadFilter()");
63 // createBuffer is an exception because it's not really tied in any way
64 // to an audio context. And it's useful to be able to create a buffer
65 // inside the oncomplete event of an offline context to use for testing
66 // purposes.
67 shouldNotThrow("context.createBuffer(1, 1, 48000)");
69 shouldThrow("context.createBufferSource()");
70 shouldThrow("context.createChannelMerger()");
71 shouldThrow("context.createChannelSplitter()");
72 shouldThrow("context.createConvolver()");
73 shouldThrow("context.createDelay()");
74 shouldThrow("context.createDynamicsCompressor()");
75 shouldThrow("context.createGain()");
76 shouldThrow("context.createOscillator()");
77 shouldThrow("context.createPanner()");
78 shouldThrow("context.createPeriodicWave(wave, wave)");
79 shouldThrow("context.createScriptProcessor()");
80 shouldThrow("context.createStereoPanner()");
81 shouldThrow("context.createWaveShaper()");
83 shouldThrow("osc.connect(gain)");
84 shouldNotThrow("gain.disconnect()");
86 // Can't resume a context that is closed (released).
87 context.resume().then(
88 function () {
89 testFailed("Attempt to resume a closed context erroneously succeeded");
91 function () {
92 testPassed("Attempt to resume a closed context was correctly rejected");
94 ).then(done);
95 });
97 // Task: test online context (3).
98 audit.defineTask('test-online-context-3', function (done) {
100 // Try closing the context again. The promise should be rejected.
101 context.close().then(
102 function () {
103 testFailed("Closing context again erroneously resolved successfully.");
105 function () {
106 testPassed("Closing context again correctly rejected promise.");
107 // Finally, run GC. The context should be gone, but this seems difficult to verify.
108 gc();
109 shouldBeNull("context.destination");
111 ).then(done);
114 // Task: test offline context (1).
115 audit.defineTask('test-offline-context-1', function (done) {
117 // For an offline context, just check that if we try to close the context,
118 // nothing happens except that the promise returned by close() is rejected.
119 shouldNotThrow("offline = new OfflineAudioContext(1, 1000, 48000)");
120 shouldBeEqualToString("offline.state", "suspended");
121 offline.close().then(
122 function () {
123 testFailed("Closing offline context erroneously resolved");
125 function (e) {
126 if (e.name === "InvalidAccessError") {
127 testPassed("Closing offline context correctly rejected: " + e);
128 } else {
129 testFailed("Closing offline context correctly rejected but expected InvalidAccessError, not: " + e);
132 ).then(done);
135 // Task: test offline context (2).
136 audit.defineTask('test-offline-context-2', function (done) {
138 // Try closing again
139 offline.close().then(
140 function () {
141 testFailed("Closing offline context again erroneously resolved");
143 function () {
144 testPassed("Closing offline context again correctly rejected");
146 ).then(
147 function () {
149 // Render the context, and check for a valid state
150 offline.oncomplete = function (event) {
151 shouldBeEqualToString("event.target.state", "closed");
152 done();
154 shouldNotThrow("offline.startRendering()");
160 audit.defineTask('finish-test', function (done) {
161 done();
162 finishJSTest();
165 audit.runTasks(
166 'test-online-context-1',
167 'test-online-context-2',
168 'test-online-context-3',
169 'test-offline-context-1',
170 'test-offline-context-2',
171 'finish-test'
174 successfullyParsed = true;
175 </script>
176 </body>
177 </html>