const BASE_URL = "http://mochi.test:8888/tests/docshell/test/navigation/";
let testSteps = [
async function() {
// Test 1: Create dynamic iframe with bfcache enabled.
// Navigate static / dynamic iframes, then navigate top level window
// and navigate back. Both iframes should still exist with history
// entries preserved.
window.onunload = null; // enable bfcache
await createDynamicFrame(document);
await loadUriInFrame(document.getElementById("staticFrame"), "frame1.html");
await loadUriInFrame(document.getElementById("dynamicFrame"), "frame1.html");
await loadUriInFrame(document.getElementById("staticFrame"), "frame2.html");
await loadUriInFrame(document.getElementById("dynamicFrame"), "frame2.html");
is(history.length, 5, "history.length");
window.location = "goback.html";
},
async function() {
let webNav = SpecialPowers.wrap(window)
.docShell
.QueryInterface(SpecialPowers.Ci.nsIWebNavigation);
let shistory = webNav.sessionHistory;
is(webNav.canGoForward, true, "canGoForward");
is(shistory.index, 4, "shistory.index");
is(history.length, 6, "history.length");
is(document.getElementById("staticFrame").contentWindow.location.href, BASE_URL + "frame2.html", "staticFrame location");
is(document.getElementById("dynamicFrame").contentWindow.location.href, BASE_URL + "frame2.html", "dynamicFrame location");
// Test 2: Load another page in dynamic iframe, canGoForward should be
// false.
await loadUriInFrame(document.getElementById("dynamicFrame"), "frame3.html");
is(webNav.canGoForward, false, "canGoForward");
is(shistory.index, 5, "shistory.index");
is(history.length, 6, "history.length");
// Test 3: Navigate to antoher page with bfcache disabled, all dynamic
// iframe entries should be removed.
window.onunload = function() {}; // disable bfcache
window.location = "goback.html";
},
async function() {
let windowWrap = SpecialPowers.wrap(window);
let docShell = windowWrap.docShell;
let shistory = docShell.QueryInterface(SpecialPowers.Ci.nsIWebNavigation)
.sessionHistory;
// Now staticFrame has frame0 -> frame1 -> frame2.
if (!SpecialPowers.Services.appinfo.sessionHistoryInParent) {
// *EntryIndex attributes aren't meaningful when the session history
// lives in the parent process.
is(docShell.previousEntryIndex, 3, "docShell.previousEntryIndex");
is(docShell.loadedEntryIndex, 2, "docShell.loadedEntryIndex");
}
is(shistory.index, 2, "shistory.index");
is(history.length, 4, "history.length");
is(document.getElementById("staticFrame").contentWindow.location.href, BASE_URL + "frame2.html", "staticFrame location");
ok(!document.getElementById("dynamicFrame"), "dynamicFrame should not exist");
// Test 4: Load a nested frame in the static frame, navigate the inner
// static frame, add a inner dynamic frame and navigate the dynamic
// frame. Then navigate the outer static frame and go back. The inner
// iframe should show the last entry of inner static frame.
let staticFrame = document.getElementById("staticFrame");
staticFrame.width = "320px";
staticFrame.height = "360px";
await loadUriInFrame(staticFrame, "iframe_static.html");
let innerStaticFrame = staticFrame.contentDocument.getElementById("staticFrame");
await loadUriInFrame(innerStaticFrame, "frame1.html");
let innerDynamicFrame = await createDynamicFrame(staticFrame.contentDocument, "frame2.html");
await loadUriInFrame(innerDynamicFrame, "frame3.html");
// staticFrame: frame0 -> frame1 -> frame2 -> iframe_static
// innerStaticFrame: frame0 -> frame1
// innerDynamicFrame: frame2 -> frame3
is(shistory.index, 5, "shistory.index");
is(history.length, 6, "history.length");
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.