js/xpconnect/tests/chrome/test_bug760109.xul

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 <?xml version="1.0"?>
michael@0 2 <?xml-stylesheet type="text/css" href="chrome://global/skin"?>
michael@0 3 <?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
michael@0 4 <!--
michael@0 5 https://bugzilla.mozilla.org/show_bug.cgi?id=760109
michael@0 6 -->
michael@0 7 <window title="Mozilla Bug 760109"
michael@0 8 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
michael@0 9 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
michael@0 10
michael@0 11 <!-- test results are displayed in the html:body -->
michael@0 12 <body xmlns="http://www.w3.org/1999/xhtml">
michael@0 13 <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=760109"
michael@0 14 target="_blank">Mozilla Bug 760109</a>
michael@0 15 </body>
michael@0 16
michael@0 17 <!-- test code goes here -->
michael@0 18 <script type="application/javascript">
michael@0 19 <![CDATA[
michael@0 20
michael@0 21 /** Test for COW prototype remapping.**/
michael@0 22
michael@0 23 // This gets decompiled and run inside the sandbox.
michael@0 24 function sandboxCode() {
michael@0 25
michael@0 26 // Check that COWs for objects with standard prototypes use the standard
michael@0 27 // prototype in the home compartment.
michael@0 28 ok(Object.getPrototypeOf(chromeArray) === Array.prototype,
michael@0 29 "Array prototype remapped properly");
michael@0 30 var protoProto = Object.getPrototypeOf(Object.getPrototypeOf(chromeObject));
michael@0 31 ok(protoProto === Object.prototype,
michael@0 32 "Object prototype remapped properly");
michael@0 33
michael@0 34 // Check |constructor|.
michael@0 35 // Note that the 'constructor' property of the underlying chrome object
michael@0 36 // will be resolved on SomeConstructor.prototype, which has an empty
michael@0 37 // __exposedProps__. This means that we shouldn't remap the property, even
michael@0 38 // though we'd also be able to find it on Object.prototype. Some recent
michael@0 39 // refactoring has made it possible to do the right thing here.
michael@0 40 is(typeof chromeObject.constructor, "undefined", "Object constructor does what we expect");
michael@0 41 ok(chromeArray.constructor === Array, "Array constructor remapped properly");
michael@0 42
michael@0 43 // We should be able to .forEach on the Array.
michael@0 44 var concat = '';
michael@0 45 chromeArray.forEach(function(val) { concat += val; });
michael@0 46 is(concat, 'abz', "Should be able to .forEach COW-ed Array");
michael@0 47
michael@0 48 // Try other Array operations.
michael@0 49 is(chromeArray.indexOf('b'), 1, "indexOf works correctly");
michael@0 50 is(chromeArray.join(''), concat, "join works correctly");
michael@0 51 is(chromeArray.slice(1).join(''), 'bz', "slice works correctly");
michael@0 52 is(chromeArray.length, 3, "Able to check array length");
michael@0 53
michael@0 54 // Try some operations that modify the array.
michael@0 55 is(chromeArray.pop(), 'z', "Able to call pop");
michael@0 56 is(chromeArray.push('z'), 3, "Able to call push");
michael@0 57 chromeArray.reverse();
michael@0 58 is(chromeArray.join(''), 'zba', "Able to call reverse");
michael@0 59 chromeArray.sort();
michael@0 60 is(chromeArray.join(''), 'abz', "Able to call sort");
michael@0 61
michael@0 62 // Make sure we can see the data on the typed array
michael@0 63 is(chromeTypedArray.length, 3, "Able to check typed array length");
michael@0 64 is(chromeTypedArray[0], 10, "Able to access typed array data");
michael@0 65
michael@0 66 // We should be able to .hasOwnProperty on the Object, and have
michael@0 67 // it filter the objects we can see.
michael@0 68 ok(chromeObject.hasOwnProperty('foo'), "Should see r property");
michael@0 69 ok(!chromeObject.hasOwnProperty('bar'), "Shouldn't see non-exposed property");
michael@0 70 ok(chromeObject.hasOwnProperty('baz'), "Should see rw property");
michael@0 71 }
michael@0 72
michael@0 73 // We use a constructor to create the test object so that there's an
michael@0 74 // intermediate object on the prototype chain between the instance and the
michael@0 75 // standard prototype.
michael@0 76 function SomeConstructor() {
michael@0 77 this.foo = 2;
michael@0 78 this.bar = 3;
michael@0 79 this.baz = 4;
michael@0 80 this.__exposedProps__ = {foo: 'r', baz: 'rw'};
michael@0 81 }
michael@0 82 SomeConstructor.prototype.__exposedProps__ = {};
michael@0 83
michael@0 84 const Cu = Components.utils;
michael@0 85 var sb = new Cu.Sandbox('http://www.example.org');
michael@0 86 sb.chromeArray = ['a', 'b', 'z'];
michael@0 87 sb.chromeArray.__exposedProps__ = {};
michael@0 88 sb.chromeTypedArray = new Uint8Array([10, 20, 30]);
michael@0 89 sb.chromeObject = new SomeConstructor();
michael@0 90 sb.ok = ok;
michael@0 91 sb.is = is;
michael@0 92 Cu.evalInSandbox('(' + sandboxCode.toSource() + ')();', sb);
michael@0 93
michael@0 94 ]]>
michael@0 95 </script>
michael@0 96 </window>

mercurial