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 WheelEventTest 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 + " }\n";
36
37
38
39
40 @Test
41 @Alerts({"[object WheelEvent]", "wheel", "false", "false", "false"})
42 public void create_ctor() throws Exception {
43 final String html = DOCTYPE_HTML
44 + "<html><head><script>\n"
45 + LOG_TITLE_FUNCTION
46 + " function test() {\n"
47 + " try {\n"
48 + " var event = new WheelEvent('wheel');\n"
49 + " dump(event);\n"
50 + " } catch(e) { logEx(e) }\n"
51 + " }\n"
52 + DUMP_EVENT_FUNCTION
53 + "</script></head><body onload='test()'>\n"
54 + "</body></html>";
55
56 loadPageVerifyTitle2(html);
57 }
58
59
60
61
62 @Test
63 @Alerts("TypeError")
64 @HtmlUnitNYI(CHROME = {"[object WheelEvent]", "undefined", "false", "false", "false"},
65 EDGE = {"[object WheelEvent]", "undefined", "false", "false", "false"},
66 FF = {"[object WheelEvent]", "undefined", "false", "false", "false"},
67 FF_ESR = {"[object WheelEvent]", "undefined", "false", "false", "false"})
68 public void create_ctorWithoutType() throws Exception {
69 final String html = DOCTYPE_HTML
70 + "<html><head><script>\n"
71 + LOG_TITLE_FUNCTION
72 + " function test() {\n"
73 + " try {\n"
74 + " var event = new WheelEvent();\n"
75 + " dump(event);\n"
76 + " } catch(e) { logEx(e) }\n"
77 + " }\n"
78 + DUMP_EVENT_FUNCTION
79 + "</script></head><body onload='test()'>\n"
80 + "</body></html>";
81
82 loadPageVerifyTitle2(html);
83 }
84
85
86
87
88 @Test
89 @Alerts({"[object WheelEvent]", "42", "false", "false", "false"})
90 public void create_ctorNumericType() throws Exception {
91 final String html = DOCTYPE_HTML
92 + "<html><head><script>\n"
93 + LOG_TITLE_FUNCTION
94 + " function test() {\n"
95 + " try {\n"
96 + " var event = new WheelEvent(42);\n"
97 + " dump(event);\n"
98 + " } catch(e) { logEx(e) }\n"
99 + " }\n"
100 + DUMP_EVENT_FUNCTION
101 + "</script></head><body onload='test()'>\n"
102 + "</body></html>";
103
104 loadPageVerifyTitle2(html);
105 }
106
107
108
109
110 @Test
111 @Alerts({"[object WheelEvent]", "null", "false", "false", "false"})
112 public void create_ctorNullType() throws Exception {
113 final String html = DOCTYPE_HTML
114 + "<html><head><script>\n"
115 + LOG_TITLE_FUNCTION
116 + " function test() {\n"
117 + " try {\n"
118 + " var event = new WheelEvent(null);\n"
119 + " dump(event);\n"
120 + " } catch(e) { logEx(e) }\n"
121 + " }\n"
122 + DUMP_EVENT_FUNCTION
123 + "</script></head><body onload='test()'>\n"
124 + "</body></html>";
125
126 loadPageVerifyTitle2(html);
127 }
128
129
130
131
132 @Test
133 @Alerts("ReferenceError")
134 public void create_ctorUnknownType() throws Exception {
135 final String html = DOCTYPE_HTML
136 + "<html><head><script>\n"
137 + LOG_TITLE_FUNCTION
138 + " function test() {\n"
139 + " try {\n"
140 + " var event = new WheelEvent(unknown);\n"
141 + " dump(event);\n"
142 + " } catch(e) { logEx(e) }\n"
143 + " }\n"
144 + DUMP_EVENT_FUNCTION
145 + "</script></head><body onload='test()'>\n"
146 + "</body></html>";
147
148 loadPageVerifyTitle2(html);
149 }
150
151
152
153
154 @Test
155 @Alerts({"[object WheelEvent]", "HtmlUnitEvent", "false", "false", "false"})
156 public void create_ctorArbitraryType() throws Exception {
157 final String html = DOCTYPE_HTML
158 + "<html><head><script>\n"
159 + LOG_TITLE_FUNCTION
160 + " function test() {\n"
161 + " try {\n"
162 + " var event = new WheelEvent('HtmlUnitEvent');\n"
163 + " dump(event);\n"
164 + " } catch(e) { logEx(e) }\n"
165 + " }\n"
166 + DUMP_EVENT_FUNCTION
167 + "</script></head><body onload='test()'>\n"
168 + "</body></html>";
169
170 loadPageVerifyTitle2(html);
171 }
172
173
174
175
176 @Test
177 @Alerts({"[object WheelEvent]", "wheel", "false", "false", "false"})
178 public void create_ctorAllDetails() throws Exception {
179 final String html = DOCTYPE_HTML
180 + "<html><head><script>\n"
181 + LOG_TITLE_FUNCTION
182 + " function test() {\n"
183 + " try {\n"
184 + " var debug = {hello: 'world'};\n"
185 + " var event = new WheelEvent('wheel', {\n"
186 + " 'deltaX': 2.3,\n"
187 + " 'deltaY': 2.4,\n"
188 + " 'deltaZ': 2.5,\n"
189 + " 'deltaMode': 1\n"
190 + " });\n"
191 + " dump(event);\n"
192 + " } catch(e) { logEx(e) }\n"
193 + " }\n"
194 + DUMP_EVENT_FUNCTION
195 + "</script></head><body onload='test()'>\n"
196 + "</body></html>";
197
198 loadPageVerifyTitle2(html);
199 }
200
201
202
203
204 @Test
205 @Alerts({"[object WheelEvent]", "wheel", "false", "false", "false"})
206 public void create_ctorAllDetailsMissingData() throws Exception {
207 final String html = DOCTYPE_HTML
208 + "<html><head><script>\n"
209 + LOG_TITLE_FUNCTION
210 + " function test() {\n"
211 + " try {\n"
212 + " var event = new WheelEvent('wheel', {\n"
213 + " });\n"
214 + " dump(event);\n"
215 + " } catch(e) { logEx(e) }\n"
216 + " }\n"
217 + DUMP_EVENT_FUNCTION
218 + "</script></head><body onload='test()'>\n"
219 + "</body></html>";
220
221 loadPageVerifyTitle2(html);
222 }
223
224
225
226
227 @Test
228 @Alerts("TypeError")
229 @HtmlUnitNYI(CHROME = {"[object WheelEvent]", "wheel", "false", "false", "false"},
230 EDGE = {"[object WheelEvent]", "wheel", "false", "false", "false"},
231 FF = {"[object WheelEvent]", "wheel", "false", "false", "false"},
232 FF_ESR = {"[object WheelEvent]", "wheel", "false", "false", "false"})
233 public void create_ctorAllDetailsWrongData() throws Exception {
234 final String html = DOCTYPE_HTML
235 + "<html><head><script>\n"
236 + LOG_TITLE_FUNCTION
237 + " function test() {\n"
238 + " try {\n"
239 + " var event = new WheelEvent('wheel', {\n"
240 + " 'deltaX': 'ten'\n"
241 + " });\n"
242 + " dump(event);\n"
243 + " } catch(e) { logEx(e) }\n"
244 + " }\n"
245 + DUMP_EVENT_FUNCTION
246 + "</script></head><body onload='test()'>\n"
247 + "</body></html>";
248
249 loadPageVerifyTitle2(html);
250 }
251
252
253
254
255 @Test
256 @Alerts("true")
257 public void inWindow() throws Exception {
258 final String html = DOCTYPE_HTML
259 + "<html>\n"
260 + "<head>\n"
261 + " <script>\n"
262 + LOG_TITLE_FUNCTION
263 + " function test() {\n"
264 + " log('WheelEvent' in window);\n"
265 + " }\n"
266 + " </script>\n"
267 + "</head>\n"
268 + "<body onload='test()'>\n"
269 + "</body>\n"
270 + "</html>";
271
272 loadPageVerifyTitle2(html);
273 }
274 }