[email protected] | 2da6ffa | 2013-10-01 00:31:35 | [diff] [blame] | 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
| 2 | <html> |
| 3 | <head> |
[email protected] | 2da6ffa | 2013-10-01 00:31:35 | [diff] [blame] | 4 | <script src="resources/audio-testing.js"></script> |
[email protected] | efb08634 | 2013-11-05 00:56:21 | [diff] [blame] | 5 | <script src="../resources/js-test.js"></script> |
[email protected] | 2da6ffa | 2013-10-01 00:31:35 | [diff] [blame] | 6 | <script src="resources/biquad-testing.js"></script> |
| 7 | </head> |
| 8 | |
| 9 | <body> |
| 10 | |
| 11 | <div id="description"></div> |
| 12 | <div id="console"></div> |
| 13 | <script> |
| 14 | description("Tests DOM exception messages"); |
| 15 | |
| 16 | var context; |
| 17 | var otherContext; |
| 18 | var node; |
| 19 | var node2; |
| 20 | var mode; |
| 21 | |
| 22 | function runTest() { |
| 23 | if (window.testRunner) { |
| 24 | testRunner.dumpAsText(); |
| 25 | } |
| 26 | |
| 27 | context = new webkitAudioContext(); |
| 28 | otherContext = new webkitAudioContext(); |
| 29 | |
[email protected] | 154cd08 | 2013-10-04 19:40:08 | [diff] [blame] | 30 | // Test creation of various objects |
[email protected] | 2da6ffa | 2013-10-01 00:31:35 | [diff] [blame] | 31 | |
[email protected] | 154cd08 | 2013-10-04 19:40:08 | [diff] [blame] | 32 | // Invalid number of channels: NotSupportedError |
[email protected] | 2da6ffa | 2013-10-01 00:31:35 | [diff] [blame] | 33 | shouldThrow("context.createBuffer(99, 1, context.sampleRate)"); |
[email protected] | 154cd08 | 2013-10-04 19:40:08 | [diff] [blame] | 34 | // Invalid sample rate: NotSupportedError |
[email protected] | 2da6ffa | 2013-10-01 00:31:35 | [diff] [blame] | 35 | shouldThrow("context.createBuffer(1, 1, 1)"); |
| 36 | shouldThrow("context.createBuffer(1, 1, 1e6)"); |
[email protected] | 154cd08 | 2013-10-04 19:40:08 | [diff] [blame] | 37 | // Invalid number of frames: NotSupportedError |
| 38 | shouldThrow("context.createBuffer(1, 0, context.sampleRate)"); |
| 39 | // Invalid ArrayBuffer (unspecified error) |
[email protected] | 2da6ffa | 2013-10-01 00:31:35 | [diff] [blame] | 40 | shouldThrow("context.createBuffer(new ArrayBuffer(100), true)"); |
[email protected] | 154cd08 | 2013-10-04 19:40:08 | [diff] [blame] | 41 | // Invalid ArrayBuffer (unspecified error) |
[email protected] | 2da6ffa | 2013-10-01 00:31:35 | [diff] [blame] | 42 | shouldThrow("context.decodeAudioData(null, function() {}, function () {})"); |
[email protected] | 154cd08 | 2013-10-04 19:40:08 | [diff] [blame] | 43 | // Invalid sources (unspecified error) |
[email protected] | 2da6ffa | 2013-10-01 00:31:35 | [diff] [blame] | 44 | shouldThrow("context.createMediaElementSource(null)"); |
| 45 | shouldThrow("context.createMediaStreamSource(null)"); |
[email protected] | 154cd08 | 2013-10-04 19:40:08 | [diff] [blame] | 46 | // Invalid buffer size: IndexSizeError |
[email protected] | 2da6ffa | 2013-10-01 00:31:35 | [diff] [blame] | 47 | shouldThrow("context.createScriptProcessor(1, 1, 1)"); |
[email protected] | 154cd08 | 2013-10-04 19:40:08 | [diff] [blame] | 48 | // Invalid number of inputs and outputs: IndexSizeError |
[email protected] | 2da6ffa | 2013-10-01 00:31:35 | [diff] [blame] | 49 | shouldThrow("context.createScriptProcessor(4096, 100, 1)"); |
| 50 | shouldThrow("context.createScriptProcessor(4096, 1, 100)"); |
[email protected] | ad2e0e3 | 2013-10-04 05:16:20 | [diff] [blame] | 51 | shouldNotThrow("context.createScriptProcessor()"); |
| 52 | shouldNotThrow("context.createScriptProcessor(0)"); |
| 53 | |
[email protected] | 154cd08 | 2013-10-04 19:40:08 | [diff] [blame] | 54 | // Invalid number of channels: IndexSizeError |
[email protected] | 2da6ffa | 2013-10-01 00:31:35 | [diff] [blame] | 55 | shouldThrow("context.createChannelSplitter(0)"); |
| 56 | shouldThrow("context.createChannelSplitter(99)"); |
| 57 | shouldThrow("context.createChannelMerger(0)"); |
| 58 | shouldThrow("context.createChannelMerger(99)"); |
[email protected] | 154cd08 | 2013-10-04 19:40:08 | [diff] [blame] | 59 | // Invalid real/imag arrays: IndexSizeError |
[email protected] | 2da6ffa | 2013-10-01 00:31:35 | [diff] [blame] | 60 | shouldThrow("context.createPeriodicWave(null, null)"); |
| 61 | shouldThrow("context.createPeriodicWave(new Float32Array(10), null)"); |
[email protected] | 154cd08 | 2013-10-04 19:40:08 | [diff] [blame] | 62 | shouldThrow("context.createPeriodicWave(new Float32Array(4100), new Float32Array(4100))"); |
| 63 | // Real and imaginary arrays must have the same size: IndexSizeError |
[email protected] | 2da6ffa | 2013-10-01 00:31:35 | [diff] [blame] | 64 | shouldThrow("context.createPeriodicWave(new Float32Array(10), new Float32Array(7))"); |
[email protected] | 154cd08 | 2013-10-04 19:40:08 | [diff] [blame] | 65 | |
[email protected] | 2da6ffa | 2013-10-01 00:31:35 | [diff] [blame] | 66 | |
| 67 | // Analysers |
| 68 | node = context.createAnalyser(); |
[email protected] | 154cd08 | 2013-10-04 19:40:08 | [diff] [blame] | 69 | // Invalid fftSize: IndexSizeError |
[email protected] | 2da6ffa | 2013-10-01 00:31:35 | [diff] [blame] | 70 | shouldThrow("node.fftSize = 42"); |
[email protected] | 154cd08 | 2013-10-04 19:40:08 | [diff] [blame] | 71 | shouldThrow("node.fftSize = 16"); |
| 72 | shouldThrow("node.fftSize = 4096"); |
[email protected] | 2da6ffa | 2013-10-01 00:31:35 | [diff] [blame] | 73 | |
[email protected] | db30267b | 2013-10-03 18:43:26 | [diff] [blame] | 74 | shouldThrow("node.minDecibels = -10"); |
| 75 | shouldThrow("node.maxDecibels = -150"); |
| 76 | shouldThrow("node.smoothingTimeConstant = -0.1"); |
| 77 | shouldThrow("node.smoothingTimeConstant = 1.5"); |
| 78 | |
[email protected] | 2da6ffa | 2013-10-01 00:31:35 | [diff] [blame] | 79 | // AudioBuffers |
| 80 | node = context.createBuffer(1,1, context.sampleRate); |
[email protected] | 154cd08 | 2013-10-04 19:40:08 | [diff] [blame] | 81 | // Invalid channel index: IndexSizeError |
[email protected] | 2da6ffa | 2013-10-01 00:31:35 | [diff] [blame] | 82 | shouldThrow("node.getChannelData(2)"); |
| 83 | |
| 84 | // AudioNode connections |
| 85 | node = context.createGain(); |
| 86 | node2 = context.createGain(); |
[email protected] | 154cd08 | 2013-10-04 19:40:08 | [diff] [blame] | 87 | // Invalid destination node (unspecified error) |
[email protected] | 2da6ffa | 2013-10-01 00:31:35 | [diff] [blame] | 88 | shouldThrow("node.connect(null, 0, 0)"); |
[email protected] | 154cd08 | 2013-10-04 19:40:08 | [diff] [blame] | 89 | // Invalid input or output index: IndexSizeError |
[email protected] | 2da6ffa | 2013-10-01 00:31:35 | [diff] [blame] | 90 | shouldThrow("node.connect(context.destination, 100, 0)"); |
| 91 | shouldThrow("node.connect(context.destination, 0, 100)"); |
| 92 | shouldThrow("node.connect(node2.gain, 100)"); |
| 93 | shouldThrow("node.disconnect(99)"); |
[email protected] | 154cd08 | 2013-10-04 19:40:08 | [diff] [blame] | 94 | // Can't connect to a different context (unspecified error) |
[email protected] | 2da6ffa | 2013-10-01 00:31:35 | [diff] [blame] | 95 | shouldThrow("node.connect(otherContext.destination)"); |
| 96 | |
[email protected] | 154cd08 | 2013-10-04 19:40:08 | [diff] [blame] | 97 | // Invalid channel count: NotSupportedError |
[email protected] | 2da6ffa | 2013-10-01 00:31:35 | [diff] [blame] | 98 | shouldThrow("node.channelCount = 99"); |
[email protected] | 154cd08 | 2013-10-04 19:40:08 | [diff] [blame] | 99 | // Invalid mode or interpretation (unspecified error) |
[email protected] | 2da6ffa | 2013-10-01 00:31:35 | [diff] [blame] | 100 | mode = "fancy"; |
| 101 | shouldThrow("node.channelCountMode = mode"); |
| 102 | shouldThrow("node.channelInterpretation = mode"); |
| 103 | |
[email protected] | 154cd08 | 2013-10-04 19:40:08 | [diff] [blame] | 104 | // Destination: IndexSizeError |
[email protected] | 2da6ffa | 2013-10-01 00:31:35 | [diff] [blame] | 105 | shouldThrow("context.destination.channelCount = 99"); |
| 106 | |
| 107 | // Delay nodes are tested elsewhere, so don't duplicate that work here. |
| 108 | |
| 109 | // OfflineAudioContext |
[email protected] | 154cd08 | 2013-10-04 19:40:08 | [diff] [blame] | 110 | // Invalid number of channels (unspecified error) |
[email protected] | 2da6ffa | 2013-10-01 00:31:35 | [diff] [blame] | 111 | shouldThrow("new webkitOfflineAudioContext(99, 100, context.sampleRate)"); |
[email protected] | 154cd08 | 2013-10-04 19:40:08 | [diff] [blame] | 112 | // Invalid sample rate. (unspecified error) |
[email protected] | 2da6ffa | 2013-10-01 00:31:35 | [diff] [blame] | 113 | shouldThrow("new webkitOfflineAudioContext(1, 100, 1)"); |
| 114 | shouldThrow("new webkitOfflineAudioContext(1, 100, 1e6)"); |
| 115 | |
[email protected] | 4e10d03 | 2013-10-02 21:48:00 | [diff] [blame] | 116 | // WaveShaper types |
| 117 | node = context.createWaveShaper(); |
| 118 | shouldThrow("node.oversample = '9x'"); |
[email protected] | ffd785f | 2013-10-29 17:19:58 | [diff] [blame] | 119 | |
| 120 | // Start/stop for AudioBufferSourceNodes |
| 121 | buffer = context.createBuffer(1,1, context.sampleRate); |
| 122 | shouldNotThrow("source = context.createBufferSource()"); |
[email protected] | eed4fa20 | 2013-10-31 02:13:29 | [diff] [blame] | 123 | shouldNotThrow("source.buffer = buffer"); |
| 124 | shouldNotThrow("source.start()"); |
| 125 | shouldNotThrow("source.stop()"); |
| 126 | |
[email protected] | 20b3e833 | 2013-11-01 00:14:05 | [diff] [blame] | 127 | // It's not clear from the spec, but I think it's valid to call start(). The spec is silent on |
| 128 | // what happens if we call stop() afterwards, so don't call it. |
[email protected] | eed4fa20 | 2013-10-31 02:13:29 | [diff] [blame] | 129 | shouldNotThrow("source = context.createBufferSource()"); |
[email protected] | ffd785f | 2013-10-29 17:19:58 | [diff] [blame] | 130 | shouldNotThrow("source.start()"); |
[email protected] | ffd785f | 2013-10-29 17:19:58 | [diff] [blame] | 131 | |
[email protected] | 20b3e833 | 2013-11-01 00:14:05 | [diff] [blame] | 132 | buffer = context.createBuffer(1,1, context.sampleRate); |
| 133 | shouldNotThrow("source = context.createBufferSource()"); |
| 134 | shouldNotThrow("source.buffer = buffer"); |
| 135 | shouldThrow("source.stop()"); |
| 136 | |
| 137 | buffer = context.createBuffer(1,1, context.sampleRate); |
| 138 | shouldNotThrow("source = context.createBufferSource()"); |
| 139 | shouldNotThrow("source.buffer = buffer"); |
| 140 | shouldNotThrow("source.start()"); |
| 141 | shouldThrow("source.start()"); |
| 142 | |
| 143 | buffer = context.createBuffer(1,1, context.sampleRate); |
| 144 | shouldNotThrow("source = context.createBufferSource()"); |
| 145 | shouldNotThrow("source.buffer = buffer"); |
| 146 | shouldNotThrow("source.start()"); |
| 147 | shouldNotThrow("source.stop()"); |
[email protected] | 20b3e833 | 2013-11-01 00:14:05 | [diff] [blame] | 148 | |
| 149 | |
[email protected] | ffd785f | 2013-10-29 17:19:58 | [diff] [blame] | 150 | // Start/stop for OscillatorNodes |
| 151 | shouldNotThrow("source = context.createOscillator()"); |
| 152 | shouldNotThrow("source.start()"); |
| 153 | shouldNotThrow("source.stop()"); |
[email protected] | 20b3e833 | 2013-11-01 00:14:05 | [diff] [blame] | 154 | |
| 155 | shouldNotThrow("osc = context.createOscillator()"); |
| 156 | shouldThrow("osc.stop()"); |
| 157 | shouldNotThrow("osc1 = context.createOscillator()"); |
| 158 | shouldNotThrow("osc1.start()"); |
| 159 | shouldNotThrow("osc1.stop()"); |
[email protected] | 5ab469f | 2014-02-12 05:59:26 | [diff] [blame^] | 160 | |
| 161 | // exponentialRampToValue should throw on non-positive target values. |
| 162 | node = context.createGain(); |
| 163 | node.connect(context.destination); |
| 164 | shouldThrow("node.gain.exponentialRampToValueAtTime(-1, 0.1)"); |
| 165 | shouldThrow("node.gain.exponentialRampToValueAtTime(0, 0.1)"); |
[email protected] | 2da6ffa | 2013-10-01 00:31:35 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | runTest(); |
| 169 | successfullyParsed = true; |
| 170 | |
| 171 | </script> |
[email protected] | 2da6ffa | 2013-10-01 00:31:35 | [diff] [blame] | 172 | </body> |
| 173 | </html> |