1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
<?xml version="1.0"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<window id="396519Test"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
width="600"
height="600"
onload="onLoad();"
title="396519 test">
<script type="application/javascript"><![CDATA[
const {BrowserTestUtils} = ChromeUtils.import("resource://testing-common/BrowserTestUtils.jsm");
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
Services.prefs.setBoolPref("browser.navigation.requireUserInteraction", false);
const LISTEN_EVENTS = ["pageshow"];
var gBrowser;
var gTestCount = 0;
var gTestsIterator;
var gExpected = [];
function ok(condition, message) {
window.arguments[0].SimpleTest.ok(condition, message);
}
function is(a, b, message) {
window.arguments[0].SimpleTest.is(a, b, message);
}
function finish() {
for (let eventType of LISTEN_EVENTS) {
gBrowser.removeEventListener(eventType, eventListener, true);
}
window.close();
window.arguments[0].SimpleTest.finish();
}
function onLoad() {
gBrowser = document.getElementById("content");
for (let eventType of LISTEN_EVENTS) {
gBrowser.addEventListener(eventType, eventListener, true);
}
gTestsIterator = testsIterator();
nextTest();
}
function eventListener(event) {
// we're in pageshow, but we need to let that finish
// content eviction and saving happen during pageshow, so when doTest
// runs, we should should be in a testable state
setTimeout(doTest, 0);
}
function doTest() {
let history;
if (SpecialPowers.Services.appinfo.sessionHistoryInParent) {
history = gBrowser.browsingContext.sessionHistory;
} else {
history = gBrowser.webNavigation.sessionHistory.legacySHistory;
}
if (history.count == gExpected.length) {
for (var i=0; i<history.count; i++) {
var shEntry = history.getEntryAtIndex(i).
QueryInterface(Ci.nsISHEntry);
is(!!shEntry.contentViewer, gExpected[i], "content viewer "+i+", test "+gTestCount);
}
// Make sure none of the SHEntries share bfcache entries with one
// another.
for (var i = 0; i < history.count; i++) {
for (var j = 0; j < history.count; j++) {
if (j == i)
continue;
let shentry1 = history.getEntryAtIndex(i)
.QueryInterface(Ci.nsISHEntry);
let shentry2 = history.getEntryAtIndex(j)
.QueryInterface(Ci.nsISHEntry);
ok(!shentry1.sharesDocumentWith(shentry2),
'Test ' + gTestCount + ': shentry[' + i + "] shouldn't " +
"share document with shentry[" + j + ']');
}
}
}
else {
is(history.count, gExpected.length, "Wrong history length in test "+gTestCount);
}
setTimeout(nextTest, 0);
}
function nextTest() {
gTestsIterator.next();
}
function* testsIterator() {
// Tests 1 + 2:
// Back/forward between two simple documents. Bfcache will be used.
var test1Doc = "data:text/html,<html><head><title>test1</title></head>" +
"<body>test1</body></html>";
gTestCount++;
gExpected = [false];
BrowserTestUtils.loadURI(gBrowser, test1Doc);
yield undefined;
gTestCount++;
gExpected = [true, false];
var test2Doc = test1Doc.replace(/1/,"2");
BrowserTestUtils.loadURI(gBrowser, test2Doc);
yield undefined;
gTestCount++;
gExpected = [true, true, false];
BrowserTestUtils.loadURI(gBrowser, test1Doc);
yield undefined;
gTestCount++;
gExpected = [true, true, true, false];
BrowserTestUtils.loadURI(gBrowser, test2Doc);
yield undefined;
gTestCount++;
gExpected = [false, true, true, true, false];
BrowserTestUtils.loadURI(gBrowser, test1Doc);
yield undefined;
gTestCount++;
gExpected = [false, false, true, true, true, false];
BrowserTestUtils.loadURI(gBrowser, test2Doc);
yield undefined;
gTestCount++;
gExpected = [false, false, true, true, false, true];
gBrowser.goBack();
yield undefined;
gTestCount++;
gExpected = [false, false, true, true, true, false];
gBrowser.goForward();
yield undefined;
gTestCount++;
gExpected = [false, false, true, true, true, false];
gBrowser.gotoIndex(1);
yield undefined;
gTestCount++;
gExpected = [false, true, true, true, false, false];
gBrowser.goBack();
yield undefined;
gTestCount++;
gExpected = [false, false, true, true, false, false];
gBrowser.gotoIndex(5);
yield undefined;
Services.prefs.clearUserPref("browser.navigation.requireUserInteraction");
finish();
}
]]></script>
<browser type="content" primary="true" flex="1" id="content" src="about:blank"/>
</window>
|