js/xpconnect/tests/chrome/test_exposeInDerived.xul

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/xpconnect/tests/chrome/test_exposeInDerived.xul	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,52 @@
     1.4 +<?xml version="1.0"?>
     1.5 +<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
     1.6 +<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
     1.7 +<!--
     1.8 +https://bugzilla.mozilla.org/show_bug.cgi?id=804630
     1.9 +-->
    1.10 +<window title="Mozilla Bug 804630"
    1.11 +        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
    1.12 +  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
    1.13 +
    1.14 +  <!-- test results are displayed in the html:body -->
    1.15 +  <body xmlns="http://www.w3.org/1999/xhtml">
    1.16 +  <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=804630"
    1.17 +     target="_blank">Mozilla Bug 804630</a>
    1.18 +  </body>
    1.19 +
    1.20 +  <!-- test code goes here -->
    1.21 +  <script type="application/javascript">
    1.22 +  <![CDATA[
    1.23 +  /** Test to make sure that COWed objects can expose properties from their prototypes. **/
    1.24 +  const Cu = Components.utils;
    1.25 +
    1.26 +  // Set up the sandbox.
    1.27 +  var sb = new Cu.Sandbox('http://www.example.com');
    1.28 +  sb.ok = ok;
    1.29 +  sb.is = is;
    1.30 +
    1.31 +  // Make a chrome object that exposes objects off its prototype.
    1.32 +  sb.proto = { read: 42, readWrite: 32, __exposedProps__: {} };
    1.33 +  sb.proto.__defineSetter__('setterProp', function(val) { this._setterProp = val; });
    1.34 +  sb.obj = { __exposedProps__: { read: 'r', readWrite: 'rw', setterProp: 'w' } };
    1.35 +  sb.obj.__proto__ = sb.proto;
    1.36 +
    1.37 +  // Make sure we can't access any of the properties on the prototype directly.
    1.38 +  Cu.evalInSandbox('is(proto.read, undefined, "proto.read inaccessible");', sb);
    1.39 +  Cu.evalInSandbox('var wrote = false; ' +
    1.40 +                   'try { proto.readWrite = 12; wrote = true; } catch(e) {} ' +
    1.41 +                   ' ok(!wrote, "Should not write proto property");', sb);
    1.42 +  Cu.evalInSandbox('var wrote = false; ' +
    1.43 +                   'try { proto.setterProp = 12; wrote = true; } catch(e) {} ' +
    1.44 +                   ' ok(!wrote, "Should not write proto setter");', sb);
    1.45 +
    1.46 +  // Make sure we can access the exposed properties via the derived object.
    1.47 +  Cu.evalInSandbox('is(obj.read, 42, "obj.read accessible");', sb);
    1.48 +  Cu.evalInSandbox('is(obj.readWrite, 32, "obj.readWrite is readable");', sb);
    1.49 +  Cu.evalInSandbox('obj.readWrite = 8; is(obj.readWrite, 8, "obj.readWrite is writable");', sb);
    1.50 +  Cu.evalInSandbox('obj.setterProp = 3;', sb);
    1.51 +  is(sb.obj._setterProp, 3, "obj.setterProp works");
    1.52 +
    1.53 +  ]]>
    1.54 +  </script>
    1.55 +</window>

mercurial