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
21 var test_content_loaded = (function() {
24 function unexpected_call() {
25 ok(false, "unexpected call");
28 function record_call(msg) {
29 return function() { calls += msg + ","; };
32 window.addEventListener("DOMContentLoaded", record_call("window.capture"), true);
33 window.addEventListener("DOMContentLoaded", record_call("window.bubble"), false);
34 document.addEventListener("DOMContentLoaded", record_call("document.capture"), true);
35 document.addEventListener("DOMContentLoaded", record_call("document.bubble"), false);
37 document.attachEvent("onDOMContentLoaded", unexpected_call);
38 document.attachEvent("DOMContentLoaded", unexpected_call);
41 ok(calls === "window.capture,document.capture,document.bubble,window.bubble,",
47 async_test("content_loaded", test_content_loaded);
49 sync_test("listener_order", function() {
50 document.body.innerHTML = '<div></div>';
51 var div = document.body.firstChild;
54 function record_call(msg) {
55 return function() { calls += msg + ","; };
58 window.addEventListener("click", record_call("window.click(capture)"), true);
59 window.addEventListener("click", record_call("window.click(bubble)"), false);
61 document.attachEvent("onclick", record_call("document.click(attached)"));
62 document.addEventListener("click", record_call("document.click(capture)"), true);
63 document.addEventListener("click", record_call("document.click(bubble)"), false);
64 document.onclick = record_call("document.onclick");
66 document.body.onclick = record_call("body.onclick");
67 document.body.addEventListener("click", record_call("body.click(capture)"), true);
68 document.body.addEventListener("click", record_call("body.click(bubble)"), false);
69 document.body.addEventListener("click", record_call("body.click(bubble2)"));
70 document.body.attachEvent("onclick", record_call("body.click(attached)"));
72 div.attachEvent("onclick", record_call("div.click(attached)"));
73 div.addEventListener("click", record_call("div.click(bubble)"), false);
74 div.onclick = record_call("div.onclick");
75 div.addEventListener("click", record_call("div.click(capture1)"), true);
76 div.addEventListener("click", record_call("div.click(capture2)"), true);
80 ok(calls === "window.click(capture),document.click(capture),body.click(capture),"
81 + "div.click(attached),div.click(bubble),div.onclick,div.click(capture1),"
82 + "div.click(capture2),body.onclick,body.click(bubble),body.click(bubble2),"
83 + "body.click(attached),document.click(attached),document.click(bubble),"
84 + "document.onclick,window.click(bubble),", "calls = " + calls);
86 div.onclick = record_call("new div.onclick");
90 ok(calls === "window.click(capture),document.click(capture),body.click(capture),"
91 + "div.click(attached),div.click(bubble),new div.onclick,div.click(capture1),"
92 + "div.click(capture2),body.onclick,body.click(bubble),body.click(bubble2),"
93 + "body.click(attached),document.click(attached),document.click(bubble),"
94 + "document.onclick,window.click(bubble),", "calls = " + calls);
96 var e = document.createEvent("Event");
97 e.initEvent("click", true, true);
100 div.dispatchEvent(e);
101 ok(calls === "window.click(capture),document.click(capture),body.click(capture),"
102 + "div.click(bubble),new div.onclick,div.click(capture1),div.click(capture2),"
103 + "body.onclick,body.click(bubble),body.click(bubble2),document.click(bubble),"
104 + "document.onclick,window.click(bubble),", "calls = " + calls);
107 sync_test("add_listener_in_listener", function() {
110 document.body.innerHTML = '<div><div></div></div>';
111 var div1 = document.body.firstChild;
112 var div2 = div1.firstChild;
114 function record_call(msg) {
115 return function() { calls += msg + ","; };
118 div1.addEventListener("click", function() {
119 div2.addEventListener("click", function() {
120 calls += "div2.click";
121 /* if we add more listeners here, whey won't be invoked */
122 div2.onclick = function() { calls += "click2,"; };
123 div2.addEventListener("click", function() { calls += "click3,"; }, false);
124 div2.attachEvent("onclick", function() { calls += "click4,"; });
130 ok(calls === "div2.click", "calls = " + calls);
133 sync_test("remove_listener_in_listener", function() {
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);
160 sync_test("add_remove_listener", function() {
163 document.body.innerHTML = '<div></div>';
164 var div = document.body.firstChild;
166 function listener() {
167 calls += "listener,";
170 /* if the same listener is added twice, second one won't be called */
171 div.addEventListener("click", listener, false);
172 div.addEventListener("click", listener, false);
176 ok(calls === "listener,", "calls = " + calls);
178 /* remove capture listener, it won't do anything */
179 div.removeEventListener("click", listener, true);
183 ok(calls === "listener,", "calls = " + calls);
185 /* remove listener once, it won't called anymore */
186 div.removeEventListener("click", listener, false);
190 ok(calls === "", "calls = " + calls);
192 div.removeEventListener("click", listener, false);
194 /* test implicit capture removeEventListener argument */
195 div.addEventListener("click", listener, false);
196 div.removeEventListener("click", listener);
200 ok(calls === "", "calls = " + calls);
203 sync_test("event_phase", function() {
204 document.body.innerHTML = '<div><div></div></div>';
205 var div1 = document.body.firstChild;
206 var div2 = div1.firstChild;
209 function check_phase(expected_phase) {
212 ok(last_event === e, "last_event != e");
215 ok(e.eventPhase === expected_phase,
216 "eventPhase = " + e.eventPhase + " expedted " + expected_phase);
220 div1.addEventListener("click", check_phase(1), true);
221 div1.addEventListener("click", check_phase(3), false);
222 div1.onclick = check_phase(3);
223 div2.addEventListener("click", check_phase(2), true);
224 div2.addEventListener("click", check_phase(2), false);
225 div2.onclick = check_phase(2);
228 ok(last_event.eventPhase === 3, "last_event.eventPhase = " + last_event.eventPhase);
231 sync_test("stop_propagation", function() {
232 document.body.innerHTML = '<div><div></div></div>';
233 var div1 = document.body.firstChild;
234 var div2 = div1.firstChild;
237 function record_call(msg) {
238 return function() { calls += msg + ","; };
241 function stop_propagation(e) {
244 ok(e.bubbles === true, "bubbles = " + e.bubbles);
245 ok(e.defaultPrevented === false, "defaultPrevented = " + e.defaultPrevented);
248 function stop_immediate_propagation(e) {
249 calls += "immediateStop,";
250 e.stopImmediatePropagation();
251 ok(e.bubbles === true, "bubbles = " + e.bubbles);
252 ok(e.cancelable === true, "cancelable = " + e.cancelable);
253 ok(e.defaultPrevented === false, "defaultPrevented = " + e.defaultPrevented);
256 div1.addEventListener("click", stop_immediate_propagation, true);
257 div1.addEventListener("click", stop_propagation, true);
258 div1.addEventListener("click", record_call("div1.click(capture)"), true);
260 div2.addEventListener("click", stop_immediate_propagation, true);
261 div2.addEventListener("click", stop_propagation, true);
262 div2.addEventListener("click", record_call("div2.click(capture)"), true);
264 div1.addEventListener("click", stop_propagation, false);
265 div1.addEventListener("click", record_call("div1.click(bubble)"), false);
267 div2.addEventListener("click", stop_propagation, false);
268 div2.addEventListener("click", record_call("div2.click(bubble)"), false);
272 ok(calls === "immediateStop,", "calls = " + calls);
274 div1.removeEventListener("click", stop_immediate_propagation, true);
277 ok(calls === "stop,div1.click(capture),", "calls = " + calls);
279 div1.removeEventListener("click", stop_propagation, true);
282 ok(calls === "div1.click(capture),immediateStop,", "calls = " + calls);
284 div2.removeEventListener("click", stop_immediate_propagation, true);
287 ok(calls === "div1.click(capture),stop,div2.click(capture),stop,div2.click(bubble),",
290 div2.removeEventListener("click", stop_propagation, true);
293 ok(calls === "div1.click(capture),div2.click(capture),stop,div2.click(bubble),",
296 div2.removeEventListener("click", stop_propagation, false);
299 ok(calls === "div1.click(capture),div2.click(capture),div2.click(bubble),stop,div1.click(bubble),",
303 sync_test("prevent_default", function() {
304 document.body.innerHTML = '<div><a href="about:blank"></a></div>';
305 var div = document.body.firstChild;
306 var a = div.firstChild;
309 div.addEventListener("click", function(e) {
310 ok(e.defaultPrevented === false, "e.defaultPrevented = " + e.defaultPrevented);
312 ok(e.defaultPrevented === e.cancelable, "e.defaultPrevented = " + e.defaultPrevented);
316 a.addEventListener("click", function(e) {
318 ok(e.defaultPrevented === true, "e.defaultPrevented = " + e.defaultPrevented);
323 ok(calls === "div,a,", "calls = " + calls);
325 var e = document.createEvent("Event");
326 e.initEvent("click", true, false);
329 div.dispatchEvent(e);
330 ok(calls === "div,", "calls = " + calls);
332 e = document.createEvent("Event");
333 e.initEvent("click", false, true);
336 div.dispatchEvent(e);
337 ok(calls === "div,", "calls = " + calls);
339 document.body.innerHTML = '<div></div>';
340 var elem = document.body.firstChild;
343 elem.onclick = function(event) {
344 event.preventDefault();
346 e = document.createEvent("Event");
347 e.initEvent("click", true, true);
348 r = elem.dispatchEvent(e);
349 ok(r === false, "dispatchEvent returned " + r);
351 elem.onclick = function(event) {
352 event.preventDefault();
353 ok(event.defaultPrevented === false, "defaultPrevented");
355 e = document.createEvent("Event");
356 e.initEvent("click", true, false);
357 r = elem.dispatchEvent(e);
358 ok(r === true, "dispatchEvent returned " + r);
360 elem.onclick = function(event) {
361 event.stopPropagation();
363 e = document.createEvent("Event");
364 e.initEvent("click", true, true);
365 r = elem.dispatchEvent(e);
366 ok(r === true, "dispatchEvent returned " + r);
368 e = document.createEvent("Event");
369 e.initEvent("click", false, true);
371 ok(e.defaultPrevented === false, "defaultPrevented = " + e.defaultPrevented);
373 e = document.createEvent("Event");
374 e.initEvent("click", false, true);
376 r = elem.dispatchEvent(e);
377 ok(r === true, "dispatchEvent returned " + r);
379 ok(e.defaultPrevented === false, "defaultPrevented = " + e.defaultPrevented);
382 sync_test("init_event", function() {
383 var e = document.createEvent("Event");
386 ok(e.type === "", "type = " + e.type);
387 ok(e.cancelable === false, "cancelable = " + e.cancelable);
388 ok(e.bubbles === false, "bubbles = " + e.bubbles);
390 e.initEvent("test", true, false);
391 ok(e.type === "test", "type = " + e.type);
392 ok(e.cancelable === false, "cancelable = " + e.cancelable);
393 ok(e.bubbles === true, "bubbles = " + e.bubbles);
394 ok(e.defaultPrevented === false, "defaultPrevented = " + e.defaultPrevented);
397 ok(e.defaultPrevented === false, "defaultPrevented = " + e.defaultPrevented);
399 e.initEvent("NewTest", false, true);
400 ok(e.type === "NewTest", "type = " + e.type);
401 ok(e.cancelable === true, "cancelable = " + e.cancelable);
402 ok(e.bubbles === false, "bubbles = " + e.bubbles);
404 document.body.innerHTML = '<div></div>';
405 var elem = document.body.firstChild;
407 elem.addEventListener("NewTest", function(event) {
408 ok(e === event, "e != event");
411 ok(e.defaultPrevented === true, "defaultPrevented = " + e.defaultPrevented);
413 /* initEvent no longer has effect */
414 event.initEvent("test", true, false);
415 ok(event.type === "NewTest", "event.type = " + event.type);
416 ok(event.bubbles === false, "bubbles = " + event.bubbles);
417 ok(event.cancelable === true, "cancelable = " + event.cancelable);
418 ok(e.defaultPrevented === true, "defaultPrevented = " + e.defaultPrevented);
424 elem.dispatchEvent(e);
425 ok(calls === 1, "calls = " + calls);
426 ok(e.type === "NewTest", "event.type = " + e.type);
427 ok(e.bubbles === false, "bubbles = " + e.bubbles);
428 ok(e.cancelable === true, "cancelable = " + e.cancelable);
429 ok(e.target === elem, "target != elem");
430 ok(e.defaultPrevented === false, "defaultPrevented = " + e.defaultPrevented);
432 /* initEvent no longer has any effect except resetting defaultPrevented */
433 e.initEvent("test", true, false);
434 ok(e.type === "NewTest", "type = " + e.type);
435 ok(e.bubbles === false, "bubbles = " + e.bubbles);
436 ok(e.cancelable === true, "cancelable = " + e.cancelable);
437 ok(e.target === elem, "target != elem");
438 ok(e.defaultPrevented === false, "defaultPrevented = " + e.defaultPrevented);
441 elem.dispatchEvent(e);
442 ok(calls === 1, "calls = " + calls);
443 ok(e.type === "NewTest", "event.type = " + e.type);
444 ok(e.bubbles === false, "bubbles = " + e.bubbles);
445 ok(e.cancelable === true, "cancelable = " + e.cancelable);
446 ok(e.target === elem, "target != elem");
448 document.body.dispatchEvent(e);
449 ok(e.target === document.body, "target != body");
452 sync_test("current_target", function() {
453 document.body.innerHTML = '<div><div></div></div>';
454 var parent = document.body.firstChild;
455 var child = parent.firstChild;
459 function expect_current_target(expected_target) {
460 return function(event) {
461 ok(event.currentTarget === expected_target, "unexpected currentTarget");
466 parent.addEventListener("test", expect_current_target(parent), true);
467 parent.addEventListener("test", expect_current_target(parent), false);
468 child.addEventListener("test", expect_current_target(child), true);
469 child.addEventListener("test", expect_current_target(child), false);
471 e = document.createEvent("Event");
472 e.initEvent("test", true, true);
473 ok(e.currentTarget === null, "currentTarget != null");
476 child.dispatchEvent(e);
477 ok(calls === 4, "calls = " + calls + " expected 4");
478 ok(e.currentTarget === null, "currentTarget != null");
481 sync_test("dispatch_event", function() {
482 document.body.innerHTML = '<div><div></div></div>';
483 var parent = document.body.firstChild;
484 var child = parent.firstChild;
488 function record_call(msg) {
489 return function(event) {
490 ok(event === e, "event != e");
491 ok(event.target === child, "target != child");
492 ok(event.srcElement === child, "srcElement != child");
497 parent.addEventListener("click", record_call("parent.click(capture)"), true);
498 parent.addEventListener("click", record_call("parent.click(bubble)"), false);
499 child.addEventListener("click", record_call("child.click(capture)"), true);
500 child.addEventListener("click", record_call("child.click(bubble)"), false);
501 parent.addEventListener("testing", record_call("parent.testing(capture)"), true);
502 parent.addEventListener("testing", record_call("parent.testing(bubble)"), false);
503 child.addEventListener("testing", record_call("child.testing(capture)"), true);
504 child.addEventListener("testing", record_call("child.testing(bubble)"), false);
506 e = document.createEvent("Event");
507 e.initEvent("click", true, true);
508 ok(e.target === null, "e.target != null");
509 ok(e.srcElement === null, "e.srcElement != null");
512 child.dispatchEvent(e);
513 ok(calls === "parent.click(capture),child.click(capture),child.click(bubble),"
514 + "parent.click(bubble),", "calls = " + calls);
515 ok(e.target === child, "e.target != child");
516 ok(e.srcElement === child, "e.srcElement != child");
517 ok(e.currentTarget === null, "e.currentTarget != null");
519 e = document.createEvent("Event");
520 e.initEvent("click", false, true);
523 child.dispatchEvent(e);
524 ok(calls === "parent.click(capture),child.click(capture),child.click(bubble),",
527 /* again, without reinitialization */
529 child.dispatchEvent(e);
530 ok(calls === "parent.click(capture),child.click(capture),child.click(bubble),",
533 e = document.createEvent("Event");
534 e.initEvent("testing", true, true);
537 child.dispatchEvent(e);
538 ok(calls === "parent.testing(capture),child.testing(capture),"
539 + "child.testing(bubble),parent.testing(bubble),", "calls = " + calls);
541 var xhr = new XMLHttpRequest();
542 xhr.addEventListener("testing", function(event) {
543 ok(event === e, "event != e");
544 ok(event.target === xhr, "target != child");
545 ok(event.srcElement === null, "srcElement != child");
546 calls += "xhr.testing";
550 xhr.dispatchEvent(e);
551 ok(calls === "xhr.testing", "calls = " + calls);
554 sync_test("recursive_dispatch", function() {
555 document.body.innerHTML = '<div></div><div></div>';
556 var elem1 = document.body.firstChild;
557 var elem2 = elem1.nextSibling;
560 var e = document.createEvent("Event");
561 ok(e.eventPhase === 0, "eventPhase = " + e.eventPhase);
563 e.initEvent("test", true, true);
564 ok(e.eventPhase === 0, "eventPhase = " + e.eventPhase);
566 elem1.addEventListener("test", function(event_arg) {
567 calls += "elem1.test,";
568 ok(event_arg === e, "event_arg != e");
570 elem2.dispatchEvent(e);
571 ok(false, "expected exception");
575 elem2.addEventListener("test", function() {
576 ok(false, "unexpected recursive event call");
580 elem1.dispatchEvent(e);
581 ok(calls === "elem1.test,", "calls = " + calls);
582 ok(e.eventPhase === 3, "eventPhase = " + e.eventPhase);
585 sync_test("time_stamp", function() {
586 document.body.innerHTML = '<div></div>';
587 var elem = document.body.firstChild;
588 var calls, last_time_stamp;
590 elem.onclick = function(event) {
591 ok(event.timeStamp === last_time_stamp, "timeStamp = " + event.timeStamp);
595 var e = document.createEvent("Event");
596 ok(typeof(e.timeStamp) === "number", "typeof(timeStamp) = " + typeof(e.timeStamp));
597 ok(e.timeStamp > 0, "timeStamp = " + e.timeStamp);
599 var now = (new Date()).getTime();
600 last_time_stamp = e.timeStamp;
601 ok(Math.abs(now - last_time_stamp) < 3, "timeStamp " + last_time_stamp + " != now " + now);
603 e.initEvent("click", true, true);
604 ok(e.timeStamp === last_time_stamp, "timeStamp = " + e.timeStamp);
606 elem.dispatchEvent(e);
607 ok(calls === 1, "calls = " + calls);
608 ok(e.timeStamp === last_time_stamp, "timeStamp = " + e.timeStamp);
610 elem.onclick = function(event) {
611 ok(event.timeStamp > 0, "timeStamp = " + event.timeStamp);
612 trace("timestamp " + event.timeStamp);
618 ok(calls === 1, "calls = " + calls);
621 sync_test("mouse_event", function() {
624 e = document.createEvent("MouseEvent");
625 ok(e.screenX === 0, "screenX = " + e.screenX);
626 ok(e.screenY === 0, "screenY = " + e.screenY);
627 ok(e.clientX === 0, "clientX = " + e.clientX);
628 ok(e.clientY === 0, "clientY = " + e.clientY);
629 ok(e.offsetX === 0, "offsetX = " + e.offsetX);
630 ok(e.offsetY === 0, "offsetY = " + e.offsetY);
631 ok(e.ctrlKey === false, "ctrlKey = " + e.ctrlKey);
632 ok(e.altKey === false, "altKey = " + e.altKey);
633 ok(e.shiftKey === false, "shiftKey = " + e.shiftKey);
634 ok(e.metaKey === false, "metaKey = " + e.metaKey);
635 ok(e.button === 0, "button = " + e.button);
636 ok(e.buttons === 0, "buttons = " + e.buttons);
637 ok(e.pageX === 0, "pageX = " + e.pageX);
638 ok(e.pageY === 0, "pageY = " + e.pageY);
639 ok(e.which === 1, "which = " + e.which);
640 ok(e.relatedTarget === null, "relatedTarget = " + e.relatedTarget);
641 ok(e.toElement === null, "toElement = " + e.toElement);
642 ok(e.fromElement === null, "fromElement = " + e.fromElement);
644 e.initMouseEvent("test", true, true, window, 1, 2, 3, 4, 5, false, false, false, false, 1, document);
645 ok(e.type === "test", "type = " + e.type);
646 ok(e.cancelable === true, "cancelable = " + e.cancelable);
647 ok(e.bubbles === true, "bubbles = " + e.bubbles);
648 ok(e.detail === 1, "detail = " + e.detail);
650 ok(e.view === window, "view != window");
651 ok(e.screenX === 2, "screenX = " + e.screenX);
652 ok(e.screenY === 3, "screenY = " + e.screenY);
653 ok(e.clientX === 4, "clientX = " + e.clientX);
654 ok(e.clientY === 5, "clientY = " + e.clientY);
655 ok(e.ctrlKey === false, "ctrlKey = " + e.ctrlKey);
656 ok(e.altKey === false, "altKey = " + e.altKey);
657 ok(e.shiftKey === false, "shiftKey = " + e.shiftKey);
658 ok(e.metaKey === false, "metaKey = " + e.metaKey);
659 ok(e.button === 1, "button = " + e.button);
660 ok(e.buttons === 0, "buttons = " + e.buttons);
661 ok(e.which === 2, "which = " + e.which);
662 ok(e.relatedTarget === document, "relatedTarget = " + e.relatedTarget);
664 e.initMouseEvent("test", false, false, window, 9, 8, 7, 6, 5, true, true, true, true, 127, document.body);
665 ok(e.type === "test", "type = " + e.type);
666 ok(e.cancelable === false, "cancelable = " + e.cancelable);
667 ok(e.bubbles === false, "bubbles = " + e.bubbles);
668 ok(e.detail === 9, "detail = " + e.detail);
669 ok(e.screenX === 8, "screenX = " + e.screenX);
670 ok(e.screenY === 7, "screenY = " + e.screenY);
671 ok(e.clientX === 6, "clientX = " + e.clientX);
672 ok(e.clientY === 5, "clientY = " + e.clientY);
673 ok(e.ctrlKey === true, "ctrlKey = " + e.ctrlKey);
674 ok(e.altKey === true, "altKey = " + e.altKey);
675 ok(e.shiftKey === true, "shiftKey = " + e.shiftKey);
676 ok(e.metaKey === true, "metaKey = " + e.metaKey);
677 ok(e.button === 127, "button = " + e.button);
678 ok(e.which === 128, "which = " + e.which);
679 ok(e.relatedTarget === document.body, "relatedTarget = " + e.relatedTarget);
681 e.initEvent("testevent", true, true);
682 ok(e.type === "testevent", "type = " + e.type);
683 ok(e.cancelable === true, "cancelable = " + e.cancelable);
684 ok(e.bubbles === true, "bubbles = " + e.bubbles);
685 ok(e.detail === 9, "detail = " + e.detail);
686 ok(e.screenX === 8, "screenX = " + e.screenX);
687 ok(e.screenY === 7, "screenY = " + e.screenY);
688 ok(e.clientX === 6, "clientX = " + e.clientX);
689 ok(e.clientY === 5, "clientY = " + e.clientY);
690 ok(e.ctrlKey === true, "ctrlKey = " + e.ctrlKey);
691 ok(e.altKey === true, "altKey = " + e.altKey);
692 ok(e.shiftKey === true, "shiftKey = " + e.shiftKey);
693 ok(e.metaKey === true, "metaKey = " + e.metaKey);
694 ok(e.button === 127, "button = " + e.button);
696 e.initUIEvent("testevent", true, true, window, 6);
697 ok(e.type === "testevent", "type = " + e.type);
698 ok(e.cancelable === true, "cancelable = " + e.cancelable);
699 ok(e.bubbles === true, "bubbles = " + e.bubbles);
700 ok(e.detail === 6, "detail = " + e.detail);
701 ok(e.screenX === 8, "screenX = " + e.screenX);
702 ok(e.screenY === 7, "screenY = " + e.screenY);
703 ok(e.clientX === 6, "clientX = " + e.clientX);
704 ok(e.clientY === 5, "clientY = " + e.clientY);
705 ok(e.ctrlKey === true, "ctrlKey = " + e.ctrlKey);
706 ok(e.altKey === true, "altKey = " + e.altKey);
707 ok(e.shiftKey === true, "shiftKey = " + e.shiftKey);
708 ok(e.metaKey === true, "metaKey = " + e.metaKey);
709 ok(e.button === 127, "button = " + e.button);
712 sync_test("ui_event", function() {
715 e = document.createEvent("UIEvent");
716 ok(e.detail === 0, "detail = " + e.detail);
718 e.initUIEvent("test", true, true, window, 3);
719 ok(e.type === "test", "type = " + e.type);
720 ok(e.cancelable === true, "cancelable = " + e.cancelable);
721 ok(e.bubbles === true, "bubbles = " + e.bubbles);
722 ok(e.detail === 3, "detail = " + e.detail);
724 ok(e.view === window, "view != window");
727 sync_test("keyboard_event", function() {
730 e = document.createEvent("KeyboardEvent");
732 e.initEvent("test", true, true);
733 ok(e.key === "", "key = " + e.key);
734 ok(e.keyCode === 0, "keyCode = " + e.keyCode);
735 ok(e.charCode === 0, "charCode = " + e.charCode);
736 ok(e.repeat === false, "repeat = " + e.repeat);
737 ok(e.ctrlKey === false, "ctrlKey = " + e.ctrlKey);
738 ok(e.altKey === false, "altKey = " + e.altKey);
739 ok(e.shiftKey === false, "shiftKey = " + e.shiftKey);
740 ok(e.metaKey === false, "metaKey = " + e.metaKey);
741 ok(e.location === 0, "location = " + e.location);
742 ok(e.detail === 0, "detail = " + e.detail);
743 ok(e.which === 0, "which = " + e.which);
746 sync_test("custom_event", function() {
747 var e = document.createEvent("CustomEvent");
749 ok(e.detail === undefined, "detail = " + e.detail);
751 e.initCustomEvent("test", true, false, 123);
752 ok(e.type === "test", "type = " + e.type);
753 ok(e.bubbles === true, "bubbles = " + e.bubbles);
754 ok(e.cancelable === false, "cancelable = " + e.cancelable);
755 ok(e.detail === 123, "detail = " + e.detail);
758 async_test("error_event", function() {
759 document.body.innerHTML = '<div><img></img></div>';
760 var div = document.body.firstChild;
761 var img = div.firstChild;
764 function record_call(msg) {
765 return function() { calls += msg + ","; };
767 var win_onerror = record_call("window.onerror");
768 var doc_onerror = record_call("doc.onerror");
769 var body_onerror = record_call("body.onerror");
771 window.addEventListener("error", win_onerror, true);
772 document.addEventListener("error", doc_onerror, true);
773 document.body.addEventListener("error", body_onerror, true);
774 div.addEventListener("error", record_call("div.onerror"), true);
776 div.addEventListener("error", function() {
777 ok(calls === "window.onerror,doc.onerror,body.onerror,div.onerror,", "calls = " + calls);
779 window.removeEventListener("error", win_onerror, true);
780 document.removeEventListener("error", doc_onerror, true);
781 document.body.removeEventListener("error", body_onerror, true);
785 img.src = "about:blank";
788 async_test("detached_img_error_event", function() {
789 var img = new Image();
790 img.onerror = function() {
793 img.src = "about:blank";