From 36e52e9c6c0ddcd9392c06c0a45062939a4a9ee5 Mon Sep 17 00:00:00 2001 From: Matt Menke Date: Fri, 21 Jul 2023 09:27:42 +0000 Subject: [PATCH] Bug 1843584 [wpt PR 41045] - [FLEDGE] Add some WPTs for expiration logic, a=testonly Automatic update from web-platform-tests [FLEDGE] Add some WPTs for expiration logic Bug: 1425952 Change-Id: I70152759a1e2e6bd7ee4ab9cfe5a6b3ea960c169 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4685086 Reviewed-by: Caleb Raitto Commit-Queue: Matt Menke Cr-Commit-Position: refs/heads/main@{#1171247} -- wpt-commits: 88c11559d0ae1178b9954f90584d011c3df88671 wpt-pr: 41045 --- testing/web-platform/tests/fledge/tentative/TODO | 3 +- ...oin-leave-ad-interest-group.https.sub.window.js | 57 ++++++++++++++++++++++ .../fledge/tentative/resources/fledge-util.js | 8 ++- 3 files changed, 62 insertions(+), 6 deletions(-) diff --git a/testing/web-platform/tests/fledge/tentative/TODO b/testing/web-platform/tests/fledge/tentative/TODO index d50e49261164..96654d2c592e 100644 --- a/testing/web-platform/tests/fledge/tentative/TODO +++ b/testing/web-platform/tests/fledge/tentative/TODO @@ -9,7 +9,8 @@ Need tests for (likely not a complete list): * Updates (both after auction and triggered). * All auctionConfig parameters (including invalid auctionConfigs, and ones with no buyers). -* Interest group expiration. +* Joining interest group with duration of 0 should just leave the IG (not + currently guaranteed to work, due to potential time skew between processes). * Multiple buyers. * Multiple interest group with same owner. * Multiple origin auctions (buyer != publisher != seller). diff --git a/testing/web-platform/tests/fledge/tentative/join-leave-ad-interest-group.https.sub.window.js b/testing/web-platform/tests/fledge/tentative/join-leave-ad-interest-group.https.sub.window.js index 973c586ca4f1..d1d6d50e4b0b 100644 --- a/testing/web-platform/tests/fledge/tentative/join-leave-ad-interest-group.https.sub.window.js +++ b/testing/web-platform/tests/fledge/tentative/join-leave-ad-interest-group.https.sub.window.js @@ -1,6 +1,7 @@ // META: script=/resources/testdriver.js // META: script=/common/utils.js // META: script=resources/fledge-util.js +// META: timeout=long "use strict;" @@ -568,3 +569,59 @@ promise_test(async test => { // This should not throw. await leaveInterestGroup({ name: 'Never join group' }); }, 'Leave an interest group that was never joined.'); + +/////////////////////////////////////////////////////////////////////////////// +// Expiration tests +/////////////////////////////////////////////////////////////////////////////// + +promise_test(async test => { + const uuid = generateUuid(test); + + // Joins the default interest group, with a 0.2 second duration. + await joinInterestGroup(test, uuid, {}, 0.2); + + // Keep on running auctions until interest group duration expires. + // Unfortunately, there's no duration that's guaranteed to be long enough to + // be be able to win an auction once, but short enough to prevent this test + // from running too long, so can't check the interest group won at least one + // auction. + while (await runBasicFledgeAuction(test, uuid) !== null); +}, 'Interest group duration.'); + +promise_test(async test => { + const uuid = generateUuid(test); + + // Join interest group with a duration of -600. The interest group should + // immediately expire, and not be allowed to participate in auctions. + await joinInterestGroup(test, uuid, {}, -600); + assert_true(await runBasicFledgeAuction(test, uuid) === null); +}, 'Interest group duration of -600.'); + +promise_test(async test => { + const uuid = generateUuid(test); + + // Join a long-lived interest group. + await joinInterestGroup(test, uuid, {}, 600); + + // Make sure interest group with a non-default timeout was joined. + assert_true(await runBasicFledgeAuction(test, uuid) !== null); + + // Re-join interest group with a duration value of 0.2 seconds. + await joinInterestGroup(test, uuid, {}, 0.2); + + // Keep on running auctions until interest group expires. + while (await runBasicFledgeAuction(test, uuid) !== null); +}, 'Interest group test with overwritten duration.'); + +promise_test(async test => { + const uuid = generateUuid(test); + + // Join a long-lived interest group. + await joinInterestGroup(test, uuid, {}, 600); + + // Re-join interest group with a duration value of 0.2 seconds. The new + // duration should take precedence, and the interest group should immediately + // expire. + await joinInterestGroup(test, uuid, {}, -600); + assert_true(await runBasicFledgeAuction(test, uuid) === null); +}, 'Interest group test with overwritten duration of -600.'); diff --git a/testing/web-platform/tests/fledge/tentative/resources/fledge-util.js b/testing/web-platform/tests/fledge/tentative/resources/fledge-util.js index 5a05764e74e9..36fb05615a77 100644 --- a/testing/web-platform/tests/fledge/tentative/resources/fledge-util.js +++ b/testing/web-platform/tests/fledge/tentative/resources/fledge-util.js @@ -171,9 +171,8 @@ function createRenderUrl(uuid, script) { // // `interestGroupOverrides` may be used to override fields in the joined // interest group. -async function joinInterestGroup(test, uuid, interestGroupOverrides = {}) { - const INTEREST_GROUP_LIFETIME_SECS = 60; - +async function joinInterestGroup(test, uuid, interestGroupOverrides = {}, + durationSeconds = 60) { let interestGroup = { owner: window.location.origin, name: DEFAULT_INTEREST_GROUP_NAME, @@ -183,8 +182,7 @@ async function joinInterestGroup(test, uuid, interestGroupOverrides = {}) { ...interestGroupOverrides }; - await navigator.joinAdInterestGroup(interestGroup, - INTEREST_GROUP_LIFETIME_SECS); + await navigator.joinAdInterestGroup(interestGroup, durationSeconds); test.add_cleanup( async () => {await navigator.leaveAdInterestGroup(interestGroup)}); } -- 2.11.4.GIT