blob: 928dcba40d67a066f3142b55fc410c83dd7302fd [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<script src="../../../resources/js-test-pre.js"></script>
</head>
<body>
<script>
description("This tests the constructors for all the event DOM classes that have them.");
function test(toEval, bubblesExpected, cancelableExpected)
{
if (bubblesExpected) {
shouldBe("(" + toEval + ").bubbles", "true");
} else {
shouldBe("(" + toEval + ").bubbles", "false");
}
if (cancelableExpected) {
shouldBe("(" + toEval + ").cancelable", "true");
} else {
shouldBe("(" + toEval + ").cancelable", "false");
}
}
// No initializer passed.
test("new Event('eventType')", false, false);
// Both true.
test("new Event('eventType', { bubbles: true, cancelable: true })", true, true);
// One true, one false.
test("new Event('eventType', { bubbles: true, cancelable: false })", true, false);
// One explicitly undefined.
test("new Event('eventType', { bubbles: true, cancelable: undefined })", true, false);
// One a numeric value.
test("new Event('eventType', { bubbles: true, cancelable: 0 })", true, false);
// One missing.
test("new Event('eventType', { bubbles: true })", true, false);
// Empty initalizer.
test("new Event('eventType', { })", false, false);
// null initializer.
test("new Event('eventType', null)", false, false);
// Explicitly undefined initializer.
test("new Event('eventType', undefined)", false, false);
// A number as the initializer.
shouldThrowErrorName("new Event('eventType', 0)", "TypeError");
// The window as the initializer.
test("new Event('eventType', window)", false, false);
// The window as the initializer, but with bubbles defined to true.
var bubbles = true;
test("new Event('eventType', window)", true, false);
// One value defined on the prototype chain of a host object.
Document.prototype.bubbles = true;
test("new Event('eventType', document)", true, false);
// One value defined on the prototype chain of a vanilla object.
var Constructible = function() { }
Constructible.prototype.bubbles = true;
var constructible = new Constructible;
test("new Event('eventType', constructible)", true, false);
// Additional properties on the initializer
test("new Event('eventType', { bubbles: true, cancelable: true, other: true })", true, true);
// One getter returning true.
test("new Event('eventType', { bubbles: true, get cancelable() { return true; } })", true, true);
// One getter returning false.
test("new Event('eventType', { bubbles: true, get cancelable() { return false; } })", true, false);
// One getter throws an exeception.
shouldThrow("new Event('eventType', { bubbles: true, get cancelable() { throw 'Custom Error'; } })")
</script>
<script src="../../../resources/js-test-post.js"></script>
</body>
</html>