Files
sousa-gecko/testing/web-platform/tests/fetch/fetch-later/new-window.https.window.js
T
Blink WPT Bot 101676ae52 Bug 1987403 [wpt PR 54738] - [fetch-later] Promote fetch-later wpt tests and fix some flakiness, a=testonly
Automatic update from web-platform-tests
[fetch-later] Promote fetch-later wpt tests and fix some flakiness (#54738)

- The [spec][1] has been merged. Remove all `.tentative` suffixes.
- Update `third_party/blink/web_tests/external/wpt/fetch/fetch-later/resources/fetch-later.html` to account for some errors like
  QuotaExceededError that can't be cloned back to parent frame.
- Fix `third_party/blink/web_tests/external/wpt/fetch/fetch-later/quota/same-origin-iframe/multiple-iframes.https.window.js` and
  remove its expectation.
- `third_party/blink/web_tests/external/wpt/fetch/fetch-later/new-window.https.window.js` is still flaky. Will address it in another CL.

[1]: https://github.com/whatwg/fetch/pull/1647

Bug: 434895695,434980772
Change-Id: Icb0d756ada01ec209a46eab7d055eb16c5b78a83
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6887785
Reviewed-by: Rune Lillesveen <futhark@chromium.org>
Commit-Queue: Ming-Ying Chung <mych@chromium.org>
Reviewed-by: Tsuyoshi Horo <horo@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1512252}

Co-authored-by: Ming-Ying Chung <mych@chromium.org>
--

wpt-commits: 89966dffac4f95ade6d83c107fed3983251db1fc
wpt-pr: 54738
2025-09-22 10:52:56 +00:00

94 lines
3.0 KiB
JavaScript

// META: script=/common/utils.js
// META: script=/common/get-host-info.sub.js
// META: script=/fetch/fetch-later/resources/fetch-later-helper.js
'use strict';
const {
HTTPS_ORIGIN,
HTTPS_NOTSAMESITE_ORIGIN,
} = get_host_info();
function fetchLaterPopupUrl(host, targetUrl) {
return `${host}/fetch/fetch-later/resources/fetch-later.html?url=${
encodeURIComponent(targetUrl)}&activateAfter=0`;
}
async function receiveMessageFromPopup(url) {
const expect =
new FetchLaterIframeExpectation(FetchLaterExpectationType.DONE);
const messageType = await new Promise((resolve, reject) => {
window.addEventListener('message', function handler(e) {
try {
if (expect.run(e, url)) {
window.removeEventListener('message', handler);
resolve(e.data.type);
}
} catch (err) {
reject(err);
}
});
});
assert_equals(messageType, FetchLaterIframeMessageType.DONE);
}
for (const target of ['', '_blank']) {
// NOTE: noopener popup window cannot communicate back. It will be too
// unreliable to only use `expectBeacon()` to test such window.
for (const features of ['', 'popup']) {
parallelPromiseTest(
async t => {
const uuid = token();
const url =
generateSetBeaconURL(uuid, {host: HTTPS_NOTSAMESITE_ORIGIN});
// Opens a blank popup window that fires a fetchLater request.
const w = window.open(
`javascript: fetchLater("${url}", {activateAfter: 0})`, target,
features);
await new Promise(resolve => w.addEventListener('load', resolve));
// The popup should have sent the request.
await expectBeacon(uuid, {count: 1});
w.close();
},
`A blank window[target='${target}'][features='${
features}'] can trigger fetchLater.`);
parallelPromiseTest(
async t => {
const uuid = token();
const popupUrl =
fetchLaterPopupUrl(HTTPS_ORIGIN, generateSetBeaconURL(uuid));
// Opens a same-origin popup that fires a fetchLater request.
const w = window.open(popupUrl, target, features);
await receiveMessageFromPopup(popupUrl);
// The popup should have sent the request.
await expectBeacon(uuid, {count: 1});
w.close();
},
`A same-origin window[target='${target}'][features='${
features}'] can trigger fetchLater.`);
parallelPromiseTest(
async t => {
const uuid = token();
const popupUrl = fetchLaterPopupUrl(
HTTPS_NOTSAMESITE_ORIGIN, generateSetBeaconURL(uuid));
// Opens a cross-origin popup that fires a fetchLater request.
const w = window.open(popupUrl, target, features);
await receiveMessageFromPopup(popupUrl);
// The popup should have sent the request.
await expectBeacon(uuid, {count: 1});
w.close();
},
`A cross-origin window[target='${target}'][features='${
features}'] can trigger fetchLater.`);
}
}