| OLD | NEW |
| (Empty) |
| 1 <!doctype html> | |
| 2 <html> | |
| 3 <head> | |
| 4 <title>Test AudioContext.close()</title> | |
| 5 <script src="../../resources/testharness.js"></script> | |
| 6 <script src="../../resources/testharnessreport.js"></script> | |
| 7 <script src="../resources/audit-util.js"></script> | |
| 8 <script src="../resources/audit.js"></script> | |
| 9 </head> | |
| 10 | |
| 11 <body> | |
| 12 <script> | |
| 13 let context; | |
| 14 let destination; | |
| 15 let offline; | |
| 16 let osc; | |
| 17 let gain; | |
| 18 let offlinePromise; | |
| 19 let wave = new Float32Array(1); | |
| 20 | |
| 21 let audit = Audit.createTaskRunner(); | |
| 22 | |
| 23 // Task: test online context (1). | |
| 24 audit.define({ | |
| 25 label: 'test-online-context-1', | |
| 26 description: "Test online context 1" | |
| 27 }, function (task, should) { | |
| 28 // Create a context and verify that the various states are correct and | |
| 29 // that close() exists. | |
| 30 should(() => context = new AudioContext(), | |
| 31 "context0 = new AudioContext()") | |
| 32 .notThrow(); | |
| 33 should(context.state, "context0.state") | |
| 34 .beEqualTo("running"); | |
| 35 | |
| 36 // Create gain and oscillator for testing later. | |
| 37 should(() => osc = context.createOscillator(), | |
| 38 "osc = context.createOscillator()") | |
| 39 .notThrow(); | |
| 40 should(() => gain = context.createGain(), | |
| 41 "gain = context0.createGain()") | |
| 42 .notThrow(); | |
| 43 destination = context.destination; | |
| 44 should(() => gain.connect(context.destination), | |
| 45 "gain.connect(context0.destination)") | |
| 46 .notThrow(); | |
| 47 | |
| 48 // Close the context. When the promise is resolved, continue the next | |
| 49 // test task. | |
| 50 let promise = context.close().then(() => { | |
| 51 should(() => gain.disconnect(destination), | |
| 52 "gain.disconnect(destination) after close") | |
| 53 .notThrow(); | |
| 54 }); | |
| 55 should(promise, "context0.close()") | |
| 56 .beResolved() | |
| 57 .then(task.done.bind(this)); | |
| 58 }); | |
| 59 | |
| 60 // Task: test online context (2). | |
| 61 audit.define({ | |
| 62 label: 'test-online-context-2', | |
| 63 description: "Test closed online context 2" | |
| 64 }, function (task, should) { | |
| 65 // Context is closed, so verify that we cannot create any more nodes, | |
| 66 // nor connect any. | |
| 67 should(() => context.createAnalyser(), "context.createAnalyser()") | |
| 68 .throw("InvalidStateError"); | |
| 69 should(() => context.createBiquadFilter(), | |
| 70 "context.createBiquadFilter()") | |
| 71 .throw("InvalidStateError"); | |
| 72 | |
| 73 // createBuffer is an exception because it's not really tied in any way | |
| 74 // to an audio context. And it's useful to be able to create a buffer | |
| 75 // inside the oncomplete event of an offline context to use for testing | |
| 76 // purposes. | |
| 77 should(() => context.createBuffer(1, 1, 48000), | |
| 78 "context.createBuffer(1, 1, 48000)") | |
| 79 .notThrow(); | |
| 80 | |
| 81 should(() => context.createBufferSource(), | |
| 82 "context.createBufferSource()") | |
| 83 .throw("InvalidStateError"); | |
| 84 should(() => context.createChannelMerger(), | |
| 85 "context.createChannelMerger()") | |
| 86 .throw("InvalidStateError"); | |
| 87 should(() => context.createChannelSplitter(), | |
| 88 "context.createChannelSplitter()") | |
| 89 .throw("InvalidStateError"); | |
| 90 should(() => context.createConvolver(), "context.createConvolver()") | |
| 91 .throw("InvalidStateError"); | |
| 92 should(() => context.createDelay(), "context.createDelay()") | |
| 93 .throw("InvalidStateError"); | |
| 94 should(() => | |
| 95 context.createDynamicsCompressor(), | |
| 96 "context.createDynamicsCompressor()").throw("InvalidStateError"); | |
| 97 should(() => context.createGain(), "context.createGain()").throw( | |
| 98 "InvalidStateError"); | |
| 99 should(() => context.createOscillator(), | |
| 100 "context.createOscillator()") | |
| 101 .throw("InvalidStateError"); | |
| 102 should(() => context.createPanner(), "context.createPanner()") | |
| 103 .throw("InvalidStateError"); | |
| 104 should(() => context.createPeriodicWave(wave, wave), | |
| 105 "context.createPeriodicWave(wave, wave)") | |
| 106 .throw("InvalidStateError"); | |
| 107 should(() => context.createScriptProcessor(), | |
| 108 "context.createScriptProcessor()") | |
| 109 .throw("InvalidStateError"); | |
| 110 should(() => | |
| 111 context.createStereoPanner(), "context.createStereoPanner()").throw( | |
| 112 "InvalidStateError"); | |
| 113 should(() => context.createWaveShaper(), | |
| 114 "context.createWaveShaper()") | |
| 115 .throw("InvalidStateError"); | |
| 116 | |
| 117 should(() => osc.connect(gain), "osc.connect(gain)") | |
| 118 .throw("InvalidStateError"); | |
| 119 should(() => gain.disconnect(), "gain.disconnect()").notThrow(); | |
| 120 | |
| 121 // Can't resume a context that is closed (released). | |
| 122 should(context.resume(), "context.resume()") | |
| 123 .beRejected() | |
| 124 .then(task.done.bind(task)); | |
| 125 }); | |
| 126 | |
| 127 // Task: test online context (3). | |
| 128 audit.define({ | |
| 129 label: 'test-online-context-3', | |
| 130 description: "Close an online context again" | |
| 131 }, function (task, should) { | |
| 132 // Try closing the context again. The promise should be rejected. | |
| 133 should(context.close(), "context.close() again") | |
| 134 .beRejected() | |
| 135 .then(() => { | |
| 136 // Finally, run GC. The context should be gone, but this seems | |
| 137 // difficult to verify. | |
| 138 if (window.gc) | |
| 139 gc(); | |
| 140 should(context.destination, "context.destination") | |
| 141 .beEqualTo(null); | |
| 142 }) | |
| 143 .then(task.done.bind(task)); | |
| 144 }); | |
| 145 | |
| 146 // Task: test online context (4). | |
| 147 audit.define({ | |
| 148 label: 'test-online-context-4', | |
| 149 description: "Test closed online context 4" | |
| 150 }, function (task, should) { | |
| 151 // Create a context and verify that its sampleRate and baseLatency return | |
| 152 // valid values whether it's open or closed. | |
| 153 should(() => context = new AudioContext(), | |
| 154 "context1 = new AudioContext()") | |
| 155 .notThrow(); | |
| 156 should(context.sampleRate, "context1.sampleRate") | |
| 157 .beGreaterThan("0"); | |
| 158 should(context.sampleRate, "context1.baseLatency") | |
| 159 .beGreaterThan("0"); | |
| 160 | |
| 161 should(context.close(), "context1.close()") | |
| 162 .beResolved() | |
| 163 .then(() => { | |
| 164 should(context.sampleRate, "After close, context1.sampleRate") | |
| 165 .beGreaterThan("0"); | |
| 166 should(context.sampleRate, "After close, context1.baseLatency") | |
| 167 .beGreaterThan("0"); | |
| 168 }) | |
| 169 .then(task.done.bind(task)); | |
| 170 }); | |
| 171 | |
| 172 // Task: test offline context (1). | |
| 173 audit.define({ | |
| 174 label: 'test-offline-context-1', | |
| 175 description: "Test offline context" | |
| 176 }, function (task, should) { | |
| 177 // For an offline context, verify that close is not defined. | |
| 178 should(() => offline = new OfflineAudioContext(1, 1000, 48000), | |
| 179 "offline = new OfflineAudioContext(1, 1000, 48000)") | |
| 180 .notThrow(); | |
| 181 should(offline.state, "offline.state") | |
| 182 .beEqualTo("suspended"); | |
| 183 should(offline.close, "offline.close") | |
| 184 .beEqualTo(undefined); | |
| 185 task.done(); | |
| 186 }); | |
| 187 | |
| 188 audit.run(); | |
| 189 </script> | |
| 190 </body> | |
| 191 </html> | |
| OLD | NEW |