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 /netwerk/test/mochitests/test_arraybufferinputstream.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 'netwerk/test/mochitests/test_arraybufferinputstream.html')
-rw-r--r-- | netwerk/test/mochitests/test_arraybufferinputstream.html | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/netwerk/test/mochitests/test_arraybufferinputstream.html b/netwerk/test/mochitests/test_arraybufferinputstream.html new file mode 100644 index 000000000..eb7796ef2 --- /dev/null +++ b/netwerk/test/mochitests/test_arraybufferinputstream.html @@ -0,0 +1,89 @@ +<!DOCTYPE HTML> +<html> +<!-- +--> +<head> + <title>ArrayBuffer stream test</title> + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> + +<script type="text/javascript"> +function detachArrayBuffer(ab) +{ + var w = new Worker("data:application/javascript,"); + w.postMessage(ab, [ab]); +} + +function test() +{ + var ab = new ArrayBuffer(4000); + var ta = new Uint8Array(ab); + ta[0] = 'a'.charCodeAt(0); + ta[1] = 'b'.charCodeAt(0); + + const Cc = SpecialPowers.Cc, Ci = SpecialPowers.Ci, Cr = SpecialPowers.Cr; + var abis = Cc["@mozilla.org/io/arraybuffer-input-stream;1"] + .createInstance(Ci.nsIArrayBufferInputStream); + + var sis = Cc["@mozilla.org/scriptableinputstream;1"] + .createInstance(Ci.nsIScriptableInputStream); + sis.init(abis); + + is(sis.read(1), "", "should read no data from an uninitialized ABIS"); + + abis.setData(ab, 0, 256 * 1024); + + is(sis.read(1), "a", "should read 'a' after init"); + + detachArrayBuffer(ab); + + SpecialPowers.forceGC(); + SpecialPowers.forceGC(); + + try + { + is(sis.read(1), "b", "should read 'b' after detaching buffer"); + } + catch (e) + { + ok(false, "reading from stream should have worked"); + } + + // A regression test for bug 1265076. Previously, overflowing + // the internal buffer from readSegments would cause incorrect + // copying. The constant mirrors the value in + // ArrayBufferInputStream::readSegments. + var size = 8192; + ab = new ArrayBuffer(2 * size); + ta = new Uint8Array(ab); + + var i; + for (i = 0; i < size; ++i) { + ta[i] = 'x'.charCodeAt(0); + } + for (i = 0; i < size; ++i) { + ta[size + i] = 'y'.charCodeAt(0); + } + + abis = Cc["@mozilla.org/io/arraybuffer-input-stream;1"] + .createInstance(Ci.nsIArrayBufferInputStream); + abis.setData(ab, 0, 2 * size); + + sis = Cc["@mozilla.org/scriptableinputstream;1"] + .createInstance(Ci.nsIScriptableInputStream); + sis.init(abis); + + var result = sis.read(2 * size); + is(result, "x".repeat(size) + "y".repeat(size), "correctly read the data"); +} + +test(); +</script> +</head> +<body> +<p id="display"></p> +<div id="content" style="display: none"></div> +<pre id="test"> +</pre> +</body> +</html> |