OLD | NEW |
---|---|
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <title>Service Worker: Controller on reload</title> | 2 <title>Service Worker: Controller on reload</title> |
3 <script src="/resources/testharness.js"></script> | 3 <script src="/resources/testharness.js"></script> |
4 <script src="/resources/testharnessreport.js"></script> | 4 <script src="/resources/testharnessreport.js"></script> |
5 <script src="resources/test-helpers.sub.js"></script> | 5 <script src="resources/test-helpers.sub.js"></script> |
6 <body> | 6 <body> |
7 <script> | 7 <script> |
8 promise_test(function(t) { | 8 promise_test(function(t) { |
9 var scope = 'resources/blank.html'; | 9 var scope = 'resources/blank.html'; |
falken
2017/02/24 06:49:27
Could we avoid repeating 'blank.html' three times
jungkees
2017/02/24 12:25:26
Yes. Addressed.
| |
10 var frame; | 10 var frame; |
11 var registration; | 11 var registration; |
12 var controller; | 12 var controller; |
13 return service_worker_unregister(t, scope) | 13 return service_worker_unregister(t, scope) |
14 .then(function() { | 14 .then(function() { |
15 return with_iframe(scope); | 15 return with_iframe(scope); |
16 }) | 16 }) |
17 .then(function(f) { | 17 .then(function(f) { |
18 frame = f; | 18 frame = f; |
19 return frame.contentWindow.navigator.serviceWorker.register( | 19 return frame.contentWindow.navigator.serviceWorker.register( |
20 'resources/empty-worker.js', {scope: scope}); | 20 'empty-worker.js', {scope: 'blank.html'}); |
21 }) | 21 }) |
22 .then(function(swr) { | 22 .then(function(swr) { |
23 registration = swr; | 23 registration = swr; |
24 return wait_for_state(t, registration.installing, 'activated'); | 24 return wait_for_state(t, registration.installing, 'activated'); |
25 }) | 25 }) |
26 .then(function() { | 26 .then(function() { |
27 var w = frame.contentWindow; | 27 var w = frame.contentWindow; |
28 assert_equals(w.navigator.serviceWorker.controller, null, | 28 assert_equals(w.navigator.serviceWorker.controller, null, |
29 'controller should be null until the document is ' + | 29 'controller should be null until the document is ' + |
30 'reloaded'); | 30 'reloaded'); |
31 return new Promise(function(resolve) { | 31 return new Promise(function(resolve) { |
32 frame.onload = function() { resolve(); } | 32 frame.onload = function() { resolve(); } |
33 w.location.reload(); | 33 w.location.reload(); |
34 }); | 34 }); |
35 }) | 35 }) |
36 .then(function() { | 36 .then(function() { |
37 var w = frame.contentWindow; | 37 var w = frame.contentWindow; |
38 controller = w.navigator.serviceWorker.controller; | 38 controller = w.navigator.serviceWorker.controller; |
39 assert_true(controller instanceof w.ServiceWorker, | 39 assert_true(controller instanceof w.ServiceWorker, |
40 'controller should be a ServiceWorker object upon reload') ; | 40 'controller should be a ServiceWorker object upon reload') ; |
41 | 41 |
42 // objects from separate windows should not be equal | 42 // objects from separate windows should not be equal |
43 assert_not_equals(controller, registration.active); | 43 assert_not_equals(controller, registration.active); |
44 | 44 |
45 return w.navigator.serviceWorker.getRegistration(); | 45 return w.navigator.serviceWorker.getRegistration('blank.html'); |
46 }) | 46 }) |
47 .then(function(frameRegistration) { | 47 .then(function(frameRegistration) { |
48 assert_equals(frameRegistration.active, controller); | 48 assert_equals(frameRegistration.active, controller); |
49 frame.remove(); | 49 frame.remove(); |
50 service_worker_unregister_and_done(t, scope); | 50 service_worker_unregister_and_done(t, scope); |
51 }); | 51 }); |
52 }, 'controller is set upon reload after registration'); | 52 }, 'controller is set upon reload after registration'); |
53 </script> | 53 </script> |
54 </body> | 54 </body> |
OLD | NEW |