Source code
Revision control
Copy as Markdown
Other Tools
<?xml version="1.0"?>
<window id="303267Test"
width="600"
height="600"
onload="setTimeout(runTest, 0);"
<script type="application/javascript" src="docshell_helpers.js" />
<script type="application/javascript"><![CDATA[
Services.prefs.setBoolPref("browser.navigation.requireUserInteraction", false);
////
//
async function runTest()
{
// Load the first test page
var navData = {
uri: getHttpUrl("662200a.html"),
eventsToListenFor: ["pageshow"],
expectedEvents: [ {type: "pageshow", title: "A"} ],
};
await promisePageNavigation(navData);
// Load the second test page.
navData = {
eventsToListenFor: ["pageshow", "pagehide"],
expectedEvents: [ {type: "pagehide",
title: "A"},
{type: "pageshow",
title: "B"} ],
}
let clicked = promisePageEvents(navData);
SpecialPowers.spawn(TestWindow.getBrowser(), [], () => {
var link = content.document.getElementById("link");
var event = content.document.createEvent("MouseEvents");
event.initMouseEvent("click", true, true, content,
0, 0, 0, 0, 0, false, false, false, false, 0, null);
link.dispatchEvent(event);
});
await clicked;
// Load the third test page.
navData = {
eventsToListenFor: ["pageshow", "pagehide"],
expectedEvents: [ {type: "pagehide",
title: "B"},
{type: "pageshow",
title: "C"} ],
};
clicked = promisePageEvents(navData);
SpecialPowers.spawn(TestWindow.getBrowser(), [], () => {
var link = content.document.getElementById("link");
var event = content.document.createEvent("MouseEvents");
event.initMouseEvent("click", true, true, content,
0, 0, 0, 0, 0, false, false, false, false, 0, null);
link.dispatchEvent(event);
});
await clicked;
// Go back.
navData = {
back: true,
eventsToListenFor: ["pageshow", "pagehide"],
expectedEvents: [ {type: "pagehide",
title: "C"},
{type: "pageshow",
title: "B"} ],
};
await promisePageNavigation(navData);
// Reload.
navData = {
eventsToListenFor: ["pageshow", "pagehide"],
expectedEvents: [ {type: "pagehide",
title: "B"},
{type: "pageshow",
title: "B"} ],
};
// Asking the docshell harness to reload for us will call reload on
// nsDocShell which has different behavior than the reload on nsSHistory
// so we call reloadCurrentEntry() (which is equivalent to reload(0) and
// visible from JS) explicitly here.
let reloaded = promisePageEvents(navData);
if (SpecialPowers.Services.appinfo.sessionHistoryInParent) {
TestWindow.getBrowser().browsingContext.sessionHistory.reloadCurrentEntry();
} else {
SpecialPowers.spawn(TestWindow.getBrowser(), [], () => {
docShell.QueryInterface(Ci.nsIWebNavigation).sessionHistory.legacySHistory.reloadCurrentEntry();
});
}
await reloaded;
// After this sequence of events, we should be able to go back and forward
is(TestWindow.getBrowser().canGoBack, true, "Should be able to go back!");
is(TestWindow.getBrowser().canGoForward, true, "Should be able to go forward!");
let requestedIndex;
if (SpecialPowers.Services.appinfo.sessionHistoryInParent) {
requestedIndex = TestWindow.getBrowser().browsingContext.sessionHistory.requestedIndex;
} else {
requestedIndex = await SpecialPowers.spawn(TestWindow.getBrowser(), [], () => {
return docShell.sessionHistory.legacySHistory.requestedIndex;
})
}
is(requestedIndex, -1, "Requested index should be cleared!");
Services.prefs.clearUserPref("browser.navigation.requireUserInteraction");
// Tell the framework the test is finished.
finish();
}
]]></script>
<browser type="content" primary="true" flex="1" id="content" remote="true" />
</window>