Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 var SCOPE = BASE_ORIGIN + | 1 var SCOPE = BASE_ORIGIN + |
| 2 '/fetch/resources/thorough-iframe.html?' + TEST_OPTIONS; | 2 '/fetch/resources/thorough-iframe.html?' + TEST_OPTIONS; |
| 3 var IFRAME_ORIGIN = BASE_ORIGIN; | 3 var IFRAME_ORIGIN = BASE_ORIGIN; |
| 4 var BASE_URL = BASE_ORIGIN + | 4 var BASE_URL = BASE_ORIGIN + |
| 5 '/serviceworker/resources/fetch-access-control.php?'; | 5 '/serviceworker/resources/fetch-access-control.php?'; |
| 6 var OTHER_BASE_URL = OTHER_ORIGIN + | 6 var OTHER_BASE_URL = OTHER_ORIGIN + |
| 7 '/serviceworker/resources/fetch-access-control.php?'; | 7 '/serviceworker/resources/fetch-access-control.php?'; |
| 8 var BASE_URL_WITH_USERNAME = BASE_URL.replace('://', '://user@'); | 8 var BASE_URL_WITH_USERNAME = BASE_URL.replace('://', '://user@'); |
| 9 var OTHER_BASE_URL_WITH_USERNAME = OTHER_BASE_URL.replace('://', '://user@'); | 9 var OTHER_BASE_URL_WITH_USERNAME = OTHER_BASE_URL.replace('://', '://user@'); |
| 10 var BASE_URL_WITH_PASSWORD = BASE_URL.replace('://', '://user:pass@'); | 10 var BASE_URL_WITH_PASSWORD = BASE_URL.replace('://', '://user:pass@'); |
| 11 var OTHER_BASE_URL_WITH_PASSWORD = | 11 var OTHER_BASE_URL_WITH_PASSWORD = |
| 12 OTHER_BASE_URL.replace('://', '://user:pass@'); | 12 OTHER_BASE_URL.replace('://', '://user:pass@'); |
| 13 var REDIRECT_URL = BASE_ORIGIN + | 13 var REDIRECT_URL = BASE_ORIGIN + |
| 14 '/serviceworker/resources/redirect.php?Redirect='; | 14 '/serviceworker/resources/redirect.php?Redirect='; |
| 15 var OTHER_REDIRECT_URL = OTHER_ORIGIN + | 15 var OTHER_REDIRECT_URL = OTHER_ORIGIN + |
| 16 '/serviceworker/resources/redirect.php?Redirect='; | 16 '/serviceworker/resources/redirect.php?Redirect='; |
| 17 var REDIRECT_LOOP_URL = BASE_ORIGIN + | 17 var REDIRECT_LOOP_URL = BASE_ORIGIN + |
| 18 '/fetch/resources/redirect-loop.php?Redirect='; | 18 '/fetch/resources/redirect-loop.php?Redirect='; |
| 19 var OTHER_REDIRECT_LOOP_URL = OTHER_ORIGIN + | 19 var OTHER_REDIRECT_LOOP_URL = OTHER_ORIGIN + |
| 20 '/fetch/resources/redirect-loop.php?Redirect='; | 20 '/fetch/resources/redirect-loop.php?Redirect='; |
| 21 var IFRAME_URL = SCOPE; | 21 var IFRAME_URL = SCOPE; |
| 22 var WORKER_URL = BASE_ORIGIN + | 22 var WORKER_URL = BASE_ORIGIN + |
| 23 '/fetch/resources/thorough-worker.js?' + | 23 '/fetch/resources/thorough-worker.js?' + |
| 24 TEST_OPTIONS; | 24 TEST_OPTIONS; |
| 25 var EMPTY_WORKER_URL = '/fetch/resources/empty-worker.js' | |
|
hiroshige
2016/06/29 16:12:46
Do we need |BASE_ORIGIN +| before '/fetch/resource
shimazu
2016/07/04 06:31:11
Done.
| |
| 25 | 26 |
| 26 function onlyOnServiceWorkerProxiedTest(checkFuncs) { | 27 function onlyOnServiceWorkerProxiedTest(checkFuncs) { |
| 27 return []; | 28 return []; |
| 28 } | 29 } |
| 29 | 30 |
| 30 // Functions to check the result from the ServiceWorker. | 31 // Functions to check the result from the ServiceWorker. |
| 31 var checkFetchResult = function(expected, url, data) { | 32 var checkFetchResult = function(expected, url, data) { |
| 32 assert_equals(data.fetchResult, expected, url + ' should be ' + expected); | 33 assert_equals(data.fetchResult, expected, url + ' should be ' + expected); |
| 33 }; | 34 }; |
| 34 var checkFetchResponseBody = function(hasBody, url, data) { | 35 var checkFetchResponseBody = function(hasBody, url, data) { |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 166 var cookieCheckB = checkJsonpCookie.bind(this, 'cookieB'); | 167 var cookieCheckB = checkJsonpCookie.bind(this, 'cookieB'); |
| 167 var cookieCheckC = checkJsonpCookie.bind(this, 'cookieC'); | 168 var cookieCheckC = checkJsonpCookie.bind(this, 'cookieC'); |
| 168 var cookieCheckNone = checkJsonpCookie.bind(this, 'undefined'); | 169 var cookieCheckNone = checkJsonpCookie.bind(this, 'undefined'); |
| 169 | 170 |
| 170 if (location.href.indexOf('base-https') >= 0) | 171 if (location.href.indexOf('base-https') >= 0) |
| 171 authCheck1 = checkJsonpAuth.bind(this, 'username1s', 'password1s', 'cookie1'); | 172 authCheck1 = checkJsonpAuth.bind(this, 'username1s', 'password1s', 'cookie1'); |
| 172 | 173 |
| 173 if (location.href.indexOf('other-https') >= 0) | 174 if (location.href.indexOf('other-https') >= 0) |
| 174 authCheck2 = checkJsonpAuth.bind(this, 'username2s', 'password2s', 'cookie2'); | 175 authCheck2 = checkJsonpAuth.bind(this, 'username2s', 'password2s', 'cookie2'); |
| 175 | 176 |
| 177 function executeTestsFromControlledPage(test_targets) { | |
| 178 var test = async_test( | |
| 179 'Verify access control of fetch() from a controlled page'); | |
| 180 test.step(function() { | |
| 181 var worker = undefined; | |
| 182 var frameWindow = {}; | |
| 183 var counter = 0; | |
| 184 window.addEventListener('message', test.step_func(onMessage), false); | |
| 185 | |
| 186 Promise.resolve() | |
| 187 .then(function() { | |
| 188 return service_worker_unregister_and_register(test, | |
| 189 EMPTY_WORKER_URL, | |
| 190 SCOPE); | |
| 191 }) | |
| 192 .then(function(registration) { | |
| 193 worker = registration.installing; | |
| 194 return wait_for_state(test, worker, 'activated'); | |
| 195 }) | |
| 196 .then(function() { | |
| 197 return with_iframe(SCOPE); | |
| 198 }) | |
| 199 .then(function(frame) { | |
| 200 frameWindow = frame.contentWindow; | |
| 201 // Start tests. | |
| 202 loadNext(); | |
| 203 }) | |
| 204 .catch(unreached_rejection(test)); | |
| 205 | |
| 206 var resultFromIframeReceived = undefined; | |
| 207 | |
| 208 function onMessage(e) { | |
| 209 // The message is sent from thorough-iframe.html in report() | |
| 210 // which is called after fetch() is called on the iframe. | |
| 211 // e.data has the result of doFetch() but e.data.response is undefined | |
| 212 // because it cannot be cloned. | |
| 213 doCheck(test_targets[counter], e.data); | |
| 214 resultFromIframeReceived(); | |
| 215 } | |
| 216 | |
| 217 function loadNext() { | |
| 218 (new Promise(function(resolve, reject) { | |
| 219 resultFromIframeReceived = resolve; | |
| 220 })) | |
| 221 .then(test.step_func(function() { | |
| 222 ++counter; | |
| 223 if (counter === test_targets.length) { | |
| 224 service_worker_unregister_and_done(test, SCOPE); | |
| 225 } else { | |
| 226 loadNext(); | |
| 227 } | |
| 228 })); | |
| 229 Promise.resolve() | |
| 230 .then(test.step_func(function() { | |
| 231 frameWindow.postMessage({fetch: true, | |
| 232 url: test_targets[counter][0]}, | |
| 233 IFRAME_ORIGIN); | |
| 234 })); | |
| 235 } | |
| 236 }); | |
| 237 } | |
| 238 | |
| 176 function executeServiceWorkerProxiedTests(test_targets) { | 239 function executeServiceWorkerProxiedTests(test_targets) { |
| 177 var test = async_test('Verify access control of fetch() in a Service Worker'); | 240 var test = async_test('Verify access control of fetch() in a Service Worker'); |
| 178 test.step(function() { | 241 test.step(function() { |
| 179 var worker = undefined; | 242 var worker = undefined; |
| 180 var frameWindow = {}; | 243 var frameWindow = {}; |
| 181 var counter = 0; | 244 var counter = 0; |
| 182 window.addEventListener('message', test.step_func(onMessage), false); | 245 window.addEventListener('message', test.step_func(onMessage), false); |
| 183 | 246 |
| 184 Promise.resolve() | 247 Promise.resolve() |
| 185 .then(function() { | 248 .then(function() { |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 363 }); | 426 }); |
| 364 }) | 427 }) |
| 365 .catch(function(e) { | 428 .catch(function(e) { |
| 366 return Promise.resolve({fetchResult: 'rejected'}); | 429 return Promise.resolve({fetchResult: 'rejected'}); |
| 367 }); | 430 }); |
| 368 } catch (e) { | 431 } catch (e) { |
| 369 return Promise.resolve({fetchResult: 'error'}); | 432 return Promise.resolve({fetchResult: 'error'}); |
| 370 } | 433 } |
| 371 } | 434 } |
| 372 | 435 |
| 436 // Check a message returned by doFetch | |
| 437 function doCheck(test_target, message) { | |
| 438 var checks = test_target[1].concat(showComment); | |
| 439 checks.forEach(function(checkFunc) { | |
| 440 checkFunc.call(this, test_target[0], message); | |
| 441 }); | |
| 442 | |
| 443 if (test_target[2]) { | |
| 444 report_data = {}; | |
| 445 if (message.fetchResult !== 'resolved' || | |
| 446 message.body === '' || | |
| 447 400 <= message.status) { | |
| 448 report({jsonpResult: 'error'}); | |
| 449 } else { | |
| 450 eval(message.body); | |
| 451 } | |
| 452 assert_not_equals(report_data, {}, 'data should be set'); | |
| 453 | |
| 454 test_target[2].forEach(function(checkFunc) { | |
| 455 checkFunc.call(this, test_target[0], report_data); | |
| 456 }); | |
| 457 } | |
| 458 } | |
| 459 | |
| 373 var report_data = {}; | 460 var report_data = {}; |
| 374 function report(data) { | 461 function report(data) { |
| 375 report_data = data; | 462 report_data = data; |
| 376 } | 463 } |
| 377 | 464 |
| 378 function executeTest(test_target) { | 465 function executeTest(test_target) { |
| 379 if (test_target.length == 0) { | 466 if (test_target.length == 0) { |
| 380 return Promise.resolve(); | 467 return Promise.resolve(); |
| 381 } | 468 } |
| 382 return doFetch(new Request(test_target[0], | 469 return doFetch(new Request(test_target[0], |
| 383 {credentials: 'same-origin', mode: 'no-cors'})) | 470 {credentials: 'same-origin', mode: 'no-cors'})) |
| 384 .then(function(message) { | 471 .then(doCheck.bind(this, test_target)); |
| 385 var checks = test_target[1].concat(showComment); | |
| 386 checks.forEach(function(checkFunc) { | |
| 387 checkFunc.call(this, test_target[0], message); | |
| 388 }); | |
| 389 | |
| 390 if (test_target[2]) { | |
| 391 report_data = {}; | |
| 392 if (message.fetchResult !== 'resolved' || | |
| 393 message.body === '' || | |
| 394 400 <= message.status) { | |
| 395 report({jsonpResult:'error'}); | |
| 396 } else { | |
| 397 eval(message.body); | |
| 398 } | |
| 399 assert_not_equals(report_data, {}, 'data should be set'); | |
| 400 | |
| 401 test_target[2].forEach(function(checkFunc) { | |
| 402 checkFunc.call(this, test_target[0], report_data); | |
| 403 }); | |
| 404 } | |
| 405 }); | |
| 406 } | 472 } |
| 407 | 473 |
| 408 function executeTests(test_targets) { | 474 function executeTests(test_targets) { |
| 409 for (var i = 0; i < test_targets.length; ++i) { | 475 for (var i = 0; i < test_targets.length; ++i) { |
| 410 promise_test( | 476 promise_test( |
| 411 function(counter, t) { | 477 function(counter, t) { |
| 412 return executeTest(test_targets[counter]); | 478 return executeTest(test_targets[counter]); |
| 413 }.bind(this, i), | 479 }.bind(this, i), |
| 414 "executeTest-" + i); | 480 "executeTest-" + i); |
| 415 } | 481 } |
| 416 } | 482 } |
| OLD | NEW |