1<!DOCTYPE html> 2<meta charset="utf-8"> 3<title>Re-initializing events while dispatching them</title> 4<link rel="author" title="Josh Matthews" href="mailto:josh@joshmatthews.net"> 5<script src="/resources/testharness.js"></script> 6<script src="/resources/testharnessreport.js"></script> 7<div id="log"></div> 8<script> 9var events = { 10 'KeyboardEvent': { 11 'constructor': function() { return new KeyboardEvent("type", {key: "A"}); }, 12 'init': function(ev) { ev.initKeyboardEvent("type2", true, true, null, "a", 1, "", true, "") }, 13 'check': function(ev) { 14 assert_equals(ev.key, "A", "initKeyboardEvent key setter should short-circuit"); 15 assert_false(ev.repeat, "initKeyboardEvent repeat setter should short-circuit"); 16 assert_equals(ev.location, 0, "initKeyboardEvent location setter should short-circuit"); 17 } 18 }, 19 'MouseEvent': { 20 'constructor': function() { return new MouseEvent("type"); }, 21 'init': function(ev) { ev.initMouseEvent("type2", true, true, null, 0, 1, 1, 1, 1, true, true, true, true, 1, null) }, 22 'check': function(ev) { 23 assert_equals(ev.screenX, 0, "initMouseEvent screenX setter should short-circuit"); 24 assert_equals(ev.screenY, 0, "initMouseEvent screenY setter should short-circuit"); 25 assert_equals(ev.clientX, 0, "initMouseEvent clientX setter should short-circuit"); 26 assert_equals(ev.clientY, 0, "initMouseEvent clientY setter should short-circuit"); 27 assert_false(ev.ctrlKey, "initMouseEvent ctrlKey setter should short-circuit"); 28 assert_false(ev.altKey, "initMouseEvent altKey setter should short-circuit"); 29 assert_false(ev.shiftKey, "initMouseEvent shiftKey setter should short-circuit"); 30 assert_false(ev.metaKey, "initMouseEvent metaKey setter should short-circuit"); 31 assert_equals(ev.button, 0, "initMouseEvent button setter should short-circuit"); 32 } 33 }, 34 'CustomEvent': { 35 'constructor': function() { return new CustomEvent("type") }, 36 'init': function(ev) { ev.initCustomEvent("type2", true, true, 1) }, 37 'check': function(ev) { 38 assert_equals(ev.detail, null, "initCustomEvent detail setter should short-circuit"); 39 } 40 }, 41 'UIEvent': { 42 'constructor': function() { return new UIEvent("type") }, 43 'init': function(ev) { ev.initUIEvent("type2", true, true, window, 1) }, 44 'check': function(ev) { 45 assert_equals(ev.view, null, "initUIEvent view setter should short-circuit"); 46 assert_equals(ev.detail, 0, "initUIEvent detail setter should short-circuit"); 47 } 48 }, 49 'Event': { 50 'constructor': function() { return new Event("type") }, 51 'init': function(ev) { ev.initEvent("type2", true, true) }, 52 'check': function(ev) { 53 assert_equals(ev.bubbles, false, "initEvent bubbles setter should short-circuit"); 54 assert_equals(ev.cancelable, false, "initEvent cancelable setter should short-circuit"); 55 assert_equals(ev.type, "type", "initEvent type setter should short-circuit"); 56 } 57 } 58}; 59 60var names = Object.keys(events); 61for (var i = 0; i < names.length; i++) { 62 var t = async_test("Calling init" + names[i] + " while dispatching."); 63 t.step(function() { 64 var e = events[names[i]].constructor(); 65 66 var target = document.createElement("div") 67 target.addEventListener("type", t.step_func(function() { 68 events[names[i]].init(e); 69 70 var o = e; 71 while ((o = Object.getPrototypeOf(o))) { 72 if (!(o.constructor.name in events)) { 73 break; 74 } 75 events[o.constructor.name].check(e); 76 } 77 }), false); 78 79 assert_equals(target.dispatchEvent(e), true, "dispatchEvent must return true") 80 }); 81 t.done(); 82} 83</script> 84