4 <script src=
"../../../resources/js-test.js"></script>
9 description("This tests the constructor for the CompositionEvent DOM class.");
11 var testObject
= {nyannyan
: 123};
13 // No initializer is passed.
14 shouldBe("new CompositionEvent('eventType').bubbles", "false");
15 shouldBe("new CompositionEvent('eventType').cancelable", "false");
16 shouldBe("new CompositionEvent('eventType').view", "null");
17 shouldBe("new CompositionEvent('eventType').detail", "0");
18 shouldBeEqualToString("new CompositionEvent('eventType').data", "");
21 shouldBe("new CompositionEvent('eventType', { bubbles: false }).bubbles", "false");
22 shouldBe("new CompositionEvent('eventType', { bubbles: true }).bubbles", "true");
24 // cancelable is passed.
25 shouldBe("new CompositionEvent('eventType', { cancelable: false }).cancelable", "false");
26 shouldBe("new CompositionEvent('eventType', { cancelable: true }).cancelable", "true");
30 shouldBe("new CompositionEvent('eventType', { view: window }).view", "window");
31 shouldBe("new CompositionEvent('eventType', { view: this }).view", "this");
33 // Non-window objects.
34 shouldThrow("new CompositionEvent('eventType', { view: testObject }).view");
35 shouldThrow("new CompositionEvent('eventType', { view: document }).view");
36 shouldBe("new CompositionEvent('eventType', { view: undefined }).view", "null");
37 shouldBe("new CompositionEvent('eventType', { view: null }).view", "null");
38 shouldThrow("new CompositionEvent('eventType', { view: false }).view");
39 shouldThrow("new CompositionEvent('eventType', { view: true }).view");
40 shouldThrow("new CompositionEvent('eventType', { view: '' }).view");
41 shouldThrow("new CompositionEvent('eventType', { view: 'chocolate' }).view");
42 shouldThrow("new CompositionEvent('eventType', { view: 12345 }).view");
43 shouldThrow("new CompositionEvent('eventType', { view: 18446744073709551615 }).view");
44 shouldThrow("new CompositionEvent('eventType', { view: NaN }).view");
45 // Note that valueOf() is not called, when the left hand side is evaluated.
46 shouldThrow("new CompositionEvent('eventType', { view: {valueOf: function () { return window; } } }).view == window");
47 shouldBe("new CompositionEvent('eventType', { get view() { return window; } }).view", "window");
48 shouldThrow("new CompositionEvent('eventType', { get view() { return 123; } }).view");
49 shouldThrow("new CompositionEvent('eventType', { get view() { throw 'CompositionEvent Error'; } })");
53 shouldBeEqualToString("new CompositionEvent('eventType', { data: 'koakuma' }).data", "koakuma");
54 shouldBeEqualToString("new CompositionEvent('eventType', { data: '' }).data", "");
57 shouldBeEqualToString("new CompositionEvent('eventType', { data: undefined }).data", "");
58 shouldBeEqualToString("new CompositionEvent('eventType', { data: null }).data", "null");
59 shouldBeEqualToString("new CompositionEvent('eventType', { data: false }).data", "false");
60 shouldBeEqualToString("new CompositionEvent('eventType', { data: true }).data", "true");
61 shouldBeEqualToString("new CompositionEvent('eventType', { data: 12345 }).data", "12345");
62 shouldBeEqualToString("new CompositionEvent('eventType', { data: 18446744073709551615 }).data", "18446744073709552000");
63 shouldBeEqualToString("new CompositionEvent('eventType', { data: NaN }).data", "NaN");
64 shouldBeEqualToString("new CompositionEvent('eventType', { data: [] }).data", "");
65 shouldBeEqualToString("new CompositionEvent('eventType', { data: [1, 2, 3] }).data", "1,2,3");
66 shouldBeEqualToString("new CompositionEvent('eventType', { data: {koakuma: 12345} }).data", "[object Object]");
67 shouldBeEqualToString("new CompositionEvent('eventType', { data: {valueOf: function () { return 'koakuma'; } } }).data", "[object Object]");
69 // All initializers are passed.
70 shouldBe("new CompositionEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, data: 'koakuma' }).bubbles", "true");
71 shouldBe("new CompositionEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, data: 'koakuma' }).cancelable", "true");
72 shouldBe("new CompositionEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, data: 'koakuma' }).view", "window");
73 shouldBe("new CompositionEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, data: 'koakuma' }).detail", "111");
74 shouldBeEqualToString("new CompositionEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, data: 'koakuma' }).data", "koakuma");