mirror of
https://github.com/servo/servo.git
synced 2025-09-06 21:18:20 +01:00
Update web-platform-tests to revision cfada7e6cb379699fa94c7ed8fcb97082327e10c
This commit is contained in:
parent
87e7e3d429
commit
06b00da16b
179 changed files with 6103 additions and 1186 deletions
|
@ -0,0 +1,8 @@
|
|||
// This worker imports a script that returns 200 on the first request and 404
|
||||
// on the second request, and a script that is updated every time when
|
||||
// requesting it.
|
||||
const params = new URLSearchParams(location.search);
|
||||
const key = params.get('Key');
|
||||
const additional_key = params.get('AdditionalKey');
|
||||
importScripts(`update-worker.py?Key=${key}&Mode=not_found`,
|
||||
`update-worker.py?Key=${additional_key}&Mode=normal`);
|
|
@ -0,0 +1,6 @@
|
|||
// This worker imports a script that returns 200 on the first request and 404
|
||||
// on the second request. The resulting body also changes each time it is
|
||||
// requested.
|
||||
const params = new URLSearchParams(location.search);
|
||||
const key = params.get('Key');
|
||||
importScripts(`update-worker.py?Key=${key}&Mode=not_found`);
|
|
@ -0,0 +1 @@
|
|||
importScripts('404.py');
|
|
@ -15,6 +15,9 @@ def redirect_response(request, response, visited_count):
|
|||
],
|
||||
'/* %s */' % str(visited_count))
|
||||
|
||||
def not_found_response():
|
||||
return 404, [('Content-Type', 'text/plain')], "Page not found"
|
||||
|
||||
def ok_response(request, response, visited_count,
|
||||
extra_body='', mime_type='application/javascript'):
|
||||
# |visited_count| is used as a unique id to differentiate responses
|
||||
|
@ -45,10 +48,13 @@ def main(request, response):
|
|||
return ok_response(request, response, visited_count)
|
||||
if mode == 'bad_mime_type':
|
||||
return ok_response(request, response, visited_count, mime_type='text/html')
|
||||
if mode == 'not_found':
|
||||
return not_found_response()
|
||||
if mode == 'redirect':
|
||||
return redirect_response(request, response, visited_count)
|
||||
if mode == 'syntax_error':
|
||||
return ok_response(request, response, visited_count, extra_body='badsyntax(isbad;')
|
||||
if mode == 'throw_install':
|
||||
return ok_response(request, response, visited_count, extra_body="addEventListener('install', function(e) { throw new Error('boom'); });")
|
||||
|
||||
return ok_response(request, response, visited_count)
|
||||
|
|
|
@ -22,8 +22,8 @@ promise_test(async function(t) {
|
|||
t.add_cleanup(() => newRegistration.unregister());
|
||||
|
||||
assert_equals(
|
||||
registration.installing.scriptURL,
|
||||
normalizeURL(newWorkerURL),
|
||||
registration.installing,
|
||||
null,
|
||||
'before activated registration.installing'
|
||||
);
|
||||
assert_equals(
|
||||
|
@ -47,13 +47,13 @@ promise_test(async function(t) {
|
|||
'before activated newRegistration.waiting'
|
||||
);
|
||||
assert_equals(
|
||||
newRegistration.active.scriptURL,
|
||||
normalizeURL(worker_url),
|
||||
newRegistration.active,
|
||||
null,
|
||||
'before activated newRegistration.active'
|
||||
);
|
||||
iframe.remove();
|
||||
|
||||
await wait_for_state(t, registration.installing, 'activated');
|
||||
await wait_for_state(t, newRegistration.installing, 'activated');
|
||||
|
||||
assert_equals(
|
||||
newRegistration.installing,
|
||||
|
@ -129,7 +129,8 @@ promise_test(async function(t) {
|
|||
|
||||
assert_equals(registration.installing, null, 'registration.installing');
|
||||
assert_equals(registration.waiting, null, 'registration.waiting');
|
||||
assert_equals(registration.active, null, 'registration.active');
|
||||
assert_equals(registration.active.scriptURL, normalizeURL(worker_url),
|
||||
'registration.active');
|
||||
assert_not_equals(registration, newRegistration, 'New registration is different');
|
||||
}, 'Registering a new script URL that fails to install does not resurrect unregistered registration');
|
||||
</script>
|
||||
|
|
|
@ -66,7 +66,7 @@ promise_test(function(t) {
|
|||
.then(function() {
|
||||
return navigator.serviceWorker.register(worker_url, { scope: scope });
|
||||
})
|
||||
.then(function(registration) {
|
||||
.then(function(newRegistration) {
|
||||
assert_equals(registration.installing, null,
|
||||
'installing version is null');
|
||||
assert_equals(registration.waiting, null, 'waiting version is null');
|
||||
|
|
|
@ -0,0 +1,127 @@
|
|||
<!DOCTYPE html>
|
||||
<meta charset="utf-8">
|
||||
<title>Tests for importScripts: import scripts ignored error</title>
|
||||
<script src="/common/utils.js"></script>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="resources/test-helpers.sub.js"></script>
|
||||
<body>
|
||||
<script>
|
||||
// This file contains tests to check if imported scripts appropriately updated.
|
||||
|
||||
const SCOPE = 'resources/simple.txt';
|
||||
|
||||
// Create a service worker (update-worker-from-file.py), which is initially
|
||||
// |initial_worker| and |updated_worker| later.
|
||||
async function prepare_ready_update_worker_from_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];
|
||||
}
|
||||
|
||||
// Create a service worker using the script under resources/.
|
||||
async function prepare_ready_normal_worker(t, filename, additional_params='') {
|
||||
const key = token();
|
||||
const worker_url = `resources/${filename}?Key=${key}&${additional_params}`;
|
||||
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');
|
||||
assert_equals(registration.waiting, null,
|
||||
'assert_installing_and_active: waiting');
|
||||
assert_equals(registration.active.scriptURL, expected_url,
|
||||
'assert_installing_and_active: active');
|
||||
}
|
||||
|
||||
function assert_waiting_and_active(registration, expected_url) {
|
||||
assert_equals(registration.installing, null,
|
||||
'assert_waiting_and_active: installing');
|
||||
assert_equals(registration.waiting.scriptURL, expected_url,
|
||||
'assert_waiting_and_active: waiting');
|
||||
assert_equals(registration.active.scriptURL, expected_url,
|
||||
'assert_waiting_and_active: active');
|
||||
}
|
||||
|
||||
function assert_active_only(registration, expected_url) {
|
||||
assert_equals(registration.installing, null,
|
||||
'assert_active_only: installing');
|
||||
assert_equals(registration.waiting, null,
|
||||
'assert_active_only: waiting');
|
||||
assert_equals(registration.active.scriptURL, expected_url,
|
||||
'assert_active_only: active');
|
||||
}
|
||||
|
||||
promise_test(async t => {
|
||||
const [registration, expected_url] =
|
||||
await prepare_ready_update_worker_from_file(
|
||||
t, 'empty.js', 'import-scripts-404.js');
|
||||
t.add_cleanup(() => registration.unregister());
|
||||
|
||||
await promise_rejects(t, new TypeError(), registration.update());
|
||||
assert_active_only(registration, expected_url);
|
||||
}, 'update() should fail when a new worker imports an unavailable script.');
|
||||
|
||||
promise_test(async t => {
|
||||
const [registration, expected_url] =
|
||||
await prepare_ready_update_worker_from_file(
|
||||
t, 'import-scripts-404-after-update.js', 'empty.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 old imported script no longer exist but ' +
|
||||
"the new worker doesn't import it.");
|
||||
|
||||
promise_test(async t => {
|
||||
const [registration, expected_url] = await prepare_ready_normal_worker(
|
||||
t, 'import-scripts-404-after-update.js');
|
||||
t.add_cleanup(() => registration.unregister());
|
||||
|
||||
await registration.update();
|
||||
assert_active_only(registration, expected_url);
|
||||
}, 'update() should treat 404 on imported scripts as no change.');
|
||||
|
||||
promise_test(async t => {
|
||||
const [registration, expected_url] = await prepare_ready_normal_worker(
|
||||
t, 'import-scripts-404-after-update-plus-update-worker.js',
|
||||
`AdditionalKey=${token()}`);
|
||||
t.add_cleanup(() => registration.unregister());
|
||||
|
||||
await promise_rejects(t, new TypeError(), registration.update());
|
||||
assert_active_only(registration, expected_url);
|
||||
}, 'update() should find an update in an imported script but update() should ' +
|
||||
'result in failure due to missing the other imported script.');
|
||||
</script>
|
||||
</body>
|
Loading…
Add table
Add a link
Reference in a new issue