test_bug1769155.html (2186B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title>XSLT error results shouldn't replace documents loaded during the transform</title> 6 <script src="/tests/SimpleTest/SimpleTest.js"></script> 7 <link rel="stylesheet" href="/tests/SimpleTest/test.css"/> 8 <script> 9 SpecialPowers.pushPrefEnv({ 10 set: [["network.xhr.block_sync_system_requests", false]] 11 }); 12 13 SimpleTest.waitForExplicitFinish(); 14 15 async function runTest() { 16 const crossOriginLocation = "https://example.org/tests/dom/xslt/tests/mochitest/file_bug1769155.html"; 17 const sjs = new URL("bug1769155.sjs", location.href); 18 // During the XSLT processing we redirect by setting location and then 19 // spin the event loop using synchronous XHR, so that the location change 20 // happens while we're still processing the XSLT. 21 let xml = ` 22 <?xml-stylesheet type="application/xml" href="#sheet"?> 23 <stylesheet id="sheet" version="1.0" xmlns="http://www.w3.org/1999/XSL/Transform"> 24 <template match="/"> 25 <script xmlns="http://www.w3.org/1999/xhtml"> 26 location = "${crossOriginLocation}"; 27 let xhr = new XMLHttpRequest(); 28 xhr.open("GET", "${sjs.href}", false); 29 xhr.send(); 30 <\/script> 31 </template> 32 </stylesheet>`; 33 34 let win = window.open(); 35 36 let redirected = new Promise((resolve) => { 37 addEventListener("message", resolve, { once: true }); 38 }); 39 40 SpecialPowers.spawn(win, [xml], value => { 41 content.location = URL.createObjectURL(new Blob([ value ], { type: "application/xml" })); 42 }); 43 await redirected; 44 45 // At this point the setting of window.location should have redirected us to 46 // a cross-origin site. 47 let threw = false; 48 try { 49 win.document; 50 } catch { 51 threw = true; 52 } 53 ok(threw, "Accessing a property on a cross-origin window should fail."); 54 55 win.close(); 56 57 SimpleTest.finish(); 58 } 59 </script> 60 </head> 61 <body onload="runTest();"> 62 <p id="display"></p> 63 <div id="content" style="display: none"></div> 64 <pre id="test"></pre> 65 </body> 66 </html>