зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1795287 [wpt PR 36458] - [Private Network Access] Parallelize iframe WPTs., a=testonly
Automatic update from web-platform-tests [Private Network Access] Parallelize iframe WPTs. As suggested by arthursonzogni@ in crrev.com/c/3916090. Bug: chromium:1291252 Change-Id: Icce72a136ce61922155f800756d6d7bfc82d3741 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3952121 Reviewed-by: Arthur Sonzogni <arthursonzogni@chromium.org> Commit-Queue: Arthur Sonzogni <arthursonzogni@chromium.org> Auto-Submit: Titouan Rigoudy <titouan@chromium.org> Commit-Queue: Titouan Rigoudy <titouan@chromium.org> Cr-Commit-Position: refs/heads/main@{#1060961} -- wpt-commits: 29092aadd2d9fa61dfd7d9c07f179a417cb1ac70 wpt-pr: 36458
This commit is contained in:
Родитель
e67ba385c9
Коммит
b1ef0faab8
|
@ -1,6 +1,5 @@
|
|||
// META: script=/common/utils.js
|
||||
// META: script=resources/support.sub.js
|
||||
// META: timeout=long
|
||||
//
|
||||
// Spec: https://wicg.github.io/private-network-access/#integration-fetch
|
||||
//
|
||||
|
@ -15,62 +14,62 @@ setup(() => {
|
|||
assert_false(window.isSecureContext);
|
||||
});
|
||||
|
||||
promise_test(t => iframeTest(t, {
|
||||
promise_test_parallel(t => iframeTest(t, {
|
||||
source: { server: Server.HTTP_LOCAL },
|
||||
target: { server: Server.HTTP_LOCAL },
|
||||
expected: IframeTestResult.SUCCESS,
|
||||
}), "local to local: no preflight required.");
|
||||
|
||||
promise_test(t => iframeTest(t, {
|
||||
promise_test_parallel(t => iframeTest(t, {
|
||||
source: { server: Server.HTTP_LOCAL },
|
||||
target: { server: Server.HTTP_PRIVATE },
|
||||
expected: IframeTestResult.SUCCESS,
|
||||
}), "local to private: no preflight required.");
|
||||
|
||||
promise_test(t => iframeTest(t, {
|
||||
promise_test_parallel(t => iframeTest(t, {
|
||||
source: { server: Server.HTTP_LOCAL },
|
||||
target: { server: Server.HTTP_PUBLIC },
|
||||
expected: IframeTestResult.SUCCESS,
|
||||
}), "local to public: no preflight required.");
|
||||
|
||||
promise_test(t => iframeTest(t, {
|
||||
promise_test_parallel(t => iframeTest(t, {
|
||||
source: { server: Server.HTTP_PRIVATE },
|
||||
target: { server: Server.HTTP_LOCAL },
|
||||
expected: IframeTestResult.FAILURE,
|
||||
}), "private to local: failure.");
|
||||
|
||||
promise_test(t => iframeTest(t, {
|
||||
promise_test_parallel(t => iframeTest(t, {
|
||||
source: { server: Server.HTTP_PRIVATE },
|
||||
target: { server: Server.HTTP_PRIVATE },
|
||||
expected: IframeTestResult.SUCCESS,
|
||||
}), "private to private: no preflight required.");
|
||||
|
||||
promise_test(t => iframeTest(t, {
|
||||
promise_test_parallel(t => iframeTest(t, {
|
||||
source: { server: Server.HTTP_PRIVATE },
|
||||
target: { server: Server.HTTP_PUBLIC },
|
||||
expected: IframeTestResult.SUCCESS,
|
||||
}), "private to public: no preflight required.");
|
||||
|
||||
promise_test(t => iframeTest(t, {
|
||||
promise_test_parallel(t => iframeTest(t, {
|
||||
source: { server: Server.HTTP_PUBLIC },
|
||||
target: { server: Server.HTTP_LOCAL },
|
||||
expected: IframeTestResult.FAILURE,
|
||||
}), "public to local: failure.");
|
||||
|
||||
|
||||
promise_test(t => iframeTest(t, {
|
||||
promise_test_parallel(t => iframeTest(t, {
|
||||
source: { server: Server.HTTP_PUBLIC },
|
||||
target: { server: Server.HTTP_PRIVATE },
|
||||
expected: IframeTestResult.FAILURE,
|
||||
}), "public to private: failure.");
|
||||
|
||||
promise_test(t => iframeTest(t, {
|
||||
promise_test_parallel(t => iframeTest(t, {
|
||||
source: { server: Server.HTTP_PUBLIC },
|
||||
target: { server: Server.HTTP_PUBLIC },
|
||||
expected: IframeTestResult.SUCCESS,
|
||||
}), "public to public: no preflight required.");
|
||||
|
||||
promise_test(t => iframeTest(t, {
|
||||
promise_test_parallel(t => iframeTest(t, {
|
||||
source: {
|
||||
server: Server.HTTP_LOCAL,
|
||||
treatAsPublic: true,
|
||||
|
@ -79,7 +78,7 @@ promise_test(t => iframeTest(t, {
|
|||
expected: IframeTestResult.FAILURE,
|
||||
}), "treat-as-public-address to local: failure.");
|
||||
|
||||
promise_test(t => iframeTest(t, {
|
||||
promise_test_parallel(t => iframeTest(t, {
|
||||
source: {
|
||||
server: Server.HTTP_LOCAL,
|
||||
treatAsPublic: true,
|
||||
|
@ -88,7 +87,7 @@ promise_test(t => iframeTest(t, {
|
|||
expected: IframeTestResult.FAILURE,
|
||||
}), "treat-as-public-address to private: failure.");
|
||||
|
||||
promise_test(t => iframeTest(t, {
|
||||
promise_test_parallel(t => iframeTest(t, {
|
||||
source: {
|
||||
server: Server.HTTP_LOCAL,
|
||||
treatAsPublic: true,
|
||||
|
|
|
@ -2,5 +2,6 @@
|
|||
<meta charset="utf-8">
|
||||
<title>Iframed</title>
|
||||
<script>
|
||||
top.postMessage("loaded", "*");
|
||||
const uuid = new URL(window.location).searchParams.get("iframe-uuid");
|
||||
top.postMessage({ uuid, message: "loaded" }, "*");
|
||||
</script>
|
||||
|
|
|
@ -1,38 +1,42 @@
|
|||
// Creates a new iframe in |doc|, calls |func| on it and appends it as a child
|
||||
// of |doc|.
|
||||
// Creates a new iframe in `doc`, calls `func` on it and appends it as a child
|
||||
// of `doc`.
|
||||
// Returns a promise that resolves to the iframe once loaded (successfully or
|
||||
// not).
|
||||
// The iframe is removed from |doc| once test |t| is done running.
|
||||
// The iframe is removed from `doc` once test `t` is done running.
|
||||
//
|
||||
// NOTE: Because iframe elements always invoke the onload event handler, even
|
||||
// in case of error, we cannot wire onerror to a promise rejection. The Promise
|
||||
// constructor requires users to resolve XOR reject the promise.
|
||||
// NOTE: There exists no interoperable way to check whether an iframe failed to
|
||||
// load, so this should only be used when the iframe is expected to load. It
|
||||
// also means we cannot wire the iframe's `error` event to a promise
|
||||
// rejection. See: https://github.com/whatwg/html/issues/125
|
||||
function appendIframeWith(t, doc, func) {
|
||||
return new Promise(resolve => {
|
||||
const child = doc.createElement("iframe");
|
||||
t.add_cleanup(() => child.remove());
|
||||
|
||||
child.addEventListener("load", () => resolve(child), { once: true });
|
||||
func(child);
|
||||
child.onload = () => { resolve(child); };
|
||||
doc.body.appendChild(child);
|
||||
t.add_cleanup(() => { doc.body.removeChild(child); });
|
||||
});
|
||||
}
|
||||
|
||||
// Appends a child iframe to |doc| sourced from |src|.
|
||||
// Appends a child iframe to `doc` sourced from `src`.
|
||||
//
|
||||
// See append_child_frame_with() for more details.
|
||||
// See `appendIframeWith()` for more details.
|
||||
function appendIframe(t, doc, src) {
|
||||
return appendIframeWith(t, doc, child => { child.src = src; });
|
||||
}
|
||||
|
||||
// Register an event listener that will resolve this promise when this
|
||||
// Registers an event listener that will resolve this promise when this
|
||||
// window receives a message posted to it.
|
||||
//
|
||||
// `options` has the following shape:
|
||||
//
|
||||
// {
|
||||
// // If specified, this function waits for the first message from the given
|
||||
// // source only, ignoring other messages.
|
||||
// source,
|
||||
// source: If specified, this function waits for the first message from the
|
||||
// given source only, ignoring other messages.
|
||||
//
|
||||
// filter: If specified, this function calls `filter` on each incoming
|
||||
// message, and resolves iff it returns true.
|
||||
// }
|
||||
//
|
||||
function futureMessage(options) {
|
||||
|
@ -42,11 +46,26 @@ function futureMessage(options) {
|
|||
return;
|
||||
}
|
||||
|
||||
if (options?.filter && !options.filter(e.data)) {
|
||||
return;
|
||||
}
|
||||
|
||||
resolve(e.data);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// Like `promise_test()`, but executes tests in parallel like `async_test()`.
|
||||
//
|
||||
// Cribbed from COEP tests.
|
||||
function promise_test_parallel(promise, description) {
|
||||
async_test(test => {
|
||||
promise(test)
|
||||
.then(() => test.done())
|
||||
.catch(test.step_func(error => { throw error; }));
|
||||
}, description);
|
||||
};
|
||||
|
||||
async function postMessageAndAwaitReply(target, message) {
|
||||
const reply = futureMessage({ source: target });
|
||||
target.postMessage(message, "*");
|
||||
|
@ -342,21 +361,28 @@ const IframeTestResult = {
|
|||
};
|
||||
|
||||
async function iframeTest(t, { source, target, expected }) {
|
||||
// Allows running tests in parallel.
|
||||
const uuid = token();
|
||||
|
||||
const targetUrl = preflightUrl(target);
|
||||
targetUrl.searchParams.set("file", "iframed.html");
|
||||
targetUrl.searchParams.set("iframe-uuid", uuid);
|
||||
|
||||
const sourceUrl =
|
||||
resolveUrl("resources/iframer.html", sourceResolveOptions(source));
|
||||
sourceUrl.searchParams.set("url", targetUrl);
|
||||
|
||||
const messagePromise = futureMessage();
|
||||
const messagePromise = futureMessage({
|
||||
filter: (data) => data.uuid === uuid,
|
||||
});
|
||||
const iframe = await appendIframe(t, document, sourceUrl);
|
||||
|
||||
// The grandchild frame posts a message iff it loads successfully.
|
||||
// There exists no interoperable way to check whether an iframe failed to
|
||||
// load, so we use a timeout. See: https://github.com/whatwg/html/issues/125
|
||||
// load, so we use a timeout.
|
||||
// See: https://github.com/whatwg/html/issues/125
|
||||
const result = await Promise.race([
|
||||
messagePromise,
|
||||
messagePromise.then((data) => data.message),
|
||||
new Promise((resolve) => {
|
||||
t.step_timeout(() => resolve("timeout"), 500 /* ms */);
|
||||
}),
|
||||
|
|
Загрузка…
Ссылка в новой задаче