2 <title>Service Worker: Registration update()
</title>
3 <script src=
"../resources/testharness.js"></script>
4 <script src=
"../resources/testharnessreport.js"></script>
5 <script src=
"resources/test-helpers.js"></script>
7 promise_test(function(t
) {
8 var scope
= 'resources/scope/update';
9 var worker_url
= 'resources/update-worker.php';
10 var expected_url
= normalizeURL(worker_url
);
13 return service_worker_unregister_and_register(t
, worker_url
, scope
)
16 return wait_for_state(t
, registration
.installing
, 'activated');
19 assert_equals(registration
.installing
, null,
20 'installing should be null in the initial state.');
21 assert_equals(registration
.waiting
, null,
22 'waiting should be null in the initial state.');
23 assert_equals(registration
.active
.scriptURL
, expected_url
,
24 'active should exist in the initial state.');
26 // A new worker (generated by update-worker.php) should be found.
27 // The returned promise should resolve when a new worker script is
28 // fetched and starts installing.
29 return Promise
.all([registration
.update(),
30 wait_for_update(t
, registration
)]);
33 assert_equals(registration
.installing
.scriptURL
, expected_url
,
34 'new installing should be set after update resolves.');
35 assert_equals(registration
.waiting
, null,
36 'waiting should still be null after update resolves.');
37 assert_equals(registration
.active
.scriptURL
, expected_url
,
38 'active should still exist after update found.');
39 return wait_for_state(t
, registration
.installing
, 'installed');
42 assert_equals(registration
.installing
, null,
43 'installing should be null after installing.');
44 assert_equals(registration
.waiting
.scriptURL
, expected_url
,
45 'waiting should be set after installing.');
46 assert_equals(registration
.active
.scriptURL
, expected_url
,
47 'active should still exist after installing.');
48 return wait_for_state(t
, registration
.waiting
, 'activated');
51 assert_equals(registration
.installing
, null,
52 'installing should be null after activated.');
53 assert_equals(registration
.waiting
, null,
54 'waiting should be null after activated.');
55 assert_equals(registration
.active
.scriptURL
, expected_url
,
56 'new worker should be promoted to active.');
59 // A new worker(generated by update-worker.php) should be found.
60 // The returned promise should reject as update-worker.php sets the
61 // mimetype to a disallowed value for this attempt.
62 return registration
.update();
65 function() { assert_unreached("update() should reject."); },
67 assert_throws('SecurityError', function() { throw e
; },
68 'Using a disallowed mimetype should make update() ' +
69 'promise reject with a SecurityError.');
70 assert_equals(registration
.active
.scriptURL
, expected_url
,
71 'active should still exist after update failure.');
72 return service_worker_unregister_and_done(t
, scope
);
74 }, 'Update a registration.');