bug396649_window.xhtml (4711B)
1 <?xml version="1.0"?> 2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?> 3 4 <window id="396649Test" 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 396649 test"> 10 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[ 14 Services.prefs.setBoolPref("browser.navigation.requireUserInteraction", false); 15 16 // Define the generator-iterator for the tests. 17 var tests = testIterator(); 18 19 // Maximum number of entries in the bfcache for this session history. 20 // This number is hardcoded in docshell code. In the test, we'll 21 // navigate through enough pages so that we hit one that's been 22 // evicted from the bfcache because it's farther from the current 23 // page than this number. 24 const MAX_BFCACHE_PAGES = 3; 25 26 //// 27 // Execute the next test in the generator function. 28 // 29 function nextTest() { 30 tests.next(); 31 } 32 33 //// 34 // Generator function for test steps for bug 396649: Content 35 // viewers should be evicted from bfcache when going back if more 36 // than MAX_BFCACHE_PAGES from the current index. 37 // 38 function* testIterator() 39 { 40 // Make sure bfcache is on. 41 enableBFCache(true); 42 43 // Load enough pages so that the first loaded is eviced from 44 // the bfcache, since it is greater the MAX_BFCACHE_PAGES from 45 // the current position in the session history. Verify all 46 // of the pages are initially stored in the bfcache when 47 // they're unloaded. 48 for (var i = 0; i <= MAX_BFCACHE_PAGES + 1; i++) { 49 let eventsToListenFor = ["pageshow"]; 50 let expectedEvents = [ { type: "pageshow", 51 title: "bug396649 page" + i } ]; 52 if (i > 0) { 53 eventsToListenFor.push("pagehide"); 54 expectedEvents.unshift({ type: "pagehide", 55 title: "bug396649 page" + (i-1) }); 56 } 57 doPageNavigation( { 58 uri: "data:text/html,<!DOCTYPE html><html>" + 59 "<head><title>bug396649 page" + i + 60 "</title></head>" + 61 "<body>" + 62 "test page " + i + 63 "</body></html>", 64 eventsToListenFor, 65 expectedEvents, 66 onNavComplete: nextTest 67 } ); 68 yield undefined; 69 } 70 71 // Go back to the first page, one page at a time. The first 72 // MAX_BFCACHE_PAGES pages loaded via back should come from the bfcache, 73 // the last should not, since it should have been evicted during the 74 // previous navigation sequence. Verify all pages are initially stored 75 // in the bfcache when they're unloaded. 76 for (i = MAX_BFCACHE_PAGES + 1; i > 0; i--) { 77 doPageNavigation( { 78 back: true, 79 eventsToListenFor: ["pageshow", "pagehide"], 80 expectedEvents: [ { type: "pagehide", 81 title: "bug396649 page" + i, 82 persisted: true }, 83 { type: "pageshow", 84 title: "bug396649 page" + (i - 1), 85 persisted: i > 1 } ], 86 onNavComplete: nextTest 87 } ); 88 yield undefined; 89 } 90 91 // Traverse history forward now. Again, the first MAX_BFCACHE_PAGES 92 // pages should come from the bfcache, the last should not, 93 // since it should have been evicted during the backwards 94 // traversal above. Verify all pages are initially stored 95 // in the bfcache when they're unloaded. 96 for (i = 1; i <= MAX_BFCACHE_PAGES + 1; i++) { 97 doPageNavigation( { 98 forward: true, 99 eventsToListenFor: ["pageshow", "pagehide"], 100 expectedEvents: [ { type: "pagehide", 101 title: "bug396649 page" + (i-1), 102 persisted: true }, 103 { type: "pageshow", 104 title: "bug396649 page" + i, 105 persisted: i < MAX_BFCACHE_PAGES + 1 } ], 106 onNavComplete: nextTest 107 } ); 108 yield undefined; 109 } 110 111 Services.prefs.clearUserPref("browser.navigation.requireUserInteraction"); 112 // Tell the framework the test is finished. 113 finish(); 114 } 115 116 ]]></script> 117 118 <browser type="content" primary="true" flex="1" id="content" remote="true" maychangeremoteness="true" /> 119 </window>