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