docshell/test/chrome/bug112564_window.xul

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 <?xml version="1.0"?>
     3 <!-- This Source Code Form is subject to the terms of the Mozilla Public
     4    - License, v. 2.0. If a copy of the MPL was not distributed with this
     5    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
     7 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
     9 <window id="112564Test"
    10         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
    11         width="600"
    12         height="600"
    13         onload="onLoad();"
    14         title="112564 test">
    16   <script type="application/javascript"><![CDATA[
    17     const LISTEN_EVENTS = ["load", "unload", "pageshow", "pagehide"];
    19     var gBrowser;
    20     var gTestsIterator;
    21     var gExpected = [];
    23     function ok(condition, message) {
    24       window.opener.wrappedJSObject.SimpleTest.ok(condition, message);
    25     }
    27     function is(a, b, message) {
    28       window.opener.wrappedJSObject.SimpleTest.is(a, b, message);
    29     }
    31     function finish() {
    32       for each (let eventType in LISTEN_EVENTS) {
    33         gBrowser.removeEventListener(eventType, eventListener, true);
    34       }
    36       // Work around bug 467960
    37       var history = gBrowser.webNavigation.sessionHistory;
    38       history.PurgeHistory(history.count);
    40       window.close();
    41       window.opener.wrappedJSObject.SimpleTest.finish();
    42     }
    44     function onLoad() {
    45       gBrowser = document.getElementById("content");
    46       for each (let eventType in LISTEN_EVENTS) {
    47         gBrowser.addEventListener(eventType, eventListener, true);
    48       }
    50       gTestsIterator = testsIterator();
    51       nextTest();
    52     }
    54     function eventListener(event) {
    55       ok(gExpected.length >= 1, "Unexpected event " + event.type);
    56       if (gExpected.length == 0) {
    57         // in case of unexpected event, try to continue anyway
    58         setTimeout(nextTest, 0);
    59         return;
    60       }
    62       var exp = gExpected.shift();
    63       is(event.type, exp.type, "Invalid event received");
    64       if (typeof(exp.persisted) != "undefined") {
    65         is(event.persisted, exp.persisted, "Invalid persisted state");
    66       }
    67       if (exp.title) {
    68         ok(event.originalTarget instanceof HTMLDocument,
    69            "originalTarget not a HTMLDocument");
    70         is(event.originalTarget.title, exp.title, "titles don't match");
    71       }
    73       if (gExpected.length == 0) {
    74         setTimeout(nextTest, 0);
    75       }
    76     }
    78     function nextTest() {
    79       try {
    80         gTestsIterator.next();
    81       } catch (err if err instanceof StopIteration) {
    82         finish();
    83       }
    84     }
    86     function testsIterator() {
    87       // Load a secure page with a no-store header, followed by a simple page
    88       // On pagehide, first page should report it is not being persisted
    89       var test1DocURI = "https://example.com:443/tests/docshell/test/chrome/112564_nocache.html";
    91       gExpected = [{type: "pagehide", persisted: true},
    92                    {type: "load", title: "test1"},
    93                    {type: "pageshow", title: "test1", persisted: false}];
    94       gBrowser.loadURI(test1DocURI);
    95       yield undefined;
    97       var test2Doc = "data:text/html,<html><head><title>test2</title></head>" +
    98                      "<body>test2</body></html>";
   100       gExpected = [{type: "pagehide", title: "test1", persisted: false},
   101                    {type: "unload", title: "test1"},
   102                    {type: "load", title: "test2"},
   103                    {type: "pageshow", title: "test2", persisted: false}];
   104       gBrowser.loadURI(test2Doc);
   105       yield undefined;
   107       // Now go back in history. First page should not have been cached.
   108       // Check persisted property to confirm
   109       gExpected = [{type: "pagehide", title: "test2", persisted: true},
   110                    {type: "load", title: "test1"},
   111                    {type: "pageshow", title: "test1", persisted: false}];
   112       gBrowser.goBack();
   113       yield undefined;
   114     }
   115   ]]></script>
   117   <browser type="content-primary" flex="1" id="content" src="about:blank"/>
   118 </window>

mercurial