js/xpconnect/tests/chrome/test_wrappers.xul

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/xpconnect/tests/chrome/test_wrappers.xul	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,96 @@
     1.4 +<?xml version="1.0"?>
     1.5 +<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
     1.6 +<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
     1.7 +                 type="text/css"?>
     1.8 +<!--
     1.9 +https://bugzilla.mozilla.org/show_bug.cgi?id=500931
    1.10 +-->
    1.11 +<window title="Mozilla Bug 500931"
    1.12 +  xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
    1.13 +  <script type="application/javascript"
    1.14 +          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
    1.15 +
    1.16 +  <!-- test results are displayed in the html:body -->
    1.17 +  <body xmlns="http://www.w3.org/1999/xhtml">
    1.18 +  <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=533596"
    1.19 +     target="_blank">Mozilla Bug 533596</a>
    1.20 +  </body>
    1.21 +
    1.22 +  <!-- test code goes here -->
    1.23 +  <script type="application/javascript"><![CDATA[
    1.24 +
    1.25 +  /** Test for Bug 533596 **/
    1.26 +
    1.27 +  function go() {
    1.28 +    var win = $('ifr').contentWindow;
    1.29 +    var utils = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
    1.30 +                      .getInterface(Components.interfaces.nsIDOMWindowUtils);
    1.31 +    is(utils.getClassName(window), "Proxy", "our window is wrapped correctly")
    1.32 +    is(utils.getClassName(location), "Location", "chrome doesn't have location wrappers")
    1.33 +    is(utils.getClassName(win), "Proxy", "win is an Proxy");
    1.34 +    is(utils.getClassName(win.location), "Proxy", "deep wrapping works");
    1.35 +    is(win.location.href, "http://example.org/tests/js/xpconnect/tests/mochitest/chrome_wrappers_helper.html",
    1.36 +       "can still get strings out");
    1.37 +
    1.38 +    var unsafeWin = win.wrappedJSObject;
    1.39 +    is(utils.getClassName(unsafeWin), "Proxy", "can get a Proxy");
    1.40 +    is(utils.getClassName(unsafeWin.location), "Proxy", "deep wrapping works");
    1.41 +
    1.42 +    Object.defineProperty(unsafeWin, "defprop1", { value: 1, writable: true, enumerable: true });
    1.43 +    /* TODO (bug 552854): the getter isn't visible in content.
    1.44 +    function checkWrapper(val) {
    1.45 +        ok(utils.getClassName(val) == "Proxy", "wrapped properly");
    1.46 +    }
    1.47 +    Object.defineProperty(unsafeWin, "defprop2", { set: checkWrapper, enumerable: true });
    1.48 +    */
    1.49 +    unsafeWin.run_test(ok, win, unsafeWin);
    1.50 +
    1.51 +    win.setTimeout(function() {
    1.52 +                       is(utils.getClassName(this), "Proxy",
    1.53 +                          "this is wrapped correctly");
    1.54 +                       SimpleTest.finish();
    1.55 +                   }, 0)
    1.56 +
    1.57 +   var saw0 = false;
    1.58 +   for (let i in $('ifr').contentDocument.getElementsByTagName('body')) {
    1.59 +       if (i === "0")
    1.60 +           saw0 = true;
    1.61 +   }
    1.62 +   ok(saw0, "properly enumerated the 0 value");
    1.63 +
    1.64 +   ok(win.XPathEvaluator.toString().indexOf("XPathEvaluator") >= 0,
    1.65 +      "Can access content window.XPathEvaluator");
    1.66 +
    1.67 +   var nativeToString =
    1.68 +       ("" + String.replace).replace("replace", "EventTarget");
    1.69 +   var eventTargetToString = "" + win.EventTarget;
    1.70 +   ok(eventTargetToString.indexOf(nativeToString) > -1,
    1.71 +      "Stringifying a DOM interface object should return the same string as " +
    1.72 +      "stringifying a native function." + " " + eventTargetToString + " " + nativeToString);
    1.73 +
    1.74 +   is(win.XPathResult.NUMBER_TYPE, 1, "can access constants on constructors");
    1.75 +   is(typeof win.IDBKeyRange.bound, "function", "can access crazy IDBKeyRange static functions");
    1.76 +
    1.77 +   // Test getter/setter lookup on Xray wrappers.
    1.78 +   ok(Object.prototype.__lookupGetter__.call(win.document, 'title'), 'found getter on document');
    1.79 +   ok(Object.prototype.__lookupGetter__.call(win.document, 'title'), 'found getter on document');
    1.80 +
    1.81 +   // Test QI on new dom bindings.
    1.82 +   var contentXHR = XPCNativeWrapper(win.wrappedJSObject.xhr);
    1.83 +   try {
    1.84 +     var QIed = contentXHR.QueryInterface(Components.interfaces.nsIClassInfo);
    1.85 +     ok(false, "Should throw for new binding objects not having classinfo");
    1.86 +   } catch(e) {
    1.87 +     ok(true, "Threw while QI-ing on wrapper");
    1.88 +   }
    1.89 +  }
    1.90 +
    1.91 +  SimpleTest.waitForExplicitFinish();
    1.92 +
    1.93 +  ]]></script>
    1.94 +  <iframe type="content"
    1.95 +          src="http://example.org/tests/js/xpconnect/tests/mochitest/chrome_wrappers_helper.html"
    1.96 +          onload="go()"
    1.97 +          id="ifr">
    1.98 +  </iframe>
    1.99 +</window>

mercurial