Chromium Code Reviews| 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/js-test.js"></script> | 5 <script src="../../resources/testharness.js"></script> |
| 6 <script src="../../resources/testharnessreport.js"></script> | |
| 6 <script src="../resources/audit-util.js"></script> | 7 <script src="../resources/audit-util.js"></script> |
| 7 <script src="../resources/audio-testing.js"></script> | 8 <script src="../resources/audit.js"></script> |
| 8 </head> | 9 </head> |
| 9 | 10 |
| 10 <body> | 11 <body> |
| 11 <script> | 12 <script> |
| 12 description("Basic functionality test of closing an AudioContext"); | 13 let context; |
| 13 window.jsTestIsAsync = true; | 14 let destination; |
| 15 let offline; | |
| 16 let osc; | |
| 17 let gain; | |
| 18 let offlinePromise; | |
| 19 let wave = new Float32Array(1); | |
| 14 | 20 |
| 15 var context; | 21 let audit = Audit.createTaskRunner(); |
| 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); | |
| 24 | |
| 25 var audit = Audit.createTaskRunner(); | |
| 26 | 22 |
| 27 // Task: test online context (1). | 23 // Task: test online context (1). |
| 28 audit.defineTask('test-online-context-1', function (done) { | 24 audit.define('test-online-context-1', function (task, should) { |
| 29 | 25 task.describe("Test online context 1"); |
| 30 // Create a context and verify that the various states are correct and | 26 // Create a context and verify that the various states are correct and |
| 31 // that close() exists. | 27 // that close() exists. |
| 32 shouldNotThrow("context = new AudioContext()"); | 28 should(function () { |
| 33 shouldBeEqualToString("context.state", "running"); | 29 context = new AudioContext(); |
| 30 }, "context = new AudioContext()") | |
| 31 .notThrow();; | |
|
hongchan
2017/01/20 23:08:41
Two semicolons.
Raymond Toy
2017/01/23 19:24:59
Done.
| |
| 32 should(context.state, "context.state") | |
| 33 .beEqualTo("running"); | |
| 34 | 34 |
| 35 // Create gain and oscillator for testing later. | 35 // Create gain and oscillator for testing later. |
| 36 shouldNotThrow("osc = context.createOscillator()"); | 36 should(function () { |
|
hongchan
2017/01/20 23:08:41
Let's use () => {} notation.
Raymond Toy
2017/01/23 19:24:59
Done.
| |
| 37 shouldNotThrow("gain = context.createGain()"); | 37 osc = context.createOscillator() |
| 38 }, "osc = context.createOscillator()") | |
| 39 .notThrow(); | |
| 40 should(function () { | |
| 41 gain = context.createGain(); | |
| 42 }, "gain = context.createGain()") | |
| 43 .notThrow(); | |
| 38 destination = context.destination; | 44 destination = context.destination; |
| 39 shouldNotThrow("gain.connect(context.destination)"); | 45 should(function () { |
| 46 gain.connect(context.destination); | |
| 47 }, "gain.connect(context.destination)") | |
| 48 .notThrow(""); | |
| 40 | 49 |
| 41 // Close the context. When the promise is resolved, continue the next | 50 // Close the context. When the promise is resolved, continue the next |
| 42 // test task. | 51 // test task. |
| 43 context.close().then( | 52 should(context.close().then(function () { |
| 44 function () { | 53 should(function () { |
| 45 testPassed("context.close() was correctly resolved"); | 54 gain.disconnect(destination) |
| 46 shouldNotThrow("gain.disconnect(destination)"); | 55 }, "gain.disconnect(destination) after close") |
| 47 }, | 56 .notThrow(); |
| 48 function () { | 57 }), "context.close()") |
| 49 testFailed("context.close() was erroneously rejected"); | 58 .beResolved() |
| 50 } | 59 .then(task.done.bind(this)); |
| 51 ).then(done); | |
| 52 | |
| 53 }); | 60 }); |
| 54 | 61 |
| 55 // Task: test online context (2). | 62 // Task: test online context (2). |
| 56 audit.defineTask('test-online-context-2', function (done) { | 63 audit.define('test-online-context-2', function (task, should) { |
| 57 | 64 task.describe("Test closed online context 2"); |
| 58 // 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, |
| 59 // nor connect any. | 66 // nor connect any. |
| 60 shouldThrow("context.createAnalyser()"); | 67 should(function () { |
| 61 shouldThrow("context.createBiquadFilter()"); | 68 context.createAnalyser(); |
| 69 }, "context.createAnalyser()") | |
| 70 .throw("InvalidStateError"); | |
| 71 should(function () { | |
| 72 context.createBiquadFilter(); | |
| 73 }, "context.createBiquadFilter()") | |
| 74 .throw("InvalidStateError"); | |
| 62 | 75 |
| 63 // createBuffer is an exception because it's not really tied in any way | 76 // 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 | 77 // 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 | 78 // inside the oncomplete event of an offline context to use for testing |
| 66 // purposes. | 79 // purposes. |
| 67 shouldNotThrow("context.createBuffer(1, 1, 48000)"); | 80 should(function () { |
| 81 context.createBuffer(1, 1, 48000); | |
| 82 }, "context.createBuffer(1, 1, 48000)") | |
| 83 .notThrow(); | |
| 68 | 84 |
| 69 shouldThrow("context.createBufferSource()"); | 85 should(function () { |
| 70 shouldThrow("context.createChannelMerger()"); | 86 context.createBufferSource(); |
| 71 shouldThrow("context.createChannelSplitter()"); | 87 }, "context.createBufferSource()") |
| 72 shouldThrow("context.createConvolver()"); | 88 .throw("InvalidStateError"); |
| 73 shouldThrow("context.createDelay()"); | 89 should(function () { |
| 74 shouldThrow("context.createDynamicsCompressor()"); | 90 context.createChannelMerger(); |
| 75 shouldThrow("context.createGain()"); | 91 }, "context.createChannelMerger()") |
| 76 shouldThrow("context.createOscillator()"); | 92 .throw("InvalidStateError"); |
| 77 shouldThrow("context.createPanner()"); | 93 should(function () { |
| 78 shouldThrow("context.createPeriodicWave(wave, wave)"); | 94 context.createChannelSplitter(); |
| 79 shouldThrow("context.createScriptProcessor()"); | 95 }, "context.createChannelSplitter()") |
| 80 shouldThrow("context.createStereoPanner()"); | 96 .throw("InvalidStateError"); |
| 81 shouldThrow("context.createWaveShaper()"); | 97 should(function () { |
| 98 context.createConvolver(); | |
| 99 }, "context.createConvolver()") | |
| 100 .throw("InvalidStateError"); | |
| 101 should(function () { | |
| 102 context.createDelay(); | |
| 103 }, "context.createDelay()") | |
| 104 .throw("InvalidStateError"); | |
| 105 should(function () { | |
| 106 context.createDynamicsCompressor(); | |
| 107 }, "context.createDynamicsCompressor()") | |
| 108 .throw("InvalidStateError"); | |
| 109 should(function () { | |
| 110 context.createGain(); | |
| 111 }, "context.createGain()") | |
| 112 .throw("InvalidStateError"); | |
| 113 should(function () { | |
| 114 context.createOscillator(); | |
| 115 }, "context.createOscillator()") | |
| 116 .throw("InvalidStateError"); | |
| 117 should(function () { | |
| 118 context.createPanner(); | |
| 119 }, "context.createPanner()") | |
| 120 .throw("InvalidStateError"); | |
| 121 should(function () { | |
| 122 context.createPeriodicWave(wave, wave); | |
| 123 }, "context.createPeriodicWave(wave, wave)") | |
| 124 .throw( | |
|
hongchan
2017/01/20 23:08:41
No line break needed.
Raymond Toy
2017/01/23 19:24:59
Done.
| |
| 125 "InvalidStateError"); | |
| 126 should(function () { | |
| 127 context.createScriptProcessor(); | |
| 128 }, "context.createScriptProcessor()") | |
| 129 .throw("InvalidStateError"); | |
| 130 should(function () { | |
| 131 context.createStereoPanner(); | |
| 132 }, "context.createStereoPanner()") | |
| 133 .throw("InvalidStateError"); | |
| 134 should(function () { | |
| 135 context.createWaveShaper(); | |
| 136 }, "context.createWaveShaper()") | |
| 137 .throw("InvalidStateError"); | |
| 82 | 138 |
| 83 shouldThrow("osc.connect(gain)"); | 139 should(function () { |
| 84 shouldNotThrow("gain.disconnect()"); | 140 osc.connect(gain); |
| 141 }, "osc.connect(gain)") | |
| 142 .throw("InvalidStateError"); | |
| 143 should(function () { | |
| 144 gain.disconnect(); | |
| 145 }, "gain.disconnect()").notThrow(); | |
| 85 | 146 |
| 86 // Can't resume a context that is closed (released). | 147 // Can't resume a context that is closed (released). |
| 87 context.resume().then( | 148 should(context.resume(), "context.resume()") |
| 88 function () { | 149 .beRejected() |
| 89 testFailed("Attempt to resume a closed context erroneously succeeded") ; | 150 .then(task.done.bind(task)); |
| 90 }, | |
| 91 function () { | |
| 92 testPassed("Attempt to resume a closed context was correctly rejected" ); | |
| 93 } | |
| 94 ).then(done); | |
| 95 }); | 151 }); |
| 96 | 152 |
| 153 | |
|
hongchan
2017/01/20 23:08:41
An extra line added here.
Raymond Toy
2017/01/23 19:24:59
Done.
| |
| 97 // Task: test online context (3). | 154 // Task: test online context (3). |
| 98 audit.defineTask('test-online-context-3', function (done) { | 155 audit.define('test-online-context-3', function (task, should) { |
| 99 | 156 task.describe("Close an online context again"); |
| 100 // Try closing the context again. The promise should be rejected. | 157 // Try closing the context again. The promise should be rejected. |
| 101 context.close().then( | 158 should(context.close(), "context.close() again") |
| 102 function () { | 159 .beRejected() |
| 103 testFailed("Closing context again erroneously resolved successfully.") ; | 160 .then(function () { |
| 104 }, | 161 // Finally, run GC. The context should be gone, but this seems |
| 105 function () { | 162 // difficult to verify. |
| 106 testPassed("Closing context again correctly rejected promise."); | 163 if (window.gc) |
| 107 // Finally, run GC. The context should be gone, but this seems difficu lt to verify. | 164 gc(); |
| 108 gc(); | 165 should(context.destination, "context.destination") |
| 109 shouldBeNull("context.destination"); | 166 .beEqualTo(null); |
| 110 } | 167 }) |
| 111 ).then(done); | 168 .then(task.done.bind(task)); |
| 112 }); | 169 }); |
| 113 | 170 |
| 114 // Task: test offline context (1). | 171 // Task: test offline context (1). |
| 115 audit.defineTask('test-offline-context-1', function (done) { | 172 audit.define('test-offline-context-1', function (task, should) { |
| 116 | 173 task.describe("Test offline context"); |
| 117 // For an offline context, verify that close is not defined. | 174 // For an offline context, verify that close is not defined. |
| 118 shouldNotThrow("offline = new OfflineAudioContext(1, 1000, 48000)"); | 175 should(function () { |
| 119 shouldBeEqualToString("offline.state", "suspended"); | 176 offline = new OfflineAudioContext(1, 1000, 48000); |
| 120 shouldBeUndefined("offline.close"); | 177 }, "offline = new OfflineAudioContext(1, 1000, 48000)") |
| 121 done(); | 178 .notThrow(); |
| 179 should(offline.state, "offline.state") | |
| 180 .beEqualTo("suspended"); | |
| 181 should(offline.close, "offline.close") | |
| 182 .beEqualTo(undefined); | |
| 183 task.done(); | |
| 122 }); | 184 }); |
| 123 | 185 |
| 124 audit.defineTask('finish-test', function (done) { | 186 audit.run(); |
| 125 done(); | |
| 126 finishJSTest(); | |
| 127 }); | |
| 128 | |
| 129 audit.runTasks(); | |
| 130 | |
| 131 successfullyParsed = true; | |
| 132 </script> | 187 </script> |
| 133 </body> | 188 </body> |
| 134 </html> | 189 </html> |
| OLD | NEW |