test_APIExposer.xul 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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=634156
  7. -->
  8. <window title="Testing API exposing capabilities"
  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=634156"
  15. target="_blank">Mozilla Bug 634156</a>
  16. </body>
  17. <!-- test code goes here -->
  18. <script type="application/javascript"><![CDATA[
  19. const Cu = Components.utils;
  20. var sandbox = new Cu.Sandbox("about:blank");
  21. sandbox.ok = ok;
  22. sandbox.is = is;
  23. Cu.evalInSandbox("Object.defineProperty(Object.prototype, 'getProp', { get: function() { throw 'FAIL: called getter' }, set: function() { throw 'FAIL: called setter'; } })", sandbox);
  24. var obj = Cu.createObjectIn(sandbox);
  25. is(obj, Cu.waiveXrays(obj), "createObjectIn waives");
  26. is(Object.getPrototypeOf(obj), Cu.waiveXrays(Cu.evalInSandbox("Object.prototype", sandbox)),
  27. "Object is a sandbox object");
  28. function genPropDesc(value) {
  29. return { enumerable: true, configurable: true, writable: true,
  30. value: value };
  31. }
  32. const props = {
  33. 'getProp': genPropDesc(function() { ok(true, "called prop that shadowed a getter"); }),
  34. 'argument': genPropDesc(function(arg) { is(arg, 42, "can pass arguments through"); }),
  35. 'returnval': genPropDesc(function() { return 42; })
  36. };
  37. Object.defineProperties(obj, props);
  38. Cu.makeObjectPropsNormal(obj);
  39. sandbox.api = obj;
  40. Cu.evalInSandbox("ok(Object.getPrototypeOf(api) === Object.prototype, 'we have the object we expected'); \
  41. api.getProp(); api.argument(42); is(api.returnval(), 42, 'return value was correct');\
  42. ok(typeof api.getProp === 'function', 'functions are functions');\
  43. ok(Object.getPrototypeOf(api.getProp) === Function.prototype, 'functions come from our scope');", sandbox);
  44. ]]></script>
  45. </window>