|
1 <!DOCTYPE html> |
|
2 <html> |
|
3 <head> |
|
4 <title>Testing ns*Event::Assign*EventData()</title> |
|
5 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
6 <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script> |
|
7 <script type="text/javascript" src="/tests/SimpleTest/NativeKeyCodes.js"></script> |
|
8 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"> |
|
9 <style> |
|
10 #a { |
|
11 background-color: transparent; |
|
12 transition: background-color 0.1s linear; |
|
13 } |
|
14 #a:focus { |
|
15 background-color: red; |
|
16 } |
|
17 .slidin { |
|
18 border: green 1px solid; |
|
19 width: 10px; |
|
20 height: 10px; |
|
21 animation-name: slidein; |
|
22 animation-duration: 1s; |
|
23 } |
|
24 @keyframes slidein { |
|
25 from { |
|
26 margin-left: 100%; |
|
27 } |
|
28 to { |
|
29 margin-left: 0; |
|
30 } |
|
31 } |
|
32 </style> |
|
33 </head> |
|
34 <body> |
|
35 <div id="display"> |
|
36 <input id="input-text"> |
|
37 <button id="button">button</button> |
|
38 <a id="a" href="about:blank">hyper link</a> |
|
39 <div id="scrollable-div" style="overflow: auto; width: 30px; height: 30px;"><div id="scrolled-div" style="width: 10px; height: 10px;"></div></div> |
|
40 <form id="form"></form> |
|
41 <div id="animated-div"></div> |
|
42 </div> |
|
43 <div id="content" style="display: none"> |
|
44 </div> |
|
45 <pre id="test"> |
|
46 </pre> |
|
47 |
|
48 <script class="testbody" type="application/javascript"> |
|
49 |
|
50 SimpleTest.waitForExplicitFinish(); |
|
51 SimpleTest.expectAssertions(0, 32); |
|
52 |
|
53 const kIsMac = (navigator.platform.indexOf("Mac") == 0); |
|
54 const kIsWin = (navigator.platform.indexOf("Win") == 0); |
|
55 |
|
56 var gEvent = null; |
|
57 var gCopiedEvent = []; |
|
58 var gCallback = null; |
|
59 var gCallPreventDefault = false; |
|
60 |
|
61 function onEvent(aEvent) |
|
62 { |
|
63 if (gCallPreventDefault) { |
|
64 aEvent.preventDefault(); |
|
65 } |
|
66 gEvent = aEvent; |
|
67 for (var attr in aEvent) { |
|
68 if (!attr.match(/^[A-Z0-9_]+$/) && // ignore const attributes |
|
69 attr != "multipleActionsPrevented" && // multipleActionsPrevented isn't defined in any DOM event specs. |
|
70 typeof(aEvent[attr]) != "function") { |
|
71 gCopiedEvent.push({ name: attr, value: aEvent[attr]}); |
|
72 } |
|
73 } |
|
74 setTimeout(gCallback, 0); |
|
75 } |
|
76 |
|
77 const kTests = [ |
|
78 { description: "InternalScrollPortEvent (overflow, vertical)", |
|
79 targetID: "scrollable-div", eventType: "overflow", |
|
80 dispatchEvent: function () { |
|
81 document.getElementById("scrolled-div").style.height = "500px"; |
|
82 }, |
|
83 canRun: function () { |
|
84 return true; |
|
85 }, |
|
86 todoMismatch: [], |
|
87 }, |
|
88 { description: "InternalScrollPortEvent (overflow, horizontal)", |
|
89 targetID: "scrollable-div", eventType: "overflow", |
|
90 dispatchEvent: function () { |
|
91 document.getElementById("scrolled-div").style.width = "500px"; |
|
92 }, |
|
93 canRun: function () { |
|
94 return true; |
|
95 }, |
|
96 todoMismatch: [], |
|
97 }, |
|
98 { description: "InternalScrollAreaEvent (MozScrolledAreaChanged, spreading)", |
|
99 target: function () { return document; }, eventType: "MozScrolledAreaChanged", |
|
100 dispatchEvent: function () { |
|
101 document.getElementById("scrollable-div").style.width = "50000px"; |
|
102 document.getElementById("scrollable-div").style.height = "50000px"; |
|
103 }, |
|
104 canRun: function () { |
|
105 return true; |
|
106 }, |
|
107 todoMismatch: [], |
|
108 }, |
|
109 { description: "InternalScrollAreaEvent (MozScrolledAreaChanged, shrinking)", |
|
110 target: function () { return document; }, eventType: "MozScrolledAreaChanged", |
|
111 dispatchEvent: function () { |
|
112 document.getElementById("scrollable-div").style.width = "30px"; |
|
113 document.getElementById("scrollable-div").style.height = "30px"; |
|
114 }, |
|
115 canRun: function () { |
|
116 return true; |
|
117 }, |
|
118 todoMismatch: [], |
|
119 }, |
|
120 { description: "WidgetKeyboardEvent (keydown of 'a' key without modifiers)", |
|
121 targetID: "input-text", eventType: "keydown", |
|
122 dispatchEvent: function () { |
|
123 document.getElementById(this.targetID).value = ""; |
|
124 document.getElementById(this.targetID).focus(); |
|
125 synthesizeNativeKey(KEYBOARD_LAYOUT_EN_US, kIsWin ? WIN_VK_A : MAC_VK_ANSI_A, |
|
126 {}, "a", "a"); |
|
127 }, |
|
128 canRun: function () { |
|
129 return (kIsMac || kIsWin); |
|
130 }, |
|
131 todoMismatch: [], |
|
132 }, |
|
133 { description: "WidgetKeyboardEvent (keyup of 'a' key without modifiers)", |
|
134 targetID: "input-text", eventType: "keydown", |
|
135 dispatchEvent: function () { |
|
136 document.getElementById(this.targetID).value = ""; |
|
137 document.getElementById(this.targetID).focus(); |
|
138 synthesizeNativeKey(KEYBOARD_LAYOUT_EN_US, kIsWin ? WIN_VK_A : MAC_VK_ANSI_A, |
|
139 {}, "a", "a"); |
|
140 }, |
|
141 canRun: function () { |
|
142 return (kIsMac || kIsWin); |
|
143 }, |
|
144 todoMismatch: [], |
|
145 }, |
|
146 { description: "WidgetKeyboardEvent (keypress of 'b' key with Shift)", |
|
147 targetID: "input-text", eventType: "keypress", |
|
148 dispatchEvent: function () { |
|
149 document.getElementById(this.targetID).value = ""; |
|
150 document.getElementById(this.targetID).focus(); |
|
151 synthesizeNativeKey(KEYBOARD_LAYOUT_EN_US, kIsWin ? WIN_VK_B : MAC_VK_ANSI_B, |
|
152 { shiftKey: true }, "B", "B"); |
|
153 }, |
|
154 canRun: function () { |
|
155 return (kIsMac || kIsWin); |
|
156 }, |
|
157 todoMismatch: [], |
|
158 }, |
|
159 { description: "WidgetKeyboardEvent (keypress of 'c' key with Accel)", |
|
160 targetID: "input-text", eventType: "keypress", |
|
161 dispatchEvent: function () { |
|
162 document.getElementById(this.targetID).value = ""; |
|
163 document.getElementById(this.targetID).focus(); |
|
164 synthesizeNativeKey(KEYBOARD_LAYOUT_EN_US, kIsWin ? WIN_VK_C : MAC_VK_ANSI_C, |
|
165 { accelKey: true }, kIsWin ? "\u0003" : "c", "c"); |
|
166 }, |
|
167 canRun: function () { |
|
168 return (kIsMac || kIsWin); |
|
169 }, |
|
170 todoMismatch: [], |
|
171 }, |
|
172 { description: "WidgetKeyboardEvent (keyup during composition)", |
|
173 targetID: "input-text", eventType: "keyup", |
|
174 dispatchEvent: function () { |
|
175 document.getElementById(this.targetID).value = ""; |
|
176 document.getElementById(this.targetID).focus(); |
|
177 synthesizeKey("a", { type: "keydown" }); |
|
178 synthesizeComposition({ type: "compositionstart" }); |
|
179 synthesizeComposition({ type: "compositionupdate", data: "\u306D" }); |
|
180 synthesizeText({ "composition": |
|
181 { "string": "\u306D", |
|
182 "clauses": |
|
183 [ |
|
184 { "length": 1, "attr": COMPOSITION_ATTR_RAWINPUT } |
|
185 ] |
|
186 }, |
|
187 "caret": { "start": 1, "length": 0 } |
|
188 }); |
|
189 synthesizeKey("a", { type: "keyup" }); |
|
190 synthesizeComposition({ type: "compositionupdate", data: "\u306D" }); |
|
191 synthesizeText({ "composition": |
|
192 { "string": "\u306D", |
|
193 "clauses": |
|
194 [ |
|
195 { "length": 0, "attr": 0 } |
|
196 ] |
|
197 }, |
|
198 "caret": { "start": 1, "length": 0 } |
|
199 }); |
|
200 synthesizeComposition({ type: "compositionend", data: "\u732B" }); |
|
201 }, |
|
202 canRun: function () { |
|
203 return true; |
|
204 }, |
|
205 todoMismatch: [ ], |
|
206 }, |
|
207 { description: "WidgetKeyboardEvent (keydown during composition)", |
|
208 targetID: "input-text", eventType: "keydown", |
|
209 dispatchEvent: function () { |
|
210 document.getElementById(this.targetID).value = ""; |
|
211 document.getElementById(this.targetID).focus(); |
|
212 synthesizeComposition({ type: "compositionstart" }); |
|
213 synthesizeComposition({ type: "compositionupdate", data: "\u306D" }); |
|
214 synthesizeText({ "composition": |
|
215 { "string": "\u306D", |
|
216 "clauses": |
|
217 [ |
|
218 { "length": 1, "attr": COMPOSITION_ATTR_RAWINPUT } |
|
219 ] |
|
220 }, |
|
221 "caret": { "start": 1, "length": 0 } |
|
222 }); |
|
223 synthesizeKey("VK_RETURN", { type: "keydown" }); |
|
224 synthesizeComposition({ type: "compositionupdate", data: "\u306D" }); |
|
225 synthesizeText({ "composition": |
|
226 { "string": "\u306D", |
|
227 "clauses": |
|
228 [ |
|
229 { "length": 0, "attr": 0 } |
|
230 ] |
|
231 }, |
|
232 "caret": { "start": 1, "length": 0 } |
|
233 }); |
|
234 synthesizeComposition({ type: "compositionend", data: "\u732B" }); |
|
235 synthesizeKey("VK_RETURN", { type: "keyup" }); |
|
236 }, |
|
237 canRun: function () { |
|
238 return true; |
|
239 }, |
|
240 todoMismatch: [ ], |
|
241 }, |
|
242 { description: "WidgetMouseEvent (mousedown of left button without modifier)", |
|
243 targetID: "button", eventType: "mousedown", |
|
244 dispatchEvent: function () { |
|
245 synthesizeMouseAtCenter(document.getElementById(this.targetID), |
|
246 { button: 0 }); |
|
247 }, |
|
248 canRun: function () { |
|
249 return true; |
|
250 }, |
|
251 todoMismatch: [], |
|
252 }, |
|
253 { description: "WidgetMouseEvent (click of middle button with Shift)", |
|
254 // XXX I'm not sure why middle click event isn't fired on button element. |
|
255 targetID: "input-text", eventType: "click", |
|
256 dispatchEvent: function () { |
|
257 document.getElementById(this.targetID).value = ""; |
|
258 synthesizeMouseAtCenter(document.getElementById(this.targetID), |
|
259 { button: 1, shiftKey: true, pressure: 0.5 }); |
|
260 }, |
|
261 canRun: function () { |
|
262 return true; |
|
263 }, |
|
264 todoMismatch: [], |
|
265 }, |
|
266 { description: "WidgetMouseEvent (mouseup of right button with Alt)", |
|
267 targetID: "button", eventType: "mouseup", |
|
268 dispatchEvent: function () { |
|
269 document.getElementById(this.targetID).value = ""; |
|
270 synthesizeMouseAtCenter(document.getElementById(this.targetID), |
|
271 { button: 2, altKey: true }); |
|
272 }, |
|
273 canRun: function () { |
|
274 return true; |
|
275 }, |
|
276 todoMismatch: [], |
|
277 }, |
|
278 { description: "WidgetDragEvent", |
|
279 targetID: "input-text", eventType: "dragstart", |
|
280 dispatchEvent: function () { |
|
281 return; |
|
282 }, |
|
283 canRun: function () { |
|
284 todo(false, "WidgetDragEvent isn't tested"); |
|
285 return false; |
|
286 }, |
|
287 todoMismatch: [], |
|
288 }, |
|
289 { description: "WidgetTextEvent (text)", |
|
290 targetID: "input-text", eventType: "text", |
|
291 dispatchEvent: function () { |
|
292 document.getElementById(this.targetID).value = ""; |
|
293 document.getElementById(this.targetID).focus(); |
|
294 synthesizeComposition({ type: "compositionstart" }); |
|
295 synthesizeComposition({ type: "compositionupdate", data: "\u306D" }); |
|
296 synthesizeText({ "composition": |
|
297 { "string": "\u306D", |
|
298 "clauses": |
|
299 [ |
|
300 { "length": 0, "attr": 0 } |
|
301 ] |
|
302 }, |
|
303 "caret": { "start": 1, "length": 0 } |
|
304 }); |
|
305 synthesizeComposition({ type: "compositionend", data: "\u732B" }); |
|
306 }, |
|
307 canRun: function () { |
|
308 return true; |
|
309 }, |
|
310 todoMismatch: [ ], |
|
311 }, |
|
312 { description: "WidgetCompositionEvent (compositionupdate)", |
|
313 targetID: "input-text", eventType: "compositionupdate", |
|
314 dispatchEvent: function () { |
|
315 document.getElementById(this.targetID).value = ""; |
|
316 document.getElementById(this.targetID).focus(); |
|
317 synthesizeComposition({ type: "compositionstart" }); |
|
318 synthesizeComposition({ type: "compositionupdate", data: "\u30E9\u30FC\u30E1\u30F3" }); |
|
319 synthesizeText({ "composition": |
|
320 { "string": "\u30E9\u30FC\u30E1\u30F3", |
|
321 "clauses": |
|
322 [ |
|
323 { "length": 0, "attr": 0 } |
|
324 ] |
|
325 }, |
|
326 "caret": { "start": 4, "length": 0 } |
|
327 }); |
|
328 synthesizeComposition({ type: "compositionend", data: "\u30E9\u30FC\u30E1\u30F3" }); |
|
329 }, |
|
330 canRun: function () { |
|
331 return true; |
|
332 }, |
|
333 todoMismatch: [ ], |
|
334 }, |
|
335 { description: "InternalEditorInputEvent (input at key input)", |
|
336 targetID: "input-text", eventType: "input", |
|
337 dispatchEvent: function () { |
|
338 document.getElementById(this.targetID).value = ""; |
|
339 document.getElementById(this.targetID).focus(); |
|
340 synthesizeNativeKey(KEYBOARD_LAYOUT_EN_US, kIsWin ? WIN_VK_B : MAC_VK_ANSI_B, |
|
341 { shiftKey: true }, "B", "B"); |
|
342 }, |
|
343 canRun: function () { |
|
344 return (kIsMac || kIsWin); |
|
345 }, |
|
346 todoMismatch: [], |
|
347 }, |
|
348 { description: "InternalEditorInputEvent (input at composing)", |
|
349 targetID: "input-text", eventType: "input", |
|
350 dispatchEvent: function () { |
|
351 document.getElementById(this.targetID).value = ""; |
|
352 document.getElementById(this.targetID).focus(); |
|
353 synthesizeComposition({ type: "compositionstart" }); |
|
354 synthesizeComposition({ type: "compositionupdate", data: "\u30E9\u30FC\u30E1\u30F3" }); |
|
355 synthesizeText({ "composition": |
|
356 { "string": "\u30E9\u30FC\u30E1\u30F3", |
|
357 "clauses": |
|
358 [ |
|
359 { "length": 4, "attr": COMPOSITION_ATTR_RAWINPUT } |
|
360 ] |
|
361 }, |
|
362 "caret": { "start": 4, "length": 0 } |
|
363 }); |
|
364 }, |
|
365 canRun: function () { |
|
366 return true; |
|
367 }, |
|
368 todoMismatch: [ ], |
|
369 }, |
|
370 { description: "InternalEditorInputEvent (input at committing)", |
|
371 targetID: "input-text", eventType: "input", |
|
372 dispatchEvent: function () { |
|
373 synthesizeText({ "composition": |
|
374 { "string": "\u30E9\u30FC\u30E1\u30F3", |
|
375 "clauses": |
|
376 [ |
|
377 { "length": 0, "attr": 0 } |
|
378 ] |
|
379 }, |
|
380 "caret": { "start": 4, "length": 0 } |
|
381 }); |
|
382 synthesizeComposition({ type: "compositionend", data: "\u30E9\u30FC\u30E1\u30F3" }); |
|
383 }, |
|
384 canRun: function () { |
|
385 return true; |
|
386 }, |
|
387 todoMismatch: [ ], |
|
388 }, |
|
389 { description: "WidgetMouseScrollEvent (DOMMouseScroll, vertical)", |
|
390 targetID: "input-text", eventType: "DOMMouseScroll", |
|
391 dispatchEvent: function () { |
|
392 document.getElementById(this.targetID).value = ""; |
|
393 synthesizeWheel(document.getElementById(this.targetID), 3, 4, |
|
394 { deltaY: 30, lineOrPageDeltaY: 2 }); |
|
395 }, |
|
396 canRun: function () { |
|
397 return true; |
|
398 }, |
|
399 todoMismatch: [ ], |
|
400 }, |
|
401 { description: "WidgetMouseScrollEvent (DOMMouseScroll, horizontal)", |
|
402 targetID: "input-text", eventType: "DOMMouseScroll", |
|
403 dispatchEvent: function () { |
|
404 document.getElementById(this.targetID).value = ""; |
|
405 synthesizeWheel(document.getElementById(this.targetID), 4, 5, |
|
406 { deltaX: 30, lineOrPageDeltaX: 2, shiftKey: true }); |
|
407 }, |
|
408 canRun: function () { |
|
409 return true; |
|
410 }, |
|
411 todoMismatch: [ ], |
|
412 }, |
|
413 { description: "WidgetMouseScrollEvent (MozMousePixelScroll, vertical)", |
|
414 targetID: "input-text", eventType: "MozMousePixelScroll", |
|
415 dispatchEvent: function () { |
|
416 document.getElementById(this.targetID).value = ""; |
|
417 synthesizeWheel(document.getElementById(this.targetID), 3, 4, |
|
418 { deltaY: 20, lineOrPageDeltaY: 1, altKey: true }); |
|
419 }, |
|
420 canRun: function () { |
|
421 return true; |
|
422 }, |
|
423 todoMismatch: [ ], |
|
424 }, |
|
425 { description: "WidgetMouseScrollEvent (MozMousePixelScroll, horizontal)", |
|
426 targetID: "input-text", eventType: "MozMousePixelScroll", |
|
427 dispatchEvent: function () { |
|
428 document.getElementById(this.targetID).value = ""; |
|
429 synthesizeWheel(document.getElementById(this.targetID), 4, 5, |
|
430 { deltaX: 20, lineOrPageDeltaX: 1, ctrlKey: true }); |
|
431 }, |
|
432 canRun: function () { |
|
433 return true; |
|
434 }, |
|
435 todoMismatch: [ ], |
|
436 }, |
|
437 { description: "WidgetWheelEvent (wheel, vertical)", |
|
438 targetID: "input-text", eventType: "wheel", |
|
439 dispatchEvent: function () { |
|
440 document.getElementById(this.targetID).value = ""; |
|
441 synthesizeWheel(document.getElementById(this.targetID), 3, 4, |
|
442 { deltaY: 20, lineOrPageDeltaY: 1, altKey: true }); |
|
443 }, |
|
444 canRun: function () { |
|
445 return true; |
|
446 }, |
|
447 todoMismatch: [ ], |
|
448 }, |
|
449 { description: "WidgetWheelEvent (wheel, horizontal)", |
|
450 targetID: "input-text", eventType: "wheel", |
|
451 dispatchEvent: function () { |
|
452 document.getElementById(this.targetID).value = ""; |
|
453 synthesizeWheel(document.getElementById(this.targetID), 4, 5, |
|
454 { deltaX: 20, lineOrPageDeltaX: 1, ctrlKey: true }); |
|
455 }, |
|
456 canRun: function () { |
|
457 return true; |
|
458 }, |
|
459 todoMismatch: [ ], |
|
460 }, |
|
461 { description: "WidgetWheelEvent (wheel, both)", |
|
462 targetID: "input-text", eventType: "wheel", |
|
463 dispatchEvent: function () { |
|
464 document.getElementById(this.targetID).value = ""; |
|
465 synthesizeWheel(document.getElementById(this.targetID), 4, 5, |
|
466 { deltaX: 20, deltaY: 10, |
|
467 lineOrPageDeltaX: 1, lineOrPageDeltaY: 1 }); |
|
468 }, |
|
469 canRun: function () { |
|
470 return true; |
|
471 }, |
|
472 todoMismatch: [ ], |
|
473 }, |
|
474 { description: "WidgetTouchEvent (touchstart)", |
|
475 target: function () { return document; }, eventType: "touchstart", |
|
476 dispatchEvent: function () { |
|
477 synthesizeTouchAtPoint(1, 2, { id: 10, rx: 4, ry: 3, angle: 0, force: 1, shiftKey: true}); |
|
478 }, |
|
479 canRun: function () { |
|
480 return true; |
|
481 }, |
|
482 todoMismatch: [ ], |
|
483 }, |
|
484 { description: "WidgetTouchEvent (touchend)", |
|
485 target: function () { return document; }, eventType: "touchend", |
|
486 dispatchEvent: function () { |
|
487 synthesizeTouchAtPoint(4, 6, { id: 5, rx: 1, ry: 2, angle: 0.5, force: 0.8, ctrlKey: true}); |
|
488 }, |
|
489 canRun: function () { |
|
490 return true; |
|
491 }, |
|
492 todoMismatch: [ ], |
|
493 }, |
|
494 { description: "InternalFormEvent (reset)", |
|
495 targetID: "form", eventType: "reset", |
|
496 dispatchEvent: function () { |
|
497 document.getElementById("form").reset(); |
|
498 }, |
|
499 canRun: function () { |
|
500 return true; |
|
501 }, |
|
502 todoMismatch: [ ], |
|
503 }, |
|
504 { description: "WidgetCommandEvent", |
|
505 targetID: "input-text", eventType: "", |
|
506 dispatchEvent: function () { |
|
507 return; |
|
508 }, |
|
509 canRun: function () { |
|
510 todo(false, "WidgetCommandEvent isn't tested"); |
|
511 return false; |
|
512 }, |
|
513 todoMismatch: [], |
|
514 }, |
|
515 { description: "InternalClipboardEvent (copy)", |
|
516 targetID: "input-text", eventType: "copy", |
|
517 dispatchEvent: function () { |
|
518 document.getElementById("input-text").value = "go to clipboard!"; |
|
519 document.getElementById("input-text").focus(); |
|
520 document.getElementById("input-text").select(); |
|
521 synthesizeKey("c", { accelKey: true }); |
|
522 }, |
|
523 canRun: function () { |
|
524 return true; |
|
525 }, |
|
526 todoMismatch: [ ], |
|
527 }, |
|
528 { description: "InternalUIEvent (DOMActivate)", |
|
529 targetID: "button", eventType: "DOMActivate", |
|
530 dispatchEvent: function () { |
|
531 synthesizeMouseAtCenter(document.getElementById(this.targetID), |
|
532 { button: 0, shiftKey: true }); |
|
533 }, |
|
534 canRun: function () { |
|
535 return true; |
|
536 }, |
|
537 todoMismatch: [], |
|
538 }, |
|
539 { description: "InternalFocusEvent (focus)", |
|
540 targetID: "input-text", eventType: "focus", |
|
541 dispatchEvent: function () { |
|
542 document.getElementById(this.targetID).focus(); |
|
543 }, |
|
544 canRun: function () { |
|
545 return true; |
|
546 }, |
|
547 todoMismatch: [], |
|
548 }, |
|
549 { description: "InternalFocusEvent (blur)", |
|
550 targetID: "input-text", eventType: "blur", |
|
551 dispatchEvent: function () { |
|
552 document.getElementById(this.targetID).blur(); |
|
553 }, |
|
554 canRun: function () { |
|
555 return true; |
|
556 }, |
|
557 todoMismatch: [], |
|
558 }, |
|
559 { description: "WidgetSimpleGestureEvent", |
|
560 targetID: "", eventType: "", |
|
561 dispatchEvent: function () { |
|
562 return; |
|
563 }, |
|
564 canRun: function () { |
|
565 // Simple gesture event may be handled before it comes content. |
|
566 // So, we cannot test it in this test. |
|
567 todo(false, "WidgetSimpleGestureEvent isn't tested"); |
|
568 return false; |
|
569 }, |
|
570 todoMismatch: [], |
|
571 }, |
|
572 { description: "InternalTransitionEvent (transitionend)", |
|
573 targetID: "a", eventType: "transitionend", |
|
574 dispatchEvent: function () { |
|
575 document.getElementById(this.targetID).focus(); |
|
576 }, |
|
577 canRun: function () { |
|
578 return true; |
|
579 }, |
|
580 todoMismatch: [], |
|
581 }, |
|
582 { description: "InternalAnimationEvent (animationend)", |
|
583 targetID: "animated-div", eventType: "animationend", |
|
584 dispatchEvent: function () { |
|
585 document.getElementById(this.targetID).className = "slidin"; |
|
586 }, |
|
587 canRun: function () { |
|
588 return true; |
|
589 }, |
|
590 todoMismatch: [], |
|
591 }, |
|
592 { description: "InternalMutationEvent (DOMAttrModified)", |
|
593 targetID: "animated-div", eventType: "DOMAttrModified", |
|
594 dispatchEvent: function () { |
|
595 document.getElementById(this.targetID).setAttribute("x-data", "foo"); |
|
596 }, |
|
597 canRun: function () { |
|
598 return true; |
|
599 }, |
|
600 todoMismatch: [], |
|
601 }, |
|
602 { description: "InternalMutationEvent (DOMNodeInserted)", |
|
603 targetID: "animated-div", eventType: "DOMNodeInserted", |
|
604 dispatchEvent: function () { |
|
605 var div = document.createElement("div"); |
|
606 div.id = "inserted-div"; |
|
607 document.getElementById("animated-div").appendChild(div); |
|
608 }, |
|
609 canRun: function () { |
|
610 return true; |
|
611 }, |
|
612 todoMismatch: [], |
|
613 }, |
|
614 { description: "InternalMutationEvent (DOMNodeRemoved)", |
|
615 targetID: "animated-div", eventType: "DOMNodeRemoved", |
|
616 dispatchEvent: function () { |
|
617 document.getElementById("animated-div").removeChild(document.getElementById("inserted-div")); |
|
618 }, |
|
619 canRun: function () { |
|
620 return true; |
|
621 }, |
|
622 todoMismatch: [], |
|
623 }, |
|
624 ]; |
|
625 |
|
626 function doTest(aTest) |
|
627 { |
|
628 if (!aTest.canRun()) { |
|
629 SimpleTest.executeSoon(runNextTest); |
|
630 return; |
|
631 } |
|
632 gEvent = null; |
|
633 gCopiedEvent = []; |
|
634 var target = aTest.target ? aTest.target() : document.getElementById(aTest.targetID); |
|
635 target.addEventListener(aTest.eventType, onEvent, true); |
|
636 gCallback = function () { |
|
637 var description = aTest.description + " (gCallPreventDefault=" + gCallPreventDefault + ")"; |
|
638 target.removeEventListener(aTest.eventType, onEvent, true); |
|
639 ok(gEvent !== null, description + ": failed to get duplicated event"); |
|
640 ok(gCopiedEvent.length > 0, description + ": count of attribute of the event must be larger than 0"); |
|
641 for (var i = 0; i < gCopiedEvent.length; ++i) { |
|
642 var name = gCopiedEvent[i].name; |
|
643 if (name == "rangeOffset") { |
|
644 todo(false, description + ": " + name + " attribute value is never reset (" + gEvent[name] + ")"); |
|
645 } else if (name == "eventPhase") { |
|
646 is(gEvent[name], 0, description + ": mismatch with fixed value (" + name + ")"); |
|
647 } else if (name == "rangeParent" || name == "currentTarget") { |
|
648 is(gEvent[name], null, description + ": mismatch with fixed value (" + name + ")"); |
|
649 } else if (aTest.todoMismatch.indexOf(name) >= 0) { |
|
650 todo_is(gEvent[name], gCopiedEvent[i].value, description + ": mismatch (" + name + ")"); |
|
651 } else { |
|
652 is(gEvent[name], gCopiedEvent[i].value, description + ": mismatch (" + name + ")"); |
|
653 } |
|
654 } |
|
655 runNextTest(); |
|
656 }; |
|
657 aTest.dispatchEvent(); |
|
658 } |
|
659 |
|
660 var gIndex = -1; |
|
661 function runNextTest() |
|
662 { |
|
663 if (++gIndex == kTests.length) { |
|
664 if (gCallPreventDefault) { |
|
665 finish(); |
|
666 return; |
|
667 } |
|
668 // Test with a call of preventDefault() of the events. |
|
669 gCallPreventDefault = true; |
|
670 gIndex = -1; |
|
671 // Restoring the initial state of all elements. |
|
672 document.getElementById("scrollable-div").style.height = "30px"; |
|
673 document.getElementById("scrollable-div").style.width = "30px"; |
|
674 document.getElementById("scrolled-div").style.height = "10px"; |
|
675 document.getElementById("scrolled-div").style.width = "10px"; |
|
676 document.getElementById("input-text").value = ""; |
|
677 document.getElementById("animated-div").className = ""; |
|
678 document.getElementById("animated-div").removeAttribute("x-data"); |
|
679 if (document.activeElement) { |
|
680 document.activeElement.blur(); |
|
681 } |
|
682 window.requestAnimationFrame(function () { |
|
683 setTimeout(runNextTest, 0); |
|
684 }); |
|
685 return; |
|
686 } |
|
687 doTest(kTests[gIndex]); |
|
688 } |
|
689 |
|
690 function init() |
|
691 { |
|
692 SpecialPowers.setBoolPref("middlemouse.contentLoadURL", false); |
|
693 SpecialPowers.setBoolPref("middlemouse.paste", false); |
|
694 SpecialPowers.setBoolPref("general.autoScroll", false); |
|
695 SpecialPowers.setIntPref("mousewheel.default.action", 0); |
|
696 SpecialPowers.setIntPref("mousewheel.default.action.override_x", -1); |
|
697 SpecialPowers.setIntPref("mousewheel.with_shift.action", 0); |
|
698 SpecialPowers.setIntPref("mousewheel.with_shift.action.override_x", -1); |
|
699 SpecialPowers.setIntPref("mousewheel.with_control.action", 0); |
|
700 SpecialPowers.setIntPref("mousewheel.with_control.action.override_x", -1); |
|
701 SpecialPowers.setIntPref("mousewheel.with_alt.action", 0); |
|
702 SpecialPowers.setIntPref("mousewheel.with_alt.action.override_x", -1); |
|
703 SpecialPowers.setIntPref("mousewheel.with_meta.action", 0); |
|
704 SpecialPowers.setIntPref("mousewheel.with_meta.action.override_x", -1); |
|
705 |
|
706 runNextTest(); |
|
707 } |
|
708 |
|
709 function finish() |
|
710 { |
|
711 SpecialPowers.clearUserPref("middlemouse.contentLoadURL"); |
|
712 SpecialPowers.clearUserPref("middlemouse.paste"); |
|
713 SpecialPowers.clearUserPref("general.autoScroll"); |
|
714 SpecialPowers.clearUserPref("mousewheel.default.action"); |
|
715 SpecialPowers.clearUserPref("mousewheel.default.action.override_x"); |
|
716 SpecialPowers.clearUserPref("mousewheel.with_shift.action"); |
|
717 SpecialPowers.clearUserPref("mousewheel.with_shift.action.override_x"); |
|
718 SpecialPowers.clearUserPref("mousewheel.with_control.action"); |
|
719 SpecialPowers.clearUserPref("mousewheel.with_control.action.override_x"); |
|
720 SpecialPowers.clearUserPref("mousewheel.with_alt.action"); |
|
721 SpecialPowers.clearUserPref("mousewheel.with_alt.action.override_x"); |
|
722 SpecialPowers.clearUserPref("mousewheel.with_meta.action"); |
|
723 SpecialPowers.clearUserPref("mousewheel.with_meta.action.override_x"); |
|
724 |
|
725 SimpleTest.finish(); |
|
726 } |
|
727 |
|
728 SimpleTest.waitForFocus(init); |
|
729 |
|
730 </script> |
|
731 </body> |