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 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 frame.remove(); | 181 frame.remove(); |
182 resolve(); | 182 resolve(); |
183 }); | 183 }); |
184 frame.contentWindow.postMessage( | 184 frame.contentWindow.postMessage( |
185 {username: username, password: password, cookie: cookie}, | 185 {username: username, password: password, cookie: cookie}, |
186 origin, [channel.port2]); | 186 origin, [channel.port2]); |
187 })); | 187 })); |
188 }); | 188 }); |
189 } | 189 } |
190 | 190 |
191 function login(test) { | 191 function login(local, remote, test) { |
192 return test_login(test, 'http://127.0.0.1:8000', | 192 return test_login(test, local, 'username1', 'password1', 'cookie1') |
193 'username1', 'password1', 'cookie1') | |
194 .then(function() { | 193 .then(function() { |
195 return test_login(test, 'http://localhost:8000', | 194 return test_login(test, remote, 'username2', 'password2', 'cookie2'); |
196 'username2', 'password2', 'cookie2'); | |
197 }); | 195 }); |
198 } | 196 } |
199 | 197 |
200 function login_https(test) { | |
201 return test_login(test, 'https://127.0.0.1:8443', | |
202 'username1s', 'password1s', 'cookie1') | |
203 .then(function() { | |
204 return test_login(test, 'https://localhost:8443', | |
205 'username2s', 'password2s', 'cookie2'); | |
206 }); | |
207 } | |
208 | |
209 // Helper for testing with ServiceWorkerRegistration objects. Compares simple | 198 // Helper for testing with ServiceWorkerRegistration objects. Compares simple |
210 // attributes defined on the interfaces. | 199 // attributes defined on the interfaces. |
211 function assert_registration_equals(actual, expected, description) { | 200 function assert_registration_equals(actual, expected, description) { |
212 assert_class_string(actual, 'ServiceWorkerRegistration', description); | 201 assert_class_string(actual, 'ServiceWorkerRegistration', description); |
213 ['scope', 'installing', 'waiting', 'active'].forEach(function(attribute) { | 202 ['scope', 'installing', 'waiting', 'active'].forEach(function(attribute) { |
214 assert_equals(actual[attribute], expected[attribute], | 203 assert_equals(actual[attribute], expected[attribute], |
215 description + ' Attributes differ: ' + attribute + '.'); | 204 description + ' Attributes differ: ' + attribute + '.'); |
216 }); | 205 }); |
217 } | 206 } |
218 | 207 |
219 // Asserts that two arrays |actual| and |expected| contain the same set of | 208 // Asserts that two arrays |actual| and |expected| contain the same set of |
220 // ServiceWorkerRegistration as determined by assert_registration_equals(). The | 209 // ServiceWorkerRegistration as determined by assert_registration_equals(). The |
221 // corresponding elements must occupy corresponding indices in their respective | 210 // corresponding elements must occupy corresponding indices in their respective |
222 // arrays. | 211 // arrays. |
223 function assert_registration_array_equals(actual, expected, description) { | 212 function assert_registration_array_equals(actual, expected, description) { |
224 assert_true(Array.isArray(actual), description); | 213 assert_true(Array.isArray(actual), description); |
225 assert_equals(actual.length, expected.length, description); | 214 assert_equals(actual.length, expected.length, description); |
226 actual.forEach(function(value, index) { | 215 actual.forEach(function(value, index) { |
227 assert_registration_equals(value, expected[index], | 216 assert_registration_equals(value, expected[index], |
228 description + ' : object[' + index + ']'); | 217 description + ' : object[' + index + ']'); |
229 }); | 218 }); |
230 } | 219 } |
OLD | NEW |