blob: df28183c7e505ac6c47c9c3f863ce8ea4b4702ee [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;
22
23function runTest() {
24 if (window.testRunner) {
25 testRunner.dumpAsText();
26 }
27
[email protected]f846f5a2014-03-25 17:33:1128 context = new AudioContext();
29 otherContext = new AudioContext();
[email protected]2da6ffa2013-10-01 00:31:3530
[email protected]154cd082013-10-04 19:40:0831 // Test creation of various objects
[email protected]2da6ffa2013-10-01 00:31:3532
[email protected]154cd082013-10-04 19:40:0833 // Invalid number of channels: NotSupportedError
[email protected]2da6ffa2013-10-01 00:31:3534 shouldThrow("context.createBuffer(99, 1, context.sampleRate)");
[email protected]ace011c2014-05-08 22:10:0335 shouldThrow("context.createBuffer(0, 1, context.sampleRate)");
[email protected]154cd082013-10-04 19:40:0836 // Invalid sample rate: NotSupportedError
[email protected]2da6ffa2013-10-01 00:31:3537 shouldThrow("context.createBuffer(1, 1, 1)");
38 shouldThrow("context.createBuffer(1, 1, 1e6)");
[email protected]c8678992014-03-25 23:51:1839 // Check valid values from crbug.com/344375
40 shouldNotThrow("context.createBuffer(1, 1, 3000)");
41 shouldNotThrow("context.createBuffer(1, 1, 192000)");
[email protected]154cd082013-10-04 19:40:0842 // Invalid number of frames: NotSupportedError
43 shouldThrow("context.createBuffer(1, 0, context.sampleRate)");
[email protected]c5f32c5a82014-04-14 18:19:1244 // 2-arg createBuffer not allowed.
[email protected]2da6ffa2013-10-01 00:31:3545 shouldThrow("context.createBuffer(new ArrayBuffer(100), true)");
[email protected]154cd082013-10-04 19:40:0846 // Invalid ArrayBuffer (unspecified error)
[email protected]2da6ffa2013-10-01 00:31:3547 shouldThrow("context.decodeAudioData(null, function() {}, function () {})");
[email protected]154cd082013-10-04 19:40:0848 // Invalid sources (unspecified error)
[email protected]2da6ffa2013-10-01 00:31:3549 shouldThrow("context.createMediaElementSource(null)");
50 shouldThrow("context.createMediaStreamSource(null)");
[email protected]154cd082013-10-04 19:40:0851 // Invalid buffer size: IndexSizeError
[email protected]2da6ffa2013-10-01 00:31:3552 shouldThrow("context.createScriptProcessor(1, 1, 1)");
[email protected]154cd082013-10-04 19:40:0853 // Invalid number of inputs and outputs: IndexSizeError
[email protected]2da6ffa2013-10-01 00:31:3554 shouldThrow("context.createScriptProcessor(4096, 100, 1)");
55 shouldThrow("context.createScriptProcessor(4096, 1, 100)");
[email protected]ad2e0e32013-10-04 05:16:2056 shouldNotThrow("context.createScriptProcessor()");
57 shouldNotThrow("context.createScriptProcessor(0)");
58
[email protected]154cd082013-10-04 19:40:0859 // Invalid number of channels: IndexSizeError
[email protected]2da6ffa2013-10-01 00:31:3560 shouldThrow("context.createChannelSplitter(0)");
61 shouldThrow("context.createChannelSplitter(99)");
62 shouldThrow("context.createChannelMerger(0)");
63 shouldThrow("context.createChannelMerger(99)");
[email protected]154cd082013-10-04 19:40:0864 // Invalid real/imag arrays: IndexSizeError
[email protected]2da6ffa2013-10-01 00:31:3565 shouldThrow("context.createPeriodicWave(null, null)");
66 shouldThrow("context.createPeriodicWave(new Float32Array(10), null)");
[email protected]154cd082013-10-04 19:40:0867 shouldThrow("context.createPeriodicWave(new Float32Array(4100), new Float32Array(4100))");
68 // Real and imaginary arrays must have the same size: IndexSizeError
[email protected]2da6ffa2013-10-01 00:31:3569 shouldThrow("context.createPeriodicWave(new Float32Array(10), new Float32Array(7))");
[email protected]154cd082013-10-04 19:40:0870
[email protected]2da6ffa2013-10-01 00:31:3571
72 // Analysers
73 node = context.createAnalyser();
[email protected]154cd082013-10-04 19:40:0874 // Invalid fftSize: IndexSizeError
[email protected]2da6ffa2013-10-01 00:31:3575 shouldThrow("node.fftSize = 42");
[email protected]154cd082013-10-04 19:40:0876 shouldThrow("node.fftSize = 16");
77 shouldThrow("node.fftSize = 4096");
[email protected]2da6ffa2013-10-01 00:31:3578
[email protected]db30267b2013-10-03 18:43:2679 shouldThrow("node.minDecibels = -10");
80 shouldThrow("node.maxDecibels = -150");
[email protected]f8f8c462014-03-31 18:24:5281 shouldThrow("node.minDecibels = -30");
82 shouldThrow("node.maxDecibels = -100");
[email protected]db30267b2013-10-03 18:43:2683 shouldThrow("node.smoothingTimeConstant = -0.1");
84 shouldThrow("node.smoothingTimeConstant = 1.5");
85
[email protected]2da6ffa2013-10-01 00:31:3586 // AudioBuffers
87 node = context.createBuffer(1,1, context.sampleRate);
[email protected]154cd082013-10-04 19:40:0888 // Invalid channel index: IndexSizeError
[email protected]2da6ffa2013-10-01 00:31:3589 shouldThrow("node.getChannelData(2)");
90
91 // AudioNode connections
92 node = context.createGain();
93 node2 = context.createGain();
[email protected]154cd082013-10-04 19:40:0894 // Invalid destination node (unspecified error)
[email protected]2da6ffa2013-10-01 00:31:3595 shouldThrow("node.connect(null, 0, 0)");
[email protected]154cd082013-10-04 19:40:0896 // Invalid input or output index: IndexSizeError
[email protected]2da6ffa2013-10-01 00:31:3597 shouldThrow("node.connect(context.destination, 100, 0)");
98 shouldThrow("node.connect(context.destination, 0, 100)");
99 shouldThrow("node.connect(node2.gain, 100)");
100 shouldThrow("node.disconnect(99)");
[email protected]154cd082013-10-04 19:40:08101 // Can't connect to a different context (unspecified error)
[email protected]2da6ffa2013-10-01 00:31:35102 shouldThrow("node.connect(otherContext.destination)");
103
[email protected]154cd082013-10-04 19:40:08104 // Invalid channel count: NotSupportedError
[email protected]2da6ffa2013-10-01 00:31:35105 shouldThrow("node.channelCount = 99");
[email protected]154cd082013-10-04 19:40:08106 // Invalid mode or interpretation (unspecified error)
[email protected]e152e8ed2014-05-14 16:20:33107 currentMode = node.channelCountMode;
108 currentInterpretation = node.channelInterpretation;
109 shouldNotThrow("node.channelCountMode = 'fancy'");
110 if (node.channelCountMode == currentMode)
111 testPassed("Invalid channelCountMode value did not change mode");
112 else
113 testFailed("node.channelCountMode incorrectly changed to invalid value " + node.channelCountMode);
114 shouldNotThrow("node.channelInterpretation = mode");
115 if (node.channelInterpretation == currentInterpretation)
116 testPassed("Invalid channelInterpration value did not change mode");
117 else
118 testFailed("node.channelInterpretation incorrectly changed to invalid value " + node.channelInterpreation);
[email protected]2da6ffa2013-10-01 00:31:35119
[email protected]154cd082013-10-04 19:40:08120 // Destination: IndexSizeError
[email protected]2da6ffa2013-10-01 00:31:35121 shouldThrow("context.destination.channelCount = 99");
122
123 // Delay nodes are tested elsewhere, so don't duplicate that work here.
124
125 // OfflineAudioContext
[email protected]84126a362014-04-14 16:55:48126 // Max supported channels
127 shouldNotThrow("new OfflineAudioContext(32, 100, context.sampleRate)");
[email protected]154cd082013-10-04 19:40:08128 // Invalid number of channels (unspecified error)
[email protected]f846f5a2014-03-25 17:33:11129 shouldThrow("new OfflineAudioContext(99, 100, context.sampleRate)");
[email protected]154cd082013-10-04 19:40:08130 // Invalid sample rate. (unspecified error)
[email protected]f846f5a2014-03-25 17:33:11131 shouldThrow("new OfflineAudioContext(1, 100, 1)");
132 shouldThrow("new OfflineAudioContext(1, 100, 1e6)");
[email protected]a9b939e2014-03-12 18:34:27133 // Invalid frame length (crbug.com/351277)
[email protected]f846f5a2014-03-25 17:33:11134 shouldThrow("new OfflineAudioContext(1, -88200000000000, 44100)");
[email protected]2da6ffa2013-10-01 00:31:35135
[email protected]4e10d032013-10-02 21:48:00136 // WaveShaper types
137 node = context.createWaveShaper();
[email protected]e152e8ed2014-05-14 16:20:33138 currentOversample = node.oversample;
139 shouldNotThrow("node.oversample = '9x'");
140 if (node.oversample == currentOversample)
141 testPassed("Invalid oversample value did not change node.oversample");
142 else
143 testFailed("node.oversample incorrectly changed to invalid value " + node.oversample);
[email protected]ffd785f2013-10-29 17:19:58144
145 // Start/stop for AudioBufferSourceNodes
146 buffer = context.createBuffer(1,1, context.sampleRate);
147 shouldNotThrow("source = context.createBufferSource()");
[email protected]eed4fa202013-10-31 02:13:29148 shouldNotThrow("source.buffer = buffer");
149 shouldNotThrow("source.start()");
150 shouldNotThrow("source.stop()");
151
[email protected]20b3e8332013-11-01 00:14:05152 // It's not clear from the spec, but I think it's valid to call start(). The spec is silent on
153 // what happens if we call stop() afterwards, so don't call it.
[email protected]eed4fa202013-10-31 02:13:29154 shouldNotThrow("source = context.createBufferSource()");
[email protected]ffd785f2013-10-29 17:19:58155 shouldNotThrow("source.start()");
[email protected]ffd785f2013-10-29 17:19:58156
[email protected]20b3e8332013-11-01 00:14:05157 buffer = context.createBuffer(1,1, context.sampleRate);
158 shouldNotThrow("source = context.createBufferSource()");
159 shouldNotThrow("source.buffer = buffer");
160 shouldThrow("source.stop()");
161
162 buffer = context.createBuffer(1,1, context.sampleRate);
163 shouldNotThrow("source = context.createBufferSource()");
164 shouldNotThrow("source.buffer = buffer");
165 shouldNotThrow("source.start()");
166 shouldThrow("source.start()");
167
168 buffer = context.createBuffer(1,1, context.sampleRate);
169 shouldNotThrow("source = context.createBufferSource()");
170 shouldNotThrow("source.buffer = buffer");
171 shouldNotThrow("source.start()");
172 shouldNotThrow("source.stop()");
[email protected]20b3e8332013-11-01 00:14:05173
174
[email protected]ffd785f2013-10-29 17:19:58175 // Start/stop for OscillatorNodes
176 shouldNotThrow("source = context.createOscillator()");
177 shouldNotThrow("source.start()");
178 shouldNotThrow("source.stop()");
[email protected]20b3e8332013-11-01 00:14:05179
180 shouldNotThrow("osc = context.createOscillator()");
181 shouldThrow("osc.stop()");
182 shouldNotThrow("osc1 = context.createOscillator()");
183 shouldNotThrow("osc1.start()");
184 shouldNotThrow("osc1.stop()");
[email protected]5ab469f2014-02-12 05:59:26185
186 // exponentialRampToValue should throw on non-positive target values.
187 node = context.createGain();
188 node.connect(context.destination);
189 shouldThrow("node.gain.exponentialRampToValueAtTime(-1, 0.1)");
190 shouldThrow("node.gain.exponentialRampToValueAtTime(0, 0.1)");
[email protected]77459e32014-03-19 00:04:10191
192 // Convolver buffer rate must match context rate. Create on offline context so we
193 // specify the context rate exactly, in case the test is run on platforms with different
194 // HW sample rates.
[email protected]f846f5a2014-03-25 17:33:11195 shouldNotThrow("oc = new OfflineAudioContext(1, 44100, 44100)");
[email protected]77459e32014-03-19 00:04:10196 shouldNotThrow("conv = oc.createConvolver()");
197 shouldThrow("conv.buffer = oc.createBuffer(1, 100, 22050)");
[email protected]2da6ffa2013-10-01 00:31:35198}
199
200runTest();
201successfullyParsed = true;
202
203</script>
[email protected]2da6ffa2013-10-01 00:31:35204</body>
205</html>