dom/events/test/test_all_synthetic_events.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

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>Test all synthetic events</title>
michael@0 5 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 6 <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
michael@0 7 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
michael@0 8 </head>
michael@0 9 <body>
michael@0 10 <p id="display"></p>
michael@0 11 <div id="content" style="display: none">
michael@0 12 </div>
michael@0 13 <pre id="test">
michael@0 14 <script type="application/javascript">
michael@0 15
michael@0 16 /**
michael@0 17 * kEventConstructors is a helper and database of all events.
michael@0 18 * The sort order of the definition is by A to Z (ignore the Event postfix).
michael@0 19 *
michael@0 20 * XXX: should we move this into EventUtils.js?
michael@0 21 *
michael@0 22 * create: function or null. If this is null, it's impossible to create untrusted event for it.
michael@0 23 * Otherwise, create(aName, aProps) returns an instance of the event initialized with aProps.
michael@0 24 * aName specifies the event's type name. See each create() code for the detail of aProps.
michael@0 25 */
michael@0 26 const kEventConstructors = {
michael@0 27 Event: { create: function (aName, aProps) {
michael@0 28 return new Event(aName, aProps);
michael@0 29 },
michael@0 30 },
michael@0 31 AnimationEvent: { create: function (aName, aProps) {
michael@0 32 return new AnimationEvent(aName, aProps);
michael@0 33 },
michael@0 34 },
michael@0 35 AudioProcessingEvent: { create: null, // Cannot create untrusted event from JS.
michael@0 36 },
michael@0 37 BeforeUnloadEvent: { create: function (aName, aProps) {
michael@0 38 var e = document.createEvent("beforeunloadevent");
michael@0 39 e.initEvent(aName, aProps.bubbles, aProps.cancelable);
michael@0 40 return e;
michael@0 41 },
michael@0 42 },
michael@0 43 BlobEvent: { create: function (aName, aProps) {
michael@0 44 return new BlobEvent(aName, aProps);
michael@0 45 },
michael@0 46 },
michael@0 47 BluetoothDeviceEvent: { create: function (aName, aProps) {
michael@0 48 return new BluetoothDeviceEvent(aName, aProps);
michael@0 49 },
michael@0 50 },
michael@0 51 BluetoothStatusChangedEvent: { create: function (aName, aProps) {
michael@0 52 return new BluetoothStatusChangedEvent(aName, aProps);
michael@0 53 },
michael@0 54 },
michael@0 55 CallEvent: { create: function (aName, aProps) {
michael@0 56 return new CallEvent(aName, aProps);
michael@0 57 },
michael@0 58 },
michael@0 59 CallGroupErrorEvent: { create: function (aName, aProps) {
michael@0 60 return new CallGroupErrorEvent(aName, aProps);
michael@0 61 },
michael@0 62 },
michael@0 63 CFStateChangeEvent: { create: function (aName, aProps) {
michael@0 64 return new CFStateChangeEvent(aName, aProps);
michael@0 65 },
michael@0 66 },
michael@0 67 CloseEvent: { create: function (aName, aProps) {
michael@0 68 return new CloseEvent(aName, aProps);
michael@0 69 },
michael@0 70 },
michael@0 71 ClipboardEvent: { create: function (aName, aProps) {
michael@0 72 return new ClipboardEvent(aName, aProps);
michael@0 73 },
michael@0 74 },
michael@0 75 CommandEvent: { create: function (aName, aProps) {
michael@0 76 var e = document.createEvent("commandevent");
michael@0 77 e.initCommandEvent(aName, aProps.bubbles, aProps.cancelable,
michael@0 78 aProps.command);
michael@0 79 return e;
michael@0 80 },
michael@0 81 },
michael@0 82 CompositionEvent: { create: function (aName, aProps) {
michael@0 83 var e = document.createEvent("compositionevent");
michael@0 84 e.initCompositionEvent(aName, aProps.bubbles, aProps.cancelable,
michael@0 85 aProps.view, aProps.data, aProps.locale);
michael@0 86 return e;
michael@0 87 },
michael@0 88 },
michael@0 89 CustomEvent: { create: function (aName, aProps) {
michael@0 90 return new CustomEvent(aName, aProps);
michael@0 91 },
michael@0 92 },
michael@0 93 DataErrorEvent: { create: function (aName, aProps) {
michael@0 94 return new DataErrorEvent(aName, aProps);
michael@0 95 },
michael@0 96 },
michael@0 97 DataContainerEvent: { create: function (aName, aProps) {
michael@0 98 var e = document.createEvent("datacontainerevent");
michael@0 99 e.initEvent(aName, aProps.bubbles, aProps.cancelable);
michael@0 100 return e;
michael@0 101 },
michael@0 102 },
michael@0 103 DataStoreChangeEvent: { create: function (aName, aProps) {
michael@0 104 return new DataStoreChangeEvent(aProps);
michael@0 105 },
michael@0 106 },
michael@0 107 DeviceLightEvent: { create: function (aName, aProps) {
michael@0 108 return new DeviceLightEvent(aName, aProps);
michael@0 109 },
michael@0 110 },
michael@0 111 DeviceMotionEvent: { create: function (aName, aProps) {
michael@0 112 var e = document.createEvent("devicemotionevent");
michael@0 113 e.initDeviceMotionEvent(aName, aProps.bubbles, aProps.cancelable, aProps.acceleration,
michael@0 114 aProps.accelerationIncludingGravity, aProps.rotationRate,
michael@0 115 aProps.interval || 0.0);
michael@0 116 return e;
michael@0 117 },
michael@0 118 },
michael@0 119 DeviceOrientationEvent: { create: function (aName, aProps) {
michael@0 120 return new DeviceOrientationEvent(aName, aProps);
michael@0 121 },
michael@0 122 },
michael@0 123 DeviceProximityEvent: { create: function (aName, aProps) {
michael@0 124 return new DeviceProximityEvent(aName, aProps);
michael@0 125 },
michael@0 126 },
michael@0 127 DeviceStorageChangeEvent: { create: function (aName, aProps) {
michael@0 128 return new DeviceStorageChangeEvent(aName, aProps);
michael@0 129 },
michael@0 130 },
michael@0 131 DownloadEvent: { create: function (aName, aProps) {
michael@0 132 return new DownloadEvent(aName, aProps);
michael@0 133 },
michael@0 134 },
michael@0 135 DOMTransactionEvent: { create: function (aName, aProps) {
michael@0 136 return new DOMTransactionEvent(aName, aProps);
michael@0 137 },
michael@0 138 },
michael@0 139 DragEvent: { create: function (aName, aProps) {
michael@0 140 var e = document.createEvent("dragevent");
michael@0 141 e.initDragEvent(aName, aProps.bubbles, aProps.cancelable,
michael@0 142 aProps.view, aProps.detail,
michael@0 143 aProps.screenX, aProps.screenY,
michael@0 144 aProps.clientX, aProps.clientY,
michael@0 145 aProps.ctrlKey, aProps.altKey, aProps.shiftKey, aProps.metaKey,
michael@0 146 aProps.button, aProps.relatedTarget, aProps.dataTransfer);
michael@0 147 return e;
michael@0 148 },
michael@0 149 },
michael@0 150 ErrorEvent: { create: function (aName, aProps) {
michael@0 151 return new ErrorEvent(aName, aProps);
michael@0 152 },
michael@0 153 },
michael@0 154 ElementReplaceEvent: { create: function (aName, aProps) {
michael@0 155 return new ElementReplaceEvent(aName, aProps);
michael@0 156 },
michael@0 157 },
michael@0 158 FocusEvent: { create: function (aName, aProps) {
michael@0 159 return new FocusEvent(aName, aProps);
michael@0 160 },
michael@0 161 },
michael@0 162 GamepadEvent: { create: function (aName, aProps) {
michael@0 163 return new GamepadEvent(aName, aProps);
michael@0 164 },
michael@0 165 },
michael@0 166 GamepadAxisMoveEvent: { create: function (aName, aProps) {
michael@0 167 return new GamepadAxisMoveEvent(aName, aProps);
michael@0 168 },
michael@0 169 },
michael@0 170 GamepadButtonEvent: { create: function (aName, aProps) {
michael@0 171 return new GamepadButtonEvent(aName, aProps);
michael@0 172 },
michael@0 173 },
michael@0 174 HashChangeEvent: { create: function (aName, aProps) {
michael@0 175 return new HashChangeEvent(aName, aProps);
michael@0 176 },
michael@0 177 },
michael@0 178 IccChangeEvent: { create: function (aName, aProps) {
michael@0 179 return new IccChangeEvent(aName, aProps);
michael@0 180 },
michael@0 181 },
michael@0 182 IDBVersionChangeEvent: { create: function (aName, aProps) {
michael@0 183 return new IDBVersionChangeEvent(aName, aProps);
michael@0 184 },
michael@0 185 },
michael@0 186 InputEvent: { create: function (aName, aProps) {
michael@0 187 return new InputEvent(aName, aProps);
michael@0 188 },
michael@0 189 },
michael@0 190 KeyEvent: { create: function (aName, aProps) {
michael@0 191 return new KeyboardEvent(aName, aProps);
michael@0 192 },
michael@0 193 },
michael@0 194 KeyboardEvent: { create: function (aName, aProps) {
michael@0 195 return new KeyboardEvent(aName, aProps);
michael@0 196 },
michael@0 197 },
michael@0 198 MediaStreamEvent: { create: function (aName, aProps) {
michael@0 199 return new MediaStreamEvent(aName, aProps);
michael@0 200 },
michael@0 201 },
michael@0 202 MessageEvent: { create: function (aName, aProps) {
michael@0 203 var e = new MessageEvent("messageevent", { bubbles: aProps.bubbles,
michael@0 204 cancelable: aProps.cancelable, data: aProps.data, origin: aProps.origin,
michael@0 205 lastEventId: aProps.lastEventId, source: aProps.source });
michael@0 206 return e;
michael@0 207 },
michael@0 208 },
michael@0 209 MouseEvent: { create: function (aName, aProps) {
michael@0 210 return new MouseEvent(aName, aProps);
michael@0 211 },
michael@0 212 },
michael@0 213 MouseScrollEvent: { create: function (aName, aProps) {
michael@0 214 var e = document.createEvent("mousescrollevents");
michael@0 215 e.initMouseScrollEvent(aName, aProps.bubbles, aProps.cancelable,
michael@0 216 aProps.view, aProps.detail,
michael@0 217 aProps.screenX, aProps.screenY,
michael@0 218 aProps.clientX, aProps.clientY,
michael@0 219 aProps.ctrlKey, aProps.altKey, aProps.shiftKey, aProps.metaKey,
michael@0 220 aProps.button, aProps.relatedTarget, aProps.axis);
michael@0 221 return e;
michael@0 222 },
michael@0 223 },
michael@0 224 MozApplicationEvent: { create: function (aName, aProps) {
michael@0 225 return new MozApplicationEvent(aName, aProps);
michael@0 226 },
michael@0 227 },
michael@0 228 MozCellBroadcastEvent: { create: function (aName, aProps) {
michael@0 229 return new MozCellBroadcastEvent(aName, aProps);
michael@0 230 },
michael@0 231 },
michael@0 232 MozContactChangeEvent: { create: function (aName, aProps) {
michael@0 233 return new MozContactChangeEvent(aName, aProps);
michael@0 234 },
michael@0 235 },
michael@0 236 MozEmergencyCbModeEvent: { create: function (aName, aProps) {
michael@0 237 return new MozEmergencyCbModeEvent(aName, aProps);
michael@0 238 },
michael@0 239 },
michael@0 240 MozMmsEvent: { create: function (aName, aProps) {
michael@0 241 return new MozMmsEvent(aName, aProps);
michael@0 242 },
michael@0 243 },
michael@0 244 MozOtaStatusEvent: { create: function (aName, aProps) {
michael@0 245 return new MozOtaStatusEvent(aName, aProps);
michael@0 246 },
michael@0 247 },
michael@0 248 MozSettingsEvent: { create: function (aName, aProps) {
michael@0 249 return new MozSettingsEvent(aName, aProps);
michael@0 250 },
michael@0 251 },
michael@0 252 MozSmsEvent: { create: function (aName, aProps) {
michael@0 253 return new MozSmsEvent(aName, aProps);
michael@0 254 },
michael@0 255 },
michael@0 256 MozStkCommandEvent: { create: function (aName, aProps) {
michael@0 257 return new MozStkCommandEvent(aName, aProps);
michael@0 258 },
michael@0 259 },
michael@0 260 MozVoicemailEvent: { create: function (aName, aProps) {
michael@0 261 return new MozVoicemailEvent(aName, aProps);
michael@0 262 },
michael@0 263 },
michael@0 264 MozWifiConnectionInfoEvent: { create: function (aName, aProps) {
michael@0 265 return new MozWifiConnectionInfoEvent(aName, aProps);
michael@0 266 },
michael@0 267 },
michael@0 268 MozWifiStatusChangeEvent: { create: function (aName, aProps) {
michael@0 269 return new MozWifiStatusChangeEvent(aName, aProps);
michael@0 270 },
michael@0 271 },
michael@0 272 MutationEvent: { create: function (aName, aProps) {
michael@0 273 var e = document.createEvent("mutationevent");
michael@0 274 e.initMutationEvent(aName, aProps.bubbles, aProps.cancelable,
michael@0 275 aProps.relatedNode, aProps.prevValue, aProps.newValue,
michael@0 276 aProps.attrName, aProps.attrChange);
michael@0 277 return e;
michael@0 278 },
michael@0 279 },
michael@0 280 NotifyPaintEvent: { create: function (aName, aProps) {
michael@0 281 var e = document.createEvent("notifypaintevent");
michael@0 282 e.initEvent(aName, aProps.bubbles, aProps.cancelable);
michael@0 283 return e;
michael@0 284 },
michael@0 285 },
michael@0 286 OfflineAudioCompletionEvent: { create: null, // Cannot create untrusted event from JS.
michael@0 287 },
michael@0 288 PageTransitionEvent: { create: function (aName, aProps) {
michael@0 289 return new PageTransitionEvent(aName, aProps);
michael@0 290 },
michael@0 291 },
michael@0 292 PointerEvent: { create: function (aName, aProps) {
michael@0 293 return new PointerEvent(aName, aProps);
michael@0 294 },
michael@0 295 },
michael@0 296 PopStateEvent: { create: function (aName, aProps) {
michael@0 297 return new PopStateEvent(aName, aProps);
michael@0 298 },
michael@0 299 },
michael@0 300 PopupBlockedEvent: { create: function (aName, aProps) {
michael@0 301 return new PopupBlockedEvent(aName, aProps);
michael@0 302 },
michael@0 303 },
michael@0 304 ProgressEvent: { create: function (aName, aProps) {
michael@0 305 return new ProgressEvent(aName, aProps);
michael@0 306 },
michael@0 307 },
michael@0 308 RecordErrorEvent: { create: function (aName, aProps) {
michael@0 309 return new RecordErrorEvent(aName, aProps);
michael@0 310 },
michael@0 311 },
michael@0 312 RTCDataChannelEvent: { create: function (aName, aProps) {
michael@0 313 return new RTCDataChannelEvent(aName, aProps);
michael@0 314 },
michael@0 315 },
michael@0 316 RTCPeerConnectionIceEvent: { create: function (aName, aProps) {
michael@0 317 return new RTCPeerConnectionIceEvent(aName, aProps);
michael@0 318 },
michael@0 319 },
michael@0 320 RTCPeerConnectionIdentityEvent: { create: function (aName, aProps) {
michael@0 321 return new RTCPeerConnectionIdentityEvent(aName, aProps);
michael@0 322 },
michael@0 323 },
michael@0 324 RTCPeerConnectionIdentityErrorEvent: { create: function (aName, aProps) {
michael@0 325 return new RTCPeerConnectionIdentityErrorEvent(aName, aProps);
michael@0 326 },
michael@0 327 },
michael@0 328 ScrollAreaEvent: { create: function (aName, aProps) {
michael@0 329 var e = document.createEvent("scrollareaevent");
michael@0 330 e.initScrollAreaEvent(aName, aProps.bubbles, aProps.cancelable,
michael@0 331 aProps.view, aProps.details,
michael@0 332 aProps.x || 0.0, aProps.y || 0.0,
michael@0 333 aProps.width || 0.0, aProps.height || 0.0);
michael@0 334 return e;
michael@0 335 },
michael@0 336 },
michael@0 337 SimpleGestureEvent: { create: function (aName, aProps) {
michael@0 338 var e = document.createEvent("simplegestureevent");
michael@0 339 e.initSimpleGestureEvent(aName, aProps.bubbles, aProps.cancelable,
michael@0 340 aProps.view, aProps.detail,
michael@0 341 aProps.screenX, aProps.screenY,
michael@0 342 aProps.clientX, aProps.clientY,
michael@0 343 aProps.ctrlKey, aProps.altKey, aProps.shiftKey, aProps.metaKey,
michael@0 344 aProps.button, aProps.relatedTarget,
michael@0 345 aProps.allowedDirections, aProps.direction, aProps.delta || 0.0,
michael@0 346 aProps.clickCount);
michael@0 347 return e;
michael@0 348 },
michael@0 349 },
michael@0 350 SmartCardEvent: { create: function (aName, aProps) {
michael@0 351 return new SmartCardEvent(aName, aProps);
michael@0 352 },
michael@0 353 },
michael@0 354 SpeechRecognitionEvent: { create: function (aName, aProps) {
michael@0 355 return new SpeechRecognitionEvent(aName, aProps);
michael@0 356 },
michael@0 357 },
michael@0 358 SpeechSynthesisEvent: { create: function (aName, aProps) {
michael@0 359 return new SpeechSynthesisEvent(aName, aProps);
michael@0 360 },
michael@0 361 },
michael@0 362 StorageEvent: { create: function (aName, aProps) {
michael@0 363 return new StorageEvent(aName, aProps);
michael@0 364 },
michael@0 365 },
michael@0 366 StyleRuleChangeEvent: { create: function (aName, aProps) {
michael@0 367 return new StyleRuleChangeEvent(aName, aProps);
michael@0 368 },
michael@0 369 chromeOnly: true,
michael@0 370 },
michael@0 371 StyleSheetApplicableStateChangeEvent: { create: function (aName, aProps) {
michael@0 372 return new StyleSheetApplicableStateChangeEvent(aName, aProps);
michael@0 373 },
michael@0 374 chromeOnly: true,
michael@0 375 },
michael@0 376 StyleSheetChangeEvent: { create: function (aName, aProps) {
michael@0 377 return new StyleSheetChangeEvent(aName, aProps);
michael@0 378 },
michael@0 379 chromeOnly: true,
michael@0 380 },
michael@0 381 SVGZoomEvent: { create: function (aName, aProps) {
michael@0 382 var e = document.createEvent("svgzoomevent");
michael@0 383 e.initUIEvent(aName, aProps.bubbles, aProps.cancelable,
michael@0 384 aProps.view, aProps.detail);
michael@0 385 return e;
michael@0 386 },
michael@0 387 },
michael@0 388 TimeEvent: { create: function (aName, aProps) {
michael@0 389 var e = document.createEvent("timeevent");
michael@0 390 e.initTimeEvent(aName, aProps.view, aProps.detail);
michael@0 391 return e;
michael@0 392 },
michael@0 393 },
michael@0 394 TouchEvent: { create: function (aName, aProps) {
michael@0 395 var e = document.createEvent("touchevent");
michael@0 396 e.initTouchEvent(aName, aProps.bubbles, aProps.cancelable,
michael@0 397 aProps.view, aProps.detail,
michael@0 398 aProps.ctrlKey, aProps.altKey, aProps.shiftKey, aProps.metaKey,
michael@0 399 aProps.touches, aProps.targetTouches, aProps.changedTouches);
michael@0 400 return e;
michael@0 401 },
michael@0 402 },
michael@0 403 TrackEvent: { create: function (aName, aProps) {
michael@0 404 return new TrackEvent(aName, aProps);
michael@0 405 },
michael@0 406 },
michael@0 407 TransitionEvent: { create: function (aName, aProps) {
michael@0 408 return new TransitionEvent(aName, aProps);
michael@0 409 },
michael@0 410 },
michael@0 411 UIEvent: { create: function (aName, aProps) {
michael@0 412 return new UIEvent(aName, aProps);
michael@0 413 },
michael@0 414 },
michael@0 415 UserProximityEvent: { create: function (aName, aProps) {
michael@0 416 return new UserProximityEvent(aName, aProps);
michael@0 417 },
michael@0 418 },
michael@0 419 USSDReceivedEvent: { create: function (aName, aProps) {
michael@0 420 return new USSDReceivedEvent(aName, aProps);
michael@0 421 },
michael@0 422 },
michael@0 423 WheelEvent: { create: function (aName, aProps) {
michael@0 424 return new WheelEvent(aName, aProps);
michael@0 425 },
michael@0 426 },
michael@0 427 };
michael@0 428
michael@0 429 for (var name of Object.keys(kEventConstructors)) {
michael@0 430 if (!kEventConstructors[name].chromeOnly) {
michael@0 431 continue;
michael@0 432 }
michael@0 433 if (window[name]) {
michael@0 434 ok(false, name + " should be chrome only.");
michael@0 435 }
michael@0 436 window[name] = SpecialPowers.unwrap(SpecialPowers.wrap(window)[name]);
michael@0 437 }
michael@0 438
michael@0 439 var props = Object.getOwnPropertyNames(window);
michael@0 440 for (var i = 0; i < props.length; i++) {
michael@0 441 // Assume that event object must be named as "FooBarEvent".
michael@0 442 if (!props[i].match(/^([A-Z][a-zA-Z]+)?Event$/)) {
michael@0 443 continue;
michael@0 444 }
michael@0 445 if (!kEventConstructors[props[i]]) {
michael@0 446 ok(false, "Unknown event found: " + props[i]);
michael@0 447 continue;
michael@0 448 }
michael@0 449 if (!kEventConstructors[props[i]].create) {
michael@0 450 todo(false, "Cannot create untrusted event of " + props[i]);
michael@0 451 continue;
michael@0 452 }
michael@0 453 ok(true, "Creating " + props[i] + "...");
michael@0 454 var event = kEventConstructors[props[i]].create("foo", {});
michael@0 455 if (!event) {
michael@0 456 ok(false, "Failed to create untrusted event: " + props[i]);
michael@0 457 continue;
michael@0 458 }
michael@0 459 if (typeof(event.getModifierState) == "function") {
michael@0 460 const kModifiers = [ "Shift", "Control", "Alt", "AltGr", "Meta", "CapsLock", "ScrollLock", "NumLock", "OS", "Fn", "SymbolLock" ];
michael@0 461 for (var j = 0; j < kModifiers.length; j++) {
michael@0 462 ok(true, "Calling " + props[i] + ".getModifierState(" + kModifiers[j] + ")...");
michael@0 463 var modifierState = event.getModifierState(kModifiers[j]);
michael@0 464 ok(true, props[i] + ".getModifierState(" + kModifiers[j] + ") = " + modifierState);
michael@0 465 }
michael@0 466 }
michael@0 467 }
michael@0 468
michael@0 469 </script>
michael@0 470 </pre>
michael@0 471 </body>
michael@0 472 </html>

mercurial