docshell/test/chrome/bug396519_window.xul

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:f8429876fae5
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="396519Test"
10 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
11 width="600"
12 height="600"
13 onload="onLoad();"
14 title="396519 test">
15
16 <script type="application/javascript"><![CDATA[
17
18 const LISTEN_EVENTS = ["pageshow"];
19
20 const Cc = Components.classes;
21 const Ci = Components.interfaces;
22
23 var gBrowser;
24 var gTestCount = 0;
25 var gTestsIterator;
26 var gExpected = [];
27
28 function ok(condition, message) {
29 window.opener.wrappedJSObject.SimpleTest.ok(condition, message);
30 }
31 function is(a, b, message) {
32 window.opener.wrappedJSObject.SimpleTest.is(a, b, message);
33 }
34 function finish() {
35 for each (let eventType in LISTEN_EVENTS) {
36 gBrowser.removeEventListener(eventType, eventListener, true);
37 }
38
39 window.close();
40 window.opener.wrappedJSObject.SimpleTest.finish();
41 }
42
43 function onLoad() {
44 gBrowser = document.getElementById("content");
45
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 // we're in pageshow, but we need to let that finish
56 // content eviction and saving happen during pageshow, so when doTest
57 // runs, we should should be in a testable state
58 setTimeout(doTest, 0);
59 }
60
61 function doTest() {
62 var history = gBrowser.webNavigation.sessionHistory;
63 if (history.count == gExpected.length) {
64 for (var i=0; i<history.count; i++) {
65 var shEntry = history.getEntryAtIndex(i,false).
66 QueryInterface(Components.interfaces.nsISHEntry);
67 is(!!shEntry.contentViewer, gExpected[i], "content viewer "+i+", test "+gTestCount);
68 }
69
70 // Make sure none of the SHEntries share bfcache entries with one
71 // another.
72 for (var i = 0; i < history.count; i++) {
73 for (var j = 0; j < history.count; j++) {
74 if (j == i)
75 continue;
76
77 let shentry1 = history.getEntryAtIndex(i, false)
78 .QueryInterface(Ci.nsISHEntry);
79 let shentry2 = history.getEntryAtIndex(j, false)
80 .QueryInterface(Ci.nsISHEntry);
81 ok(!shentry1.sharesDocumentWith(shentry2),
82 'Test ' + gTestCount + ': shentry[' + i + "] shouldn't " +
83 "share document with shentry[" + j + ']');
84 }
85 }
86 }
87 else {
88 is(history.count, gExpected.length, "Wrong history length in test "+gTestCount);
89 }
90
91 setTimeout(nextTest, 0);
92 }
93
94 function nextTest() {
95 try {
96 gTestsIterator.next();
97 } catch (err if err instanceof StopIteration) {
98 finish();
99 }
100 }
101
102 function testsIterator() {
103
104 // Tests 1 + 2:
105 // Back/forward between two simple documents. Bfcache will be used.
106
107 var test1Doc = "data:text/html,<html><head><title>test1</title></head>" +
108 "<body>test1</body></html>";
109
110 gTestCount++;
111 gExpected = [false];
112 gBrowser.loadURI(test1Doc);
113 yield undefined;
114
115 gTestCount++;
116 gExpected = [true, false];
117 var test2Doc = test1Doc.replace(/1/,"2");
118 gBrowser.loadURI(test2Doc);
119 yield undefined;
120
121 gTestCount++;
122 gExpected = [true, true, false];
123 gBrowser.loadURI(test1Doc);
124 yield undefined;
125
126 gTestCount++;
127 gExpected = [true, true, true, false];
128 gBrowser.loadURI(test2Doc);
129 yield undefined;
130
131 gTestCount++;
132 gExpected = [false, true, true, true, false];
133 gBrowser.loadURI(test1Doc);
134 yield undefined;
135
136 gTestCount++;
137 gExpected = [false, false, true, true, true, false];
138 gBrowser.loadURI(test2Doc);
139 yield undefined;
140
141 gTestCount++;
142 gExpected = [false, false, true, true, false, true];
143 gBrowser.goBack();
144 yield undefined;
145
146 gTestCount++;
147 gExpected = [false, false, true, true, true, false];
148 gBrowser.goForward();
149 yield undefined;
150
151 gTestCount++;
152 gExpected = [false, false, true, true, true, false];
153 gBrowser.gotoIndex(1);
154 yield undefined;
155
156 gTestCount++;
157 gExpected = [false, true, true, true, false, false];
158 gBrowser.goBack();
159 yield undefined;
160
161 gTestCount++;
162 gExpected = [false, false, true, true, false, false];
163 gBrowser.gotoIndex(5);
164 yield undefined;
165 }
166 ]]></script>
167
168 <browser type="content-primary" flex="1" id="content" src="about:blank"/>
169 </window>

mercurial