Commit 270d4abd authored by Asami Doi's avatar Asami Doi Committed by Commit Bot

ServiceWorker: Add new WPT tests to make sure to update a registration

with different script type and identical script content.

These tests check that a registration is updated correctly with
different script type. At first Service Worker is registered as
classic script type, then it is re-registered as module script type,
and vice versa. A main script is identical.

Bug: 824647
Change-Id: I2a3f87da1013f84c6e9495f362899dfe6ab97b45
Reviewed-on: https://chromium-review.googlesource.com/c/1298822
Commit-Queue: Asami Doi <asamidoi@google.com>
Reviewed-by: default avatarHiroki Nakagawa <nhiroki@chromium.org>
Reviewed-by: default avatarMatt Falkenhagen <falken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#604551}
parent b7c90b6e
This is a testharness.js-based test.
PASS Update the registration with a different script type (classic => module).
PASS Update the registration with a different script type (module => classic).
PASS Update the registration with a different script type (classic => module) and with a same main script.
FAIL Update the registration with a different script type (module => classic) and with a same main script. promise_test: Unhandled rejection with value: object "Error: wait_for_state must be passed a ServiceWorker"
PASS Does not update the registration with the same script type and the same main script.
FAIL Update the registration with a different script type (classic => module) and with a same main script. Expect evaluation failed. assert_unreached: Should have rejected: Registering with invalid evaluation should be failed. Reached unreachable code
FAIL Update the registration with a different script type (module => classic) and with a same main script. Expect evaluation failed. assert_unreached: Should have rejected: Registering with invalid evaluation should be failed. Reached unreachable code
Harness: the test ran to completion.
......@@ -7,8 +7,8 @@
<script src="/resources/testharnessreport.js"></script>
<script src="resources/test-helpers.sub.js"></script>
<script>
// These tests check that a registration is updated correctly with
// different script type. At first Service Worker is register as
// The following two tests check that a registration is updated correctly
// with different script type. At first Service Worker is registered as
// classic script type, then it is re-registered as module script type,
// and vice versa. A main script is also updated at the same time.
promise_test(async t => {
......@@ -70,5 +70,135 @@ promise_test(async t => {
assert_equals(msgEvent.data, 'A classic script.');
assert_equals(firstRegistration, secondRegistration);
}, 'Update the registration with a different script type (module => classic).');
// The following two tests change the script type while keeping
// the script identical.
promise_test(async t => {
const script = 'resources/empty-worker.js';
const scope = 'resources/update-registration-with-type';
await service_worker_unregister(t, scope);
t.add_cleanup(() => service_worker_unregister(t, scope));
// Register with classic script type.
const firstRegistration = await navigator.serviceWorker.register(script, {
scope: scope,
type: 'classic'
});
await wait_for_state(t, firstRegistration.installing, 'activated');
const firstActiveWorker = firstRegistration.active;
// Re-register with module script type.
const secondRegistration = await navigator.serviceWorker.register(script, {
scope: scope,
type: 'module'
});
await wait_for_state(t, secondRegistration.installing, 'activated');
const secondActiveWorker = secondRegistration.active;
assert_not_equals(firstActiveWorker, secondActiveWorker);
assert_equals(firstRegistration, secondRegistration);
}, 'Update the registration with a different script type (classic => module) '
+ 'and with a same main script.');
promise_test(async t => {
const script = 'resources/empty-worker.js';
const scope = 'resources/update-registration-with-type';
await service_worker_unregister(t, scope);
t.add_cleanup(() => service_worker_unregister(t, scope));
// Register with module script type.
const firstRegistration = await navigator.serviceWorker.register(script, {
scope: scope,
type: 'module'
});
await wait_for_state(t, firstRegistration.installing, 'activated');
const firstActiveWorker = firstRegistration.active;
// Re-register with classic script type.
const secondRegistration = await navigator.serviceWorker.register(script, {
scope: scope,
type: 'classic'
});
await wait_for_state(t, secondRegistration.installing, 'activated');
const secondActiveWorker = secondRegistration.active;
assert_not_equals(firstActiveWorker, secondActiveWorker);
assert_equals(firstRegistration, secondRegistration);
}, 'Update the registration with a different script type (module => classic) '
+ 'and with a same main script.');
// This test checks that a registration is not updated with the same script
// type and the same main script.
promise_test(async t => {
const script = 'resources/empty-worker.js';
const scope = 'resources/update-registration-with-type';
await service_worker_unregister(t, scope);
t.add_cleanup(() => service_worker_unregister(t, scope));
// Register with module script type.
const firstRegistration = await navigator.serviceWorker.register(script, {
scope: scope,
type: 'module'
});
await wait_for_state(t, firstRegistration.installing, 'activated');
// Re-register with module script type.
const secondRegistration = await navigator.serviceWorker.register(script, {
scope: scope,
type: 'module'
});
assert_equals(secondRegistration.installing, null);
assert_equals(firstRegistration, secondRegistration);
}, 'Does not update the registration with the same script type and '
+ 'the same main script.');
// In the case (classic => module), a worker script contains importScripts()
// that is disallowed on module scripts, so the second registration is
// expected to fail script evaluation.
promise_test(async t => {
const script = 'resources/classic-worker.js';
const scope = 'resources/update-registration-with-type';
await service_worker_unregister(t, scope);
t.add_cleanup(() => service_worker_unregister(t, scope));
// Register with classic script type.
const firstRegistration = await navigator.serviceWorker.register(script, {
scope: scope,
type: 'classic'
});
assert_not_equals(firstRegistration.installing, null);
// Re-register with module script type and expect TypeError.
return promise_rejects(t, new TypeError, navigator.serviceWorker.register(script, {
scope: scope,
type: 'module'
}), 'Registering with invalid evaluation should be failed.');
}, 'Update the registration with a different script type (classic => module) '
+ 'and with a same main script. Expect evaluation failed.');
// In the case (module => classic), a worker script contains static-import
// that is disallowed on classic scripts, so the second registration is
// expected to fail script evaluation.
promise_test(async t => {
const script = 'resources/module-worker.js';
const scope = 'resources/update-registration-with-type';
await service_worker_unregister(t, scope);
t.add_cleanup(() => service_worker_unregister(t, scope));
// Register with module script type.
const firstRegistration = await navigator.serviceWorker.register(script, {
scope: scope,
type: 'module'
});
assert_not_equals(firstRegistration.installing, null);
// Re-register with classic script type and expect TypeError.
return promise_rejects(t, new TypeError, navigator.serviceWorker.register(script, {
scope: scope,
type: 'classic'
}), 'Registering with invalid evaluation should be failed.');
}, 'Update the registration with a different script type (module => classic) '
+ 'and with a same main script. Expect evaluation failed.');
</script>
</body>
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