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') | 17 'unregister and register should not fail')); |
falken
2014/08/18 05:01:06
Added this error message to aid debugging.
| |
14 ); | |
15 } | 18 } |
16 | 19 |
17 function service_worker_unregister_and_done(test, scope) { | 20 function service_worker_unregister_and_done(test, scope) { |
18 return navigator.serviceWorker.unregister(scope).then( | 21 return navigator.serviceWorker.unregister(scope).then( |
19 test.done.bind(test), | 22 test.done.bind(test), |
20 unreached_rejection(test, 'Unregister should not fail')); | 23 unreached_rejection(test, 'unregister should not fail')); |
21 } | 24 } |
22 | 25 |
23 // Rejection-specific helper that provides more details | 26 // Rejection-specific helper that provides more details |
24 function unreached_rejection(test, prefix) { | 27 function unreached_rejection(test, prefix) { |
25 return test.step_func(function(error) { | 28 return test.step_func(function(error) { |
26 var reason = error.message || error.name || error; | 29 var reason = error.message || error.name || error; |
27 var error_prefix = prefix || 'unexpected rejection'; | 30 var error_prefix = prefix || 'unexpected rejection'; |
28 assert_unreached(error_prefix + ': ' + reason); | 31 assert_unreached(error_prefix + ': ' + reason); |
29 }); | 32 }); |
30 } | 33 } |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
151 HTTP_ORIGIN: 'http://' + ORIGINAL_HOST + ':' + HTTP_PORT, | 154 HTTP_ORIGIN: 'http://' + ORIGINAL_HOST + ':' + HTTP_PORT, |
152 HTTPS_ORIGIN: 'https://' + ORIGINAL_HOST + ':' + HTTPS_PORT, | 155 HTTPS_ORIGIN: 'https://' + ORIGINAL_HOST + ':' + HTTPS_PORT, |
153 HTTP_REMOTE_ORIGIN: 'http://' + REMOTE_HOST + ':' + HTTP_PORT, | 156 HTTP_REMOTE_ORIGIN: 'http://' + REMOTE_HOST + ':' + HTTP_PORT, |
154 HTTPS_REMOTE_ORIGIN: 'https://' + REMOTE_HOST + ':' + HTTPS_PORT | 157 HTTPS_REMOTE_ORIGIN: 'https://' + REMOTE_HOST + ':' + HTTPS_PORT |
155 }; | 158 }; |
156 } | 159 } |
157 | 160 |
158 function base_path() { | 161 function base_path() { |
159 return location.pathname.replace(/\/[^\/]*$/, '/'); | 162 return location.pathname.replace(/\/[^\/]*$/, '/'); |
160 } | 163 } |
OLD | NEW |