Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AnonymousIframe: WPT BroadcastChannel #2 #32346

Merged
merged 1 commit into from
Jan 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// META: timeout=long
// META: script=/common/get-host-info.sub.js
// META: script=/common/utils.js
// META: script=/common/dispatcher/dispatcher.js
Expand All @@ -16,7 +17,15 @@ const emit_script = (key, message) => `
bc.postMessage("${message}");
`;

promise_test(async test => {
// For incorrect web browser implementations, some tests are failing by timing
// out. Calling this function turns timeout into errors. This informs developers
// about which precise test is failing.
const errorOnTimeout = test =>
test.step_timeout(test.unreached_func("Timeout"), 9000);

promise_test_parallel(async test => {
errorOnTimeout(test);

const origin = get_host_info().HTTPS_REMOTE_ORIGIN;
const key_1 = token();
const key_2 = token();
Expand Down Expand Up @@ -53,4 +62,78 @@ promise_test(async test => {
send(iframe_normal, emit_script(key_2, "msg_4"));
assert_equals(await receive(queue_1), "msg_3");
assert_equals(await receive(queue_2), "msg_4");
})
}, "Anonymous iframe and normal iframe aren't in the same partition")

promise_test_parallel(async test => {
errorOnTimeout(test);

const origin = get_host_info().HTTPS_REMOTE_ORIGIN;
const key = token();

const iframe_anonymous_1 = newAnonymousIframe(origin);
const iframe_anonymous_2 = newAnonymousIframe(origin);
const queue = token();

send(iframe_anonymous_1 , listen_script(key, queue, queue));
assert_equals(await receive(queue), "registered");
send(iframe_anonymous_2, emit_script(key, "msg"));
assert_equals(await receive(queue), "msg");
}, "Two sibling same-origin anonymous iframes are in the same partition");

promise_test_parallel(async test => {
errorOnTimeout(test);

const origin = get_host_info().HTTPS_REMOTE_ORIGIN;
const key = token();
const queue = token();

const iframe_anonymous_1 = newAnonymousIframe(origin);
send(iframe_anonymous_1, `
const importScript = ${importScript};
await importScript("/common/utils.js");
await importScript("/html/cross-origin-embedder-policy/credentialless" +
"/resources/common.js");
const newAnonymousIframe = ${newAnonymousIframe};
const iframe_anonymous_2 = newAnonymousIframe("${origin}");
send("${queue}", iframe_anonymous_2);
`);
const iframe_anonymous_2 = await receive(queue);

send(iframe_anonymous_1 , listen_script(key, queue, queue));
assert_equals(await receive(queue), "registered");
send(iframe_anonymous_2, emit_script(key, "msg"));
assert_equals(await receive(queue), "msg");
}, "Nested same-origin anonymous iframe are in the same partition");

promise_test_parallel(async test => {
errorOnTimeout(test);

const origin = get_host_info().HTTPS_REMOTE_ORIGIN;
const key = token();
const queue = token();

const iframe_anonymous_1 = newAnonymousIframe(origin);
const popup = newPopup(origin);
send(popup, `
const importScript = ${importScript};
await importScript("/common/utils.js");
await importScript("/html/cross-origin-embedder-policy/credentialless" +
"/resources/common.js");
const newAnonymousIframe = ${newAnonymousIframe};
send("${queue}", newAnonymousIframe("${origin}"));
`);
const iframe_anonymous_2 = await receive(queue);

const unexpected_queue = token();
receive(unexpected_queue).then(test.unreached_func(
"Two same-origin anonymous iframe in different windows shouldn't be able " +
"to communicate using BroadcastChannel"));

send(iframe_anonymous_1 , listen_script(key, queue, unexpected_queue));
assert_equals(await receive(queue), "registered");
await send(iframe_anonymous_2, emit_script(key, "msg"));

// Wait a bit to give the opportunity for unexpected message to be received.
await new Promise(r => test.step_timeout(r, 500));
}, "Two anonymous iframes in different windows do not share the same " +
"partition");
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,20 @@ const newIframe = (child_origin) => {
document.body.appendChild(iframe);
return sub_document_token;
};

// Create a popup. The new document will execute any scripts sent toward the
// token it returns.
const newPopup = (origin) => {
const popup_token = token();
const popup = window.open(origin + executor_path + `&uuid=${popup_token}`);
return popup_token;
};

const importScript = (url) => {
const script = document.createElement("script");
script.type = "text/javascript";
script.src = url;
const loaded = new Promise(resolve => script.onload = resolve);
document.body.appendChild(script);
return loaded;
}