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

Fix selectURL() loaded iframes not getting window.fence. #50394

Merged
merged 1 commit into from
Feb 3, 2025
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
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