browser/base/content/test/chrome/test_aboutCrashed.xul

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/base/content/test/chrome/test_aboutCrashed.xul	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,86 @@
     1.4 +<?xml version="1.0"?>
     1.5 +<!-- This Source Code Form is subject to the terms of the Mozilla Public
     1.6 +   - License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 +   - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
     1.8 +
     1.9 +<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
    1.10 +<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
    1.11 +
    1.12 +<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
    1.13 +  <script type="application/javascript"
    1.14 +          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" />
    1.15 +  <iframe type="content" id="frame1"/>
    1.16 +  <iframe type="content" id="frame2" onload="doTest()"/>
    1.17 +  <script type="application/javascript"><![CDATA[
    1.18 +    const Ci = Components.interfaces;
    1.19 +    const Cu = Components.utils;
    1.20 +
    1.21 +    Cu.import("resource://gre/modules/Services.jsm");
    1.22 +    Cu.import("resource://gre/modules/Task.jsm");
    1.23 +    Cu.import("resource://gre/modules/Promise.jsm");
    1.24 +    Cu.import("resource://gre/modules/XPCOMUtils.jsm");
    1.25 +
    1.26 +    SimpleTest.waitForExplicitFinish();
    1.27 +
    1.28 +    // Load error pages do not fire "load" events, so let's use a progressListener.
    1.29 +    function waitForErrorPage(frame) {
    1.30 +      let errorPageDeferred = Promise.defer();
    1.31 +
    1.32 +      let progressListener = {
    1.33 +        onLocationChange: function(aWebProgress, aRequest, aLocation, aFlags) {
    1.34 +          if (aFlags & Ci.nsIWebProgressListener.LOCATION_CHANGE_ERROR_PAGE) {
    1.35 +            frame.docShell.QueryInterface(Ci.nsIInterfaceRequestor)
    1.36 +                          .getInterface(Ci.nsIWebProgress)
    1.37 +                          .removeProgressListener(progressListener,
    1.38 +                                                  Ci.nsIWebProgress.NOTIFY_LOCATION);
    1.39 +
    1.40 +            errorPageDeferred.resolve();
    1.41 +          }
    1.42 +        },
    1.43 +
    1.44 +        QueryInterface: XPCOMUtils.generateQI([Ci.nsIWebProgressListener,
    1.45 +                                               Ci.nsISupportsWeakReference])
    1.46 +      };
    1.47 +
    1.48 +      frame.docShell.QueryInterface(Ci.nsIInterfaceRequestor)
    1.49 +                    .getInterface(Ci.nsIWebProgress)
    1.50 +                    .addProgressListener(progressListener,
    1.51 +                                         Ci.nsIWebProgress.NOTIFY_LOCATION);
    1.52 +
    1.53 +      return errorPageDeferred.promise;
    1.54 +    }
    1.55 +
    1.56 +  function doTest() {
    1.57 +    Task.spawn(function test_aboutCrashed() {
    1.58 +      let frame1 = document.getElementById("frame1");
    1.59 +      let frame2 = document.getElementById("frame2");
    1.60 +      let uri1 = Services.io.newURI("http://www.example.com/1", null, null);
    1.61 +      let uri2 = Services.io.newURI("http://www.example.com/2", null, null);
    1.62 +
    1.63 +      let errorPageReady = waitForErrorPage(frame1);
    1.64 +      frame1.docShell.chromeEventHandler.setAttribute("crashedPageTitle", "pageTitle");
    1.65 +      frame1.docShell.displayLoadError(Components.results.NS_ERROR_CONTENT_CRASHED, uri1, null);
    1.66 +
    1.67 +      yield errorPageReady;
    1.68 +      frame1.docShell.chromeEventHandler.removeAttribute("crashedPageTitle");
    1.69 +
    1.70 +      SimpleTest.is(frame1.contentDocument.documentURI,
    1.71 +                    "about:tabcrashed?e=tabcrashed&u=http%3A//www.example.com/1&c=UTF-8&f=regular&d=pageTitle",
    1.72 +                    "Correct about:tabcrashed displayed for page with title.");
    1.73 +
    1.74 +      errorPageReady = waitForErrorPage(frame2);
    1.75 +      frame2.docShell.displayLoadError(Components.results.NS_ERROR_CONTENT_CRASHED, uri2, null);
    1.76 +
    1.77 +      yield errorPageReady;
    1.78 +
    1.79 +      SimpleTest.is(frame2.contentDocument.documentURI,
    1.80 +                    "about:tabcrashed?e=tabcrashed&u=http%3A//www.example.com/2&c=UTF-8&f=regular&d=%20",
    1.81 +                    "Correct about:tabcrashed displayed for page with no title.");
    1.82 +
    1.83 +      SimpleTest.finish();
    1.84 +  });
    1.85 +  }
    1.86 +  ]]></script>
    1.87 +
    1.88 +  <body xmlns="http://www.w3.org/1999/xhtml" style="height: 300px; overflow: auto;" />
    1.89 +</window>

mercurial