tor-browser

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

browser_loadURI_postdata.js (1347B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 const gPostData = "postdata=true";
      5 const gUrl =
      6  "http://mochi.test:8888/browser/docshell/test/browser/print_postdata.sjs";
      7 
      8 add_task(async function test_loadURI_persists_postData() {
      9  waitForExplicitFinish();
     10 
     11  let tab = (gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser));
     12  registerCleanupFunction(function () {
     13    gBrowser.removeTab(tab);
     14  });
     15 
     16  var dataStream = Cc["@mozilla.org/io/string-input-stream;1"].createInstance(
     17    Ci.nsIStringInputStream
     18  );
     19  dataStream.setByteStringData(gPostData);
     20 
     21  var postStream = Cc[
     22    "@mozilla.org/network/mime-input-stream;1"
     23  ].createInstance(Ci.nsIMIMEInputStream);
     24  postStream.addHeader("Content-Type", "application/x-www-form-urlencoded");
     25  postStream.setData(dataStream);
     26  var systemPrincipal = Cc["@mozilla.org/systemprincipal;1"].getService(
     27    Ci.nsIPrincipal
     28  );
     29 
     30  tab.linkedBrowser.loadURI(Services.io.newURI(gUrl), {
     31    triggeringPrincipal: systemPrincipal,
     32    postData: postStream,
     33  });
     34  await BrowserTestUtils.browserLoaded(tab.linkedBrowser, false, gUrl);
     35  let body = await SpecialPowers.spawn(
     36    tab.linkedBrowser,
     37    [],
     38    () => content.document.body.textContent
     39  );
     40  is(body, gPostData, "post data was submitted correctly");
     41  finish();
     42 });