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 // Can only be used with a worker that installs successfully, since it | 3 // Can only be used with a worker that installs successfully, since it |
| 4 // first registers to acquire a ServiceWorkerRegistration object to | 4 // first registers to acquire a ServiceWorkerRegistration object to |
| 5 // unregister. | 5 // unregister. |
| 6 // FIXME: Use getRegistration() when implemented. | 6 // FIXME: Use getRegistration() when implemented. |
| 7 function service_worker_unregister_and_register(test, url, scope) { | 7 function service_worker_unregister_and_register(test, url, scope) { |
| 8 if (!scope || scope.length == 0) | 8 if (!scope || scope.length == 0) |
| 9 return Promise.reject(new Error('tests must define a scope')); | 9 return Promise.reject(new Error('tests must define a scope')); |
| 10 | 10 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 59 iframe.src = ''; | 59 iframe.src = ''; |
| 60 iframe.remove(); | 60 iframe.remove(); |
| 61 return saw_unload; | 61 return saw_unload; |
| 62 } | 62 } |
| 63 | 63 |
| 64 function normalizeURL(url) { | 64 function normalizeURL(url) { |
| 65 return new URL(url, document.location).toString().replace(/#.*$/, ''); | 65 return new URL(url, document.location).toString().replace(/#.*$/, ''); |
| 66 } | 66 } |
| 67 | 67 |
| 68 function wait_for_update(test, registration) { | 68 function wait_for_update(test, registration) { |
| 69 return new Promise(test.step_func(function(resolve) { | 69 if (!registration || registration.unregister == undefined) { |
| 70 registration.addEventListener('updatefound', test.step_func(function() { | 70 return Promise.reject(new Error( |
| 71 resolve(registration.installing); | 71 'wait_for_update must be passed a ServiceWorkerRegistration')); |
|
michaeln
2014/09/12 00:37:20
ditto
horo
2014/09/12 01:16:32
Done.
| |
| 72 })); | 72 } |
| 73 | |
| 74 return new Promise(test.step_func(function(resolve) { | |
| 75 registration.addEventListener('updatefound', test.step_func(function() { | |
| 76 resolve(registration.installing); | |
| 77 })); | |
| 73 })); | 78 })); |
| 74 } | 79 } |
| 75 | 80 |
| 76 function wait_for_state(test, worker, state) { | 81 function wait_for_state(test, worker, state) { |
| 77 return new Promise(test.step_func(function(resolve) { | 82 if (!worker || worker.state == undefined) { |
| 78 worker.addEventListener('statechange', test.step_func(function() { | 83 return Promise.reject(new Error( |
| 79 if (worker.state === state) | 84 'wait_for_state must be passed a ServiceWorker')); |
|
michaeln
2014/09/12 00:37:20
nit: 2 more spaces
horo
2014/09/12 01:16:33
Done.
| |
| 80 resolve(state); | 85 } |
| 86 | |
| 87 return new Promise(test.step_func(function(resolve) { | |
| 88 worker.addEventListener('statechange', test.step_func(function() { | |
| 89 if (worker.state === state) | |
| 90 resolve(state); | |
| 81 })); | 91 })); |
| 82 })); | 92 })); |
| 83 } | 93 } |
| 84 | 94 |
| 85 function wait_for_activated(test, registration) { | 95 function wait_for_activated(test, registration) { |
| 86 var expected_state = 'activated'; | 96 var expected_state = 'activated'; |
| 87 if (registration.active) { | 97 if (registration.active) { |
| 88 if (registration.active.state === expected_state) | 98 if (registration.active.state === expected_state) |
| 89 return Promise.resolve(registration.active); | 99 return Promise.resolve(registration.active); |
| 90 else | 100 else |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 175 HTTPS_ORIGIN: 'https://' + ORIGINAL_HOST + ':' + HTTPS_PORT, | 185 HTTPS_ORIGIN: 'https://' + ORIGINAL_HOST + ':' + HTTPS_PORT, |
| 176 HTTP_REMOTE_ORIGIN: 'http://' + REMOTE_HOST + ':' + HTTP_PORT, | 186 HTTP_REMOTE_ORIGIN: 'http://' + REMOTE_HOST + ':' + HTTP_PORT, |
| 177 HTTPS_REMOTE_ORIGIN: 'https://' + REMOTE_HOST + ':' + HTTPS_PORT, | 187 HTTPS_REMOTE_ORIGIN: 'https://' + REMOTE_HOST + ':' + HTTPS_PORT, |
| 178 UNAUTHENTICATED_ORIGIN: 'http://' + UNAUTHENTICATED_HOST + ':' + HTTP_PO RT | 188 UNAUTHENTICATED_ORIGIN: 'http://' + UNAUTHENTICATED_HOST + ':' + HTTP_PO RT |
| 179 }; | 189 }; |
| 180 } | 190 } |
| 181 | 191 |
| 182 function base_path() { | 192 function base_path() { |
| 183 return location.pathname.replace(/\/[^\/]*$/, '/'); | 193 return location.pathname.replace(/\/[^\/]*$/, '/'); |
| 184 } | 194 } |
| OLD | NEW |