Commit 6386d9d8 authored by Kenichi Ishibashi's avatar Kenichi Ishibashi Committed by Commit Bot

Update service_worker_unregister_and_register()

Allows callsites of this helper function to pass RegistrationOptions.
It will be useful for testing module service workers.

Bug: 824647
Change-Id: Idc9a5c012144da46dfc4d692ce26df9f604a6ea1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1851624
Commit-Queue: Kenichi Ishibashi <bashi@chromium.org>
Reviewed-by: default avatarHiroki Nakagawa <nhiroki@chromium.org>
Cr-Commit-Position: refs/heads/master@{#704963}
parent 195df6b5
// Adapter for testharness.js-style tests with Service Workers
function service_worker_unregister_and_register(test, url, scope) {
/**
* @param options an object that represents RegistrationOptions except for scope.
* @param options.type a WorkerType.
* @param options.updateViaCache a ServiceWorkerUpdateViaCache.
* @see https://w3c.github.io/ServiceWorker/#dictdef-registrationoptions
*/
function service_worker_unregister_and_register(test, url, scope, options = {}) {
if (!scope || scope.length == 0)
return Promise.reject(new Error('tests must define a scope'));
var options = { scope: scope };
options.scope = scope;
return service_worker_unregister(test, scope)
.then(function() {
return navigator.serviceWorker.register(url, options);
......
// Adapter for testharness.js-style tests with Service Workers
function service_worker_unregister_and_register(
test, url, scope, updateViaCache = 'imports') {
function service_worker_unregister_and_register(test, url, scope, options = {}) {
if (!scope || scope.length == 0)
return Promise.reject(new Error('tests must define a scope'));
var options = { scope: scope, updateViaCache: updateViaCache };
options.scope = scope;
return service_worker_unregister(test, scope)
.then(function() {
return navigator.serviceWorker.register(url, options);
......
......@@ -14,8 +14,9 @@ for (let update_via_cache of ['none', 'imports']) {
promise_test(function(t) {
let registration;
let options = { updateViaCache: update_via_cache };
return service_worker_unregister_and_register(t, worker_url, scope,
update_via_cache)
options)
.then(function(r) {
// The script resource for this register() having a non-zero
// max-age value was cached.
......@@ -44,8 +45,9 @@ for (let update_via_cache of ['all']) {
promise_test(function(t) {
let registration;
let options = { updateViaCache: update_via_cache };
return service_worker_unregister_and_register(t, worker_url, scope,
update_via_cache)
options)
.then(function(r) {
// The script resource for this register() having a non-zero
// max-age value was cached.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment