CLOSED TREE: TraceMonkey merge head. (a=blockers)
[mozilla-central.git] / docshell / test / chrome / bug321671_window.xul
blobff6bf51a3952af8ed910e8b6fd5616db99ac46f1
1 <?xml version="1.0"?>
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"
6 width="600"
7 height="600"
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;
25 ////
26 // Execute the next test in the generator function.
28 function nextTest() {
29 tests.next();
32 ////
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.
43 enableBFCache(true);
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++) {
50 doPageNavigation( {
51 uri: "data:text/html,<html><head><title>bug321671 page" + (i + 1) +
52 "</title></head>" +
53 "<body><table border='1' width='300' height='1000'>" +
54 "<tbody><tr><td>" +
55 " page " + (i + 1) + ": foobar foobar foobar foobar " +
56 "</td></tr></tbody></table> " +
57 "</body></html>",
58 eventsToListenFor: ["pageshow", "pagehide"],
59 expectedEvents: [ { type: "pagehide",
60 persisted: true,
61 title: i == 0 ?
62 undefined : "bug321671 page" + i },
63 { type: "pageshow",
64 title: "bug321671 page" + (i + 1) } ],
65 onNavComplete: nextTest
66 } );
67 yield;
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--) {
84 doPageNavigation( {
85 back: true,
86 eventsToListenFor: ["pageshow", "pagehide"],
87 expectedEvents: [ { type: "pagehide",
88 title: "bug321671 page" + (i+1),
89 persisted: true },
90 { type: "pageshow",
91 title: "bug321671 page" + i,
92 persisted: i > 1 } ],
93 onNavComplete: nextTest
94 } );
95 yield;
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++) {
107 doPageNavigation( {
108 forward: true,
109 eventsToListenFor: ["pageshow", "pagehide"],
110 expectedEvents: [ { type: "pagehide",
111 persisted: true,
112 title: "bug321671 page" + i },
113 { type: "pageshow",
114 persisted: i < MAX_BFCACHE_PAGES + 1,
115 title: "bug321671 page" + (i + 1) } ],
116 onNavComplete: nextTest
117 } );
118 yield;
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.
126 finish();
127 yield;
130 ]]></script>
132 <browser type="content-primary" flex="1" id="content" src="about:blank"/>
133 </window>