tor-browser

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

test_aboutRestartRequired.xhtml (3398B)


      1 <?xml version="1.0"?>
      2 <!-- This Source Code Form is subject to the terms of the Mozilla Public
      3   - License, v. 2.0. If a copy of the MPL was not distributed with this
      4   - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
      5 
      6 <?xml-stylesheet href="chrome://global/skin/global.css" type="text/css"?>
      7 <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
      8 
      9 <window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
     10  <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" />
     11  <iframe type="content" id="frame1"/>
     12  <iframe type="content" id="frame2" onload="doTest()"/>
     13  <script type="application/javascript"><![CDATA[
     14    SimpleTest.waitForExplicitFinish();
     15 
     16    // Load error pages do not fire "load" events, so let's use a progressListener.
     17    function waitForErrorPage(frame) {
     18      return new Promise(resolve => {
     19        let progressListener = {
     20          onLocationChange(aWebProgress, aRequest, aLocation, aFlags) {
     21            if (aFlags & Ci.nsIWebProgressListener.LOCATION_CHANGE_ERROR_PAGE) {
     22              frame.docShell.QueryInterface(Ci.nsIInterfaceRequestor)
     23                            .getInterface(Ci.nsIWebProgress)
     24                            .removeProgressListener(progressListener,
     25                                                    Ci.nsIWebProgress.NOTIFY_LOCATION);
     26 
     27              resolve();
     28            }
     29          },
     30 
     31          QueryInterface: ChromeUtils.generateQI(["nsIWebProgressListener",
     32                                                  "nsISupportsWeakReference"])
     33        };
     34 
     35        frame.docShell.QueryInterface(Ci.nsIInterfaceRequestor)
     36                      .getInterface(Ci.nsIWebProgress)
     37                      .addProgressListener(progressListener,
     38                                           Ci.nsIWebProgress.NOTIFY_LOCATION);
     39      });
     40    }
     41 
     42  function doTest() {
     43    (async function testBody() {
     44      let frame1 = document.getElementById("frame1");
     45      let frame2 = document.getElementById("frame2");
     46      // eslint-disable-next-line @microsoft/sdl/no-insecure-url
     47      let uri1 = Services.io.newURI("http://www.example.com/1");
     48      // eslint-disable-next-line @microsoft/sdl/no-insecure-url
     49      let uri2 = Services.io.newURI("http://www.example.com/2");
     50 
     51      let errorPageReady = waitForErrorPage(frame1);
     52      frame1.docShell.displayLoadError(Cr.NS_ERROR_BUILDID_MISMATCH, uri1, null);
     53 
     54      await errorPageReady;
     55      frame1.docShell.chromeEventHandler.removeAttribute("crashedPageTitle");
     56 
     57      SimpleTest.is(frame1.contentDocument.documentURI,
     58                    "about:restartrequired?e=restartrequired&u=http%3A//www.example.com/1&c=UTF-8&d=%20",
     59                    "Correct about:restartrequired displayed for page with title.");
     60 
     61      errorPageReady = waitForErrorPage(frame2);
     62      frame2.docShell.displayLoadError(Cr.NS_ERROR_BUILDID_MISMATCH, uri2, null);
     63 
     64      await errorPageReady;
     65 
     66      SimpleTest.is(frame2.contentDocument.documentURI,
     67                    "about:restartrequired?e=restartrequired&u=http%3A//www.example.com/2&c=UTF-8&d=%20",
     68                    "Correct about:restartrequired displayed for page with no title.");
     69 
     70      SimpleTest.finish();
     71    })().catch(ex => SimpleTest.ok(false, ex));
     72  }
     73  ]]></script>
     74 
     75  <body xmlns="http://www.w3.org/1999/xhtml" style="height: 300px; overflow: auto;" />
     76 </window>