-
Notifications
You must be signed in to change notification settings - Fork 3k
/
update-registration-with-type.https.html
74 lines (69 loc) · 2.83 KB
/
update-registration-with-type.https.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<!DOCTYPE html>
<meta charset="utf-8">
<title>Service Worker: Update the registration with a different script type.</title>
<!-- common.js is for guid() -->
<script src="/mixed-content/generic/common.js"></script>
<script src="/resources/testharness.js"></script>
<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
// 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 => {
const key = guid();
const script = `resources/update-registration-with-type.py?classic_first=1&key=${key}`;
const scope = 'resources/update-registration-with-type';
await service_worker_unregister(t, scope);
// Register with classic script type.
const firstRegistration = await navigator.serviceWorker.register(script, {
scope: scope,
type: 'classic'
});
firstRegistration.installing.postMessage(' ');
let msgEvent = await new Promise(resolve => {
navigator.serviceWorker.onmessage = resolve;
});
assert_equals(msgEvent.data, 'A classic script.');
// Re-register with module script type.
const secondRegistration = await navigator.serviceWorker.register(script, {
scope: scope,
type: 'module'
});
secondRegistration.installing.postMessage(' ');
msgEvent = await new Promise(resolve => {
navigator.serviceWorker.onmessage = resolve;
});
assert_equals(msgEvent.data, 'A module script.');
assert_equals(firstRegistration, secondRegistration);
}, 'Update the registration with a different script type (classic => module).');
promise_test(async t => {
const key = guid();
const script = `resources/update-registration-with-type.py?classic_first=0&key=${key}`;
const scope = 'resources/update-registration-with-type';
await service_worker_unregister(t, scope);
// Register with module script type.
const firstRegistration = await navigator.serviceWorker.register(script, {
scope: scope,
type: 'module'
});
firstRegistration.installing.postMessage(' ');
let msgEvent = await new Promise(resolve => {
navigator.serviceWorker.onmessage = resolve;
});
assert_equals(msgEvent.data, 'A module script.');
// Re-register with classic script type.
const secondRegistration = await navigator.serviceWorker.register(script, {
scope: scope,
type: 'classic'
});
secondRegistration.installing.postMessage(' ');
msgEvent = await new Promise(resolve => {
navigator.serviceWorker.onmessage = resolve;
});
assert_equals(msgEvent.data, 'A classic script.');
assert_equals(firstRegistration, secondRegistration);
}, 'Update the registration with a different script type (module => classic).');
</script>
</body>