Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[service-workers] Use asynchronous cleanup #13164

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@

return service_worker_unregister_and_register(t, script, scope)
.then(function(r) {
t.add_cleanup(function() {
return service_worker_unregister(t, scope);
});

registration = r;

return wait_for_state(t, registration.installing, 'activated');
})
.then(function() {
Expand All @@ -28,7 +33,6 @@
})
.then(function(result) {
assert_equals(result, 'OK');
return service_worker_unregister_and_done(t, scope);
});
}, 'Post loopback messages');

Expand All @@ -41,6 +45,10 @@

return service_worker_unregister_and_register(t, script1, scope)
.then(function(r) {
t.add_cleanup(function() {
return service_worker_unregister(t, scope);
});

registration = r;
return wait_for_state(t, registration.installing, 'activated');
})
Expand Down Expand Up @@ -69,7 +77,6 @@
.then(function(result) {
assert_equals(result, 'OK');
frame.remove();
return service_worker_unregister_and_done(t, scope);
});
}, 'Post messages among service workers');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@

return service_worker_unregister_and_register(t, script, scope)
.then(function(registration) {
t.add_cleanup(function() {
return service_worker_unregister(t, scope);
});

return wait_for_state(t, registration.installing, 'redundant');
})
.then(function() {
Expand All @@ -21,7 +25,6 @@
result,
undefined,
'After unregister(), the registration should not found');
return service_worker_unregister_and_done(t, scope);
});
}, 'Unregister on script evaluation');

Expand All @@ -31,6 +34,10 @@

return service_worker_unregister_and_register(t, script, scope)
.then(function(registration) {
t.add_cleanup(function() {
return service_worker_unregister(t, scope);
});

return wait_for_state(t, registration.installing, 'redundant');
})
.then(function() {
Expand All @@ -41,7 +48,6 @@
result,
undefined,
'After unregister(), the registration should not found');
return service_worker_unregister_and_done(t, scope);
});
}, 'Unregister on installing event');

Expand All @@ -51,6 +57,10 @@

return service_worker_unregister_and_register(t, script, scope)
.then(function(registration) {
t.add_cleanup(function() {
return service_worker_unregister(t, scope);
});

return wait_for_state(t, registration.installing, 'redundant');
})
.then(function() {
Expand All @@ -61,7 +71,6 @@
result,
undefined,
'After unregister(), the registration should not found');
return service_worker_unregister_and_done(t, scope);
});
}, 'Unregister on activate event');

Expand All @@ -74,6 +83,10 @@

return service_worker_unregister_and_register(t, script, scope)
.then(function(registration) {
t.add_cleanup(function() {
return service_worker_unregister(t, scope);
});

return wait_for_state(t, registration.installing, 'activated');
})
.then(function() { return with_iframe(scope); })
Expand Down Expand Up @@ -120,7 +133,6 @@

frame.remove();
new_frame.remove();
return service_worker_unregister_and_done(t, scope);
})
}, 'Unregister controlling service worker');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@

return service_worker_unregister_and_register(t, script, scope)
.then(function(r) {
t.add_cleanup(function() {
return service_worker_unregister(t, scope);
});

registration = r;
return wait_for_state(t, registration.installing, 'activated');
})
Expand All @@ -38,7 +42,6 @@
'events seen by the worker');
frame1.remove();
frame2.remove();
return service_worker_unregister_and_done(t, scope);
});
}, 'Update a registration on ServiceWorkerGlobalScope');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@

async function doAsyncTest(t, scope) {
let reg = await service_worker_unregister_and_register(t, worker, scope);

t.add_cleanup(() => service_worker_unregister(t, scope));

await wait_for_state(t, reg.installing, 'activated');

// Load the scope as a frame. We expect this in turn to have a nested
Expand Down Expand Up @@ -96,7 +99,6 @@
}

frame.remove();
await service_worker_unregister_and_done(t, scope);
}

promise_test(async function(t) {
Expand Down Expand Up @@ -126,6 +128,9 @@
const scope = 'resources/about-blank-replacement-uncontrolled-nested-frame.html';

let reg = await service_worker_unregister_and_register(t, worker, scope);

t.add_cleanup(() => service_worker_unregister(t, scope));

await wait_for_state(t, reg.installing, 'activated');

// Load the scope as a frame. We expect this in turn to have a nested
Expand All @@ -147,7 +152,6 @@
'nested frame should not be controlled');

frame.remove();
await service_worker_unregister_and_done(t, scope);
}, 'Initial about:blank is controlled, exposed to clients.matchAll(), and ' +
'final Client is not controlled by a service worker.');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@

return service_worker_unregister_and_register(t, script, scope)
.then(function(registration) {
t.add_cleanup(function() {
return service_worker_unregister(t, scope);
});

var sw = registration.installing;

return new Promise(t.step_func(function(resolve) {
Expand All @@ -23,9 +27,6 @@
});
}));
})
.then(function() {
return service_worker_unregister_and_done(t, scope);
})
.catch(unreached_rejection(t));
}, 'installed event should be fired before activating service worker');

Expand Down
9 changes: 6 additions & 3 deletions service-workers/service-worker/claim-fetch.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@

