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 const iframe_scope = 'blank.html'; |
| 10 const scope = 'resources/' + iframe_scope; |
10 var frame; | 11 var frame; |
11 var registration; | 12 var registration; |
12 var controller; | 13 var controller; |
13 return service_worker_unregister(t, scope) | 14 return service_worker_unregister(t, scope) |
14 .then(function() { | 15 .then(function() { |
15 return with_iframe(scope); | 16 return with_iframe(scope); |
16 }) | 17 }) |
17 .then(function(f) { | 18 .then(function(f) { |
18 frame = f; | 19 frame = f; |
19 return frame.contentWindow.navigator.serviceWorker.register( | 20 return frame.contentWindow.navigator.serviceWorker.register( |
20 'resources/empty-worker.js', {scope: scope}); | 21 'empty-worker.js', {scope: iframe_scope}); |
21 }) | 22 }) |
22 .then(function(swr) { | 23 .then(function(swr) { |
23 registration = swr; | 24 registration = swr; |
24 return wait_for_state(t, registration.installing, 'activated'); | 25 return wait_for_state(t, registration.installing, 'activated'); |
25 }) | 26 }) |
26 .then(function() { | 27 .then(function() { |
27 var w = frame.contentWindow; | 28 var w = frame.contentWindow; |
28 assert_equals(w.navigator.serviceWorker.controller, null, | 29 assert_equals(w.navigator.serviceWorker.controller, null, |
29 'controller should be null until the document is ' + | 30 'controller should be null until the document is ' + |
30 'reloaded'); | 31 'reloaded'); |
31 return new Promise(function(resolve) { | 32 return new Promise(function(resolve) { |
32 frame.onload = function() { resolve(); } | 33 frame.onload = function() { resolve(); } |
33 w.location.reload(); | 34 w.location.reload(); |
34 }); | 35 }); |
35 }) | 36 }) |
36 .then(function() { | 37 .then(function() { |
37 var w = frame.contentWindow; | 38 var w = frame.contentWindow; |
38 controller = w.navigator.serviceWorker.controller; | 39 controller = w.navigator.serviceWorker.controller; |
39 assert_true(controller instanceof w.ServiceWorker, | 40 assert_true(controller instanceof w.ServiceWorker, |
40 'controller should be a ServiceWorker object upon reload')
; | 41 'controller should be a ServiceWorker object upon reload')
; |
41 | 42 |
42 // objects from separate windows should not be equal | 43 // objects from separate windows should not be equal |
43 assert_not_equals(controller, registration.active); | 44 assert_not_equals(controller, registration.active); |
44 | 45 |
45 return w.navigator.serviceWorker.getRegistration(); | 46 return w.navigator.serviceWorker.getRegistration(iframe_scope); |
46 }) | 47 }) |
47 .then(function(frameRegistration) { | 48 .then(function(frameRegistration) { |
48 assert_equals(frameRegistration.active, controller); | 49 assert_equals(frameRegistration.active, controller); |
49 frame.remove(); | 50 frame.remove(); |
50 service_worker_unregister_and_done(t, scope); | 51 service_worker_unregister_and_done(t, scope); |
51 }); | 52 }); |
52 }, 'controller is set upon reload after registration'); | 53 }, 'controller is set upon reload after registration'); |
53 </script> | 54 </script> |
54 </body> | 55 </body> |
OLD | NEW |