tor-browser

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

test_docRedirect.xhtml (2978B)


      1 <?xml version="1.0"?>
      2 <?xml-stylesheet type="text/css" href="chrome://global/skin"?>
      3 <?xml-stylesheet type="text/css" href="/tests/SimpleTest/test.css"?>
      4 <!--
      5 https://bugzilla.mozilla.org/show_bug.cgi?id=1342989
      6 -->
      7 <window title="Mozilla Bug 1342989"
      8        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
      9 
     10  <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
     11 
     12  <script type="application/javascript">
     13  <![CDATA[
     14  SimpleTest.waitForExplicitFinish();
     15 
     16  const WEB_PROGRESS_LISTENER_FLAGS =
     17      Object.keys(Ci.nsIWebProgressListener).filter(
     18    propName => propName.startsWith("STATE_")
     19  );
     20 
     21  function bitFlagsToNames(flags, knownNames, intf) {
     22    return knownNames.map( (F) => {
     23      return (flags & intf[F]) ? F : undefined;
     24    }).filter( (s) => !!s );
     25  }
     26 
     27  var progressListener = {
     28    add(docShell, callback) {
     29      this.callback = callback;
     30      this.docShell = docShell;
     31      docShell.
     32            QueryInterface(Ci.nsIInterfaceRequestor).
     33            getInterface(Ci.nsIWebProgress).
     34            addProgressListener(this, Ci.nsIWebProgress.NOTIFY_STATE_ALL);
     35    },
     36 
     37    finish(success) {
     38      this.docShell.
     39            QueryInterface(Ci.nsIInterfaceRequestor).
     40            getInterface(Ci.nsIWebProgress).
     41            removeProgressListener(this);
     42      this.callback(success);
     43    },
     44 
     45    onStateChange (webProgress, req, flags) {
     46      if (!(flags & Ci.nsIWebProgressListener.STATE_IS_DOCUMENT) &&
     47          !(flags & Ci.nsIWebProgressListener.STATE_IS_REDIRECTED_DOCUMENT))
     48        return;
     49 
     50      var channel = req.QueryInterface(Ci.nsIChannel);
     51 
     52      if (flags & Ci.nsIWebProgressListener.STATE_IS_REDIRECTED_DOCUMENT) {
     53        SimpleTest.is(channel.URI.host, "example.org",
     54            "Should be redirected to example.org (see test_docRedirect.sjs)");
     55        this.finish(true);
     56      }
     57 
     58      // Fail in case we didn't receive document redirection event.
     59      if (flags & Ci.nsIWebProgressListener.STATE_STOP)
     60        this.finish(false);
     61    },
     62 
     63    QueryInterface: ChromeUtils.generateQI([
     64      "nsIWebProgressListener",
     65      "nsISupportsWeakReference",
     66    ]),
     67  }
     68 
     69  var webNav = SpecialPowers.Services.appShell.createWindowlessBrowser(true);
     70  let docShell = webNav.docShell;
     71  let system = Cc["@mozilla.org/systemprincipal;1"].getService(Ci.nsIPrincipal);
     72  docShell.createAboutBlankDocumentViewer(system, system);
     73 
     74  progressListener.add(docShell, function(success) {
     75    webNav.close();
     76    SimpleTest.is(success, true, "Received document redirect event");
     77    SimpleTest.finish();
     78  });
     79 
     80  var win = docShell.docViewer.DOMDocument.defaultView;
     81  // eslint-disable-next-line @microsoft/sdl/no-insecure-url
     82  win.location = "http://example.com/chrome/docshell/test/chrome/test_docRedirect.sjs"
     83 
     84  ]]>
     85  </script>
     86 
     87  <body xmlns="http://www.w3.org/1999/xhtml">
     88  <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1342989"
     89     target="_blank">Mozilla Bug 1342989</a>
     90  </body>
     91 </window>