access-control-basic-allow-access-control-origin-header-data-url.htm (1301B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title>Tests that cross-origin access is granted to null-origin embedded iframe</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 url = get_host_info().HTTP_REMOTE_ORIGIN + "/xhr/resources/access-control-origin-header.py"; 12 async_test(function(test) { 13 window.addEventListener("message", test.step_func(function(evt) { 14 if (evt.data == "ready") { 15 document.getElementById("frame").contentWindow.postMessage(url, "*"); 16 } else { 17 assert_equals(evt.data, "PASS: Cross-domain access allowed.\nHTTP_ORIGIN: null"); 18 test.done(); 19 } 20 }), false); 21 }, "Access granted to null-origin iframe"); 22 </script> 23 <iframe id="frame" src='data:text/html, 24 <script> 25 (function() { 26 parent.postMessage("ready", "*"); 27 window.addEventListener("message", function(evt) { 28 try { 29 const url = evt.data; 30 const xhr = new XMLHttpRequest; 31 32 xhr.open("GET", url, false); 33 xhr.send(); 34 35 parent.postMessage(xhr.responseText, "*"); 36 } catch(e) { 37 parent.postMessage(e.message, "*"); 38 } 39 }); 40 })(); 41 </script>'> 42 </body> 43 </html>