js/xpconnect/tests/chrome/test_wrappers.xul
author Bobby Holley <bobbyholley@gmail.com>
Fri, 14 Oct 2011 10:52:47 -0700
changeset 78738 51541b56d20d588edc5a6111d670ca5af3db39d5
parent 74312 js/src/xpconnect/tests/chrome/test_wrappers.xul@67f6f1908b0f4cb8c00d3de763787fdb8fe8eeeb
child 78866 781ed55e16dcbc67d8c11239025f37b7c5e0f863
permissions -rw-r--r--
Bug 691411 - Move js/src/xpconnect to js/xpconnect and rename source files while we're at it. r=khuey, sr=mrbkap

<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
                 type="text/css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=500931
-->
<window title="Mozilla Bug 500931"
  xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  <script type="application/javascript"
          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>

  <!-- test results are displayed in the html:body -->
  <body xmlns="http://www.w3.org/1999/xhtml">
  <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=533596"
     target="_blank">Mozilla Bug 533596</a>
  </body>

  <!-- test code goes here -->
  <script type="application/javascript"><![CDATA[

  /** Test for Bug 533596 **/

  function go() {
    var win = $('ifr').contentWindow;
    var utils = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
                      .getInterface(Components.interfaces.nsIDOMWindowUtils);
    is(utils.getClassName(window), "Proxy", "our window is wrapped correctly")
    is(utils.getClassName(location), "Proxy", "our location is wrapped correctly")
    is(utils.getClassName(win), "Proxy", "win is an Proxy");
    is(utils.getClassName(win.location), "Proxy", "deep wrapping works");
    is(win.location.href, "http://example.org/tests/js/xpconnect/tests/mochitest/chrome_wrappers_helper.html",
       "can still get strings out");

    var unsafeWin = win.wrappedJSObject;
    is(utils.getClassName(unsafeWin), "Proxy", "can get a Proxy");
    is(utils.getClassName(unsafeWin.location), "Proxy", "deep wrapping works");

    Object.defineProperty(unsafeWin, "defprop1", { value: 1, writable: true, enumerable: true });
    /* TODO (bug 552854): the getter isn't visible in content.
    function checkWrapper(val) {
        ok(utils.getClassName(val) == "Proxy", "wrapped properly");
    }
    Object.defineProperty(unsafeWin, "defprop2", { set: checkWrapper, enumerable: true });
    */
    unsafeWin.run_test(ok, win, unsafeWin);

    win.setTimeout(function() {
                       is(utils.getClassName(this), "Proxy",
                          "this is wrapped correctly");
                       SimpleTest.finish();
                   }, 0)

   var saw0 = false;
   for (let i in $('ifr').contentDocument.getElementsByTagName('body')) {
       if (i === "0")
           saw0 = true;
   }
   ok(saw0, "properly enumerated the 0 value");

   ok(win.XPathEvaluator.toString().indexOf("XPathEvaluator") >= 0,
      "Can access content window.XPathEvaluator");
  }

  SimpleTest.waitForExplicitFinish();

  ]]></script>
  <iframe type="content"
          src="http://example.org/tests/js/xpconnect/tests/mochitest/chrome_wrappers_helper.html"
          onload="go()"
          id="ifr">
  </iframe>
</window>