test_bug916945.html (2842B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=916945 5 --> 6 <head> 7 <meta charset="utf-8"> 8 <title>Test for Bug 916945</title> 9 <script src="/tests/SimpleTest/SimpleTest.js"></script> 10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 11 <script type="application/javascript"> 12 13 /** Test for Bug 916945 **/ 14 SimpleTest.waitForExplicitFinish(); 15 16 var gLoadCount = 0; 17 function loaded() { 18 if (++gLoadCount == 2) 19 go(); 20 } 21 async function go() { 22 // Both same-origin and cross-origin names should be visible if they're set 23 // on the iframe element. 24 ok('winA' in window, "same-origin named access works"); 25 ok(winA instanceof winA.Window, "same-origin named access works"); 26 ok('winB' in window, "cross-origin named access works when iframe name matches"); 27 is(winB.parent, window, "cross-origin named access works when iframe name matches"); 28 29 // Setting the 'name' attribute should propagate to the docshell. 30 var ifrB = document.getElementById('ifrB'); 31 await SpecialPowers.spawn(ifrB, [], () => { 32 Assert.equal(this.content.name, 'winB', 33 'initial attribute value propagates to the docshell'); 34 }); 35 36 ifrB.setAttribute('name', 'foo'); 37 await SpecialPowers.spawn(ifrB, [], () => { 38 Assert.equal(this.content.name, 'foo', 39 'attribute sets propagate to the docshell'); 40 }); 41 ok('foo' in window, "names are dynamic if updated via setAttribute"); 42 is(foo.parent, window, "names are dynamic if updated via setAttribute"); 43 44 // Setting window.name on the subframe should not propagate to the attribute. 45 await SpecialPowers.spawn(ifrB, [], () => { 46 this.content.name = "bar"; 47 }); 48 is(ifrB.getAttribute('name'), 'foo', 'docshell updates dont propagate to the attribute'); 49 50 // When the frame element attribute and docshell name don't match, nothing is returned. 51 ok(!('foo' in window), "frame element name not resolved if it doesn't match the docshell"); 52 ok(!('bar' in window), "docshell name not resolved if it doesn't match the frame element"); 53 54 // This shouldn't assert. 55 function listener() { 56 document.body.appendChild(ifrA); 57 ifrA.name = ""; 58 } 59 ifrA.addEventListener("DOMNodeInserted", listener, {once: true}); 60 document.body.appendChild(ifrA); 61 62 SimpleTest.finish(); 63 } 64 65 </script> 66 </head> 67 <body> 68 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=916945">Mozilla Bug 916945</a> 69 <p id="display"></p> 70 <div id="content" style="display: none"> 71 72 </div> 73 <iframe id="ifrA" name="winA" onload="loaded();" src="file_empty.html"></iframe> 74 <iframe id="ifrB" name="winB" onload="loaded();" src="http://example.org/tests/js/xpconnect/tests/mochitest/file_empty.html"></iframe> 75 <pre id="test"> 76 </pre> 77 </body> 78 </html>