diff options
Diffstat (limited to 'testing/web-platform/tests/fenced-frame/resources')
8 files changed, 139 insertions, 125 deletions
diff --git a/testing/web-platform/tests/fenced-frame/resources/automatic-beacon-helper.js b/testing/web-platform/tests/fenced-frame/resources/automatic-beacon-helper.js index d0a4133e84..8286c94fec 100644 --- a/testing/web-platform/tests/fenced-frame/resources/automatic-beacon-helper.js +++ b/testing/web-platform/tests/fenced-frame/resources/automatic-beacon-helper.js @@ -92,13 +92,12 @@ async function setupAutomaticBeacon( async function verifyBeaconData( event_type, event_data, expected_success = true, t) { if (expected_success) { - const beacon_initiator_origin = - await nextAutomaticBeacon(event_type, event_data); + const beacon_initiator_origin = await nextBeacon(event_type, event_data); assert_equals(beacon_initiator_origin, get_host_info().HTTPS_ORIGIN); } else { const timeout = new Promise(r => t.step_timeout(r, 1000)); - const result = await Promise.race( - [nextAutomaticBeacon(event_type, event_data), timeout]); + const result = + await Promise.race([nextBeacon(event_type, event_data), timeout]); assert_true(typeof result === 'undefined'); } } diff --git a/testing/web-platform/tests/fenced-frame/resources/automatic-beacon-store.py b/testing/web-platform/tests/fenced-frame/resources/automatic-beacon-store.py deleted file mode 100644 index ba1b73201b..0000000000 --- a/testing/web-platform/tests/fenced-frame/resources/automatic-beacon-store.py +++ /dev/null @@ -1,44 +0,0 @@ -""" -Automatic beacon store server. - -- When a request body is specified, stores the data in the body and serves a 200 - response without body. -- When a request body is not specified, serves a 200 response whose body - contains the stored value from the automatic beacon. Since the data is stored - using a hash of the data as the key, it expects an `expected_body` query - parameter to know what key to look up. If the stored value doesn't exist, - serves a 200 response with an empty body. -""" -import uuid -import hashlib - -NO_DATA_STRING = b"<No data>" -NOT_SET_STRING = b"<Not set>" - -# The server stash requires a uuid to store data. Use a hash of the automatic -# beacon data as the uuid to store and retrieve the data. -def string_to_uuid(input): - hash_value = hashlib.md5(str(input).encode("UTF-8")).hexdigest() - return str(uuid.UUID(hex=hash_value)) - -def main(request, response): - stash = request.server.stash; - event_type = request.GET.first(b"type", NO_DATA_STRING) - - # The stash is accessed concurrently by many clients. A lock is used to - # avoid interleaved read/write from different clients. - with stash.lock: - # Requests with a body imply they were sent as an automatic beacon. Note - # that this only stores the most recent beacon that was sent. - if request.method == "POST": - request_body = request.body or NO_DATA_STRING - request_headers = request.headers.get("Origin") or NO_DATA_STRING - stash.put(string_to_uuid(event_type + request_body), - request_headers) - return (200, [], b"") - - # Requests without a body imply they were sent as the request from - # nextAutomaticBeacon(). - expected_body = request.GET.first(b"expected_body", NO_DATA_STRING) - data = stash.take(string_to_uuid(event_type + expected_body)) or NOT_SET_STRING - return(200, [], data) diff --git a/testing/web-platform/tests/fenced-frame/resources/automatic-beacon-unfenced-page.html b/testing/web-platform/tests/fenced-frame/resources/automatic-beacon-unfenced-page.html index 4ce7e0d78a..7f17c1a904 100644 --- a/testing/web-platform/tests/fenced-frame/resources/automatic-beacon-unfenced-page.html +++ b/testing/web-platform/tests/fenced-frame/resources/automatic-beacon-unfenced-page.html @@ -13,7 +13,7 @@ // '../automatic-beacon-unfenced-top.https.html'. An automatic beacon will // have been sent as a result of the navigation. const beacon_data = "This is the beacon data!"; - const beacon_initiator_origin = await nextAutomaticBeacon( + const beacon_initiator_origin = await nextBeacon( "reserved.top_navigation_commit", beacon_data); assert_equals(beacon_initiator_origin, get_host_info().HTTPS_ORIGIN); }); diff --git a/testing/web-platform/tests/fenced-frame/resources/beacon-store.py b/testing/web-platform/tests/fenced-frame/resources/beacon-store.py new file mode 100644 index 0000000000..4c89687f4a --- /dev/null +++ b/testing/web-platform/tests/fenced-frame/resources/beacon-store.py @@ -0,0 +1,56 @@ +""" +Event beacon store server. + +- When a request body is specified, stores the data in the body for the 'type' + specified in the query parameters and serves a 200 response without body. +- When a request body is not specified and the request is not served with an + 'expected_body' parameter, stores an empty body for the 'type' specified in + the query parameters and serves a 200 response without body. +- When a request body is not specified and the request is served with an + 'expected_body' parameter, serves a 200 response whose body contains the + stored value from the automatic beacon. Since the data is stored using a hash + of the data as the key, it uses the `expected_body` query parameter to know + what key to look up. If the stored value doesn't exist, serves a 200 response + with an empty body. +""" +import uuid +import hashlib + +NO_DATA_STRING = b"<No data>" +NOT_SET_STRING = b"<Not set>" + +# The server stash requires a uuid to store data. Use a hash of the automatic +# beacon data as the uuid to store and retrieve the data. +def string_to_uuid(input): + hash_value = hashlib.md5(str(input).encode("UTF-8")).hexdigest() + return str(uuid.UUID(hex=hash_value)) + +def main(request, response): + stash = request.server.stash; + event_type = request.GET.first(b"type", NO_DATA_STRING) + + # The stash is accessed concurrently by many clients. A lock is used to + # avoid interleaved read/write from different clients. + with stash.lock: + # GET requests with an 'expected_body' parameter imply they were sent as + # the request from nextBeacon(). + if request.method == "GET" and b"expected_body" in request.GET: + expected_body = request.GET.first(b"expected_body", NO_DATA_STRING) + data = stash.take(string_to_uuid(event_type + expected_body)) or NOT_SET_STRING + return (200, [], data) + + # Requests with a body imply they were sent as a reporting beacon + # (either through reportEvent() or through an automatic beacon). + if request.method == "POST" and event_type: + request_body = request.body or NO_DATA_STRING + request_headers = request.headers.get("Origin") or NO_DATA_STRING + stash.put(string_to_uuid(event_type + request_body), + request_headers) + return (200, [], b"") + # GET requests without an 'expected_body' parameter imply they were sent + # as a destination URL reporting beacon. + if request.method == "GET" and event_type: + stash.put(string_to_uuid(event_type + NO_DATA_STRING), NO_DATA_STRING) + return (200, [], b"") + + return (400, [], u"") diff --git a/testing/web-platform/tests/fenced-frame/resources/fledge-bidding-logic.py b/testing/web-platform/tests/fenced-frame/resources/fledge-bidding-logic.py index c91b31fd02..9acab47203 100644 --- a/testing/web-platform/tests/fenced-frame/resources/fledge-bidding-logic.py +++ b/testing/web-platform/tests/fenced-frame/resources/fledge-bidding-logic.py @@ -17,7 +17,7 @@ def main(request, response): # Parse URL params. requested_size = request.GET.first(b"requested-size", None) ad_with_size = request.GET.first(b"ad-with-size", None) - automatic_beacon = request.GET.first(b"automatic-beacon", None) + beacon = request.GET.first(b"beacon", None) # Use URL params to modify Javascript. requested_size_check = '' @@ -53,15 +53,18 @@ def main(request, response): ) register_ad_beacon = '' - if automatic_beacon is not None: + if beacon is not None: register_ad_beacon = ( '''registerAdBeacon({ 'reserved.top_navigation_start': browserSignals.interestGroupOwner + - '/fenced-frame/resources/automatic-beacon-store.py?type=reserved.top_navigation_start', + '/fenced-frame/resources/beacon-store.py?type=reserved.top_navigation_start', 'reserved.top_navigation_commit': browserSignals.interestGroupOwner + - '/fenced-frame/resources/automatic-beacon-store.py?type=reserved.top_navigation_commit', + '/fenced-frame/resources/beacon-store.py?type=reserved.top_navigation_commit', + 'click': + browserSignals.interestGroupOwner + + '/fenced-frame/resources/beacon-store.py?type=click', }); ''' ) diff --git a/testing/web-platform/tests/fenced-frame/resources/shared-worker.js b/testing/web-platform/tests/fenced-frame/resources/shared-worker.js new file mode 100644 index 0000000000..ac59fe6498 --- /dev/null +++ b/testing/web-platform/tests/fenced-frame/resources/shared-worker.js @@ -0,0 +1,14 @@ +// This is loaded as a SharedWorker in a WPT. When postMessaged to, forwards +// that message to all registered ports through a postMessage call. +const ports = []; + +onconnect = function (event) { + const port = event.ports[0]; + ports.push(port); + + port.onmessage = async function(e) { + ports.forEach(curPort => { + curPort.postMessage(e.data); + }); + } +} diff --git a/testing/web-platform/tests/fenced-frame/resources/unreached.https.html b/testing/web-platform/tests/fenced-frame/resources/unreached.https.html deleted file mode 100644 index bd389ec4fb..0000000000 --- a/testing/web-platform/tests/fenced-frame/resources/unreached.https.html +++ /dev/null @@ -1,15 +0,0 @@ -<!DOCTYPE html> -<title>File used to assert that navigations do not succeed.</title> - -<script src="/resources/testharness.js"></script> -<script src="/resources/testharnessreport.js"></script> -<script src="utils.js"></script> -<script src="/common/get-host-info.sub.js"></script> - -<body> -<script> - promise_test(async(t) => { - assert_unreached('This navigation should not have succeeded.'); - }); -</script> -</body> 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 |