tenfourfox/netwerk/test/mochitests/test_arraybufferinputstream.html
Cameron Kaiser c9b2922b70 hello FPR
2017-04-19 00:56:45 -07:00

63 lines
1.4 KiB
HTML

<!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 neuter(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");
neuter(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");
}
}
test();
</script>
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none"></div>
<pre id="test">
</pre>
</body>
</html>