| 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); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 }); | 59 }); |
| 60 iframe.src = ''; | 60 iframe.src = ''; |
| 61 iframe.remove(); | 61 iframe.remove(); |
| 62 return saw_unload; | 62 return saw_unload; |
| 63 } | 63 } |
| 64 | 64 |
| 65 function normalizeURL(url) { | 65 function normalizeURL(url) { |
| 66 return new URL(url, document.location).toString().replace(/#.*$/, ''); | 66 return new URL(url, document.location).toString().replace(/#.*$/, ''); |
| 67 } | 67 } |
| 68 | 68 |
| 69 function get_newest_worker(registration) { | |
| 70 if (!registration) { | |
| 71 return Promise.reject(new Error( | |
| 72 'get_newest_worker must be passed a ServiceWorkerRegistration')); | |
| 73 } | |
| 74 if (registration.installing) | |
| 75 return Promise.resolve(registration.installing); | |
| 76 if (registration.waiting) | |
| 77 return Promise.resolve(registration.waiting); | |
| 78 if (registration.active) | |
| 79 return Promise.resolve(registration.active); | |
| 80 return Promise.reject(new Error( | |
| 81 'registration must have at least one version')); | |
| 82 } | |
| 83 | |
| 84 function wait_for_update(test, registration) { | 69 function wait_for_update(test, registration) { |
| 85 if (!registration || registration.unregister == undefined) { | 70 if (!registration || registration.unregister == undefined) { |
| 86 return Promise.reject(new Error( | 71 return Promise.reject(new Error( |
| 87 'wait_for_update must be passed a ServiceWorkerRegistration')); | 72 'wait_for_update must be passed a ServiceWorkerRegistration')); |
| 88 } | 73 } |
| 89 | 74 |
| 90 return new Promise(test.step_func(function(resolve) { | 75 return new Promise(test.step_func(function(resolve) { |
| 91 registration.addEventListener('updatefound', test.step_func(function() { | 76 registration.addEventListener('updatefound', test.step_func(function() { |
| 92 resolve(registration.installing); | 77 resolve(registration.installing); |
| 93 })); | 78 })); |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 channel.port1.onmessage = test.step_func(function() { | 242 channel.port1.onmessage = test.step_func(function() { |
| 258 unload_iframe(frame).catch(function() {}); | 243 unload_iframe(frame).catch(function() {}); |
| 259 resolve(); | 244 resolve(); |
| 260 }); | 245 }); |
| 261 frame.contentWindow.postMessage( | 246 frame.contentWindow.postMessage( |
| 262 {username: username, password: password, cookie: cookie}, | 247 {username: username, password: password, cookie: cookie}, |
| 263 [channel.port2], origin); | 248 [channel.port2], origin); |
| 264 })); | 249 })); |
| 265 }); | 250 }); |
| 266 } | 251 } |
| OLD | NEW |