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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
<!DOCTYPE html>
<title>Service Worker: Registration update()</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/testharness-helpers.js"></script>
<script src="resources/test-helpers.sub.js"></script>
<script>
promise_test(function(t) {
var scope = 'resources/simple.txt';
var worker_url = 'resources/update-worker.py';
var expected_url = normalizeURL(worker_url);
var registration;
var iframe;
return service_worker_unregister_and_register(t, worker_url, scope)
.then(function(r) {
registration = r;
return wait_for_state(t, registration.installing, 'activated');
})
.then(function() {
assert_equals(registration.installing, null,
'installing should be null in the initial state.');
assert_equals(registration.waiting, null,
'waiting should be null in the initial state.');
assert_equals(registration.active.scriptURL, expected_url,
'active should exist in the initial state.');
// A new worker (generated by update-worker.py) should be found.
// The returned promise should resolve when a new worker script is
// fetched and starts installing.
return Promise.all([registration.update(),
wait_for_update(t, registration)]);
})
.then(function() {
assert_equals(registration.installing.scriptURL, expected_url,
'new installing should be set after update resolves.');
assert_equals(registration.waiting, null,
'waiting should still be null after update resolves.');
assert_equals(registration.active.scriptURL, expected_url,
'active should still exist after update found.');
return wait_for_state(t, registration.installing, 'installed');
})
.then(function() {
assert_equals(registration.installing, null,
'installing should be null after installing.');
if (registration.waiting) {
assert_equals(registration.waiting.scriptURL, expected_url,
'waiting should be set after installing.');
assert_equals(registration.active.scriptURL, expected_url,
'active should still exist after installing.');
return wait_for_state(t, registration.waiting, 'activated');
}
})
.then(function() {
assert_equals(registration.installing, null,
'installing should be null after activated.');
assert_equals(registration.waiting, null,
'waiting should be null after activated.');
assert_equals(registration.active.scriptURL, expected_url,
'new worker should be promoted to active.');
})
.then(function() {
// A new worker(generated by update-worker.py) should be found.
// The returned promise should reject as update-worker.py sets the
// mimetype to a disallowed value for this attempt.
return registration.update();
})
.then(
function() { assert_unreached("update() should reject."); },
function(e) {
assert_throws('SecurityError', function() { throw e; },
'Using a disallowed mimetype should make update() ' +
'promise reject with a SecurityError.');
assert_equals(registration.active.scriptURL, expected_url,
'active should still exist after update failure.');
// A new worker(generated by update-worker.py) should be found.
// The returned promise should reject as update-worker.py returns
// a worker script with a syntax error.
return registration.update();
})
.then(
function() { assert_unreached("update() should reject."); },
function(e) {
assert_throws({name: 'TypeError'}, function () { throw e; },
'A script syntax error should make update() ' +
'promise reject with a TypeError.');
assert_equals(registration.active.scriptURL, expected_url,
'active should still exist after update failure.');
// A new worker(generated by update-worker.py) should be found.
// The returned promise should not reject, even though
// update-worker.py returns a worker script that throws in the
// install event handler.
return Promise.all([registration.update(),
wait_for_update(t, registration)]);
})
.then(function() {
assert_equals(registration.installing.scriptURL, expected_url,
'new installing should be set after update resolves.');
assert_equals(registration.waiting, null,
'waiting should be null after activated.');
assert_equals(registration.active.scriptURL, expected_url,
'active should still exist after update found.');
// We need to hold a client alive so that unregister() below doesn't
// remove the registration before update() has had a chance to look
// at the pending uninstall flag.
return with_iframe(scope);
})
.then(function(frame) {
iframe = frame;
return assert_promise_rejects(
Promise.all([registration.unregister(), registration.update()]),
new TypeError(),
'Calling update() while the uninstalling flag is set ' +
'should return a promise that rejects with a TypeError.');
})
.then(function() {
iframe.remove();
return t.done();
});
}, 'Update a registration.');
</script>
|