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('resources/foreign-fetch-helper-script.j s'); | |
horo
2016/06/30 10:12:09
nit: Wrap at 80 columns.
https://www.chromium.org
Marijn Kruisselbrink
2016/06/30 22:43:12
Done
| |
51 let channel = new MessageChannel(); | |
52 worker.port.postMessage({url: remote_url, | |
53 port: channel.port1}, | |
54 [channel.port1]); | |
55 channel.port2.onmessage = reply => resolve(reply.data); | |
56 })) | |
57 .then(response => assert_equals(response, 'Success: Foreign Fetch')); | |
58 }, 'Foreign fetch can intercept fetches made from a shared worker'); | |
59 | |
60 function fetch_from_cross_origin_worker(worker_type, origin, url) { | |
61 return with_iframe(origin + | |
62 '/serviceworker/resources/foreign-fetch-helper-iframe.html') | |
63 .then(frame => new Promise((resolve) => { | |
64 let channel = new MessageChannel(); | |
65 frame.contentWindow.postMessage({url: url, | |
66 port: channel.port1, | |
67 worker: worker_type}, | |
68 '*', [channel.port1]); | |
69 channel.port2.onmessage = reply => resolve(reply.data); | |
70 })); | |
71 } | |
72 | |
73 promise_test(t => { | |
74 var scope = 'simple.txt?basic_dedicated_insecure'; | |
75 var remote_url = | |
76 host_info.AUTHENTICATED_ORIGIN + '/serviceworker/resources/' + scope; | |
77 return install_cross_origin_worker(t, ff_worker, scope, | |
78 host_info.AUTHENTICATED_ORIGIN) | |
79 .then(() => fetch_from_cross_origin_worker('dedicated', | |
80 host_info.HTTPS_REMOTE_ORIGIN, remote_url)) | |
81 .then(response => assert_equals(response, 'Success: Foreign Fetch')) | |
82 .then(() => fetch_from_cross_origin_worker('dedicated', | |
83 host_info.UNAUTHENTICATED_ORIGIN, remote_url)) | |
84 .then(response => assert_equals(response, | |
85 'Error: TypeError: Failed to fetch')); | |
86 }, 'Service Worker does not intercept fetches from an insecure dedicated worke r.'); | |
horo
2016/06/30 10:12:09
ditto
Marijn Kruisselbrink
2016/06/30 22:43:12
Done
| |
87 | |
88 promise_test(t => { | |
89 var scope = 'simple.txt?basic_shared_insecure'; | |
90 var remote_url = | |
91 host_info.AUTHENTICATED_ORIGIN + '/serviceworker/resources/' + scope; | |
92 return install_cross_origin_worker(t, ff_worker, scope, | |
93 host_info.AUTHENTICATED_ORIGIN) | |
94 .then(() => fetch_from_cross_origin_worker('shared', | |
95 host_info.HTTPS_REMOTE_ORIGIN, remote_url)) | |
96 .then(response => assert_equals(response, 'Success: Foreign Fetch')) | |
97 .then(() => fetch_from_cross_origin_worker('shared', | |
98 host_info.UNAUTHENTICATED_ORIGIN, remote_url)) | |
99 .then(response => assert_equals(response, | |
100 'Error: TypeError: Failed to fetch')); | |
101 }, 'Service Worker does not intercept fetches from an insecure shared worker.' ); | |
horo
2016/06/30 10:12:09
ditto
Marijn Kruisselbrink
2016/06/30 22:43:12
Done
| |
102 | |
103 </script> | |
104 </body> | |
OLD | NEW |