From d8bbc7858622b6d9c278469aab701ca0b609cddf Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 15 May 2024 05:35:49 +0200 Subject: Merging upstream version 126.0. Signed-off-by: Daniel Baumann --- .../tests/fenced-frame/resources/utils.js | 115 +++++++++++---------- 1 file changed, 58 insertions(+), 57 deletions(-) (limited to 'testing/web-platform/tests/fenced-frame/resources/utils.js') diff --git a/testing/web-platform/tests/fenced-frame/resources/utils.js b/testing/web-platform/tests/fenced-frame/resources/utils.js index d6cca91437..462bda37fc 100644 --- a/testing/web-platform/tests/fenced-frame/resources/utils.js +++ b/testing/web-platform/tests/fenced-frame/resources/utils.js @@ -1,5 +1,5 @@ const STORE_URL = '/fenced-frame/resources/key-value-store.py'; -const BEACON_URL = '/fenced-frame/resources/automatic-beacon-store.py'; +const BEACON_URL = '/fenced-frame/resources/beacon-store.py'; const REMOTE_EXECUTOR_URL = '/fenced-frame/resources/remote-context-executor.https.html'; // If your test needs to modify FLEDGE bidding or decision logic, you should @@ -78,7 +78,7 @@ async function runSelectURL(href, keylist = [], resolve_to_config = false) { async function generateURNFromFledgeRawURL( href, nested_urls, resolve_to_config = false, ad_with_size = false, - requested_size = null, automatic_beacon = false) { + requested_size = null, register_beacon = false) { const bidding_token = token(); const seller_token = token(); @@ -88,16 +88,19 @@ async function generateURNFromFledgeRawURL( { renderURL: url } }); - let interestGroup = - { - name: 'testAd1', - owner: location.origin, - biddingLogicURL: new URL(FLEDGE_BIDDING_URL, location.origin), - ads: [{renderURL: href, bid: 1}], - userBiddingSignals: {biddingToken: bidding_token}, - trustedBiddingSignalsKeys: ['key1'], - adComponents: ad_components_list, - }; + let interestGroup = { + name: 'testAd1', + owner: location.origin, + biddingLogicURL: new URL(FLEDGE_BIDDING_URL, location.origin), + ads: [{ + renderURL: href, + bid: 1, + allowedReportingOrigins: [location.origin], + }], + userBiddingSignals: {biddingToken: bidding_token}, + trustedBiddingSignalsKeys: ['key1'], + adComponents: ad_components_list, + }; let biddingURLParams = new URLSearchParams(interestGroup.biddingLogicURL.search); @@ -106,8 +109,8 @@ async function generateURNFromFledgeRawURL( 'requested-size', requested_size[0] + '-' + requested_size[1]); if (ad_with_size) biddingURLParams.set('ad-with-size', 1); - if (automatic_beacon) - biddingURLParams.set('automatic-beacon', 1); + if (register_beacon) + biddingURLParams.set('beacon', 1); interestGroup.biddingLogicURL.search = biddingURLParams; if (ad_with_size) { @@ -158,16 +161,16 @@ async function generateURNFromFledgeRawURL( // frame config. // @param {boolean} [ad_with_size = false] - Determines whether the auction is // run with ad sizes specified. -// @param {boolean} [automatic_beacon = false] - If true, FLEDGE logic will -// register an automatic beacon +// @param {boolean} [register_beacon = false] - If true, FLEDGE logic will +// register reporting beacons // after completion. async function generateURNFromFledge( href, keylist, nested_urls = [], resolve_to_config = false, - ad_with_size = false, requested_size = null, automatic_beacon = false) { + ad_with_size = false, requested_size = null, register_beacon = false) { const full_url = generateURL(href, keylist); return generateURNFromFledgeRawURL( full_url, nested_urls, resolve_to_config, ad_with_size, requested_size, - automatic_beacon); + register_beacon); } // Extracts a list of UUIDs from the from the current page's URL. @@ -279,7 +282,7 @@ function attachContext(object_constructor, html, headers, origin) { // 2. crbug.com/1394559: unfenced-top.https.html async function attachOpaqueContext( generator_api, resolve_to_config, ad_with_size, requested_size, - automatic_beacon, object_constructor, html, headers, origin, + register_beacon, object_constructor, html, headers, origin, num_components) { const [uuid, url] = generateRemoteContextURL(headers, origin); @@ -298,7 +301,7 @@ async function attachOpaqueContext( generator_api == 'fledge' ? generateURNFromFledge( url, [], components_list, resolve_to_config, ad_with_size, - requested_size, automatic_beacon) : + requested_size, register_beacon) : runSelectURL(url, [], resolve_to_config)); const object = object_constructor(id); return buildRemoteContextForObject(object, uuid, html); @@ -306,13 +309,12 @@ async function attachOpaqueContext( function attachPotentiallyOpaqueContext( generator_api, resolve_to_config, ad_with_size, requested_size, - automatic_beacon, frame_constructor, html, headers, origin, - num_components) { + register_beacon, frame_constructor, html, headers, origin, num_components) { generator_api = generator_api.toLowerCase(); if (generator_api == 'fledge' || generator_api == 'sharedstorage') { return attachOpaqueContext( generator_api, resolve_to_config, ad_with_size, requested_size, - automatic_beacon, frame_constructor, html, headers, origin, + register_beacon, frame_constructor, html, headers, origin, num_components); } else { return attachContext(frame_constructor, html, headers, origin); @@ -321,7 +323,7 @@ function attachPotentiallyOpaqueContext( function attachFrameContext( element_name, generator_api, resolve_to_config, ad_with_size, - requested_size, automatic_beacon, html, headers, attributes, origin, + requested_size, register_beacon, html, headers, attributes, origin, num_components) { frame_constructor = (id) => { frame = document.createElement(element_name); @@ -341,7 +343,7 @@ function attachFrameContext( }; return attachPotentiallyOpaqueContext( generator_api, resolve_to_config, ad_with_size, requested_size, - automatic_beacon, frame_constructor, html, headers, origin, + register_beacon, frame_constructor, html, headers, origin, num_components); } @@ -350,7 +352,7 @@ function replaceFrameContext(frame_proxy, { resolve_to_config = false, ad_with_size = false, requested_size = null, - automatic_beacon = false, + register_beacon = false, html = '', headers = [], origin = '' @@ -368,15 +370,15 @@ function replaceFrameContext(frame_proxy, { }; return attachPotentiallyOpaqueContext( generator_api, resolve_to_config, ad_with_size, requested_size, - automatic_beacon, frame_constructor, html, headers, origin); + register_beacon, frame_constructor, html, headers, origin); } -// Attach a fenced frame that waits for scripts to execute. -// Takes as input a(n optional) dictionary of configs: +// Attach a fenced frame that waits for scripts to execute. Takes as input a(n +// optional) dictionary of configs: // - generator_api: the name of the API that should generate the urn/config. // Supports (case-insensitive) "fledge" and "sharedstorage", or any other -// value as a default. -// If you generate a urn, then you need to await the result of this function. +// value as a default. If you generate a urn, then you need to await the +// result of this function. // - resolve_to_config: whether a config should be used. (currently only works // for FLEDGE and sharedStorage generator_api) // - ad_with_size: whether an ad auction is run with size specified for the ads @@ -385,22 +387,22 @@ function replaceFrameContext(frame_proxy, { // requestedSize in the FLEDGE auction config. This is different from // ad_with_size, which refers to size information provided alongside the ads // themselves. -// - automatic_beacon: If true and generator_api = "fledge", an automatic beacon -// will be registered for a top-level navigation after the FLEDGE auction -// completes. +// - register_beacon: If true and generator_api = "fledge", an automatic beacon +// and a destination URL reportEvent() beacon will be registered after the +// FLEDGE auction completes. // - html: extra HTML source code to inject into the loaded frame // - headers: an array of header pairs [[key, value], ...] // - attributes: an array of attribute pairs to set on the frame [[key, value], -// ...] -// - origin: origin of the url, default to location.origin if not set -// Returns a proxy that acts like the frame HTML element, but with an extra -// function `execute`. See `attachFrameContext` or the README for more details. +// ...] +// - origin: origin of the url, default to location.origin if not set. Returns a +// proxy that acts like the frame HTML element, but with an extra function +// `execute`. See `attachFrameContext` or the README for more details. function attachFencedFrameContext({ generator_api = '', resolve_to_config = false, ad_with_size = false, requested_size = null, - automatic_beacon = false, + register_beacon = false, html = '', headers = [], attributes = [], @@ -409,7 +411,7 @@ function attachFencedFrameContext({ } = {}) { return attachFrameContext( 'fencedframe', generator_api, resolve_to_config, ad_with_size, - requested_size, automatic_beacon, html, headers, attributes, origin, + requested_size, register_beacon, html, headers, attributes, origin, num_components); } @@ -417,7 +419,7 @@ function attachFencedFrameContext({ // See `attachFencedFrameContext` for more details. function attachIFrameContext({ generator_api = '', - automatic_beacon = false, + register_beacon = false, html = '', headers = [], attributes = [], @@ -426,8 +428,8 @@ function attachIFrameContext({ } = {}) { return attachFrameContext( 'iframe', generator_api, resolve_to_config = false, ad_with_size = false, - requested_size = null, automatic_beacon, html, headers, attributes, - origin, num_components); + requested_size = null, register_beacon, html, headers, attributes, origin, + num_components); } // Open a window that waits for scripts to execute. @@ -563,9 +565,9 @@ async function nextValueFromServer(key) { } } -// Checks the automatic beacon data server to see if it has received an -// automatic beacon with a given event type and body. -async function readAutomaticBeaconDataFromServer(event_type, expected_body) { +// Checks the beacon data server to see if it has received a beacon with a given +// event type and body. +async function readBeaconDataFromServer(event_type, expected_body) { let serverURL = `${BEACON_URL}`; const response = await fetch(serverURL + "?" + new URLSearchParams({ type: event_type, @@ -586,11 +588,11 @@ async function readAutomaticBeaconDataFromServer(event_type, expected_body) { // available on the server. The server uses a hash of the concatenated event // type and beacon data as the key when storing the beacon in the database. To // retrieve it, we need to supply the endpoint with both pieces of information. -async function nextAutomaticBeacon(event_type, expected_body) { +async function nextBeacon(event_type, expected_body) { while (true) { // Fetches the test result from the server. - const { status, value } = - await readAutomaticBeaconDataFromServer(event_type, expected_body); + const {status, value} = + await readBeaconDataFromServer(event_type, expected_body); if (!status) { // The test result has not been stored yet. Retry after a while. await new Promise(resolve => setTimeout(resolve, 20)); @@ -639,17 +641,16 @@ function createLocalSource(key, url) { } function setupCSP(csp, second_csp=null) { - let meta = document.createElement('meta'); - meta.httpEquiv = "Content-Security-Policy"; - meta.content = "fenced-frame-src " + csp; - document.head.appendChild(meta); + let headers = []; + headers.push(["Content-Security-Policy", "fenced-frame-src " + csp]); if (second_csp != null) { - let second_meta = document.createElement('meta'); - second_meta.httpEquiv = "Content-Security-Policy"; - second_meta.content = "frame-src " + second_csp; - document.head.appendChild(second_meta); + headers.push(["Content-Security-Policy", "frame-src " + second_csp]); } + + const iframe = attachIFrameContext({headers: headers}); + + return iframe; } // Clicking in WPT tends to be flaky (https://crbug.com/1066891), so you may -- cgit v1.2.3