This commit is contained in:
Bobby Holley 2012-07-27 12:15:46 +02:00
Родитель 14f5762294
Коммит b52dbb1296
3 изменённых файлов: 93 добавлений и 3 удалений

Просмотреть файл

@ -35,7 +35,10 @@ MOCHITEST_CHROME_FILES = \
test_bug743843.xul \
test_bug758563.xul \
test_bug760076.xul \
test_bug760109.xul \
test_bug763343.xul \
test_bug771429.xul \
test_bug773962.xul \
test_APIExposer.xul \
test_chrometoSource.xul \
outoflinexulscript.js \
@ -55,8 +58,6 @@ MOCHITEST_CHROME_FILES = \
test_weakmaps.xul \
test_weakref.xul \
test_wrappers.xul \
test_bug771429.xul \
test_bug773962.xul \
$(NULL)
# Disabled until this test gets updated to test the new proxy based

Просмотреть файл

@ -0,0 +1,89 @@
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=760109
-->
<window title="Mozilla Bug 760109"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=760109"
target="_blank">Mozilla Bug 760109</a>
</body>
<!-- test code goes here -->
<script type="application/javascript">
<![CDATA[
/** Test for COW prototype remapping.**/
// This gets decompiled and run inside the sandbox.
function sandboxCode() {
// Check that COWs for objects with standard prototypes use the standard
// prototype in the home compartment.
ok(Object.getPrototypeOf(chromeArray) === Array.prototype,
"Array prototype remapped properly");
var protoProto = Object.getPrototypeOf(Object.getPrototypeOf(chromeObject));
ok(protoProto === Object.prototype,
"Object prototype remapped properly");
// Check |constructor|. The semantics of this weird for the case of an
// object with a custom chrome-implemented prototype, because we'll end up
// bouncing up the prototype chain to Object, even though that's not fully
// accurate. It's unlikely to be a problem though, so we just verify that
// it does what we expect.
ok(chromeObject.constructor === Object, "Object constructor does what we expect");
ok(chromeArray.constructor === Array, "Array constructor remapped properly");
// We should be able to .forEach on the Array.
var concat = '';
chromeArray.forEach(function(val) { concat += val; });
is(concat, 'abz', "Should be able to .forEach COW-ed Array");
// Try other Array operations.
is(chromeArray.indexOf('b'), 1, "indexOf works correctly");
is(chromeArray.join(''), concat, "join works correctly");
is(chromeArray.slice(1).join(''), 'bz', "slice works correctly");
// Try some operations that modify the array.
is(chromeArray.pop(), 'z', "Able to call pop");
is(chromeArray.push('z'), 3, "Able to call push");
chromeArray.reverse();
is(chromeArray.join(''), 'zba', "Able to call reverse");
chromeArray.sort();
is(chromeArray.join(''), 'abz', "Able to call sort");
// We should be able to .hasOwnProperty on the Object, and have
// it filter the objects we can see.
ok(chromeObject.hasOwnProperty('foo'), "Should see r property");
ok(!chromeObject.hasOwnProperty('bar'), "Shouldn't see non-exposed property");
ok(chromeObject.hasOwnProperty('baz'), "Should see rw property");
}
// We use a constructor to create the test object so that there's an
// intermediate object on the prototype chain between the instance and the
// standard prototype.
function SomeConstructor() {
this.foo = 2;
this.bar = 3;
this.baz = 4;
this.__exposedProps__ = {foo: 'r', baz: 'rw'};
}
SomeConstructor.prototype.__exposedProps__ = {};
const Cu = Components.utils;
var sb = new Cu.Sandbox('http://www.example.org');
sb.chromeArray = ['a', 'b', 'z'];
sb.chromeArray.__exposedProps__ = {};
sb.chromeObject = new SomeConstructor();
sb.ok = ok;
sb.is = is;
Cu.evalInSandbox('(' + sandboxCode.toSource() + ')();', sb);
]]>
</script>
</window>

Просмотреть файл

@ -92,7 +92,7 @@ function COWTests() {
//is(cow.foo, undefined, "one test to rule them all");
//return;
const PROPS_TO_TEST = ['foo', 'bar', '__proto__', 'prototype', 'constructor'];
const PROPS_TO_TEST = ['foo', 'bar', 'prototype'];
var empty = {};
// Once we flip the default for __exposedProps__, this should behave