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