test_wrappers.xhtml (3524B)
1 <?xml version="1.0"?> 2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?> 3 <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" 4 type="text/css"?> 5 <!-- 6 https://bugzilla.mozilla.org/show_bug.cgi?id=500931 7 --> 8 <window title="Mozilla Bug 500931" 9 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> 10 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 11 12 <!-- test results are displayed in the html:body --> 13 <body xmlns="http://www.w3.org/1999/xhtml"> 14 <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=533596" 15 target="_blank">Mozilla Bug 533596</a> 16 </body> 17 18 <!-- test code goes here --> 19 <script type="application/javascript"><![CDATA[ 20 21 /** Test for Bug 533596 */ 22 23 function go() { 24 var win = $('ifr').contentWindow; 25 var utils = window.windowUtils; 26 is(utils.getClassName(window), "Proxy", "our window is wrapped correctly") 27 is(utils.getClassName(location), "Location", "chrome doesn't have location wrappers") 28 is(utils.getClassName(win), "Proxy", "win is an Proxy"); 29 is(utils.getClassName(win.location), "Proxy", "deep wrapping works"); 30 is(win.location.href, "https://example.org/tests/js/xpconnect/tests/mochitest/chrome_wrappers_helper.html", 31 "can still get strings out"); 32 33 var unsafeWin = win.wrappedJSObject; 34 is(utils.getClassName(unsafeWin), "Proxy", "can get a Proxy"); 35 is(utils.getClassName(unsafeWin.location), "Proxy", "deep wrapping works"); 36 37 Object.defineProperty(unsafeWin, "defprop1", { value: 1, writable: true, enumerable: true, configurable: true }); 38 /* TODO (bug 552854): the getter isn't visible in content. 39 function checkWrapper(val) { 40 ok(utils.getClassName(val) == "Proxy", "wrapped properly"); 41 } 42 Object.defineProperty(unsafeWin, "defprop2", { set: checkWrapper, enumerable: true, configurable: true }); 43 */ 44 unsafeWin.run_test(ok, win, unsafeWin); 45 46 win.setTimeout(function() { 47 is(utils.getClassName(this), "Proxy", 48 "this is wrapped correctly"); 49 SimpleTest.finish(); 50 }, 0) 51 52 var saw0 = false; 53 for (let i in $('ifr').contentDocument.getElementsByTagName('body')) { 54 if (i === "0") 55 saw0 = true; 56 } 57 ok(saw0, "properly enumerated the 0 value"); 58 59 ok(win.XPathEvaluator.toString().includes("XPathEvaluator"), 60 "Can access content window.XPathEvaluator"); 61 62 var nativeToString = 63 ("" + Math.sin).replace("sin", "EventTarget"); 64 var eventTargetToString = "" + win.EventTarget; 65 ok(eventTargetToString.indexOf(nativeToString) > -1, 66 "Stringifying a DOM interface object should return the same string as " + 67 "stringifying a native function. " + eventTargetToString + " " + nativeToString); 68 69 is(win.XPathResult.NUMBER_TYPE, 1, "can access constants on constructors"); 70 is(typeof win.IDBKeyRange.bound, "function", "can access crazy IDBKeyRange static functions"); 71 72 // Test getter/setter lookup on Xray wrappers. 73 ok(Object.prototype.__lookupGetter__.call(win.document, 'title'), 'found getter on document'); 74 ok(Object.prototype.__lookupGetter__.call(win.document, 'title'), 'found getter on document'); 75 } 76 77 SimpleTest.waitForExplicitFinish(); 78 79 ]]></script> 80 <iframe type="content" 81 src="https://example.org/tests/js/xpconnect/tests/mochitest/chrome_wrappers_helper.html" 82 onload="go()" 83 id="ifr"> 84 </iframe> 85 </window>