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 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 } | 198 } |
199 | 199 |
200 function login_https(test) { | 200 function login_https(test) { |
201 return test_login(test, 'https://127.0.0.1:8443', | 201 return test_login(test, 'https://127.0.0.1:8443', |
202 'username1s', 'password1s', 'cookie1') | 202 'username1s', 'password1s', 'cookie1') |
203 .then(function() { | 203 .then(function() { |
204 return test_login(test, 'https://localhost:8443', | 204 return test_login(test, 'https://localhost:8443', |
205 'username2s', 'password2s', 'cookie2'); | 205 'username2s', 'password2s', 'cookie2'); |
206 }); | 206 }); |
207 } | 207 } |
| 208 |
| 209 // Helper for testing with ServiceWorkerRegistration objects. Compares simple |
| 210 // attributes defined on the interfaces. |
| 211 function assert_registration_equals(actual, expected, description) { |
| 212 assert_class_string(actual, 'ServiceWorkerRegistration', description); |
| 213 ['scope', 'installing', 'waiting', 'active'].forEach(function(attribute) { |
| 214 assert_equals(actual[attribute], expected[attribute], |
| 215 description + ' Attributes differ: ' + attribute + '.'); |
| 216 }); |
| 217 } |
| 218 |
| 219 // Asserts that two arrays |actual| and |expected| contain the same set of |
| 220 // ServiceWorkerRegistration as determined by assert_registration_equals(). The |
| 221 // corresponding elements must occupy corresponding indices in their respective |
| 222 // arrays. |
| 223 function assert_registration_array_equals(actual, expected, description) { |
| 224 assert_true(Array.isArray(actual), description); |
| 225 assert_equals(actual.length, expected.length, description); |
| 226 actual.forEach(function(value, index) { |
| 227 assert_registration_equals(value, expected[index], |
| 228 description + ' : object[' + index + ']'); |
| 229 }); |
| 230 } |
OLD | NEW |