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')); |
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')); |
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() { | 95 (function() { |
86 function fetch_tests_from_worker(worker) { | 96 function fetch_tests_from_worker(worker) { |
87 return new Promise(function(resolve, reject) { | 97 return new Promise(function(resolve, reject) { |
88 var messageChannel = new MessageChannel(); | 98 var messageChannel = new MessageChannel(); |
89 messageChannel.port1.addEventListener('message', function(message) { | 99 messageChannel.port1.addEventListener('message', function(message) { |
90 if (message.data.type == 'complete') { | 100 if (message.data.type == 'complete') { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 HTTP_ORIGIN: 'http://' + ORIGINAL_HOST + ':' + HTTP_PORT, | 167 HTTP_ORIGIN: 'http://' + ORIGINAL_HOST + ':' + HTTP_PORT, |
158 HTTPS_ORIGIN: 'https://' + ORIGINAL_HOST + ':' + HTTPS_PORT, | 168 HTTPS_ORIGIN: 'https://' + ORIGINAL_HOST + ':' + HTTPS_PORT, |
159 HTTP_REMOTE_ORIGIN: 'http://' + REMOTE_HOST + ':' + HTTP_PORT, | 169 HTTP_REMOTE_ORIGIN: 'http://' + REMOTE_HOST + ':' + HTTP_PORT, |
160 HTTPS_REMOTE_ORIGIN: 'https://' + REMOTE_HOST + ':' + HTTPS_PORT | 170 HTTPS_REMOTE_ORIGIN: 'https://' + REMOTE_HOST + ':' + HTTPS_PORT |
161 }; | 171 }; |
162 } | 172 } |
163 | 173 |
164 function base_path() { | 174 function base_path() { |
165 return location.pathname.replace(/\/[^\/]*$/, '/'); | 175 return location.pathname.replace(/\/[^\/]*$/, '/'); |
166 } | 176 } |
OLD | NEW |