OLD | NEW |
| (Empty) |
1 <!DOCTYPE html> | |
2 <title>Service Worker: Fetch for the frame loading.</title> | |
3 <script src="../resources/testharness.js"></script> | |
4 <script src="../resources/testharnessreport.js"></script> | |
5 <script src="../resources/get-host-info.js"></script> | |
6 <script src="resources/test-helpers.js"></script> | |
7 <body> | |
8 <script> | |
9 var worker = 'resources/fetch-rewrite-worker.js'; | |
10 var path = base_path() + 'resources/fetch-access-control.php'; | |
11 var host_info = get_host_info(); | |
12 | |
13 if (window.testRunner) { | |
14 testRunner.setCanOpenWindows(); | |
15 } | |
16 | |
17 async_test(function(t) { | |
18 var scope = 'resources/fetch-frame-resource/frame-basic'; | |
19 service_worker_unregister_and_register(t, worker, scope) | |
20 .then(function(reg) { | |
21 return wait_for_state(t, reg.installing, 'activated'); | |
22 }) | |
23 .then(function() { | |
24 return with_iframe( | |
25 scope + '?url=' + | |
26 encodeURIComponent(host_info['HTTP_ORIGIN'] + path)); | |
27 }) | |
28 .then(function(frame) { | |
29 assert_equals( | |
30 frame.contentDocument.body.textContent.substr(0, 7), | |
31 'report(', | |
32 'Basic type response could be loaded in the iframe.'); | |
33 frame.remove(); | |
34 return service_worker_unregister_and_done(t, scope); | |
35 }) | |
36 .catch(unreached_rejection(t)); | |
37 }, 'Basic type response could be loaded in the iframe.'); | |
38 | |
39 async_test(function(t) { | |
40 var scope = 'resources/fetch-frame-resource/frame-cors'; | |
41 service_worker_unregister_and_register(t, worker, scope) | |
42 .then(function(reg) { | |
43 return wait_for_state(t, reg.installing, 'activated'); | |
44 }) | |
45 .then(function() { | |
46 return with_iframe( | |
47 scope + '?mode=cors&url=' + | |
48 encodeURIComponent(host_info['HTTP_REMOTE_ORIGIN'] + path + | |
49 '?ACAOrigin=' + host_info['HTTP_ORIGIN'])); | |
50 }) | |
51 .then(function(frame) { | |
52 assert_equals( | |
53 frame.contentDocument.body.textContent.substr(0, 7), | |
54 'report(', | |
55 'CORS type response could be loaded in the iframe.'); | |
56 frame.remove(); | |
57 return service_worker_unregister_and_done(t, scope); | |
58 }) | |
59 .catch(unreached_rejection(t)); | |
60 }, 'CORS type response could be loaded in the iframe.'); | |
61 | |
62 async_test(function(t) { | |
63 var scope = 'resources/fetch-frame-resource/frame-opaque'; | |
64 service_worker_unregister_and_register(t, worker, scope) | |
65 .then(function(reg) { | |
66 return wait_for_state(t, reg.installing, 'activated'); | |
67 }) | |
68 .then(function() { | |
69 var frame = document.createElement('iframe'); | |
70 frame.src = | |
71 scope + '?mode=no-cors&url=' + | |
72 encodeURIComponent(host_info['HTTP_REMOTE_ORIGIN'] + path); | |
73 document.body.appendChild(frame); | |
74 return new Promise(function(resolve) { | |
75 frame.onload = function () { resolve(frame) }; | |
76 }); | |
77 }) | |
78 .then(function(frame) { | |
79 assert_throws('SecurityError', _ => { | |
80 assert_equals(frame.contentDocument.body.textContent, ''); | |
81 }, 'Opaque response renders error page in the iframe.'); | |
82 frame.remove(); | |
83 return service_worker_unregister_and_done(t, scope); | |
84 }) | |
85 .catch(unreached_rejection(t)); | |
86 }, 'Opaque type response could not be loaded in the iframe.'); | |
87 | |
88 async_test(function(t) { | |
89 var scope = 'resources/fetch-frame-resource/window-basic'; | |
90 service_worker_unregister_and_register(t, worker, scope) | |
91 .then(function(reg) { | |
92 return wait_for_state(t, reg.installing, 'activated'); | |
93 }) | |
94 .then(function() { | |
95 return new Promise(function(resolve) { | |
96 var win = window.open( | |
97 scope + '?url=' + | |
98 encodeURIComponent(host_info['HTTP_ORIGIN'] + path)); | |
99 win.onload = function() { resolve(win); }; | |
100 }); | |
101 }) | |
102 .then(function(win) { | |
103 assert_equals( | |
104 win.document.body.textContent.substr(0, 7), | |
105 'report(', | |
106 'Basic type response could be loaded in the new window.'); | |
107 win.close(); | |
108 return service_worker_unregister_and_done(t, scope); | |
109 }) | |
110 .catch(unreached_rejection(t)); | |
111 }, 'Basic type response could be loaded in the new window.'); | |
112 | |
113 async_test(function(t) { | |
114 var scope = 'resources/fetch-frame-resource/window-cors'; | |
115 service_worker_unregister_and_register(t, worker, scope) | |
116 .then(function(reg) { | |
117 return wait_for_state(t, reg.installing, 'activated'); | |
118 }) | |
119 .then(function() { | |
120 return new Promise(function(resolve) { | |
121 var win = window.open( | |
122 scope + '?mode=cors&url=' + | |
123 encodeURIComponent(host_info['HTTP_REMOTE_ORIGIN'] + path + | |
124 '?ACAOrigin=' + host_info['HTTP_ORIGIN'])); | |
125 win.onload = function() { resolve(win); }; | |
126 }); | |
127 }) | |
128 .then(function(win) { | |
129 assert_equals( | |
130 win.document.body.textContent.substr(0, 7), | |
131 'report(', | |
132 'CORS type response could be loaded in the new window.'); | |
133 win.close(); | |
134 return service_worker_unregister_and_done(t, scope); | |
135 }) | |
136 .catch(unreached_rejection(t)); | |
137 }, 'CORS type response could be loaded in the new window.'); | |
138 | |
139 async_test(function(t) { | |
140 var scope = 'resources/fetch-frame-resource/window-opaque'; | |
141 service_worker_unregister_and_register(t, worker, scope) | |
142 .then(function(reg) { | |
143 return wait_for_state(t, reg.installing, 'activated'); | |
144 }) | |
145 .then(function() { | |
146 return window.open( | |
147 scope + '?mode=no-cors&url=' + | |
148 encodeURIComponent(host_info['HTTP_REMOTE_ORIGIN'] + path)); | |
149 }) | |
150 .then(function(win) { | |
151 // Give the window time to load: we won't get any error or load events | |
152 // so we'll set a timeout instead: | |
153 setTimeout(_ => { | |
154 assert_throws('SecurityError', _ => { | |
155 assert_equals(win.document.body.textContent, ''); | |
156 }, 'Opaque response renders error page in the new window.'); | |
157 win.close(); | |
158 return service_worker_unregister_and_done(t, scope); | |
159 }, 1000); | |
160 }) | |
161 // .catch(unreached_rejection(t)); | |
162 }, 'Opaque type response could not be loaded in the new window.'); | |
163 </script> | |
164 </body> | |
OLD | NEW |