opaque-response-preloaded.https.html (2007B)
1 <!DOCTYPE html> 2 <meta charset="utf-8"> 3 <title>Opaque responses should not be reused for XHRs</title> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <script src="resources/test-helpers.sub.js"></script> 7 <script> 8 const WORKER = 9 'resources/opaque-response-preloaded-worker.js'; 10 11 var done; 12 13 // These test that the browser does not inappropriately use a cached opaque 14 // response for a request that is not no-cors. The test opens a controlled 15 // iframe that uses link rel=preload to issue a same-origin no-cors request. 16 // The service worker responds to the request with an opaque response. Then the 17 // iframe does an XHR (not no-cors) to that URL again. The request should fail. 18 promise_test(t => { 19 const SCOPE = 20 'resources/opaque-response-being-preloaded-xhr.html'; 21 const promise = new Promise(resolve => done = resolve); 22 23 return service_worker_unregister_and_register(t, WORKER, SCOPE) 24 .then(reg => { 25 add_completion_callback(() => reg.unregister()); 26 return wait_for_state(t, reg.installing, 'activated'); 27 }) 28 .then(() => with_iframe(SCOPE)) 29 .then(frame => t.add_cleanup(() => frame.remove() )) 30 .then(() => promise) 31 .then(result => assert_equals(result, 'PASS')); 32 }, 'Opaque responses should not be reused for XHRs, loading case'); 33 34 promise_test(t => { 35 const SCOPE = 36 'resources/opaque-response-preloaded-xhr.html'; 37 const promise = new Promise(resolve => done = resolve); 38 39 return service_worker_unregister_and_register(t, WORKER, SCOPE) 40 .then(reg => { 41 add_completion_callback(() => reg.unregister()); 42 return wait_for_state(t, reg.installing, 'activated'); 43 }) 44 .then(() => with_iframe(SCOPE)) 45 .then(frame => t.add_cleanup(() => frame.remove() )) 46 .then(() => promise) 47 .then(result => assert_equals(result, 'PASS')); 48 }, 'Opaque responses should not be reused for XHRs, done case'); 49 50 </script>