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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/test-helpers.sub.js"></script>
<script>
async_test(function(t) {
var documentURL = 'no-such-worker';
navigator.serviceWorker.getRegistration(documentURL)
.then(function(value) {
assert_equals(value, undefined,
'getRegistration should resolve with undefined');
t.done();
})
.catch(unreached_rejection(t));
}, 'getRegistration');
promise_test(function(t) {
var scope = 'resources/scope/getregistration/normal';
var registration;
return service_worker_unregister_and_register(t, 'resources/empty-worker.js',
scope)
.then(function(r) {
t.add_cleanup(function() {
return service_worker_unregister(t, scope);
});
registration = r;
return navigator.serviceWorker.getRegistration(scope);
})
.then(function(value) {
assert_equals(
value, registration,
'getRegistration should resolve to the same registration object');
});
}, 'Register then getRegistration');
promise_test(function(t) {
var scope = 'resources/scope/getregistration/url-with-fragment';
var documentURL = scope + '#ref';
var registration;
return service_worker_unregister_and_register(t, 'resources/empty-worker.js',
scope)
.then(function(r) {
t.add_cleanup(function() {
return service_worker_unregister(t, scope);
});
registration = r;
return navigator.serviceWorker.getRegistration(documentURL);
})
.then(function(value) {
assert_equals(
value, registration,
'getRegistration should resolve to the same registration object');
});
}, 'Register then getRegistration with a URL having a fragment');
async_test(function(t) {
var documentURL = 'http://example.com/';
navigator.serviceWorker.getRegistration(documentURL)
.then(function() {
assert_unreached(
'getRegistration with an out of origin URL should fail');
}, function(reason) {
assert_equals(
reason.name, 'SecurityError',
'getRegistration with an out of origin URL should fail');
t.done();
})
.catch(unreached_rejection(t));
}, 'getRegistration with a cross origin URL');
async_test(function(t) {
var scope = 'resources/scope/getregistration/register-unregister';
service_worker_unregister_and_register(t, 'resources/empty-worker.js',
scope)
.then(function(registration) {
return registration.unregister();
})
.then(function() {
return navigator.serviceWorker.getRegistration(scope);
})
.then(function(value) {
assert_equals(value, undefined,
'getRegistration should resolve with undefined');
t.done();
})
.catch(unreached_rejection(t));
}, 'Register then Unregister then getRegistration');
promise_test(async function(t) {
const scope = 'resources/scope/getregistration/register-unregister';
const registration = await service_worker_unregister_and_register(
t, 'resources/empty-worker.js', scope
);
const frame = await with_iframe(scope);
t.add_cleanup(() => frame.remove());
const frameNav = frame.contentWindow.navigator;
await registration.unregister();
const value = await frameNav.serviceWorker.getRegistration(scope);
assert_equals(value, undefined, 'getRegistration should resolve with undefined');
}, 'Register then Unregister then getRegistration in controlled iframe');
</script>
|