c30448005b21746d1d173af6485f8792eee506fe
[WebKit-https.git] / LayoutTests / fast / events / constructors / focus-event-constructor.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="../../js/resources/js-test-pre.js"></script>
5 </head>
6 <body>
7 <script>
8
9 description("This tests the constructor for the FocusEvent DOM class.");
10
11 var testObject = {nyannyan: 123};
12 var testDiv = document.createElement("div");
13 var xhr = new XMLHttpRequest;
14
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");
21
22 // bubbles is passed.
23 shouldBe("new FocusEvent('eventType', { bubbles: false }).bubbles", "false");
24 shouldBe("new FocusEvent('eventType', { bubbles: true }).bubbles", "true");
25
26 // cancelable is passed.
27 shouldBe("new FocusEvent('eventType', { cancelable: false }).cancelable", "false");
28 shouldBe("new FocusEvent('eventType', { cancelable: true }).cancelable", "true");
29
30 // view is passed.
31 // Window objects.
32 shouldBe("new FocusEvent('eventType', { view: window }).view", "window");
33 shouldBe("new FocusEvent('eventType', { view: this }).view", "this");
34
35 // Non-window objects.
36 shouldBe("new FocusEvent('eventType', { view: testObject }).view", "null");
37 shouldBe("new FocusEvent('eventType', { view: document }).view", "null");
38 shouldBe("new FocusEvent('eventType', { view: undefined }).view", "null");
39 shouldBe("new FocusEvent('eventType', { view: null }).view", "null");
40 shouldBe("new FocusEvent('eventType', { view: false }).view", "null");
41 shouldBe("new FocusEvent('eventType', { view: true }).view", "null");
42 shouldBe("new FocusEvent('eventType', { view: '' }).view", "null");
43 shouldBe("new FocusEvent('eventType', { view: 'chocolate' }).view", "null");
44 shouldBe("new FocusEvent('eventType', { view: 12345 }).view", "null");
45 shouldBe("new FocusEvent('eventType', { view: 18446744073709551615 }).view", "null");
46 shouldBe("new FocusEvent('eventType', { view: NaN }).view", "null");
47 // Note that valueOf() is not called, when the left hand side is evaluated.
48 shouldBeFalse("new FocusEvent('eventType', { view: {valueOf: function () { return window; } } }).view == window");
49 shouldBe("new FocusEvent('eventType', { get view() { return 123; } }).view", "null");
50 shouldThrow("new FocusEvent('eventType', { get view() { throw 'FocusEvent Error'; } })");
51
52 // relatedTarget is passed.
53 // Valid objects.
54 shouldBe("new FocusEvent('eventType', { relatedTarget: testDiv }).relatedTarget", "testDiv");
55 shouldBe("new FocusEvent('eventType', { relatedTarget: document }).relatedTarget", "document");
56 shouldBe("new FocusEvent('eventType', { relatedTarget: xhr }).relatedTarget", "xhr");
57 shouldBe("new FocusEvent('eventType', { relatedTarget: window }).relatedTarget", "window");
58
59 // Invalid objects.
60 shouldBe("new FocusEvent('eventType', { relatedTarget: testObject }).relatedTarget", "null");
61 shouldBe("new FocusEvent('eventType', { relatedTarget: undefined }).relatedTarget", "null");
62 shouldBe("new FocusEvent('eventType', { relatedTarget: null }).relatedTarget", "null");
63 shouldBe("new FocusEvent('eventType', { relatedTarget: false }).relatedTarget", "null");
64 shouldBe("new FocusEvent('eventType', { relatedTarget: true }).relatedTarget", "null");
65 shouldBe("new FocusEvent('eventType', { relatedTarget: '' }).relatedTarget", "null");
66 shouldBe("new FocusEvent('eventType', { relatedTarget: 'chocolate' }).relatedTarget", "null");
67 shouldBe("new FocusEvent('eventType', { relatedTarget: 12345 }).relatedTarget", "null");
68 shouldBe("new FocusEvent('eventType', { relatedTarget: 18446744073709551615 }).relatedTarget", "null");
69 shouldBe("new FocusEvent('eventType', { relatedTarget: NaN }).relatedTarget", "null");
70 // Note that valueOf() is not called, when the left hand side is evaluated.
71 shouldBeFalse("new FocusEvent('eventType', { relatedTarget: {valueOf: function () { return testDiv; } } }).relatedTarget == testDiv");
72 shouldBe("new FocusEvent('eventType', { get relatedTarget() { return 123; } }).relatedTarget", "null");
73 shouldThrow("new FocusEvent('eventType', { get relatedTarget() { throw 'FocusEvent Error'; } })");
74
75 // All initializers are passed.
76 shouldBe("new FocusEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, relatedTarget: testDiv }).bubbles", "true");
77 shouldBe("new FocusEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, relatedTarget: testDiv }).cancelable", "true");
78 shouldBe("new FocusEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, relatedTarget: testDiv }).view", "window");
79 shouldBe("new FocusEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, relatedTarget: testDiv }).detail", "111");
80 shouldBe("new FocusEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, relatedTarget: testDiv }).relatedTarget", "testDiv");
81 </script>
82 <script src="../../js/resources/js-test-post.js"></script>
83 </body>
84 </html>