Commit c2180b54 authored by Makoto Shimazu's avatar Makoto Shimazu Committed by Commit Bot

A test to check if service worker can be updated when the script shrinks

Bug: 986688
Change-Id: I8f669c43120fea64dc7b856934e4f2e3198b998d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1712954Reviewed-by: default avatarMatt Falkenhagen <falken@chromium.org>
Commit-Queue: Makoto Shimazu <shimazu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#679889}
parent 49496e98
......@@ -2378,6 +2378,13 @@ crbug.com/411164 [ Win ] http/tests/security/powerfulFeatureRestrictions/service
crbug.com/686118 http/tests/security/setDomainRelaxationForbiddenForURLScheme.html [ Crash Pass ]
# Service worker updates need to succeed when the script shrinks.
crbug.com/986688 external/wpt/service-workers/service-worker/update.https.html [ Skip ]
crbug.com/986688 virtual/blink-cors/external/wpt/service-workers/service-worker/update.https.html [ Skip ]
crbug.com/986688 virtual/cache-storage-sequence/external/wpt/service-workers/service-worker/update.https.html [ Skip ]
crbug.com/986688 virtual/not-omt-sw-fetch/external/wpt/service-workers/service-worker/update.https.html [ Skip ]
crbug.com/986688 virtual/omt-worker-fetch/external/wpt/service-workers/service-worker/update.https.html [ Skip ]
# In external/wpt/html/, we prefer checking in failure
# expectation files. The following tests with [ Failure ] don't have failure
# expectation files because they contain local path names.
......
import os
def serve_js_from_file(request, response, filename):
body = ''
path = os.path.join(os.path.dirname(__file__), filename)
with open(path, 'rb') as f:
body = f.read()
return (
[
('Cache-Control', 'no-cache, must-revalidate'),
('Pragma', 'no-cache'),
('Content-Type', 'application/javascript')
], body)
def main(request, response):
key = request.GET["Key"]
visited_count = request.server.stash.take(key)
if visited_count is None:
visited_count = 0
# Keep how many times the test requested this resource.
visited_count += 1
request.server.stash.put(key, visited_count)
# Serve a file based on how many times it's requested.
if visited_count == 1:
return serve_js_from_file(request, response, request.GET["First"])
if visited_count == 2:
return serve_js_from_file(request, response, request.GET["Second"])
raise "Unknown state"
......@@ -10,11 +10,12 @@
'use strict';
const SCOPE = 'resources/simple.txt';
const WORKER_URL_BASE = 'resources/update-worker.py';
async function prepare_ready_registration(t, mode) {
// Create a service worker (update-worker.py). The response to update() will be
// different based on the mode.
async function prepare_ready_registration_with_mode(t, mode) {
const key = token();
const worker_url = `${WORKER_URL_BASE}?Key=${key}&Mode=${mode}`;
const worker_url = `resources/update-worker.py?Key=${key}&Mode=${mode}`;
const expected_url = normalizeURL(worker_url);
const registration = await service_worker_unregister_and_register(
t, worker_url, SCOPE);
......@@ -28,6 +29,27 @@ async function prepare_ready_registration(t, mode) {
return [registration, expected_url];
}
// Create a service worker (update-worker-from-file.py), which is initially
// |initial_worker| and |updated_worker| later.
async function prepare_ready_registration_with_file(
t, initial_worker, updated_worker) {
const key = token();
const worker_url = `resources/update-worker-from-file.py?` +
`First=${initial_worker}&Second=${updated_worker}&Key=${key}`;
const expected_url = normalizeURL(worker_url);
const registration = await service_worker_unregister_and_register(
t, worker_url, SCOPE);
await wait_for_state(t, registration.installing, 'activated');
assert_equals(registration.installing, null,
'prepare_ready: installing');
assert_equals(registration.waiting, null,
'prepare_ready: waiting');
assert_equals(registration.active.scriptURL, expected_url,
'prepare_ready: active');
return [registration, expected_url];
}
function assert_installing_and_active(registration, expected_url) {
assert_equals(registration.installing.scriptURL, expected_url,
'assert_installing_and_active: installing');
......@@ -57,7 +79,7 @@ function assert_active_only(registration, expected_url) {
promise_test(async t => {
const [registration, expected_url] =
await prepare_ready_registration(t, 'normal');
await prepare_ready_registration_with_mode(t, 'normal');
t.add_cleanup(() => registration.unregister());
await Promise.all([registration.update(), wait_for_update(t, registration)]);
......@@ -72,7 +94,7 @@ promise_test(async t => {
promise_test(async t => {
const [registration, expected_url] =
await prepare_ready_registration(t, 'bad_mime_type');
await prepare_ready_registration_with_mode(t, 'bad_mime_type');
t.add_cleanup(() => registration.unregister());
await promise_rejects(t, 'SecurityError', registration.update());
......@@ -81,7 +103,7 @@ promise_test(async t => {
promise_test(async t => {
const [registration, expected_url] =
await prepare_ready_registration(t, 'redirect');
await prepare_ready_registration_with_mode(t, 'redirect');
t.add_cleanup(() => registration.unregister());
await promise_rejects(t, new TypeError(), registration.update());
......@@ -90,7 +112,7 @@ promise_test(async t => {
promise_test(async t => {
const [registration, expected_url] =
await prepare_ready_registration(t, 'syntax_error');
await prepare_ready_registration_with_mode(t, 'syntax_error');
t.add_cleanup(() => registration.unregister());
await promise_rejects(t, new TypeError(), registration.update());
......@@ -99,7 +121,7 @@ promise_test(async t => {
promise_test(async t => {
const [registration, expected_url] =
await prepare_ready_registration(t, 'throw_install');
await prepare_ready_registration_with_mode(t, 'throw_install');
t.add_cleanup(() => registration.unregister());
await Promise.all([registration.update(), wait_for_update(t, registration)]);
......@@ -108,7 +130,7 @@ promise_test(async t => {
promise_test(async t => {
const [registration, expected_url] =
await prepare_ready_registration(t, 'normal');
await prepare_ready_registration_with_mode(t, 'normal');
t.add_cleanup(() => registration.unregister());
// We need to hold a client alive so that unregister() below doesn't remove
......@@ -120,5 +142,23 @@ promise_test(async t => {
await promise_rejects(
t, new TypeError(),
Promise.all([registration.unregister(), registration.update()]));
}, 'update() should fail when the pending uninstall flag is set.')
}, 'update() should fail when the pending uninstall flag is set.');
promise_test(async t => {
const [registration, expected_url] =
await prepare_ready_registration_with_file(
t,
'update-smaller-body-before-update-worker.js',
'update-smaller-body-after-update-worker.js');
t.add_cleanup(() => registration.unregister());
await Promise.all([registration.update(), wait_for_update(t, registration)]);
assert_installing_and_active(registration, expected_url);
await wait_for_state(t, registration.installing, 'installed');
assert_waiting_and_active(registration, expected_url);
await wait_for_state(t, registration.waiting, 'activated');
assert_active_only(registration, expected_url);
}, 'update() should succeed when the script shrinks.');
</script>
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