Bug 1027131 - Additional tests for wrapReflectors. r=gabor

This commit is contained in:
Bobby Holley 2014-06-23 13:25:09 -07:00
parent 488e6d0acd
commit 214d37d725
2 changed files with 24 additions and 2 deletions

View File

@ -122,6 +122,7 @@
// The second sandbox is for testing the exportHelper version of the cloneInto
var sandbox2 = new Cu.Sandbox("http://example.com", sandboxOptions);
sandbox.sandbox2 = sandbox2;
sandbox2.sandbox = sandbox;
function cloneAndTest(test) {
var output = sandbox.test = Cu.cloneInto(test, sandbox);
@ -168,11 +169,23 @@
is(Cu.unwaiveXrays(Cu.waiveXrays(withReflectors).win), window, "Window passes");
sandbox2.sandbox = sandbox;
checkThrows(function() { Cu.evalInSandbox('cloneInto({}, sandbox)', sandbox2); },
'CloneInto should only work on less privileged target scopes.',
/denied|insecure/);
var cloneTarget = new Cu.Sandbox('http://example.com');
var sameOriginSB = new Cu.Sandbox('http://example.com', { wantGlobalProperties: ['XMLHttpRequest'] });
var crossOriginSB = new Cu.Sandbox('http://example.net', { wantGlobalProperties: ['XMLHttpRequest'] });
sandbox2.cloneTarget = cloneTarget;
sandbox2.soXHR = Cu.evalInSandbox('new XMLHttpRequest()', sameOriginSB);
sandbox2.xoXHR = Cu.evalInSandbox('new XMLHttpRequest()', crossOriginSB);
sandbox2.chromeDoc = document;
Cu.evalInSandbox('function tryToClone(x) { return cloneInto({val: x}, cloneTarget, { wrapReflectors: true }).val; }', sandbox2);
is(Cu.evalInSandbox('tryToClone(soXHR)', sandbox2), sandbox2.soXHR, 'Same-origin wrapReflectors works');
checkThrows(function() { Cu.evalInSandbox('tryToClone(chromeDoc)', sandbox2); },
'wrapReflectors may not wrap cross-origin reflectors', /denied|insecure/);
var test = { a: function() { return 42; } };
cloneAndTestWithFunctions(test);

View File

@ -3,7 +3,7 @@ function run_test() {
var epsb = new Cu.Sandbox(["http://example.com", "http://example.org"], { wantExportHelpers: true });
var subsb = new Cu.Sandbox("http://example.com", { wantGlobalProperties: ["XMLHttpRequest"] });
var subsb2 = new Cu.Sandbox("http://example.com", { wantGlobalProperties: ["XMLHttpRequest"] });
var xorigsb = new Cu.Sandbox("http://test.com");
var xorigsb = new Cu.Sandbox("http://test.com", { wantGlobalProperties: ["XMLHttpRequest"] });
epsb.subsb = subsb;
epsb.xorigsb = xorigsb;
@ -50,6 +50,15 @@ function run_test() {
imported(42,tobecloned, native, mixed);
}.toSource() + ")()", subsb);
// Invoking an exported function with cross-origin arguments should throw.
subsb.xoNative = Cu.evalInSandbox('new XMLHttpRequest()', xorigsb);
try {
Cu.evalInSandbox('imported({val: xoNative})', subsb);
do_check_true(false);
} catch (e) {
do_check_true(/denied|insecure/.test(e));
}
// Apply should work but the |this| argument should not be
// possible to be changed.
Cu.evalInSandbox("(" + function() {