blob: ba43ba31604e3142e6710477ef643cb428e829fb [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
25function runTest() {
26 if (window.testRunner) {
27 testRunner.dumpAsText();
28 }
29
[email protected]f846f5a2014-03-25 17:33:1130 context = new AudioContext();
31 otherContext = new AudioContext();
[email protected]2da6ffa2013-10-01 00:31:3532
[email protected]154cd082013-10-04 19:40:0833 // Test creation of various objects
[email protected]2da6ffa2013-10-01 00:31:3534
[email protected]154cd082013-10-04 19:40:0835 // Invalid number of channels: NotSupportedError
[email protected]2da6ffa2013-10-01 00:31:3536 shouldThrow("context.createBuffer(99, 1, context.sampleRate)");
[email protected]ace011c2014-05-08 22:10:0337 shouldThrow("context.createBuffer(0, 1, context.sampleRate)");
[email protected]154cd082013-10-04 19:40:0838 // Invalid sample rate: NotSupportedError
[email protected]2da6ffa2013-10-01 00:31:3539 shouldThrow("context.createBuffer(1, 1, 1)");
40 shouldThrow("context.createBuffer(1, 1, 1e6)");
[email protected]c8678992014-03-25 23:51:1841 // Check valid values from crbug.com/344375
42 shouldNotThrow("context.createBuffer(1, 1, 3000)");
43 shouldNotThrow("context.createBuffer(1, 1, 192000)");
[email protected]154cd082013-10-04 19:40:0844 // Invalid number of frames: NotSupportedError
45 shouldThrow("context.createBuffer(1, 0, context.sampleRate)");
[email protected]c5f32c5a82014-04-14 18:19:1246 // 2-arg createBuffer not allowed.
[email protected]2da6ffa2013-10-01 00:31:3547 shouldThrow("context.createBuffer(new ArrayBuffer(100), true)");
[email protected]154cd082013-10-04 19:40:0848 // Invalid ArrayBuffer (unspecified error)
[email protected]2da6ffa2013-10-01 00:31:3549 shouldThrow("context.decodeAudioData(null, function() {}, function () {})");
[email protected]154cd082013-10-04 19:40:0850 // Invalid sources (unspecified error)
[email protected]2da6ffa2013-10-01 00:31:3551 shouldThrow("context.createMediaElementSource(null)");
52 shouldThrow("context.createMediaStreamSource(null)");
[email protected]154cd082013-10-04 19:40:0853 // Invalid buffer size: IndexSizeError
[email protected]2da6ffa2013-10-01 00:31:3554 shouldThrow("context.createScriptProcessor(1, 1, 1)");
[email protected]154cd082013-10-04 19:40:0855 // Invalid number of inputs and outputs: IndexSizeError
[email protected]2da6ffa2013-10-01 00:31:3556 shouldThrow("context.createScriptProcessor(4096, 100, 1)");
57 shouldThrow("context.createScriptProcessor(4096, 1, 100)");
[email protected]ad2e0e32013-10-04 05:16:2058 shouldNotThrow("context.createScriptProcessor()");
59 shouldNotThrow("context.createScriptProcessor(0)");
60
[email protected]154cd082013-10-04 19:40:0861 // Invalid number of channels: IndexSizeError
[email protected]2da6ffa2013-10-01 00:31:3562 shouldThrow("context.createChannelSplitter(0)");
63 shouldThrow("context.createChannelSplitter(99)");
64 shouldThrow("context.createChannelMerger(0)");
65 shouldThrow("context.createChannelMerger(99)");
[email protected]154cd082013-10-04 19:40:0866 // Invalid real/imag arrays: IndexSizeError
[email protected]2da6ffa2013-10-01 00:31:3567 shouldThrow("context.createPeriodicWave(null, null)");
68 shouldThrow("context.createPeriodicWave(new Float32Array(10), null)");
[email protected]154cd082013-10-04 19:40:0869 shouldThrow("context.createPeriodicWave(new Float32Array(4100), new Float32Array(4100))");
70 // Real and imaginary arrays must have the same size: IndexSizeError
[email protected]2da6ffa2013-10-01 00:31:3571 shouldThrow("context.createPeriodicWave(new Float32Array(10), new Float32Array(7))");
[email protected]154cd082013-10-04 19:40:0872
[email protected]2da6ffa2013-10-01 00:31:3573
74 // Analysers
75 node = context.createAnalyser();
[email protected]154cd082013-10-04 19:40:0876 // Invalid fftSize: IndexSizeError
[email protected]2da6ffa2013-10-01 00:31:3577 shouldThrow("node.fftSize = 42");
[email protected]154cd082013-10-04 19:40:0878 shouldThrow("node.fftSize = 16");
79 shouldThrow("node.fftSize = 4096");
[email protected]2da6ffa2013-10-01 00:31:3580
[email protected]db30267b2013-10-03 18:43:2681 shouldThrow("node.minDecibels = -10");
82 shouldThrow("node.maxDecibels = -150");
[email protected]f8f8c462014-03-31 18:24:5283 shouldThrow("node.minDecibels = -30");
84 shouldThrow("node.maxDecibels = -100");
[email protected]db30267b2013-10-03 18:43:2685 shouldThrow("node.smoothingTimeConstant = -0.1");
86 shouldThrow("node.smoothingTimeConstant = 1.5");
87
[email protected]2da6ffa2013-10-01 00:31:3588 // AudioBuffers
89 node = context.createBuffer(1,1, context.sampleRate);
[email protected]154cd082013-10-04 19:40:0890 // Invalid channel index: IndexSizeError
[email protected]2da6ffa2013-10-01 00:31:3591 shouldThrow("node.getChannelData(2)");
92
93 // AudioNode connections
94 node = context.createGain();
95 node2 = context.createGain();
[email protected]154cd082013-10-04 19:40:0896 // Invalid destination node (unspecified error)
[email protected]2da6ffa2013-10-01 00:31:3597 shouldThrow("node.connect(null, 0, 0)");
[email protected]154cd082013-10-04 19:40:0898 // Invalid input or output index: IndexSizeError
[email protected]2da6ffa2013-10-01 00:31:3599 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]154cd082013-10-04 19:40:08103 // Can't connect to a different context (unspecified error)
[email protected]2da6ffa2013-10-01 00:31:35104 shouldThrow("node.connect(otherContext.destination)");
105
[email protected]154cd082013-10-04 19:40:08106 // Invalid channel count: NotSupportedError
[email protected]2da6ffa2013-10-01 00:31:35107 shouldThrow("node.channelCount = 99");
[email protected]154cd082013-10-04 19:40:08108 // Invalid mode or interpretation (unspecified error)
[email protected]e152e8ed2014-05-14 16:20:33109 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
115 testFailed("node.channelCountMode incorrectly changed to invalid value " + node.channelCountMode);
116 shouldNotThrow("node.channelInterpretation = mode");
117 if (node.channelInterpretation == currentInterpretation)
118 testPassed("Invalid channelInterpration value did not change mode");
119 else
120 testFailed("node.channelInterpretation incorrectly changed to invalid value " + node.channelInterpreation);
[email protected]2da6ffa2013-10-01 00:31:35121
[email protected]154cd082013-10-04 19:40:08122 // Destination: IndexSizeError
[email protected]2da6ffa2013-10-01 00:31:35123 shouldThrow("context.destination.channelCount = 99");
124
125 // Delay nodes are tested elsewhere, so don't duplicate that work here.
126
127 // OfflineAudioContext
[email protected]84126a362014-04-14 16:55:48128 // Max supported channels
129 shouldNotThrow("new OfflineAudioContext(32, 100, context.sampleRate)");
[email protected]154cd082013-10-04 19:40:08130 // Invalid number of channels (unspecified error)
[email protected]f846f5a2014-03-25 17:33:11131 shouldThrow("new OfflineAudioContext(99, 100, context.sampleRate)");
[email protected]154cd082013-10-04 19:40:08132 // Invalid sample rate. (unspecified error)
[email protected]f846f5a2014-03-25 17:33:11133 shouldThrow("new OfflineAudioContext(1, 100, 1)");
134 shouldThrow("new OfflineAudioContext(1, 100, 1e6)");
[email protected]a9b939e2014-03-12 18:34:27135 // Invalid frame length (crbug.com/351277)
[email protected]f846f5a2014-03-25 17:33:11136 shouldThrow("new OfflineAudioContext(1, -88200000000000, 44100)");
[email protected]2da6ffa2013-10-01 00:31:35137
[email protected]4e10d032013-10-02 21:48:00138 // WaveShaper types
139 node = context.createWaveShaper();
[email protected]e152e8ed2014-05-14 16:20:33140 currentOversample = node.oversample;
141 shouldNotThrow("node.oversample = '9x'");
142 if (node.oversample == currentOversample)
143 testPassed("Invalid oversample value did not change node.oversample");
144 else
145 testFailed("node.oversample incorrectly changed to invalid value " + node.oversample);
[email protected]ffd785f2013-10-29 17:19:58146
147 // Start/stop for AudioBufferSourceNodes
148 buffer = context.createBuffer(1,1, context.sampleRate);
149 shouldNotThrow("source = context.createBufferSource()");
[email protected]eed4fa202013-10-31 02:13:29150 shouldNotThrow("source.buffer = buffer");
[email protected]288a06a2014-09-26 03:53:55151 shouldThrow("source.start(-1)");
152 shouldThrow("source.start(Infinity)");
153 shouldThrow("source.start(-Infinity)");
154 shouldThrow("source.start(NaN)");
155 shouldThrow("source.start(1, Infinity)");
156 shouldThrow("source.start(1, -Infinity)");
157 shouldThrow("source.start(1, NaN)");
158 shouldThrow("source.start(1, -1)");
159 shouldThrow("source.start(1, 1, Infinity)");
160 shouldThrow("source.start(1, 1, -Infinity)");
161 shouldThrow("source.start(1, 1, NaN)");
162 shouldThrow("source.start(1, 1, -1)");
[email protected]eed4fa202013-10-31 02:13:29163 shouldNotThrow("source.start()");
[email protected]288a06a2014-09-26 03:53:55164 shouldThrow("source.stop(-1)");
165 shouldThrow("source.stop(Infinity)");
166 shouldThrow("source.stop(-Infinity)");
167 shouldThrow("source.stop(NaN)");
[email protected]eed4fa202013-10-31 02:13:29168 shouldNotThrow("source.stop()");
169
[email protected]20b3e8332013-11-01 00:14:05170 // It's not clear from the spec, but I think it's valid to call start(). The spec is silent on
171 // what happens if we call stop() afterwards, so don't call it.
[email protected]eed4fa202013-10-31 02:13:29172 shouldNotThrow("source = context.createBufferSource()");
[email protected]ffd785f2013-10-29 17:19:58173 shouldNotThrow("source.start()");
[email protected]ffd785f2013-10-29 17:19:58174
[email protected]20b3e8332013-11-01 00:14:05175 buffer = context.createBuffer(1,1, context.sampleRate);
176 shouldNotThrow("source = context.createBufferSource()");
177 shouldNotThrow("source.buffer = buffer");
178 shouldThrow("source.stop()");
179
180 buffer = context.createBuffer(1,1, context.sampleRate);
181 shouldNotThrow("source = context.createBufferSource()");
182 shouldNotThrow("source.buffer = buffer");
183 shouldNotThrow("source.start()");
184 shouldThrow("source.start()");
185
186 buffer = context.createBuffer(1,1, context.sampleRate);
187 shouldNotThrow("source = context.createBufferSource()");
188 shouldNotThrow("source.buffer = buffer");
189 shouldNotThrow("source.start()");
190 shouldNotThrow("source.stop()");
[email protected]20b3e8332013-11-01 00:14:05191
192
[email protected]ffd785f2013-10-29 17:19:58193 // Start/stop for OscillatorNodes
194 shouldNotThrow("source = context.createOscillator()");
[email protected]288a06a2014-09-26 03:53:55195 shouldThrow("source.start(-1)");
196 shouldThrow("source.start(Infinity)");
197 shouldThrow("source.start(-Infinity)");
198 shouldThrow("source.start(NaN)");
[email protected]ffd785f2013-10-29 17:19:58199 shouldNotThrow("source.start()");
[email protected]288a06a2014-09-26 03:53:55200 shouldThrow("source.stop(-1)");
201 shouldThrow("source.stop(Infinity)");
202 shouldThrow("source.stop(-Infinity)");
203 shouldThrow("source.stop(NaN)");
[email protected]ffd785f2013-10-29 17:19:58204 shouldNotThrow("source.stop()");
[email protected]20b3e8332013-11-01 00:14:05205
206 shouldNotThrow("osc = context.createOscillator()");
207 shouldThrow("osc.stop()");
208 shouldNotThrow("osc1 = context.createOscillator()");
209 shouldNotThrow("osc1.start()");
210 shouldNotThrow("osc1.stop()");
[email protected]5ab469f2014-02-12 05:59:26211
212 // exponentialRampToValue should throw on non-positive target values.
213 node = context.createGain();
214 node.connect(context.destination);
215 shouldThrow("node.gain.exponentialRampToValueAtTime(-1, 0.1)");
216 shouldThrow("node.gain.exponentialRampToValueAtTime(0, 0.1)");
[email protected]77459e32014-03-19 00:04:10217
218 // Convolver buffer rate must match context rate. Create on offline context so we
219 // specify the context rate exactly, in case the test is run on platforms with different
220 // HW sample rates.
[email protected]f846f5a2014-03-25 17:33:11221 shouldNotThrow("oc = new OfflineAudioContext(1, 44100, 44100)");
[email protected]77459e32014-03-19 00:04:10222 shouldNotThrow("conv = oc.createConvolver()");
223 shouldThrow("conv.buffer = oc.createBuffer(1, 100, 22050)");
[email protected]1d4178a2014-09-26 21:37:44224
225 // PannerNode channel count and mode
226 panner = context.createPanner();
227 // Channel count can only be set to 1 or 2.
228 shouldNotThrow("panner.channelCount = 1");
229 shouldNotThrow("panner.channelCount = 2");
230 shouldThrow("panner.channelCount = 0");
231 shouldThrow("panner.channelCount = 3");
232 // It is illegal to set the mode to 'max'
233 shouldThrow("panner.channelCountMode = 'max'");
234 shouldNotThrow("panner.channelCountMode = 'explicit'");
235 shouldNotThrow("panner.channelCountMode = 'clamped-max'");
236 shouldNotThrow("panner.channelCountMode = 'junk'");
[email protected]7baad8982014-09-29 22:11:48237
238 // Test channel count and mode for a ScriptProcessor.
239 shouldNotThrow("script = context.createScriptProcessor(256, 3)");
240 // Make sure the channelCount and mode are set correctly.
241 shouldBeEqualToNumber("script.channelCount", 3);
242 shouldBeEqualToString("script.channelCountMode", "explicit");
243 // Cannot change the channelCount or mode to anything else
244 shouldNotThrow("script.channelCount = 3");
245 shouldThrow("script.channelCount = 1");
246 shouldThrow("script.channelCount = 7");
247 shouldNotThrow("script.channelCountMode = 'explicit'");
248 shouldThrow("script.channelCountMode = 'max'");
249 shouldThrow("script.channelCountMode = 'clamped-max'");
250 shouldNotThrow("script.channelCountMode = 'junk'");
[email protected]2da6ffa2013-10-01 00:31:35251}
252
253runTest();
254successfullyParsed = true;
255
256</script>
[email protected]2da6ffa2013-10-01 00:31:35257</body>
258</html>