|
1 <?xml version="1.0"?> |
|
2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?> |
|
3 |
|
4 <window id="321671Test" |
|
5 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" |
|
6 width="600" |
|
7 height="600" |
|
8 onload="setTimeout(nextTest,0);" |
|
9 title="bug 321671 test"> |
|
10 |
|
11 <script type="text/javascript" |
|
12 src="chrome://mochikit/content/tests/SimpleTest/specialpowersAPI.js"/> |
|
13 <script type="text/javascript" |
|
14 src="chrome://mochikit/content/tests/SimpleTest/SpecialPowersObserverAPI.js"/> |
|
15 <script type="text/javascript" |
|
16 src="chrome://mochikit/content/tests/SimpleTest/ChromePowers.js"/> |
|
17 <script type="application/javascript" src= "chrome://mochikit/content/chrome-harness.js" /> |
|
18 <script type="application/javascript" src="docshell_helpers.js" /> |
|
19 <script type="application/javascript"><![CDATA[ |
|
20 |
|
21 // Define the generator-iterator for the tests. |
|
22 var tests = testIterator(); |
|
23 |
|
24 // Maximum number of entries in the bfcache for this session history. |
|
25 // This number is hardcoded in docshell code. In the test, we'll |
|
26 // navigate through enough pages so that we hit one that's been |
|
27 // evicted from the bfcache because it's farther from the current |
|
28 // page than this number. |
|
29 const MAX_BFCACHE_PAGES = 3; |
|
30 |
|
31 //// |
|
32 // Execute the next test in the generator function. |
|
33 // |
|
34 function nextTest() { |
|
35 tests.next(); |
|
36 } |
|
37 |
|
38 //// |
|
39 // Generator function for test steps for bug 321671: Scroll position |
|
40 // should be retained when moving backwards and forwards through pages |
|
41 // when bfcache is enabled. |
|
42 // |
|
43 function testIterator() |
|
44 { |
|
45 // Variable to hold the scroll positions of the test pages. |
|
46 var scrollPositions = []; |
|
47 |
|
48 // Make sure bfcache is on. |
|
49 enableBFCache(true); |
|
50 |
|
51 // Load enough test pages that so the first one is evicted from the |
|
52 // bfcache, scroll down on each page, and save the |
|
53 // current scroll position before continuing. Verify that each |
|
54 // page we're navigating away from is initially put into the bfcache. |
|
55 for (var i = 0; i <= MAX_BFCACHE_PAGES + 1; i++) { |
|
56 doPageNavigation( { |
|
57 uri: "data:text/html,<html><head><title>bug321671 page" + (i + 1) + |
|
58 "</title></head>" + |
|
59 "<body><table border='1' width='300' height='1000'>" + |
|
60 "<tbody><tr><td>" + |
|
61 " page " + (i + 1) + ": foobar foobar foobar foobar " + |
|
62 "</td></tr></tbody></table> " + |
|
63 "</body></html>", |
|
64 eventsToListenFor: ["pageshow", "pagehide"], |
|
65 expectedEvents: [ { type: "pagehide", |
|
66 persisted: true, |
|
67 title: i == 0 ? |
|
68 undefined : "bug321671 page" + i }, |
|
69 { type: "pageshow", |
|
70 title: "bug321671 page" + (i + 1) } ], |
|
71 onNavComplete: nextTest |
|
72 } ); |
|
73 yield undefined; |
|
74 |
|
75 is(TestWindow.getWindow().scrollY, 0, |
|
76 "Page initially has non-zero scrollY position"); |
|
77 TestWindow.getWindow().scrollByLines(10 + (2*i)); |
|
78 ok(TestWindow.getWindow().scrollY > 0, |
|
79 "Page has zero scrollY position after scrolling"); |
|
80 scrollPositions[i] = TestWindow.getWindow().scrollY; |
|
81 } |
|
82 |
|
83 // Go back to the first page, one page at a time. For each 'back' |
|
84 // action, verify that its vertical scroll position is restored |
|
85 // correctly. Verify that the last page in the sequence |
|
86 // does not come from the bfcache. Again verify that all pages |
|
87 // that we navigate away from are initially |
|
88 // stored in the bfcache. |
|
89 for (i = MAX_BFCACHE_PAGES + 1; i > 0; i--) { |
|
90 doPageNavigation( { |
|
91 back: true, |
|
92 eventsToListenFor: ["pageshow", "pagehide"], |
|
93 expectedEvents: [ { type: "pagehide", |
|
94 title: "bug321671 page" + (i+1), |
|
95 persisted: true }, |
|
96 { type: "pageshow", |
|
97 title: "bug321671 page" + i, |
|
98 persisted: i > 1 } ], |
|
99 onNavComplete: nextTest |
|
100 } ); |
|
101 yield undefined; |
|
102 |
|
103 is(TestWindow.getWindow().scrollY, scrollPositions[i-1], |
|
104 "Scroll position not restored while going back!"); |
|
105 } |
|
106 |
|
107 // Traverse history forward now, and verify scroll position is still |
|
108 // restored. Similar to the backward traversal, verify that all |
|
109 // but the last page in the sequence comes from the bfcache. Also |
|
110 // verify that all of the pages get stored in the bfcache when we |
|
111 // navigate away from them. |
|
112 for (i = 1; i <= MAX_BFCACHE_PAGES + 1; i++) { |
|
113 doPageNavigation( { |
|
114 forward: true, |
|
115 eventsToListenFor: ["pageshow", "pagehide"], |
|
116 expectedEvents: [ { type: "pagehide", |
|
117 persisted: true, |
|
118 title: "bug321671 page" + i }, |
|
119 { type: "pageshow", |
|
120 persisted: i < MAX_BFCACHE_PAGES + 1, |
|
121 title: "bug321671 page" + (i + 1) } ], |
|
122 onNavComplete: nextTest |
|
123 } ); |
|
124 yield undefined; |
|
125 |
|
126 is(TestWindow.getWindow().scrollY, scrollPositions[i], |
|
127 "Scroll position not restored while going forward!"); |
|
128 } |
|
129 |
|
130 // Tell the framework the test is finished. Include the final 'yield' |
|
131 // statement to prevent a StopIteration exception from being thrown. |
|
132 finish(); |
|
133 yield undefined; |
|
134 } |
|
135 |
|
136 ]]></script> |
|
137 |
|
138 <browser type="content-primary" flex="1" id="content" src="about:blank"/> |
|
139 </window> |