Skip to content

Commit

Permalink
Fix wpt flaky tests
Browse files Browse the repository at this point in the history
Add missing await and change has() to hasOwnProperty().

Change-Id: Ifba707f18b4e8082af2ffb8809d4d959a14f1ca5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5980292
Reviewed-by: Kentaro Hara <[email protected]>
Commit-Queue: Tianyang Xu <[email protected]>
Reviewed-by: mmenke <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1378513}
  • Loading branch information
Tianyang Xu authored and chromium-wpt-export-bot committed Nov 5, 2024
1 parent 813d3cf commit d017b5e
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 49 deletions.
33 changes: 17 additions & 16 deletions fledge/tentative/trusted-bidding-signals.https.window.js
Original file line number Diff line number Diff line change
Expand Up @@ -820,19 +820,20 @@ subsetTest(promise_test, async test => {
/////////////////////////////////////////////////////////////////////////////
// maxTrustedBiddingSignalsURLLength tests
/////////////////////////////////////////////////////////////////////////////
// To detect whether two signals are fetched together or separately, the trusted bidding signals
// Python server will return the request URL as the signal value if the request URL contains the
// string url in its query parameters.

// Trusted bidding signals can be retrieved when `maxTrustedBiddingSignalsURLLength` is set to 0,
// which means infinite length limit.
// In the following three tests, the generated request URL contains approximately 166 characters.
// The target of the tests is primarily to make sure all the signals are fetched with the full URL.
subsetTest(promise_test, async test => {
const name = 'group';
const expect_queries = 'keys=interest-group-names,url&interestGroupNames=group';
await runTrustedBiddingSignalsTest(
test,
// Check the URL length is within an approximate range to ensure the URL is not truncated.
// Check returned signal contains expected queries to ensure the URL is not truncated.
` trustedBiddingSignals["interest-group-names"] === '["${name}"]' &&
trustedBiddingSignals["url"].length > 150 &&
trustedBiddingSignals["url"].length < 180 `,
trustedBiddingSignals["url"].includes("${expect_queries}") `,
{
name: name,
trustedBiddingSignalsKeys: ['interest-group-names', 'url'],
Expand All @@ -847,11 +848,12 @@ subsetTest(promise_test, async test => {
// larger than the limit.
subsetTest(promise_test, async test => {
const name = 'group';
const expect_queries = 'keys=interest-group-names,url&interestGroupNames=group';
await runTrustedBiddingSignalsTest(
test,
// Check returned signal contains expected queries to ensure the URL is not truncated.
` trustedBiddingSignals["interest-group-names"] === '["${name}"]' &&
trustedBiddingSignals["url"].length > 150 &&
trustedBiddingSignals["url"].length < 180 `,
trustedBiddingSignals["url"].includes("${expect_queries}") `,
{
name: name,
trustedBiddingSignalsKeys: ['interest-group-names', 'url'],
Expand All @@ -864,10 +866,12 @@ subsetTest(promise_test, async test => {
// a value larger than the length of the request URL.
subsetTest(promise_test, async test => {
const name = 'group';
const expect_queries = 'keys=interest-group-names,url&interestGroupNames=group';
await runTrustedBiddingSignalsTest(
test,
// Check returned signal contains expected queries to ensure the URL is not truncated.
` trustedBiddingSignals["interest-group-names"] === '["${name}"]' &&
trustedBiddingSignals["url"].length < 180 `,
trustedBiddingSignals["url"].includes("${expect_queries}") `,
{
name: name,
trustedBiddingSignalsKeys: ['interest-group-names', 'url'],
Expand All @@ -880,10 +884,7 @@ subsetTest(promise_test, async test => {
// groups, will be split into two parts when `maxTrustedBiddingSignalsURLLength` is set to a
// value larger than a single URL length and smaller than the combined URL length. A request
// URL from a single interest group contains about 188 characters, while a request URL from
// two interest groups contains about 216 characters. Note that this test can only verifies
// the fetch status of the winner's trusted bidding signal, which is the second interest
// group. We consider the request to be split if the URL length check passes for the second
// interest group.
// two interest groups contains about 216 characters.
subsetTest(promise_test, async test => {
const uuid = generateUuid(test);
const name1 = 'extraordinarilyLongNameGroup1';
Expand Down Expand Up @@ -917,14 +918,14 @@ subsetTest(promise_test, async test => {
{
generateBid:
`if (trustedBiddingSignals["interest-group-names"] !== '["${name2}"]' ||
trustedBiddingSignals["url"].length > 200) {
trustedBiddingSignals["url"].includes("${name1}")) {
throw "unexpected trustedBiddingSignals";
}
return { bid: 10, render: interestGroup.ads[0].renderURL };`})
})
]
);
runBasicFledgeTestExpectingWinner(test, uuid);
await runBasicFledgeTestExpectingWinner(test, uuid);
}, 'Trusted bidding signals splits the request if the combined URL length exceeds the limit of regular value.');

// Test whether an oversized trusted bidding signals request URL, generated from two interest
Expand Down Expand Up @@ -960,14 +961,14 @@ subsetTest(promise_test, async test => {
{
generateBid:
`if (trustedBiddingSignals["interest-group-names"] !== '["${name2}"]' ||
trustedBiddingSignals["url"].length > 200) {
trustedBiddingSignals["url"].includes("${name1}")) {
throw "unexpected trustedBiddingSignals";
}
return { bid: 10, render: interestGroup.ads[0].renderURL };`})
})
]
);
runBasicFledgeTestExpectingWinner(test, uuid);
await runBasicFledgeTestExpectingWinner(test, uuid);
}, 'Trusted bidding signals splits the request if the combined URL length exceeds the limit of small value.');

/////////////////////////////////////////////////////////////////////////////
Expand Down
73 changes: 40 additions & 33 deletions fledge/tentative/trusted-scoring-signals.https.window.js
Original file line number Diff line number Diff line change
Expand Up @@ -635,23 +635,24 @@ subsetTest(promise_test, async test => {
/////////////////////////////////////////////////////////////////////////////
// maxTrustedBiddingSignalsURLLength tests
/////////////////////////////////////////////////////////////////////////////
// To detect whether two signals are fetched together or separately, the trusted scoring signals
// Python server will return the request URL as the signal value if the request URL contains the
// string `url` in its query parameters.

// Trusted scoring signals can be retrieved when `maxTrustedScoringSignalsURLLength` is set to 0.
// In the following three tests, the generated request URL contains approximately 294 characters.
// The target of the tests is primarily to make sure the signals were fetched with the full URL.
// Check if the returned signal contains value of `renderURL` to make sure the signal is fetched
// with the full URL.
subsetTest(promise_test, async test => {
const uuid = generateUuid(test);
const renderURL = createRenderURL(uuid, /*script=*/null, 'url');
const renderURL = createRenderURL(uuid, /*script=*/null, /*signalsParam=*/'url');
const interestGroupOverrides = { ads: [{ renderURL: renderURL }] };
const auctionConfigOverrides = {
trustedScoringSignalsURL: TRUSTED_SCORING_SIGNALS_URL,
maxTrustedScoringSignalsURLLength: 0,
decisionLogicURL:
createDecisionScriptURL(uuid, {
// Check the URL length is within an approximate range to ensure the URL is not truncated.
scoreAd:
`if (trustedScoringSignals.renderURL["${renderURL}"].length < 280 ||
trustedScoringSignals.renderURL["${renderURL}"].length > 300)
`if (!trustedScoringSignals.renderURL["${renderURL}"].includes(encodeURIComponent("${renderURL}")))
throw "error";`
})
};
Expand All @@ -666,20 +667,19 @@ subsetTest(promise_test, async test => {
}, 'Trusted scoring signals request works with a URL length limit set to 0.');

// Trusted scoring signals can be retrieved when `maxTrustedScoringSignalsURLLength` is set to
// a non-zero value smaller than the length of the request URL.
// a non-zero value smaller than the length of the request URL. Check if the returned signal
// contains value of `renderURL` to make sure the signal was fetched with the full URL.
subsetTest(promise_test, async test => {
const uuid = generateUuid(test);
const renderURL = createRenderURL(uuid, /*script=*/null, 'url');
const renderURL = createRenderURL(uuid, /*script=*/null, /*signalsParam=*/'url');
const interestGroupOverrides = { ads: [{ renderURL: renderURL }] };
const auctionConfigOverrides = {
trustedScoringSignalsURL: TRUSTED_SCORING_SIGNALS_URL,
maxTrustedScoringSignalsURLLength: 1,
decisionLogicURL:
createDecisionScriptURL(uuid, {
// Check the URL length is within an approximate range to ensure the URL is not truncated.
scoreAd:
`if (trustedScoringSignals.renderURL["${renderURL}"].length < 280 ||
trustedScoringSignals.renderURL["${renderURL}"].length > 300)
`if (!trustedScoringSignals.renderURL["${renderURL}"].includes(encodeURIComponent("${renderURL}")))
throw "error";`
})
};
Expand All @@ -694,17 +694,20 @@ subsetTest(promise_test, async test => {
}, 'Trusted scoring signals request works with a URL length limit smaller than the URL length.');

// Trusted scoring signals can be retrieved when `maxTrustedScoringSignalsURLLength` is set to
// a value larger than the length of the request URL.
// a value larger than the length of the request URL. Check if the returned signal contains
// value of `renderURL` to make sure the signal was fetched with the full URL.
subsetTest(promise_test, async test => {
const uuid = generateUuid(test);
const renderURL = createRenderURL(uuid, /*script=*/null, 'url');
const renderURL = createRenderURL(uuid, /*script=*/null, /*signalsParam=*/'url');
const interestGroupOverrides = { ads: [{ renderURL: renderURL }] };
const auctionConfigOverrides = {
trustedScoringSignalsURL: TRUSTED_SCORING_SIGNALS_URL,
maxTrustedScoringSignalsURLLength: 1000,
decisionLogicURL:
createDecisionScriptURL(uuid, {
scoreAd: `if (trustedScoringSignals.renderURL["${renderURL}"].length > 300) throw "error";`
scoreAd:
`if (!trustedScoringSignals.renderURL["${renderURL}"].includes(encodeURIComponent("${renderURL}")))
throw "error";`
})
};

Expand All @@ -719,25 +722,25 @@ subsetTest(promise_test, async test => {

// Test whether an oversized trusted scoring signals request URL, generated from two interest
// groups, will be split into two parts when `maxTrustedScoringSignalsURLLength` is set to a
// value larger than a single URL length and smaller than the combined URL length. A request
// URL from a single interest group contains about 294 characters, while a request URL from
// two interest groups contains about 466 characters.
// value larger than a single URL length and smaller than the combined URL length. Check the returned
// signal for interest group `group 1` only contains string `group1` but not `group2` to ensure the
// fetch requests are not combined together.
subsetTest(promise_test, async test => {
const uuid = generateUuid(test);
const renderURL1 = createRenderURL(uuid, /*script=*/null, 'url,group1');
const renderURL2 = createRenderURL(uuid, /*script=*/null, 'url,group2');
const renderURL1 = createRenderURL(uuid, /*script=*/null, /*signalsParam=*/'url,group1');
const renderURL2 = createRenderURL(uuid, /*script=*/null, /*signalsParam=*/'url,group2');
const auctionConfigOverrides = {
trustedScoringSignalsURL: TRUSTED_SCORING_SIGNALS_URL,
maxTrustedScoringSignalsURLLength: 300,
decisionLogicURL:
createDecisionScriptURL(uuid, {
// This will make the auction reject `renderURL2`, and if `renderURL1` passes the URL
// length check, we consider `renderURL2` is fetched by itself in the trusted scoring
// signals request.
// This will make the auction reject `renderURL2`, and if `renderURL1` passes check,
// we consider `renderURL2` is fetched by itself in the trusted scoring signals request.
scoreAd:
`if (!trustedScoringSignals.renderURL.has("${renderURL1}") ||
trustedScoringSignals.renderURL.has("${renderURL2}") ||
trustedScoringSignals.renderURL["${renderURL1}"].length > 300) {
`if (!trustedScoringSignals.renderURL.hasOwnProperty("${renderURL1}") ||
trustedScoringSignals.renderURL.hasOwnProperty("${renderURL2}") ||
trustedScoringSignals.renderURL["${renderURL1}"].includes('group2') ||
!trustedScoringSignals.renderURL["${renderURL1}"].includes('group1')) {
throw "error";
}`
})
Expand All @@ -748,25 +751,29 @@ subsetTest(promise_test, async test => {
joinInterestGroup(test, uuid, { name: 'group 2', ads: [{ renderURL: renderURL2 }] }) ]
);

runBasicFledgeTestExpectingWinner(test, uuid, auctionConfigOverrides);
await runBasicFledgeTestExpectingWinner(test, uuid, auctionConfigOverrides);
}, 'Trusted scoring signals splits the request if the combined URL length exceeds the limit of regular value.');

// Test whether an oversized trusted scoring signals request URL, generated from two interest
// groups, will be split into two parts when `maxTrustedScoringSignalsURLLength` is set to a
// value smaller than a single URL length.
// value smaller than a single URL length. Check the returned signal for interest group `group 1`
// only contains `group1` but not `group2` to ensure the fetch requests are not combined together.
subsetTest(promise_test, async test => {
const uuid = generateUuid(test);
const renderURL1 = createRenderURL(uuid, /*script=*/null, 'url,group1');
const renderURL2 = createRenderURL(uuid, /*script=*/null, 'url,group2');
const renderURL1 = createRenderURL(uuid, /*script=*/null, /*signalsParam=*/'url,group1');
const renderURL2 = createRenderURL(uuid, /*script=*/null, /*signalsParam=*/'url,group2');
const auctionConfigOverrides = {
trustedScoringSignalsURL: TRUSTED_SCORING_SIGNALS_URL,
maxTrustedScoringSignalsURLLength: 1,
decisionLogicURL:
createDecisionScriptURL(uuid, {
// This will make the auction reject `renderURL2`, and if `renderURL1` passes check,
// we consider `renderURL2` is fetched by itself in the trusted scoring signals request.
scoreAd:
`if (!trustedScoringSignals.renderURL.has("${renderURL1}") ||
trustedScoringSignals.renderURL.has("${renderURL2}") ||
trustedScoringSignals.renderURL["${renderURL1}"].length > 300) {
`if (!trustedScoringSignals.renderURL.hasOwnProperty("${renderURL1}") ||
trustedScoringSignals.renderURL.hasOwnProperty("${renderURL2}") ||
trustedScoringSignals.renderURL["${renderURL1}"].includes('group2') ||
!trustedScoringSignals.renderURL["${renderURL1}"].includes('group1')) {
throw "error";
}`
})
Expand All @@ -777,5 +784,5 @@ subsetTest(promise_test, async test => {
joinInterestGroup(test, uuid, { name: 'group 2', ads: [{ renderURL: renderURL2 }] }) ]
);

runBasicFledgeTestExpectingWinner(test, uuid, auctionConfigOverrides);
await runBasicFledgeTestExpectingWinner(test, uuid, auctionConfigOverrides);
}, 'Trusted scoring signals splits the request if the combined URL length exceeds the limit of small value.');

0 comments on commit d017b5e

Please sign in to comment.