tor-browser

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

test_aboutCrashed.xhtml (3460B)


      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.chromeEventHandler.setAttribute("crashedPageTitle", "pageTitle");
     53      frame1.docShell.displayLoadError(Cr.NS_ERROR_CONTENT_CRASHED, uri1, null);
     54 
     55      await errorPageReady;
     56      frame1.docShell.chromeEventHandler.removeAttribute("crashedPageTitle");
     57 
     58      SimpleTest.is(frame1.contentDocument.documentURI,
     59                    "about:tabcrashed?e=tabcrashed&u=http%3A//www.example.com/1&c=UTF-8&d=pageTitle",
     60                    "Correct about:tabcrashed displayed for page with title.");
     61 
     62      errorPageReady = waitForErrorPage(frame2);
     63      frame2.docShell.displayLoadError(Cr.NS_ERROR_CONTENT_CRASHED, uri2, null);
     64 
     65      await errorPageReady;
     66 
     67      SimpleTest.is(frame2.contentDocument.documentURI,
     68                    "about:tabcrashed?e=tabcrashed&u=http%3A//www.example.com/2&c=UTF-8&d=%20",
     69                    "Correct about:tabcrashed displayed for page with no title.");
     70 
     71      SimpleTest.finish();
     72    })().catch(ex => SimpleTest.ok(false, ex));
     73  }
     74  ]]></script>
     75 
     76  <body xmlns="http://www.w3.org/1999/xhtml" style="height: 300px; overflow: auto;" />
     77 </window>