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.

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

mercurial