Bug 1689686 - Ensure docshell/test/navigation/test_bug1326251.html works with SHIP-BFCache, r=peterv

Differential Revision: https://phabricator.services.mozilla.com/D109945
This commit is contained in:
Olli Pettay 2021-03-30 09:27:04 +00:00
Родитель 0c43e7ec41
Коммит 07ba2fd435
3 изменённых файлов: 89 добавлений и 49 удалений

Просмотреть файл

@ -559,6 +559,15 @@ void CanonicalBrowsingContext::SessionHistoryCommit(uint64_t aLoadId,
bool addEntry = ShouldUpdateSessionHistory(aLoadType);
if (IsTop()) {
if (mActiveEntry && !mActiveEntry->GetFrameLoader()) {
bool sharesDocument = true;
mActiveEntry->SharesDocumentWith(newActiveEntry, &sharesDocument);
if (!sharesDocument) {
// If the old page won't be in the bfcache,
// clear the dynamic entries.
RemoveDynEntriesFromActiveSessionHistoryEntry();
}
}
mActiveEntry = newActiveEntry;
if (LOAD_TYPE_HAS_FLAGS(aLoadType,

Просмотреть файл

@ -4,6 +4,21 @@
<meta charset="utf-8">
<title>Bug 1326251</title>
<script>
var bc = new BroadcastChannel("file_bug1326251");
bc.onmessage = function(event) {
if ("nextTest" in event.data) {
testSteps[event.data.nextTest]();
}
}
function is(val1, val2, msg) {
bc.postMessage({type: "is", value1: val1, value2: val2, message: msg});
}
function ok(val, msg) {
bc.postMessage({type: "ok", value: val, message: msg});
}
const BASE_URL = "http://mochi.test:8888/tests/docshell/test/navigation/";
let testSteps = [
async function() {
@ -17,7 +32,7 @@
await loadUriInFrame(document.getElementById("dynamicFrame"), "frame1.html");
await loadUriInFrame(document.getElementById("staticFrame"), "frame2.html");
await loadUriInFrame(document.getElementById("dynamicFrame"), "frame2.html");
opener.is(history.length, 5, "history.length");
is(history.length, 5, "history.length");
window.location = "goback.html";
},
async function() {
@ -25,18 +40,18 @@
.docShell
.QueryInterface(SpecialPowers.Ci.nsIWebNavigation);
let shistory = webNav.sessionHistory;
opener.is(webNav.canGoForward, true, "canGoForward");
opener.is(shistory.index, 4, "shistory.index");
opener.is(history.length, 6, "history.length");
opener.is(document.getElementById("staticFrame").contentWindow.location.href, BASE_URL + "frame2.html", "staticFrame location");
opener.is(document.getElementById("dynamicFrame").contentWindow.location.href, BASE_URL + "frame2.html", "dynamicFrame location");
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");
opener.is(webNav.canGoForward, false, "canGoForward");
opener.is(shistory.index, 5, "shistory.index");
opener.is(history.length, 6, "history.length");
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.
@ -49,12 +64,16 @@
let shistory = docShell.QueryInterface(SpecialPowers.Ci.nsIWebNavigation)
.sessionHistory;
// Now staticFrame has frame0 -> frame1 -> frame2.
opener.is(docShell.previousEntryIndex, 3, "docShell.previousEntryIndex");
opener.is(docShell.loadedEntryIndex, 2, "docShell.loadedEntryIndex");
opener.is(shistory.index, 2, "shistory.index");
opener.is(history.length, 4, "history.length");
opener.is(document.getElementById("staticFrame").contentWindow.location.href, BASE_URL + "frame2.html", "staticFrame location");
opener.ok(!document.getElementById("dynamicFrame"), "dynamicFrame should not exist");
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
@ -71,8 +90,8 @@
// staticFrame: frame0 -> frame1 -> frame2 -> iframe_static
// innerStaticFrame: frame0 -> frame1
// innerDynamicFrame: frame2 -> frame3
opener.is(shistory.index, 5, "shistory.index");
opener.is(history.length, 6, "history.length");
is(shistory.index, 5, "shistory.index");
is(history.length, 6, "history.length");
// Wait for 2 load events - navigation and goback.
let onloadPromise = awaitOnload(staticFrame, 2);
@ -80,11 +99,11 @@
await onloadPromise;
// staticFrame: frame0 -> frame1 -> frame2 -> iframe_static -> goback
// innerStaticFrame: frame0 -> frame1
opener.is(shistory.index, 4, "shistory.index");
opener.is(history.length, 6, "history.length");
is(shistory.index, 4, "shistory.index");
is(history.length, 6, "history.length");
innerStaticFrame = staticFrame.contentDocument.getElementById("staticFrame");
opener.is(innerStaticFrame.contentDocument.location.href, BASE_URL + "frame1.html", "innerStaticFrame location");
opener.ok(!staticFrame.contentDocument.getElementById("dynamicFrame"), "innerDynamicFrame should not exist");
is(innerStaticFrame.contentDocument.location.href, BASE_URL + "frame1.html", "innerStaticFrame location");
ok(!staticFrame.contentDocument.getElementById("dynamicFrame"), "innerDynamicFrame should not exist");
// Test 5: Insert and navigate inner dynamic frame again with bfcache
// enabled, and navigate top level window to a special page which will
@ -98,8 +117,8 @@
// staticFrame: frame0 -> frame1 -> frame2 -> iframe_static
// innerStaticFrame: frame0 -> frame1
// innerDynamicFrame: frame2 -> frame3
opener.is(shistory.index, 5, "shistory.index");
opener.is(history.length, 6, "history.length");
is(shistory.index, 5, "shistory.index");
is(history.length, 6, "history.length");
window.location = "file_bug1326251_evict_cache.html";
},
async function() {
@ -109,14 +128,18 @@
.sessionHistory;
// staticFrame: frame0 -> frame1 -> frame2 -> iframe_static
// innerStaticFrame: frame0 -> frame1
opener.is(docShell.previousEntryIndex, 5, "docShell.previousEntryIndex");
opener.is(docShell.loadedEntryIndex, 4, "docShell.loadedEntryIndex");
opener.is(shistory.index, 4, "shistory.index");
opener.is(history.length, 6, "history.length");
if (!SpecialPowers.Services.appinfo.sessionHistoryInParent) {
// *EntryIndex attributes aren't meaningful when the session history
// lives in the parent process.
is(docShell.previousEntryIndex, 5, "docShell.previousEntryIndex");
is(docShell.loadedEntryIndex, 4, "docShell.loadedEntryIndex");
}
is(shistory.index, 4, "shistory.index");
is(history.length, 6, "history.length");
let staticFrame = document.getElementById("staticFrame");
let innerStaticFrame = staticFrame.contentDocument.getElementById("staticFrame");
opener.is(innerStaticFrame.contentDocument.location.href, BASE_URL + "frame1.html", "innerStaticFrame location");
opener.ok(!staticFrame.contentDocument.getElementById("dynamicFrame"), "innerDynamicFrame should not exist");
is(innerStaticFrame.contentDocument.location.href, BASE_URL + "frame1.html", "innerStaticFrame location");
ok(!staticFrame.contentDocument.getElementById("dynamicFrame"), "innerDynamicFrame should not exist");
// Test 6: Insert and navigate inner dynamic frame and then reload outer
// frame. Verify that inner dynamic frame entries are all removed.
@ -127,8 +150,8 @@
// staticFrame: frame0 -> frame1 -> frame2 -> iframe_static
// innerStaticFrame: frame0 -> frame1
// innerDynamicFrame: frame2 -> frame3
opener.is(shistory.index, 5, "shistory.index");
opener.is(history.length, 6, "history.length");
is(shistory.index, 5, "shistory.index");
is(history.length, 6, "history.length");
let staticFrameLoadPromise = new Promise(resolve => {
staticFrame.onload = resolve;
});
@ -136,12 +159,14 @@
await staticFrameLoadPromise;
// staticFrame: frame0 -> frame1 -> frame2 -> iframe_static
// innerStaticFrame: frame0 -> frame1
opener.is(shistory.index, 4, "shistory.index");
opener.is(history.length, 5, "history.length");
is(shistory.index, 4, "shistory.index");
is(history.length, 5, "history.length");
innerStaticFrame = staticFrame.contentDocument.getElementById("staticFrame");
opener.is(innerStaticFrame.contentDocument.location.href, BASE_URL + "frame1.html", "innerStaticFrame location");
opener.ok(!staticFrame.contentDocument.getElementById("dynamicFrame"), "innerDynamicFrame should not exist");
opener.finishTest();
is(innerStaticFrame.contentDocument.location.href, BASE_URL + "frame1.html", "innerStaticFrame location");
ok(!staticFrame.contentDocument.getElementById("dynamicFrame"), "innerDynamicFrame should not exist");
bc.postMessage("finishTest");
bc.close();
window.close();
},
];
@ -175,10 +200,7 @@
}
function test() {
if (opener) {
// Ensure the tests are not executed in onload hander.
setTimeout(testSteps[opener.testCount++], 0);
}
bc.postMessage("requestNextTest");
}
</script>
</head>

Просмотреть файл

@ -19,17 +19,26 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=
var testCount = 0;
SimpleTest.waitForExplicitFinish();
var testWindow;
function runTest() {
testWindow = window.open("file_bug1326251.html", "", "width=360,height=480");
testWindow.onunload = function() { }; // to prevent bfcache
var bc = new BroadcastChannel("file_bug1326251");
bc.onmessage = function(event) {
if (event.data == "requestNextTest") {
bc.postMessage({ nextTest: testCount++ });
} else if (event.data.type == "is") {
is(event.data.value1, event.data.value2, event.data.message);
} else if (event.data.type == "ok") {
ok(event.data.value, event.data.message);
} else if (event.data == "finishTest") {
SimpleTest.finish();
}
}
function finishTest() {
testWindow.close();
SimpleTest.finish();
SimpleTest.waitForExplicitFinish();
function runTest() {
// If Fission is disabled, the pref is no-op.
SpecialPowers.pushPrefEnv({set: [["fission.bfcacheInParent", true]]}, () => {
window.open("file_bug1326251.html", "", "width=360,height=480,noopener");
});
}
</script>