docshell/test/browser/browser_loadURI.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/docshell/test/browser/browser_loadURI.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,45 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +const Cc = Components.classes;
     1.8 +const Ci = Components.interfaces;
     1.9 +
    1.10 +const gPostData = "postdata=true";
    1.11 +
    1.12 +function test() {
    1.13 +  waitForExplicitFinish();
    1.14 +
    1.15 +  let tab = gBrowser.selectedTab = gBrowser.addTab();
    1.16 +  registerCleanupFunction(function () {
    1.17 +    gBrowser.removeTab(tab);
    1.18 +  });
    1.19 +
    1.20 +  var dataStream = Cc["@mozilla.org/io/string-input-stream;1"].
    1.21 +                   createInstance(Ci.nsIStringInputStream);
    1.22 +  dataStream.data = gPostData;
    1.23 +
    1.24 +  var postStream = Cc["@mozilla.org/network/mime-input-stream;1"].
    1.25 +                   createInstance(Ci.nsIMIMEInputStream);
    1.26 +  postStream.addHeader("Content-Type", "application/x-www-form-urlencoded");
    1.27 +  postStream.addContentLength = true;
    1.28 +  postStream.setData(dataStream);
    1.29 +
    1.30 +  tab.linkedBrowser.loadURIWithFlags("http://mochi.test:8888/browser/docshell/test/browser/print_postdata.sjs", 0, null, null, postStream);
    1.31 +  onTabLoad(tab, function (doc) {
    1.32 +    var bodyText = doc.body.textContent;
    1.33 +    is(bodyText, gPostData, "post data was submitted correctly");
    1.34 +    finish();
    1.35 +  });
    1.36 +}
    1.37 +
    1.38 +function onTabLoad(tab, cb) {
    1.39 +  tab.linkedBrowser.addEventListener("load", function listener(event) {
    1.40 +    if (event.originalTarget != tab.linkedBrowser.contentDocument ||
    1.41 +        event.target.location.href == "about:blank") {
    1.42 +      info("skipping spurious load event");
    1.43 +      return;
    1.44 +    }
    1.45 +    tab.linkedBrowser.removeEventListener("load", listener, true);
    1.46 +    cb(tab.linkedBrowser.contentDocument);
    1.47 +  }, true);
    1.48 +}

mercurial