OLD | NEW |
1 <!doctype html> | 1 <!doctype html> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
4 <title>Test AudioContext.close()</title> | 4 <title>Test AudioContext.close()</title> |
5 <script src="../../resources/testharness.js"></script> | 5 <script src="../../resources/testharness.js"></script> |
6 <script src="../../resources/testharnessreport.js"></script> | 6 <script src="../../resources/testharnessreport.js"></script> |
7 <script src="../resources/audit-util.js"></script> | 7 <script src="../resources/audit-util.js"></script> |
8 <script src="../resources/audit.js"></script> | 8 <script src="../resources/audit.js"></script> |
9 </head> | 9 </head> |
10 | 10 |
11 <body> | 11 <body> |
12 <script> | 12 <script> |
13 let context; | 13 let context; |
14 let destination; | 14 let destination; |
15 let offline; | 15 let offline; |
16 let osc; | 16 let osc; |
17 let gain; | 17 let gain; |
18 let offlinePromise; | 18 let offlinePromise; |
19 let wave = new Float32Array(1); | 19 let wave = new Float32Array(1); |
20 | 20 |
21 let audit = Audit.createTaskRunner(); | 21 let audit = Audit.createTaskRunner(); |
22 | 22 |
23 // Task: test online context (1). | 23 // Task: test online context (1). |
24 audit.define('test-online-context-1', function (task, should) { | 24 audit.define({ |
25 task.describe("Test online context 1"); | 25 label: 'test-online-context-1', |
| 26 description: "Test online context 1" |
| 27 }, function (task, should) { |
26 // Create a context and verify that the various states are correct and | 28 // Create a context and verify that the various states are correct and |
27 // that close() exists. | 29 // that close() exists. |
28 should(() => context = new AudioContext(), | 30 should(() => context = new AudioContext(), |
29 "context = new AudioContext()") | 31 "context = new AudioContext()") |
30 .notThrow(); | 32 .notThrow(); |
31 should(context.state, "context.state") | 33 should(context.state, "context.state") |
32 .beEqualTo("running"); | 34 .beEqualTo("running"); |
33 | 35 |
34 // Create gain and oscillator for testing later. | 36 // Create gain and oscillator for testing later. |
35 should(() => osc = context.createOscillator(), | 37 should(() => osc = context.createOscillator(), |
(...skipping 13 matching lines...) Expand all Loading... |
49 should(() => gain.disconnect(destination), | 51 should(() => gain.disconnect(destination), |
50 "gain.disconnect(destination) after close") | 52 "gain.disconnect(destination) after close") |
51 .notThrow(); | 53 .notThrow(); |
52 }); | 54 }); |
53 should(promise, "context.close()") | 55 should(promise, "context.close()") |
54 .beResolved() | 56 .beResolved() |
55 .then(task.done.bind(this)); | 57 .then(task.done.bind(this)); |
56 }); | 58 }); |
57 | 59 |
58 // Task: test online context (2). | 60 // Task: test online context (2). |
59 audit.define('test-online-context-2', function (task, should) { | 61 audit.define({ |
60 task.describe("Test closed online context 2"); | 62 label: 'test-online-context-2', |
| 63 description: "Test closed online context 2" |
| 64 }, function (task, should) { |
61 // Context is closed, so verify that we cannot create any more nodes, | 65 // Context is closed, so verify that we cannot create any more nodes, |
62 // nor connect any. | 66 // nor connect any. |
63 should(() => context.createAnalyser(), "context.createAnalyser()") | 67 should(() => context.createAnalyser(), "context.createAnalyser()") |
64 .throw("InvalidStateError"); | 68 .throw("InvalidStateError"); |
65 should(() => context.createBiquadFilter(), | 69 should(() => context.createBiquadFilter(), |
66 "context.createBiquadFilter()") | 70 "context.createBiquadFilter()") |
67 .throw("InvalidStateError"); | 71 .throw("InvalidStateError"); |
68 | 72 |
69 // createBuffer is an exception because it's not really tied in any way | 73 // createBuffer is an exception because it's not really tied in any way |
70 // to an audio context. And it's useful to be able to create a buffer | 74 // to an audio context. And it's useful to be able to create a buffer |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 .throw("InvalidStateError"); | 118 .throw("InvalidStateError"); |
115 should(() => gain.disconnect(), "gain.disconnect()").notThrow(); | 119 should(() => gain.disconnect(), "gain.disconnect()").notThrow(); |
116 | 120 |
117 // Can't resume a context that is closed (released). | 121 // Can't resume a context that is closed (released). |
118 should(context.resume(), "context.resume()") | 122 should(context.resume(), "context.resume()") |
119 .beRejected() | 123 .beRejected() |
120 .then(task.done.bind(task)); | 124 .then(task.done.bind(task)); |
121 }); | 125 }); |
122 | 126 |
123 // Task: test online context (3). | 127 // Task: test online context (3). |
124 audit.define('test-online-context-3', function (task, should) { | 128 audit.define({ |
125 task.describe("Close an online context again"); | 129 label: 'test-online-context-3', |
| 130 description: "Close an online context again" |
| 131 }, function (task, should) { |
126 // Try closing the context again. The promise should be rejected. | 132 // Try closing the context again. The promise should be rejected. |
127 should(context.close(), "context.close() again") | 133 should(context.close(), "context.close() again") |
128 .beRejected() | 134 .beRejected() |
129 .then(() => { | 135 .then(() => { |
130 // Finally, run GC. The context should be gone, but this seems | 136 // Finally, run GC. The context should be gone, but this seems |
131 // difficult to verify. | 137 // difficult to verify. |
132 if (window.gc) | 138 if (window.gc) |
133 gc(); | 139 gc(); |
134 should(context.destination, "context.destination") | 140 should(context.destination, "context.destination") |
135 .beEqualTo(null); | 141 .beEqualTo(null); |
136 }) | 142 }) |
137 .then(task.done.bind(task)); | 143 .then(task.done.bind(task)); |
138 }); | 144 }); |
139 | 145 |
140 // Task: test online context (4). | 146 // Task: test online context (4). |
141 audit.define('test-online-context-4', function (task, should) { | 147 audit.define({ |
142 task.describe("Test closed online context 4"); | 148 label: 'test-online-context-4', |
| 149 description: "Test closed online context 4" |
| 150 }, function (task, should) { |
143 // Create a context and verify that its sampleRate and baseLatency return | 151 // Create a context and verify that its sampleRate and baseLatency return |
144 // valid values whether it's open or closed. | 152 // valid values whether it's open or closed. |
145 should(() => context = new AudioContext(), | 153 should(() => context = new AudioContext(), |
146 "context = new AudioContext()") | 154 "context = new AudioContext()") |
147 .notThrow(); | 155 .notThrow(); |
148 should(context.sampleRate, "context.sampleRate") | 156 should(context.sampleRate, "context.sampleRate") |
149 .beGreaterThan("0"); | 157 .beGreaterThan("0"); |
150 should(context.sampleRate, "context.baseLatency") | 158 should(context.sampleRate, "context.baseLatency") |
151 .beGreaterThan("0"); | 159 .beGreaterThan("0"); |
152 | 160 |
153 should(context.close(), "context.close()") | 161 should(context.close(), "context.close()") |
154 .beResolved() | 162 .beResolved() |
155 .then(() => { | 163 .then(() => { |
156 should(context.sampleRate, "context.sampleRate") | 164 should(context.sampleRate, "context.sampleRate") |
157 .beGreaterThan("0"); | 165 .beGreaterThan("0"); |
158 should(context.sampleRate, "context.baseLatency") | 166 should(context.sampleRate, "context.baseLatency") |
159 .beGreaterThan("0"); | 167 .beGreaterThan("0"); |
160 }) | 168 }) |
161 .then(task.done.bind(task)); | 169 .then(task.done.bind(task)); |
162 }); | 170 }); |
163 | 171 |
164 // Task: test offline context (1). | 172 // Task: test offline context (1). |
165 audit.define('test-offline-context-1', function (task, should) { | 173 audit.define({ |
166 task.describe("Test offline context"); | 174 label: 'test-offline-context-1', |
| 175 description: "Test offline context" |
| 176 }, function (task, should) { |
167 // For an offline context, verify that close is not defined. | 177 // For an offline context, verify that close is not defined. |
168 should(() => offline = new OfflineAudioContext(1, 1000, 48000), | 178 should(() => offline = new OfflineAudioContext(1, 1000, 48000), |
169 "offline = new OfflineAudioContext(1, 1000, 48000)") | 179 "offline = new OfflineAudioContext(1, 1000, 48000)") |
170 .notThrow(); | 180 .notThrow(); |
171 should(offline.state, "offline.state") | 181 should(offline.state, "offline.state") |
172 .beEqualTo("suspended"); | 182 .beEqualTo("suspended"); |
173 should(offline.close, "offline.close") | 183 should(offline.close, "offline.close") |
174 .beEqualTo(undefined); | 184 .beEqualTo(undefined); |
175 task.done(); | 185 task.done(); |
176 }); | 186 }); |
177 | 187 |
178 audit.run(); | 188 audit.run(); |
179 </script> | 189 </script> |
180 </body> | 190 </body> |
181 </html> | 191 </html> |
OLD | NEW |