2 * Copyright 2017 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 var test_content_loaded = (function() {
22 function unexpected_call() {
23 ok(false, "unexpected call");
26 function record_call(msg) {
27 return function() { calls += msg + "," };
30 window.addEventListener("DOMContentLoaded", record_call("window.capture"), true);
31 window.addEventListener("DOMContentLoaded", record_call("window.bubble"), false);
32 document.addEventListener("DOMContentLoaded", record_call("document.capture"), true);
33 document.addEventListener("DOMContentLoaded", record_call("document.bubble"), false);
35 document.attachEvent("onDOMContentLoaded", unexpected_call);
36 document.attachEvent("DOMContentLoaded", unexpected_call);
39 ok(calls === "window.capture,document.capture,document.bubble,window.bubble,",
45 function test_listener_order() {
46 document.body.innerHTML = '<div></div>';
47 var div = document.body.firstChild;
50 function record_call(msg) {
51 return function() { calls += msg + "," };
54 window.addEventListener("click", record_call("window.click(capture)"), true);
55 window.addEventListener("click", record_call("window.click(bubble)"), false);
57 document.attachEvent("onclick", record_call("document.click(attached)"));
58 document.addEventListener("click", record_call("document.click(capture)"), true);
59 document.addEventListener("click", record_call("document.click(bubble)"), false);
60 document.onclick = record_call("document.onclick");
62 document.body.onclick = record_call("body.onclick");
63 document.body.addEventListener("click", record_call("body.click(capture)"), true);
64 document.body.addEventListener("click", record_call("body.click(bubble)"), false);
65 document.body.addEventListener("click", record_call("body.click(bubble2)"));
66 document.body.attachEvent("onclick", record_call("body.click(attached)"));
68 div.attachEvent("onclick", record_call("div.click(attached)"));
69 div.addEventListener("click", record_call("div.click(bubble)"), false);
70 div.onclick = record_call("div.onclick");
71 div.addEventListener("click", record_call("div.click(capture1)"), true);
72 div.addEventListener("click", record_call("div.click(capture2)"), true);
76 ok(calls === "window.click(capture),document.click(capture),body.click(capture),"
77 + "div.click(attached),div.click(bubble),div.onclick,div.click(capture1),"
78 + "div.click(capture2),body.onclick,body.click(bubble),body.click(bubble2),"
79 + "body.click(attached),document.click(attached),document.click(bubble),"
80 + "document.onclick,window.click(bubble),", "calls = " + calls);
82 div.onclick = record_call("new div.onclick");
86 ok(calls === "window.click(capture),document.click(capture),body.click(capture),"
87 + "div.click(attached),div.click(bubble),new div.onclick,div.click(capture1),"
88 + "div.click(capture2),body.onclick,body.click(bubble),body.click(bubble2),"
89 + "body.click(attached),document.click(attached),document.click(bubble),"
90 + "document.onclick,window.click(bubble),", "calls = " + calls);
92 var e = document.createEvent("Event");
93 e.initEvent("click", true, true);
97 ok(calls === "window.click(capture),document.click(capture),body.click(capture),"
98 + "div.click(bubble),new div.onclick,div.click(capture1),div.click(capture2),"
99 + "body.onclick,body.click(bubble),body.click(bubble2),document.click(bubble),"
100 + "document.onclick,window.click(bubble),", "calls = " + calls);
105 function test_add_listener_in_listener() {
108 document.body.innerHTML = '<div><div></div></div>';
109 var div1 = document.body.firstChild;
110 var div2 = div1.firstChild;
112 function record_call(msg) {
113 return function() { calls += msg + "," };
116 div1.addEventListener("click", function() {
117 div2.addEventListener("click", function() {
118 calls += "div2.click";
119 /* if we add more listeners here, whey won't be invoked */
120 div2.onclick = function() { calls += "click2,"; };
121 div2.addEventListener("click", function() { calls += "click3,"; }, false);
122 div2.attachEvent("onclick", function() { calls += "click4,"; });
128 ok(calls === "div2.click", "calls = " + calls);
133 function test_remove_listener_in_listener() {
136 document.body.innerHTML = '<div></div>';
137 var div = document.body.firstChild;
139 function record_call(msg) {
140 return function() { calls += msg + "," };
143 var capture = record_call("capture"), bubble = record_call("bubble");
145 div.addEventListener("click", function() {
146 div.removeEventListener("click", capture, true);
147 div.removeEventListener("click", bubble, false);
151 div.addEventListener("click", capture, true);
152 div.addEventListener("click", bubble, false);
153 div.onclick = record_call("onclick");
157 ok(calls === "remove,capture,bubble,onclick,", "calls = " + calls);
162 function test_add_remove_listener() {
165 document.body.innerHTML = '<div></div>';
166 var div = document.body.firstChild;
168 function listener() {
169 calls += "listener,";
172 /* if the same listener is added twice, second one won't be called */
173 div.addEventListener("click", listener, false);
174 div.addEventListener("click", listener, false);
178 ok(calls === "listener,", "calls = " + calls);
180 /* remove capture listener, it won't do anything */
181 div.removeEventListener("click", listener, true);
185 ok(calls === "listener,", "calls = " + calls);
187 /* remove listener once, it won't called anymore */
188 div.removeEventListener("click", listener, false);
192 ok(calls === "", "calls = " + calls);
194 div.removeEventListener("click", listener, false);
196 /* test implicit capture removeEventListener argument */
197 div.addEventListener("click", listener, false);
198 div.removeEventListener("click", listener);
202 ok(calls === "", "calls = " + calls);
207 function test_event_phase() {
208 document.body.innerHTML = '<div><div></div></div>';
209 var div1 = document.body.firstChild;
210 var div2 = div1.firstChild;
213 function check_phase(expected_phase) {
216 ok(last_event === e, "last_event != e");
219 ok(e.eventPhase === expected_phase,
220 "eventPhase = " + e.eventPhase + " expedted " + expected_phase);
224 div1.addEventListener("click", check_phase(1), true);
225 div1.addEventListener("click", check_phase(3), false);
226 div1.onclick = check_phase(3);
227 div2.addEventListener("click", check_phase(2), true);
228 div2.addEventListener("click", check_phase(2), false);
229 div2.onclick = check_phase(2);
232 ok(last_event.eventPhase === 3, "last_event.eventPhase = " + last_event.eventPhase);
237 function test_stop_propagation() {
238 document.body.innerHTML = '<div><div></div></div>';
239 var div1 = document.body.firstChild;
240 var div2 = div1.firstChild;
243 function record_call(msg) {
244 return function() { calls += msg + "," };
247 function stop_propagation(e) {
250 ok(e.bubbles === true, "bubbles = " + e.bubbles);
251 ok(e.defaultPrevented === false, "defaultPrevented = " + e.defaultPrevented);
254 function stop_immediate_propagation(e) {
255 calls += "immediateStop,";
256 e.stopImmediatePropagation();
257 ok(e.bubbles === true, "bubbles = " + e.bubbles);
258 ok(e.cancelable === true, "cancelable = " + e.cancelable);
259 ok(e.defaultPrevented === false, "defaultPrevented = " + e.defaultPrevented);
262 div1.addEventListener("click", stop_immediate_propagation, true);
263 div1.addEventListener("click", stop_propagation, true);
264 div1.addEventListener("click", record_call("div1.click(capture)"), true);
266 div2.addEventListener("click", stop_immediate_propagation, true);
267 div2.addEventListener("click", stop_propagation, true);
268 div2.addEventListener("click", record_call("div2.click(capture)"), true);
270 div1.addEventListener("click", stop_propagation, false);
271 div1.addEventListener("click", record_call("div1.click(bubble)"), false);
273 div2.addEventListener("click", stop_propagation, false);
274 div2.addEventListener("click", record_call("div2.click(bubble)"), false);
278 ok(calls === "immediateStop,", "calls = " + calls);
280 div1.removeEventListener("click", stop_immediate_propagation, true);
283 ok(calls === "stop,div1.click(capture),", "calls = " + calls);
285 div1.removeEventListener("click", stop_propagation, true);
288 ok(calls === "div1.click(capture),immediateStop,", "calls = " + calls);
290 div2.removeEventListener("click", stop_immediate_propagation, true);
293 ok(calls === "div1.click(capture),stop,div2.click(capture),stop,div2.click(bubble),",
296 div2.removeEventListener("click", stop_propagation, true);
299 ok(calls === "div1.click(capture),div2.click(capture),stop,div2.click(bubble),",
302 div2.removeEventListener("click", stop_propagation, false);
305 ok(calls === "div1.click(capture),div2.click(capture),div2.click(bubble),stop,div1.click(bubble),",
311 function test_prevent_default() {
312 document.body.innerHTML = '<div><a href="about:blank"></a></div>';
313 var div = document.body.firstChild;
314 var a = div.firstChild;
317 div.addEventListener("click", function(e) {
318 ok(e.defaultPrevented === false, "e.defaultPrevented = " + e.defaultPrevented);
320 ok(e.defaultPrevented === e.cancelable, "e.defaultPrevented = " + e.defaultPrevented);
324 a.addEventListener("click", function(e) {
326 ok(e.defaultPrevented === true, "e.defaultPrevented = " + e.defaultPrevented);
331 ok(calls === "div,a,", "calls = " + calls);
333 var e = document.createEvent("Event");
334 e.initEvent("click", true, false);
337 div.dispatchEvent(e);
338 ok(calls === "div,", "calls = " + calls);
340 e = document.createEvent("Event");
341 e.initEvent("click", false, true);
344 div.dispatchEvent(e);
345 ok(calls === "div,", "calls = " + calls);
347 document.body.innerHTML = '<div></div>';
348 var elem = document.body.firstChild;
351 elem.onclick = function(event) {
352 event.preventDefault();
354 e = document.createEvent("Event");
355 e.initEvent("click", true, true);
356 r = elem.dispatchEvent(e);
357 ok(r === false, "dispatchEvent returned " + r);
359 elem.onclick = function(event) {
360 event.preventDefault();
361 ok(event.defaultPrevented === false, "defaultPrevented");
363 e = document.createEvent("Event");
364 e.initEvent("click", true, false);
365 r = elem.dispatchEvent(e);
366 ok(r === true, "dispatchEvent returned " + r);
368 elem.onclick = function(event) {
369 event.stopPropagation();
371 e = document.createEvent("Event");
372 e.initEvent("click", true, true);
373 r = elem.dispatchEvent(e);
374 ok(r === true, "dispatchEvent returned " + r);
376 e = document.createEvent("Event");
377 e.initEvent("click", false, true);
379 ok(e.defaultPrevented === false, "defaultPrevented = " + e.defaultPrevented);
381 e = document.createEvent("Event");
382 e.initEvent("click", false, true);
384 r = elem.dispatchEvent(e);
385 ok(r === true, "dispatchEvent returned " + r);
387 ok(e.defaultPrevented === false, "defaultPrevented = " + e.defaultPrevented);
392 function test_init_event() {
393 var e = document.createEvent("Event");
396 ok(e.type === "", "type = " + e.type);
397 ok(e.cancelable === false, "cancelable = " + e.cancelable);
398 ok(e.bubbles === false, "bubbles = " + e.bubbles);
400 e.initEvent("test", true, false);
401 ok(e.type === "test", "type = " + e.type);
402 ok(e.cancelable === false, "cancelable = " + e.cancelable);
403 ok(e.bubbles === true, "bubbles = " + e.bubbles);
404 ok(e.defaultPrevented === false, "defaultPrevented = " + e.defaultPrevented);
407 ok(e.defaultPrevented === false, "defaultPrevented = " + e.defaultPrevented);
409 e.initEvent("NewTest", false, true);
410 ok(e.type === "NewTest", "type = " + e.type);
411 ok(e.cancelable === true, "cancelable = " + e.cancelable);
412 ok(e.bubbles === false, "bubbles = " + e.bubbles);
414 document.body.innerHTML = '<div></div>';
415 var elem = document.body.firstChild;
417 elem.addEventListener("NewTest", function(event) {
418 ok(e === event, "e != event");
421 ok(e.defaultPrevented === true, "defaultPrevented = " + e.defaultPrevented);
423 /* initEvent no longer has effect */
424 event.initEvent("test", true, false);
425 ok(event.type === "NewTest", "event.type = " + event.type);
426 ok(event.bubbles === false, "bubbles = " + event.bubbles);
427 ok(event.cancelable === true, "cancelable = " + event.cancelable);
428 ok(e.defaultPrevented === true, "defaultPrevented = " + e.defaultPrevented);
434 elem.dispatchEvent(e);
435 ok(calls === 1, "calls = " + calls);
436 ok(e.type === "NewTest", "event.type = " + e.type);
437 ok(e.bubbles === false, "bubbles = " + e.bubbles);
438 ok(e.cancelable === true, "cancelable = " + e.cancelable);
439 ok(e.target === elem, "target != elem");
440 ok(e.defaultPrevented === false, "defaultPrevented = " + e.defaultPrevented);
442 /* initEvent no longer has any effect except resetting defaultPrevented */
443 e.initEvent("test", true, false);
444 ok(e.type === "NewTest", "type = " + e.type);
445 ok(e.bubbles === false, "bubbles = " + e.bubbles);
446 ok(e.cancelable === true, "cancelable = " + e.cancelable);
447 ok(e.target === elem, "target != elem");
448 ok(e.defaultPrevented === false, "defaultPrevented = " + e.defaultPrevented);
451 elem.dispatchEvent(e);
452 ok(calls === 1, "calls = " + calls);
453 ok(e.type === "NewTest", "event.type = " + e.type);
454 ok(e.bubbles === false, "bubbles = " + e.bubbles);
455 ok(e.cancelable === true, "cancelable = " + e.cancelable);
456 ok(e.target === elem, "target != elem");
458 document.body.dispatchEvent(e);
459 ok(e.target === document.body, "target != body");
464 function test_current_target() {
465 document.body.innerHTML = '<div><div></div></div>';
466 var parent = document.body.firstChild;
467 var child = parent.firstChild;
471 function expect_current_target(expected_target) {
472 return function(event) {
473 ok(event.currentTarget === expected_target, "unexpected currentTarget");
478 parent.addEventListener("test", expect_current_target(parent), true);
479 parent.addEventListener("test", expect_current_target(parent), false);
480 child.addEventListener("test", expect_current_target(child), true);
481 child.addEventListener("test", expect_current_target(child), false);
483 e = document.createEvent("Event");
484 e.initEvent("test", true, true);
485 ok(e.currentTarget === null, "currentTarget != null");
488 child.dispatchEvent(e);
489 ok(calls === 4, "calls = " + calls + " expected 4");
490 ok(e.currentTarget === null, "currentTarget != null");
495 function test_dispatch_event() {
496 document.body.innerHTML = '<div><div></div></div>';
497 var parent = document.body.firstChild;
498 var child = parent.firstChild;
502 function record_call(msg) {
503 return function(event) {
504 ok(event === e, "event != e");
505 ok(event.target === child, "target != child");
506 ok(event.srcElement === child, "srcElement != child");
511 parent.addEventListener("click", record_call("parent.click(capture)"), true);
512 parent.addEventListener("click", record_call("parent.click(bubble)"), false);
513 child.addEventListener("click", record_call("child.click(capture)"), true);
514 child.addEventListener("click", record_call("child.click(bubble)"), false);
515 parent.addEventListener("testing", record_call("parent.testing(capture)"), true);
516 parent.addEventListener("testing", record_call("parent.testing(bubble)"), false);
517 child.addEventListener("testing", record_call("child.testing(capture)"), true);
518 child.addEventListener("testing", record_call("child.testing(bubble)"), false);
520 e = document.createEvent("Event");
521 e.initEvent("click", true, true);
522 ok(e.target === null, "e.target != null");
523 ok(e.srcElement === null, "e.srcElement != null");
526 child.dispatchEvent(e);
527 ok(calls === "parent.click(capture),child.click(capture),child.click(bubble),"
528 + "parent.click(bubble),", "calls = " + calls);
529 ok(e.target === child, "e.target != child");
530 ok(e.srcElement === child, "e.srcElement != child");
531 ok(e.currentTarget === null, "e.currentTarget != null");
533 e = document.createEvent("Event");
534 e.initEvent("click", false, true);
537 child.dispatchEvent(e);
538 ok(calls === "parent.click(capture),child.click(capture),child.click(bubble),",
541 /* again, without reinitialization */
543 child.dispatchEvent(e);
544 ok(calls === "parent.click(capture),child.click(capture),child.click(bubble),",
547 e = document.createEvent("Event");
548 e.initEvent("testing", true, true);
551 child.dispatchEvent(e);
552 ok(calls === "parent.testing(capture),child.testing(capture),"
553 + "child.testing(bubble),parent.testing(bubble),", "calls = " + calls);
555 var xhr = new XMLHttpRequest();
556 xhr.addEventListener("testing", function(event) {
557 ok(event === e, "event != e");
558 ok(event.target === xhr, "target != child");
559 ok(event.srcElement === null, "srcElement != child");
560 calls += "xhr.testing";
564 xhr.dispatchEvent(e);
565 ok(calls === "xhr.testing", "calls = " + calls);
570 function test_recursive_dispatch() {
571 document.body.innerHTML = '<div></div><div></div>';
572 var elem1 = document.body.firstChild;
573 var elem2 = elem1.nextSibling;
576 var e = document.createEvent("Event");
577 ok(e.eventPhase === 0, "eventPhase = " + e.eventPhase);
579 e.initEvent("test", true, true);
580 ok(e.eventPhase === 0, "eventPhase = " + e.eventPhase);
582 elem1.addEventListener("test", function(event_arg) {
583 calls += "elem1.test,";
584 ok(event_arg === e, "event_arg != e");
586 elem2.dispatchEvent(e);
587 ok(false, "expected exception");
591 elem2.addEventListener("test", function() {
592 ok(false, "unexpected recursive event call");
596 elem1.dispatchEvent(e);
597 ok(calls === "elem1.test,", "calls = " + calls);
598 ok(e.eventPhase === 3, "eventPhase = " + e.eventPhase);
603 function test_time_stamp() {
604 document.body.innerHTML = '<div></div>';
605 var elem = document.body.firstChild;
606 var calls, last_time_stamp;
608 elem.onclick = function(event) {
609 ok(event.timeStamp === last_time_stamp, "timeStamp = " + event.timeStamp);
613 var e = document.createEvent("Event");
614 ok(typeof(e.timeStamp) === "number", "typeof(timeStamp) = " + typeof(e.timeStamp));
615 ok(e.timeStamp > 0, "timeStamp = " + e.timeStamp);
617 var now = (new Date()).getTime();
618 last_time_stamp = e.timeStamp;
619 ok(Math.abs(now - last_time_stamp) < 3, "timeStamp " + last_time_stamp + " != now " + now);
621 e.initEvent("click", true, true);
622 ok(e.timeStamp === last_time_stamp, "timeStamp = " + e.timeStamp);
624 elem.dispatchEvent(e);
625 ok(calls === 1, "calls = " + calls);
626 ok(e.timeStamp === last_time_stamp, "timeStamp = " + e.timeStamp);
628 elem.onclick = function(event) {
629 ok(event.timeStamp > 0, "timeStamp = " + event.timeStamp);
630 trace("timestamp " + event.timeStamp);
636 ok(calls === 1, "calls = " + calls);
641 function test_mouse_event() {
644 e = document.createEvent("MouseEvent");
645 ok(e.screenX === 0, "screenX = " + e.screenX);
646 ok(e.screenY === 0, "screenY = " + e.screenY);
647 ok(e.clientX === 0, "clientX = " + e.clientX);
648 ok(e.clientY === 0, "clientY = " + e.clientY);
649 ok(e.offsetX === 0, "offsetX = " + e.offsetX);
650 ok(e.offsetY === 0, "offsetY = " + e.offsetY);
651 ok(e.ctrlKey === false, "ctrlKey = " + e.ctrlKey);
652 ok(e.altKey === false, "altKey = " + e.altKey);
653 ok(e.shiftKey === false, "shiftKey = " + e.shiftKey);
654 ok(e.metaKey === false, "metaKey = " + e.metaKey);
655 ok(e.button === 0, "button = " + e.button);
656 ok(e.buttons === 0, "buttons = " + e.buttons);
657 ok(e.pageX === 0, "pageX = " + e.pageX);
658 ok(e.pageY === 0, "pageY = " + e.pageY);
659 ok(e.which === 1, "which = " + e.which);
660 ok(e.relatedTarget === null, "relatedTarget = " + e.relatedTarget);
661 ok(e.toElement === null, "toElement = " + e.toElement);
662 ok(e.fromElement === null, "fromElement = " + e.fromElement);
664 e.initMouseEvent("test", true, true, window, 1, 2, 3, 4, 5, false, false, false, false, 1, document);
665 ok(e.type === "test", "type = " + e.type);
666 ok(e.cancelable === true, "cancelable = " + e.cancelable);
667 ok(e.bubbles === true, "bubbles = " + e.bubbles);
668 ok(e.detail === 1, "detail = " + e.detail);
670 ok(e.view === window, "view != window");
671 ok(e.screenX === 2, "screenX = " + e.screenX);
672 ok(e.screenY === 3, "screenY = " + e.screenY);
673 ok(e.clientX === 4, "clientX = " + e.clientX);
674 ok(e.clientY === 5, "clientY = " + e.clientY);
675 ok(e.ctrlKey === false, "ctrlKey = " + e.ctrlKey);
676 ok(e.altKey === false, "altKey = " + e.altKey);
677 ok(e.shiftKey === false, "shiftKey = " + e.shiftKey);
678 ok(e.metaKey === false, "metaKey = " + e.metaKey);
679 ok(e.button === 1, "button = " + e.button);
680 ok(e.buttons === 0, "buttons = " + e.buttons);
681 ok(e.which === 2, "which = " + e.which);
682 ok(e.relatedTarget === document, "relatedTarget = " + e.relatedTarget);
684 e.initMouseEvent("test", false, false, window, 9, 8, 7, 6, 5, true, true, true, true, 127, document.body);
685 ok(e.type === "test", "type = " + e.type);
686 ok(e.cancelable === false, "cancelable = " + e.cancelable);
687 ok(e.bubbles === false, "bubbles = " + e.bubbles);
688 ok(e.detail === 9, "detail = " + e.detail);
689 ok(e.screenX === 8, "screenX = " + e.screenX);
690 ok(e.screenY === 7, "screenY = " + e.screenY);
691 ok(e.clientX === 6, "clientX = " + e.clientX);
692 ok(e.clientY === 5, "clientY = " + e.clientY);
693 ok(e.ctrlKey === true, "ctrlKey = " + e.ctrlKey);
694 ok(e.altKey === true, "altKey = " + e.altKey);
695 ok(e.shiftKey === true, "shiftKey = " + e.shiftKey);
696 ok(e.metaKey === true, "metaKey = " + e.metaKey);
697 ok(e.button === 127, "button = " + e.button);
698 ok(e.which === 128, "which = " + e.which);
699 ok(e.relatedTarget === document.body, "relatedTarget = " + e.relatedTarget);
701 e.initEvent("testevent", true, true);
702 ok(e.type === "testevent", "type = " + e.type);
703 ok(e.cancelable === true, "cancelable = " + e.cancelable);
704 ok(e.bubbles === true, "bubbles = " + e.bubbles);
705 ok(e.detail === 9, "detail = " + e.detail);
706 ok(e.screenX === 8, "screenX = " + e.screenX);
707 ok(e.screenY === 7, "screenY = " + e.screenY);
708 ok(e.clientX === 6, "clientX = " + e.clientX);
709 ok(e.clientY === 5, "clientY = " + e.clientY);
710 ok(e.ctrlKey === true, "ctrlKey = " + e.ctrlKey);
711 ok(e.altKey === true, "altKey = " + e.altKey);
712 ok(e.shiftKey === true, "shiftKey = " + e.shiftKey);
713 ok(e.metaKey === true, "metaKey = " + e.metaKey);
714 ok(e.button === 127, "button = " + e.button);
716 e.initUIEvent("testevent", true, true, window, 6);
717 ok(e.type === "testevent", "type = " + e.type);
718 ok(e.cancelable === true, "cancelable = " + e.cancelable);
719 ok(e.bubbles === true, "bubbles = " + e.bubbles);
720 ok(e.detail === 6, "detail = " + e.detail);
721 ok(e.screenX === 8, "screenX = " + e.screenX);
722 ok(e.screenY === 7, "screenY = " + e.screenY);
723 ok(e.clientX === 6, "clientX = " + e.clientX);
724 ok(e.clientY === 5, "clientY = " + e.clientY);
725 ok(e.ctrlKey === true, "ctrlKey = " + e.ctrlKey);
726 ok(e.altKey === true, "altKey = " + e.altKey);
727 ok(e.shiftKey === true, "shiftKey = " + e.shiftKey);
728 ok(e.metaKey === true, "metaKey = " + e.metaKey);
729 ok(e.button === 127, "button = " + e.button);
734 function test_ui_event() {
737 e = document.createEvent("UIEvent");
738 ok(e.detail === 0, "detail = " + e.detail);
740 e.initUIEvent("test", true, true, window, 3);
741 ok(e.type === "test", "type = " + e.type);
742 ok(e.cancelable === true, "cancelable = " + e.cancelable);
743 ok(e.bubbles === true, "bubbles = " + e.bubbles);
744 ok(e.detail === 3, "detail = " + e.detail);
746 ok(e.view === window, "view != window");
751 function test_keyboard_event() {
754 e = document.createEvent("KeyboardEvent");
756 e.initEvent("test", true, true);
757 ok(e.key === "", "key = " + e.key);
758 ok(e.keyCode === 0, "keyCode = " + e.keyCode);
759 ok(e.charCode === 0, "charCode = " + e.charCode);
760 ok(e.repeat === false, "repeat = " + e.repeat);
761 ok(e.ctrlKey === false, "ctrlKey = " + e.ctrlKey);
762 ok(e.altKey === false, "altKey = " + e.altKey);
763 ok(e.shiftKey === false, "shiftKey = " + e.shiftKey);
764 ok(e.metaKey === false, "metaKey = " + e.metaKey);
765 ok(e.location === 0, "location = " + e.location);
766 ok(e.detail === 0, "detail = " + e.detail);
767 ok(e.which === 0, "which = " + e.which);
772 function test_custom_event() {
773 var e = document.createEvent("CustomEvent");
775 ok(e.detail === undefined, "detail = " + e.detail);
777 e.initCustomEvent("test", true, false, 123);
778 ok(e.type === "test", "type = " + e.type);
779 ok(e.bubbles === true, "bubbles = " + e.bubbles);
780 ok(e.cancelable === false, "cancelable = " + e.cancelable);
781 ok(e.detail === 123, "detail = " + e.detail);
786 function test_error_event() {
787 document.body.innerHTML = '<div><img></img></div>';
788 var div = document.body.firstChild;
789 var img = div.firstChild;
792 function record_call(msg) {
793 return function() { calls += msg + "," };
795 var win_onerror = record_call("window.onerror");
796 var doc_onerror = record_call("doc.onerror");
797 var body_onerror = record_call("body.onerror");
799 window.addEventListener("error", win_onerror, true);
800 document.addEventListener("error", doc_onerror, true);
801 document.body.addEventListener("error", body_onerror, true);
802 div.addEventListener("error", record_call("div.onerror"), true);
804 div.addEventListener("error", function() {
805 ok(calls === "window.onerror,doc.onerror,body.onerror,div.onerror,", "calls = " + calls);
807 window.removeEventListener("error", win_onerror, true);
808 document.removeEventListener("error", doc_onerror, true);
809 document.body.removeEventListener("error", body_onerror, true);
813 img.src = "about:blank";
816 function test_detached_img_error_event() {
817 var img = new Image();
818 img.onerror = function() {
821 img.src = "about:blank";
826 test_add_remove_listener,
827 test_add_listener_in_listener,
828 test_remove_listener_in_listener,
830 test_stop_propagation,
831 test_prevent_default,
835 test_recursive_dispatch,
841 test_detached_img_error_event,