tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

browser_inputStream_structuredClone.js (1805B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 const URIs = [
      5  "about:about",
      6  "http://example.com/browser/dom/base/test/empty.html",
      7 ];
      8 
      9 async function runTest(input, url) {
     10  let tab = BrowserTestUtils.addTab(gBrowser, url);
     11  let browser = gBrowser.getBrowserForTab(tab);
     12 
     13  await BrowserTestUtils.browserLoaded(browser);
     14 
     15  let stream = Cc["@mozilla.org/io/string-input-stream;1"].createInstance(
     16    Ci.nsIStringInputStream
     17  );
     18  stream.setByteStringData(input);
     19 
     20  let data = {
     21    inputStream: stream,
     22  };
     23 
     24  is(
     25    data.inputStream.available(),
     26    input.length,
     27    "The length of the inputStream matches: " + input.length
     28  );
     29 
     30  // FIXME: SpecialPowers.spawn currently crashes when trying to return
     31  // values containing input streams.
     32  /* eslint-disable no-shadow */
     33  let dataBack = await ContentTask.spawn(browser, data, function (data) {
     34    let dataBack = {
     35      inputStream: data.inputStream,
     36      check: true,
     37    };
     38 
     39    if (content.location.href.startsWith("about:")) {
     40      dataBack.check =
     41        data.inputStream instanceof
     42        content.Components.interfaces.nsIInputStream;
     43    }
     44 
     45    return dataBack;
     46  });
     47  /* eslint-enable no-shadow */
     48 
     49  ok(dataBack.check, "The inputStream is a nsIInputStream also on content.");
     50  ok(
     51    data.inputStream instanceof Ci.nsIInputStream,
     52    "The original object was an inputStream"
     53  );
     54  ok(
     55    dataBack.inputStream instanceof Ci.nsIInputStream,
     56    "We have an inputStream back from the content."
     57  );
     58 
     59  BrowserTestUtils.removeTab(tab);
     60 }
     61 
     62 add_task(async function test() {
     63  let a = "a";
     64  for (let i = 0; i < 25; ++i) {
     65    a += a;
     66  }
     67 
     68  for (let i = 0; i < URIs.length; ++i) {
     69    await runTest("Hello world", URIs[i]);
     70    await runTest(a, URIs[i]);
     71  }
     72 });