OLD | NEW |
---|---|
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <script src="../resources/testharness.js"></script> | 2 <script src="../resources/testharness.js"></script> |
3 <script src="../resources/testharnessreport.js"></script> | 3 <script src="../resources/testharnessreport.js"></script> |
4 <script src="resources/test-helpers.js"></script> | 4 <script src="resources/test-helpers.js"></script> |
5 <script> | 5 <script> |
6 var worker_url = 'resources/simple-intercept-worker.js'; | 6 var worker_url = 'resources/simple-intercept-worker.js'; |
7 | 7 |
8 async_test(function(t) { | 8 async_test(function(t) { |
9 var scope = | 9 var scope = |
10 'resources/unregister-controller-page.html?load-before-unregister'; | 10 'resources/unregister-controller-page.html?load-before-unregister'; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
61 'document should not have a controller'); | 61 'document should not have a controller'); |
62 return frame_window.fetch_url('simple.txt'); | 62 return frame_window.fetch_url('simple.txt'); |
63 }) | 63 }) |
64 .then(function(response) { | 64 .then(function(response) { |
65 assert_equals(response, 'a simple text file\n', | 65 assert_equals(response, 'a simple text file\n', |
66 'requests should not be intercepted'); | 66 'requests should not be intercepted'); |
67 t.done(); | 67 t.done(); |
68 }) | 68 }) |
69 .catch(unreached_rejection(t)); | 69 .catch(unreached_rejection(t)); |
70 }, 'Unregister prevents control of subsequent navigations'); | 70 }, 'Unregister prevents control of subsequent navigations'); |
71 | |
72 async_test(function(t) { | |
73 var scope = | |
74 'resources/unregister-controller-page.html?unregister-then-register'; | |
75 var worker; | |
76 var controller; | |
77 var iframe; | |
78 | |
79 service_worker_unregister_and_register(t, worker_url, scope) | |
80 .then(function(registered_worker) { | |
81 worker = registered_worker; | |
82 return wait_for_state(t, worker, 'activated'); | |
83 }) | |
84 .then(function() { | |
85 return with_iframe(scope); | |
86 }) | |
87 .then(function(frame) { | |
88 iframe = frame; | |
89 var w = iframe.contentWindow; | |
90 controller = w.navigator.serviceWorker.controller; | |
91 assert_true(controller instanceof w.ServiceWorker, | |
92 'document should load with a controller'); | |
93 return navigator.serviceWorker.unregister(scope); | |
94 }) | |
95 .then(function() { | |
96 return navigator.serviceWorker.register(worker_url, { scope: scope }); | |
97 }) | |
98 .then(function(registered_worker) { | |
99 assert_equals(registered_worker, worker, | |
100 'register should resolve to controller'); | |
101 assert_equals(registered_worker.state, 'activated', | |
102 'controller should be activated'); | |
103 var sawUnload = new Promise(function(resolve) { | |
104 iframe.contentWindow.addEventListener('unload', function() { | |
105 resolve(); | |
106 }); | |
107 }); | |
108 iframe.src = ''; | |
109 iframe.remove(); | |
110 iframe = null; | |
111 return sawUnload; | |
112 }) | |
113 .then(function() { | |
114 return with_iframe(scope); | |
115 }) | |
116 .then(function(frame) { | |
117 var w = frame.contentWindow; | |
118 assert_true( | |
119 w.navigator.serviceWorker.controller instanceof w.ServiceWorker, | |
120 'document should load with a controller'); | |
121 // FIXME: Failing expectation. | |
falken
2014/07/28 12:23:23
I think this would fail regardless of unregister.
falken
2014/07/28 12:24:51
Actually, my expectation was not right. The window
| |
122 assert_not_equals( | |
123 w.navigator.serviceWorker.controller, controller, | |
124 'controller should be the same as the previous document\'s'); | |
125 return w.fetch_url('simple.txt'); | |
126 }) | |
127 .then(function(response) { | |
128 assert_equals(response, 'intercepted by service worker', | |
129 'controller should intercept requests'); | |
130 }) | |
131 .then(function() { | |
132 service_worker_unregister_and_done(t, scope); | |
133 }) | |
134 .catch(unreached_rejection(t)); | |
135 }, 'Unregister is cancelable by register'); | |
71 </script> | 136 </script> |
OLD | NEW |