4 <script src=
"../../../resources/js-test.js"></script>
9 description("This tests the constructor for the CloseEvent DOM class.");
11 // No initializer is passed.
12 shouldBe("new CloseEvent('eventType').bubbles", "false");
13 shouldBe("new CloseEvent('eventType').cancelable", "false");
14 shouldBe("new CloseEvent('eventType').wasClean", "false");
15 shouldBe("new CloseEvent('eventType').code", "0");
16 shouldBeEqualToString("new CloseEvent('eventType').reason", "");
19 shouldBe("new CloseEvent('eventType', { bubbles: false }).bubbles", "false");
20 shouldBe("new CloseEvent('eventType', { bubbles: true }).bubbles", "true");
22 // cancelable is passed.
23 shouldBe("new CloseEvent('eventType', { cancelable: false }).cancelable", "false");
24 shouldBe("new CloseEvent('eventType', { cancelable: true }).cancelable", "true");
26 // wasClean is passed.
27 shouldBe("new CloseEvent('eventType', { wasClean: false }).wasClean", "false");
28 shouldBe("new CloseEvent('eventType', { wasClean: true }).wasClean", "true");
32 shouldBeEqualToString("new CloseEvent('eventType', { reason: 'koakuma' }).reason", "koakuma");
33 shouldBeEqualToString("new CloseEvent('eventType', { reason: '' }).reason", "");
36 shouldBeEqualToString("new CloseEvent('eventType', { reason: undefined }).reason", "");
37 shouldBeEqualToString("new CloseEvent('eventType', { reason: null }).reason", "null");
38 shouldBeEqualToString("new CloseEvent('eventType', { reason: false }).reason", "false");
39 shouldBeEqualToString("new CloseEvent('eventType', { reason: true }).reason", "true");
40 shouldBeEqualToString("new CloseEvent('eventType', { reason: 12345 }).reason", "12345");
41 shouldBeEqualToString("new CloseEvent('eventType', { reason: 18446744073709551615 }).reason", "18446744073709552000");
42 shouldBeEqualToString("new CloseEvent('eventType', { reason: NaN }).reason", "NaN");
43 shouldBeEqualToString("new CloseEvent('eventType', { reason: [] }).reason", "");
44 shouldBeEqualToString("new CloseEvent('eventType', { reason: [1, 2, 3] }).reason", "1,2,3");
45 shouldBeEqualToString("new CloseEvent('eventType', { reason: {koakuma: 12345} }).reason", "[object Object]");
46 shouldBeEqualToString("new CloseEvent('eventType', { reason: {valueOf: function () { return 'koakuma'; } } }).reason", "[object Object]");
49 // Numbers within the unsigned short range.
50 shouldBe("new CloseEvent('eventType', { code: 0 }).code", "0");
51 shouldBe("new CloseEvent('eventType', { code: 1 }).code", "1");
52 shouldBe("new CloseEvent('eventType', { code: 65534 }).code", "65534");
53 shouldBe("new CloseEvent('eventType', { code: 65535 }).code", "65535");
55 // Numbers out of the unsigned short range.
56 // 2^{53}-1, the largest number that can be exactly represented by double.
57 shouldBe("new CloseEvent('eventType', { code: 9007199254740991 }).code", "65535");
59 shouldBe("new CloseEvent('eventType', { code: 18446744073709551615 }).code", "0");
60 shouldBe("new CloseEvent('eventType', { code: 12345678901234567890 }).code", "2048");
61 shouldBe("new CloseEvent('eventType', { code: -1 }).code", "65535");
62 shouldBe("new CloseEvent('eventType', { code: 123.45 }).code", "123");
63 shouldBe("new CloseEvent('eventType', { code: NaN }).code", "0");
65 // Non-numeric values.
66 shouldBe("new CloseEvent('eventType', { code: undefined }).code", "0");
67 shouldBe("new CloseEvent('eventType', { code: null }).code", "0");
68 shouldBe("new CloseEvent('eventType', { code: '' }).code", "0");
69 shouldBe("new CloseEvent('eventType', { code: '12345' }).code", "12345");
70 shouldBe("new CloseEvent('eventType', { code: '12345a' }).code", "0");
71 shouldBe("new CloseEvent('eventType', { code: 'abc' }).code", "0");
72 shouldBe("new CloseEvent('eventType', { code: [] }).code", "0");
73 shouldBe("new CloseEvent('eventType', { code: [12345] }).code", "12345");
74 shouldBe("new CloseEvent('eventType', { code: [12345, 67890] }).code", "0");
75 shouldBe("new CloseEvent('eventType', { code: {} }).code", "0");
76 shouldBe("new CloseEvent('eventType', { code: {moemoe: 12345} }).code", "0");
77 shouldBe("new CloseEvent('eventType', { code: {valueOf: function () { return 12345; }} }).code", "12345");
79 // All initializers are passed.
80 shouldBe("new CloseEvent('eventType', { bubbles: true, cancelable: true, wasClean: true, code : 12345, reason: 'koakuma' }).bubbles", "true");
81 shouldBe("new CloseEvent('eventType', { bubbles: true, cancelable: true, wasClean: true, code : 12345, reason: 'koakuma' }).cancelable", "true");
82 shouldBe("new CloseEvent('eventType', { bubbles: true, cancelable: true, wasClean: true, code : 12345, reason: 'koakuma' }).wasClean", "true");
83 shouldBe("new CloseEvent('eventType', { bubbles: true, cancelable: true, wasClean: true, code : 12345, reason: 'koakuma' }).code", "12345");
84 shouldBeEqualToString("new CloseEvent('eventType', { bubbles: true, cancelable: true, wasClean: true, code : 12345, reason: 'koakuma' }).reason", "koakuma");