docshell/test/chrome/bug321671_window.xul

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rwxr-xr-x

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial