Skip to content

Commit

Permalink
[ServiceWorker] Propagate change for ServiceWorkerRegistration#update…
Browse files Browse the repository at this point in the history
…ViaCache

This CL propagates change of registration's `updateViaCache` to
corresponding registration objects in the renderer process to set their
ServiceWorkerRegistration#updateViaCache attribute.

BUG=675540

Change-Id: I6bb80dacbdd6a276f7ba8eb95f9f1e5379fbf03b
Reviewed-on: https://chromium-review.googlesource.com/1002732
Reviewed-by: Makoto Shimazu <[email protected]>
Reviewed-by: Matt Falkenhagen <[email protected]>
Reviewed-by: Kinuko Yasuda <[email protected]>
Commit-Queue: Matt Falkenhagen <[email protected]>
Cr-Commit-Position: refs/heads/master@{#558157}
  • Loading branch information
Han Leon authored and foolip committed May 13, 2018
1 parent f260ef9 commit 7baa334
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 7 deletions.
4 changes: 2 additions & 2 deletions service-workers/service-worker/activation.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
return wait_for_state(t, registration.installing, 'installed');
})
.then(() => {
return wait_for_activation_on_dummy_scope(t);
return wait_for_activation_on_dummy_scope(t, self);
})
.then(() => {
assert_not_equals(registration.waiting, null);
Expand All @@ -69,7 +69,7 @@
iframe = result.iframe;
// Finish the in-flight request.
registration.active.postMessage('go');
return wait_for_activation_on_dummy_scope(t);
return wait_for_activation_on_dummy_scope(t, self);
})
.then(() => {
// The new worker is still waiting. Remove the frame and it should
Expand Down
2 changes: 1 addition & 1 deletion service-workers/service-worker/detached-context.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
() => {});
r.update().then(() => resolvedCount += 1,
() => {});
return wait_for_activation_on_dummy_scope(t);
return wait_for_activation_on_dummy_scope(t, window);
})
.then(() => {
assert_equals(resolvedCount, 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,18 @@
await wait_for_state(t, sw, 'activated');
const values = await getScriptTimes(sw, testName);

const frame = await with_iframe(SCOPE);
const reg_in_frame = await frame.contentWindow.navigator.serviceWorker.getRegistration(normalizeURL(SCOPE));
assert_equals(reg_in_frame.updateViaCache, updateViaCache1 || 'imports', "reg_in_frame.updateViaCache");

opts = {scope: SCOPE};
if (updateViaCache2) opts.updateViaCache = updateViaCache2;

await navigator.serviceWorker.register(fullScriptUrl, opts);

assert_equals(reg.updateViaCache, updateViaCache2 || 'imports', "reg.updateViaCache updated");
const expected_updateViaCache = updateViaCache2 || 'imports';

assert_equals(reg.updateViaCache, expected_updateViaCache, "reg.updateViaCache updated");
// If the update happens via the cache, the scripts will come back byte-identical.
// We bypass the byte-identical check if the script URL has changed, but not if
// only the updateViaCache value has changed.
Expand Down Expand Up @@ -138,9 +143,44 @@
}
}

// Wait for all registration related tasks on |frame| to complete.
await wait_for_activation_on_dummy_scope(t, frame.contentWindow);
// The updateViaCache change should have been propagated to all
// corresponding JS registration objects.
assert_equals(reg_in_frame.updateViaCache, expected_updateViaCache, "reg_in_frame.updateViaCache updated");
frame.remove();

await cleanup();
}, testName);
}
}

// Test accessing updateViaCache of an unregistered registration.
for (const updateViaCache of UPDATE_VIA_CACHE_VALUES) {
const testName = `access-updateViaCache-after-unregister-${updateViaCache}`;

promise_test(async t => {
await cleanup();

const opts = {scope: SCOPE};

if (updateViaCache) opts.updateViaCache = updateViaCache;

const reg = await navigator.serviceWorker.register(
`${SCRIPT_URL}?test=${testName}`,
opts
);

const expected_updateViaCache = updateViaCache || 'imports';
assert_equals(reg.updateViaCache, expected_updateViaCache, "reg.updateViaCache");

await reg.unregister();

// Keep the original value.
assert_equals(reg.updateViaCache, expected_updateViaCache, "reg.updateViaCache");

await cleanup();
}, testName);
}

</script>
6 changes: 3 additions & 3 deletions service-workers/service-worker/resources/test-helpers.sub.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,10 @@ function with_sandboxed_iframe(url, sandbox) {
// activate, and then unregister a service worker. When checking that
// certain behavior does *NOT* happen, this is preferable to using an
// arbitrary delay.
async function wait_for_activation_on_dummy_scope(t) {
const script = 'resources/empty-worker.js';
async function wait_for_activation_on_dummy_scope(t, window_or_workerglobalscope) {
const script = '/service-workers/service-worker/resources/empty-worker.js';
const scope = 'resources/there/is/no/there/there?' + Date.now();
let registration = await navigator.serviceWorker.register(script, { scope });
let registration = await window_or_workerglobalscope.navigator.serviceWorker.register(script, { scope });
await wait_for_state(t, registration.installing, 'activated');
await registration.unregister();
}

0 comments on commit 7baa334

Please sign in to comment.