OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <title>Service Worker: fetch()</title> | 2 <title>Service Worker: fetch()</title> |
3 <script src="../resources/testharness.js"></script> | 3 <script src="../resources/testharness.js"></script> |
4 <script src="../resources/testharnessreport.js"></script> | 4 <script src="../resources/testharnessreport.js"></script> |
5 <script src="resources/test-helpers.js"></script> | 5 <script src="resources/test-helpers.js"></script> |
6 <body> | 6 <body> |
7 <script> | 7 <script> |
8 var SCOPE = 'resources/fetch-access-control-iframe.html'; | 8 var SCOPE = 'resources/fetch-access-control-iframe.html'; |
9 var BASE_URL = 'http://127.0.0.1:8000/serviceworker/resources/fetch-access-contr
ol.php?'; | 9 var BASE_URL = 'http://127.0.0.1:8000/serviceworker/resources/fetch-access-contr
ol.php?'; |
10 var OTHER_BASE_URL = 'http://localhost:8000/serviceworker/resources/fetch-access
-control.php?'; | 10 var OTHER_BASE_URL = 'http://localhost:8000/serviceworker/resources/fetch-access
-control.php?'; |
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 [OTHER_BASE_URL + 'Auth&mode=cors&credentials=include&ACAOrigin=http://127.0.0
.1:8000&ACACredentials=true', | 481 [OTHER_BASE_URL + 'Auth&mode=cors&credentials=include&ACAOrigin=http://127.0.0
.1:8000&ACACredentials=true', |
482 [fetchResolved, hasBody], [authCheck2]], | 482 [fetchResolved, hasBody], [authCheck2]], |
483 | 483 |
484 // Redirect | 484 // Redirect |
485 // FIXME: Currently we don't support redirect in Fech() API. | 485 // FIXME: Currently we don't support redirect in Fech() API. |
486 [REDIRECT_URL + encodeURIComponent(BASE_URL), | 486 [REDIRECT_URL + encodeURIComponent(BASE_URL), |
487 [fetchRejected]], | 487 [fetchRejected]], |
488 [REDIRECT_URL + encodeURIComponent(OTHER_BASE_URL), | 488 [REDIRECT_URL + encodeURIComponent(OTHER_BASE_URL), |
489 [fetchRejected]] | 489 [fetchRejected]] |
490 ]; | 490 ]; |
491 | |
492 function login(test, origin, username, password) { | |
493 return new Promise(function(resolve, reject) { | |
494 with_iframe( | |
495 origin + | |
496 '/serviceworker/resources/fetch-access-control-login.html') | |
497 .then(test.step_func(function(frame) { | |
498 var channel = new MessageChannel(); | |
499 channel.port1.onmessage = test.step_func(function() { | |
500 resolve(); | |
501 }); | |
502 frame.contentWindow.postMessage( | |
503 {username: username, password: password}, | |
504 [channel.port2], origin); | |
505 })); | |
506 }); | |
507 } | |
508 | 491 |
509 var test = async_test('Verify access control of fetch() in a Service Worker'); | 492 var test = async_test('Verify access control of fetch() in a Service Worker'); |
510 test.step(function() { | 493 test.step(function() { |
511 var login1 = login(test, 'http://127.0.0.1:8000', 'username1', 'password1'); | 494 var login1 = |
512 var login2 = login(test, 'http://localhost:8000', 'username2', 'password2'); | 495 test_login(test, 'http://127.0.0.1:8000', 'username1', 'password1'); |
| 496 var login2 = |
| 497 test_login(test, 'http://localhost:8000', 'username2', 'password2'); |
513 var workerScript = 'resources/fetch-access-control-worker.js'; | 498 var workerScript = 'resources/fetch-access-control-worker.js'; |
514 var worker = undefined; | 499 var worker = undefined; |
515 var frameWindow = {}; | 500 var frameWindow = {}; |
516 var counter = 0; | 501 var counter = 0; |
517 window.addEventListener('message', test.step_func(onMessage), false); | 502 window.addEventListener('message', test.step_func(onMessage), false); |
518 | 503 |
519 Promise.all([login1, login2]) | 504 Promise.all([login1, login2]) |
520 .then(function() { | 505 .then(function() { |
521 return service_worker_unregister_and_register(test, | 506 return service_worker_unregister_and_register(test, |
522 workerScript, | 507 workerScript, |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
596 })) | 581 })) |
597 .then(test.step_func(function() { | 582 .then(test.step_func(function() { |
598 frameWindow.postMessage( | 583 frameWindow.postMessage( |
599 {url: TEST_TARGETS[counter][0]}, | 584 {url: TEST_TARGETS[counter][0]}, |
600 IFRAME_ORIGIN); | 585 IFRAME_ORIGIN); |
601 })); | 586 })); |
602 } | 587 } |
603 }); | 588 }); |
604 </script> | 589 </script> |
605 </body> | 590 </body> |
OLD | NEW |