cross-origin-to-whom.window.js (1727B)
1 async_test(t => { 2 const frame = document.body.appendChild(document.createElement("iframe")); 3 frame.src = "support/document-with-embedded-svg.html"; 4 const elements = { 5 "embed": ["getSVGDocument"], 6 "frame": ["contentDocument"], 7 "iframe": ["getSVGDocument", "contentDocument"], 8 "object": ["getSVGDocument", "contentDocument"] 9 }; 10 function assert_apis(instance) { 11 const name = instance.localName; 12 let priorPossibleDocument = null; 13 elements[name].forEach(api => { 14 const possibleDocument = api == "getSVGDocument" ? instance[api]() : instance[api]; 15 assert_not_equals(possibleDocument, null, `${name}.${api}`); 16 // This needs standardizing still 17 // assert_class_string(possibleDocument, "XMLDocument"); 18 19 // Ensure getSVGDocument() and contentDocument if both available return the same 20 if (priorPossibleDocument === null) { 21 priorPossibleDocument = possibleDocument; 22 } else { 23 assert_equals(priorPossibleDocument, possibleDocument); 24 } 25 }); 26 } 27 frame.onload = t.step_func_done(() => { 28 const instances = Object.keys(elements).map(element => frame.contentDocument.querySelector(element)); 29 // Everything is same origin and same origin-domain, no sweat 30 instances.forEach(instance => assert_apis(instance)); 31 // Make the current settings object cross origin-domain (SVG and its container are not affected) 32 document.domain = document.domain; 33 assert_equals(frame.contentDocument, null); 34 instances.forEach(instance => assert_apis(instance)); 35 }); 36 document.body.appendChild(frame); 37 }, "Test embed/frame/iframe/object nested document APIs for same origin-domain and cross origin-domain current settings object");