CLOSED TREE: TraceMonkey merge head. (a=blockers)
[mozilla-central.git] / docshell / test / chrome / bug215405_window.xul
blobc5c6c9b7c1ccaba0c394322b6ceb8bca689828ba
1 <?xml version="1.0"?>
3 <!-- ***** BEGIN LICENSE BLOCK *****
4 - Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 - The contents of this file are subject to the Mozilla Public License Version
7 - 1.1 (the "License"); you may not use this file except in compliance with
8 - the License. You may obtain a copy of the License at
9 - http://www.mozilla.org/MPL/
11 - Software distributed under the License is distributed on an "AS IS" basis,
12 - WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 - for the specific language governing rights and limitations under the
14 - License.
16 - The Original Code is bug 215405 test code
18 - The Initial Developer of the Original Code is
19 - Graeme McCutcheon <graememcc_firefox@graeme-online.co.uk>.
20 - Portions created by the Initial Developer are Copyright (C) 2008
21 - the Initial Developer. All Rights Reserved.
23 - Contributor(s):
25 - Alternatively, the contents of this file may be used under the terms of
26 - either the GNU General Public License Version 2 or later (the "GPL"), or
27 - the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 - in which case the provisions of the GPL or the LGPL are applicable instead
29 - of those above. If you wish to allow use of your version of this file only
30 - under the terms of either the GPL or the LGPL, and not to allow others to
31 - use your version of this file under the terms of the MPL, indicate your
32 - decision by deleting the provisions above and replace them with the notice
33 - and other provisions required by the LGPL or the GPL. If you do not delete
34 - the provisions above, a recipient may use your version of this file under
35 - the terms of any one of the MPL, the GPL or the LGPL.
37 - ***** END LICENSE BLOCK ***** -->
39 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
41 <window id="215405Test"
42 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
43 width="600"
44 height="600"
45 onload="onLoad();"
46 title="215405 test">
48 <script type="application/javascript"><![CDATA[
49 var imports = [ "SimpleTest", "is", "isnot", "ok"];
50 for each (var name in imports) {
51 window[name] = window.opener.wrappedJSObject[name];
54 const text="MOZILLA";
55 const nostoreURI = "http://mochi.test:8888/tests/docshell/test/chrome/" +
56 "215405_nostore.html";
57 const nocacheURI = "https://example.com:443/tests/docshell/test/chrome/" +
58 "215405_nocache.html";
60 var gBrowser;
61 var gTestsIterator;
62 var scrollX = 0;
63 var scrollY = 0;
65 function finish() {
66 gBrowser.removeEventListener("pageshow", eventListener, true);
67 // Work around bug 467960
68 var history = gBrowser.webNavigation.sessionHistory;
69 history.PurgeHistory(history.count);
71 window.close();
72 window.opener.wrappedJSObject.SimpleTest.finish();
75 function onLoad(e) {
76 gBrowser = document.getElementById("content");
77 gBrowser.addEventListener("pageshow", eventListener, true);
79 gTestsIterator = testsIterator();
80 nextTest();
83 function eventListener(event) {
84 setTimeout(nextTest, 0);
87 function nextTest() {
88 try {
89 gTestsIterator.next();
90 } catch (err if err instanceof StopIteration) {
91 finish();
95 function testsIterator() {
96 // No-store tests
97 var testName = "[nostore]";
99 // Load a page with a no-store header
100 gBrowser.loadURI(nostoreURI);
101 yield;
104 // Now that the page has loaded, amend the form contents
105 var form = gBrowser.contentDocument.getElementById("inp");
106 form.value = text;
108 // Attempt to scroll the page
109 var originalXPosition = gBrowser.contentWindow.scrollX;
110 var originalYPosition = gBrowser.contentWindow.scrollY;
111 var scrollToX = gBrowser.contentWindow.scrollMaxX;
112 var scrollToY = gBrowser.contentWindow.scrollMaxY;
113 gBrowser.contentWindow.scrollBy(scrollToX, scrollToY);
115 // Save the scroll position for future comparison
116 scrollX = gBrowser.contentWindow.scrollX;
117 scrollY = gBrowser.contentWindow.scrollY;
118 isnot(scrollX, originalXPosition,
119 testName + " failed to scroll window horizontally");
120 isnot(scrollY, originalYPosition,
121 testName + " failed to scroll window vertically");
123 // Load a new document into the browser
124 var simple = "data:text/html,<html><head><title>test2</title></head>" +
125 "<body>test2</body></html>";
126 gBrowser.loadURI(simple);
127 yield;
130 // Now go back in history. First page should not have been cached.
131 gBrowser.goBack();
132 yield;
135 // First uncacheable page will now be reloaded. Check scroll position
136 // restored, and form contents not
137 is(gBrowser.contentWindow.scrollX, scrollX, testName +
138 " horizontal axis scroll position not correctly restored");
139 is(gBrowser.contentWindow.scrollY, scrollY, testName +
140 " vertical axis scroll position not correctly restored");
141 var formValue = gBrowser.contentDocument.getElementById("inp").value;
142 isnot(formValue, text, testName + " form value incorrectly restored");
145 // https no-cache
146 testName = "[nocache]";
148 // Load a page with a no-cache header
149 gBrowser.loadURI(nocacheURI);
150 yield;
153 // Now that the page has loaded, amend the form contents
154 form = gBrowser.contentDocument.getElementById("inp");
155 form.value = text;
157 // Attempt to scroll the page
158 originalXPosition = gBrowser.contentWindow.scrollX;
159 originalYPosition = gBrowser.contentWindow.scrollY;
160 scrollToX = gBrowser.contentWindow.scrollMaxX;
161 scrollToY = gBrowser.contentWindow.scrollMaxY;
162 gBrowser.contentWindow.scrollBy(scrollToX, scrollToY);
164 // Save the scroll position for future comparison
165 scrollX = gBrowser.contentWindow.scrollX;
166 scrollY = gBrowser.contentWindow.scrollY;
167 isnot(scrollX, originalXPosition,
168 testName + " failed to scroll window horizontally");
169 isnot(scrollY, originalYPosition,
170 testName + " failed to scroll window vertically");
172 gBrowser.loadURI(simple);
173 yield;
176 // Now go back in history. First page should not have been cached.
177 gBrowser.goBack();
178 yield;
181 // First uncacheable page will now be reloaded. Check scroll position
182 // restored, and form contents not
183 is(gBrowser.contentWindow.scrollX, scrollX, testName +
184 " horizontal axis scroll position not correctly restored");
185 is(gBrowser.contentWindow.scrollY, scrollY, testName +
186 " vertical axis scroll position not correctly restored");
187 var formValue = gBrowser.contentDocument.getElementById("inp").value;
188 isnot(formValue, text, testName + " form value incorrectly restored");
190 // nextTest has to be called from here, as no events are fired in this
191 // step
192 setTimeout(nextTest, 0);
193 yield;
195 ]]></script>
197 <browser type="content-primary" flex="1" id="content" src="about:blank"/>
198 </window>