Bug 1500869 - Test that BrowsingContexts work with BFCache. r=peterv

Differential Revision: https://phabricator.services.mozilla.com/D9367

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Andreas Farre 2018-10-30 09:58:47 +00:00
Родитель e4eacc915f
Коммит 719ab63a7d
4 изменённых файлов: 92 добавлений и 0 удалений

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

@ -55,6 +55,8 @@ support-files =
head.js
frame-head.js
file_click_link_within_view_source.html
onload_message.html
onpageshow_message.html
[browser_bug1206879.js]
[browser_bug1309900_crossProcessHistoryNavigation.js]

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

@ -122,3 +122,67 @@ add_task(async function() {
todo_isnot(browsingContext2.parent, browsingContext1);
});
});
add_task(async function() {
await BrowserTestUtils.withNewTab({ gBrowser, url: getRootDirectory(gTestPath).replace("chrome://mochitests/content", "http://example.com") + "dummy_page.html" },
async function(browser) {
let path = getRootDirectory(gTestPath).replace("chrome://mochitests/content", "http://example.com");
await ContentTask.spawn(browser, path, async function(path) {
function waitForMessage(command) {
let r;
let p = new Promise(resolve => {
content.window.addEventListener('message', e => resolve({result: r, event: e}),
{once: true});
});
r = command();
return p;
}
// Open a new window and wait for the message.
let { result: win, event: e1 } =
await waitForMessage(
_ => content.window.open(path + "onpageshow_message.html"));
is(e1.data, "pageshow");
{
// Create, attach and load an iframe into the window's document.
let frame = win.document.createElement('iframe');
win.document.body.appendChild(frame);
frame.src = "dummy_page.html";
await ContentTaskUtils.waitForEvent(frame, "load");
}
is(win.frames.length, 1, "Here we should have an iframe");
// The frame should have expected browsing context and docshell.
let frameBC = win.frames[0].docShell.browsingContext;
let winDocShell = win.frames[0].docShell;
// Navigate the window and wait for the message.
let { event: e2 } = await waitForMessage(
_ => win.location = path + "onload_message.html");
is(e2.data, "load");
is(win.frames.length, 0, "Here there shouldn't be an iframe");
// Return to the previous document. N.B. we expect to trigger
// BFCache here, hence we wait for pageshow.
let { event: e3 } = await waitForMessage(_ => win.history.back());
is(e3.data, "pageshow");
is(win.frames.length, 1, "And again there should be an iframe");
is(winDocShell, win.frames[0].docShell, "BF cache cached docshell");
is(frameBC, win.frames[0].docShell.browsingContext, "BF cache cached BC");
is(frameBC.id, win.frames[0].docShell.browsingContext.id,
"BF cached BC's have same id");
is(win.docShell.browsingContext.getChildren()[0], frameBC,
"BF cached BC's should still be a child of its parent");
is(win.docShell.browsingContext, frameBC.parent,
"BF cached BC's should still be a connected to its parent");
win.close();
});
});
});

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

@ -0,0 +1,13 @@
<html>
<head>
<meta charset="utf-8">
<script>
addEventListener('load', function() {
opener.postMessage("load", "*");
});
</script>
</head>
<body>
This file posts a message containing "load" to opener on load completion.
</body>
</html>

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

@ -0,0 +1,13 @@
<html>
<head>
<meta charset="utf-8">
<script>
addEventListener('pageshow', function() {
opener.postMessage("pageshow", "*");
});
</script>
</head>
<body>
This file posts a message containing "pageshow" to opener on pageshow.
</body>
</html>