4 <script src="../../js/resources/js-test-pre.js"></script>
9 description("This tests the constructors for all the event DOM classes that have them.");
11 function test(toEval, bubblesExpected, cancelableExpected)
13 if (bubblesExpected) {
14 shouldBe("(" + toEval + ").bubbles", "true");
16 shouldBe("(" + toEval + ").bubbles", "false");
19 if (cancelableExpected) {
20 shouldBe("(" + toEval + ").cancelable", "true");
22 shouldBe("(" + toEval + ").cancelable", "false");
26 // No initializer passed.
27 test("new Event('eventType')", false, false);
30 test("new Event('eventType', { bubbles: true, cancelable: true })", true, true);
32 // One true, one false.
33 test("new Event('eventType', { bubbles: true, cancelable: false })", true, false);
35 // One explicitly undefined.
36 test("new Event('eventType', { bubbles: true, cancelable: undefined })", true, false);
38 // One a numeric value.
39 test("new Event('eventType', { bubbles: true, cancelable: 0 })", true, false);
42 test("new Event('eventType', { bubbles: true })", true, false);
45 test("new Event('eventType', { })", false, false);
48 test("new Event('eventType', null)", false, false);
50 // Explicitly undefined initializer.
51 test("new Event('eventType', undefined)", false, false);
53 // A number as the initializer.
54 // FIXME: Should this throw?
55 test("new Event('eventType', 0)", false, false);
57 // The window as the initializer.
58 test("new Event('eventType', window)", false, false);
60 // The window as the initializer, but with bubbles defined to true.
62 test("new Event('eventType', window)", true, false);
64 // One value defined on the prototype chain of a host object.
65 Document.prototype.bubbles = true;
66 test("new Event('eventType', document)", true, false);
68 // One value defined on the prototype chain of a vanilla object.
69 var Constructible = function() { }
70 Constructible.prototype.bubbles = true;
71 var constructible = new Constructible;
72 test("new Event('eventType', constructible)", true, false);
74 // Additional properties on the initializer
75 test("new Event('eventType', { bubbles: true, cancelable: true, other: true })", true, true);
77 // One getter returning true.
78 test("new Event('eventType', { bubbles: true, get cancelable() { return true; } })", true, true);
80 // One getter returning false.
81 test("new Event('eventType', { bubbles: true, get cancelable() { return false; } })", true, false);
83 // One getter throws an exeception.
84 shouldThrow("new Event('eventType', { bubbles: true, get cancelable() { throw 'Custom Error'; } })")
86 <script src="../../js/resources/js-test-post.js"></script>