tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_APIExposer.xhtml (2254B)


      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 src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
     11 
     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 
     18  <!-- test code goes here -->
     19  <script type="application/javascript"><![CDATA[
     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 
     25      var obj = Cu.createObjectIn(sandbox);
     26      is(obj, Cu.waiveXrays(obj), "createObjectIn waives");
     27      is(Object.getPrototypeOf(obj), Cu.waiveXrays(Cu.evalInSandbox("Object.prototype", sandbox)),
     28         "Object is a sandbox object");
     29 
     30      function genPropDesc(value) {
     31          return { enumerable: true, configurable: true, writable: true,
     32                   value };
     33      }
     34      const props = {
     35          'getProp': genPropDesc(function() { ok(true, "called prop that shadowed a getter"); }),
     36          'argument': genPropDesc(function(arg) { is(arg, 42, "can pass arguments through"); }),
     37          'returnval': genPropDesc(function() { return 42; })
     38      };
     39      Object.defineProperties(obj, props);
     40      Cu.makeObjectPropsNormal(obj);
     41 
     42      sandbox.api = obj;
     43      Cu.evalInSandbox("ok(Object.getPrototypeOf(api) === Object.prototype, 'we have the object we expected'); \
     44      api.getProp(); api.argument(42); is(api.returnval(), 42, 'return value was correct');\
     45      ok(typeof api.getProp === 'function', 'functions are functions');\
     46      ok(Object.getPrototypeOf(api.getProp) === Function.prototype, 'functions come from our scope');", sandbox);
     47  ]]></script>
     48 </window>