diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /dom/media/webaudio/test/test_AudioBuffer.html | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'dom/media/webaudio/test/test_AudioBuffer.html')
-rw-r--r-- | dom/media/webaudio/test/test_AudioBuffer.html | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/dom/media/webaudio/test/test_AudioBuffer.html b/dom/media/webaudio/test/test_AudioBuffer.html new file mode 100644 index 000000000..82bfdd420 --- /dev/null +++ b/dom/media/webaudio/test/test_AudioBuffer.html @@ -0,0 +1,105 @@ +<!DOCTYPE HTML> +<html> +<head> + <title>Test whether we can create an AudioContext interface</title> + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> +</head> +<body> +<pre id="test"> +<script src="webaudio.js" type="text/javascript"></script> +<script class="testbody" type="text/javascript"> + +SimpleTest.waitForExplicitFinish(); +addLoadEvent(function() { + var context = new AudioContext(); + var buffer = context.createBuffer(2, 2048, context.sampleRate); + SpecialPowers.gc(); // Make sure that our channels are accessible after GC + ok(buffer, "Buffer was allocated successfully"); + is(buffer.sampleRate, context.sampleRate, "Correct sample rate"); + is(buffer.length, 2048, "Correct length"); + ok(Math.abs(buffer.duration - 2048 / context.sampleRate) < 0.0001, "Correct duration"); + is(buffer.numberOfChannels, 2, "Correct number of channels"); + for (var i = 0; i < buffer.numberOfChannels; ++i) { + var buf = buffer.getChannelData(i); + ok(buf, "Buffer index " + i + " exists"); + ok(buf instanceof Float32Array, "Result is a typed array"); + is(buf.length, buffer.length, "Correct length"); + var foundNonZero = false; + for (var j = 0; j < buf.length; ++j) { + if (buf[j] != 0) { + foundNonZero = true; + break; + } + buf[j] = j; + } + ok(!foundNonZero, "Buffer " + i + " should be initialized to 0"); + } + + // Now test copying the channel data out of a normal buffer + var copy = new Float32Array(100); + buffer.copyFromChannel(copy, 0, 1024); + for (var i = 0; i < copy.length; ++i) { + is(copy[i], 1024 + i, "Correct sample"); + } + + // Test copying the channel data out of a playing buffer + var srcNode = context.createBufferSource(); + srcNode.buffer = buffer; + srcNode.start(0); + copy = new Float32Array(100); + buffer.copyFromChannel(copy, 0, 1024); + for (var i = 0; i < copy.length; ++i) { + is(copy[i], 1024 + i, "Correct sample"); + } + + // Test copying to the channel data + var newData = new Float32Array(200); + buffer.copyToChannel(newData, 0, 100); + var changedData = buffer.getChannelData(0); + for (var i = 0; i < changedData.length; ++i) { + if (i < 100 || i >= 300) { + is(changedData[i], i, "Untouched sample"); + } else { + is(changedData[i], 0, "Correct sample"); + } + } + + // Now, detach the array buffer + var worker = new Worker("audioBufferSourceNodeDetached_worker.js"); + var data = buffer.getChannelData(0).buffer; + worker.postMessage(data, [data]); + SpecialPowers.gc(); + + expectException(function() { + buffer.copyFromChannel(copy, 0, 1024); + }, DOMException.INDEX_SIZE_ERR); + + expectException(function() { + buffer.copyToChannel(newData, 0, 100); + }, DOMException.INDEX_SIZE_ERR); + + expectException(function() { + context.createBuffer(2, 2048, 7999); + }, DOMException.INDEX_SIZE_ERR); + expectException(function() { + context.createBuffer(2, 2048, 192001); + }, DOMException.INDEX_SIZE_ERR); + context.createBuffer(2, 2048, 8000); // no exception + context.createBuffer(2, 2048, 192000); // no exception + context.createBuffer(32, 2048, 48000); // no exception + // Null length + expectException(function() { + context.createBuffer(2, 0, 48000); + }, DOMException.INDEX_SIZE_ERR); + // Null number of channels + expectException(function() { + context.createBuffer(0, 2048, 48000); + }, DOMException.INDEX_SIZE_ERR); + SimpleTest.finish(); +}); + +</script> +</pre> +</body> +</html> |