test_bug1530146.html (2186B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=1530146 5 --> 6 <head> 7 <meta charset="utf-8"> 8 <title>Test for Bug 1530146</title> 9 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 10 <link rel="stylesheet" type="text/css" href="chrome://global/skin"/> 11 <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/> 12 <script type="application/javascript"> 13 14 /** Test for Bug 1530146 */ 15 SimpleTest.waitForExplicitFinish(); 16 17 addLoadEvent(setupTest); 18 19 var sb; 20 21 function setupTest() { 22 // Create a sandbox with an expanded principal for our iframe. 23 sb = new Cu.Sandbox([frames[0].document.nodePrincipal], 24 {sandboxPrototype: frames[0]}); 25 // Grab a waiver for the subframe in the sandbox to make sure the waiver 26 // stays alive. It would be nice if we could just use waiveXray in the 27 // sandbox: https://bugzilla.mozilla.org/show_bug.cgi?id=1531614 28 Cu.evalInSandbox('this.waiver = document.querySelector("iframe").contentWindow.wrappedJSObject', 29 sb); 30 var ifr = frames[0].document.querySelector("iframe"); 31 ifr.onload = doTest; 32 ifr.src = "file_bug1530146_inner.html"; 33 } 34 35 function doTest() { 36 // Create a new sandbox for the iframe's subframe 37 var sb2 = new Cu.Sandbox([frames[0][0].document.nodePrincipal], 38 {sandboxPrototype: frames[0][0]}); 39 // Reget the waiver; this is where things can go awry. 40 Cu.evalInSandbox('this.waiver = window.wrappedJSObject', sb2); 41 is(Cu.evalInSandbox("this.waiver.obj.a", sb2), "hello", 42 "Should get the right value and not crash"); 43 is(Cu.evalInSandbox("(new this.waiver.Image()).localName", sb2), "img", 44 "Should create an image and not crash"); 45 SimpleTest.finish(); 46 } 47 </script> 48 </head> 49 <body> 50 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1530146">Mozilla Bug 1530146</a> 51 <p id="display"></p> 52 <div id="content" style="display: none"> 53 <iframe src="http://mochi.test:8888/chrome/js/xpconnect/tests/chrome/file_bug1530146.html"></iframe> 54 </div> 55 <pre id="test"> 56 </pre> 57 </body> 58 </html>