summaryrefslogtreecommitdiffstats
path: root/netwerk/test/mochitests/test_arraybufferinputstream_large.html
blob: 33922d6e37718567b67235de5f1f8379636c4468 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  <title>ArrayBuffer stream with large ArrayBuffer test</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />

<script type="text/javascript">
add_task(async function testLargeArrayBuffer() {
  let ab = new ArrayBuffer(4.5 * 1024 * 1024 * 1024); // 4.5 GB.
  let ta = new Uint8Array(ab);

  const { Cc, Ci } = SpecialPowers;
  let abis = Cc["@mozilla.org/io/arraybuffer-input-stream;1"]
               .createInstance(Ci.nsIArrayBufferInputStream);

  let sis = Cc["@mozilla.org/scriptableinputstream;1"]
              .createInstance(Ci.nsIScriptableInputStream);
  sis.init(abis);

  // The stream currently doesn't support more than UINT32_MAX bytes.
  let ex;
  try {
    abis.setData(ab, 0, ab.byteLength);
  } catch (e) {
    ex = e;
  }
  is(ex.message.includes("NS_ERROR_ILLEGAL_VALUE"), true, "Expecting exception");

  // Reading a small slice of the large ArrayBuffer is fine, even near the end.
  ta[ta.length - 10] = "a".charCodeAt(0);
  ta[ta.length - 9] = "b".charCodeAt(0);
  ta[ta.length - 8] = "c".charCodeAt(0);
  abis.setData(ab, ab.byteLength - 10, 2);
  is(sis.read(1), "a", "should read 'a' after init");
  is(sis.read(1), "b", "should read 'b' after 'a'");
  is(sis.read(1), "", "Should be done reading data");
});
</script>

</head>
<body>
</body>
</html>