[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] | f846f5a | 2014-03-25 17:33:11 | [diff] [blame] | 4 | <script src="resources/compatibility.js"></script> |
[email protected] | 2da6ffa | 2013-10-01 00:31:35 | [diff] [blame] | 5 | <script src="resources/audio-testing.js"></script> |
[email protected] | efb08634 | 2013-11-05 00:56:21 | [diff] [blame] | 6 | <script src="../resources/js-test.js"></script> |
[email protected] | 2da6ffa | 2013-10-01 00:31:35 | [diff] [blame] | 7 | <script src="resources/biquad-testing.js"></script> |
| 8 | </head> |
| 9 | |
| 10 | <body> |
| 11 | |
| 12 | <div id="description"></div> |
| 13 | <div id="console"></div> |
| 14 | <script> |
| 15 | description("Tests DOM exception messages"); |
| 16 | |
| 17 | var context; |
| 18 | var otherContext; |
| 19 | var node; |
| 20 | var node2; |
| 21 | var mode; |
[email protected] | 1d4178a | 2014-09-26 21:37:44 | [diff] [blame] | 22 | var panner; |
[email protected] | 7baad898 | 2014-09-29 22:11:48 | [diff] [blame] | 23 | var script; |
[email protected] | 2da6ffa | 2013-10-01 00:31:35 | [diff] [blame] | 24 | |
| 25 | function runTest() { |
| 26 | if (window.testRunner) { |
| 27 | testRunner.dumpAsText(); |
| 28 | } |
[email protected] | b702bbb | 2014-12-05 04:53:16 | [diff] [blame^] | 29 | |
[email protected] | f846f5a | 2014-03-25 17:33:11 | [diff] [blame] | 30 | context = new AudioContext(); |
| 31 | otherContext = new AudioContext(); |
[email protected] | 2da6ffa | 2013-10-01 00:31:35 | [diff] [blame] | 32 | |
[email protected] | 154cd08 | 2013-10-04 19:40:08 | [diff] [blame] | 33 | // Test creation of various objects |
[email protected] | 2da6ffa | 2013-10-01 00:31:35 | [diff] [blame] | 34 | |
[email protected] | 154cd08 | 2013-10-04 19:40:08 | [diff] [blame] | 35 | // Invalid number of channels: NotSupportedError |
[email protected] | 2da6ffa | 2013-10-01 00:31:35 | [diff] [blame] | 36 | shouldThrow("context.createBuffer(99, 1, context.sampleRate)"); |
[email protected] | ace011c | 2014-05-08 22:10:03 | [diff] [blame] | 37 | shouldThrow("context.createBuffer(0, 1, context.sampleRate)"); |
[email protected] | 154cd08 | 2013-10-04 19:40:08 | [diff] [blame] | 38 | // Invalid sample rate: NotSupportedError |
[email protected] | 2da6ffa | 2013-10-01 00:31:35 | [diff] [blame] | 39 | shouldThrow("context.createBuffer(1, 1, 1)"); |
| 40 | shouldThrow("context.createBuffer(1, 1, 1e6)"); |
[email protected] | c867899 | 2014-03-25 23:51:18 | [diff] [blame] | 41 | // Check valid values from crbug.com/344375 |
| 42 | shouldNotThrow("context.createBuffer(1, 1, 3000)"); |
| 43 | shouldNotThrow("context.createBuffer(1, 1, 192000)"); |
[email protected] | 154cd08 | 2013-10-04 19:40:08 | [diff] [blame] | 44 | // Invalid number of frames: NotSupportedError |
| 45 | shouldThrow("context.createBuffer(1, 0, context.sampleRate)"); |
[email protected] | c5f32c5a8 | 2014-04-14 18:19:12 | [diff] [blame] | 46 | // 2-arg createBuffer not allowed. |
[email protected] | 2da6ffa | 2013-10-01 00:31:35 | [diff] [blame] | 47 | shouldThrow("context.createBuffer(new ArrayBuffer(100), true)"); |
[email protected] | 154cd08 | 2013-10-04 19:40:08 | [diff] [blame] | 48 | // Invalid ArrayBuffer (unspecified error) |
[email protected] | 2da6ffa | 2013-10-01 00:31:35 | [diff] [blame] | 49 | shouldThrow("context.decodeAudioData(null, function() {}, function () {})"); |
[email protected] | 154cd08 | 2013-10-04 19:40:08 | [diff] [blame] | 50 | // Invalid sources (unspecified error) |
[email protected] | 2da6ffa | 2013-10-01 00:31:35 | [diff] [blame] | 51 | shouldThrow("context.createMediaElementSource(null)"); |
| 52 | shouldThrow("context.createMediaStreamSource(null)"); |
[email protected] | 154cd08 | 2013-10-04 19:40:08 | [diff] [blame] | 53 | // Invalid buffer size: IndexSizeError |
[email protected] | 2da6ffa | 2013-10-01 00:31:35 | [diff] [blame] | 54 | shouldThrow("context.createScriptProcessor(1, 1, 1)"); |
[email protected] | 154cd08 | 2013-10-04 19:40:08 | [diff] [blame] | 55 | // Invalid number of inputs and outputs: IndexSizeError |
[email protected] | 2da6ffa | 2013-10-01 00:31:35 | [diff] [blame] | 56 | shouldThrow("context.createScriptProcessor(4096, 100, 1)"); |
| 57 | shouldThrow("context.createScriptProcessor(4096, 1, 100)"); |
[email protected] | ad2e0e3 | 2013-10-04 05:16:20 | [diff] [blame] | 58 | shouldNotThrow("context.createScriptProcessor()"); |
| 59 | shouldNotThrow("context.createScriptProcessor(0)"); |
| 60 | |
[email protected] | 154cd08 | 2013-10-04 19:40:08 | [diff] [blame] | 61 | // Invalid number of channels: IndexSizeError |
[email protected] | 2da6ffa | 2013-10-01 00:31:35 | [diff] [blame] | 62 | shouldThrow("context.createChannelSplitter(0)"); |
| 63 | shouldThrow("context.createChannelSplitter(99)"); |
| 64 | shouldThrow("context.createChannelMerger(0)"); |
| 65 | shouldThrow("context.createChannelMerger(99)"); |
[email protected] | 154cd08 | 2013-10-04 19:40:08 | [diff] [blame] | 66 | // Invalid real/imag arrays: IndexSizeError |
[email protected] | 2da6ffa | 2013-10-01 00:31:35 | [diff] [blame] | 67 | shouldThrow("context.createPeriodicWave(null, null)"); |
| 68 | shouldThrow("context.createPeriodicWave(new Float32Array(10), null)"); |
[email protected] | 154cd08 | 2013-10-04 19:40:08 | [diff] [blame] | 69 | shouldThrow("context.createPeriodicWave(new Float32Array(4100), new Float32Array(4100))"); |
| 70 | // Real and imaginary arrays must have the same size: IndexSizeError |
[email protected] | 2da6ffa | 2013-10-01 00:31:35 | [diff] [blame] | 71 | shouldThrow("context.createPeriodicWave(new Float32Array(10), new Float32Array(7))"); |
[email protected] | b702bbb | 2014-12-05 04:53:16 | [diff] [blame^] | 72 | |
[email protected] | 2da6ffa | 2013-10-01 00:31:35 | [diff] [blame] | 73 | |
| 74 | // Analysers |
| 75 | node = context.createAnalyser(); |
[email protected] | 154cd08 | 2013-10-04 19:40:08 | [diff] [blame] | 76 | // Invalid fftSize: IndexSizeError |
[email protected] | 2da6ffa | 2013-10-01 00:31:35 | [diff] [blame] | 77 | shouldThrow("node.fftSize = 42"); |
[email protected] | 154cd08 | 2013-10-04 19:40:08 | [diff] [blame] | 78 | shouldThrow("node.fftSize = 16"); |
| 79 | shouldThrow("node.fftSize = 4096"); |
[email protected] | 2da6ffa | 2013-10-01 00:31:35 | [diff] [blame] | 80 | |
[email protected] | db30267b | 2013-10-03 18:43:26 | [diff] [blame] | 81 | shouldThrow("node.minDecibels = -10"); |
| 82 | shouldThrow("node.maxDecibels = -150"); |
[email protected] | f8f8c46 | 2014-03-31 18:24:52 | [diff] [blame] | 83 | shouldThrow("node.minDecibels = -30"); |
| 84 | shouldThrow("node.maxDecibels = -100"); |
[email protected] | db30267b | 2013-10-03 18:43:26 | [diff] [blame] | 85 | shouldThrow("node.smoothingTimeConstant = -0.1"); |
| 86 | shouldThrow("node.smoothingTimeConstant = 1.5"); |
| 87 | |
[email protected] | 2da6ffa | 2013-10-01 00:31:35 | [diff] [blame] | 88 | // AudioBuffers |
| 89 | node = context.createBuffer(1,1, context.sampleRate); |
[email protected] | 154cd08 | 2013-10-04 19:40:08 | [diff] [blame] | 90 | // Invalid channel index: IndexSizeError |
[email protected] | 2da6ffa | 2013-10-01 00:31:35 | [diff] [blame] | 91 | shouldThrow("node.getChannelData(2)"); |
| 92 | |
| 93 | // AudioNode connections |
| 94 | node = context.createGain(); |
| 95 | node2 = context.createGain(); |
[email protected] | 154cd08 | 2013-10-04 19:40:08 | [diff] [blame] | 96 | // Invalid destination node (unspecified error) |
[email protected] | 2da6ffa | 2013-10-01 00:31:35 | [diff] [blame] | 97 | shouldThrow("node.connect(null, 0, 0)"); |
[email protected] | 154cd08 | 2013-10-04 19:40:08 | [diff] [blame] | 98 | // Invalid input or output index: IndexSizeError |
[email protected] | 2da6ffa | 2013-10-01 00:31:35 | [diff] [blame] | 99 | shouldThrow("node.connect(context.destination, 100, 0)"); |
| 100 | shouldThrow("node.connect(context.destination, 0, 100)"); |
| 101 | shouldThrow("node.connect(node2.gain, 100)"); |
| 102 | shouldThrow("node.disconnect(99)"); |
[email protected] | 154cd08 | 2013-10-04 19:40:08 | [diff] [blame] | 103 | // Can't connect to a different context (unspecified error) |
[email protected] | 2da6ffa | 2013-10-01 00:31:35 | [diff] [blame] | 104 | shouldThrow("node.connect(otherContext.destination)"); |
| 105 | |
[email protected] | 154cd08 | 2013-10-04 19:40:08 | [diff] [blame] | 106 | // Invalid channel count: NotSupportedError |
[email protected] | 2da6ffa | 2013-10-01 00:31:35 | [diff] [blame] | 107 | shouldThrow("node.channelCount = 99"); |
[email protected] | 154cd08 | 2013-10-04 19:40:08 | [diff] [blame] | 108 | // Invalid mode or interpretation (unspecified error) |
[email protected] | e152e8ed | 2014-05-14 16:20:33 | [diff] [blame] | 109 | currentMode = node.channelCountMode; |
| 110 | currentInterpretation = node.channelInterpretation; |
| 111 | shouldNotThrow("node.channelCountMode = 'fancy'"); |
| 112 | if (node.channelCountMode == currentMode) |
| 113 | testPassed("Invalid channelCountMode value did not change mode"); |
| 114 | else |
[email protected] | b702bbb | 2014-12-05 04:53:16 | [diff] [blame^] | 115 | testFailed("node.channelCountMode incorrectly changed to invalid value " + node.channelCountMode); |
[email protected] | e152e8ed | 2014-05-14 16:20:33 | [diff] [blame] | 116 | shouldNotThrow("node.channelInterpretation = mode"); |
| 117 | if (node.channelInterpretation == currentInterpretation) |
| 118 | testPassed("Invalid channelInterpration value did not change mode"); |
| 119 | else |
[email protected] | b702bbb | 2014-12-05 04:53:16 | [diff] [blame^] | 120 | testFailed("node.channelInterpretation incorrectly changed to invalid value " + node.channelInterpreation); |
[email protected] | 2da6ffa | 2013-10-01 00:31:35 | [diff] [blame] | 121 | |
[email protected] | b702bbb | 2014-12-05 04:53:16 | [diff] [blame^] | 122 | // Destination node channel count: should throw IndexSizeError on invalid |
| 123 | // channel count. shouldNotThrow() method cannot be used because the error |
| 124 | // message includes the number of channels, which can change depending on |
| 125 | // the actual attached hardware. |
| 126 | try { |
| 127 | eval("context.destination.channelCount = 99"); |
| 128 | } catch (e) { |
| 129 | if (e.message === "Failed to set the 'channelCount' property on 'AudioNode': The channel count provided (99) is outside the range [1, " + context.destination.maxChannelCount + "]." && e.name === "IndexSizeError") |
| 130 | testPassed("context.destination.channelCount = 99 threw IndexSizeError exception on invalid channel count."); |
| 131 | else |
| 132 | testFailed("context.destination.channelCount = 99 should throw IndexSizeError exception on invalid channel count."); |
| 133 | } |
[email protected] | 2da6ffa | 2013-10-01 00:31:35 | [diff] [blame] | 134 | |
| 135 | // Delay nodes are tested elsewhere, so don't duplicate that work here. |
| 136 | |
| 137 | // OfflineAudioContext |
[email protected] | 84126a36 | 2014-04-14 16:55:48 | [diff] [blame] | 138 | // Max supported channels |
| 139 | shouldNotThrow("new OfflineAudioContext(32, 100, context.sampleRate)"); |
[email protected] | 154cd08 | 2013-10-04 19:40:08 | [diff] [blame] | 140 | // Invalid number of channels (unspecified error) |
[email protected] | f846f5a | 2014-03-25 17:33:11 | [diff] [blame] | 141 | shouldThrow("new OfflineAudioContext(99, 100, context.sampleRate)"); |
[email protected] | 154cd08 | 2013-10-04 19:40:08 | [diff] [blame] | 142 | // Invalid sample rate. (unspecified error) |
[email protected] | f846f5a | 2014-03-25 17:33:11 | [diff] [blame] | 143 | shouldThrow("new OfflineAudioContext(1, 100, 1)"); |
| 144 | shouldThrow("new OfflineAudioContext(1, 100, 1e6)"); |
[email protected] | a9b939e | 2014-03-12 18:34:27 | [diff] [blame] | 145 | // Invalid frame length (crbug.com/351277) |
[email protected] | f846f5a | 2014-03-25 17:33:11 | [diff] [blame] | 146 | shouldThrow("new OfflineAudioContext(1, -88200000000000, 44100)"); |
[email protected] | 2da6ffa | 2013-10-01 00:31:35 | [diff] [blame] | 147 | |
[email protected] | 4e10d03 | 2013-10-02 21:48:00 | [diff] [blame] | 148 | // WaveShaper types |
| 149 | node = context.createWaveShaper(); |
[email protected] | e152e8ed | 2014-05-14 16:20:33 | [diff] [blame] | 150 | currentOversample = node.oversample; |
| 151 | shouldNotThrow("node.oversample = '9x'"); |
| 152 | if (node.oversample == currentOversample) |
| 153 | testPassed("Invalid oversample value did not change node.oversample"); |
| 154 | else |
| 155 | testFailed("node.oversample incorrectly changed to invalid value " + node.oversample); |
[email protected] | ffd785f | 2013-10-29 17:19:58 | [diff] [blame] | 156 | |
| 157 | // Start/stop for AudioBufferSourceNodes |
| 158 | buffer = context.createBuffer(1,1, context.sampleRate); |
| 159 | shouldNotThrow("source = context.createBufferSource()"); |
[email protected] | eed4fa20 | 2013-10-31 02:13:29 | [diff] [blame] | 160 | shouldNotThrow("source.buffer = buffer"); |
[email protected] | 288a06a | 2014-09-26 03:53:55 | [diff] [blame] | 161 | shouldThrow("source.start(-1)"); |
| 162 | shouldThrow("source.start(Infinity)"); |
| 163 | shouldThrow("source.start(-Infinity)"); |
| 164 | shouldThrow("source.start(NaN)"); |
| 165 | shouldThrow("source.start(1, Infinity)"); |
| 166 | shouldThrow("source.start(1, -Infinity)"); |
| 167 | shouldThrow("source.start(1, NaN)"); |
| 168 | shouldThrow("source.start(1, -1)"); |
| 169 | shouldThrow("source.start(1, 1, Infinity)"); |
| 170 | shouldThrow("source.start(1, 1, -Infinity)"); |
| 171 | shouldThrow("source.start(1, 1, NaN)"); |
| 172 | shouldThrow("source.start(1, 1, -1)"); |
[email protected] | eed4fa20 | 2013-10-31 02:13:29 | [diff] [blame] | 173 | shouldNotThrow("source.start()"); |
[email protected] | 288a06a | 2014-09-26 03:53:55 | [diff] [blame] | 174 | shouldThrow("source.stop(-1)"); |
| 175 | shouldThrow("source.stop(Infinity)"); |
| 176 | shouldThrow("source.stop(-Infinity)"); |
| 177 | shouldThrow("source.stop(NaN)"); |
[email protected] | eed4fa20 | 2013-10-31 02:13:29 | [diff] [blame] | 178 | shouldNotThrow("source.stop()"); |
| 179 | |
[email protected] | 20b3e833 | 2013-11-01 00:14:05 | [diff] [blame] | 180 | // It's not clear from the spec, but I think it's valid to call start(). The spec is silent on |
| 181 | // what happens if we call stop() afterwards, so don't call it. |
[email protected] | eed4fa20 | 2013-10-31 02:13:29 | [diff] [blame] | 182 | shouldNotThrow("source = context.createBufferSource()"); |
[email protected] | ffd785f | 2013-10-29 17:19:58 | [diff] [blame] | 183 | shouldNotThrow("source.start()"); |
[email protected] | ffd785f | 2013-10-29 17:19:58 | [diff] [blame] | 184 | |
[email protected] | 20b3e833 | 2013-11-01 00:14:05 | [diff] [blame] | 185 | buffer = context.createBuffer(1,1, context.sampleRate); |
| 186 | shouldNotThrow("source = context.createBufferSource()"); |
| 187 | shouldNotThrow("source.buffer = buffer"); |
| 188 | shouldThrow("source.stop()"); |
| 189 | |
| 190 | buffer = context.createBuffer(1,1, context.sampleRate); |
| 191 | shouldNotThrow("source = context.createBufferSource()"); |
| 192 | shouldNotThrow("source.buffer = buffer"); |
| 193 | shouldNotThrow("source.start()"); |
| 194 | shouldThrow("source.start()"); |
| 195 | |
| 196 | buffer = context.createBuffer(1,1, context.sampleRate); |
| 197 | shouldNotThrow("source = context.createBufferSource()"); |
| 198 | shouldNotThrow("source.buffer = buffer"); |
| 199 | shouldNotThrow("source.start()"); |
| 200 | shouldNotThrow("source.stop()"); |
[email protected] | 20b3e833 | 2013-11-01 00:14:05 | [diff] [blame] | 201 | |
[email protected] | b702bbb | 2014-12-05 04:53:16 | [diff] [blame^] | 202 | |
[email protected] | ffd785f | 2013-10-29 17:19:58 | [diff] [blame] | 203 | // Start/stop for OscillatorNodes |
| 204 | shouldNotThrow("source = context.createOscillator()"); |
[email protected] | 288a06a | 2014-09-26 03:53:55 | [diff] [blame] | 205 | shouldThrow("source.start(-1)"); |
| 206 | shouldThrow("source.start(Infinity)"); |
| 207 | shouldThrow("source.start(-Infinity)"); |
| 208 | shouldThrow("source.start(NaN)"); |
[email protected] | ffd785f | 2013-10-29 17:19:58 | [diff] [blame] | 209 | shouldNotThrow("source.start()"); |
[email protected] | 288a06a | 2014-09-26 03:53:55 | [diff] [blame] | 210 | shouldThrow("source.stop(-1)"); |
| 211 | shouldThrow("source.stop(Infinity)"); |
| 212 | shouldThrow("source.stop(-Infinity)"); |
| 213 | shouldThrow("source.stop(NaN)"); |
[email protected] | ffd785f | 2013-10-29 17:19:58 | [diff] [blame] | 214 | shouldNotThrow("source.stop()"); |
[email protected] | 20b3e833 | 2013-11-01 00:14:05 | [diff] [blame] | 215 | |
| 216 | shouldNotThrow("osc = context.createOscillator()"); |
| 217 | shouldThrow("osc.stop()"); |
| 218 | shouldNotThrow("osc1 = context.createOscillator()"); |
| 219 | shouldNotThrow("osc1.start()"); |
| 220 | shouldNotThrow("osc1.stop()"); |
[email protected] | 5ab469f | 2014-02-12 05:59:26 | [diff] [blame] | 221 | |
| 222 | // exponentialRampToValue should throw on non-positive target values. |
| 223 | node = context.createGain(); |
| 224 | node.connect(context.destination); |
| 225 | shouldThrow("node.gain.exponentialRampToValueAtTime(-1, 0.1)"); |
| 226 | shouldThrow("node.gain.exponentialRampToValueAtTime(0, 0.1)"); |
[email protected] | 77459e3 | 2014-03-19 00:04:10 | [diff] [blame] | 227 | |
| 228 | // Convolver buffer rate must match context rate. Create on offline context so we |
| 229 | // specify the context rate exactly, in case the test is run on platforms with different |
| 230 | // HW sample rates. |
[email protected] | f846f5a | 2014-03-25 17:33:11 | [diff] [blame] | 231 | shouldNotThrow("oc = new OfflineAudioContext(1, 44100, 44100)"); |
[email protected] | 77459e3 | 2014-03-19 00:04:10 | [diff] [blame] | 232 | shouldNotThrow("conv = oc.createConvolver()"); |
| 233 | shouldThrow("conv.buffer = oc.createBuffer(1, 100, 22050)"); |
[email protected] | 1d4178a | 2014-09-26 21:37:44 | [diff] [blame] | 234 | |
| 235 | // PannerNode channel count and mode |
| 236 | panner = context.createPanner(); |
| 237 | // Channel count can only be set to 1 or 2. |
| 238 | shouldNotThrow("panner.channelCount = 1"); |
| 239 | shouldNotThrow("panner.channelCount = 2"); |
| 240 | shouldThrow("panner.channelCount = 0"); |
| 241 | shouldThrow("panner.channelCount = 3"); |
| 242 | // It is illegal to set the mode to 'max' |
| 243 | shouldThrow("panner.channelCountMode = 'max'"); |
| 244 | shouldNotThrow("panner.channelCountMode = 'explicit'"); |
| 245 | shouldNotThrow("panner.channelCountMode = 'clamped-max'"); |
| 246 | shouldNotThrow("panner.channelCountMode = 'junk'"); |
[email protected] | 7baad898 | 2014-09-29 22:11:48 | [diff] [blame] | 247 | |
| 248 | // Test channel count and mode for a ScriptProcessor. |
| 249 | shouldNotThrow("script = context.createScriptProcessor(256, 3)"); |
| 250 | // Make sure the channelCount and mode are set correctly. |
| 251 | shouldBeEqualToNumber("script.channelCount", 3); |
| 252 | shouldBeEqualToString("script.channelCountMode", "explicit"); |
| 253 | // Cannot change the channelCount or mode to anything else |
| 254 | shouldNotThrow("script.channelCount = 3"); |
| 255 | shouldThrow("script.channelCount = 1"); |
| 256 | shouldThrow("script.channelCount = 7"); |
| 257 | shouldNotThrow("script.channelCountMode = 'explicit'"); |
| 258 | shouldThrow("script.channelCountMode = 'max'"); |
| 259 | shouldThrow("script.channelCountMode = 'clamped-max'"); |
| 260 | shouldNotThrow("script.channelCountMode = 'junk'"); |
[email protected] | 7cc3e78 | 2014-11-10 22:37:54 | [diff] [blame] | 261 | |
| 262 | // noteOn and noteOff don't exist anymore |
| 263 | shouldBeUndefined("osc.noteOn"); |
| 264 | shouldBeUndefined("osc.noteOff"); |
| 265 | shouldBeUndefined("source.noteOn"); |
| 266 | shouldBeUndefined("source.noteOff"); |
[email protected] | 2da6ffa | 2013-10-01 00:31:35 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | runTest(); |
| 270 | successfullyParsed = true; |
| 271 | |
[email protected] | b702bbb | 2014-12-05 04:53:16 | [diff] [blame^] | 272 | </script> |
[email protected] | 2da6ffa | 2013-10-01 00:31:35 | [diff] [blame] | 273 | </body> |
| 274 | </html> |