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