| 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 function service_worker_unregister_and_register(test, url, scope) { | 3 function service_worker_unregister_and_register(test, url, scope) { |
| 4 if (!scope || scope.length == 0) | 4 if (!scope || scope.length == 0) |
| 5 return Promise.reject(new Error('tests must define a scope')); | 5 return Promise.reject(new Error('tests must define a scope')); |
| 6 | 6 |
| 7 var options = { scope: scope }; | 7 var options = { scope: scope }; |
| 8 return service_worker_unregister(test, scope) | 8 return service_worker_unregister(test, scope) |
| 9 .then(function() { | 9 .then(function() { |
| 10 return navigator.serviceWorker.register(url, options); | 10 return navigator.serviceWorker.register(url, options); |
| 11 }) | 11 }) |
| 12 .catch(unreached_rejection(test, | 12 .catch(unreached_rejection(test, |
| 13 'unregister and register should not fail')); | 13 'unregister and register should not fail')); |
| 14 } | 14 } |
| 15 | 15 |
| 16 function service_worker_unregister(test, documentUrl) { | 16 function service_worker_unregister(test, documentUrl) { |
| 17 return navigator.serviceWorker.getRegistration(documentUrl) | 17 return navigator.serviceWorker.getRegistration(documentUrl) |
| 18 .then(function(registration) { | 18 .then(function(registration) { |
| 19 if (registration) | 19 if (registration) |
| 20 return registration.unregister(); | 20 return registration.unregister(); |
| 21 }) | 21 }) |
| 22 .catch(unreached_rejection(test, 'unregister should not fail')); | 22 .catch(unreached_rejection(test, 'unregister should not fail')); |
| 23 } | 23 } |
| 24 | 24 |
| 25 function service_worker_unregister_and_done(test, scope) { | 25 function service_worker_unregister_and_done(test, scope) { |
| 26 return service_worker_unregister(test, scope) | 26 return service_worker_unregister(test, scope) |
| 27 .then(test.done.bind(test)); | 27 .then(test.done.bind(test)); |
| 28 } | 28 } |
| 29 | 29 |
| 30 function unreached_fulfillment(test, prefix) { |
| 31 return test.step_func(function(result) { |
| 32 var error_prefix = prefix || 'unexpected fulfillment'; |
| 33 assert_unreached(error_prefix + ': ' + result); |
| 34 }); |
| 35 } |
| 36 |
| 30 // Rejection-specific helper that provides more details | 37 // Rejection-specific helper that provides more details |
| 31 function unreached_rejection(test, prefix) { | 38 function unreached_rejection(test, prefix) { |
| 32 return test.step_func(function(error) { | 39 return test.step_func(function(error) { |
| 33 var reason = error.message || error.name || error; | 40 var reason = error.message || error.name || error; |
| 34 var error_prefix = prefix || 'unexpected rejection'; | 41 var error_prefix = prefix || 'unexpected rejection'; |
| 35 assert_unreached(error_prefix + ': ' + reason); | 42 assert_unreached(error_prefix + ': ' + reason); |
| 36 }); | 43 }); |
| 37 } | 44 } |
| 38 | 45 |
| 39 // Adds an iframe to the document and returns a promise that resolves to the | 46 // Adds an iframe to the document and returns a promise that resolves to the |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 } | 213 } |
| 207 | 214 |
| 208 function login_https(test) { | 215 function login_https(test) { |
| 209 return test_login(test, 'https://127.0.0.1:8443', | 216 return test_login(test, 'https://127.0.0.1:8443', |
| 210 'username1s', 'password1s', 'cookie1') | 217 'username1s', 'password1s', 'cookie1') |
| 211 .then(function() { | 218 .then(function() { |
| 212 return test_login(test, 'https://localhost:8443', | 219 return test_login(test, 'https://localhost:8443', |
| 213 'username2s', 'password2s', 'cookie2'); | 220 'username2s', 'password2s', 'cookie2'); |
| 214 }); | 221 }); |
| 215 } | 222 } |
| OLD | NEW |