blob: 3971cdf6f2a7a1187738bb113f7ae614ce9aa928 [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>
[email protected]f846f5a2014-03-25 17:33:114<script src="resources/compatibility.js"></script>
[email protected]2da6ffa2013-10-01 00:31:355<script src="resources/audio-testing.js"></script>
[email protected]efb086342013-11-05 00:56:216<script src="../resources/js-test.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 ArrayBuffer (unspecified error)
[email protected]2da6ffa2013-10-01 00:31:3554 shouldThrow("context.decodeAudioData(null, function() {}, function () {})");
[email protected]154cd082013-10-04 19:40:0855 // Invalid sources (unspecified error)
[email protected]2da6ffa2013-10-01 00:31:3556 shouldThrow("context.createMediaElementSource(null)");
57 shouldThrow("context.createMediaStreamSource(null)");
[email protected]154cd082013-10-04 19:40:0858 // Invalid buffer size: IndexSizeError
[email protected]2da6ffa2013-10-01 00:31:3559 shouldThrow("context.createScriptProcessor(1, 1, 1)");
[email protected]154cd082013-10-04 19:40:0860 // Invalid number of inputs and outputs: IndexSizeError
[email protected]2da6ffa2013-10-01 00:31:3561 shouldThrow("context.createScriptProcessor(4096, 100, 1)");
62 shouldThrow("context.createScriptProcessor(4096, 1, 100)");
[email protected]ad2e0e32013-10-04 05:16:2063 shouldNotThrow("context.createScriptProcessor()");
64 shouldNotThrow("context.createScriptProcessor(0)");
65
[email protected]154cd082013-10-04 19:40:0866 // Invalid number of channels: IndexSizeError
[email protected]2da6ffa2013-10-01 00:31:3567 shouldThrow("context.createChannelSplitter(0)");
68 shouldThrow("context.createChannelSplitter(99)");
69 shouldThrow("context.createChannelMerger(0)");
70 shouldThrow("context.createChannelMerger(99)");
[email protected]154cd082013-10-04 19:40:0871 // Invalid real/imag arrays: IndexSizeError
[email protected]2da6ffa2013-10-01 00:31:3572 shouldThrow("context.createPeriodicWave(null, null)");
73 shouldThrow("context.createPeriodicWave(new Float32Array(10), null)");
[email protected]154cd082013-10-04 19:40:0874 shouldThrow("context.createPeriodicWave(new Float32Array(4100), new Float32Array(4100))");
75 // Real and imaginary arrays must have the same size: IndexSizeError
[email protected]2da6ffa2013-10-01 00:31:3576 shouldThrow("context.createPeriodicWave(new Float32Array(10), new Float32Array(7))");
[email protected]b702bbb2014-12-05 04:53:1677
[email protected]2da6ffa2013-10-01 00:31:3578
79 // Analysers
80 node = context.createAnalyser();
[email protected]154cd082013-10-04 19:40:0881 // Invalid fftSize: IndexSizeError
[email protected]c026bfd22015-01-16 00:24:2682 shouldThrowAndBeUnchanged("node.fftSize", "42");
83 shouldThrowAndBeUnchanged("node.fftSize", "16");
[email protected]9a535ba2015-01-13 20:56:1984 shouldNotThrow("node.fftSize = 32768");
[email protected]c026bfd22015-01-16 00:24:2685 shouldThrowAndBeUnchanged("node.fftSize", "65536");
[email protected]2da6ffa2013-10-01 00:31:3586
[email protected]c026bfd22015-01-16 00:24:2687 shouldThrowAndBeUnchanged("node.minDecibels", "-10");
88 shouldThrowAndBeUnchanged("node.maxDecibels", "-150");
89 shouldThrowAndBeUnchanged("node.minDecibels", "-30");
90 shouldThrowAndBeUnchanged("node.maxDecibels", "-100");
91
92 shouldThrowAndBeUnchanged("node.smoothingTimeConstant", "-0.1");
93 shouldThrowAndBeUnchanged("node.smoothingTimeConstant", "1.5");
[email protected]db30267b2013-10-03 18:43:2694
[email protected]2da6ffa2013-10-01 00:31:3595 // AudioBuffers
96 node = context.createBuffer(1,1, context.sampleRate);
[email protected]154cd082013-10-04 19:40:0897 // Invalid channel index: IndexSizeError
[email protected]2da6ffa2013-10-01 00:31:3598 shouldThrow("node.getChannelData(2)");
99
100 // AudioNode connections
101 node = context.createGain();
102 node2 = context.createGain();
[email protected]154cd082013-10-04 19:40:08103 // Invalid destination node (unspecified error)
[email protected]2da6ffa2013-10-01 00:31:35104 shouldThrow("node.connect(null, 0, 0)");
[email protected]154cd082013-10-04 19:40:08105 // Invalid input or output index: IndexSizeError
[email protected]2da6ffa2013-10-01 00:31:35106 shouldThrow("node.connect(context.destination, 100, 0)");
107 shouldThrow("node.connect(context.destination, 0, 100)");
108 shouldThrow("node.connect(node2.gain, 100)");
109 shouldThrow("node.disconnect(99)");
[email protected]154cd082013-10-04 19:40:08110 // Can't connect to a different context (unspecified error)
[email protected]2da6ffa2013-10-01 00:31:35111 shouldThrow("node.connect(otherContext.destination)");
112
[email protected]154cd082013-10-04 19:40:08113 // Invalid channel count: NotSupportedError
[email protected]c026bfd22015-01-16 00:24:26114 shouldThrowAndBeUnchanged("node.channelCount", "99");
[email protected]154cd082013-10-04 19:40:08115 // Invalid mode or interpretation (unspecified error)
[email protected]e152e8ed2014-05-14 16:20:33116 currentMode = node.channelCountMode;
117 currentInterpretation = node.channelInterpretation;
118 shouldNotThrow("node.channelCountMode = 'fancy'");
119 if (node.channelCountMode == currentMode)
120 testPassed("Invalid channelCountMode value did not change mode");
121 else
[email protected]b702bbb2014-12-05 04:53:16122 testFailed("node.channelCountMode incorrectly changed to invalid value " + node.channelCountMode);
[email protected]e152e8ed2014-05-14 16:20:33123 shouldNotThrow("node.channelInterpretation = mode");
124 if (node.channelInterpretation == currentInterpretation)
125 testPassed("Invalid channelInterpration value did not change mode");
126 else
[email protected]b702bbb2014-12-05 04:53:16127 testFailed("node.channelInterpretation incorrectly changed to invalid value " + node.channelInterpreation);
[email protected]2da6ffa2013-10-01 00:31:35128
[email protected]b702bbb2014-12-05 04:53:16129 // Destination node channel count: should throw IndexSizeError on invalid
130 // channel count. shouldNotThrow() method cannot be used because the error
131 // message includes the number of channels, which can change depending on
132 // the actual attached hardware.
133 try {
134 eval("context.destination.channelCount = 99");
135 } catch (e) {
136 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")
137 testPassed("context.destination.channelCount = 99 threw IndexSizeError exception on invalid channel count.");
138 else
139 testFailed("context.destination.channelCount = 99 should throw IndexSizeError exception on invalid channel count.");
140 }
[email protected]2da6ffa2013-10-01 00:31:35141
142 // Delay nodes are tested elsewhere, so don't duplicate that work here.
143
144 // OfflineAudioContext
[email protected]84126a362014-04-14 16:55:48145 // Max supported channels
146 shouldNotThrow("new OfflineAudioContext(32, 100, context.sampleRate)");
[email protected]154cd082013-10-04 19:40:08147 // Invalid number of channels (unspecified error)
[email protected]f846f5a2014-03-25 17:33:11148 shouldThrow("new OfflineAudioContext(99, 100, context.sampleRate)");
[email protected]154cd082013-10-04 19:40:08149 // Invalid sample rate. (unspecified error)
[email protected]f846f5a2014-03-25 17:33:11150 shouldThrow("new OfflineAudioContext(1, 100, 1)");
151 shouldThrow("new OfflineAudioContext(1, 100, 1e6)");
[email protected]a9b939e2014-03-12 18:34:27152 // Invalid frame length (crbug.com/351277)
[email protected]f846f5a2014-03-25 17:33:11153 shouldThrow("new OfflineAudioContext(1, -88200000000000, 44100)");
[email protected]2da6ffa2013-10-01 00:31:35154
[email protected]4e10d032013-10-02 21:48:00155 // WaveShaper types
156 node = context.createWaveShaper();
[email protected]e152e8ed2014-05-14 16:20:33157 currentOversample = node.oversample;
158 shouldNotThrow("node.oversample = '9x'");
159 if (node.oversample == currentOversample)
160 testPassed("Invalid oversample value did not change node.oversample");
161 else
162 testFailed("node.oversample incorrectly changed to invalid value " + node.oversample);
[email protected]837dc8c2015-01-13 18:00:30163 shouldThrow("node.curve = new Float32Array(1)");
[email protected]c026bfd22015-01-16 00:24:26164 shouldBeNull("node.curve");
[email protected]837dc8c2015-01-13 18:00:30165 shouldNotThrow("node.curve = new Float32Array(2)");
[email protected]6eec933d2015-01-21 20:55:00166 shouldNotThrow("node.curve = null");
[email protected]ffd785f2013-10-29 17:19:58167
168 // Start/stop for AudioBufferSourceNodes
169 buffer = context.createBuffer(1,1, context.sampleRate);
170 shouldNotThrow("source = context.createBufferSource()");
[email protected]eed4fa202013-10-31 02:13:29171 shouldNotThrow("source.buffer = buffer");
[email protected]288a06a2014-09-26 03:53:55172 shouldThrow("source.start(-1)");
173 shouldThrow("source.start(Infinity)");
174 shouldThrow("source.start(-Infinity)");
175 shouldThrow("source.start(NaN)");
176 shouldThrow("source.start(1, Infinity)");
177 shouldThrow("source.start(1, -Infinity)");
178 shouldThrow("source.start(1, NaN)");
179 shouldThrow("source.start(1, -1)");
180 shouldThrow("source.start(1, 1, Infinity)");
181 shouldThrow("source.start(1, 1, -Infinity)");
182 shouldThrow("source.start(1, 1, NaN)");
183 shouldThrow("source.start(1, 1, -1)");
[email protected]eed4fa202013-10-31 02:13:29184 shouldNotThrow("source.start()");
[email protected]288a06a2014-09-26 03:53:55185 shouldThrow("source.stop(-1)");
186 shouldThrow("source.stop(Infinity)");
187 shouldThrow("source.stop(-Infinity)");
188 shouldThrow("source.stop(NaN)");
[email protected]eed4fa202013-10-31 02:13:29189 shouldNotThrow("source.stop()");
190
[email protected]20b3e8332013-11-01 00:14:05191 // It's not clear from the spec, but I think it's valid to call start(). The spec is silent on
192 // what happens if we call stop() afterwards, so don't call it.
[email protected]eed4fa202013-10-31 02:13:29193 shouldNotThrow("source = context.createBufferSource()");
[email protected]ffd785f2013-10-29 17:19:58194 shouldNotThrow("source.start()");
[email protected]ffd785f2013-10-29 17:19:58195
[email protected]20b3e8332013-11-01 00:14:05196 buffer = context.createBuffer(1,1, context.sampleRate);
197 shouldNotThrow("source = context.createBufferSource()");
198 shouldNotThrow("source.buffer = buffer");
199 shouldThrow("source.stop()");
200
201 buffer = context.createBuffer(1,1, context.sampleRate);
202 shouldNotThrow("source = context.createBufferSource()");
203 shouldNotThrow("source.buffer = buffer");
204 shouldNotThrow("source.start()");
205 shouldThrow("source.start()");
206
207 buffer = context.createBuffer(1,1, context.sampleRate);
208 shouldNotThrow("source = context.createBufferSource()");
209 shouldNotThrow("source.buffer = buffer");
210 shouldNotThrow("source.start()");
211 shouldNotThrow("source.stop()");
[email protected]20b3e8332013-11-01 00:14:05212
[email protected]b702bbb2014-12-05 04:53:16213
[email protected]ffd785f2013-10-29 17:19:58214 // Start/stop for OscillatorNodes
215 shouldNotThrow("source = context.createOscillator()");
[email protected]288a06a2014-09-26 03:53:55216 shouldThrow("source.start(-1)");
217 shouldThrow("source.start(Infinity)");
218 shouldThrow("source.start(-Infinity)");
219 shouldThrow("source.start(NaN)");
[email protected]ffd785f2013-10-29 17:19:58220 shouldNotThrow("source.start()");
[email protected]288a06a2014-09-26 03:53:55221 shouldThrow("source.stop(-1)");
222 shouldThrow("source.stop(Infinity)");
223 shouldThrow("source.stop(-Infinity)");
224 shouldThrow("source.stop(NaN)");
[email protected]ffd785f2013-10-29 17:19:58225 shouldNotThrow("source.stop()");
[email protected]20b3e8332013-11-01 00:14:05226
227 shouldNotThrow("osc = context.createOscillator()");
228 shouldThrow("osc.stop()");
229 shouldNotThrow("osc1 = context.createOscillator()");
230 shouldNotThrow("osc1.start()");
231 shouldNotThrow("osc1.stop()");
[email protected]5ab469f2014-02-12 05:59:26232
233 // exponentialRampToValue should throw on non-positive target values.
234 node = context.createGain();
235 node.connect(context.destination);
236 shouldThrow("node.gain.exponentialRampToValueAtTime(-1, 0.1)");
237 shouldThrow("node.gain.exponentialRampToValueAtTime(0, 0.1)");
[email protected]77459e32014-03-19 00:04:10238
239 // Convolver buffer rate must match context rate. Create on offline context so we
240 // specify the context rate exactly, in case the test is run on platforms with different
241 // HW sample rates.
[email protected]f846f5a2014-03-25 17:33:11242 shouldNotThrow("oc = new OfflineAudioContext(1, 44100, 44100)");
[email protected]77459e32014-03-19 00:04:10243 shouldNotThrow("conv = oc.createConvolver()");
244 shouldThrow("conv.buffer = oc.createBuffer(1, 100, 22050)");
[email protected]1d4178a2014-09-26 21:37:44245
246 // PannerNode channel count and mode
247 panner = context.createPanner();
248 // Channel count can only be set to 1 or 2.
249 shouldNotThrow("panner.channelCount = 1");
250 shouldNotThrow("panner.channelCount = 2");
[email protected]c026bfd22015-01-16 00:24:26251 shouldThrowAndBeUnchanged("panner.channelCount", "0");
252 shouldThrowAndBeUnchanged("panner.channelCount", "3");
[email protected]1d4178a2014-09-26 21:37:44253 // It is illegal to set the mode to 'max'
[email protected]c026bfd22015-01-16 00:24:26254 shouldThrowAndBeUnchanged("panner.channelCountMode", "'max'");
[email protected]1d4178a2014-09-26 21:37:44255 shouldNotThrow("panner.channelCountMode = 'explicit'");
256 shouldNotThrow("panner.channelCountMode = 'clamped-max'");
257 shouldNotThrow("panner.channelCountMode = 'junk'");
[email protected]7baad8982014-09-29 22:11:48258
259 // Test channel count and mode for a ScriptProcessor.
260 shouldNotThrow("script = context.createScriptProcessor(256, 3)");
261 // Make sure the channelCount and mode are set correctly.
262 shouldBeEqualToNumber("script.channelCount", 3);
263 shouldBeEqualToString("script.channelCountMode", "explicit");
264 // Cannot change the channelCount or mode to anything else
265 shouldNotThrow("script.channelCount = 3");
[email protected]c026bfd22015-01-16 00:24:26266 shouldThrowAndBeUnchanged("script.channelCount", "1");
267
268 shouldThrowAndBeUnchanged("script.channelCount", "7");
[email protected]7baad8982014-09-29 22:11:48269 shouldNotThrow("script.channelCountMode = 'explicit'");
[email protected]c026bfd22015-01-16 00:24:26270 shouldThrowAndBeUnchanged("script.channelCountMode", "'max'");
271 shouldThrowAndBeUnchanged("script.channelCountMode", "'clamped-max'");
[email protected]7baad8982014-09-29 22:11:48272 shouldNotThrow("script.channelCountMode = 'junk'");
[email protected]7cc3e782014-11-10 22:37:54273
274 // noteOn and noteOff don't exist anymore
275 shouldBeUndefined("osc.noteOn");
276 shouldBeUndefined("osc.noteOff");
277 shouldBeUndefined("source.noteOn");
278 shouldBeUndefined("source.noteOff");
[email protected]2da6ffa2013-10-01 00:31:35279}
280
281runTest();
282successfullyParsed = true;
283
[email protected]b702bbb2014-12-05 04:53:16284</script>
[email protected]2da6ffa2013-10-01 00:31:35285</body>
286</html>