| 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_test(url, description) { | 3 function service_worker_test(url, description) { |
| 4 var t = async_test(description); | 4 var t = async_test(description); |
| 5 t.step(function() { | 5 t.step(function() { |
| 6 var scope = 'nonexistent'; | 6 var scope = 'nonexistent'; |
| 7 service_worker_unregister_and_register(t, url, scope, onRegistered); | 7 service_worker_unregister_and_register(t, url, scope, onRegistered); |
| 8 | 8 |
| 9 function onRegistered(worker) { | 9 function onRegistered(worker) { |
| 10 var messageChannel = new MessageChannel(); | 10 var messageChannel = new MessageChannel(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 return navigator.serviceWorker.register(url, options); | 27 return navigator.serviceWorker.register(url, options); |
| 28 }, | 28 }, |
| 29 unreached_rejection(test, 'Unregister should not fail') | 29 unreached_rejection(test, 'Unregister should not fail') |
| 30 ).then( | 30 ).then( |
| 31 test.step_func(onregister), | 31 test.step_func(onregister), |
| 32 unreached_rejection(test, 'Registration should not fail') | 32 unreached_rejection(test, 'Registration should not fail') |
| 33 ); | 33 ); |
| 34 } | 34 } |
| 35 | 35 |
| 36 function service_worker_unregister_and_done(test, scope) { | 36 function service_worker_unregister_and_done(test, scope) { |
| 37 navigator.serviceWorker.unregister(scope).then( | 37 return navigator.serviceWorker.unregister(scope).then( |
| 38 test.done.bind(test), | 38 test.done.bind(test), |
| 39 unreached_rejection(test, 'Unregister should not fail')); | 39 unreached_rejection(test, 'Unregister should not fail')); |
| 40 } | 40 } |
| 41 | 41 |
| 42 // Rejection-specific helper that provides more details | 42 // Rejection-specific helper that provides more details |
| 43 function unreached_rejection(test, prefix) { | 43 function unreached_rejection(test, prefix) { |
| 44 return test.step_func(function(reason) { | 44 return test.step_func(function(reason) { |
| 45 assert_unreached(prefix + ': ' + reason.name); | 45 assert_unreached(prefix + ': ' + reason.name); |
| 46 }); | 46 }); |
| 47 } | 47 } |
| 48 | 48 |
| 49 // FIXME: Clean up the iframe when the test completes. | 49 // FIXME: Clean up the iframe when the test completes. |
| 50 function with_iframe(url, f) { | 50 function with_iframe(url, f) { |
| 51 var frame = document.createElement('iframe'); | 51 return new Promise(function(resolve, reject) { |
| 52 frame.src = url; | 52 var frame = document.createElement('iframe'); |
| 53 frame.onload = function() { | 53 frame.src = url; |
| 54 f(frame); | 54 frame.onload = function() { |
| 55 }; | 55 if (f) { |
| 56 document.body.appendChild(frame); | 56 f(frame); |
| 57 } |
| 58 resolve(frame); |
| 59 }; |
| 60 document.body.appendChild(frame); |
| 61 }); |
| 57 } | 62 } |
| 58 | 63 |
| 59 function normalizeURL(url) { | 64 function normalizeURL(url) { |
| 60 return new URL(url, document.location).toString().replace(/#.*$/, ''); | 65 return new URL(url, document.location).toString().replace(/#.*$/, ''); |
| 61 } | 66 } |
| OLD | NEW |