tor-browser

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

test_bug812415.xhtml (4069B)


      1 <?xml version="1.0"?>
      2 <?xml-stylesheet type="text/css" href="chrome://global/skin"?>
      3 <?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
      4 <!--
      5 https://bugzilla.mozilla.org/show_bug.cgi?id=812415
      6 -->
      7 <window title="Mozilla Bug 812415"
      8        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
      9  <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
     10 
     11  <!-- test results are displayed in the html:body -->
     12  <body xmlns="http://www.w3.org/1999/xhtml">
     13  <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=812415"
     14     target="_blank">Mozilla Bug 812415</a>
     15  </body>
     16 
     17  <!-- test code goes here -->
     18  <script type="application/javascript">
     19  <![CDATA[
     20  /** Test for Bug 812415 and Bug 823348 */
     21 
     22  SimpleTest.waitForExplicitFinish();
     23 
     24  function testWaiving(iwin, sb) {
     25    sb.win = iwin;
     26    is(Cu.evalInSandbox('win', sb), iwin, "Basic identity works");
     27    is(Cu.evalInSandbox('win.wrappedJSObject.expando', sb), 42, "Waivers work via .wrappedJSObject");
     28    is(Cu.evalInSandbox('XPCNativeWrapper.unwrap(win).expando', sb), 42, "Waivers work via XPCNativeWrapper.unwrap");
     29    is(Cu.evalInSandbox('win.wrappedJSObject.document.defaultView.expando', sb), 42, "Waivers are deep");
     30  }
     31 
     32  function checkThrows(expression, sb, msg) {
     33    var result = Cu.evalInSandbox('(function() { try { ' + expression + '; return "allowed"; } catch (e) { return e.toString(); }})();', sb);
     34    ok(!!/denied/.exec(result), msg);
     35  }
     36 
     37  function testAsymmetric(regular, expanded) {
     38 
     39    // Set up objects.
     40    expanded.regFun = Cu.evalInSandbox('function reg() { return 42; }; reg', regular);
     41    expanded.regObj = Cu.evalInSandbox('new Object({foo: 2})', regular);
     42    regular.expFun = Cu.evalInSandbox('function exp() { return 41; }; exp', expanded);
     43    regular.expObj = Cu.evalInSandbox('new Object({bar: 3})', expanded);
     44 
     45    // Check objects.
     46    is(Cu.evalInSandbox('regObj.foo', expanded), 2, "Expanded can see regular object prop");
     47    checkThrows('expObj.bar', regular, "Regular shouldn't read properties");
     48    Cu.evalInSandbox('regObj.foo = 20', expanded);
     49    is(expanded.regObj.foo, 20, "Expanded can set properties");
     50    checkThrows('expFun.bar = 0', regular, "Regular shouldn't write properties");
     51 
     52    // Check functions.
     53    is(Cu.evalInSandbox('regFun()', expanded), 42, "Expanded can call regular function");
     54    checkThrows('expFun()', regular, "Regular cannot call expanded function");
     55    is(Cu.evalInSandbox('regFun.name', expanded), 'reg', "Expanded can see regular function's name");
     56    checkThrows('expFun.name', regular, "Regular can't see expanded function's name");
     57    Cu.evalInSandbox('regFun.expando = 30', expanded);
     58    is(Cu.evalInSandbox('regFun.expando', expanded), 30, "Expanded can set expandos");
     59    checkThrows('expFun.expando = 29', regular, "Regular can't set expandos");
     60 
     61    // Check __proto__ stuff.
     62    is(Cu.evalInSandbox('regFun.__proto__', expanded), regular.Function.prototype, "expanded can get __proto__");
     63    checkThrows('expFun.__proto__', regular, "regular can't use __proto__");
     64    checkThrows('expFun.__proto__ = {}', regular, "regular can't mutate __proto__");
     65  }
     66 
     67  function go() {
     68    var iwin = document.getElementById('ifr').contentWindow;
     69    iwin.wrappedJSObject.expando = 42;
     70 
     71    // Make our sandboxes. We pass wantXrays=false for the nsEP to ensure that
     72    // the Xrays we get are the result of being an nsEP, not from the wantXrays
     73    // flag.
     74    var regular = new Cu.Sandbox(iwin);
     75    var expanded = new Cu.Sandbox([iwin], {wantXrays: false});
     76 
     77    // Because of the crazy secret life of wantXrays, passing wantXrays=false
     78    // has the side effect of waiving Xrays on the returned sandbox. Undo that.
     79    expanded = Cu.unwaiveXrays(expanded);
     80 
     81    testWaiving(iwin, regular);
     82    testWaiving(iwin, expanded);
     83    testAsymmetric(regular, expanded);
     84    SimpleTest.finish();
     85  }
     86 
     87  ]]>
     88  </script>
     89  <iframe id="ifr" onload="go();" src="http://example.org/tests/js/xpconnect/tests/mochitest/file_empty.html" />
     90 </window>