js/xpconnect/tests/chrome/test_wrappers.xul

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial