OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <title>Service Worker: CORS XHR of fetch()</title> | 2 <title>Service Worker: CORS XHR of 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?pipe=sub"></script> | 5 <script src="resources/test-helpers.js?pipe=sub"></script> |
| 6 <body> |
6 <script> | 7 <script> |
7 async_test(function(t) { | 8 async_test(function(t) { |
| 9 var login1 = |
| 10 test_login(t, 'http://127.0.0.1:8000', 'username1', 'password1'); |
| 11 var login2 = |
| 12 test_login(t, 'http://localhost:8000', 'username2', 'password2'); |
8 var SCOPE = 'resources/fetch-cors-xhr-iframe.html'; | 13 var SCOPE = 'resources/fetch-cors-xhr-iframe.html'; |
9 var SCRIPT = 'resources/fetch-rewrite-worker.js'; | 14 var SCRIPT = 'resources/fetch-rewrite-worker.js'; |
10 var host_info = get_host_info(); | 15 var host_info = get_host_info(); |
11 service_worker_unregister_and_register(t, SCRIPT, SCOPE) | 16 |
| 17 Promise.all([login1, login2]) |
| 18 .then(function() { |
| 19 return service_worker_unregister_and_register(t, SCRIPT, SCOPE); |
| 20 }) |
12 .then(function(registration) { | 21 .then(function(registration) { |
13 return wait_for_update(t, registration); | 22 return wait_for_update(t, registration); |
14 }) | 23 }) |
15 .then(function(sw) { | 24 .then(function(sw) { |
16 return wait_for_state(t, sw, 'activated'); | 25 return wait_for_state(t, sw, 'activated'); |
17 }) | 26 }) |
18 .then(function() { return with_iframe(SCOPE); }) | 27 .then(function() { return with_iframe(SCOPE); }) |
19 .then(function(frame) { | 28 .then(function(frame) { |
20 return new Promise(function(resolve, reject) { | 29 return new Promise(function(resolve, reject) { |
21 var channel = new MessageChannel(); | 30 var channel = new MessageChannel(); |
22 channel.port1.onmessage = t.step_func(function(e) { | 31 channel.port1.onmessage = t.step_func(function(e) { |
23 assert_equals(e.data.results, 'finish'); | 32 assert_equals(e.data.results, 'finish'); |
| 33 unload_iframe(frame); |
24 service_worker_unregister_and_done(t, SCOPE); | 34 service_worker_unregister_and_done(t, SCOPE); |
25 }); | 35 }); |
26 frame.contentWindow.postMessage({}, | 36 frame.contentWindow.postMessage({}, |
27 [channel.port2], | 37 [channel.port2], |
28 host_info['HTTP_ORIGIN']); | 38 host_info['HTTP_ORIGIN']); |
29 }); | 39 }); |
30 }) | 40 }) |
31 .catch(unreached_rejection(t)); | 41 .catch(unreached_rejection(t)); |
32 }, 'Verify CORS XHR of fetch() in a Service Worker'); | 42 }, 'Verify CORS XHR of fetch() in a Service Worker'); |
33 </script> | 43 </script> |
| 44 </body> |
OLD | NEW |