Skip to content

Commit

Permalink
Reland "Reland "Service worker web platform tests."" (#46145)
Browse files Browse the repository at this point in the history
This reverts commit 93a580699ecf6d102a5853455b5faeceea4cd31e.

Reason for revert: Removed the test case that times out,
(the one that waits for the update url).

Original change's description:
> Revert "Reland "Service worker web platform tests.""
>
> This reverts commit 436f1b9f6153002fd41599d5d4ec8343cf930a43.
>
> Reason for revert: There are still timeouts in some tests
>
> Original change's description:
> > Reland "Service worker web platform tests."
> >
> > This reverts commit 36a1c457dac0ecaa54c0553b28f67c0c61752494.
> >
> > Reason for revert: The test that looks for 'update-url.py' takes too long and therefore will require this test file to be part of slowTests
> >
> > Original change's description:
> > > Revert "Service worker web platform tests."
> > >
> > > This reverts commit 63858f1b1ed058d07e73cebb0a98214aa2cfc715.
> > >
> > > Reason for revert: New test added; fails immediately on some bots.
> > >
> > > See
> > > https://ci.chromium.org/ui/p/chromium/builders/ci/mac11-arm64-rel-tests/38089/overview
> > > for the first failures. (And consistently in subsequent builds)
> > >
> > > Original change's description:
> > > > Service worker web platform tests.
> > > >
> > > > This tests that when an auction is ran, service workers do not intercept requests with URLs that are meant to be private.
> > > >
> > > >
> > > > Bug: 293383734
> > > > Change-Id: I06858f7cae4794a35c045fb8dad30d6316a26ead
> > > > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5459094
> > > > Commit-Queue: Youssef Bourouphael <ybourouphael@google.com>
> > > > Reviewed-by: mmenke <mmenke@chromium.org>
> > > > Reviewed-by: Orr Bernstein <orrb@google.com>
> > > > Cr-Commit-Position: refs/heads/main@{#1294960}
> > >
> > > Bug: 293383734
> > > Change-Id: I3431f0e45e65767ff1529002d8a2d14657d0cb5a
> > > No-Presubmit: true
> > > No-Tree-Checks: true
> > > No-Try: true
> > > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5506634
> > > Auto-Submit: Ian Clelland <iclelland@chromium.org>
> > > Owners-Override: Ian Clelland <iclelland@chromium.org>
> > > Commit-Queue: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
> > > Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
> > > Cr-Commit-Position: refs/heads/main@{#1295015}
> >
> > Bug: 293383734
> > Change-Id: I762dd50282f99617796df64d73a27d149cac0a86
> > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5512083
> > Commit-Queue: Youssef Bourouphael <ybourouphael@google.com>
> > Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
> > Reviewed-by: Orr Bernstein <orrb@google.com>
> > Reviewed-by: mmenke <mmenke@chromium.org>
> > Cr-Commit-Position: refs/heads/main@{#1296948}
>
> Bug: 293383734
> Change-Id: I9b06c0453656aaa448d0030960a48fc264bcf867
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5515623
> Auto-Submit: Youssef Bourouphael <ybourouphael@google.com>
> Commit-Queue: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
> Commit-Queue: mmenke <mmenke@chromium.org>
> Reviewed-by: mmenke <mmenke@chromium.org>
> Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
> Cr-Commit-Position: refs/heads/main@{#1297048}

Bug: 293383734
Change-Id: I7ae169c2750432bb1cb9c1c340585dc27d8cd419
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5521778
Commit-Queue: Youssef Bourouphael <ybourouphael@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Reviewed-by: mmenke <mmenke@chromium.org>
Reviewed-by: Orr Bernstein <orrb@google.com>
Cr-Commit-Position: refs/heads/main@{#1298807}

Co-authored-by: Youssef Bourouphael <ybourouphael@google.com>
  • Loading branch information
chromium-wpt-export-bot and HabibiYou committed May 10, 2024
1 parent 2478ccc commit bbfa8b9
Show file tree
Hide file tree
Showing 3 changed files with 175 additions and 0 deletions.
3 changes: 3 additions & 0 deletions fledge/tentative/TODO
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,6 @@ If possible:
but maybe a test where batching could be used, and make sure things work,
whether batching is used or not?
* reporting timeout being 0.
* Test that service workers cannot see update urls.
* This was attempted in [here](https://chromium-review.googlesource.com/c/chromium/src/+/5512083),
but needed to be reverted because it kept timing out, [see here](https://g-issues.chromium.org/issues/339048485)
49 changes: 49 additions & 0 deletions fledge/tentative/service-worker-helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"use strict;"

const privateRequests = ['resources/trusted-bidding-signals.py',
'update-url.py', // This requires another test, since it takes a while,
// see TODO file for more info.
'wasm-helper.py',
'bidding-logic.py',
'decision-logic.py',
'trusted-scoring-signals.py',
'trusted-bidding-signals.py',
'bidder_report',
'seller_report'];
const publicRequests = ['direct-from-seller-signals.py'];

// The service worker intercepts fetch calls and uses
// pre-defined lists to categorize requests as "public"
// or "private". It broadcasts a success/failure status
// on the appropriate BroadcastChannel.
self.addEventListener('fetch', (event) => {
const privateRequestChannel = new BroadcastChannel('private-requests-test');
const publicRequestChannel = new BroadcastChannel('public-requests-test');

privateRequests.forEach(privateRequest => {
if (event.request.url.includes(privateRequest)) {
privateRequestChannel.postMessage({
result: 'failed',
message: "service worker should not have seen: " +
privateRequest
});
}
});

publicRequests.forEach(publicRequest => {
if (event.request.url.includes(publicRequest)) {
publicRequestChannel.postMessage({
result: 'passed',
message: "service worker properly saw: " +
publicRequest
});
}
});

// This endpoint is specifically for the 'private-requests-test' to signal
// completion and ensure proper BroadcastChannel response behavior.
if (event.request.url.includes('COMPLETE-TEST')) {
privateRequestChannel.postMessage({result:'completed'});
}
});

123 changes: 123 additions & 0 deletions fledge/tentative/service-worker-request-visibility.https.window.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
// META: script=/resources/testdriver.js
// META: script=/common/utils.js
// META: script=resources/fledge-util.sub.js
// META: script=/common/subset-tests.js
// META: timeout=long
// META: variant=?1-last

"use strict;"

const SERVICE_WORKER_SCRIPT = "service-worker-helper.js";

async function setUpServiceWorkerAndGetBroadcastChannel(broadcastChannelName) {
await registerServiceWorker();
await checkServiceWorkersAndReload();
return new BroadcastChannel(broadcastChannelName);
}

// In order to validate a service worker, its scriptURL should
// be the one we registered in registerServiceWorker().
function validateServiceWorker() {
if (navigator.serviceWorker.controller) {
return navigator.serviceWorker.controller.scriptURL.includes(SERVICE_WORKER_SCRIPT);
}
return false;
}

// Prepares the test environment by ensuring a valid service worker
// registration. Reloads the page if no service worker is found or
// if it's not registered correctly.
async function checkServiceWorkersAndReload() {
let count = (await navigator.serviceWorker.getRegistrations()).length;
if (count === 0 || !validateServiceWorker()) {
window.location.reload();
}
}

// Registers a service worker to the current scope.
async function registerServiceWorker() {
try {
await navigator.serviceWorker.register(`./${SERVICE_WORKER_SCRIPT}`);
await navigator.serviceWorker.ready;
} catch (error) {
throw (Error, "Error while registering service worker: " + error);
}
}

// Tests that public requests are seen by the service worker.
// Specifically anything that contains:
// - 'direct-from-seller-signals.py'

// This test works by having the service worker send a message over
// the broadcastChannel, if it sees a request that contains any of
// the following strings above, it will send a 'passed' result and
// also change the variable 'finish_test', to true, so that guarantees
// that the request was seen before we complete the test.
subsetTest(promise_test, async test => {
const broadcastChannel = await setUpServiceWorkerAndGetBroadcastChannel('public-requests-test');

let finishTest = new Promise((resolve, reject) => {
broadcastChannel.addEventListener('message', (event) => {
if (event.data.result === 'passed') {
resolve();
} else {
reject(`unexpected result: ${event.data.message}`);
}
});
});

await fetchDirectFromSellerSignals({ 'Buyer-Origin': window.location.origin });
await finishTest;
}, "Make sure service workers do see public requests.");

// Tests that private requests are not seen by the service worker.
// Specifically anything that contains:
// - 'resources/trusted-bidding-signals.py'
// - 'resources/trusted-scoring-signals.py'
// - 'wasm-helper.py'
// - 'bidding-logic.py'
// - 'decision-logic.py'
// - 'seller_report'
// - 'bidder_report'

// This test works by having the service worker send a message
// over the broadcastChannel, if it sees a request that contains
// any of the following strings above, it will send a 'failed'
// result which will cause assert_false case to fail.
subsetTest(promise_test, async test => {
const uuid = generateUuid(test);
const broadcastChannel = await setUpServiceWorkerAndGetBroadcastChannel('private-requests-test');

let finishTest = new Promise((resolve, reject) => {
broadcastChannel.addEventListener('message', (event) => {
if (event.data.result === 'completed') {
resolve();
} else {
reject(`unexpected result: ${event.data.message}`);
}
});
});
broadcastChannel.addEventListener('message', (event) => {
assert_false(event.data.result === 'failed',
/*errorMessage=*/event.data.message);
});
let interestGroupOverrides = {
biddingWasmHelperURL: `${RESOURCE_PATH}wasm-helper.py`,
trustedBiddingSignalsURL: TRUSTED_BIDDING_SIGNALS_URL,
trustedScoringSignalsURL: TRUSTED_SCORING_SIGNALS_URL,
};

await joinInterestGroup(test, uuid, interestGroupOverrides);
await runBasicFledgeAuctionAndNavigate(test, uuid);
// By verifying that these requests are observed we can assume
// none of the other requests were seen by the service-worker.
await waitForObservedRequests(
uuid,
[createBidderReportURL(uuid), createSellerReportURL(uuid)]);

// Service worker will post a 'completed' result when it sees a fetch request with
// 'COMPLETE-TEST' within the URL. This let's us ensure that the service worker's
// 'postMessage' has nothing pending.
await fetch('COMPLETE-TEST');
await finishTest;
}, "Make sure service workers do not see private requests");

0 comments on commit bbfa8b9

Please sign in to comment.