1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit.javascript.host.event;
16
17 import org.htmlunit.WebDriverTestCase;
18 import org.htmlunit.junit.annotation.Alerts;
19 import org.htmlunit.junit.annotation.HtmlUnitNYI;
20 import org.junit.jupiter.api.Test;
21
22
23
24
25
26
27 public class FocusEventTest extends WebDriverTestCase {
28
29 private static final String DUMP_EVENT_FUNCTION = " function dump(event) {\n"
30 + " log(event);\n"
31 + " log(event.type);\n"
32 + " log(event.bubbles);\n"
33 + " log(event.cancelable);\n"
34 + " log(event.composed);\n"
35
36
37 + " }\n";
38
39
40
41
42 @Test
43 @Alerts({"[object FocusEvent]", "focus", "false", "false", "false"})
44 public void create_ctor() throws Exception {
45 final String html = DOCTYPE_HTML
46 + "<html><head><script>\n"
47 + LOG_TITLE_FUNCTION
48 + " function test() {\n"
49 + " try {\n"
50 + " var event = new FocusEvent('focus');\n"
51 + " dump(event);\n"
52 + " } catch(e) { logEx(e) }\n"
53 + " }\n"
54 + DUMP_EVENT_FUNCTION
55 + "</script></head><body onload='test()'>\n"
56 + "</body></html>";
57
58 loadPageVerifyTitle2(html);
59 }
60
61
62
63
64 @Test
65 @Alerts("TypeError")
66 @HtmlUnitNYI(CHROME = {"[object FocusEvent]", "undefined", "false", "false", "false"},
67 EDGE = {"[object FocusEvent]", "undefined", "false", "false", "false"},
68 FF = {"[object FocusEvent]", "undefined", "false", "false", "false"},
69 FF_ESR = {"[object FocusEvent]", "undefined", "false", "false", "false"})
70 public void create_ctorWithoutType() throws Exception {
71 final String html = DOCTYPE_HTML
72 + "<html><head><script>\n"
73 + LOG_TITLE_FUNCTION
74 + " function test() {\n"
75 + " try {\n"
76 + " var event = new FocusEvent();\n"
77 + " dump(event);\n"
78 + " } catch(e) { logEx(e) }\n"
79 + " }\n"
80 + DUMP_EVENT_FUNCTION
81 + "</script></head><body onload='test()'>\n"
82 + "</body></html>";
83
84 loadPageVerifyTitle2(html);
85 }
86
87
88
89
90 @Test
91 @Alerts({"[object FocusEvent]", "42", "false", "false", "false"})
92 public void create_ctorNumericType() throws Exception {
93 final String html = DOCTYPE_HTML
94 + "<html><head><script>\n"
95 + LOG_TITLE_FUNCTION
96 + " function test() {\n"
97 + " try {\n"
98 + " var event = new FocusEvent(42);\n"
99 + " dump(event);\n"
100 + " } catch(e) { logEx(e) }\n"
101 + " }\n"
102 + DUMP_EVENT_FUNCTION
103 + "</script></head><body onload='test()'>\n"
104 + "</body></html>";
105
106 loadPageVerifyTitle2(html);
107 }
108
109
110
111
112 @Test
113 @Alerts({"[object FocusEvent]", "null", "false", "false", "false"})
114 public void create_ctorNullType() throws Exception {
115 final String html = DOCTYPE_HTML
116 + "<html><head><script>\n"
117 + LOG_TITLE_FUNCTION
118 + " function test() {\n"
119 + " try {\n"
120 + " var event = new FocusEvent(null);\n"
121 + " dump(event);\n"
122 + " } catch(e) { logEx(e) }\n"
123 + " }\n"
124 + DUMP_EVENT_FUNCTION
125 + "</script></head><body onload='test()'>\n"
126 + "</body></html>";
127
128 loadPageVerifyTitle2(html);
129 }
130
131
132
133
134 @Test
135 @Alerts("ReferenceError")
136 public void create_ctorUnknownType() throws Exception {
137 final String html = DOCTYPE_HTML
138 + "<html><head><script>\n"
139 + LOG_TITLE_FUNCTION
140 + " function test() {\n"
141 + " try {\n"
142 + " var event = new FocusEvent(unknown);\n"
143 + " dump(event);\n"
144 + " } catch(e) { logEx(e) }\n"
145 + " }\n"
146 + DUMP_EVENT_FUNCTION
147 + "</script></head><body onload='test()'>\n"
148 + "</body></html>";
149
150 loadPageVerifyTitle2(html);
151 }
152
153
154
155
156 @Test
157 @Alerts({"[object FocusEvent]", "HtmlUnitEvent", "false", "false", "false"})
158 public void create_ctorArbitraryType() throws Exception {
159 final String html = DOCTYPE_HTML
160 + "<html><head><script>\n"
161 + LOG_TITLE_FUNCTION
162 + " function test() {\n"
163 + " try {\n"
164 + " var event = new FocusEvent('HtmlUnitEvent');\n"
165 + " dump(event);\n"
166 + " } catch(e) { logEx(e) }\n"
167 + " }\n"
168 + DUMP_EVENT_FUNCTION
169 + "</script></head><body onload='test()'>\n"
170 + "</body></html>";
171
172 loadPageVerifyTitle2(html);
173 }
174
175
176
177
178 @Test
179 @Alerts({"[object FocusEvent]", "focus", "false", "false", "false"})
180 public void create_ctorAllDetails() throws Exception {
181 final String html = DOCTYPE_HTML
182 + "<html><head><script>\n"
183 + LOG_TITLE_FUNCTION
184 + " function test() {\n"
185 + " try {\n"
186 + " var event = new FocusEvent('focus', {\n"
187
188 + " });\n"
189 + " dump(event);\n"
190 + " } catch(e) { logEx(e) }\n"
191 + " }\n"
192 + DUMP_EVENT_FUNCTION
193 + "</script></head><body onload='test()'>\n"
194 + "</body></html>";
195
196 loadPageVerifyTitle2(html);
197 }
198
199
200
201
202 @Test
203 @Alerts({"[object FocusEvent]", "focus", "false", "false", "false"})
204 public void create_ctorAllDetailsMissingData() throws Exception {
205 final String html = DOCTYPE_HTML
206 + "<html><head><script>\n"
207 + LOG_TITLE_FUNCTION
208 + " function test() {\n"
209 + " try {\n"
210 + " var event = new FocusEvent('focus', {\n"
211 + " });\n"
212 + " dump(event);\n"
213 + " } catch(e) { logEx(e) }\n"
214 + " }\n"
215 + DUMP_EVENT_FUNCTION
216 + "</script></head><body onload='test()'>\n"
217 + "</body></html>";
218
219 loadPageVerifyTitle2(html);
220 }
221
222
223
224
225 @Test
226 @Alerts({"[object FocusEvent]", "focus", "false", "false", "false"})
227 public void create_ctorAllDetailsWrongData() throws Exception {
228 final String html = DOCTYPE_HTML
229 + "<html><head><script>\n"
230 + LOG_TITLE_FUNCTION
231 + " function test() {\n"
232 + " try {\n"
233 + " var event = new FocusEvent('focus', {\n"
234 + " 'data': ['Html', 'Unit']\n"
235 + " });\n"
236 + " dump(event);\n"
237 + " } catch(e) { logEx(e) }\n"
238 + " }\n"
239 + DUMP_EVENT_FUNCTION
240 + "</script></head><body onload='test()'>\n"
241 + "</body></html>";
242
243 loadPageVerifyTitle2(html);
244 }
245
246
247
248
249 @Test
250 @Alerts("true")
251 public void inWindow() throws Exception {
252 final String html = DOCTYPE_HTML
253 + "<html>\n"
254 + "<head>\n"
255 + " <script>\n"
256 + LOG_TITLE_FUNCTION
257 + " function test() {\n"
258 + " log('FocusEvent' in window);\n"
259 + " }\n"
260 + " </script>\n"
261 + "</head>\n"
262 + "<body onload='test()'>\n"
263 + "</body>\n"
264 + "</html>";
265
266 loadPageVerifyTitle2(html);
267 }
268 }