dom/events/test/test_eventctors.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <!--
michael@0 4 https://bugzilla.mozilla.org/show_bug.cgi?id=675884
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <title>Test for Bug 675884</title>
michael@0 8 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
michael@0 10 </head>
michael@0 11 <body>
michael@0 12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=675884">Mozilla Bug 675884</a>
michael@0 13 <p id="display"></p>
michael@0 14 <div id="content" style="display: none">
michael@0 15
michael@0 16 </div>
michael@0 17 <pre id="test">
michael@0 18 <script type="application/javascript">
michael@0 19
michael@0 20 /** Test for Bug 675884 **/
michael@0 21
michael@0 22 var receivedEvent;
michael@0 23 document.addEventListener("hello", function(e) { receivedEvent = e; }, true);
michael@0 24
michael@0 25 // Event
michael@0 26 var e;
michael@0 27 var ex = false;
michael@0 28 try {
michael@0 29 e = new Event();
michael@0 30 } catch(exp) {
michael@0 31 ex = true;
michael@0 32 }
michael@0 33 ok(ex, "First parameter is required!");
michael@0 34 ex = false;
michael@0 35
michael@0 36 try {
michael@0 37 e = new Event("foo", 123);
michael@0 38 } catch(exp) {
michael@0 39 ex = true;
michael@0 40 }
michael@0 41 ok(ex, "2nd parameter should be an object!");
michael@0 42 ex = false;
michael@0 43
michael@0 44 try {
michael@0 45 e = new Event("foo", "asdf");
michael@0 46 } catch(exp) {
michael@0 47 ex = true;
michael@0 48 }
michael@0 49 ok(ex, "2nd parameter should be an object!");
michael@0 50 ex = false;
michael@0 51
michael@0 52
michael@0 53 try {
michael@0 54 e = new Event("foo", false);
michael@0 55 } catch(exp) {
michael@0 56 ex = true;
michael@0 57 }
michael@0 58 ok(ex, "2nd parameter should be an object!");
michael@0 59 ex = false;
michael@0 60
michael@0 61
michael@0 62 e = new Event("hello");
michael@0 63 is(e.type, "hello", "Wrong event type!");
michael@0 64 ok(!e.isTrusted, "Event shouldn't be trusted!");
michael@0 65 e.isTrusted = true;
michael@0 66 ok(!e.isTrusted, "Event shouldn't be trusted!");
michael@0 67
michael@0 68 try {
michael@0 69 e.__defineGetter__("isTrusted", function() { return true });
michael@0 70 } catch (exp) {
michael@0 71 ex = true;
michael@0 72 }
michael@0 73 ok(ex, "Shouldn't be able to re-define the getter for isTrusted.");
michael@0 74 ex = false;
michael@0 75 ok(!e.isTrusted, "Event shouldn't be trusted!");
michael@0 76
michael@0 77 ok(!("isTrusted" in Object.getPrototypeOf(e)))
michael@0 78
michael@0 79 ok(!e.bubbles, "Event shouldn't bubble!");
michael@0 80 ok(!e.cancelable, "Event shouldn't be cancelable!");
michael@0 81 is(e.eventPhase, Event.NONE, "Wrong event phase");
michael@0 82 document.dispatchEvent(e);
michael@0 83 is(e.eventPhase, Event.NONE, "Wrong event phase");
michael@0 84 is(receivedEvent, e, "Wrong event!");
michael@0 85
michael@0 86 e = new Event("hello", null);
michael@0 87 is(e.type, "hello", "Wrong event type!");
michael@0 88 ok(!e.isTrusted, "Event shouldn't be trusted!");
michael@0 89 ok(!e.bubbles, "Event shouldn't bubble!");
michael@0 90 ok(!e.cancelable, "Event shouldn't be cancelable!");
michael@0 91 is(e.eventPhase, Event.NONE, "Wrong event phase");
michael@0 92 document.dispatchEvent(e);
michael@0 93 is(e.eventPhase, Event.NONE, "Wrong event phase");
michael@0 94 is(receivedEvent, e, "Wrong event!");
michael@0 95
michael@0 96 e = new Event("hello", undefined);
michael@0 97 is(e.type, "hello", "Wrong event type!");
michael@0 98 ok(!e.isTrusted, "Event shouldn't be trusted!");
michael@0 99 ok(!e.bubbles, "Event shouldn't bubble!");
michael@0 100 ok(!e.cancelable, "Event shouldn't be cancelable!");
michael@0 101 is(e.eventPhase, Event.NONE, "Wrong event phase");
michael@0 102 document.dispatchEvent(e);
michael@0 103 is(e.eventPhase, Event.NONE, "Wrong event phase");
michael@0 104 is(receivedEvent, e, "Wrong event!");
michael@0 105
michael@0 106 e = new Event("hello", {});
michael@0 107 is(e.type, "hello", "Wrong event type!");
michael@0 108 ok(!e.isTrusted, "Event shouldn't be trusted!");
michael@0 109 ok(!e.bubbles, "Event shouldn't bubble!");
michael@0 110 ok(!e.cancelable, "Event shouldn't be cancelable!");
michael@0 111 is(e.eventPhase, Event.NONE, "Wrong event phase");
michael@0 112 document.dispatchEvent(e);
michael@0 113 is(e.eventPhase, Event.NONE, "Wrong event phase");
michael@0 114 is(receivedEvent, e, "Wrong event!");
michael@0 115
michael@0 116 e = new Event("hello", { bubbles: true, cancelable: true });
michael@0 117 is(e.type, "hello", "Wrong event type!");
michael@0 118 ok(!e.isTrusted, "Event shouldn't be trusted!");
michael@0 119 ok(e.bubbles, "Event should bubble!");
michael@0 120 ok(e.cancelable, "Event should be cancelable!");
michael@0 121 document.dispatchEvent(e);
michael@0 122 is(receivedEvent, e, "Wrong event!");
michael@0 123
michael@0 124 // CustomEvent
michael@0 125
michael@0 126 try {
michael@0 127 e = new CustomEvent();
michael@0 128 } catch(exp) {
michael@0 129 ex = true;
michael@0 130 }
michael@0 131 ok(ex, "First parameter is required!");
michael@0 132 ex = false;
michael@0 133
michael@0 134 e = new CustomEvent("hello");
michael@0 135 is(e.type, "hello", "Wrong event type!");
michael@0 136 ok(!e.isTrusted, "Event shouldn't be trusted!");
michael@0 137 ok(!e.bubbles, "Event shouldn't bubble!");
michael@0 138 ok(!e.cancelable, "Event shouldn't be cancelable!");
michael@0 139 document.dispatchEvent(e);
michael@0 140 is(receivedEvent, e, "Wrong event!");
michael@0 141
michael@0 142 e = new CustomEvent("hello", { bubbles: true, cancelable: true, detail: window });
michael@0 143 is(e.type, "hello", "Wrong event type!");
michael@0 144 ok(!e.isTrusted, "Event shouldn't be trusted!");
michael@0 145 ok(e.bubbles, "Event should bubble!");
michael@0 146 ok(e.cancelable, "Event should be cancelable!");
michael@0 147 is(e.detail, window , "Wrong event.detail!");
michael@0 148 document.dispatchEvent(e);
michael@0 149 is(receivedEvent, e, "Wrong event!");
michael@0 150
michael@0 151 e = new CustomEvent("hello", { cancelable: true, detail: window });
michael@0 152 is(e.type, "hello", "Wrong event type!");
michael@0 153 ok(!e.isTrusted, "Event shouldn't be trusted!");
michael@0 154 ok(!e.bubbles, "Event shouldn't bubble!");
michael@0 155 ok(e.cancelable, "Event should be cancelable!");
michael@0 156 is(e.detail, window , "Wrong event.detail!");
michael@0 157
michael@0 158 e = new CustomEvent("hello", { detail: 123 });
michael@0 159 is(e.detail, 123, "Wrong event.detail!");
michael@0 160 ok(!e.bubbles, "Event shouldn't bubble!");
michael@0 161 ok(!e.cancelable, "Event shouldn't be cancelable!");
michael@0 162
michael@0 163 var dict = { get detail() { return document.body } };
michael@0 164 e = new CustomEvent("hello", dict);
michael@0 165 is(e.detail, dict.detail, "Wrong event.detail!");
michael@0 166 ok(!e.bubbles, "Event shouldn't bubble!");
michael@0 167 ok(!e.cancelable, "Event shouldn't be cancelable!");
michael@0 168
michael@0 169 var dict = { get detail() { throw "foo"; } };
michael@0 170
michael@0 171 try {
michael@0 172 e = new CustomEvent("hello", dict);
michael@0 173 } catch (exp) {
michael@0 174 ex = true;
michael@0 175 }
michael@0 176 ok(ex, "Should have thrown an exception!");
michael@0 177 ex = false;
michael@0 178
michael@0 179 // BlobEvent
michael@0 180
michael@0 181 try {
michael@0 182 e = new BlobEvent();
michael@0 183 } catch(exp) {
michael@0 184 ex = true;
michael@0 185 }
michael@0 186 ok(ex, "First parameter is required!");
michael@0 187 ex = false;
michael@0 188
michael@0 189 e = new BlobEvent("hello");
michael@0 190 is(e.type, "hello", "Wrong event type!");
michael@0 191 ok(!e.isTrusted, "Event shouldn't be trusted!");
michael@0 192 try {
michael@0 193 e.__defineGetter__("isTrusted", function() { return true });
michael@0 194 } catch (exp) {
michael@0 195 ex = true;
michael@0 196 }
michael@0 197 ok(ex, "Shouldn't be able to re-define the getter for isTrusted.");
michael@0 198 ex = false;
michael@0 199 ok(!e.isTrusted, "BlobEvent shouldn't be trusted!");
michael@0 200
michael@0 201 ok(!e.bubbles, "Event shouldn't bubble!");
michael@0 202 ok(!e.cancelable, "Event shouldn't be cancelable!");
michael@0 203 document.dispatchEvent(e);
michael@0 204 is(receivedEvent, e, "Wrong event!");
michael@0 205
michael@0 206 var blob = Blob();
michael@0 207 e = new BlobEvent("hello", { bubbles: true, cancelable: true, data: blob });
michael@0 208 is(e.type, "hello", "Wrong event type!");
michael@0 209 ok(!e.isTrusted, "Event shouldn't be trusted!");
michael@0 210 ok(e.bubbles, "Event should bubble!");
michael@0 211 ok(e.cancelable, "Event should be cancelable!");
michael@0 212 is(e.data, blob , "Wrong event.data!");
michael@0 213 document.dispatchEvent(e);
michael@0 214 is(receivedEvent, e, "Wrong event!");
michael@0 215
michael@0 216
michael@0 217 e = new BlobEvent("hello", {data: blob});
michael@0 218 is(e.type, "hello", "Wrong event type!");
michael@0 219 ok(!e.isTrusted, "Event shouldn't be trusted!");
michael@0 220 ok(!e.bubbles, "Event shouldn't bubble!");
michael@0 221 ok(!e.cancelable, "Event should be cancelable1!");
michael@0 222 is(e.data, blob , "Wrong event.data!");
michael@0 223
michael@0 224 e = new BlobEvent("hello", { data: null });
michael@0 225 is(e.data, null, "Wrong event.data!");
michael@0 226 ok(!e.bubbles, "Event shouldn't bubble!");
michael@0 227 ok(!e.cancelable, "Event shouldn't be cancelable!");
michael@0 228 blob = null;
michael@0 229 // CloseEvent
michael@0 230
michael@0 231 try {
michael@0 232 e = new CloseEvent();
michael@0 233 } catch(exp) {
michael@0 234 ex = true;
michael@0 235 }
michael@0 236 ok(ex, "First parameter is required!");
michael@0 237 ex = false;
michael@0 238
michael@0 239 e = new CloseEvent("hello");
michael@0 240 is(e.type, "hello", "Wrong event type!");
michael@0 241 ok(!e.isTrusted, "Event shouldn't be trusted!");
michael@0 242 ok(!e.bubbles, "Event shouldn't bubble!");
michael@0 243 ok(!e.cancelable, "Event shouldn't be cancelable!");
michael@0 244 is(e.wasClean, false, "wasClean should be false!");
michael@0 245 is(e.code, 0, "code should be 0!");
michael@0 246 is(e.reason, "", "reason should be ''!");
michael@0 247 document.dispatchEvent(e);
michael@0 248 is(receivedEvent, e, "Wrong event!");
michael@0 249
michael@0 250 e = new CloseEvent("hello",
michael@0 251 { bubbles: true, cancelable: true, wasClean: true, code: 1, reason: "foo" });
michael@0 252 is(e.type, "hello", "Wrong event type!");
michael@0 253 ok(!e.isTrusted, "Event shouldn't be trusted!");
michael@0 254 ok(e.bubbles, "Event should bubble!");
michael@0 255 ok(e.cancelable, "Event should be cancelable!");
michael@0 256 is(e.wasClean, true, "wasClean should be true!");
michael@0 257 is(e.code, 1, "code should be 1!");
michael@0 258 is(e.reason, "foo", "reason should be 'foo'!");
michael@0 259 document.dispatchEvent(e);
michael@0 260 is(receivedEvent, e, "Wrong event!");
michael@0 261
michael@0 262 e = new CloseEvent("hello",
michael@0 263 { bubbles: true, cancelable: true, wasClean: true, code: 1 });
michael@0 264 is(e.type, "hello", "Wrong event type!");
michael@0 265 ok(!e.isTrusted, "Event shouldn't be trusted!");
michael@0 266 ok(e.bubbles, "Event should bubble!");
michael@0 267 ok(e.cancelable, "Event should be cancelable!");
michael@0 268 is(e.wasClean, true, "wasClean should be true!");
michael@0 269 is(e.code, 1, "code should be 1!");
michael@0 270 is(e.reason, "", "reason should be ''!");
michael@0 271 document.dispatchEvent(e);
michael@0 272 is(receivedEvent, e, "Wrong event!");
michael@0 273
michael@0 274
michael@0 275 // HashChangeEvent
michael@0 276
michael@0 277 try {
michael@0 278 e = new HashChangeEvent();
michael@0 279 } catch(exp) {
michael@0 280 ex = true;
michael@0 281 }
michael@0 282 ok(ex, "First parameter is required!");
michael@0 283 ex = false;
michael@0 284
michael@0 285 e = new HashChangeEvent("hello");
michael@0 286 is(e.type, "hello", "Wrong event type!");
michael@0 287 ok(!e.isTrusted, "Event shouldn't be trusted!");
michael@0 288 ok(!e.bubbles, "Event shouldn't bubble!");
michael@0 289 ok(!e.cancelable, "Event shouldn't be cancelable!");
michael@0 290 is(e.oldURL, "", "oldURL should be ''");
michael@0 291 is(e.newURL, "", "newURL should be ''");
michael@0 292 document.dispatchEvent(e);
michael@0 293 is(receivedEvent, e, "Wrong event!");
michael@0 294
michael@0 295 e = new HashChangeEvent("hello",
michael@0 296 { bubbles: true, cancelable: true, oldURL: "old", newURL: "new" });
michael@0 297 is(e.type, "hello", "Wrong event type!");
michael@0 298 ok(!e.isTrusted, "Event shouldn't be trusted!");
michael@0 299 ok(e.bubbles, "Event should bubble!");
michael@0 300 ok(e.cancelable, "Event should be cancelable!");
michael@0 301 is(e.oldURL, "old", "oldURL should be 'old'");
michael@0 302 is(e.newURL, "new", "newURL should be 'new'");
michael@0 303 document.dispatchEvent(e);
michael@0 304 is(receivedEvent, e, "Wrong event!");
michael@0 305
michael@0 306 e = new HashChangeEvent("hello",
michael@0 307 { bubbles: true, cancelable: true, newURL: "new" });
michael@0 308 is(e.type, "hello", "Wrong event type!");
michael@0 309 ok(!e.isTrusted, "Event shouldn't be trusted!");
michael@0 310 ok(e.bubbles, "Event should bubble!");
michael@0 311 ok(e.cancelable, "Event should be cancelable!");
michael@0 312 is(e.oldURL, "", "oldURL should be ''");
michael@0 313 is(e.newURL, "new", "newURL should be 'new'");
michael@0 314 document.dispatchEvent(e);
michael@0 315 is(receivedEvent, e, "Wrong event!");
michael@0 316
michael@0 317 // InputEvent
michael@0 318
michael@0 319 e = new InputEvent("hello");
michael@0 320 is(e.type, "hello", "Wrong event type!");
michael@0 321 ok(!e.isTrusted, "Event shouldn't be trusted!");
michael@0 322 ok(!e.bubbles, "Event shouldn't bubble!");
michael@0 323 ok(!e.cancelable, "Event shouldn't be cancelable!");
michael@0 324 is(e.detail, 0, "detail should be 0");
michael@0 325 ok(!e.isComposing, "isComposing should be false");
michael@0 326
michael@0 327 e = new InputEvent("hi!", { bubbles: true, detail: 5, isComposing: false });
michael@0 328 is(e.type, "hi!", "Wrong event type!");
michael@0 329 ok(!e.isTrusted, "Event shouldn't be trusted!");
michael@0 330 ok(e.bubbles, "Event should bubble!");
michael@0 331 ok(!e.cancelable, "Event shouldn't be cancelable!");
michael@0 332 is(e.detail, 5, "detail should be 5");
michael@0 333 ok(!e.isComposing, "isComposing should be false");
michael@0 334
michael@0 335 e = new InputEvent("hi!", { cancelable: true, detail: 0, isComposing: true });
michael@0 336 is(e.type, "hi!", "Wrong event type!");
michael@0 337 ok(!e.isTrusted, "Event shouldn't be trusted!");
michael@0 338 ok(!e.bubbles, "Event shouldn't bubble!");
michael@0 339 ok(e.cancelable, "Event should be cancelable!");
michael@0 340 is(e.detail, 0, "detail should be 0");
michael@0 341 ok(e.isComposing, "isComposing should be true");
michael@0 342
michael@0 343 // KeyboardEvent
michael@0 344
michael@0 345 try {
michael@0 346 e = new KeyboardEvent();
michael@0 347 } catch(exp) {
michael@0 348 ex = true;
michael@0 349 }
michael@0 350 ok(ex, "KeyboardEvent: First parameter is required!");
michael@0 351 ex = false;
michael@0 352
michael@0 353 e = new KeyboardEvent("hello");
michael@0 354 ok(e.type, "hello", "KeyboardEvent: Wrong event type!");
michael@0 355 ok(!e.isTrusted, "KeyboardEvent: Event shouldn't be trusted!");
michael@0 356 ok(!e.bubbles, "KeyboardEvent: Event shouldn't bubble!");
michael@0 357 ok(!e.cancelable, "KeyboardEvent: Event shouldn't be cancelable!");
michael@0 358 document.dispatchEvent(e);
michael@0 359 is(receivedEvent, e, "KeyboardEvent: Wrong event!");
michael@0 360
michael@0 361 var keyboardEventProps =
michael@0 362 [
michael@0 363 { bubbles: false },
michael@0 364 { cancelable: false },
michael@0 365 { view: null },
michael@0 366 { detail: 0 },
michael@0 367 { key: "" },
michael@0 368 { location: 0 },
michael@0 369 { ctrlKey: false },
michael@0 370 { shiftKey: false },
michael@0 371 { altKey: false },
michael@0 372 { metaKey: false },
michael@0 373 { repeat: false },
michael@0 374 { isComposing: false },
michael@0 375 { charCode: 0 },
michael@0 376 { keyCode: 0 },
michael@0 377 { which: 0 },
michael@0 378 ];
michael@0 379
michael@0 380 var testKeyboardProps =
michael@0 381 [
michael@0 382 { bubbles: true },
michael@0 383 { cancelable: true },
michael@0 384 { view: window },
michael@0 385 { detail: 1 },
michael@0 386 { key: "CustomKey" },
michael@0 387 { location: 1 },
michael@0 388 { ctrlKey: true },
michael@0 389 { shiftKey: true },
michael@0 390 { altKey: true },
michael@0 391 { metaKey: true },
michael@0 392 { repeat: true },
michael@0 393 { isComposing: true },
michael@0 394 { charCode: 2 },
michael@0 395 { keyCode: 3 },
michael@0 396 { which: 4 },
michael@0 397 { charCode: 5, which: 6 },
michael@0 398 { keyCode: 7, which: 8 },
michael@0 399 { keyCode: 9, charCode: 10 },
michael@0 400 { keyCode: 11, charCode: 12, which: 13 },
michael@0 401 ];
michael@0 402
michael@0 403 var defaultKeyboardEventValues = {};
michael@0 404 for (var i = 0; i < keyboardEventProps.length; ++i) {
michael@0 405 for (prop in keyboardEventProps[i]) {
michael@0 406 ok(prop in e, "keyboardEvent: KeyboardEvent doesn't have property " + prop + "!");
michael@0 407 defaultKeyboardEventValues[prop] = keyboardEventProps[i][prop];
michael@0 408 }
michael@0 409 }
michael@0 410
michael@0 411 while (testKeyboardProps.length) {
michael@0 412 var p = testKeyboardProps.shift();
michael@0 413 e = new KeyboardEvent("foo", p);
michael@0 414 for (var def in defaultKeyboardEventValues) {
michael@0 415 if (!(def in p)) {
michael@0 416 is(e[def], defaultKeyboardEventValues[def],
michael@0 417 "KeyboardEvent: Wrong default value for " + def + "!");
michael@0 418 } else {
michael@0 419 is(e[def], p[def],
michael@0 420 "KeyboardEvent: Wrong event init value for " + def + "!");
michael@0 421 }
michael@0 422 }
michael@0 423 }
michael@0 424
michael@0 425 // PageTransitionEvent
michael@0 426
michael@0 427 try {
michael@0 428 e = new PageTransitionEvent();
michael@0 429 } catch(exp) {
michael@0 430 ex = true;
michael@0 431 }
michael@0 432 ok(ex, "First parameter is required!");
michael@0 433 ex = false;
michael@0 434
michael@0 435 e = new PageTransitionEvent("hello");
michael@0 436 is(e.type, "hello", "Wrong event type!");
michael@0 437 ok(!e.isTrusted, "Event shouldn't be trusted!");
michael@0 438 ok(!e.bubbles, "Event shouldn't bubble!");
michael@0 439 ok(!e.cancelable, "Event shouldn't be cancelable!");
michael@0 440 is(e.persisted, false, "persisted should be false");
michael@0 441 document.dispatchEvent(e);
michael@0 442 is(receivedEvent, e, "Wrong event!");
michael@0 443
michael@0 444 e = new PageTransitionEvent("hello",
michael@0 445 { bubbles: true, cancelable: true, persisted: true});
michael@0 446 is(e.type, "hello", "Wrong event type!");
michael@0 447 ok(!e.isTrusted, "Event shouldn't be trusted!");
michael@0 448 ok(e.bubbles, "Event should bubble!");
michael@0 449 ok(e.cancelable, "Event should be cancelable!");
michael@0 450 is(e.persisted, true, "persisted should be true");
michael@0 451 document.dispatchEvent(e);
michael@0 452 is(receivedEvent, e, "Wrong event!");
michael@0 453
michael@0 454 e = new PageTransitionEvent("hello", { persisted: true});
michael@0 455 is(e.type, "hello", "Wrong event type!");
michael@0 456 ok(!e.isTrusted, "Event shouldn't be trusted!");
michael@0 457 ok(!e.bubbles, "Event shouldn't bubble!");
michael@0 458 ok(!e.cancelable, "Event shouldn't be cancelable!");
michael@0 459 is(e.persisted, true, "persisted should be true");
michael@0 460 document.dispatchEvent(e);
michael@0 461 is(receivedEvent, e, "Wrong event!");
michael@0 462
michael@0 463 // PopStateEvent
michael@0 464
michael@0 465 try {
michael@0 466 e = new PopStateEvent();
michael@0 467 } catch(exp) {
michael@0 468 ex = true;
michael@0 469 }
michael@0 470 ok(ex, "First parameter is required!");
michael@0 471 ex = false;
michael@0 472
michael@0 473 e = new PopStateEvent("hello");
michael@0 474 is(e.type, "hello", "Wrong event type!");
michael@0 475 ok(!e.isTrusted, "Event shouldn't be trusted!");
michael@0 476 ok(!e.bubbles, "Event shouldn't bubble!");
michael@0 477 ok(!e.cancelable, "Event shouldn't be cancelable!");
michael@0 478 is(e.state, null, "persisted should be null");
michael@0 479 document.dispatchEvent(e);
michael@0 480 is(receivedEvent, e, "Wrong event!");
michael@0 481
michael@0 482 e = new PopStateEvent("hello",
michael@0 483 { bubbles: true, cancelable: true, state: window});
michael@0 484 is(e.type, "hello", "Wrong event type!");
michael@0 485 ok(!e.isTrusted, "Event shouldn't be trusted!");
michael@0 486 ok(e.bubbles, "Event should bubble!");
michael@0 487 ok(e.cancelable, "Event should be cancelable!");
michael@0 488 is(e.state, window, "persisted should be window");
michael@0 489 document.dispatchEvent(e);
michael@0 490 is(receivedEvent, e, "Wrong event!");
michael@0 491
michael@0 492
michael@0 493 e = new PopStateEvent("hello", { state: window});
michael@0 494 is(e.type, "hello", "Wrong event type!");
michael@0 495 ok(!e.isTrusted, "Event shouldn't be trusted!");
michael@0 496 ok(!e.bubbles, "Event shouldn't bubble!");
michael@0 497 ok(!e.cancelable, "Event shouldn't be cancelable!");
michael@0 498 is(e.state, window, "persisted should be window");
michael@0 499 document.dispatchEvent(e);
michael@0 500 is(receivedEvent, e, "Wrong event!");
michael@0 501
michael@0 502 // UIEvent
michael@0 503
michael@0 504 try {
michael@0 505 e = new UIEvent();
michael@0 506 } catch(exp) {
michael@0 507 ex = true;
michael@0 508 }
michael@0 509 ok(ex, "First parameter is required!");
michael@0 510 ex = false;
michael@0 511
michael@0 512 try {
michael@0 513 e = new UIEvent("foo", { view: {} });
michael@0 514 e.view.onunload;
michael@0 515 } catch(exp) {
michael@0 516 ex = true;
michael@0 517 }
michael@0 518 ok(ex, "{} isn't a valid value.");
michael@0 519 ex = false;
michael@0 520
michael@0 521 try {
michael@0 522 e = new UIEvent("foo", { view: null });
michael@0 523 } catch(exp) {
michael@0 524 ex = true;
michael@0 525 }
michael@0 526 ok(!ex, "null is a valid value.");
michael@0 527 is(e.view, null);
michael@0 528 ex = false;
michael@0 529
michael@0 530 e = new UIEvent("hello");
michael@0 531 is(e.type, "hello", "Wrong event type!");
michael@0 532 ok(!e.isTrusted, "Event shouldn't be trusted!");
michael@0 533 ok(!e.bubbles, "Event shouldn't bubble!");
michael@0 534 ok(!e.cancelable, "Event shouldn't be cancelable!");
michael@0 535 is(e.detail, 0, "detail should be 0");
michael@0 536 is(e.view, null, "view should be null");
michael@0 537 document.dispatchEvent(e);
michael@0 538 is(receivedEvent, e, "Wrong event!");
michael@0 539
michael@0 540 e = new UIEvent("hello",
michael@0 541 { bubbles: true, cancelable: true, view: window, detail: 1});
michael@0 542 is(e.type, "hello", "Wrong event type!");
michael@0 543 ok(!e.isTrusted, "Event shouldn't be trusted!");
michael@0 544 ok(e.bubbles, "Event should bubble!");
michael@0 545 ok(e.cancelable, "Event should be cancelable!");
michael@0 546 is(e.detail, 1, "detail should be 1");
michael@0 547 is(e.view, window, "view should be window");
michael@0 548 document.dispatchEvent(e);
michael@0 549 is(receivedEvent, e, "Wrong event!");
michael@0 550
michael@0 551 // StorageEvent
michael@0 552
michael@0 553 e = document.createEvent("StorageEvent");
michael@0 554 ok(e, "Should have created an event!");
michael@0 555
michael@0 556 try {
michael@0 557 e = new StorageEvent();
michael@0 558 } catch(exp) {
michael@0 559 ex = true;
michael@0 560 }
michael@0 561 ok(ex, "First parameter is required!");
michael@0 562 ex = false;
michael@0 563
michael@0 564 e = new StorageEvent("hello");
michael@0 565 is(e.type, "hello", "Wrong event type!");
michael@0 566 ok(!e.isTrusted, "Event shouldn't be trusted!");
michael@0 567 ok(!e.bubbles, "Event shouldn't bubble!");
michael@0 568 ok(!e.cancelable, "Event shouldn't be cancelable!");
michael@0 569 is(e.key, null, "key should be null");
michael@0 570 is(e.oldValue, null, "oldValue should be null");
michael@0 571 is(e.newValue, null, "newValue should be null");
michael@0 572 is(e.url, "", "url should be ''");
michael@0 573 document.dispatchEvent(e);
michael@0 574 is(receivedEvent, e, "Wrong event!");
michael@0 575
michael@0 576 e = new StorageEvent("hello",
michael@0 577 { bubbles: true, cancelable: true, key: "key",
michael@0 578 oldValue: "oldValue", newValue: "newValue", url: "url",
michael@0 579 storageArea: localStorage });
michael@0 580 is(e.type, "hello", "Wrong event type!");
michael@0 581 ok(!e.isTrusted, "Event shouldn't be trusted!");
michael@0 582 ok(e.bubbles, "Event should bubble!");
michael@0 583 ok(e.cancelable, "Event should be cancelable!");
michael@0 584 is(e.key, "key", "Wrong value");
michael@0 585 is(e.oldValue, "oldValue", "Wrong value");
michael@0 586 is(e.newValue, "newValue", "Wrong value");
michael@0 587 is(e.url, "url", "Wrong value");
michael@0 588 is(e.storageArea, localStorage, "Wrong value");
michael@0 589 document.dispatchEvent(e);
michael@0 590 is(receivedEvent, e, "Wrong event!");
michael@0 591
michael@0 592 // DeviceProximityEvent
michael@0 593 e = new DeviceProximityEvent("hello", {min: 0, value: 1, max: 2});
michael@0 594 is(e.type, "hello", "Wrong event type!");
michael@0 595 ok(!e.isTrusted, "Event should not be trusted");
michael@0 596 is(e.value, 1, "value should be 1");
michael@0 597 is(e.min, 0, "min should be 0");
michael@0 598 is(e.max, 2, "max should be 2");
michael@0 599 document.dispatchEvent(e);
michael@0 600 is(receivedEvent, e, "Wrong event!");
michael@0 601 e = new DeviceProximityEvent("hello");
michael@0 602 is(e.value, Infinity, "Uninitialized value should be infinity");
michael@0 603 is(e.min, -Infinity, "Uninitialized min should be -infinity");
michael@0 604 is(e.max, Infinity, "Uninitialized max should be infinity");
michael@0 605
michael@0 606 // UserProximityEvent
michael@0 607 e = new UserProximityEvent("hello", {near: true});
michael@0 608 is(e.type, "hello", "Wrong event type!");
michael@0 609 ok(!e.isTrusted, "Event should not be trusted");
michael@0 610 is(e.near, true, "near should be true");
michael@0 611 document.dispatchEvent(e);
michael@0 612 is(receivedEvent, e, "Wrong event!");
michael@0 613
michael@0 614 // DeviceLightEvent
michael@0 615 e = new DeviceLightEvent("hello", {value: 1} );
michael@0 616 is(e.type, "hello", "Wrong event type!");
michael@0 617 ok(!e.isTrusted, "Event should not be trusted");
michael@0 618 is(e.value, 1, "value should be 1");
michael@0 619 document.dispatchEvent(e);
michael@0 620 is(receivedEvent, e, "Wrong event!");
michael@0 621 e = new DeviceLightEvent("hello", {value: Infinity} );
michael@0 622 is(e.value, Infinity, "value should be positive infinity");
michael@0 623 e = new DeviceLightEvent("hello", {value: -Infinity} );
michael@0 624 is(e.value, -Infinity, "value should be negative infinity");
michael@0 625 e = new DeviceLightEvent("hello");
michael@0 626 is(e.value, Infinity, "Uninitialized value should be positive infinity");
michael@0 627
michael@0 628 // DeviceOrientationEvent
michael@0 629 e = new DeviceOrientationEvent("hello");
michael@0 630 is(e.type, "hello", "Wrong event type!");
michael@0 631 ok(!e.isTrusted, "Event should not be trusted");
michael@0 632 is(e.alpha, 0);
michael@0 633 is(e.beta, 0);
michael@0 634 is(e.gamma, 0);
michael@0 635 is(e.absolute, false);
michael@0 636
michael@0 637 e = new DeviceOrientationEvent("hello", { alpha: 1, beta: 2, gamma: 3, absolute: true } );
michael@0 638 is(e.type, "hello", "Wrong event type!");
michael@0 639 ok(!e.isTrusted, "Event should not be trusted");
michael@0 640 is(e.alpha, 1);
michael@0 641 is(e.beta, 2);
michael@0 642 is(e.gamma, 3);
michael@0 643 is(e.absolute, true);
michael@0 644 document.dispatchEvent(e);
michael@0 645 is(receivedEvent, e, "Wrong event!");
michael@0 646
michael@0 647 // MouseEvent
michael@0 648
michael@0 649 try {
michael@0 650 e = new MouseEvent();
michael@0 651 } catch(exp) {
michael@0 652 ex = true;
michael@0 653 }
michael@0 654 ok(ex, "MouseEvent: First parameter is required!");
michael@0 655 ex = false;
michael@0 656
michael@0 657 e = new MouseEvent("hello");
michael@0 658 is(e.type, "hello", "MouseEvent: Wrong event type!");
michael@0 659 ok(!e.isTrusted, "MouseEvent: Event shouldn't be trusted!");
michael@0 660 ok(!e.bubbles, "MouseEvent: Event shouldn't bubble!");
michael@0 661 ok(!e.cancelable, "MouseEvent: Event shouldn't be cancelable!");
michael@0 662 document.dispatchEvent(e);
michael@0 663 is(receivedEvent, e, "MouseEvent: Wrong event!");
michael@0 664
michael@0 665 var mouseEventProps =
michael@0 666 [ { screenX: 0 },
michael@0 667 { screenY: 0 },
michael@0 668 { clientX: 0 },
michael@0 669 { clientY: 0 },
michael@0 670 { ctrlKey: false },
michael@0 671 { shiftKey: false },
michael@0 672 { altKey: false },
michael@0 673 { metaKey: false },
michael@0 674 { button: 0 },
michael@0 675 { buttons: 0 },
michael@0 676 { relatedTarget: null }
michael@0 677 ];
michael@0 678
michael@0 679 var testProps =
michael@0 680 [
michael@0 681 { screenX: 1 },
michael@0 682 { screenY: 2 },
michael@0 683 { clientX: 3 },
michael@0 684 { clientY: 4 },
michael@0 685 { ctrlKey: true },
michael@0 686 { shiftKey: true },
michael@0 687 { altKey: true },
michael@0 688 { metaKey: true },
michael@0 689 { button: 5 },
michael@0 690 { buttons: 6 },
michael@0 691 { relatedTarget: window }
michael@0 692 ];
michael@0 693
michael@0 694 var defaultMouseEventValues = {};
michael@0 695 for (var i = 0; i < mouseEventProps.length; ++i) {
michael@0 696 for (prop in mouseEventProps[i]) {
michael@0 697 ok(prop in e, "MouseEvent: MouseEvent doesn't have property " + prop + "!");
michael@0 698 defaultMouseEventValues[prop] = mouseEventProps[i][prop];
michael@0 699 }
michael@0 700 }
michael@0 701
michael@0 702 while (testProps.length) {
michael@0 703 var p = testProps.shift();
michael@0 704 e = new MouseEvent("foo", p);
michael@0 705 for (var def in defaultMouseEventValues) {
michael@0 706 if (!(def in p)) {
michael@0 707 is(e[def], defaultMouseEventValues[def],
michael@0 708 "MouseEvent: Wrong default value for " + def + "!");
michael@0 709 } else {
michael@0 710 is(e[def], p[def], "MouseEvent: Wrong event init value for " + def + "!");
michael@0 711 }
michael@0 712 }
michael@0 713 }
michael@0 714
michael@0 715 // PopupBlockedEvent
michael@0 716
michael@0 717 try {
michael@0 718 e = new PopupBlockedEvent();
michael@0 719 } catch(exp) {
michael@0 720 ex = true;
michael@0 721 }
michael@0 722 ok(ex, "PopupBlockedEvent: First parameter is required!");
michael@0 723 ex = false;
michael@0 724
michael@0 725 e = new PopupBlockedEvent("hello");
michael@0 726 is(e.type, "hello", "PopupBlockedEvent: Wrong event type!");
michael@0 727 ok(!e.isTrusted, "PopupBlockedEvent: Event shouldn't be trusted!");
michael@0 728 ok(!e.bubbles, "PopupBlockedEvent: Event shouldn't bubble!");
michael@0 729 ok(!e.cancelable, "PopupBlockedEvent: Event shouldn't be cancelable!");
michael@0 730 document.dispatchEvent(e);
michael@0 731 is(receivedEvent, e, "PopupBlockedEvent: Wrong event!");
michael@0 732
michael@0 733 e = new PopupBlockedEvent("hello",
michael@0 734 { requestingWindow: window,
michael@0 735 popupWindowFeatures: "features",
michael@0 736 popupWindowName: "name"
michael@0 737 });
michael@0 738 is(e.requestingWindow, window);
michael@0 739 is(e.popupWindowFeatures, "features");
michael@0 740 is(e.popupWindowName, "name");
michael@0 741
michael@0 742
michael@0 743 // SmartCardEvent
michael@0 744
michael@0 745 try {
michael@0 746 e = new SmartCardEvent();
michael@0 747 } catch(exp) {
michael@0 748 ex = true;
michael@0 749 }
michael@0 750 ok(ex, "SmartCardEvent: First parameter is required!");
michael@0 751 ex = false;
michael@0 752
michael@0 753 e = new SmartCardEvent("hello");
michael@0 754 is(e.type, "hello", "SmartCardEvent: Wrong event type!");
michael@0 755 ok(!e.isTrusted, "SmartCardEvent: Event shouldn't be trusted!");
michael@0 756 ok(!e.bubbles, "SmartCardEvent: Event shouldn't bubble!");
michael@0 757 ok(!e.cancelable, "SmartCardEvent: Event shouldn't be cancelable!");
michael@0 758 is(e.tokenName, "");
michael@0 759 document.dispatchEvent(e);
michael@0 760 is(receivedEvent, e, "SmartCardEvent: Wrong event!");
michael@0 761
michael@0 762 e = new SmartCardEvent("hello", { tokenName: "foo" });
michael@0 763 is(e.tokenName, "foo");
michael@0 764
michael@0 765 // WheelEvent
michael@0 766
michael@0 767 try {
michael@0 768 e = new WheelEvent();
michael@0 769 } catch(exp) {
michael@0 770 ex = true;
michael@0 771 }
michael@0 772 ok(ex, "WheelEvent: First parameter is required!");
michael@0 773 ex = false;
michael@0 774
michael@0 775 e = new WheelEvent("hello");
michael@0 776 is(e.type, "hello", "WheelEvent: Wrong event type!");
michael@0 777 ok(!e.isTrusted, "WheelEvent: Event shouldn't be trusted!");
michael@0 778 ok(!e.bubbles, "WheelEvent: Event shouldn't bubble!");
michael@0 779 ok(!e.cancelable, "WheelEvent: Event shouldn't be cancelable!");
michael@0 780 document.dispatchEvent(e);
michael@0 781 is(receivedEvent, e, "WheelEvent: Wrong event!");
michael@0 782
michael@0 783 var wheelEventProps =
michael@0 784 [ { screenX: 0 },
michael@0 785 { screenY: 0 },
michael@0 786 { clientX: 0 },
michael@0 787 { clientY: 0 },
michael@0 788 { ctrlKey: false },
michael@0 789 { shiftKey: false },
michael@0 790 { altKey: false },
michael@0 791 { metaKey: false },
michael@0 792 { button: 0 },
michael@0 793 { buttons: 0 },
michael@0 794 { relatedTarget: null },
michael@0 795 { deltaX: 0.0 },
michael@0 796 { deltaY: 0.0 },
michael@0 797 { deltaZ: 0.0 },
michael@0 798 { deltaMode: 0 }
michael@0 799 ];
michael@0 800
michael@0 801 var testWheelProps =
michael@0 802 [
michael@0 803 { screenX: 1 },
michael@0 804 { screenY: 2 },
michael@0 805 { clientX: 3 },
michael@0 806 { clientY: 4 },
michael@0 807 { ctrlKey: true },
michael@0 808 { shiftKey: true },
michael@0 809 { altKey: true },
michael@0 810 { metaKey: true },
michael@0 811 { button: 5 },
michael@0 812 { buttons: 6 },
michael@0 813 { relatedTarget: window },
michael@0 814 { deltaX: 7.8 },
michael@0 815 { deltaY: 9.1 },
michael@0 816 { deltaZ: 2.3 },
michael@0 817 { deltaMode: 4 }
michael@0 818 ];
michael@0 819
michael@0 820 var defaultWheelEventValues = {};
michael@0 821 for (var i = 0; i < wheelEventProps.length; ++i) {
michael@0 822 for (prop in wheelEventProps[i]) {
michael@0 823 ok(prop in e, "WheelEvent: WheelEvent doesn't have property " + prop + "!");
michael@0 824 defaultWheelEventValues[prop] = wheelEventProps[i][prop];
michael@0 825 }
michael@0 826 }
michael@0 827
michael@0 828 while (testWheelProps.length) {
michael@0 829 var p = testWheelProps.shift();
michael@0 830 e = new WheelEvent("foo", p);
michael@0 831 for (var def in defaultWheelEventValues) {
michael@0 832 if (!(def in p)) {
michael@0 833 is(e[def], defaultWheelEventValues[def],
michael@0 834 "WheelEvent: Wrong default value for " + def + "!");
michael@0 835 } else {
michael@0 836 is(e[def], p[def], "WheelEvent: Wrong event init value for " + def + "!");
michael@0 837 }
michael@0 838 }
michael@0 839 }
michael@0 840
michael@0 841 // TransitionEvent
michael@0 842 e = new TransitionEvent("hello", { propertyName: "color", elapsedTime: 3.5, pseudoElement: "", foobar: "baz" })
michael@0 843 is("propertyName" in e, true, "Transition events have propertyName property");
michael@0 844 is("foobar" in e, false, "Transition events do not copy random properties from event init");
michael@0 845 is(e.propertyName, "color", "Transition event copies propertyName from TransitionEventInit");
michael@0 846 is(e.elapsedTime, 3.5, "Transition event copies elapsedTime from TransitionEventInit");
michael@0 847 is(e.pseudoElement, "", "Transition event copies pseudoElement from TransitionEventInit");
michael@0 848 is(e.bubbles, false, "Lack of bubbles property in TransitionEventInit");
michael@0 849 is(e.cancelable, false, "Lack of cancelable property in TransitionEventInit");
michael@0 850 is(e.type, "hello", "Wrong event type!");
michael@0 851 is(e.isTrusted, false, "Event shouldn't be trusted!");
michael@0 852 is(e.eventPhase, Event.NONE, "Wrong event phase");
michael@0 853
michael@0 854 // AnimationEvent
michael@0 855 e = new AnimationEvent("hello", { animationName: "bounce3", elapsedTime: 3.5, pseudoElement: "", foobar: "baz" })
michael@0 856 is("animationName" in e, true, "Animation events have animationName property");
michael@0 857 is("foobar" in e, false, "Animation events do not copy random properties from event init");
michael@0 858 is(e.animationName, "bounce3", "Animation event copies animationName from AnimationEventInit");
michael@0 859 is(e.elapsedTime, 3.5, "Animation event copies elapsedTime from AnimationEventInit");
michael@0 860 is(e.pseudoElement, "", "Animation event copies pseudoElement from AnimationEventInit");
michael@0 861 is(e.bubbles, false, "Lack of bubbles property in AnimationEventInit");
michael@0 862 is(e.cancelable, false, "Lack of cancelable property in AnimationEventInit");
michael@0 863 is(e.type, "hello", "Wrong event type!");
michael@0 864 is(e.isTrusted, false, "Event shouldn't be trusted!");
michael@0 865 is(e.eventPhase, Event.NONE, "Wrong event phase");
michael@0 866
michael@0 867 </script>
michael@0 868 </pre>
michael@0 869 </body>
michael@0 870 </html>

mercurial