access-control-sandboxed-iframe-denied.htm (1458B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title>Tests that sandboxed iframe does not have CORS XHR access to its server</title> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 <script src="/common/get-host-info.sub.js"></script> 8 </head> 9 <body> 10 <script type="text/javascript"> 11 const path = "/xhr/resources/pass.txt?pipe=" + 12 "header(Cache-Control,no-store)|" + 13 "header(Content-Type,text/plain)"; 14 15 async_test((test) => { 16 const xhr = new XMLHttpRequest; 17 xhr.open("GET", get_host_info().HTTP_ORIGIN + path); 18 xhr.send(); 19 xhr.onerror = test.unreached_func("Unexpected error"); 20 xhr.onload = test.step_func_done(() => { 21 assert_equals(xhr.status, 200); 22 assert_equals(xhr.responseText.trim(), "PASS"); 23 }); 24 }, "Check that path exists and is accessible via local XHR request"); 25 26 async_test((test) => { 27 window.addEventListener("message", test.step_func((evt) => { 28 if (evt.data === "ready") { 29 document.getElementById("frame").contentWindow.postMessage( 30 get_host_info().HTTP_ORIGIN + path, "*"); 31 } else { 32 assert_equals(evt.data, "Exception thrown. Sandboxed iframe XHR access was denied in 'send'."); 33 test.done(); 34 } 35 }), false); 36 }, "Sandboxed iframe is denied access to path"); 37 </script> 38 <iframe id="frame" sandbox="allow-scripts" src="/xhr/resources/access-control-sandboxed-iframe.html"> 39 </iframe> 40 </body> 41 </html>