Bug 991981 - ArrayBufferInputStream test. r=sfink, r=jdm
authorJeff Walden <jwalden@mit.edu>
Fri, 04 Apr 2014 17:34:09 -0700
changeset 210238 3d859600949d0aeac0b829acc3facb8083ed69d9
parent 210237 40394288cb644aee43b7a14af03ab4a5755a1593
child 210239 3a3027f77f625bab53a9d1f7e300090904f70021
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewerssfink, jdm
bugs991981
milestone35.0a1
Bug 991981 - ArrayBufferInputStream test. r=sfink, r=jdm
netwerk/test/mochitests/mochitest.ini
netwerk/test/mochitests/test_arraybufferinputstream.html
--- a/netwerk/test/mochitests/mochitest.ini
+++ b/netwerk/test/mochitests/mochitest.ini
@@ -1,14 +1,15 @@
 [DEFAULT]
 skip-if = buildapp == 'b2g' || e10s
 support-files =
   method.sjs
   partial_content.sjs
   user_agent.sjs
   user_agent_update.sjs
 
+[test_arraybufferinputstream.html]
 [test_partially_cached_content.html]
 [test_uri_scheme.html]
 [test_user_agent_overrides.html]
 [test_user_agent_updates.html]
 [test_user_agent_updates_reset.html]
-[test_xhr_method_case.html]
\ No newline at end of file
+[test_xhr_method_case.html]
new file mode 100644
--- /dev/null
+++ b/netwerk/test/mochitests/test_arraybufferinputstream.html
@@ -0,0 +1,63 @@
+<!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);
+
+  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
+  {
+    sis.read(1);
+    ok(false, "reading from stream shouldn't have worked");
+  }
+  catch (e)
+  {
+    ok(e.result === Cr.NS_BASE_STREAM_CLOSED,
+       "neutering underneath an input stream should close it");
+  }
+}
+
+test();
+</script>
+</head>
+<body>
+<p id="display"></p>
+<div id="content" style="display: none"></div>
+<pre id="test">
+</pre>
+</body>
+</html>