Bug 1606366 [wpt PR 20953] - Portals: Use WebContents::ClosePage to run unload handlers for portals., a=testonly

Automatic update from web-platform-tests
Portals: Use WebContents::ClosePage to run unload handlers for portals.

On the way, refactor how the Portal <-> WebContentsImpl pointers are
maintained, as this work caused the raw WebContentsImpl* to dangling while
writing the main code of this CL, which made for a confusing bug. This
refactoring is mainly a mechanical gathering of the code responsible for
updating these into a small nested class.

Bug: 964481
Change-Id: I8a63e1a5531de4807569b35ea0f3fcb19baf343c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1976000
Reviewed-by: Adithya Srinivasan <adithyas@chromium.org>
Reviewed-by: Lucas Gadani <lfg@chromium.org>
Commit-Queue: Jeremy Roman <jbroman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#728057}

--

wpt-commits: 37a6910565388a7dc76aedd17c3aa74400d39286
wpt-pr: 20953
This commit is contained in:
Jeremy Roman 2020-01-06 16:09:15 +00:00 коммит произвёл moz-wptsync-bot
Родитель 6cc16aa449
Коммит bab449e22c
2 изменённых файлов: 61 добавлений и 0 удалений

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

@ -0,0 +1,37 @@
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/open-blank-host.js"></script>
<script>
function nextEvent(target, type) {
return new Promise((resolve, reject) => target.addEventListener(type, e => resolve(e), {once: true}));
}
function timePasses(delay) {
return new Promise((resolve, reject) => step_timeout(() => resolve(), delay));
}
promise_test(async () => {
const w = await openBlankPortalHost();
try {
const portal = w.document.createElement('portal');
portal.src = new URL('resources/simple-portal.html', location.href);
w.document.body.appendChild(portal);
const pagehideFired = nextEvent(w, 'pagehide');
const unloadFired = nextEvent(w, 'unload');
await portal.activate();
assert_true((await pagehideFired) instanceof w.PageTransitionEvent);
assert_true((await unloadFired) instanceof w.Event);
} finally {
w.close();
}
}, "pagehide and unload should fire if the predecessor is not adopted");
promise_test(async () => {
localStorage.setItem('predecessor-fires-unload-events', '');
window.open('resources/predecessor-fires-unload-watch-unload.html', '_blank', 'noopener');
while (localStorage.getItem('predecessor-fires-unload-events') != 'pagehide unload') {
await timePasses(50);
}
}, "pagehide and unload should fire if the predecessor is not adopted, even without a window/opener association");
</script>

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

@ -0,0 +1,24 @@
<!DOCTYPE html>
<body>
<script>
function nextEvent(target, type) {
return new Promise((resolve, reject) => target.addEventListener(type, e => resolve(e), {once: true}));
}
onload = function() {
const portal = document.createElement('portal');
portal.src = new URL('simple-portal.html', location.href);
document.body.appendChild(portal);
let firedEvents = [];
for (let type of ['pagehide', 'unload']) {
nextEvent(window, type).then(() => {
firedEvents.push(type);
localStorage.setItem('predecessor-fires-unload-events', firedEvents.join(' '));
});
}
portal.activate();
}
</script>
</body>