// Register a service worker.
.then(() => service_worker_unregister_and_register(t, script, scope))
.then(r => worker = r.installing)
.then(() => wait_for_state(t, worker, 'activated'))
.then(r => {
t.add_cleanup(() => service_worker_unregister(t, scope));

worker = r.installing;

return wait_for_state(t, worker, 'activated');
})
// Let the service worker claim the iframe.
.then(() => {
var channel = new MessageChannel();
Expand Down Expand Up @@ -62,7 +66,6 @@

// Cleanup this testcase.
.then(() => frame.remove())
.then(() => service_worker_unregister_and_done(t, scope));
}, 'fetch() should be intercepted after the client is claimed.')

</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
return service_worker_unregister_and_register(
t, init_worker_url, init_scope)
.then(function(registration) {
t.add_cleanup(function() {
return service_worker_unregister(t, init_scope);
});

return wait_for_state(t, registration.installing, 'activated');
})
.then(function() {
Expand All @@ -35,6 +39,10 @@
{scope: claim_scope});
})
.then(function(registration) {
t.add_cleanup(function() {
return service_worker_unregister(t, claim_scope);
});

claim_worker = registration.installing;
claim_registration = registration;
return wait_for_state(t, registration.installing, 'activated');
Expand Down Expand Up @@ -67,9 +75,6 @@
frame1.remove();
frame2.remove();
return claim_registration.unregister();
})
.then(function() {
return service_worker_unregister_and_done(t, init_scope);
});
}, 'Test claim client which is not using registration');

Expand All @@ -86,6 +91,10 @@
claim_worker_url, {scope: claim_scope});
})
.then(function(registration) {
t.add_cleanup(function() {
return service_worker_unregister(t, claim_scope);
});

claim_worker = registration.installing;
return wait_for_state(t, registration.installing, 'activated');
})
Expand All @@ -94,6 +103,10 @@
installing_worker_url, {scope: scope});
})
.then(function() {
t.add_cleanup(function() {
return service_worker_unregister(t, scope);
});

var channel = new MessageChannel();
var saw_message = new Promise(function(resolve) {
channel.port1.onmessage = t.step_func(function(e) {
Expand All @@ -111,10 +124,6 @@
'Frame should not be claimed when a longer-matched ' +
'registration exists');
frame.remove();
return service_worker_unregister(t, claim_scope);
})
.then(function() {
return service_worker_unregister_and_done(t, scope);
});
}, 'Test claim client when there\'s a longer-matched registration not ' +
'already used by the page');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@
'fetch() should not be intercepted.'))
// Register a service worker.
.then(() => service_worker_unregister_and_register(t, script, scope))
.then(r => worker = r.installing)
.then(() => wait_for_state(t, worker, 'activated'))
.then(r => {
t.add_cleanup(() => service_worker_unregister(t, scope));

worker = r.installing;

return wait_for_state(t, worker, 'activated')
})
// Let the service worker claim the iframe and the shared worker.
.then(() => {
var channel = new MessageChannel();
Expand Down Expand Up @@ -60,8 +64,7 @@
'fetch() in the shared worker should be intercepted.'))

// Cleanup this testcase.
.then(() => frame.remove())
.then(() => service_worker_unregister_and_done(t, scope));
.then(() => frame.remove());
}, 'fetch() in SharedWorker should be intercepted after the client is claimed.')

</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
var worker, sw_registration, frame;
return service_worker_unregister_and_register(t, url1, scope)
.then(function(registration) {
t.add_cleanup(function() {
return service_worker_unregister(t, scope);
});

return wait_for_state(t, registration.installing, 'activated');
})
.then(function() {
Expand Down Expand Up @@ -50,9 +54,6 @@
'Frame1 controller scriptURL should be changed to url2');
frame.remove();
return sw_registration.unregister();
})
.then(function() {
return service_worker_unregister_and_done(t, scope);
});
}, 'Test worker claims client which is using another registration');

Expand All @@ -63,6 +64,10 @@
var frame, worker;
return service_worker_unregister_and_register(t, url1, scope)
.then(function(registration) {
t.add_cleanup(function() {
return service_worker_unregister(t, scope);
});

return wait_for_state(t, registration.installing, 'activated');
})
.then(function() {
Expand Down Expand Up @@ -91,7 +96,6 @@
})
.then(function() {
frame.remove();
return service_worker_unregister_and_done(t, scope);
});
}, 'Test for the waiting worker claims a client which is using the the ' +
'same registration');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@
return service_worker_unregister_and_register(
t, 'resources/clients-matchall-worker.js', scope)
.then(function(registration) {
t.add_cleanup(function() {
return service_worker_unregister(t, scope);
});

return wait_for_state(t, registration.installing, 'activated');
})
.then(function() { return with_iframe(iframe_url); })
Expand All @@ -66,16 +70,18 @@
})
.then(function() {
frame.remove();
return service_worker_unregister_and_done(t, scope);
})
.catch(unreached_rejection(t));
});
}, 'Verify matchAll() with window client type');

promise_test(function(t) {
var frame;
return service_worker_unregister_and_register(
t, 'resources/clients-matchall-worker.js', scope)
.then(function(registration) {
t.add_cleanup(function() {
return service_worker_unregister(t, scope);
});

return wait_for_state(t, registration.installing, 'activated');
})
.then(function() { return with_iframe(iframe_url); })
Expand Down Expand Up @@ -112,7 +118,6 @@
})
.then(function() {
frame.remove();
return service_worker_unregister_and_done(t, scope);
});
}, 'Verify matchAll() with {window, sharedworker, worker} client types');

Expand Down
Loading