blob: 6e566a15cb87094f5eea60f660811b34b1496589 [file] [log] [blame]
<!DOCTYPE html>
<title>[LenientThis] test</title>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script>
test(function() {
// GlobalEventHandlers.onmouseenter is [LenientThis].
assert_equals(document.onmouseenter, null, "|this| is an appropriate object.");
assert_equals(Document.prototype.onmouseenter, undefined, "|this| is not an appropriate object.");
Document.prototype.onmouseenter = 'foo'; // must not throw.
assert_equals(Document.prototype.onmouseenter, undefined, "the value must not change.");
// GlobalEventHandlers.onmousedown is NOT [LenientThis].
assert_equals(document.onmousedown, null, "|this| is an appropriate object.");
assert_throws(new TypeError, function() {
Document.prototype.onmousedown;
}, "Document.prototype is invalid as |this|.");
assert_throws(new TypeError, function() {
Document.prototype.onmousedown = 'foo';
}, "Document.prototype is invalid as |this|.");
}, "Test [LenientThis] and non-[LenientThis].");
test(function() {
var noop = function() {};
var testPatterns = [
{name: 'document', instance: document, holder: Document.prototype, noninstance: window},
{name: 'window', instance: window, holder: window, noninstance: document}
];
function msg(pattern, text) {
return '[' + pattern.name + '] ' + text;
}
for (var p, i = 0; p = testPatterns[i]; ++i) {
var pd = Object.getOwnPropertyDescriptor(p.holder, 'onmouseleave');
// get
assert_equals(pd.get.call(p.noninstance), undefined, msg(p, 'get: non-instance should return undefined.'));
assert_equals(pd.get.call(p.instance), null, msg(p, 'get: instance should return null by default.'));
// set
assert_equals(pd.set.call(p.noninstance, noop), undefined, msg(p, 'set: setter always returns undefined.'));
assert_equals(pd.get.call(p.noninstance), undefined, msg(p, 'set: non-instance should returns undefined.'));
assert_equals(pd.set.call(p.instance, noop), undefined, msg(p, 'set: even instance should return undefined.'));
assert_equals(pd.get.call(p.instance), noop, msg(p, 'set: instance should return the assigned function.'));
}
// document specific tests.
pd = Object.getOwnPropertyDescriptor(Document.prototype, 'onmouseleave');
assert_equals(pd.get.call(null), undefined, '[document] get: null is not a valid instance.');
assert_equals(pd.get.call(undefined), undefined, '[document] get: undefined is not a valid instance.');
// window specific tests.
pd = Object.getOwnPropertyDescriptor(window, 'onmouseleave');
assert_equals(pd.get.call(null), noop, '[window] get: null should be interpreted as the global object.');
assert_equals(pd.get.call(undefined), noop, '[window] get: undefined should be interpreted as the global object.');
assert_equals(pd.set.call(undefined, null), undefined, '[window] set: returns undefined.');
assert_equals(pd.get.call(undefined), null, '[window] set: should be updated.');
}, "Test with extracted accessors.");
</script>