test_wrappers.xul 3.9 KB

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