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/get-host-info.js"></script> | 4 <script src="resources/get-host-info.sub.js"></script> |
5 <script src="resources/test-helpers.js"></script> | 5 <script src="resources/test-helpers.sub.js"></script> |
6 <script src="resources/foreign-fetch-helpers.js"></script> | 6 <script src="resources/foreign-fetch-helpers.js"></script> |
7 <body> | 7 <body> |
8 <script> | 8 <script> |
9 var host_info = get_host_info(); | 9 var host_info = get_host_info(); |
10 var ff_worker = 'foreign-fetch-worker.js?{}'; | 10 var ff_worker = 'foreign-fetch-worker.js?{}'; |
| 11 var resource_path = new URL('resources/', location).pathname; |
11 | 12 |
12 promise_test(t => { | 13 promise_test(t => { |
13 var ff_scope = 'simple.txt?basic_sw'; | 14 var ff_scope = 'simple.txt?basic_sw'; |
14 var worker = 'resources/foreign-fetch-helper-worker.js'; | 15 var worker = 'resources/foreign-fetch-helper-worker.js'; |
15 var scope = 'resources/simple.html?foreignfetch'; | 16 var scope = 'resources/simple.html?foreignfetch'; |
16 return install_cross_origin_worker(t, ff_worker, ff_scope) | 17 return install_cross_origin_worker(t, ff_worker, ff_scope) |
17 .then(() => service_worker_unregister_and_register(t, worker, scope)) | 18 .then(() => service_worker_unregister_and_register(t, worker, scope)) |
18 .then(r => { | 19 .then(r => { |
19 add_completion_callback(() => r.unregister()); | 20 add_completion_callback(() => r.unregister()); |
20 return wait_for_state(t, r.installing, 'activated'); | 21 return wait_for_state(t, r.installing, 'activated'); |
21 }) | 22 }) |
22 .then(() => with_iframe(scope)) | 23 .then(() => with_iframe(scope)) |
23 .then(frame => { | 24 .then(frame => { |
24 assert_equals(frame.contentDocument.body.innerText, 'Foreign Fetch'); | 25 assert_equals(frame.contentDocument.body.innerText, 'Foreign Fetch'); |
25 }); | 26 }); |
26 }, 'Foreign fetch can intercept fetches made from a service worker'); | 27 }, 'Foreign fetch can intercept fetches made from a service worker'); |
27 | 28 |
28 promise_test(t => { | 29 promise_test(t => { |
29 let scope = 'simple.txt?basic_dedicated'; | 30 let scope = 'simple.txt?basic_dedicated'; |
30 let remote_url = | 31 let remote_url = host_info.HTTPS_REMOTE_ORIGIN + resource_path + scope; |
31 host_info.HTTPS_REMOTE_ORIGIN + '/serviceworker/resources/' + scope; | |
32 return install_cross_origin_worker(t, ff_worker, scope) | 32 return install_cross_origin_worker(t, ff_worker, scope) |
33 .then(() => new Promise(resolve => { | 33 .then(() => new Promise(resolve => { |
34 let worker = new Worker('resources/foreign-fetch-helper-script.js'); | 34 let worker = new Worker('resources/foreign-fetch-helper-script.js'); |
35 let channel = new MessageChannel(); | 35 let channel = new MessageChannel(); |
36 worker.postMessage({url: remote_url, | 36 worker.postMessage({url: remote_url, |
37 port: channel.port1}, | 37 port: channel.port1}, |
38 [channel.port1]); | 38 [channel.port1]); |
39 channel.port2.onmessage = reply => resolve(reply.data); | 39 channel.port2.onmessage = reply => resolve(reply.data); |
40 })) | 40 })) |
41 .then(response => assert_equals(response, 'Success: Foreign Fetch')); | 41 .then(response => assert_equals(response, 'Success: Foreign Fetch')); |
42 }, 'Foreign fetch can intercept fetches made from a dedicated worker'); | 42 }, 'Foreign fetch can intercept fetches made from a dedicated worker'); |
43 | 43 |
44 promise_test(t => { | 44 promise_test(t => { |
45 let scope = 'simple.txt?basic_shared'; | 45 let scope = 'simple.txt?basic_shared'; |
46 let remote_url = | 46 let remote_url = host_info.HTTPS_REMOTE_ORIGIN + resource_path + scope; |
47 host_info.HTTPS_REMOTE_ORIGIN + '/serviceworker/resources/' + scope; | |
48 return install_cross_origin_worker(t, ff_worker, scope) | 47 return install_cross_origin_worker(t, ff_worker, scope) |
49 .then(() => new Promise(resolve => { | 48 .then(() => new Promise(resolve => { |
50 let worker = new SharedWorker( | 49 let worker = new SharedWorker( |
51 'resources/foreign-fetch-helper-script.js'); | 50 'resources/foreign-fetch-helper-script.js'); |
52 let channel = new MessageChannel(); | 51 let channel = new MessageChannel(); |
53 worker.port.postMessage({url: remote_url, | 52 worker.port.postMessage({url: remote_url, |
54 port: channel.port1}, | 53 port: channel.port1}, |
55 [channel.port1]); | 54 [channel.port1]); |
56 channel.port2.onmessage = reply => resolve(reply.data); | 55 channel.port2.onmessage = reply => resolve(reply.data); |
57 })) | 56 })) |
58 .then(response => assert_equals(response, 'Success: Foreign Fetch')); | 57 .then(response => assert_equals(response, 'Success: Foreign Fetch')); |
59 }, 'Foreign fetch can intercept fetches made from a shared worker'); | 58 }, 'Foreign fetch can intercept fetches made from a shared worker'); |
60 | 59 |
61 function fetch_from_cross_origin_worker(worker_type, origin, url) { | |
62 return with_iframe(origin + | |
63 '/serviceworker/resources/foreign-fetch-helper-iframe.html') | |
64 .then(frame => new Promise((resolve) => { | |
65 let channel = new MessageChannel(); | |
66 frame.contentWindow.postMessage({url: url, | |
67 port: channel.port1, | |
68 worker: worker_type}, | |
69 '*', [channel.port1]); | |
70 channel.port2.onmessage = reply => resolve(reply.data); | |
71 })); | |
72 } | |
73 | |
74 promise_test(t => { | 60 promise_test(t => { |
75 var scope = 'simple.txt?basic_dedicated_insecure'; | 61 var scope = 'simple.txt?basic_dedicated_insecure'; |
76 var remote_url = | 62 var remote_url = host_info.AUTHENTICATED_ORIGIN + resource_path + scope; |
77 host_info.AUTHENTICATED_ORIGIN + '/serviceworker/resources/' + scope; | |
78 return install_cross_origin_worker(t, ff_worker, scope, | 63 return install_cross_origin_worker(t, ff_worker, scope, |
79 host_info.AUTHENTICATED_ORIGIN) | 64 host_info.AUTHENTICATED_ORIGIN) |
80 .then(() => fetch_from_cross_origin_worker('dedicated', | 65 .then(() => fetch_from_different_origin( |
81 host_info.HTTPS_REMOTE_ORIGIN, remote_url)) | 66 host_info.HTTPS_REMOTE_ORIGIN, remote_url, 'dedicated')) |
82 .then(response => assert_equals(response, 'Success: Foreign Fetch')) | 67 .then(response => assert_equals(response, 'Success: Foreign Fetch')) |
83 .then(() => fetch_from_cross_origin_worker('dedicated', | 68 .then(() => fetch_from_different_origin( |
84 host_info.UNAUTHENTICATED_ORIGIN, remote_url)) | 69 host_info.UNAUTHENTICATED_ORIGIN, remote_url, 'dedicated')) |
85 .then(response => assert_equals(response, | 70 .then(response => assert_equals(response, |
86 'Error: TypeError: Failed to fetch')); | 71 'Error: TypeError: Failed to fetch')); |
87 }, 'Fetches from an insecure dedicated worker aren\'t intercepted.'); | 72 }, 'Fetches from an insecure dedicated worker aren\'t intercepted.'); |
88 | 73 |
89 promise_test(t => { | 74 promise_test(t => { |
90 var scope = 'simple.txt?basic_shared_insecure'; | 75 var scope = 'simple.txt?basic_shared_insecure'; |
91 var remote_url = | 76 var remote_url = host_info.AUTHENTICATED_ORIGIN + resource_path + scope; |
92 host_info.AUTHENTICATED_ORIGIN + '/serviceworker/resources/' + scope; | |
93 return install_cross_origin_worker(t, ff_worker, scope, | 77 return install_cross_origin_worker(t, ff_worker, scope, |
94 host_info.AUTHENTICATED_ORIGIN) | 78 host_info.AUTHENTICATED_ORIGIN) |
95 .then(() => fetch_from_cross_origin_worker('shared', | 79 .then(() => fetch_from_different_origin( |
96 host_info.HTTPS_REMOTE_ORIGIN, remote_url)) | 80 host_info.HTTPS_REMOTE_ORIGIN, remote_url, 'shared')) |
97 .then(response => assert_equals(response, 'Success: Foreign Fetch')) | 81 .then(response => assert_equals(response, 'Success: Foreign Fetch')) |
98 .then(() => fetch_from_cross_origin_worker('shared', | 82 .then(() => fetch_from_different_origin( |
99 host_info.UNAUTHENTICATED_ORIGIN, remote_url)) | 83 host_info.UNAUTHENTICATED_ORIGIN, remote_url, 'shared')) |
100 .then(response => assert_equals(response, | 84 .then(response => assert_equals(response, |
101 'Error: TypeError: Failed to fetch')); | 85 'Error: TypeError: Failed to fetch')); |
102 }, 'Fetches from an insecure shared worker aren\'t intercepted.'); | 86 }, 'Fetches from an insecure shared worker aren\'t intercepted.'); |
103 | |
104 </script> | 87 </script> |
105 </body> | 88 </body> |
OLD | NEW |