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 if (!registration || registration.unregister == undefined) { | 69 return new Promise(test.step_func(function(resolve) { |
70 return Promise.reject(new Error( | 70 registration.addEventListener('updatefound', test.step_func(function() { |
71 'wait_for_update must be passed a ServiceWorkerRegistration')); | 71 resolve(registration.installing); |
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 })); | |
78 })); | 73 })); |
79 } | 74 } |
80 | 75 |
81 function wait_for_state(test, worker, state) { | 76 function wait_for_state(test, worker, state) { |
82 if (!worker || worker.state == undefined) { | 77 return new Promise(test.step_func(function(resolve) { |
83 return Promise.reject(new Error( | 78 worker.addEventListener('statechange', test.step_func(function() { |
84 'wait_for_state must be passed a ServiceWorker')); | 79 if (worker.state === state) |
85 } | 80 resolve(state); |
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); | |
91 })); | 81 })); |
92 })); | 82 })); |
93 } | 83 } |
94 | 84 |
95 (function() { | 85 (function() { |
96 function fetch_tests_from_worker(worker) { | 86 function fetch_tests_from_worker(worker) { |
97 return new Promise(function(resolve, reject) { | 87 return new Promise(function(resolve, reject) { |
98 var messageChannel = new MessageChannel(); | 88 var messageChannel = new MessageChannel(); |
99 messageChannel.port1.addEventListener('message', function(message) { | 89 messageChannel.port1.addEventListener('message', function(message) { |
100 if (message.data.type == 'complete') { | 90 if (message.data.type == 'complete') { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 HTTP_ORIGIN: 'http://' + ORIGINAL_HOST + ':' + HTTP_PORT, | 157 HTTP_ORIGIN: 'http://' + ORIGINAL_HOST + ':' + HTTP_PORT, |
168 HTTPS_ORIGIN: 'https://' + ORIGINAL_HOST + ':' + HTTPS_PORT, | 158 HTTPS_ORIGIN: 'https://' + ORIGINAL_HOST + ':' + HTTPS_PORT, |
169 HTTP_REMOTE_ORIGIN: 'http://' + REMOTE_HOST + ':' + HTTP_PORT, | 159 HTTP_REMOTE_ORIGIN: 'http://' + REMOTE_HOST + ':' + HTTP_PORT, |
170 HTTPS_REMOTE_ORIGIN: 'https://' + REMOTE_HOST + ':' + HTTPS_PORT | 160 HTTPS_REMOTE_ORIGIN: 'https://' + REMOTE_HOST + ':' + HTTPS_PORT |
171 }; | 161 }; |
172 } | 162 } |
173 | 163 |
174 function base_path() { | 164 function base_path() { |
175 return location.pathname.replace(/\/[^\/]*$/, '/'); | 165 return location.pathname.replace(/\/[^\/]*$/, '/'); |
176 } | 166 } |
OLD | NEW |