|
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=804630 |
|
6 --> |
|
7 <window title="Mozilla Bug 804630" |
|
8 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> |
|
9 <script type="application/javascript" 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=804630" |
|
14 target="_blank">Mozilla Bug 804630</a> |
|
15 </body> |
|
16 |
|
17 <!-- test code goes here --> |
|
18 <script type="application/javascript"> |
|
19 <![CDATA[ |
|
20 /** Test to make sure that COWed objects can expose properties from their prototypes. **/ |
|
21 const Cu = Components.utils; |
|
22 |
|
23 // Set up the sandbox. |
|
24 var sb = new Cu.Sandbox('http://www.example.com'); |
|
25 sb.ok = ok; |
|
26 sb.is = is; |
|
27 |
|
28 // Make a chrome object that exposes objects off its prototype. |
|
29 sb.proto = { read: 42, readWrite: 32, __exposedProps__: {} }; |
|
30 sb.proto.__defineSetter__('setterProp', function(val) { this._setterProp = val; }); |
|
31 sb.obj = { __exposedProps__: { read: 'r', readWrite: 'rw', setterProp: 'w' } }; |
|
32 sb.obj.__proto__ = sb.proto; |
|
33 |
|
34 // Make sure we can't access any of the properties on the prototype directly. |
|
35 Cu.evalInSandbox('is(proto.read, undefined, "proto.read inaccessible");', sb); |
|
36 Cu.evalInSandbox('var wrote = false; ' + |
|
37 'try { proto.readWrite = 12; wrote = true; } catch(e) {} ' + |
|
38 ' ok(!wrote, "Should not write proto property");', sb); |
|
39 Cu.evalInSandbox('var wrote = false; ' + |
|
40 'try { proto.setterProp = 12; wrote = true; } catch(e) {} ' + |
|
41 ' ok(!wrote, "Should not write proto setter");', sb); |
|
42 |
|
43 // Make sure we can access the exposed properties via the derived object. |
|
44 Cu.evalInSandbox('is(obj.read, 42, "obj.read accessible");', sb); |
|
45 Cu.evalInSandbox('is(obj.readWrite, 32, "obj.readWrite is readable");', sb); |
|
46 Cu.evalInSandbox('obj.readWrite = 8; is(obj.readWrite, 8, "obj.readWrite is writable");', sb); |
|
47 Cu.evalInSandbox('obj.setterProp = 3;', sb); |
|
48 is(sb.obj._setterProp, 3, "obj.setterProp works"); |
|
49 |
|
50 ]]> |
|
51 </script> |
|
52 </window> |