Bug 808608 - Fix test_bug802557. r=bz

There are a number of fixes to this important tests, so this warrants a separate
patch.

First of all, the boundTo machinery goes away, because we no longer have same-
compartment Xrays giving us the weird bound methods.

Furthermore, now that the sensitive methods are just regular old methods
off the prototype. They'll fail correctly when used on a same-scope object,
but not for cross-scope XOWs they'll just fail in the
GetWrappedNativeOfJSObject rat's nest (when they can't unwrap the security
wrapper), so we'll just get a generic XPConnect error instead of a security
exception. I want to fix this soon, so I changed the skipMessageCheck stuff
to use todo_is.

However, _that_ caused an UNEXPECTED-PASS for the DefaultValue test (which
was the only one of the array of tests that was throwing a security exception
in step 2). So I added an annotation for that in item[2].
This commit is contained in:
Bobby Holley 2012-11-21 13:20:05 -08:00
parent 4fb0eb55a2
commit d889379068
2 changed files with 19 additions and 19 deletions

View File

@ -34,7 +34,11 @@ var gTests = {
}
};
gTests.getLocationApply1.skipMessageCheck = true;
gTests.getLocationApply2.skipMessageCheck = true;
gTests.getLocationApply3.skipMessageCheck = true;
gTests.getLocationViaPrototype.skipMessageCheck = true;
gTests.getHrefViaApply.skipMessageCheck = true;
gTests.getHrefViaPrototype.skipMessageCheck = true;
</script>

View File

@ -32,15 +32,13 @@ function checkThrows(fun, desc, skipMessageCheck) {
ok(false, "Didn't throw when " + desc);
} catch(e) {
ok(true, "Threw when " + desc + " " + e);
if (!skipMessageCheck)
ok(/denied|insecure/.exec(e), "Should be security exception");
(skipMessageCheck ? todo : ok)(/denied|insecure/.exec(e), "Should be security exception");
}
}
var loadCount = 0;
var ifr = document.getElementById('ifr');
var iWin = ifr.contentWindow;
function boundTo(item, l) { return item[3] && item[2] === l; };
function go() {
++loadCount;
@ -48,19 +46,19 @@ function go() {
gLoc = iWin.location;
// Note that accessors pulled off Xrays are currently bound. This is bug 658909.
// [getter, description, locationObj, bound]
gGetters = [[ location.toString, 'toString from LW', location, true ],
[ gLoc.toString, 'toString from XLW', gLoc, true ],
[ Location.prototype.toString, 'toString from Location.prototype', location, false ],
[ iWin.Location.prototype.toString, 'toString from iWin.Location.prototype', gLoc, false ],
[ Object.__lookupGetter__.call(location, 'href'), 'href getter from LW', location, true ],
[ Object.__lookupGetter__.call(gLoc, 'href'), 'href getter from XLW', gLoc, true ],
[ Object.getOwnPropertyDescriptor(Location.prototype, 'href').get, 'href getter from Location.prototype', location, false ],
[ Object.getOwnPropertyDescriptor(iWin.Location.prototype, 'href').get, 'href getter from iWin.Location.prototype', gLoc, false ],
[ function() { return this + ''; }, 'implicit conversion via [[DefaultValue]]', location, false]];
gGetters = [[ location.toString, 'toString from LW' ],
[ gLoc.toString, 'toString from XLW' ],
[ Location.prototype.toString, 'toString from Location.prototype' ],
[ iWin.Location.prototype.toString, 'toString from iWin.Location.prototype' ],
[ Object.__lookupGetter__.call(location, 'href'), 'href getter from LW' ],
[ Object.__lookupGetter__.call(gLoc, 'href'), 'href getter from XLW' ],
[ Object.getOwnPropertyDescriptor(Location.prototype, 'href').get, 'href getter from Location.prototype' ],
[ Object.getOwnPropertyDescriptor(iWin.Location.prototype, 'href').get, 'href getter from iWin.Location.prototype' ],
[ function() { return this + ''; }, 'implicit conversion via [[DefaultValue]]', /* doMessageCheck = */ true ]];
gGetters.forEach(function(item) {
try {
(boundTo(item, gLoc) ? todo_is : is)(item[0].call(location), location.toString(), 'Same-origin LW: ' + item[1]);
(boundTo(item, location) ? todo_is : is)(item[0].call(gLoc), gLoc.toString(), 'Same-origin XLW: ' + item[1]);
is(item[0].call(location), location.toString(), 'Same-origin LW: ' + item[1]);
is(item[0].call(gLoc), gLoc.toString(), 'Same-origin XLW: ' + item[1]);
} catch (e) {
ok(false, "Threw while applying " + item[1] + " to same-origin location object: " + e);
}
@ -69,11 +67,9 @@ function go() {
}
else if (loadCount == 2) {
gGetters.forEach(function(item) {
// If the getter is bound to our local window.location, it's not going to throw
if (!boundTo(item, window.location))
checkThrows(function() { item[0].call(gLoc); },
'call()ing ' + item[1] + ' after navigation cross-origin',
/* skipMessageCheck = */ true);
checkThrows(function() { item[0].call(gLoc); },
'call()ing ' + item[1] + ' after navigation cross-origin',
/* skipMessageCheck = */ false);
});
ifr.src = 'http://mochi.test:8888/tests/js/xpconnect/tests/mochitest/file_bug802557.html';
}