Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(256)

Side by Side Diff: LayoutTests/http/tests/serviceworker/resources/test-helpers.js

Issue 1314123002: Remove hard-coded origins in layout tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Add ?pipe=sub and make test first parameter. Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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(test, local, remote) {
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698