bug360511_window.xhtml (4811B)
1 <?xml version="1.0"?> 2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?> 3 4 <window id="360511Test" 5 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" 6 width="600" 7 height="600" 8 onload="setTimeout(runTest, 0);" 9 title="bug 360511 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 function getScrollY() 17 { 18 return SpecialPowers.spawn(TestWindow.getBrowser(), [], () => { 19 return content.scrollY; 20 }); 21 } 22 function getLocation() 23 { 24 return SpecialPowers.spawn(TestWindow.getBrowser(), [], () => { 25 return content.location.href; 26 }); 27 } 28 29 //// 30 // Bug 360511: Fragment uri's in session history should be restored correctly 31 // upon back navigation. 32 // 33 async function runTest() 34 { 35 // Case 1: load a page containing a fragment link; the page should be 36 // stored in the bfcache. 37 // Case 2: load a page containing a fragment link; the page should NOT 38 // be stored in the bfcache. 39 for (var i = 1; i < 3; i++) 40 { 41 var url = "bug360511_case" + i + ".html"; 42 await promisePageNavigation( { 43 uri: getHttpUrl(url), 44 preventBFCache: i != 1 45 } ); 46 47 // Store the original url for later comparison. 48 var originalUrl = TestWindow.getBrowser().currentURI.spec; 49 var originalDocLocation = await getLocation(); 50 51 // Verify we're at the top of the page. 52 is(await getScrollY(), 0, "Page initially has a non-zero scrollY property"); 53 54 // Click the on the fragment link in the browser, and use setTimeout 55 // to give the event a chance to be processed. 56 await SpecialPowers.spawn(TestWindow.getBrowser(), [], () => { 57 var event = content.document.createEvent('MouseEvent'); 58 event.initMouseEvent("click", true, true, content, 0, 59 0, 0, 0, 0, 60 false, false, false, false, 0, null); 61 content.document.getElementById("link1").dispatchEvent(event); 62 }); 63 await promiseNextPaint(); 64 65 // Verify we're no longer at the top of the page. 66 await promiseTrue(async function() { 67 return await getScrollY() > 0; 68 }, 20); 69 70 // Store the fragment url for later comparison. 71 var fragmentUrl = TestWindow.getBrowser().currentURI.spec; 72 let fragDocLocation = await getLocation(); 73 74 // Now navigate to any other page 75 var expectedPageTitle = "bug360511 case " + i; 76 await promisePageNavigation( { 77 uri: getHttpUrl("generic.html"), 78 eventsToListenFor: ["pagehide", "pageshow"], 79 expectedEvents: [ {type: "pagehide", title: expectedPageTitle, 80 persisted: i == 1}, 81 {type: "pageshow"} ], 82 } ); 83 84 // Go back 85 await promisePageNavigation( { 86 back: true, 87 eventsToListenFor: ["pageshow"], 88 expectedEvents: [ {type: "pageshow", title: expectedPageTitle, 89 persisted: i == 1} ], 90 } ); 91 92 // Verify the current url is the fragment url 93 is(TestWindow.getBrowser().currentURI.spec, fragmentUrl, 94 "current url is not the previous fragment url"); 95 is(await getLocation(), fragDocLocation, 96 "document.location is not the previous fragment url"); 97 98 // Go back again. Since we're just going from a fragment url to 99 // parent url, no pageshow event is fired, so don't wait for any 100 // events. Rather, just wait for the page's scrollY property to 101 // change. 102 var originalScrollY = await getScrollY(); 103 doPageNavigation( { 104 back: true, 105 eventsToListenFor: [] 106 } ); 107 await promiseTrue( 108 async function() { 109 return (await getScrollY() != originalScrollY); 110 }, 20); 111 112 // Verify the current url is the original url without fragment 113 is(TestWindow.getBrowser().currentURI.spec, originalUrl, 114 "current url is not the original url"); 115 is(await getLocation(), originalDocLocation, 116 "document.location is not the original url"); 117 } 118 119 Services.prefs.clearUserPref("browser.navigation.requireUserInteraction"); 120 // Tell the framework the test is finished. 121 finish(); 122 } 123 124 ]]></script> 125 126 <browser type="content" primary="true" flex="1" id="content" remote="true" maychangeremoteness="true" /> 127 </window>