| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <meta charset="utf-8"> | 2 <meta charset="utf-8"> |
| 3 <title>Opaque responses on MemoryCache should not be reused for XHRs</title> | 3 <title>Opaque responses should not be reused for XHRs</title> |
| 4 <script src="/resources/testharness.js"></script> | 4 <script src="/resources/testharness.js"></script> |
| 5 <script src="/resources/testharnessreport.js"></script> | 5 <script src="/resources/testharnessreport.js"></script> |
| 6 <script src="resources/test-helpers.js"></script> | 6 <script src="resources/test-helpers.sub.js"></script> |
| 7 <script> | 7 <script> |
| 8 const WORKER = | 8 const WORKER = |
| 9 'resources/opaque-response-in-memorycache-worker.js'; | 9 'resources/opaque-response-preloaded-worker.js'; |
| 10 const SCOPE = | 10 const SCOPE = |
| 11 'resources/opaque-response-in-memorycache-iframe.html'; | 11 'resources/opaque-response-preloaded-iframe.html'; |
| 12 var resolve_done; | 12 var resolve_done; |
| 13 var done_was_called = new Promise(resolve => resolve_done = resolve); | 13 var done_was_called = new Promise(resolve => resolve_done = resolve); |
| 14 // Called by the iframe when done. | 14 // Called by the iframe when done. |
| 15 function done(result) { resolve_done(result); } | 15 function done(result) { resolve_done(result); } |
| 16 | 16 |
| 17 // This test creates an controlled iframe that makes a fetch request. The | 17 // This tests that the browser does not inappropriately use a cached opaque |
| 18 // service worker returns a response with a body stream containing an invalid | 18 // response for a request that is not no-cors. The test opens a controlled |
| 19 // chunk. | 19 // iframe that uses link rel=preload to issue a same-origin no-cors request. |
| 20 // The service worker responds to the request with an opaque response. Then the |
| 21 // iframe does an XHR (not no-cors) to that URL again. The request should fail. |
| 20 promise_test(t => { | 22 promise_test(t => { |
| 21 return service_worker_unregister_and_register(t, WORKER, SCOPE) | 23 return service_worker_unregister_and_register(t, WORKER, SCOPE) |
| 22 .then(reg => { | 24 .then(reg => { |
| 23 add_completion_callback(() => reg.unregister()); | 25 add_completion_callback(() => reg.unregister()); |
| 24 return wait_for_state(t, reg.installing, 'activated'); | 26 return wait_for_state(t, reg.installing, 'activated'); |
| 25 }) | 27 }) |
| 26 .then(() => with_iframe(SCOPE)) | 28 .then(() => with_iframe(SCOPE)) |
| 29 .then(frame => t.add_cleanup(() => frame.remove() )) |
| 27 .then(() => done_was_called) | 30 .then(() => done_was_called) |
| 28 .then(result => assert_equals(result, 'PASS')); | 31 .then(result => assert_equals(result, 'PASS')); |
| 29 }, 'Opaque responses on MemoryCache should not be reused for XHRs'); | 32 }, 'Opaque responses should not be reused for XHRs'); |
| 30 </script> | 33 </script> |
| OLD | NEW |