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 e88ae41819
commit 4e1532195c
3 changed files with 27 additions and 16 deletions

View File

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

View File

@@ -228,7 +228,24 @@ if (params.timeoutAsPass) {
} }
if (params.conditionedProfile) { 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) { if (params.comparePrefs) {

View File

@@ -475,10 +475,10 @@ export class SpecialPowersChild extends JSWindowActorChild {
return this.sendQuery("Ping").then(aCallback); return this.sendQuery("Ping").then(aCallback);
} }
async registeredServiceWorkers() { async registeredServiceWorkers(aForceCheck) {
// Please see the comment in SpecialPowersParent.sys.mjs above // Please see the comment in SpecialPowersParent.sys.mjs above
// this._serviceWorkerListener's assignment for what this returns. // 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 // 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 // call to the parent to make sure that it called unregister on all of its
// service workers. // service workers.