| OLD | NEW |
| (Empty) |
| 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/audit-util.js"></script> | |
| 8 <script src="resources/audio-testing.js"></script> | |
| 9 </head> | |
| 10 | |
| 11 <body> | |
| 12 <script> | |
| 13 description("Basic functionality test of closing an AudioContext"); | |
| 14 window.jsTestIsAsync = true; | |
| 15 | |
| 16 var context; | |
| 17 var destination; | |
| 18 var offline; | |
| 19 var osc; | |
| 20 var gain; | |
| 21 var promise1; | |
| 22 var promise2; | |
| 23 var offlinePromise; | |
| 24 var wave = new Float32Array(1); | |
| 25 | |
| 26 var audit = Audit.createTaskRunner(); | |
| 27 | |
| 28 // Task: test online context (1). | |
| 29 audit.defineTask('test-online-context-1', function (done) { | |
| 30 | |
| 31 // Create a context and verify that the various states are correct and | |
| 32 // that close() exists. | |
| 33 shouldNotThrow("context = new AudioContext()"); | |
| 34 shouldBeEqualToString("context.state", "running"); | |
| 35 | |
| 36 // Create gain and oscillator for testing later. | |
| 37 shouldNotThrow("osc = context.createOscillator()"); | |
| 38 shouldNotThrow("gain = context.createGain()"); | |
| 39 destination = context.destination; | |
| 40 shouldNotThrow("gain.connect(context.destination)"); | |
| 41 | |
| 42 // Close the context. When the promise is resolved, continue the next | |
| 43 // test task. | |
| 44 context.close().then( | |
| 45 function () { | |
| 46 testPassed("context.close() was correctly resolved"); | |
| 47 shouldNotThrow("gain.disconnect(destination)"); | |
| 48 }, | |
| 49 function () { | |
| 50 testFailed("context.close() was erroneously rejected"); | |
| 51 } | |
| 52 ).then(done); | |
| 53 | |
| 54 }); | |
| 55 | |
| 56 // Task: test online context (2). | |
| 57 audit.defineTask('test-online-context-2', function (done) { | |
| 58 | |
| 59 // Context is closed, so verify that we cannot create any more nodes, | |
| 60 // nor connect any. | |
| 61 shouldThrow("context.createAnalyser()"); | |
| 62 shouldThrow("context.createBiquadFilter()"); | |
| 63 | |
| 64 // createBuffer is an exception because it's not really tied in any way | |
| 65 // to an audio context. And it's useful to be able to create a buffer | |
| 66 // inside the oncomplete event of an offline context to use for testing | |
| 67 // purposes. | |
| 68 shouldNotThrow("context.createBuffer(1, 1, 48000)"); | |
| 69 | |
| 70 shouldThrow("context.createBufferSource()"); | |
| 71 shouldThrow("context.createChannelMerger()"); | |
| 72 shouldThrow("context.createChannelSplitter()"); | |
| 73 shouldThrow("context.createConvolver()"); | |
| 74 shouldThrow("context.createDelay()"); | |
| 75 shouldThrow("context.createDynamicsCompressor()"); | |
| 76 shouldThrow("context.createGain()"); | |
| 77 shouldThrow("context.createOscillator()"); | |
| 78 shouldThrow("context.createPanner()"); | |
| 79 shouldThrow("context.createPeriodicWave(wave, wave)"); | |
| 80 shouldThrow("context.createScriptProcessor()"); | |
| 81 shouldThrow("context.createStereoPanner()"); | |
| 82 shouldThrow("context.createWaveShaper()"); | |
| 83 | |
| 84 shouldThrow("osc.connect(gain)"); | |
| 85 shouldNotThrow("gain.disconnect()"); | |
| 86 | |
| 87 // Can't resume a context that is closed (released). | |
| 88 context.resume().then( | |
| 89 function () { | |
| 90 testFailed("Attempt to resume a closed context erroneously succeeded")
; | |
| 91 }, | |
| 92 function () { | |
| 93 testPassed("Attempt to resume a closed context was correctly rejected"
); | |
| 94 } | |
| 95 ).then(done); | |
| 96 }); | |
| 97 | |
| 98 // Task: test online context (3). | |
| 99 audit.defineTask('test-online-context-3', function (done) { | |
| 100 | |
| 101 // Try closing the context again. The promise should be rejected. | |
| 102 context.close().then( | |
| 103 function () { | |
| 104 testFailed("Closing context again erroneously resolved successfully.")
; | |
| 105 }, | |
| 106 function () { | |
| 107 testPassed("Closing context again correctly rejected promise."); | |
| 108 // Finally, run GC. The context should be gone, but this seems difficu
lt to verify. | |
| 109 gc(); | |
| 110 shouldBeNull("context.destination"); | |
| 111 } | |
| 112 ).then(done); | |
| 113 }); | |
| 114 | |
| 115 // Task: test offline context (1). | |
| 116 audit.defineTask('test-offline-context-1', function (done) { | |
| 117 | |
| 118 // For an offline context, verify that close is not defined. | |
| 119 shouldNotThrow("offline = new OfflineAudioContext(1, 1000, 48000)"); | |
| 120 shouldBeEqualToString("offline.state", "suspended"); | |
| 121 shouldBeUndefined("offline.close"); | |
| 122 done(); | |
| 123 }); | |
| 124 | |
| 125 audit.defineTask('finish-test', function (done) { | |
| 126 done(); | |
| 127 finishJSTest(); | |
| 128 }); | |
| 129 | |
| 130 audit.runTasks(); | |
| 131 | |
| 132 successfullyParsed = true; | |
| 133 </script> | |
| 134 </body> | |
| 135 </html> | |
| OLD | NEW |