docshell/test/chrome/bug112564_window.xul

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/docshell/test/chrome/bug112564_window.xul	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,118 @@
     1.4 +<?xml version="1.0"?>
     1.5 +
     1.6 +<!-- This Source Code Form is subject to the terms of the Mozilla Public
     1.7 +   - License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 +   - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
     1.9 +
    1.10 +<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
    1.11 +
    1.12 +<window id="112564Test"
    1.13 +        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
    1.14 +        width="600"
    1.15 +        height="600"
    1.16 +        onload="onLoad();"
    1.17 +        title="112564 test">
    1.18 +
    1.19 +  <script type="application/javascript"><![CDATA[
    1.20 +    const LISTEN_EVENTS = ["load", "unload", "pageshow", "pagehide"];
    1.21 +
    1.22 +    var gBrowser;
    1.23 +    var gTestsIterator;
    1.24 +    var gExpected = [];
    1.25 +
    1.26 +    function ok(condition, message) {
    1.27 +      window.opener.wrappedJSObject.SimpleTest.ok(condition, message);
    1.28 +    }
    1.29 +
    1.30 +    function is(a, b, message) {
    1.31 +      window.opener.wrappedJSObject.SimpleTest.is(a, b, message);
    1.32 +    }
    1.33 +
    1.34 +    function finish() {
    1.35 +      for each (let eventType in LISTEN_EVENTS) {
    1.36 +        gBrowser.removeEventListener(eventType, eventListener, true);
    1.37 +      }
    1.38 +
    1.39 +      // Work around bug 467960
    1.40 +      var history = gBrowser.webNavigation.sessionHistory;
    1.41 +      history.PurgeHistory(history.count);
    1.42 +
    1.43 +      window.close();
    1.44 +      window.opener.wrappedJSObject.SimpleTest.finish();
    1.45 +    }
    1.46 +
    1.47 +    function onLoad() {
    1.48 +      gBrowser = document.getElementById("content");
    1.49 +      for each (let eventType in LISTEN_EVENTS) {
    1.50 +        gBrowser.addEventListener(eventType, eventListener, true);
    1.51 +      }
    1.52 +             
    1.53 +      gTestsIterator = testsIterator();
    1.54 +      nextTest();
    1.55 +    }
    1.56 +
    1.57 +    function eventListener(event) {
    1.58 +      ok(gExpected.length >= 1, "Unexpected event " + event.type);
    1.59 +      if (gExpected.length == 0) {
    1.60 +        // in case of unexpected event, try to continue anyway
    1.61 +        setTimeout(nextTest, 0);
    1.62 +        return;
    1.63 +      }
    1.64 +
    1.65 +      var exp = gExpected.shift();
    1.66 +      is(event.type, exp.type, "Invalid event received");
    1.67 +      if (typeof(exp.persisted) != "undefined") {
    1.68 +        is(event.persisted, exp.persisted, "Invalid persisted state");
    1.69 +      }
    1.70 +      if (exp.title) {
    1.71 +        ok(event.originalTarget instanceof HTMLDocument,
    1.72 +           "originalTarget not a HTMLDocument");
    1.73 +        is(event.originalTarget.title, exp.title, "titles don't match");
    1.74 +      }
    1.75 +
    1.76 +      if (gExpected.length == 0) {
    1.77 +        setTimeout(nextTest, 0);
    1.78 +      }
    1.79 +    }
    1.80 +
    1.81 +    function nextTest() {
    1.82 +      try {
    1.83 +        gTestsIterator.next();
    1.84 +      } catch (err if err instanceof StopIteration) {
    1.85 +        finish();
    1.86 +      }
    1.87 +    }
    1.88 +
    1.89 +    function testsIterator() {
    1.90 +      // Load a secure page with a no-store header, followed by a simple page
    1.91 +      // On pagehide, first page should report it is not being persisted
    1.92 +      var test1DocURI = "https://example.com:443/tests/docshell/test/chrome/112564_nocache.html";
    1.93 +
    1.94 +      gExpected = [{type: "pagehide", persisted: true},
    1.95 +                   {type: "load", title: "test1"},
    1.96 +                   {type: "pageshow", title: "test1", persisted: false}];
    1.97 +      gBrowser.loadURI(test1DocURI);
    1.98 +      yield undefined;
    1.99 +
   1.100 +      var test2Doc = "data:text/html,<html><head><title>test2</title></head>" +
   1.101 +                     "<body>test2</body></html>";
   1.102 +
   1.103 +      gExpected = [{type: "pagehide", title: "test1", persisted: false},
   1.104 +                   {type: "unload", title: "test1"},
   1.105 +                   {type: "load", title: "test2"},
   1.106 +                   {type: "pageshow", title: "test2", persisted: false}];
   1.107 +      gBrowser.loadURI(test2Doc);
   1.108 +      yield undefined;
   1.109 +
   1.110 +      // Now go back in history. First page should not have been cached.
   1.111 +      // Check persisted property to confirm
   1.112 +      gExpected = [{type: "pagehide", title: "test2", persisted: true},
   1.113 +                   {type: "load", title: "test1"},
   1.114 +                   {type: "pageshow", title: "test1", persisted: false}];
   1.115 +      gBrowser.goBack();
   1.116 +      yield undefined;
   1.117 +    }
   1.118 +  ]]></script>
   1.119 +
   1.120 +  <browser type="content-primary" flex="1" id="content" src="about:blank"/>
   1.121 +</window>

mercurial