OLD | NEW |
1 // Adapter for testharness.js-style tests with Service Workers | 1 // Adapter for testharness.js-style tests with Service Workers |
2 | 2 |
| 3 // Can only be used with a worker that installs successfully, since it |
| 4 // first registers to acquire a ServiceWorkerRegistration object to |
| 5 // unregister. |
| 6 // FIXME: Use getRegistration() when implemented. |
3 function service_worker_unregister_and_register(test, url, scope) { | 7 function service_worker_unregister_and_register(test, url, scope) { |
4 var options = scope ? { scope: scope } : {}; | 8 var options = scope ? { scope: scope } : {}; |
5 return navigator.serviceWorker.unregister(scope).then( | 9 return navigator.serviceWorker.register(url, options) |
6 test.step_func(function() { | 10 .then(function(registration) { |
7 return navigator.serviceWorker.register(url, options); | 11 return registration.unregister(); |
8 }), | 12 }) |
9 unreached_rejection(test, 'Unregister should not fail') | 13 .then(function() { |
10 ).then(test.step_func(function(worker) { | 14 return navigator.serviceWorker.register(url, options); |
11 return Promise.resolve(worker); | 15 }) |
12 }), | 16 .catch(unreached_rejection(test)); |
13 unreached_rejection(test, 'Registration should not fail') | |
14 ); | |
15 } | 17 } |
16 | 18 |
17 function service_worker_unregister_and_done(test, scope) { | 19 function service_worker_unregister_and_done(test, scope) { |
18 return navigator.serviceWorker.unregister(scope).then( | 20 return navigator.serviceWorker.unregister(scope).then( |
19 test.done.bind(test), | 21 test.done.bind(test), |
20 unreached_rejection(test, 'Unregister should not fail')); | 22 unreached_rejection(test, 'Unregister should not fail')); |
21 } | 23 } |
22 | 24 |
23 // Rejection-specific helper that provides more details | 25 // Rejection-specific helper that provides more details |
24 function unreached_rejection(test, prefix) { | 26 function unreached_rejection(test, prefix) { |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 HTTP_ORIGIN: 'http://' + ORIGINAL_HOST + ':' + HTTP_PORT, | 153 HTTP_ORIGIN: 'http://' + ORIGINAL_HOST + ':' + HTTP_PORT, |
152 HTTPS_ORIGIN: 'https://' + ORIGINAL_HOST + ':' + HTTPS_PORT, | 154 HTTPS_ORIGIN: 'https://' + ORIGINAL_HOST + ':' + HTTPS_PORT, |
153 HTTP_REMOTE_ORIGIN: 'http://' + REMOTE_HOST + ':' + HTTP_PORT, | 155 HTTP_REMOTE_ORIGIN: 'http://' + REMOTE_HOST + ':' + HTTP_PORT, |
154 HTTPS_REMOTE_ORIGIN: 'https://' + REMOTE_HOST + ':' + HTTPS_PORT | 156 HTTPS_REMOTE_ORIGIN: 'https://' + REMOTE_HOST + ':' + HTTPS_PORT |
155 }; | 157 }; |
156 } | 158 } |
157 | 159 |
158 function base_path() { | 160 function base_path() { |
159 return location.pathname.replace(/\/[^\/]*$/, '/'); | 161 return location.pathname.replace(/\/[^\/]*$/, '/'); |
160 } | 162 } |
OLD | NEW |