1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/docshell/test/chrome/bug321671_window.xul Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,139 @@ 1.4 +<?xml version="1.0"?> 1.5 +<?xml-stylesheet href="chrome://global/skin" type="text/css"?> 1.6 + 1.7 +<window id="321671Test" 1.8 + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" 1.9 + width="600" 1.10 + height="600" 1.11 + onload="setTimeout(nextTest,0);" 1.12 + title="bug 321671 test"> 1.13 + 1.14 + <script type="text/javascript" 1.15 + src="chrome://mochikit/content/tests/SimpleTest/specialpowersAPI.js"/> 1.16 + <script type="text/javascript" 1.17 + src="chrome://mochikit/content/tests/SimpleTest/SpecialPowersObserverAPI.js"/> 1.18 + <script type="text/javascript" 1.19 + src="chrome://mochikit/content/tests/SimpleTest/ChromePowers.js"/> 1.20 + <script type="application/javascript" src= "chrome://mochikit/content/chrome-harness.js" /> 1.21 + <script type="application/javascript" src="docshell_helpers.js" /> 1.22 + <script type="application/javascript"><![CDATA[ 1.23 + 1.24 + // Define the generator-iterator for the tests. 1.25 + var tests = testIterator(); 1.26 + 1.27 + // Maximum number of entries in the bfcache for this session history. 1.28 + // This number is hardcoded in docshell code. In the test, we'll 1.29 + // navigate through enough pages so that we hit one that's been 1.30 + // evicted from the bfcache because it's farther from the current 1.31 + // page than this number. 1.32 + const MAX_BFCACHE_PAGES = 3; 1.33 + 1.34 + //// 1.35 + // Execute the next test in the generator function. 1.36 + // 1.37 + function nextTest() { 1.38 + tests.next(); 1.39 + } 1.40 + 1.41 + //// 1.42 + // Generator function for test steps for bug 321671: Scroll position 1.43 + // should be retained when moving backwards and forwards through pages 1.44 + // when bfcache is enabled. 1.45 + // 1.46 + function testIterator() 1.47 + { 1.48 + // Variable to hold the scroll positions of the test pages. 1.49 + var scrollPositions = []; 1.50 + 1.51 + // Make sure bfcache is on. 1.52 + enableBFCache(true); 1.53 + 1.54 + // Load enough test pages that so the first one is evicted from the 1.55 + // bfcache, scroll down on each page, and save the 1.56 + // current scroll position before continuing. Verify that each 1.57 + // page we're navigating away from is initially put into the bfcache. 1.58 + for (var i = 0; i <= MAX_BFCACHE_PAGES + 1; i++) { 1.59 + doPageNavigation( { 1.60 + uri: "data:text/html,<html><head><title>bug321671 page" + (i + 1) + 1.61 + "</title></head>" + 1.62 + "<body><table border='1' width='300' height='1000'>" + 1.63 + "<tbody><tr><td>" + 1.64 + " page " + (i + 1) + ": foobar foobar foobar foobar " + 1.65 + "</td></tr></tbody></table> " + 1.66 + "</body></html>", 1.67 + eventsToListenFor: ["pageshow", "pagehide"], 1.68 + expectedEvents: [ { type: "pagehide", 1.69 + persisted: true, 1.70 + title: i == 0 ? 1.71 + undefined : "bug321671 page" + i }, 1.72 + { type: "pageshow", 1.73 + title: "bug321671 page" + (i + 1) } ], 1.74 + onNavComplete: nextTest 1.75 + } ); 1.76 + yield undefined; 1.77 + 1.78 + is(TestWindow.getWindow().scrollY, 0, 1.79 + "Page initially has non-zero scrollY position"); 1.80 + TestWindow.getWindow().scrollByLines(10 + (2*i)); 1.81 + ok(TestWindow.getWindow().scrollY > 0, 1.82 + "Page has zero scrollY position after scrolling"); 1.83 + scrollPositions[i] = TestWindow.getWindow().scrollY; 1.84 + } 1.85 + 1.86 + // Go back to the first page, one page at a time. For each 'back' 1.87 + // action, verify that its vertical scroll position is restored 1.88 + // correctly. Verify that the last page in the sequence 1.89 + // does not come from the bfcache. Again verify that all pages 1.90 + // that we navigate away from are initially 1.91 + // stored in the bfcache. 1.92 + for (i = MAX_BFCACHE_PAGES + 1; i > 0; i--) { 1.93 + doPageNavigation( { 1.94 + back: true, 1.95 + eventsToListenFor: ["pageshow", "pagehide"], 1.96 + expectedEvents: [ { type: "pagehide", 1.97 + title: "bug321671 page" + (i+1), 1.98 + persisted: true }, 1.99 + { type: "pageshow", 1.100 + title: "bug321671 page" + i, 1.101 + persisted: i > 1 } ], 1.102 + onNavComplete: nextTest 1.103 + } ); 1.104 + yield undefined; 1.105 + 1.106 + is(TestWindow.getWindow().scrollY, scrollPositions[i-1], 1.107 + "Scroll position not restored while going back!"); 1.108 + } 1.109 + 1.110 + // Traverse history forward now, and verify scroll position is still 1.111 + // restored. Similar to the backward traversal, verify that all 1.112 + // but the last page in the sequence comes from the bfcache. Also 1.113 + // verify that all of the pages get stored in the bfcache when we 1.114 + // navigate away from them. 1.115 + for (i = 1; i <= MAX_BFCACHE_PAGES + 1; i++) { 1.116 + doPageNavigation( { 1.117 + forward: true, 1.118 + eventsToListenFor: ["pageshow", "pagehide"], 1.119 + expectedEvents: [ { type: "pagehide", 1.120 + persisted: true, 1.121 + title: "bug321671 page" + i }, 1.122 + { type: "pageshow", 1.123 + persisted: i < MAX_BFCACHE_PAGES + 1, 1.124 + title: "bug321671 page" + (i + 1) } ], 1.125 + onNavComplete: nextTest 1.126 + } ); 1.127 + yield undefined; 1.128 + 1.129 + is(TestWindow.getWindow().scrollY, scrollPositions[i], 1.130 + "Scroll position not restored while going forward!"); 1.131 + } 1.132 + 1.133 + // Tell the framework the test is finished. Include the final 'yield' 1.134 + // statement to prevent a StopIteration exception from being thrown. 1.135 + finish(); 1.136 + yield undefined; 1.137 + } 1.138 + 1.139 + ]]></script> 1.140 + 1.141 + <browser type="content-primary" flex="1" id="content" src="about:blank"/> 1.142 +</window>