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