Bug 1839316: part 5) Guard the "fetchpriority" attribute behind a pref. r=kershaw...
[gecko.git] / docshell / test / chrome / bug215405_window.xhtml
blob107b34ab9df6dfb10a0799bb3c1cbd87a2abaced
1 <?xml version="1.0"?>
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"
11 width="600"
12 height="600"
13 onload="onLoad();"
14 title="215405 test">
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];
28 const text="MOZILLA";
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";
34 var gBrowser;
35 var gTestsIterator;
36 var currScrollX = 0;
37 var currScrollY = 0;
39 function finish() {
40 gBrowser.removeEventListener("pageshow", eventListener, true);
41 // Work around bug 467960
42 let historyPurged;
43 if (SpecialPowers.Services.appinfo.sessionHistoryInParent) {
44 let history = gBrowser.browsingContext.sessionHistory;
45 history.purgeHistory(history.count);
46 historyPurged = Promise.resolve();
47 } else {
48 historyPurged = SpecialPowers.spawn(gBrowser, [], () => {
49 let history = docShell.QueryInterface(Ci.nsIWebNavigation).sessionHistory
50 .legacySHistory;
51 history.purgeHistory(history.count);
52 });
55 historyPurged.then(_ => {
56 window.close();
57 window.arguments[0].SimpleTest.finish();
58 });
61 function onLoad(e) {
62 gBrowser = document.getElementById("content");
63 gBrowser.addEventListener("pageshow", eventListener, true);
65 gTestsIterator = testsIterator();
66 nextTest();
69 function eventListener(event) {
70 setTimeout(nextTest, 0);
73 function nextTest() {
74 gTestsIterator.next();
77 function* testsIterator() {
78 // No-store tests
79 var testName = "[nostore]";
81 // Load a page with a no-store header
82 BrowserTestUtils.loadURIString(gBrowser, nostoreURI);
83 yield undefined;
86 // Now that the page has loaded, amend the form contents
87 var form = gBrowser.contentDocument.getElementById("inp");
88 form.value = text;
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);
109 yield undefined;
112 // Now go back in history. First page should not have been cached.
113 gBrowser.goBack();
114 yield undefined;
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");
127 // https no-cache
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);
133 yield undefined;
136 // Now that the page has loaded, amend the form contents
137 form = gBrowser.contentDocument.getElementById("inp");
138 form.value = text;
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);
156 yield undefined;
159 // Now go back in history to the cached page.
160 gBrowser.goBack();
161 yield undefined;
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");
174 finish();
176 ]]></script>
178 <browser type="content" primary="true" flex="1" id="content" src="about:blank"/>
179 </window>