diff options
Diffstat (limited to 'testing/web-platform/tests/html/webappapis/scripting/events')
13 files changed, 425 insertions, 0 deletions
diff --git a/testing/web-platform/tests/html/webappapis/scripting/events/.gitkeep b/testing/web-platform/tests/html/webappapis/scripting/events/.gitkeep new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/testing/web-platform/tests/html/webappapis/scripting/events/.gitkeep diff --git a/testing/web-platform/tests/html/webappapis/scripting/events/body-onload.html b/testing/web-platform/tests/html/webappapis/scripting/events/body-onload.html new file mode 100644 index 000000000..1e43d1ccd --- /dev/null +++ b/testing/web-platform/tests/html/webappapis/scripting/events/body-onload.html @@ -0,0 +1,20 @@ +<!DOCTYPE html> +<title>HTMLBodyElement.onload</title> +<link rel="author" title="Boris Zbarsky" href="mailto:bzbarsky@mit.edu"> +<link rel="author" title="Ms2ger" href="mailto:ms2ger@gmail.com"> +<link rel="help" href="https://html.spec.whatwg.org/multipage/#handler-window-onload"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id="log"></div> +<script> +var t = async_test("body.onload should set the window.onload handler") +window.onload = t.step_func(function() { + assert_unreached("This handler should be overwritten.") +}) +var b = document.createElement("body") +b.onload = t.step_func(function(e) { + assert_equals(e.currentTarget, window, + "The event should be fired at the window.") + t.done() +}) +</script> diff --git a/testing/web-platform/tests/html/webappapis/scripting/events/contains.json b/testing/web-platform/tests/html/webappapis/scripting/events/contains.json new file mode 100644 index 000000000..65f3062d2 --- /dev/null +++ b/testing/web-platform/tests/html/webappapis/scripting/events/contains.json @@ -0,0 +1,18 @@ +[ + { + "id": "event-handler-attributes", + "original_id": "event-handler-attributes" + }, + { + "id": "event-handlers-on-elements-document-objects-and-window-objects", + "original_id": "event-handlers-on-elements,-document-objects,-and-window-objects" + }, + { + "id": "event-firing", + "original_id": "event-firing" + }, + { + "id": "events-and-the-window-object", + "original_id": "events-and-the-window-object" + } +]
\ No newline at end of file diff --git a/testing/web-platform/tests/html/webappapis/scripting/events/event-handler-attributes-body-window.html b/testing/web-platform/tests/html/webappapis/scripting/events/event-handler-attributes-body-window.html new file mode 100644 index 000000000..1c87892cb --- /dev/null +++ b/testing/web-platform/tests/html/webappapis/scripting/events/event-handler-attributes-body-window.html @@ -0,0 +1,34 @@ +<!DOCTYPE html> +<title>HTMLBodyElement event handlers</title> + +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id="log"></div> +<body> +<script> +function f() { + return 0; +} + +var handlers = ['blur','error','focus','load','resize','scroll', + 'afterprint','beforeprint','beforeunload','hashchange', + 'languagechange','message','offline','online','pagehide', + 'pageshow','popstate','storage','unload']; +handlers.forEach(function(handler) { + test(function() { + document.body['on' + handler] = f; + assert_equals(window['on' + handler], f); + }, handler); +}); + +handlers.forEach(function(handler) { + document.body['on' + handler] = null; +}); + +handlers.forEach(function(handler) { + test(function() { + assert_equals(document.body['on' + handler], null); + assert_equals(window['on' + handler], null); + }, handler + " removal"); +}); +</script> diff --git a/testing/web-platform/tests/html/webappapis/scripting/events/event-handler-javascript.html b/testing/web-platform/tests/html/webappapis/scripting/events/event-handler-javascript.html new file mode 100644 index 000000000..657a37839 --- /dev/null +++ b/testing/web-platform/tests/html/webappapis/scripting/events/event-handler-javascript.html @@ -0,0 +1,20 @@ +<!DOCTYPE html> +<title>Event handler with labels</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<body onload="javascript: + for (var i = 0; i < 2; ++i) { + for (var j = 0; j < 2; ++j) { + t.step(function() { + assert_equals(i, 0); + assert_equals(j, 0); + }); + break javascript; + } + } + t.done(); +"> +<div id="log"></div> +<script> +var t = async_test("Event handlers starting with 'javascript:' should treat that as a label."); +</script> diff --git a/testing/web-platform/tests/html/webappapis/scripting/events/event-handler-onresize.html b/testing/web-platform/tests/html/webappapis/scripting/events/event-handler-onresize.html new file mode 100644 index 000000000..8686716e1 --- /dev/null +++ b/testing/web-platform/tests/html/webappapis/scripting/events/event-handler-onresize.html @@ -0,0 +1,38 @@ +<!DOCTYPE html> +<title>HTMLBodyElement.onresize</title> +<link rel="author" title="His-Name-Is-Joof" href="mailto:jeffrharrison@gmail.com"> +<link rel="help" href="https://html.spec.whatwg.org/multipage/#handler-window-onresize"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id="log"></div> +<script> +var t = async_test("body.onresize should set the window.onload handler") +window.onresize = t.step_func(function() { + assert_unreached("This handler should be overwritten.") +}) + +var body = document.createElement("body") +body.onresize = t.step_func(function(e) { + assert_equals(e.currentTarget, window, + "The event should be fired at the window.") + t.done() +}) +window.dispatchEvent(new Event('resize')); + +t = async_test("document.onresize should set the document.onresize handler"); +document.onresize = t.step_func(function(e) { + assert_equals(e.currentTarget, document, + "The event should be fired at the document") + t.done() +}) +document.dispatchEvent(new Event('resize')); + +t = async_test("meta.onresize should set the meta.onresize handler"); +var meta = document.createElement("meta") +meta.onresize = t.step_func(function(e) { + assert_equals(e.currentTarget, meta, + "The event should be fired at the <meta> object") + t.done() +}) +meta.dispatchEvent(new Event('resize')); +</script> diff --git a/testing/web-platform/tests/html/webappapis/scripting/events/event-handler-processing-algorithm.html b/testing/web-platform/tests/html/webappapis/scripting/events/event-handler-processing-algorithm.html new file mode 100644 index 000000000..f3848b5ad --- /dev/null +++ b/testing/web-platform/tests/html/webappapis/scripting/events/event-handler-processing-algorithm.html @@ -0,0 +1,63 @@ +<!DOCTYPE html> +<title>Event handlers processing algorithm</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> + <body> + <div id="foo" style="width: 100px; height: 100px; background-color: black"></div> + <script> + async_test(function(t) { + var ev = new Event('mouseover', {cancelable: true}); + document.getElementById("foo").onmouseover = t.step_func(function() { return true }); + document.getElementById("foo").dispatchEvent(ev); + assert_equals(ev.defaultPrevented, true) + t.done(); + }, "mouseover listener returning true cancels event"); + + async_test(function(t) { + var ev = new Event('mouseover', {cancelable: true}); + document.getElementById("foo").onmouseover = t.step_func(function() { return false; }); + document.getElementById("foo").dispatchEvent(ev); + assert_equals(ev.defaultPrevented, false); + t.done(); + }, "mouseover listener returning false doesn't cancel event"); + + async_test(function(t) { + var ev = new Event('beforeunload', {cancelable: true}); + window.onbeforeunload = t.step_func(function() {return null}); + window.dispatchEvent(ev); + assert_equals(ev.defaultPrevented, true); + t.done(); + }, "beforeunload listener returning null cancels event"); + + async_test(function(t) { + var ev = new Event('beforeunload', {cancelable: true}); + window.onbeforeunload = t.step_func(function() {return true}); + window.dispatchEvent(ev); + assert_equals(ev.defaultPrevented, false); + t.done(); + }, "beforeunload listener returning non-null doesn't cancel event"); + + async_test(function(t) { + var ev = new Event("click", {cancelable: true}); + document.getElementById("foo").onclick = t.step_func(function() { return false; }); + document.getElementById("foo").dispatchEvent(ev); + assert_equals(ev.defaultPrevented, true); + t.done(); + }, "click listener returning false cancels event"); + + async_test(function(t) { + var ev = new Event("blur", {cancelable: true}); + document.getElementById("foo").onblur = t.step_func(function() { return false; }); + document.getElementById("foo").dispatchEvent(ev); + assert_equals(ev.defaultPrevented, true); + t.done(); + }, "blur listener returning false cancels event"); + + async_test(function(t) { + var ev = new Event("dblclick", {cancelable: true}); + document.getElementById("foo").ondblclick = t.step_func(function() { return false; }); + document.getElementById("foo").dispatchEvent(ev); + assert_equals(ev.defaultPrevented, true); + t.done(); + }, "dblclick listener returning false cancels event"); +</script> diff --git a/testing/web-platform/tests/html/webappapis/scripting/events/event-handler-spec-example.html b/testing/web-platform/tests/html/webappapis/scripting/events/event-handler-spec-example.html new file mode 100644 index 000000000..c06806e3c --- /dev/null +++ b/testing/web-platform/tests/html/webappapis/scripting/events/event-handler-spec-example.html @@ -0,0 +1,65 @@ +<!DOCTYPE html> +<title>Event handler invocation order</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id="log"></div> +<script> +var objects = [{}, function() {}, new Number(42), new String()]; +var primitives = [42, null, undefined, ""]; +objects.forEach(function(object) { + var t = async_test("Event handler listeners should be registered when they " + + "are first set to an object value (" + + format_value(object) + ")."); + t.step(function() { + var i = 0; + var uncalled = "t.step(function() { assert_unreached('First event handler.') })" + var button = document.createElement('button'); + button.onclick = object; // event handler listener is registered here + button.addEventListener('click', t.step_func(function () { assert_equals(++i, 2) }), false); + button.setAttribute('onclick', uncalled); + button.addEventListener('click', t.step_func(function () { assert_equals(++i, 3) }), false); + button.onclick = t.step_func(function () { assert_equals(++i, 1); }); + button.addEventListener('click', t.step_func(function () { assert_equals(++i, 4) }), false); + button.click() + assert_equals(button.getAttribute("onclick"), uncalled) + assert_equals(i, 4); + t.done() + }); +}); +primitives.forEach(function(primitive) { + var t = async_test("Event handler listeners should be registered when they " + + "are first set to an object value (" + + format_value(primitive) + ")."); + t.step(function() { + var i = 0; + var uncalled = "t.step(function() { assert_unreached('First event handler.') })" + var button = document.createElement('button'); + button.onclick = primitive; + button.addEventListener('click', t.step_func(function () { assert_equals(++i, 1) }), false); + button.setAttribute('onclick', uncalled); // event handler listener is registered here + button.addEventListener('click', t.step_func(function () { assert_equals(++i, 3) }), false); + button.onclick = t.step_func(function () { assert_equals(++i, 2); }); + button.addEventListener('click', t.step_func(function () { assert_equals(++i, 4) }), false); + button.click() + assert_equals(button.getAttribute("onclick"), uncalled) + assert_equals(i, 4); + t.done() + }); +}); +var t = async_test("Event handler listeners should be registered when they " + + "are first set to an object value."); +t.step(function() { + var i = 0; + var uncalled = "t.step(function() { assert_unreached('First event handler.') })" + var button = document.createElement('button'); + button.addEventListener('click', t.step_func(function () { assert_equals(++i, 1) }), false); + button.setAttribute('onclick', uncalled); // event handler listener is registered here + button.addEventListener('click', t.step_func(function () { assert_equals(++i, 3) }), false); + button.onclick = t.step_func(function () { assert_equals(++i, 2); }); + button.addEventListener('click', t.step_func(function () { assert_equals(++i, 4) }), false); + button.click() + assert_equals(button.getAttribute("onclick"), uncalled) + assert_equals(i, 4); + t.done() +}); +</script> diff --git a/testing/web-platform/tests/html/webappapis/scripting/events/inline-event-handler-ordering.html b/testing/web-platform/tests/html/webappapis/scripting/events/inline-event-handler-ordering.html new file mode 100644 index 000000000..90e29bfd1 --- /dev/null +++ b/testing/web-platform/tests/html/webappapis/scripting/events/inline-event-handler-ordering.html @@ -0,0 +1,52 @@ +<!doctype html> +<meta charset="utf-8"> +<title>Inline event handlers retain their ordering even when invalid</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<body> +<script> +var events = []; + +test(function() { + events = []; + var e = document.createElement("div"); + document.body.appendChild(e); + e.addEventListener("click", function() { events.push("ONE") }); + e.setAttribute("onclick", "window.open("); + e.addEventListener("click", function() { events.push("THREE") }); + // Try to compile the event handler. + e.onclick; + e.setAttribute("onclick", "events.push('TWO')"); + e.dispatchEvent(new Event("click")); + var expected_events = ["ONE", "TWO", "THREE"]; + assert_array_equals(events, expected_events); +}, "Inline event handlers retain their ordering when invalid and force-compiled"); + +test(function() { + events = []; + var e = document.createElement("div"); + document.body.appendChild(e); + e.addEventListener("click", function() { events.push("ONE") }); + e.setAttribute("onclick", "window.open("); + e.addEventListener("click", function() { events.push("THREE") }); + e.dispatchEvent(new Event("click")); + e.setAttribute("onclick", "events.push('TWO')"); + e.dispatchEvent(new Event("click")); + var expected_events = ["ONE", "THREE", "ONE", "TWO", "THREE"]; + assert_array_equals(events, expected_events); +}, "Inline event handlers retain their ordering when invalid and force-compiled via dispatch"); + +test(function() { + events = []; + var e = document.createElement("div"); + document.body.appendChild(e); + e.addEventListener("click", function() { events.push("ONE") }); + e.setAttribute("onclick", "window.open("); + e.addEventListener("click", function() { events.push("THREE") }); + e.setAttribute("onclick", "events.push('TWO')"); + e.dispatchEvent(new Event("click")); + var expected_events = ["ONE", "TWO", "THREE"]; + assert_array_equals(events, expected_events); +}, "Inline event handlers retain their ordering when invalid and lazy-compiled"); +</script> +</body> diff --git a/testing/web-platform/tests/html/webappapis/scripting/events/invalid-uncompiled-raw-handler-compiled-late.html b/testing/web-platform/tests/html/webappapis/scripting/events/invalid-uncompiled-raw-handler-compiled-late.html new file mode 100644 index 000000000..a0e7bbcdd --- /dev/null +++ b/testing/web-platform/tests/html/webappapis/scripting/events/invalid-uncompiled-raw-handler-compiled-late.html @@ -0,0 +1,25 @@ +<!doctype html> +<meta charset="utf-8"> +<title>Invalid uncompiled raw handlers should only be compiled when about to call them.</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<body> +<script> +setup({ allow_uncaught_exception: true }); + +test(function() { + var events = []; + window.onerror = function() { + events.push("Error"); + }; + + var div = document.createElement("div"); + div.addEventListener("click", function (e) { events.push("click 1") }); + div.setAttribute("onclick", "}"); + div.addEventListener("click", function (e) { events.push("click 2") }); + div.dispatchEvent(new Event("click")); + assert_equals(div.onclick, null); + assert_array_equals(events, ["click 1", "error", "click 2"]); +}); +</script> +</body> diff --git a/testing/web-platform/tests/html/webappapis/scripting/events/invalid-uncompiled-raw-handler-compiled-once.html b/testing/web-platform/tests/html/webappapis/scripting/events/invalid-uncompiled-raw-handler-compiled-once.html new file mode 100644 index 000000000..a67f66ead --- /dev/null +++ b/testing/web-platform/tests/html/webappapis/scripting/events/invalid-uncompiled-raw-handler-compiled-once.html @@ -0,0 +1,23 @@ +<!doctype html> +<meta charset="utf-8"> +<title>Invalid uncompiled raw handlers should only be compiled once.</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<body> +<script> +setup({ allow_uncaught_exception: true }); + +var errors = 0; +window.onerror = function() { + errors++; +}; + +test(function() { + var e = document.body; + e.setAttribute("onclick", "window.open("); + assert_equals(e.onclick, null); + assert_equals(e.onclick, null); + assert_equals(errors, 1); +}); +</script> +</body> diff --git a/testing/web-platform/tests/html/webappapis/scripting/events/onerroreventhandler-frame.html b/testing/web-platform/tests/html/webappapis/scripting/events/onerroreventhandler-frame.html new file mode 100644 index 000000000..79e4af302 --- /dev/null +++ b/testing/web-platform/tests/html/webappapis/scripting/events/onerroreventhandler-frame.html @@ -0,0 +1,56 @@ +<body></body> +<script> +function check1(args, callee) { + parent.t.step(function() { + parent.assert_equals(callee.length, 5); + parent.assert_equals(args.length, 5); + parent.assert_equals(args[0], reference_error.message); + parent.assert_equals(args[1], reference_error.filename); + parent.assert_equals(args[2], reference_error.lineno); + parent.assert_equals(args[3], reference_error.colno); + parent.assert_equals(args[4], reference_error.error); + parent.t.done(); + }); +} + +var reference_error = new ErrorEvent("error", { + filename: "error_file.js", + lineno: 333, + colno: 999, + message: "there was an error", + error: {nondefault: 'some unusual object'}, +}); + +parent.t.step(function() { + document.body.outerHTML = "<body onerror='check1(arguments, arguments.callee)'></body>" + window.dispatchEvent(reference_error); +}); + +function check2(args, callee) { + parent.t2.step(function() { + parent.assert_equals(callee.length, 5); + parent.assert_equals(args.length, 1); + parent.assert_false(args[0] instanceof ErrorEvent); + parent.t2.done() + }); +} + +parent.t2.step(function() { + document.body.outerHTML = "<body onerror='check2(arguments, arguments.callee)'></body>" + window.dispatchEvent(new Event("error")); +}); + +function check3(args, callee) { + parent.t3.step(function() { + parent.assert_equals(args.length, 1); + parent.assert_equals(callee.length, 1); + }); +} + +parent.t3.step(function() { + document.body.outerHTML = "<body><span onerror='check3(arguments, arguments.callee)'></span></body>" + document.body.firstChild.dispatchEvent(reference_error); + document.body.firstChild.dispatchEvent(new Event("error")); + parent.t3.done(); +}); +</script> diff --git a/testing/web-platform/tests/html/webappapis/scripting/events/onerroreventhandler.html b/testing/web-platform/tests/html/webappapis/scripting/events/onerroreventhandler.html new file mode 100644 index 000000000..60fc674d5 --- /dev/null +++ b/testing/web-platform/tests/html/webappapis/scripting/events/onerroreventhandler.html @@ -0,0 +1,11 @@ +<!doctype html> +<meta charset=utf-8> +<title>OnErrorEventHandler + ErrorEvent is treated differently</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script> +var t = async_test("onerror + ErrorEvent + Window"); +var t2 = async_test("onerror + !ErrorEvent + Window"); +var t3 = async_test("onerror + Document"); +</script> +<iframe src="onerroreventhandler-frame.html"></iframe> |