| 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(() => context = new AudioContext(), |
| 33 shouldBeEqualToString("context.state", "running"); | 29 "context = new AudioContext()") |
| 30 .notThrow(); |
| 31 should(context.state, "context.state") |
| 32 .beEqualTo("running"); |
| 34 | 33 |
| 35 // Create gain and oscillator for testing later. | 34 // Create gain and oscillator for testing later. |
| 36 shouldNotThrow("osc = context.createOscillator()"); | 35 should(() => osc = context.createOscillator(), |
| 37 shouldNotThrow("gain = context.createGain()"); | 36 "osc = context.createOscillator()") |
| 37 .notThrow(); |
| 38 should(() => gain = context.createGain(), |
| 39 "gain = context.createGain()") |
| 40 .notThrow(); |
| 38 destination = context.destination; | 41 destination = context.destination; |
| 39 shouldNotThrow("gain.connect(context.destination)"); | 42 should(() => gain.connect(context.destination), |
| 43 "gain.connect(context.destination)") |
| 44 .notThrow(); |
| 40 | 45 |
| 41 // Close the context. When the promise is resolved, continue the next | 46 // Close the context. When the promise is resolved, continue the next |
| 42 // test task. | 47 // test task. |
| 43 context.close().then( | 48 let promise = context.close().then(() => { |
| 44 function () { | 49 should(() => gain.disconnect(destination), |
| 45 testPassed("context.close() was correctly resolved"); | 50 "gain.disconnect(destination) after close") |
| 46 shouldNotThrow("gain.disconnect(destination)"); | 51 .notThrow(); |
| 47 }, | 52 }); |
| 48 function () { | 53 should(promise, "context.close()") |
| 49 testFailed("context.close() was erroneously rejected"); | 54 .beResolved() |
| 50 } | 55 .then(task.done.bind(this)); |
| 51 ).then(done); | |
| 52 | |
| 53 }); | 56 }); |
| 54 | 57 |
| 55 // Task: test online context (2). | 58 // Task: test online context (2). |
| 56 audit.defineTask('test-online-context-2', function (done) { | 59 audit.define('test-online-context-2', function (task, should) { |
| 57 | 60 task.describe("Test closed online context 2"); |
| 58 // Context is closed, so verify that we cannot create any more nodes, | 61 // Context is closed, so verify that we cannot create any more nodes, |
| 59 // nor connect any. | 62 // nor connect any. |
| 60 shouldThrow("context.createAnalyser()"); | 63 should(() => context.createAnalyser(), "context.createAnalyser()") |
| 61 shouldThrow("context.createBiquadFilter()"); | 64 .throw("InvalidStateError"); |
| 65 should(() => context.createBiquadFilter(), |
| 66 "context.createBiquadFilter()") |
| 67 .throw("InvalidStateError"); |
| 62 | 68 |
| 63 // createBuffer is an exception because it's not really tied in any way | 69 // 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 | 70 // 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 | 71 // inside the oncomplete event of an offline context to use for testing |
| 66 // purposes. | 72 // purposes. |
| 67 shouldNotThrow("context.createBuffer(1, 1, 48000)"); | 73 should(() => context.createBuffer(1, 1, 48000), |
| 74 "context.createBuffer(1, 1, 48000)") |
| 75 .notThrow(); |
| 68 | 76 |
| 69 shouldThrow("context.createBufferSource()"); | 77 should(() => context.createBufferSource(), |
| 70 shouldThrow("context.createChannelMerger()"); | 78 "context.createBufferSource()") |
| 71 shouldThrow("context.createChannelSplitter()"); | 79 .throw("InvalidStateError"); |
| 72 shouldThrow("context.createConvolver()"); | 80 should(() => context.createChannelMerger(), |
| 73 shouldThrow("context.createDelay()"); | 81 "context.createChannelMerger()") |
| 74 shouldThrow("context.createDynamicsCompressor()"); | 82 .throw("InvalidStateError"); |
| 75 shouldThrow("context.createGain()"); | 83 should(() => context.createChannelSplitter(), |
| 76 shouldThrow("context.createOscillator()"); | 84 "context.createChannelSplitter()") |
| 77 shouldThrow("context.createPanner()"); | 85 .throw("InvalidStateError"); |
| 78 shouldThrow("context.createPeriodicWave(wave, wave)"); | 86 should(() => context.createConvolver(), "context.createConvolver()") |
| 79 shouldThrow("context.createScriptProcessor()"); | 87 .throw("InvalidStateError"); |
| 80 shouldThrow("context.createStereoPanner()"); | 88 should(() => context.createDelay(), "context.createDelay()") |
| 81 shouldThrow("context.createWaveShaper()"); | 89 .throw("InvalidStateError"); |
| 90 should(() => |
| 91 context.createDynamicsCompressor(), |
| 92 "context.createDynamicsCompressor()").throw("InvalidStateError"); |
| 93 should(() => context.createGain(), "context.createGain()").throw( |
| 94 "InvalidStateError"); |
| 95 should(() => context.createOscillator(), |
| 96 "context.createOscillator()") |
| 97 .throw("InvalidStateError"); |
| 98 should(() => context.createPanner(), "context.createPanner()") |
| 99 .throw("InvalidStateError"); |
| 100 should(() => context.createPeriodicWave(wave, wave), |
| 101 "context.createPeriodicWave(wave, wave)") |
| 102 .throw("InvalidStateError"); |
| 103 should(() => context.createScriptProcessor(), |
| 104 "context.createScriptProcessor()") |
| 105 .throw("InvalidStateError"); |
| 106 should(() => |
| 107 context.createStereoPanner(), "context.createStereoPanner()").throw( |
| 108 "InvalidStateError"); |
| 109 should(() => context.createWaveShaper(), |
| 110 "context.createWaveShaper()") |
| 111 .throw("InvalidStateError"); |
| 82 | 112 |
| 83 shouldThrow("osc.connect(gain)"); | 113 should(() => osc.connect(gain), "osc.connect(gain)") |
| 84 shouldNotThrow("gain.disconnect()"); | 114 .throw("InvalidStateError"); |
| 115 should(() => gain.disconnect(), "gain.disconnect()").notThrow(); |
| 85 | 116 |
| 86 // Can't resume a context that is closed (released). | 117 // Can't resume a context that is closed (released). |
| 87 context.resume().then( | 118 should(context.resume(), "context.resume()") |
| 88 function () { | 119 .beRejected() |
| 89 testFailed("Attempt to resume a closed context erroneously succeeded")
; | 120 .then(task.done.bind(task)); |
| 90 }, | |
| 91 function () { | |
| 92 testPassed("Attempt to resume a closed context was correctly rejected"
); | |
| 93 } | |
| 94 ).then(done); | |
| 95 }); | 121 }); |
| 96 | 122 |
| 97 // Task: test online context (3). | 123 // Task: test online context (3). |
| 98 audit.defineTask('test-online-context-3', function (done) { | 124 audit.define('test-online-context-3', function (task, should) { |
| 99 | 125 task.describe("Close an online context again"); |
| 100 // Try closing the context again. The promise should be rejected. | 126 // Try closing the context again. The promise should be rejected. |
| 101 context.close().then( | 127 should(context.close(), "context.close() again") |
| 102 function () { | 128 .beRejected() |
| 103 testFailed("Closing context again erroneously resolved successfully.")
; | 129 .then(() => { |
| 104 }, | 130 // Finally, run GC. The context should be gone, but this seems |
| 105 function () { | 131 // difficult to verify. |
| 106 testPassed("Closing context again correctly rejected promise."); | 132 if (window.gc) |
| 107 // Finally, run GC. The context should be gone, but this seems difficu
lt to verify. | 133 gc(); |
| 108 gc(); | 134 should(context.destination, "context.destination") |
| 109 shouldBeNull("context.destination"); | 135 .beEqualTo(null); |
| 110 } | 136 }) |
| 111 ).then(done); | 137 .then(task.done.bind(task)); |
| 112 }); | 138 }); |
| 113 | 139 |
| 114 // Task: test offline context (1). | 140 // Task: test offline context (1). |
| 115 audit.defineTask('test-offline-context-1', function (done) { | 141 audit.define('test-offline-context-1', function (task, should) { |
| 116 | 142 task.describe("Test offline context"); |
| 117 // For an offline context, verify that close is not defined. | 143 // For an offline context, verify that close is not defined. |
| 118 shouldNotThrow("offline = new OfflineAudioContext(1, 1000, 48000)"); | 144 should(() => offline = new OfflineAudioContext(1, 1000, 48000), |
| 119 shouldBeEqualToString("offline.state", "suspended"); | 145 "offline = new OfflineAudioContext(1, 1000, 48000)") |
| 120 shouldBeUndefined("offline.close"); | 146 .notThrow(); |
| 121 done(); | 147 should(offline.state, "offline.state") |
| 148 .beEqualTo("suspended"); |
| 149 should(offline.close, "offline.close") |
| 150 .beEqualTo(undefined); |
| 151 task.done(); |
| 122 }); | 152 }); |
| 123 | 153 |
| 124 audit.defineTask('finish-test', function (done) { | 154 audit.run(); |
| 125 done(); | |
| 126 finishJSTest(); | |
| 127 }); | |
| 128 | |
| 129 audit.runTasks(); | |
| 130 | |
| 131 successfullyParsed = true; | |
| 132 </script> | 155 </script> |
| 133 </body> | 156 </body> |
| 134 </html> | 157 </html> |
| OLD | NEW |