Skip to content

Commit

Permalink
Fix selectURL() loaded iframes not getting window.fence. (web-platfor…
Browse files Browse the repository at this point in the history
…m-tests#50394)

We are temporarily allowing APIs like Protected Audience and Shared
Storage selectURL() to load into iframes as part of the fenced frame
transition process. As part of this, we expose the fenced frame
window.fence call to these kinds of iframes. This was launched as part
of the fenced frames launch.
See: https://chromestatus.com/feature/5699388062040064

A restriction currently exists where the config created by the API must
have some kind of reporting metadata to give the iframe access to
window.fence. This is a legacy restriction and is no longer necessary,
and it results in selectURL()-created iframes without reporting metadata
supplied from accessing window.fence.

This CL fixes that by removing the restriction. It also adds a test to
check the selectURL() without reporting path. It also updates the fenced
frame WPT infrastructure to allow selectURL() to be invoked with or
without reporting metadata.

As part of this change, the renderer is no longer being told whether the
fenced frame has reporting metadata. This is information that can be
determined in the browser rather than calculating it on the
renderer-side and then verifying the calculation in the browser, so
having the renderer be part of this check is unnecessary.

Change-Id: Ieec3cdaa31cd62bfe6fdb1993e13d68f00f00f28
Bug: 392650252
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6197762
Reviewed-by: Shivani Sharma <[email protected]>
Commit-Queue: Liam Brady <[email protected]>
Reviewed-by: Arthur Sonzogni <[email protected]>
Reviewed-by: Daniel Cheng <[email protected]>
Reviewed-by: Xiaochen Zhou <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1413688}

Co-authored-by: Liam Brady <[email protected]>
  • Loading branch information
chromium-wpt-export-bot and Liam Brady authored Feb 3, 2025
1 parent 1691f56 commit 03ab2bf
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 13 deletions.
3 changes: 2 additions & 1 deletion fenced-frame/automatic-beacon-shared-storage.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
const actions = new test_driver.Actions();
const fencedframe = await attachFencedFrameContext(
{generator_api: 'sharedstorage',
origin: get_host_info().HTTPS_REMOTE_ORIGIN});
origin: get_host_info().HTTPS_REMOTE_ORIGIN,
register_beacon: true});

let start_event = {
eventType: "reserved.top_navigation_start",
Expand Down
31 changes: 31 additions & 0 deletions fenced-frame/fence-object-urn-iframe.https.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!DOCTYPE html>
<title>Test window.fence exists in URN iframes.</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/utils.js"></script>
<script src="/common/dispatcher/dispatcher.js"></script>
<script src="resources/utils.js"></script>

<body>
<script>
async function runTest(generator_api) {
const frame = await attachIFrameContext({
generator_api: generator_api,
register_beacon: false,
});

await frame.execute(() => {
assert_true(window.fence != null, "window.fence should exist");
});
}

promise_test(async () => {
return runTest("fledge");
}, 'window.fence in a URN iframe created with Protected Audience');

promise_test(async () => {
return runTest("sharedstorage");
}, 'window.fence in a URN iframe created with Shared Storage');

</script>
</body>
3 changes: 2 additions & 1 deletion fenced-frame/fence-report-event-sub-fencedframe.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
});
await fencedframe.execute(async () => {
const fencedframe = await attachFencedFrameContext({
generator_api: 'sharedstorage'
generator_api: 'sharedstorage',
register_beacon: true
});
await fencedframe.execute(() => {
const destination_url = new URL(BEACON_URL + "?type=url",
Expand Down
27 changes: 16 additions & 11 deletions fenced-frame/resources/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ function getRemoteContextURL(origin) {
return new URL(REMOTE_EXECUTOR_URL, origin);
}

async function runSelectRawURL(href, resolve_to_config = false) {
async function runSelectRawURL(
href, resolve_to_config = false, register_beacon = false) {
try {
await sharedStorage.worklet.addModule(
"/shared-storage/resources/simple-module.js");
Expand All @@ -35,14 +36,17 @@ async function runSelectRawURL(href, resolve_to_config = false) {
// in a try/catch so that if it runs a second time in a test, it will
// gracefully fail rather than bring the whole test down.
}
let operation = {url: href};
if (register_beacon) {
operation.reportingMetadata = {
'reserved.top_navigation_start':
BEACON_URL + '?type=reserved.top_navigation_start',
'reserved.top_navigation_commit':
BEACON_URL + '?type=reserved.top_navigation_commit',
};
}
return await sharedStorage.selectURL(
'test-url-selection-operation', [{url: href,
reportingMetadata: {
'reserved.top_navigation_start': BEACON_URL +
"?type=reserved.top_navigation_start",
'reserved.top_navigation_commit': BEACON_URL +
"?type=reserved.top_navigation_commit",
}}], {
'test-url-selection-operation', [operation], {
data: {'mockResult': 0},
resolveToConfig: resolve_to_config,
keepAlive: true,
Expand Down Expand Up @@ -71,9 +75,10 @@ async function runSelectRawURL(href, resolve_to_config = false) {
// needs to be enabled for `selectURL()` to return a fenced frame config.
// Otherwise `selectURL()` will fall back to the old behavior that returns an
// urn:uuid.
async function runSelectURL(href, keylist = [], resolve_to_config = false) {
async function runSelectURL(
href, keylist = [], resolve_to_config = false, register_beacon = false) {
const full_url = generateURL(href, keylist);
return await runSelectRawURL(full_url, resolve_to_config);
return await runSelectRawURL(full_url, resolve_to_config, register_beacon);
}

async function generateURNFromFledgeRawURL(
Expand Down Expand Up @@ -302,7 +307,7 @@ async function attachOpaqueContext(
generateURNFromFledge(
url, [], components_list, resolve_to_config, ad_with_size,
requested_size, register_beacon) :
runSelectURL(url, [], resolve_to_config));
runSelectURL(url, [], resolve_to_config, register_beacon));
const object = object_constructor(id);
return buildRemoteContextForObject(object, uuid, html);
}
Expand Down

0 comments on commit 03ab2bf

Please sign in to comment.