Bug 1926132 - condprof should check registered SWs at start of test. r=jmaher

Differential Revision: https://phabricator.services.mozilla.com/D226589
This commit is contained in:
Andrew Sutherland 2024-10-23 16:06:22 +00:00
parent 2ff5841fcc
commit 55576b9325
3 changed files with 27 additions and 16 deletions

View File

@ -1494,16 +1494,14 @@ SimpleTest.finish = function () {
);
}
} else if (workers.length) {
let FULL_PROFILE_WORKERS_TO_IGNORE = [];
let FULL_PROFILE_WORKERS_TO_IGNORE = new Set();
if (parentRunner.conditionedProfile) {
// Full profile has service workers in the profile, without clearing the
// profile service workers will be leftover. We perform a startsWith
// check below because some origins (s.0cf.io) use a cache-busting query
// parameter.
FULL_PROFILE_WORKERS_TO_IGNORE = [
"https://www.youtube.com/sw.js",
"https://s.0cf.io/sw.js",
];
// profile service workers will be leftover.
for (const knownWorker of parentRunner.conditionedProfile
.knownServiceWorkers) {
FULL_PROFILE_WORKERS_TO_IGNORE.add(knownWorker.scriptSpec);
}
} else {
SimpleTest.ok(
false,
@ -1512,11 +1510,7 @@ SimpleTest.finish = function () {
}
for (let worker of workers) {
if (
FULL_PROFILE_WORKERS_TO_IGNORE.some(ignoreBase =>
worker.scriptSpec.startsWith(ignoreBase)
)
) {
if (FULL_PROFILE_WORKERS_TO_IGNORE.has(worker.scriptSpec)) {
continue;
}
SimpleTest.ok(

View File

@ -228,7 +228,24 @@ if (params.timeoutAsPass) {
}
if (params.conditionedProfile) {
TestRunner.conditionedProfile = true;
TestRunner.conditionedProfile = {
knownServiceWorkers: null,
};
// Asynchronously populate knownServiceWorkers above. Because we only check
// this list after awaiting a different call to registeredServiceWorkers() in
// SimpleTest.js's afterCleanup, we are guaranteed that the list will be
// populated before we check it.
//
// That said, the question is whether the list was sampled before the test
// could start and add a ServiceWorker. And the answer is mainly yes because
// the request will make it to the parent process main thread before any call
// to register() can get there with very high probability. (We are dealing
// with different top-level protocols so there are some theoretical
// opportunities for pathological scheduling but practically speaking it is
// very unlikely to happen.)
SpecialPowers.registeredServiceWorkers(/* aForce */ true).then(workers => {
TestRunner.conditionedProfile.knownServiceWorkers = workers;
});
}
if (params.comparePrefs) {

View File

@ -475,10 +475,10 @@ export class SpecialPowersChild extends JSWindowActorChild {
return this.sendQuery("Ping").then(aCallback);
}
async registeredServiceWorkers() {
async registeredServiceWorkers(aForceCheck) {
// Please see the comment in SpecialPowersParent.sys.mjs above
// this._serviceWorkerListener's assignment for what this returns.
if (this._serviceWorkerRegistered) {
if (this._serviceWorkerRegistered || aForceCheck) {
// This test registered at least one service worker. Send a synchronous
// call to the parent to make sure that it called unregister on all of its
// service workers.