2 <?xml-stylesheet href=
"chrome://global/skin" type=
"text/css"?>
4 <window id=
"360511Test"
5 xmlns=
"http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
8 onload=
"setTimeout(runTest, 0);"
9 title=
"bug 360511 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[
14 Services.prefs.setBoolPref(
"browser.navigation.requireUserInteraction", false);
18 return SpecialPowers.spawn(TestWindow.getBrowser(), [], () =
> {
19 return content.scrollY;
22 function getLocation()
24 return SpecialPowers.spawn(TestWindow.getBrowser(), [], () =
> {
25 return content.location.href;
30 // Bug
360511: Fragment uri's in session history should be restored correctly
31 // upon back navigation.
33 async function runTest()
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++)
41 var url =
"bug360511_case" + i +
".html";
42 await promisePageNavigation( {
44 preventBFCache: i !=
1
47 // Store the original url for later comparison.
48 var originalUrl = TestWindow.getBrowser().currentURI.spec;
49 var originalDocLocation = await getLocation();
51 // Verify we're at the top of the page.
52 is(await getScrollY(),
0,
"Page initially has a non-zero scrollY property");
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,
60 false, false, false, false,
0, null);
61 content.document.getElementById(
"link1").dispatchEvent(event);
63 await promiseNextPaint();
65 // Verify we're no longer at the top of the page.
66 await promiseTrue(async function() {
67 return await getScrollY()
> 0;
70 // Store the fragment url for later comparison.
71 var fragmentUrl = TestWindow.getBrowser().currentURI.spec;
72 let fragDocLocation = await getLocation();
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,
85 await promisePageNavigation( {
87 eventsToListenFor: [
"pageshow"],
88 expectedEvents: [ {type:
"pageshow", title: expectedPageTitle,
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");
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
102 var originalScrollY = await getScrollY();
105 eventsToListenFor: []
109 return (await getScrollY() != originalScrollY);
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");
119 Services.prefs.clearUserPref(
"browser.navigation.requireUserInteraction");
120 // Tell the framework the test is finished.
126 <browser type=
"content" primary=
"true" flex=
"1" id=
"content" remote=
"true" maychangeremoteness=
"true" />