OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <title>Service Worker: Fetch for the frame loading.</title> | 2 <title>Service Worker: Fetch for the frame loading.</title> |
3 <script src="../resources/testharness.js"></script> | 3 <script src="../resources/testharness.js"></script> |
4 <script src="../resources/testharnessreport.js"></script> | 4 <script src="../resources/testharnessreport.js"></script> |
5 <script src="../resources/get-host-info.js"></script> | 5 <script src="../resources/get-host-info.js"></script> |
6 <script src="resources/test-helpers.js"></script> | 6 <script src="resources/test-helpers.js"></script> |
7 <body> | 7 <body> |
8 <script> | 8 <script> |
9 var worker = 'resources/fetch-rewrite-worker.js'; | 9 var worker = 'resources/fetch-rewrite-worker.js'; |
10 var path = base_path() + 'resources/fetch-access-control.php'; | 10 var path = base_path() + 'resources/fetch-access-control.php'; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 service_worker_unregister_and_register(t, worker, scope) | 64 service_worker_unregister_and_register(t, worker, scope) |
65 .then(function(reg) { | 65 .then(function(reg) { |
66 return wait_for_state(t, reg.installing, 'activated'); | 66 return wait_for_state(t, reg.installing, 'activated'); |
67 }) | 67 }) |
68 .then(function() { | 68 .then(function() { |
69 var frame = document.createElement('iframe'); | 69 var frame = document.createElement('iframe'); |
70 frame.src = | 70 frame.src = |
71 scope + '?mode=no-cors&url=' + | 71 scope + '?mode=no-cors&url=' + |
72 encodeURIComponent(host_info['HTTP_REMOTE_ORIGIN'] + path); | 72 encodeURIComponent(host_info['HTTP_REMOTE_ORIGIN'] + path); |
73 document.body.appendChild(frame); | 73 document.body.appendChild(frame); |
74 // We can't catch the network error on iframe. So we use the timer. | |
75 return new Promise(function(resolve) { | 74 return new Promise(function(resolve) { |
76 setTimeout(function() { resolve(frame); }, 1000); | 75 frame.onload = function () { resolve(frame) }; |
77 }); | 76 }); |
78 }) | 77 }) |
79 .then(function(frame) { | 78 .then(function(frame) { |
80 assert_equals( | 79 assert_throws('SecurityError', _ => { |
81 frame.contentDocument.body.textContent, | 80 assert_equals(frame.contentDocument.body.textContent, ''); |
82 '', | 81 }, 'Opaque response renders error page in the iframe.'); |
83 'Opaque type response could not be loaded in the iframe.'); | |
84 frame.remove(); | 82 frame.remove(); |
85 return service_worker_unregister_and_done(t, scope); | 83 return service_worker_unregister_and_done(t, scope); |
86 }) | 84 }) |
87 .catch(unreached_rejection(t)); | 85 .catch(unreached_rejection(t)); |
88 }, 'Opaque type response could not be loaded in the iframe.'); | 86 }, 'Opaque type response could not be loaded in the iframe.'); |
89 | 87 |
90 async_test(function(t) { | 88 async_test(function(t) { |
91 var scope = 'resources/fetch-frame-resource/window-basic'; | 89 var scope = 'resources/fetch-frame-resource/window-basic'; |
92 service_worker_unregister_and_register(t, worker, scope) | 90 service_worker_unregister_and_register(t, worker, scope) |
93 .then(function(reg) { | 91 .then(function(reg) { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 .catch(unreached_rejection(t)); | 136 .catch(unreached_rejection(t)); |
139 }, 'CORS type response could be loaded in the new window.'); | 137 }, 'CORS type response could be loaded in the new window.'); |
140 | 138 |
141 async_test(function(t) { | 139 async_test(function(t) { |
142 var scope = 'resources/fetch-frame-resource/window-opaque'; | 140 var scope = 'resources/fetch-frame-resource/window-opaque'; |
143 service_worker_unregister_and_register(t, worker, scope) | 141 service_worker_unregister_and_register(t, worker, scope) |
144 .then(function(reg) { | 142 .then(function(reg) { |
145 return wait_for_state(t, reg.installing, 'activated'); | 143 return wait_for_state(t, reg.installing, 'activated'); |
146 }) | 144 }) |
147 .then(function() { | 145 .then(function() { |
148 var win = window.open( | 146 return window.open( |
149 scope + '?mode=no-cors&url=' + | 147 scope + '?mode=no-cors&url=' + |
150 encodeURIComponent(host_info['HTTP_REMOTE_ORIGIN'] + path)); | 148 encodeURIComponent(host_info['HTTP_REMOTE_ORIGIN'] + path)); |
151 // We can't catch the network error on window. So we use the timer. | |
152 return new Promise(function(resolve) { | |
153 setTimeout(function() { resolve(win); }, 1000); | |
154 }); | |
155 }) | 149 }) |
156 .then(function(win) { | 150 .then(function(win) { |
157 assert_equals( | 151 // Give the window time to load: we won't get any error or load events |
158 win.document.body.textContent, | 152 // so we'll set a timeout instead: |
159 '', | 153 setTimeout(_ => { |
160 'Opaque type response could not be loaded in the new window.'); | 154 assert_throws('SecurityError', _ => { |
161 win.close(); | 155 assert_equals(win.document.body.textContent, ''); |
162 return service_worker_unregister_and_done(t, scope); | 156 }, 'Opaque response renders error page in the new window.'); |
| 157 win.close(); |
| 158 return service_worker_unregister_and_done(t, scope); |
| 159 }, 1000); |
163 }) | 160 }) |
164 .catch(unreached_rejection(t)); | 161 // .catch(unreached_rejection(t)); |
165 }, 'Opaque type response could not be loaded in the new window.'); | 162 }, 'Opaque type response could not be loaded in the new window.'); |
166 </script> | 163 </script> |
167 </body> | 164 </body> |
OLD | NEW |