Chromium Code Reviews| 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) { |
|
nhiroki
2015/09/01 04:06:44
nit: can you move |test| to the first argument to
| |
| 192 return test_login(test, 'http://127.0.0.1:8000', | 192 var suffix = (local.indexOf("https") != -1) ? "s": ""; |
| 193 'username1', 'password1', 'cookie1') | 193 return test_login(test, local, 'username1' + suffix, 'password1' + suffix, |
| 194 'cookie1') | |
| 194 .then(function() { | 195 .then(function() { |
| 195 return test_login(test, 'http://localhost:8000', | 196 return test_login(test, remote, 'username2' + suffix, |
| 196 'username2', 'password2', 'cookie2'); | 197 'password2' + suffix, 'cookie2'); |
| 197 }); | 198 }); |
| 198 } | 199 } |
| 199 | 200 |
| 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 | 201 // Helper for testing with ServiceWorkerRegistration objects. Compares simple |
| 210 // attributes defined on the interfaces. | 202 // attributes defined on the interfaces. |
| 211 function assert_registration_equals(actual, expected, description) { | 203 function assert_registration_equals(actual, expected, description) { |
| 212 assert_class_string(actual, 'ServiceWorkerRegistration', description); | 204 assert_class_string(actual, 'ServiceWorkerRegistration', description); |
| 213 ['scope', 'installing', 'waiting', 'active'].forEach(function(attribute) { | 205 ['scope', 'installing', 'waiting', 'active'].forEach(function(attribute) { |
| 214 assert_equals(actual[attribute], expected[attribute], | 206 assert_equals(actual[attribute], expected[attribute], |
| 215 description + ' Attributes differ: ' + attribute + '.'); | 207 description + ' Attributes differ: ' + attribute + '.'); |
| 216 }); | 208 }); |
| 217 } | 209 } |
| 218 | 210 |
| 219 // Asserts that two arrays |actual| and |expected| contain the same set of | 211 // Asserts that two arrays |actual| and |expected| contain the same set of |
| 220 // ServiceWorkerRegistration as determined by assert_registration_equals(). The | 212 // ServiceWorkerRegistration as determined by assert_registration_equals(). The |
| 221 // corresponding elements must occupy corresponding indices in their respective | 213 // corresponding elements must occupy corresponding indices in their respective |
| 222 // arrays. | 214 // arrays. |
| 223 function assert_registration_array_equals(actual, expected, description) { | 215 function assert_registration_array_equals(actual, expected, description) { |
| 224 assert_true(Array.isArray(actual), description); | 216 assert_true(Array.isArray(actual), description); |
| 225 assert_equals(actual.length, expected.length, description); | 217 assert_equals(actual.length, expected.length, description); |
| 226 actual.forEach(function(value, index) { | 218 actual.forEach(function(value, index) { |
| 227 assert_registration_equals(value, expected[index], | 219 assert_registration_equals(value, expected[index], |
| 228 description + ' : object[' + index + ']'); | 220 description + ' : object[' + index + ']'); |
| 229 }); | 221 }); |
| 230 } | 222 } |
| OLD | NEW |