зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1568120 [wpt PR 17993] - A test to check if service worker can be updated when the script shrinks, a=testonly
Automatic update from web-platform-tests 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/+/1712954 Reviewed-by: Matt Falkenhagen <falken@chromium.org> Commit-Queue: Makoto Shimazu <shimazu@chromium.org> Cr-Commit-Position: refs/heads/master@{#679889} -- wpt-commits: a04bcd452ecf99580ea4557fe3c4b2db42bc27b4 wpt-pr: 17993
This commit is contained in:
Родитель
59a9932780
Коммит
2991dbed6d
|
@ -0,0 +1 @@
|
|||
// Hello world!
|
|
@ -0,0 +1,2 @@
|
|||
// Hello world!
|
||||
// **with extra body**
|
|
@ -0,0 +1,31 @@
|
|||
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>
|
||||
|
|
Загрузка…
Ссылка в новой задаче