blob: a8e5a9735c2cbb73752aaf2b9e142bef9d383d97 [file] [log] [blame]
[email protected]2da6ffa2013-10-01 00:31:351<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2<html>
3<head>
hongchanf9085842016-08-05 00:33:174<script src="../resources/js-test.js"></script>
[email protected]f846f5a2014-03-25 17:33:115<script src="resources/compatibility.js"></script>
[email protected]2da6ffa2013-10-01 00:31:356<script src="resources/audio-testing.js"></script>
[email protected]2da6ffa2013-10-01 00:31:357<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>
15description("Tests DOM exception messages");
16
17var context;
18var otherContext;
19var node;
20var node2;
21var mode;
[email protected]1d4178a2014-09-26 21:37:4422var panner;
[email protected]7baad8982014-09-29 22:11:4823var script;
[email protected]2da6ffa2013-10-01 00:31:3524
[email protected]c026bfd22015-01-16 00:24:2625function shouldThrowAndBeUnchanged(attr, value) {
26 shouldThrow(attr + " = " + value);
27 shouldNotBe(attr, value);
28}
29
[email protected]2da6ffa2013-10-01 00:31:3530function runTest() {
31 if (window.testRunner) {
32 testRunner.dumpAsText();
33 }
[email protected]b702bbb2014-12-05 04:53:1634
[email protected]f846f5a2014-03-25 17:33:1135 context = new AudioContext();
36 otherContext = new AudioContext();
[email protected]2da6ffa2013-10-01 00:31:3537
[email protected]154cd082013-10-04 19:40:0838 // Test creation of various objects
[email protected]2da6ffa2013-10-01 00:31:3539
[email protected]154cd082013-10-04 19:40:0840 // Invalid number of channels: NotSupportedError
[email protected]2da6ffa2013-10-01 00:31:3541 shouldThrow("context.createBuffer(99, 1, context.sampleRate)");
[email protected]ace011c2014-05-08 22:10:0342 shouldThrow("context.createBuffer(0, 1, context.sampleRate)");
[email protected]154cd082013-10-04 19:40:0843 // Invalid sample rate: NotSupportedError
[email protected]2da6ffa2013-10-01 00:31:3544 shouldThrow("context.createBuffer(1, 1, 1)");
45 shouldThrow("context.createBuffer(1, 1, 1e6)");
[email protected]c8678992014-03-25 23:51:1846 // Check valid values from crbug.com/344375
47 shouldNotThrow("context.createBuffer(1, 1, 3000)");
48 shouldNotThrow("context.createBuffer(1, 1, 192000)");
[email protected]154cd082013-10-04 19:40:0849 // Invalid number of frames: NotSupportedError
50 shouldThrow("context.createBuffer(1, 0, context.sampleRate)");
[email protected]c5f32c5a82014-04-14 18:19:1251 // 2-arg createBuffer not allowed.
[email protected]2da6ffa2013-10-01 00:31:3552 shouldThrow("context.createBuffer(new ArrayBuffer(100), true)");
[email protected]154cd082013-10-04 19:40:0853 // Invalid sources (unspecified error)
[email protected]2da6ffa2013-10-01 00:31:3554 shouldThrow("context.createMediaElementSource(null)");
55 shouldThrow("context.createMediaStreamSource(null)");
[email protected]154cd082013-10-04 19:40:0856 // Invalid buffer size: IndexSizeError
[email protected]2da6ffa2013-10-01 00:31:3557 shouldThrow("context.createScriptProcessor(1, 1, 1)");
[email protected]154cd082013-10-04 19:40:0858 // Invalid number of inputs and outputs: IndexSizeError
[email protected]2da6ffa2013-10-01 00:31:3559 shouldThrow("context.createScriptProcessor(4096, 100, 1)");
60 shouldThrow("context.createScriptProcessor(4096, 1, 100)");
[email protected]ad2e0e32013-10-04 05:16:2061 shouldNotThrow("context.createScriptProcessor()");
62 shouldNotThrow("context.createScriptProcessor(0)");
63
[email protected]154cd082013-10-04 19:40:0864 // Invalid number of channels: IndexSizeError
[email protected]2da6ffa2013-10-01 00:31:3565 shouldThrow("context.createChannelSplitter(0)");
66 shouldThrow("context.createChannelSplitter(99)");
67 shouldThrow("context.createChannelMerger(0)");
68 shouldThrow("context.createChannelMerger(99)");
[email protected]154cd082013-10-04 19:40:0869 // Invalid real/imag arrays: IndexSizeError
[email protected]2da6ffa2013-10-01 00:31:3570 shouldThrow("context.createPeriodicWave(null, null)");
71 shouldThrow("context.createPeriodicWave(new Float32Array(10), null)");
[email protected]6843aa42015-07-23 19:34:5072 // Verify that we can use large arrays with no limit. Roughly.
73 shouldNotThrow("context.createPeriodicWave(new Float32Array(4100), new Float32Array(4100))");
74 shouldNotThrow("context.createPeriodicWave(new Float32Array(8192), new Float32Array(8192))");
75 shouldNotThrow("context.createPeriodicWave(new Float32Array(10000), new Float32Array(10000))");
[email protected]154cd082013-10-04 19:40:0876 // Real and imaginary arrays must have the same size: IndexSizeError
[email protected]2da6ffa2013-10-01 00:31:3577 shouldThrow("context.createPeriodicWave(new Float32Array(10), new Float32Array(7))");
[email protected]b702bbb2014-12-05 04:53:1678
[email protected]2da6ffa2013-10-01 00:31:3579
80 // Analysers
81 node = context.createAnalyser();
[email protected]154cd082013-10-04 19:40:0882 // Invalid fftSize: IndexSizeError
[email protected]c026bfd22015-01-16 00:24:2683 shouldThrowAndBeUnchanged("node.fftSize", "42");
84 shouldThrowAndBeUnchanged("node.fftSize", "16");
[email protected]9a535ba2015-01-13 20:56:1985 shouldNotThrow("node.fftSize = 32768");
[email protected]c026bfd22015-01-16 00:24:2686 shouldThrowAndBeUnchanged("node.fftSize", "65536");
[email protected]2da6ffa2013-10-01 00:31:3587
[email protected]c026bfd22015-01-16 00:24:2688 shouldThrowAndBeUnchanged("node.minDecibels", "-10");
89 shouldThrowAndBeUnchanged("node.maxDecibels", "-150");
90 shouldThrowAndBeUnchanged("node.minDecibels", "-30");
91 shouldThrowAndBeUnchanged("node.maxDecibels", "-100");
92
93 shouldThrowAndBeUnchanged("node.smoothingTimeConstant", "-0.1");
94 shouldThrowAndBeUnchanged("node.smoothingTimeConstant", "1.5");
[email protected]db30267b2013-10-03 18:43:2695
philipjeb440262015-12-04 21:20:3996 shouldThrow("node.getFloatFrequencyData(null)");
97 shouldThrow("node.getByteFrequencyData(null)");
98 shouldThrow("node.getFloatTimeDomainData(null)");
99 shouldThrow("node.getByteTimeDomainData(null)");
100
[email protected]2da6ffa2013-10-01 00:31:35101 // AudioBuffers
102 node = context.createBuffer(1,1, context.sampleRate);
[email protected]154cd082013-10-04 19:40:08103 // Invalid channel index: IndexSizeError
[email protected]2da6ffa2013-10-01 00:31:35104 shouldThrow("node.getChannelData(2)");
105
106 // AudioNode connections
107 node = context.createGain();
108 node2 = context.createGain();
[email protected]154cd082013-10-04 19:40:08109 // Invalid destination node (unspecified error)
[email protected]2da6ffa2013-10-01 00:31:35110 shouldThrow("node.connect(null, 0, 0)");
[email protected]154cd082013-10-04 19:40:08111 // Invalid input or output index: IndexSizeError
[email protected]2da6ffa2013-10-01 00:31:35112 shouldThrow("node.connect(context.destination, 100, 0)");
113 shouldThrow("node.connect(context.destination, 0, 100)");
114 shouldThrow("node.connect(node2.gain, 100)");
115 shouldThrow("node.disconnect(99)");
[email protected]154cd082013-10-04 19:40:08116 // Can't connect to a different context (unspecified error)
[email protected]2da6ffa2013-10-01 00:31:35117 shouldThrow("node.connect(otherContext.destination)");
118
[email protected]154cd082013-10-04 19:40:08119 // Invalid channel count: NotSupportedError
[email protected]c026bfd22015-01-16 00:24:26120 shouldThrowAndBeUnchanged("node.channelCount", "99");
[email protected]154cd082013-10-04 19:40:08121 // Invalid mode or interpretation (unspecified error)
[email protected]e152e8ed2014-05-14 16:20:33122 currentMode = node.channelCountMode;
123 currentInterpretation = node.channelInterpretation;
124 shouldNotThrow("node.channelCountMode = 'fancy'");
125 if (node.channelCountMode == currentMode)
126 testPassed("Invalid channelCountMode value did not change mode");
127 else
[email protected]b702bbb2014-12-05 04:53:16128 testFailed("node.channelCountMode incorrectly changed to invalid value " + node.channelCountMode);
[email protected]e152e8ed2014-05-14 16:20:33129 shouldNotThrow("node.channelInterpretation = mode");
130 if (node.channelInterpretation == currentInterpretation)
131 testPassed("Invalid channelInterpration value did not change mode");
132 else
[email protected]b702bbb2014-12-05 04:53:16133 testFailed("node.channelInterpretation incorrectly changed to invalid value " + node.channelInterpreation);
[email protected]2da6ffa2013-10-01 00:31:35134
[email protected]b702bbb2014-12-05 04:53:16135 // Destination node channel count: should throw IndexSizeError on invalid
136 // channel count. shouldNotThrow() method cannot be used because the error
137 // message includes the number of channels, which can change depending on
138 // the actual attached hardware.
139 try {
140 eval("context.destination.channelCount = 99");
141 } catch (e) {
142 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")
143 testPassed("context.destination.channelCount = 99 threw IndexSizeError exception on invalid channel count.");
144 else
145 testFailed("context.destination.channelCount = 99 should throw IndexSizeError exception on invalid channel count.");
146 }
[email protected]2da6ffa2013-10-01 00:31:35147
philipjeb440262015-12-04 21:20:39148 // AudioParams
149 param = context.createGain().gain;
150 shouldThrow("param.setValueCurveAtTime(null, 0, 0)");
151
152 // BiquadFilterNode
153 node = context.createBiquadFilter();
154 shouldNotThrow("node.getFrequencyResponse(new Float32Array(1), new Float32Array(1), new Float32Array(1))");
155 shouldThrow("node.getFrequencyResponse(null, new Float32Array(1), new Float32Array(1))");
156 shouldThrow("node.getFrequencyResponse(new Float32Array(1), null, new Float32Array(1))");
157 shouldThrow("node.getFrequencyResponse(new Float32Array(1), new Float32Array(1), null)");
158
[email protected]2da6ffa2013-10-01 00:31:35159 // Delay nodes are tested elsewhere, so don't duplicate that work here.
160
161 // OfflineAudioContext
[email protected]84126a362014-04-14 16:55:48162 // Max supported channels
163 shouldNotThrow("new OfflineAudioContext(32, 100, context.sampleRate)");
[email protected]154cd082013-10-04 19:40:08164 // Invalid number of channels (unspecified error)
[email protected]f846f5a2014-03-25 17:33:11165 shouldThrow("new OfflineAudioContext(99, 100, context.sampleRate)");
[email protected]154cd082013-10-04 19:40:08166 // Invalid sample rate. (unspecified error)
[email protected]f846f5a2014-03-25 17:33:11167 shouldThrow("new OfflineAudioContext(1, 100, 1)");
168 shouldThrow("new OfflineAudioContext(1, 100, 1e6)");
[email protected]a9b939e2014-03-12 18:34:27169 // Invalid frame length (crbug.com/351277)
[email protected]f846f5a2014-03-25 17:33:11170 shouldThrow("new OfflineAudioContext(1, -88200000000000, 44100)");
[email protected]2da6ffa2013-10-01 00:31:35171
[email protected]4e10d032013-10-02 21:48:00172 // WaveShaper types
173 node = context.createWaveShaper();
[email protected]e152e8ed2014-05-14 16:20:33174 currentOversample = node.oversample;
175 shouldNotThrow("node.oversample = '9x'");
176 if (node.oversample == currentOversample)
177 testPassed("Invalid oversample value did not change node.oversample");
178 else
179 testFailed("node.oversample incorrectly changed to invalid value " + node.oversample);
philipjeb440262015-12-04 21:20:39180 shouldThrow("node.curve = {}");
[email protected]837dc8c2015-01-13 18:00:30181 shouldThrow("node.curve = new Float32Array(1)");
[email protected]c026bfd22015-01-16 00:24:26182 shouldBeNull("node.curve");
[email protected]837dc8c2015-01-13 18:00:30183 shouldNotThrow("node.curve = new Float32Array(2)");
[email protected]6eec933d2015-01-21 20:55:00184 shouldNotThrow("node.curve = null");
[email protected]ffd785f2013-10-29 17:19:58185
186 // Start/stop for AudioBufferSourceNodes
187 buffer = context.createBuffer(1,1, context.sampleRate);
188 shouldNotThrow("source = context.createBufferSource()");
[email protected]eed4fa202013-10-31 02:13:29189 shouldNotThrow("source.buffer = buffer");
[email protected]f6101492015-05-05 17:18:47190 shouldThrow("source.buffer = context.createBuffer(1, 10, context.sampleRate)");
[email protected]288a06a2014-09-26 03:53:55191 shouldThrow("source.start(-1)");
192 shouldThrow("source.start(Infinity)");
193 shouldThrow("source.start(-Infinity)");
194 shouldThrow("source.start(NaN)");
195 shouldThrow("source.start(1, Infinity)");
196 shouldThrow("source.start(1, -Infinity)");
197 shouldThrow("source.start(1, NaN)");
198 shouldThrow("source.start(1, -1)");
[email protected]8e4304c2015-04-28 18:20:21199 shouldThrow("source.start(1, -Number.MIN_VALUE)");
[email protected]288a06a2014-09-26 03:53:55200 shouldThrow("source.start(1, 1, Infinity)");
201 shouldThrow("source.start(1, 1, -Infinity)");
202 shouldThrow("source.start(1, 1, NaN)");
203 shouldThrow("source.start(1, 1, -1)");
[email protected]8e4304c2015-04-28 18:20:21204 shouldThrow("source.start(1, 1, -Number.MIN_VALUE)");
[email protected]eed4fa202013-10-31 02:13:29205 shouldNotThrow("source.start()");
[email protected]8e4304c2015-04-28 18:20:21206 shouldThrow("source.stop(-Number.MIN_VALUE)");
[email protected]288a06a2014-09-26 03:53:55207 shouldThrow("source.stop(Infinity)");
208 shouldThrow("source.stop(-Infinity)");
209 shouldThrow("source.stop(NaN)");
[email protected]eed4fa202013-10-31 02:13:29210 shouldNotThrow("source.stop()");
211
[email protected]8e4304c2015-04-28 18:20:21212 // Verify that start(0, 0) doesn't signal.
213 shouldNotThrow("source = context.createBufferSource()");
214 shouldNotThrow("source.buffer = buffer");
215 shouldNotThrow("source.start(0, 0)");
216
217 // Verify that start(0, -0.0) doesn't signal.
218 shouldNotThrow("source = context.createBufferSource()");
219 shouldNotThrow("source.buffer = buffer");
220 shouldNotThrow("source.start(0, -1/Infinity)");
221
[email protected]20b3e8332013-11-01 00:14:05222 // It's not clear from the spec, but I think it's valid to call start(). The spec is silent on
223 // what happens if we call stop() afterwards, so don't call it.
[email protected]eed4fa202013-10-31 02:13:29224 shouldNotThrow("source = context.createBufferSource()");
[email protected]ffd785f2013-10-29 17:19:58225 shouldNotThrow("source.start()");
[email protected]ffd785f2013-10-29 17:19:58226
[email protected]20b3e8332013-11-01 00:14:05227 buffer = context.createBuffer(1,1, context.sampleRate);
228 shouldNotThrow("source = context.createBufferSource()");
229 shouldNotThrow("source.buffer = buffer");
230 shouldThrow("source.stop()");
231
232 buffer = context.createBuffer(1,1, context.sampleRate);
233 shouldNotThrow("source = context.createBufferSource()");
234 shouldNotThrow("source.buffer = buffer");
235 shouldNotThrow("source.start()");
236 shouldThrow("source.start()");
237
238 buffer = context.createBuffer(1,1, context.sampleRate);
239 shouldNotThrow("source = context.createBufferSource()");
240 shouldNotThrow("source.buffer = buffer");
241 shouldNotThrow("source.start()");
242 shouldNotThrow("source.stop()");
[email protected]20b3e8332013-11-01 00:14:05243
[email protected]b702bbb2014-12-05 04:53:16244
[email protected]ffd785f2013-10-29 17:19:58245 // Start/stop for OscillatorNodes
246 shouldNotThrow("source = context.createOscillator()");
[email protected]8e4304c2015-04-28 18:20:21247 shouldThrow("source.start(-Number.MIN_VALUE)");
[email protected]288a06a2014-09-26 03:53:55248 shouldThrow("source.start(Infinity)");
249 shouldThrow("source.start(-Infinity)");
250 shouldThrow("source.start(NaN)");
[email protected]ffd785f2013-10-29 17:19:58251 shouldNotThrow("source.start()");
[email protected]8e4304c2015-04-28 18:20:21252 shouldThrow("source.stop(-Number.MIN_VALUE)");
[email protected]288a06a2014-09-26 03:53:55253 shouldThrow("source.stop(Infinity)");
254 shouldThrow("source.stop(-Infinity)");
255 shouldThrow("source.stop(NaN)");
[email protected]ffd785f2013-10-29 17:19:58256 shouldNotThrow("source.stop()");
[email protected]20b3e8332013-11-01 00:14:05257
258 shouldNotThrow("osc = context.createOscillator()");
259 shouldThrow("osc.stop()");
260 shouldNotThrow("osc1 = context.createOscillator()");
261 shouldNotThrow("osc1.start()");
262 shouldNotThrow("osc1.stop()");
[email protected]5ab469f2014-02-12 05:59:26263
philipjeb440262015-12-04 21:20:39264 shouldThrow("osc.setPeriodicWave(null)");
265
rtoya4ce5a82015-12-15 15:45:12266 // exponentialRampToValue should throw only for "zero" target values.
[email protected]5ab469f2014-02-12 05:59:26267 node = context.createGain();
268 node.connect(context.destination);
rtoya4ce5a82015-12-15 15:45:12269 shouldNotThrow("node.gain.exponentialRampToValueAtTime(-1, 0.1)");
[email protected]5ab469f2014-02-12 05:59:26270 shouldThrow("node.gain.exponentialRampToValueAtTime(0, 0.1)");
rtoya4ce5a82015-12-15 15:45:12271 // 1e-100 is 0 when converted to a single precision float.
272 shouldThrow("node.gain.exponentialRampToValueAtTime(1e-100, 0.1)");
[email protected]14fab3df12015-02-19 21:03:46273 // See crbug.com/459391.
274 // Math.pow(2, -149) = 1.401298464324817e-45 is the double-float value of the
275 // least positive single float number. We do it this way to make sure no round-off or conversion
276 // errors happen when reading 1.401298464324817e-45.
277 shouldNotThrow("node.gain.exponentialRampToValueAtTime(Math.pow(2, -149), 0.1)");
278 // Math.pow(2, -150) = 7.006492321624085d-46 is the largest double float value such that
279 // conversion to a float produces 0. Any larger value would produce a non-zero value when
280 // converted to a single float.
281 shouldThrow("node.gain.exponentialRampToValueAtTime(Math.pow(2, -150), 0.1)");
[email protected]77459e32014-03-19 00:04:10282
283 // Convolver buffer rate must match context rate. Create on offline context so we
284 // specify the context rate exactly, in case the test is run on platforms with different
285 // HW sample rates.
[email protected]f846f5a2014-03-25 17:33:11286 shouldNotThrow("oc = new OfflineAudioContext(1, 44100, 44100)");
[email protected]77459e32014-03-19 00:04:10287 shouldNotThrow("conv = oc.createConvolver()");
philipjeb440262015-12-04 21:20:39288 shouldThrow("conv.buffer = {}");
[email protected]77459e32014-03-19 00:04:10289 shouldThrow("conv.buffer = oc.createBuffer(1, 100, 22050)");
[email protected]300c8f412015-04-08 23:04:55290 // conv.buffer should be unchanged (null) because the above failed.
291 shouldBeNull("conv.buffer");
philipjeb440262015-12-04 21:20:39292
[email protected]1d4178a2014-09-26 21:37:44293 // PannerNode channel count and mode
294 panner = context.createPanner();
295 // Channel count can only be set to 1 or 2.
296 shouldNotThrow("panner.channelCount = 1");
297 shouldNotThrow("panner.channelCount = 2");
[email protected]c026bfd22015-01-16 00:24:26298 shouldThrowAndBeUnchanged("panner.channelCount", "0");
299 shouldThrowAndBeUnchanged("panner.channelCount", "3");
[email protected]1d4178a2014-09-26 21:37:44300 // It is illegal to set the mode to 'max'
[email protected]c026bfd22015-01-16 00:24:26301 shouldThrowAndBeUnchanged("panner.channelCountMode", "'max'");
[email protected]1d4178a2014-09-26 21:37:44302 shouldNotThrow("panner.channelCountMode = 'explicit'");
303 shouldNotThrow("panner.channelCountMode = 'clamped-max'");
304 shouldNotThrow("panner.channelCountMode = 'junk'");
[email protected]7baad8982014-09-29 22:11:48305
306 // Test channel count and mode for a ScriptProcessor.
307 shouldNotThrow("script = context.createScriptProcessor(256, 3)");
308 // Make sure the channelCount and mode are set correctly.
309 shouldBeEqualToNumber("script.channelCount", 3);
310 shouldBeEqualToString("script.channelCountMode", "explicit");
311 // Cannot change the channelCount or mode to anything else
312 shouldNotThrow("script.channelCount = 3");
[email protected]c026bfd22015-01-16 00:24:26313 shouldThrowAndBeUnchanged("script.channelCount", "1");
314
315 shouldThrowAndBeUnchanged("script.channelCount", "7");
[email protected]7baad8982014-09-29 22:11:48316 shouldNotThrow("script.channelCountMode = 'explicit'");
[email protected]c026bfd22015-01-16 00:24:26317 shouldThrowAndBeUnchanged("script.channelCountMode", "'max'");
318 shouldThrowAndBeUnchanged("script.channelCountMode", "'clamped-max'");
[email protected]7baad8982014-09-29 22:11:48319 shouldNotThrow("script.channelCountMode = 'junk'");
[email protected]7cc3e782014-11-10 22:37:54320
321 // noteOn and noteOff don't exist anymore
322 shouldBeUndefined("osc.noteOn");
323 shouldBeUndefined("osc.noteOff");
324 shouldBeUndefined("source.noteOn");
325 shouldBeUndefined("source.noteOff");
[email protected]2da6ffa2013-10-01 00:31:35326}
327
328runTest();
329successfullyParsed = true;
330
[email protected]b702bbb2014-12-05 04:53:16331</script>
[email protected]2da6ffa2013-10-01 00:31:35332</body>
333</html>