4 <script src=
"../../../resources/js-test.js"></script>
9 description("This tests the constructor for the FocusEvent DOM class.");
11 var testObject
= {nyannyan
: 123};
12 var testDiv
= document
.createElement("div");
13 var xhr
= new XMLHttpRequest
;
15 // No initializer is passed.
16 shouldBe("new FocusEvent('eventType').bubbles", "false");
17 shouldBe("new FocusEvent('eventType').cancelable", "false");
18 shouldBe("new FocusEvent('eventType').view", "null");
19 shouldBe("new FocusEvent('eventType').detail", "0");
20 shouldBe("new FocusEvent('eventType').relatedTarget", "null");
23 shouldBe("new FocusEvent('eventType', { bubbles: false }).bubbles", "false");
24 shouldBe("new FocusEvent('eventType', { bubbles: true }).bubbles", "true");
26 // cancelable is passed.
27 shouldBe("new FocusEvent('eventType', { cancelable: false }).cancelable", "false");
28 shouldBe("new FocusEvent('eventType', { cancelable: true }).cancelable", "true");
32 shouldBe("new FocusEvent('eventType', { view: window }).view", "window");
33 shouldBe("new FocusEvent('eventType', { view: this }).view", "this");
35 // Non-window objects.
36 shouldThrow("new FocusEvent('eventType', { view: testObject }).view");
37 shouldThrow("new FocusEvent('eventType', { view: document }).view");
38 shouldBe("new FocusEvent('eventType', { view: undefined }).view", "null");
39 shouldBe("new FocusEvent('eventType', { view: null }).view", "null");
40 shouldThrow("new FocusEvent('eventType', { view: false }).view");
41 shouldThrow("new FocusEvent('eventType', { view: true }).view");
42 shouldThrow("new FocusEvent('eventType', { view: '' }).view");
43 shouldThrow("new FocusEvent('eventType', { view: 'chocolate' }).view");
44 shouldThrow("new FocusEvent('eventType', { view: 12345 }).view");
45 shouldThrow("new FocusEvent('eventType', { view: 18446744073709551615 }).view");
46 shouldThrow("new FocusEvent('eventType', { view: NaN }).view");
47 // Note that valueOf() is not called, when the left hand side is evaluated.
48 shouldThrow("new FocusEvent('eventType', { view: {valueOf: function () { return window; } } }).view == window");
49 shouldBe("new FocusEvent('eventType', { get view() { return window; } }).view", "window");
50 shouldThrow("new FocusEvent('eventType', { get view() { return 123; } }).view");
51 shouldThrow("new FocusEvent('eventType', { get view() { throw 'FocusEvent Error'; } })");
53 // relatedTarget is passed.
55 shouldBe("new FocusEvent('eventType', { relatedTarget: testDiv }).relatedTarget", "testDiv");
56 shouldBe("new FocusEvent('eventType', { relatedTarget: document }).relatedTarget", "document");
57 shouldBe("new FocusEvent('eventType', { relatedTarget: xhr }).relatedTarget", "xhr");
58 shouldBe("new FocusEvent('eventType', { relatedTarget: window }).relatedTarget", "window");
61 shouldThrow("new FocusEvent('eventType', { relatedTarget: testObject }).relatedTarget");
62 shouldBe("new FocusEvent('eventType', { relatedTarget: undefined }).relatedTarget", "null");
63 shouldBe("new FocusEvent('eventType', { relatedTarget: null }).relatedTarget", "null");
64 shouldThrow("new FocusEvent('eventType', { relatedTarget: false }).relatedTarget");
65 shouldThrow("new FocusEvent('eventType', { relatedTarget: true }).relatedTarget");
66 shouldThrow("new FocusEvent('eventType', { relatedTarget: '' }).relatedTarget");
67 shouldThrow("new FocusEvent('eventType', { relatedTarget: 'chocolate' }).relatedTarget");
68 shouldThrow("new FocusEvent('eventType', { relatedTarget: 12345 }).relatedTarget");
69 shouldThrow("new FocusEvent('eventType', { relatedTarget: 18446744073709551615 }).relatedTarget");
70 shouldThrow("new FocusEvent('eventType', { relatedTarget: NaN }).relatedTarget");
71 // Note that valueOf() is not called, when the left hand side is evaluated.
72 shouldThrow("new FocusEvent('eventType', { relatedTarget: {valueOf: function () { return testDiv; } } }).relatedTarget == testDiv");
73 shouldBeTrue("new FocusEvent('eventType', { get relatedTarget() { return testDiv; } }).relatedTarget == testDiv");
74 shouldThrow("new FocusEvent('eventType', { get relatedTarget() { return 123; } }).relatedTarget");
75 shouldThrow("new FocusEvent('eventType', { get relatedTarget() { throw 'FocusEvent Error'; } })");
77 // All initializers are passed.
78 shouldBe("new FocusEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, relatedTarget: testDiv }).bubbles", "true");
79 shouldBe("new FocusEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, relatedTarget: testDiv }).cancelable", "true");
80 shouldBe("new FocusEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, relatedTarget: testDiv }).view", "window");
81 shouldBe("new FocusEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, relatedTarget: testDiv }).detail", "111");
82 shouldBe("new FocusEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, relatedTarget: testDiv }).relatedTarget", "testDiv");