diff --git a/dlls/mshtml/tests/events.js b/dlls/mshtml/tests/events.js index 9ec3db7ee00e..fc68d8ad87fd 100644 --- a/dlls/mshtml/tests/events.js +++ b/dlls/mshtml/tests/events.js @@ -89,6 +89,16 @@ function test_listener_order() { + "body.click(attached),document.click(attached),document.click(bubble)," + "document.onclick,window.click(bubble),", "calls = " + calls); + var e = document.createEvent("Event"); + e.initEvent("click", true, true); + + calls = ""; + div.dispatchEvent(e); + ok(calls === "window.click(capture),document.click(capture),body.click(capture)," + + "div.click(bubble),new div.onclick,div.click(capture1),div.click(capture2)," + + "body.onclick,body.click(bubble),body.click(bubble2),document.click(bubble)," + + "document.onclick,window.click(bubble),", "calls = " + calls); + next_test(); } @@ -237,6 +247,8 @@ function test_stop_propagation() { function stop_propagation(e) { calls += "stop,"; e.stopPropagation(); + ok(e.bubbles === true, "bubbles = " + e.bubbles); + ok(e.defaultPrevented === false, "defaultPrevented = " + e.defaultPrevented); } div1.addEventListener("click", stop_propagation, true); @@ -286,7 +298,7 @@ function test_prevent_default() { calls += "div,"; ok(e.defaultPrevented === false, "e.defaultPrevented = " + e.defaultPrevented); e.preventDefault(); - ok(e.defaultPrevented === true, "e.defaultPrevented = " + e.defaultPrevented); + ok(e.defaultPrevented === e.cancelable, "e.defaultPrevented = " + e.defaultPrevented); }, true); a.addEventListener("click", function(e) { @@ -298,6 +310,244 @@ function test_prevent_default() { a.click(); ok(calls === "div,a,", "calls = " + calls); + var e = document.createEvent("Event"); + e.initEvent("click", true, false); + + calls = ""; + div.dispatchEvent(e); + ok(calls === "div,", "calls = " + calls); + + e = document.createEvent("Event"); + e.initEvent("click", false, true); + + calls = ""; + div.dispatchEvent(e); + ok(calls === "div,", "calls = " + calls); + + document.body.innerHTML = '
'; + var elem = document.body.firstChild; + var e, r; + + elem.onclick = function(event) { + event.preventDefault(); + } + e = document.createEvent("Event"); + e.initEvent("click", true, true); + r = elem.dispatchEvent(e); + ok(r === false, "dispatchEvent returned " + r); + + elem.onclick = function(event) { + event.preventDefault(); + } + e = document.createEvent("Event"); + e.initEvent("click", true, false); + r = elem.dispatchEvent(e); + ok(r === true, "dispatchEvent returned " + r); + + elem.onclick = function(event) { + event.stopPropagation(); + } + e = document.createEvent("Event"); + e.initEvent("click", true, true); + r = elem.dispatchEvent(e); + ok(r === true, "dispatchEvent returned " + r); + + next_test(); +} + +function test_init_event() { + var e = document.createEvent("Event"); + var calls; + + ok(e.type === "", "type = " + e.type); + ok(e.cancelable === false, "cancelable = " + e.cancelable); + ok(e.bubbles === false, "bubbles = " + e.bubbles); + + e.initEvent("test", true, false); + ok(e.type === "test", "type = " + e.type); + ok(e.cancelable === false, "cancelable = " + e.cancelable); + ok(e.bubbles === true, "bubbles = " + e.bubbles); + ok(e.defaultPrevented === false, "defaultPrevented = " + e.defaultPrevented); + + e.preventDefault(); + ok(e.defaultPrevented === false, "defaultPrevented = " + e.defaultPrevented); + + e.initEvent("NewTest", false, true); + ok(e.type === "NewTest", "type = " + e.type); + ok(e.cancelable === true, "cancelable = " + e.cancelable); + ok(e.bubbles === false, "bubbles = " + e.bubbles); + + document.body.innerHTML = ''; + var elem = document.body.firstChild; + + elem.addEventListener("NewTest", function(event) { + ok(e === event, "e != event"); + + e.preventDefault(); + ok(e.defaultPrevented === true, "defaultPrevented = " + e.defaultPrevented); + + /* initEvent no longer has effect */ + event.initEvent("test", true, false); + ok(event.type === "NewTest", "event.type = " + event.type); + ok(event.bubbles === false, "bubbles = " + event.bubbles); + ok(event.cancelable === true, "cancelable = " + event.cancelable); + ok(e.defaultPrevented === true, "defaultPrevented = " + e.defaultPrevented); + + calls++; + }, true); + + calls = 0; + elem.dispatchEvent(e); + ok(calls === 1, "calls = " + calls); + ok(e.type === "NewTest", "event.type = " + e.type); + ok(e.bubbles === false, "bubbles = " + e.bubbles); + ok(e.cancelable === true, "cancelable = " + e.cancelable); + ok(e.target === elem, "target != elem"); + ok(e.defaultPrevented === false, "defaultPrevented = " + e.defaultPrevented); + + /* initEvent no longer has effect except reseting defaultPrevented */ + e.initEvent("test", true, false); + ok(e.type === "NewTest", "type = " + e.type); + ok(e.bubbles === false, "bubbles = " + e.bubbles); + ok(e.cancelable === true, "cancelable = " + e.cancelable); + ok(e.target === elem, "target != elem"); + ok(e.defaultPrevented === false, "defaultPrevented = " + e.defaultPrevented); + + calls = 0; + elem.dispatchEvent(e); + ok(calls === 1, "calls = " + calls); + ok(e.type === "NewTest", "event.type = " + e.type); + ok(e.bubbles === false, "bubbles = " + e.bubbles); + ok(e.cancelable === true, "cancelable = " + e.cancelable); + ok(e.target === elem, "target != elem"); + + document.body.dispatchEvent(e); + ok(e.target === document.body, "target != body"); + + next_test(); +} + +function test_current_target() { + document.body.innerHTML = '