mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-03 18:47:53 +00:00
Bug 1740516 - Fire pageshow for an iframe before the pageshow for its parent window when coming out of BFCache with session history in parent. r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D131891
This commit is contained in:
parent
b3c7bf3a3e
commit
d8fcefcdde
@ -2910,12 +2910,21 @@ void BrowsingContext::DidSet(FieldIndex<IDX_IsInBFCache>) {
|
|||||||
nsDocShell::Cast(mDocShell)->MaybeDisconnectChildListenersOnPageHide();
|
nsDocShell::Cast(mDocShell)->MaybeDisconnectChildListenersOnPageHide();
|
||||||
}
|
}
|
||||||
|
|
||||||
PreOrderWalk([&](BrowsingContext* aContext) {
|
if (isInBFCache) {
|
||||||
nsCOMPtr<nsIDocShell> shell = aContext->GetDocShell();
|
PreOrderWalk([&](BrowsingContext* aContext) {
|
||||||
if (shell) {
|
nsCOMPtr<nsIDocShell> shell = aContext->GetDocShell();
|
||||||
nsDocShell::Cast(shell)->FirePageHideShowNonRecursive(!isInBFCache);
|
if (shell) {
|
||||||
}
|
nsDocShell::Cast(shell)->FirePageHideShowNonRecursive(false);
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
PostOrderWalk([&](BrowsingContext* aContext) {
|
||||||
|
nsCOMPtr<nsIDocShell> shell = aContext->GetDocShell();
|
||||||
|
if (shell) {
|
||||||
|
nsDocShell::Cast(shell)->FirePageHideShowNonRecursive(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (isInBFCache) {
|
if (isInBFCache) {
|
||||||
PreOrderWalk([&](BrowsingContext* aContext) {
|
PreOrderWalk([&](BrowsingContext* aContext) {
|
||||||
|
29
docshell/test/mochitest/file_bug1740516_1.html
Normal file
29
docshell/test/mochitest/file_bug1740516_1.html
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
<!DOCTYPE HTML>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<script>
|
||||||
|
window.addEventListener("pageshow", ({ persisted }) => {
|
||||||
|
let bc = new BroadcastChannel("bug1740516_1");
|
||||||
|
bc.addEventListener("message", ({ data }) => {
|
||||||
|
bc.close();
|
||||||
|
switch (data) {
|
||||||
|
case "block_bfcache_and_navigate":
|
||||||
|
window.onunload = () => {};
|
||||||
|
// Fall through
|
||||||
|
case "navigate":
|
||||||
|
document.location = "file_bug1740516_2.html";
|
||||||
|
break;
|
||||||
|
case "close":
|
||||||
|
window.close();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
bc.postMessage(persisted);
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<iframe src="file_bug1740516_1_inner.html"></iframe>
|
||||||
|
</body>
|
||||||
|
</html>
|
15
docshell/test/mochitest/file_bug1740516_1_inner.html
Normal file
15
docshell/test/mochitest/file_bug1740516_1_inner.html
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<!DOCTYPE HTML>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<script>
|
||||||
|
window.addEventListener("pageshow", ({ persisted }) => {
|
||||||
|
let bc = new BroadcastChannel("bug1740516_1_inner");
|
||||||
|
bc.postMessage(persisted);
|
||||||
|
bc.close();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
</body>
|
||||||
|
</html>
|
11
docshell/test/mochitest/file_bug1740516_2.html
Normal file
11
docshell/test/mochitest/file_bug1740516_2.html
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<!DOCTYPE HTML>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<script>
|
||||||
|
addEventListener("pageshow", () => { history.back(); });
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -112,6 +112,11 @@ support-files = file_bug675587.html
|
|||||||
[test_bug1729662.html]
|
[test_bug1729662.html]
|
||||||
support-files =
|
support-files =
|
||||||
file_bug1729662.html
|
file_bug1729662.html
|
||||||
|
[test_bug1740516.html]
|
||||||
|
support-files =
|
||||||
|
file_bug1740516_1.html
|
||||||
|
file_bug1740516_1_inner.html
|
||||||
|
file_bug1740516_2.html
|
||||||
[test_close_onpagehide_by_history_back.html]
|
[test_close_onpagehide_by_history_back.html]
|
||||||
[test_close_onpagehide_by_window_close.html]
|
[test_close_onpagehide_by_window_close.html]
|
||||||
[test_compressed_multipart.html]
|
[test_compressed_multipart.html]
|
||||||
|
76
docshell/test/mochitest/test_bug1740516.html
Normal file
76
docshell/test/mochitest/test_bug1740516.html
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
<!DOCTYPE HTML>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>Test pageshow event order for iframe</title>
|
||||||
|
<script src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||||
|
<link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
|
||||||
|
<script>
|
||||||
|
SimpleTest.waitForExplicitFinish();
|
||||||
|
|
||||||
|
function waitForPageShow(outer, inner) {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
let results = [];
|
||||||
|
outer.addEventListener("message", ({ data: persisted }) => {
|
||||||
|
results.push({ name: outer.name, persisted });
|
||||||
|
if (results.length == 2) {
|
||||||
|
resolve(results);
|
||||||
|
}
|
||||||
|
}, { once: true });
|
||||||
|
inner.addEventListener("message", ({ data: persisted }) => {
|
||||||
|
results.push({ name: inner.name, persisted });
|
||||||
|
if (results.length == 2) {
|
||||||
|
resolve(results);
|
||||||
|
}
|
||||||
|
}, { once: true });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
async function runTest() {
|
||||||
|
let outerBC = new BroadcastChannel("bug1740516_1");
|
||||||
|
let innerBC = new BroadcastChannel("bug1740516_1_inner");
|
||||||
|
|
||||||
|
let check = waitForPageShow(outerBC, innerBC).then(([first, second]) => {
|
||||||
|
is(first.name, "bug1740516_1_inner", "Should get pageShow from inner iframe page first.");
|
||||||
|
ok(!first.persisted, "First navigation shouldn't come from BFCache.");
|
||||||
|
is(second.name, "bug1740516_1", "Should get pageShow from outer page second.");
|
||||||
|
ok(!second.persisted, "First navigation shouldn't come from BFCache.");
|
||||||
|
}, () => {
|
||||||
|
ok(false, "The promises should not be rejected.");
|
||||||
|
});
|
||||||
|
window.open("file_bug1740516_1.html", "", "noopener");
|
||||||
|
await check;
|
||||||
|
|
||||||
|
check = waitForPageShow(outerBC, innerBC).then(([first, second]) => {
|
||||||
|
is(first.name, "bug1740516_1_inner", "Should get pageShow from inner iframe page first.");
|
||||||
|
ok(first.persisted, "Second navigation should come from BFCache");
|
||||||
|
is(second.name, "bug1740516_1", "Should get pageShow from outer page second.");
|
||||||
|
ok(second.persisted, "Second navigation should come from BFCache");
|
||||||
|
}, () => {
|
||||||
|
ok(false, "The promises should not be rejected.");
|
||||||
|
});
|
||||||
|
outerBC.postMessage("navigate");
|
||||||
|
await check;
|
||||||
|
|
||||||
|
check = waitForPageShow(outerBC, innerBC).then(([first, second]) => {
|
||||||
|
is(first.name, "bug1740516_1_inner", "Should get pageShow from inner iframe page first.");
|
||||||
|
ok(!first.persisted, "Third navigation should not come from BFCache");
|
||||||
|
is(second.name, "bug1740516_1", "Should get pageShow from outer page second.");
|
||||||
|
ok(!second.persisted, "Third navigation should not come from BFCache");
|
||||||
|
}, () => {
|
||||||
|
ok(false, "The promises should not be rejected.");
|
||||||
|
});
|
||||||
|
outerBC.postMessage("block_bfcache_and_navigate");
|
||||||
|
await check;
|
||||||
|
|
||||||
|
outerBC.postMessage("close");
|
||||||
|
|
||||||
|
SimpleTest.finish();
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
<body onload="runTest();">
|
||||||
|
<p id="display"></p>
|
||||||
|
<div id="content" style="display: none"></div>
|
||||||
|
<pre id="test"></pre>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in New Issue
Block a user