| 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 | 75 |
| 76 function wait_for_state(test, worker, state) { | 76 function wait_for_state(test, worker, state) { |
| 77 return new Promise(test.step_func(function(resolve) { | 77 return new Promise(test.step_func(function(resolve) { |
| 78 worker.addEventListener('statechange', test.step_func(function() { | 78 worker.addEventListener('statechange', test.step_func(function() { |
| 79 if (worker.state === state) | 79 if (worker.state === state) |
| 80 resolve(state); | 80 resolve(state); |
| 81 })); | 81 })); |
| 82 })); | 82 })); |
| 83 } | 83 } |
| 84 | 84 |
| 85 function wait_for_activated(test, registration) { |
| 86 var expected_state = 'activated'; |
| 87 if (registration.active) { |
| 88 if (registration.active.state === expected_state) |
| 89 return Promise.resolve(registration.active); |
| 90 else |
| 91 return wait_for_state(test, registration.active, expected_state); |
| 92 } |
| 93 if (registration.waiting) |
| 94 return wait_for_state(test, registration.waiting, expected_state); |
| 95 if (registration.installing) |
| 96 return wait_for_state(test, registration.installing, expected_state); |
| 97 return Promise.reject( |
| 98 new Error('registration must have at least one version')); |
| 99 } |
| 100 |
| 85 (function() { | 101 (function() { |
| 86 function fetch_tests_from_worker(worker) { | 102 function fetch_tests_from_worker(worker) { |
| 87 return new Promise(function(resolve, reject) { | 103 return new Promise(function(resolve, reject) { |
| 88 var messageChannel = new MessageChannel(); | 104 var messageChannel = new MessageChannel(); |
| 89 messageChannel.port1.addEventListener('message', function(message) { | 105 messageChannel.port1.addEventListener('message', function(message) { |
| 90 if (message.data.type == 'complete') { | 106 if (message.data.type == 'complete') { |
| 91 synthesize_tests(message.data.tests, message.data.status); | 107 synthesize_tests(message.data.tests, message.data.status); |
| 92 resolve(); | 108 resolve(); |
| 93 } | 109 } |
| 94 }); | 110 }); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 HTTPS_ORIGIN: 'https://' + ORIGINAL_HOST + ':' + HTTPS_PORT, | 175 HTTPS_ORIGIN: 'https://' + ORIGINAL_HOST + ':' + HTTPS_PORT, |
| 160 HTTP_REMOTE_ORIGIN: 'http://' + REMOTE_HOST + ':' + HTTP_PORT, | 176 HTTP_REMOTE_ORIGIN: 'http://' + REMOTE_HOST + ':' + HTTP_PORT, |
| 161 HTTPS_REMOTE_ORIGIN: 'https://' + REMOTE_HOST + ':' + HTTPS_PORT, | 177 HTTPS_REMOTE_ORIGIN: 'https://' + REMOTE_HOST + ':' + HTTPS_PORT, |
| 162 UNAUTHENTICATED_ORIGIN: 'http://' + UNAUTHENTICATED_HOST + ':' + HTTP_PO
RT | 178 UNAUTHENTICATED_ORIGIN: 'http://' + UNAUTHENTICATED_HOST + ':' + HTTP_PO
RT |
| 163 }; | 179 }; |
| 164 } | 180 } |
| 165 | 181 |
| 166 function base_path() { | 182 function base_path() { |
| 167 return location.pathname.replace(/\/[^\/]*$/, '/'); | 183 return location.pathname.replace(/\/[^\/]*$/, '/'); |
| 168 } | 184 } |
| OLD | NEW |