OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <script src="../resources/testharness.js"></script> | 2 <script src="../resources/testharness.js"></script> |
3 <script src="../resources/testharnessreport.js"></script> | 3 <script src="../resources/testharnessreport.js"></script> |
4 <script src="resources/test-helpers.js"></script> | 4 <script src="resources/test-helpers.js"></script> |
5 <body> | 5 <body> |
6 <script> | 6 <script> |
7 var worker = 'resources/foreign-fetch-worker.js'; | 7 function worker_for_origins(origins) { |
| 8 var worker = 'resources/foreign-fetch-worker.js?'; |
| 9 return worker + encodeURIComponent(JSON.stringify(origins)); |
| 10 } |
8 | 11 |
9 promise_test(t => { | 12 promise_test(t => { |
10 var scope = 'resources/foreign-fetch/scope'; | 13 var scope = 'resources/foreign-fetch/scope'; |
11 return service_worker_unregister_and_register(t, worker, scope) | 14 return service_worker_unregister_and_register( |
| 15 t, worker_for_origins('*'), scope) |
12 .then(r => { | 16 .then(r => { |
13 add_completion_callback(() => r.unregister()); | 17 add_completion_callback(() => r.unregister()); |
14 return wait_for_state(t, r.installing, 'activated'); | 18 return wait_for_state(t, r.installing, 'activated'); |
15 }) | 19 }) |
16 .then(() => fetch(scope + '/foo')) | 20 .then(() => fetch(scope + '/foo')) |
17 .then(response => { | 21 .then(response => { |
18 assert_equals(response.status, 404); | 22 assert_equals(response.status, 404); |
19 return fetch(scope + '/intercept/foo'); | 23 return fetch(scope + '/intercept/foo'); |
20 }) | 24 }) |
21 .then(response => response.text()) | 25 .then(response => response.text()) |
22 .then(response_text => { | 26 .then(response_text => { |
23 assert_equals(response_text, 'Foreign Fetch'); | 27 assert_equals(response_text, 'Foreign Fetch'); |
24 }); | 28 }); |
25 }, 'Service Worker intercepts fetches in scope.'); | 29 }, 'Service Worker intercepts fetches in scope with wildcard origin.'); |
| 30 |
| 31 promise_test(t => { |
| 32 var scope = 'resources/foreign-fetch/scope/match-origin'; |
| 33 return service_worker_unregister_and_register( |
| 34 t, worker_for_origins(location.origin), scope) |
| 35 .then(r => { |
| 36 add_completion_callback(() => r.unregister()); |
| 37 return wait_for_state(t, r.installing, 'activated'); |
| 38 }) |
| 39 .then(() => fetch(scope + '/intercept/foo')) |
| 40 .then(response => response.text()) |
| 41 .then(response_text => { |
| 42 assert_equals(response_text, 'Foreign Fetch'); |
| 43 }); |
| 44 }, 'Service Worker intercepts fetches in scope with explicit origin.'); |
| 45 |
| 46 promise_test(t => { |
| 47 var scope = 'resources/foreign-fetch/scope/nomatch-origin'; |
| 48 return service_worker_unregister_and_register( |
| 49 t, worker_for_origins('https://example.com'), scope) |
| 50 .then(r => { |
| 51 add_completion_callback(() => r.unregister()); |
| 52 return wait_for_state(t, r.installing, 'activated'); |
| 53 }) |
| 54 .then(() => fetch(scope + '/intercept/foo')) |
| 55 .then(response => { |
| 56 assert_equals(response.status, 404); |
| 57 }); |
| 58 }, 'Service Worker doesn\'t intercept fetches with non matching origin.'); |
| 59 |
| 60 promise_test(t => { |
| 61 var scope = 'resources/foreign-fetch/scope/origin-list'; |
| 62 return service_worker_unregister_and_register( |
| 63 t, worker_for_origins([location.origin, 'https://example.com']), scope) |
| 64 .then(r => { |
| 65 add_completion_callback(() => r.unregister()); |
| 66 return wait_for_state(t, r.installing, 'activated'); |
| 67 }) |
| 68 .then(() => fetch(scope + '/intercept/foo')) |
| 69 .then(response => response.text()) |
| 70 .then(response_text => { |
| 71 assert_equals(response_text, 'Foreign Fetch'); |
| 72 }); |
| 73 }, 'Service Worker intercepts fetches in scope with explicit origin list.'); |
| 74 |
26 </script> | 75 </script> |
27 </body> | 76 </body> |
OLD | NEW |