|
1 <?xml version="1.0"?> |
|
2 |
|
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/. --> |
|
6 |
|
7 <?xml-stylesheet href="chrome://global/skin" type="text/css"?> |
|
8 |
|
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"> |
|
15 |
|
16 <script type="application/javascript"><![CDATA[ |
|
17 const LISTEN_EVENTS = ["load", "unload", "pageshow", "pagehide"]; |
|
18 |
|
19 var gBrowser; |
|
20 var gTestsIterator; |
|
21 var gExpected = []; |
|
22 |
|
23 function ok(condition, message) { |
|
24 window.opener.wrappedJSObject.SimpleTest.ok(condition, message); |
|
25 } |
|
26 |
|
27 function is(a, b, message) { |
|
28 window.opener.wrappedJSObject.SimpleTest.is(a, b, message); |
|
29 } |
|
30 |
|
31 function finish() { |
|
32 for each (let eventType in LISTEN_EVENTS) { |
|
33 gBrowser.removeEventListener(eventType, eventListener, true); |
|
34 } |
|
35 |
|
36 // Work around bug 467960 |
|
37 var history = gBrowser.webNavigation.sessionHistory; |
|
38 history.PurgeHistory(history.count); |
|
39 |
|
40 window.close(); |
|
41 window.opener.wrappedJSObject.SimpleTest.finish(); |
|
42 } |
|
43 |
|
44 function onLoad() { |
|
45 gBrowser = document.getElementById("content"); |
|
46 for each (let eventType in LISTEN_EVENTS) { |
|
47 gBrowser.addEventListener(eventType, eventListener, true); |
|
48 } |
|
49 |
|
50 gTestsIterator = testsIterator(); |
|
51 nextTest(); |
|
52 } |
|
53 |
|
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 } |
|
61 |
|
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 } |
|
72 |
|
73 if (gExpected.length == 0) { |
|
74 setTimeout(nextTest, 0); |
|
75 } |
|
76 } |
|
77 |
|
78 function nextTest() { |
|
79 try { |
|
80 gTestsIterator.next(); |
|
81 } catch (err if err instanceof StopIteration) { |
|
82 finish(); |
|
83 } |
|
84 } |
|
85 |
|
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"; |
|
90 |
|
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; |
|
96 |
|
97 var test2Doc = "data:text/html,<html><head><title>test2</title></head>" + |
|
98 "<body>test2</body></html>"; |
|
99 |
|
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; |
|
106 |
|
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> |
|
116 |
|
117 <browser type="content-primary" flex="1" id="content" src="about:blank"/> |
|
118 </window> |