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=
"215405Test"
10 xmlns=
"http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
16 <script type=
"application/javascript"><![CDATA[
17 const {BrowserTestUtils} = ChromeUtils.importESModule(
18 "resource://testing-common/BrowserTestUtils.sys.mjs"
20 Services.prefs.setBoolPref(
"browser.navigation.requireUserInteraction", false);
22 /* globals SimpleTest, is, isnot, ok */
23 var imports = [
"SimpleTest",
"is",
"isnot",
"ok"];
24 for (var name of imports) {
25 window[name] = window.arguments[
0][name];
29 const nostoreURI =
"http://mochi.test:8888/tests/docshell/test/chrome/" +
30 "215405_nostore.html";
31 const nocacheURI =
"https://example.com:443/tests/docshell/test/chrome/" +
32 "215405_nocache.html";
40 gBrowser.removeEventListener(
"pageshow", eventListener, true);
41 // Work around bug
467960
43 if (SpecialPowers.Services.appinfo.sessionHistoryInParent) {
44 let history = gBrowser.browsingContext.sessionHistory;
45 history.purgeHistory(history.count);
46 historyPurged = Promise.resolve();
48 historyPurged = SpecialPowers.spawn(gBrowser, [], () =
> {
49 let history = docShell.QueryInterface(Ci.nsIWebNavigation).sessionHistory
51 history.purgeHistory(history.count);
55 historyPurged.then(_ =
> {
57 window.arguments[
0].SimpleTest.finish();
62 gBrowser = document.getElementById(
"content");
63 gBrowser.addEventListener(
"pageshow", eventListener, true);
65 gTestsIterator = testsIterator();
69 function eventListener(event) {
70 setTimeout(nextTest,
0);
74 gTestsIterator.next();
77 function* testsIterator() {
79 var testName =
"[nostore]";
81 // Load a page with a no-store header
82 BrowserTestUtils.loadURIString(gBrowser, nostoreURI);
86 // Now that the page has loaded, amend the form contents
87 var form = gBrowser.contentDocument.getElementById(
"inp");
90 // Attempt to scroll the page
91 var originalXPosition = gBrowser.contentWindow.scrollX;
92 var originalYPosition = gBrowser.contentWindow.scrollY;
93 var scrollToX = gBrowser.contentWindow.scrollMaxX;
94 var scrollToY = gBrowser.contentWindow.scrollMaxY;
95 gBrowser.contentWindow.scrollBy(scrollToX, scrollToY);
97 // Save the scroll position for future comparison
98 currScrollX = gBrowser.contentWindow.scrollX;
99 currScrollY = gBrowser.contentWindow.scrollY;
100 isnot(currScrollX, originalXPosition,
101 testName +
" failed to scroll window horizontally");
102 isnot(currScrollY, originalYPosition,
103 testName +
" failed to scroll window vertically");
105 // Load a new document into the browser
106 var simple =
"data:text/html,<html><head><title>test2</title></head>" +
107 "<body>test2</body></html>";
108 BrowserTestUtils.loadURIString(gBrowser, simple);
112 // Now go back in history. First page should not have been cached.
117 // First uncacheable page will now be reloaded. Check scroll position
118 // restored, and form contents not
119 is(gBrowser.contentWindow.scrollX, currScrollX, testName +
120 " horizontal axis scroll position not correctly restored");
121 is(gBrowser.contentWindow.scrollY, currScrollY, testName +
122 " vertical axis scroll position not correctly restored");
123 var formValue = gBrowser.contentDocument.getElementById(
"inp").value;
124 isnot(formValue, text, testName +
" form value incorrectly restored");
128 testName =
"[nocache]";
130 // Load a page with a no-cache header. This should not be
131 // restricted like no-store (bug
567365)
132 BrowserTestUtils.loadURIString(gBrowser, nocacheURI);
136 // Now that the page has loaded, amend the form contents
137 form = gBrowser.contentDocument.getElementById(
"inp");
140 // Attempt to scroll the page
141 originalXPosition = gBrowser.contentWindow.scrollX;
142 originalYPosition = gBrowser.contentWindow.scrollY;
143 scrollToX = gBrowser.contentWindow.scrollMaxX;
144 scrollToY = gBrowser.contentWindow.scrollMaxY;
145 gBrowser.contentWindow.scrollBy(scrollToX, scrollToY);
147 // Save the scroll position for future comparison
148 currScrollX = gBrowser.contentWindow.scrollX;
149 currScrollY = gBrowser.contentWindow.scrollY;
150 isnot(currScrollX, originalXPosition,
151 testName +
" failed to scroll window horizontally");
152 isnot(currScrollY, originalYPosition,
153 testName +
" failed to scroll window vertically");
155 BrowserTestUtils.loadURIString(gBrowser, simple);
159 // Now go back in history to the cached page.
164 // First page will now be reloaded. Check scroll position
165 // and form contents are restored
166 is(gBrowser.contentWindow.scrollX, currScrollX, testName +
167 " horizontal axis scroll position not correctly restored");
168 is(gBrowser.contentWindow.scrollY, currScrollY, testName +
169 " vertical axis scroll position not correctly restored");
170 formValue = gBrowser.contentDocument.getElementById(
"inp").value;
171 is(formValue, text, testName +
" form value not correctly restored");
173 Services.prefs.clearUserPref(
"browser.navigation.requireUserInteraction");
178 <browser type=
"content" primary=
"true" flex=
"1" id=
"content" src=
"about:blank"/>