|
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="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"> |
|
15 |
|
16 <script type="application/javascript"><![CDATA[ |
|
17 var imports = [ "SimpleTest", "is", "isnot", "ok"]; |
|
18 for each (var name in imports) { |
|
19 window[name] = window.opener.wrappedJSObject[name]; |
|
20 } |
|
21 |
|
22 const text="MOZILLA"; |
|
23 const nostoreURI = "http://mochi.test:8888/tests/docshell/test/chrome/" + |
|
24 "215405_nostore.html"; |
|
25 const nocacheURI = "https://example.com:443/tests/docshell/test/chrome/" + |
|
26 "215405_nocache.html"; |
|
27 |
|
28 var gBrowser; |
|
29 var gTestsIterator; |
|
30 var scrollX = 0; |
|
31 var scrollY = 0; |
|
32 |
|
33 function finish() { |
|
34 gBrowser.removeEventListener("pageshow", eventListener, true); |
|
35 // Work around bug 467960 |
|
36 var history = gBrowser.webNavigation.sessionHistory; |
|
37 history.PurgeHistory(history.count); |
|
38 |
|
39 window.close(); |
|
40 window.opener.wrappedJSObject.SimpleTest.finish(); |
|
41 } |
|
42 |
|
43 function onLoad(e) { |
|
44 gBrowser = document.getElementById("content"); |
|
45 gBrowser.addEventListener("pageshow", eventListener, true); |
|
46 |
|
47 gTestsIterator = testsIterator(); |
|
48 nextTest(); |
|
49 } |
|
50 |
|
51 function eventListener(event) { |
|
52 setTimeout(nextTest, 0); |
|
53 } |
|
54 |
|
55 function nextTest() { |
|
56 try { |
|
57 gTestsIterator.next(); |
|
58 } catch (err if err instanceof StopIteration) { |
|
59 finish(); |
|
60 } |
|
61 } |
|
62 |
|
63 function testsIterator() { |
|
64 // No-store tests |
|
65 var testName = "[nostore]"; |
|
66 |
|
67 // Load a page with a no-store header |
|
68 gBrowser.loadURI(nostoreURI); |
|
69 yield undefined; |
|
70 |
|
71 |
|
72 // Now that the page has loaded, amend the form contents |
|
73 var form = gBrowser.contentDocument.getElementById("inp"); |
|
74 form.value = text; |
|
75 |
|
76 // Attempt to scroll the page |
|
77 var originalXPosition = gBrowser.contentWindow.scrollX; |
|
78 var originalYPosition = gBrowser.contentWindow.scrollY; |
|
79 var scrollToX = gBrowser.contentWindow.scrollMaxX; |
|
80 var scrollToY = gBrowser.contentWindow.scrollMaxY; |
|
81 gBrowser.contentWindow.scrollBy(scrollToX, scrollToY); |
|
82 |
|
83 // Save the scroll position for future comparison |
|
84 scrollX = gBrowser.contentWindow.scrollX; |
|
85 scrollY = gBrowser.contentWindow.scrollY; |
|
86 isnot(scrollX, originalXPosition, |
|
87 testName + " failed to scroll window horizontally"); |
|
88 isnot(scrollY, originalYPosition, |
|
89 testName + " failed to scroll window vertically"); |
|
90 |
|
91 // Load a new document into the browser |
|
92 var simple = "data:text/html,<html><head><title>test2</title></head>" + |
|
93 "<body>test2</body></html>"; |
|
94 gBrowser.loadURI(simple); |
|
95 yield undefined; |
|
96 |
|
97 |
|
98 // Now go back in history. First page should not have been cached. |
|
99 gBrowser.goBack(); |
|
100 yield undefined; |
|
101 |
|
102 |
|
103 // First uncacheable page will now be reloaded. Check scroll position |
|
104 // restored, and form contents not |
|
105 is(gBrowser.contentWindow.scrollX, scrollX, testName + |
|
106 " horizontal axis scroll position not correctly restored"); |
|
107 is(gBrowser.contentWindow.scrollY, scrollY, testName + |
|
108 " vertical axis scroll position not correctly restored"); |
|
109 var formValue = gBrowser.contentDocument.getElementById("inp").value; |
|
110 isnot(formValue, text, testName + " form value incorrectly restored"); |
|
111 |
|
112 |
|
113 // https no-cache |
|
114 testName = "[nocache]"; |
|
115 |
|
116 // Load a page with a no-cache header |
|
117 gBrowser.loadURI(nocacheURI); |
|
118 yield undefined; |
|
119 |
|
120 |
|
121 // Now that the page has loaded, amend the form contents |
|
122 form = gBrowser.contentDocument.getElementById("inp"); |
|
123 form.value = text; |
|
124 |
|
125 // Attempt to scroll the page |
|
126 originalXPosition = gBrowser.contentWindow.scrollX; |
|
127 originalYPosition = gBrowser.contentWindow.scrollY; |
|
128 scrollToX = gBrowser.contentWindow.scrollMaxX; |
|
129 scrollToY = gBrowser.contentWindow.scrollMaxY; |
|
130 gBrowser.contentWindow.scrollBy(scrollToX, scrollToY); |
|
131 |
|
132 // Save the scroll position for future comparison |
|
133 scrollX = gBrowser.contentWindow.scrollX; |
|
134 scrollY = gBrowser.contentWindow.scrollY; |
|
135 isnot(scrollX, originalXPosition, |
|
136 testName + " failed to scroll window horizontally"); |
|
137 isnot(scrollY, originalYPosition, |
|
138 testName + " failed to scroll window vertically"); |
|
139 |
|
140 gBrowser.loadURI(simple); |
|
141 yield undefined; |
|
142 |
|
143 |
|
144 // Now go back in history. First page should not have been cached. |
|
145 gBrowser.goBack(); |
|
146 yield undefined; |
|
147 |
|
148 |
|
149 // First uncacheable page will now be reloaded. Check scroll position |
|
150 // restored, and form contents not |
|
151 is(gBrowser.contentWindow.scrollX, scrollX, testName + |
|
152 " horizontal axis scroll position not correctly restored"); |
|
153 is(gBrowser.contentWindow.scrollY, scrollY, testName + |
|
154 " vertical axis scroll position not correctly restored"); |
|
155 var formValue = gBrowser.contentDocument.getElementById("inp").value; |
|
156 isnot(formValue, text, testName + " form value incorrectly restored"); |
|
157 |
|
158 // nextTest has to be called from here, as no events are fired in this |
|
159 // step |
|
160 setTimeout(nextTest, 0); |
|
161 yield undefined; |
|
162 } |
|
163 ]]></script> |
|
164 |
|
165 <browser type="content-primary" flex="1" id="content" src="about:blank"/> |
|
166 </window> |