| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
| <html> |
| <head> |
| <script src="resources/compatibility.js"></script> |
| <script src="resources/audio-testing.js"></script> |
| <script src="../resources/js-test.js"></script> |
| <script src="resources/biquad-testing.js"></script> |
| </head> |
| |
| <body> |
| |
| <div id="description"></div> |
| <div id="console"></div> |
| <script> |
| description("Tests DOM exception messages"); |
| |
| var context; |
| var otherContext; |
| var node; |
| var node2; |
| var mode; |
| |
| function runTest() { |
| if (window.testRunner) { |
| testRunner.dumpAsText(); |
| } |
| |
| context = new AudioContext(); |
| otherContext = new AudioContext(); |
| |
| // Test creation of various objects |
| |
| // Invalid number of channels: NotSupportedError |
| shouldThrow("context.createBuffer(99, 1, context.sampleRate)"); |
| // Invalid sample rate: NotSupportedError |
| shouldThrow("context.createBuffer(1, 1, 1)"); |
| shouldThrow("context.createBuffer(1, 1, 1e6)"); |
| // Invalid number of frames: NotSupportedError |
| shouldThrow("context.createBuffer(1, 0, context.sampleRate)"); |
| // Invalid ArrayBuffer (unspecified error) |
| shouldThrow("context.createBuffer(new ArrayBuffer(100), true)"); |
| // Invalid ArrayBuffer (unspecified error) |
| shouldThrow("context.decodeAudioData(null, function() {}, function () {})"); |
| // Invalid sources (unspecified error) |
| shouldThrow("context.createMediaElementSource(null)"); |
| shouldThrow("context.createMediaStreamSource(null)"); |
| // Invalid buffer size: IndexSizeError |
| shouldThrow("context.createScriptProcessor(1, 1, 1)"); |
| // Invalid number of inputs and outputs: IndexSizeError |
| shouldThrow("context.createScriptProcessor(4096, 100, 1)"); |
| shouldThrow("context.createScriptProcessor(4096, 1, 100)"); |
| shouldNotThrow("context.createScriptProcessor()"); |
| shouldNotThrow("context.createScriptProcessor(0)"); |
| |
| // Invalid number of channels: IndexSizeError |
| shouldThrow("context.createChannelSplitter(0)"); |
| shouldThrow("context.createChannelSplitter(99)"); |
| shouldThrow("context.createChannelMerger(0)"); |
| shouldThrow("context.createChannelMerger(99)"); |
| // Invalid real/imag arrays: IndexSizeError |
| shouldThrow("context.createPeriodicWave(null, null)"); |
| shouldThrow("context.createPeriodicWave(new Float32Array(10), null)"); |
| shouldThrow("context.createPeriodicWave(new Float32Array(4100), new Float32Array(4100))"); |
| // Real and imaginary arrays must have the same size: IndexSizeError |
| shouldThrow("context.createPeriodicWave(new Float32Array(10), new Float32Array(7))"); |
| |
| |
| // Analysers |
| node = context.createAnalyser(); |
| // Invalid fftSize: IndexSizeError |
| shouldThrow("node.fftSize = 42"); |
| shouldThrow("node.fftSize = 16"); |
| shouldThrow("node.fftSize = 4096"); |
| |
| shouldThrow("node.minDecibels = -10"); |
| shouldThrow("node.maxDecibels = -150"); |
| shouldThrow("node.smoothingTimeConstant = -0.1"); |
| shouldThrow("node.smoothingTimeConstant = 1.5"); |
| |
| // AudioBuffers |
| node = context.createBuffer(1,1, context.sampleRate); |
| // Invalid channel index: IndexSizeError |
| shouldThrow("node.getChannelData(2)"); |
| |
| // AudioNode connections |
| node = context.createGain(); |
| node2 = context.createGain(); |
| // Invalid destination node (unspecified error) |
| shouldThrow("node.connect(null, 0, 0)"); |
| // Invalid input or output index: IndexSizeError |
| shouldThrow("node.connect(context.destination, 100, 0)"); |
| shouldThrow("node.connect(context.destination, 0, 100)"); |
| shouldThrow("node.connect(node2.gain, 100)"); |
| shouldThrow("node.disconnect(99)"); |
| // Can't connect to a different context (unspecified error) |
| shouldThrow("node.connect(otherContext.destination)"); |
| |
| // Invalid channel count: NotSupportedError |
| shouldThrow("node.channelCount = 99"); |
| // Invalid mode or interpretation (unspecified error) |
| mode = "fancy"; |
| shouldThrow("node.channelCountMode = mode"); |
| shouldThrow("node.channelInterpretation = mode"); |
| |
| // Destination: IndexSizeError |
| shouldThrow("context.destination.channelCount = 99"); |
| |
| // Delay nodes are tested elsewhere, so don't duplicate that work here. |
| |
| // OfflineAudioContext |
| // Invalid number of channels (unspecified error) |
| shouldThrow("new OfflineAudioContext(99, 100, context.sampleRate)"); |
| // Invalid sample rate. (unspecified error) |
| shouldThrow("new OfflineAudioContext(1, 100, 1)"); |
| shouldThrow("new OfflineAudioContext(1, 100, 1e6)"); |
| // Invalid frame length (crbug.com/351277) |
| shouldThrow("new OfflineAudioContext(1, -88200000000000, 44100)"); |
| |
| // WaveShaper types |
| node = context.createWaveShaper(); |
| shouldThrow("node.oversample = '9x'"); |
| |
| // Start/stop for AudioBufferSourceNodes |
| buffer = context.createBuffer(1,1, context.sampleRate); |
| shouldNotThrow("source = context.createBufferSource()"); |
| shouldNotThrow("source.buffer = buffer"); |
| shouldNotThrow("source.start()"); |
| shouldNotThrow("source.stop()"); |
| |
| // It's not clear from the spec, but I think it's valid to call start(). The spec is silent on |
| // what happens if we call stop() afterwards, so don't call it. |
| shouldNotThrow("source = context.createBufferSource()"); |
| shouldNotThrow("source.start()"); |
| |
| buffer = context.createBuffer(1,1, context.sampleRate); |
| shouldNotThrow("source = context.createBufferSource()"); |
| shouldNotThrow("source.buffer = buffer"); |
| shouldThrow("source.stop()"); |
| |
| buffer = context.createBuffer(1,1, context.sampleRate); |
| shouldNotThrow("source = context.createBufferSource()"); |
| shouldNotThrow("source.buffer = buffer"); |
| shouldNotThrow("source.start()"); |
| shouldThrow("source.start()"); |
| |
| buffer = context.createBuffer(1,1, context.sampleRate); |
| shouldNotThrow("source = context.createBufferSource()"); |
| shouldNotThrow("source.buffer = buffer"); |
| shouldNotThrow("source.start()"); |
| shouldNotThrow("source.stop()"); |
| |
| |
| // Start/stop for OscillatorNodes |
| shouldNotThrow("source = context.createOscillator()"); |
| shouldNotThrow("source.start()"); |
| shouldNotThrow("source.stop()"); |
| |
| shouldNotThrow("osc = context.createOscillator()"); |
| shouldThrow("osc.stop()"); |
| shouldNotThrow("osc1 = context.createOscillator()"); |
| shouldNotThrow("osc1.start()"); |
| shouldNotThrow("osc1.stop()"); |
| |
| // exponentialRampToValue should throw on non-positive target values. |
| node = context.createGain(); |
| node.connect(context.destination); |
| shouldThrow("node.gain.exponentialRampToValueAtTime(-1, 0.1)"); |
| shouldThrow("node.gain.exponentialRampToValueAtTime(0, 0.1)"); |
| |
| // Convolver buffer rate must match context rate. Create on offline context so we |
| // specify the context rate exactly, in case the test is run on platforms with different |
| // HW sample rates. |
| shouldNotThrow("oc = new OfflineAudioContext(1, 44100, 44100)"); |
| shouldNotThrow("conv = oc.createConvolver()"); |
| shouldThrow("conv.buffer = oc.createBuffer(1, 100, 22050)"); |
| } |
| |
| runTest(); |
| successfullyParsed = true; |
| |
| </script> |
| </body> |
| </html> |