Chromium Code Reviews| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 56 iframe.contentWindow.addEventListener('unload', function() { | 56 iframe.contentWindow.addEventListener('unload', function() { |
| 57 resolve(); | 57 resolve(); |
| 58 }); | 58 }); |
| 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, location).toString().replace(/#.*$/, ''); |
|
falken
2015/01/19 08:45:04
nit: self.location to be clear it's global
nhiroki
2015/01/20 11:10:07
Done.
| |
| 67 } | 67 } |
| 68 | 68 |
| 69 function wait_for_update(test, registration) { | 69 function wait_for_update(test, registration) { |
| 70 if (!registration || registration.unregister == undefined) { | 70 if (!registration || registration.unregister == undefined) { |
| 71 return Promise.reject(new Error( | 71 return Promise.reject(new Error( |
| 72 'wait_for_update must be passed a ServiceWorkerRegistration')); | 72 'wait_for_update must be passed a ServiceWorkerRegistration')); |
| 73 } | 73 } |
| 74 | 74 |
| 75 return new Promise(test.step_func(function(resolve) { | 75 return new Promise(test.step_func(function(resolve) { |
| 76 registration.addEventListener('updatefound', test.step_func(function() { | 76 registration.addEventListener('updatefound', test.step_func(function() { |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 202 channel.port1.onmessage = test.step_func(function() { | 202 channel.port1.onmessage = test.step_func(function() { |
| 203 unload_iframe(frame).catch(function() {}); | 203 unload_iframe(frame).catch(function() {}); |
| 204 resolve(); | 204 resolve(); |
| 205 }); | 205 }); |
| 206 frame.contentWindow.postMessage( | 206 frame.contentWindow.postMessage( |
| 207 {username: username, password: password, cookie: cookie}, | 207 {username: username, password: password, cookie: cookie}, |
| 208 [channel.port2], origin); | 208 [channel.port2], origin); |
| 209 })); | 209 })); |
| 210 }); | 210 }); |
| 211 } | 211 } |
| OLD | NEW |