diff options
Diffstat (limited to 'testing/web-platform/tests/uievents/interface')
6 files changed, 193 insertions, 0 deletions
diff --git a/testing/web-platform/tests/uievents/interface/README.md b/testing/web-platform/tests/uievents/interface/README.md new file mode 100644 index 0000000000..970fdd4df3 --- /dev/null +++ b/testing/web-platform/tests/uievents/interface/README.md @@ -0,0 +1,13 @@ +Interface tests +============================== + +These test that the basic UI Events interfaces exist, specifically: + +1. Does the interface exist +2. Are all the members defined on the interface accounted for: + * UIEvent + * MouseEvent + * FocusEvent + * KeyboardEvent + * WheelEvent + * CompositionEvent diff --git a/testing/web-platform/tests/uievents/interface/click-event-manual.htm b/testing/web-platform/tests/uievents/interface/click-event-manual.htm new file mode 100644 index 0000000000..88db98d591 --- /dev/null +++ b/testing/web-platform/tests/uievents/interface/click-event-manual.htm @@ -0,0 +1,21 @@ +<!doctype html> +<html> + <head> + <title>Click event is a MouseEvent</title> + <script src="/resources/testharness.js"></script> + <script src="/resources/testharnessreport.js"></script> + <style>#clicktarget { width: 100px; height: 100px; background-color: red; }</style> + </head> + <body> + <div id='clicktarget'>Click in this box.</div> + <div id="log"></div> + <script type="text/javascript"> +var t = async_test('click event generated from user action "click" is a MouseEvent'); +document.querySelector("#clicktarget").addEventListener('click', t.step_func(function (e) { + assert_equals(e.constructor, window.MouseEvent); + document.querySelector("#clicktarget").style.backgroundColor = "green"; + t.done(); +})); + </script> + </body> +</html> diff --git a/testing/web-platform/tests/uievents/interface/click-event.htm b/testing/web-platform/tests/uievents/interface/click-event.htm new file mode 100644 index 0000000000..b45dc29063 --- /dev/null +++ b/testing/web-platform/tests/uievents/interface/click-event.htm @@ -0,0 +1,32 @@ +<!doctype html> +<html> + <head> + <title>Click event is a PointerEvent</title> + <link rel="help" href="https://github.com/w3c/pointerevents/pull/317"> + <script src="/resources/testharness.js"></script> + <script src="/resources/testharnessreport.js"></script> + </head> + <body> + <div id='clicktarget'></div> + <div id="log"></div> + <script type="text/javascript"> + var clicktarget = document.querySelector("#clicktarget"); + var t = async_test("synthetic click event is a PointerEvent"); + clicktarget.addEventListener('click', t.step_func(function (e) { + assert_equals(e.constructor, window.PointerEvent, "Click is a PointerEvent"); + assert_true(e instanceof window.PointerEvent, "Click is an instance of PointerEvent"); + // Since this click is not generated by a pointing device, pointerId must have + // the reserved value -1, and pointerType must have the default empty string + assert_equals(e.pointerId, -1, "Click's pointerId has the default value of -1"); + assert_equals(e.pointerType, "", "Click's pointerType has the default value of empty string"); + assert_equals(e.screenX, 0, "Click's screenX coordinate should not be set."); + assert_equals(e.screenY, 0, "Click's screenY coordinate should not be set."); + assert_equals(e.clientX, 0, "Click's clientX coordinate should not be set."); + assert_equals(e.clientY, 0, "Click's clientY coordinate should not be set."); + assert_equals(e.detail, 0, "element.click click event should not populate click count"); + t.done(); + })); + document.querySelector('#clicktarget').click(); + </script> + </body> +</html> diff --git a/testing/web-platform/tests/uievents/interface/dblclick-event-manual.htm b/testing/web-platform/tests/uievents/interface/dblclick-event-manual.htm new file mode 100644 index 0000000000..7ea0bdbf13 --- /dev/null +++ b/testing/web-platform/tests/uievents/interface/dblclick-event-manual.htm @@ -0,0 +1,21 @@ +<!doctype html> +<html> + <head> + <title>Double click (dblclick) event is a MouseEvent</title> + <script src="/resources/testharness.js"></script> + <script src="/resources/testharnessreport.js"></script> + <style>#clicktarget { width: 100px; height: 100px; background-color: red; }</style> + </head> + <body> + <div id='clicktarget'>Double Click in this box.</div> + <div id="log"></div> + <script type="text/javascript"> +var t = async_test('click event generated from user action "click" is a MouseEvent'); +document.querySelector("#clicktarget").addEventListener('dblclick', t.step_func(function (e) { + assert_equals(e.constructor, window.MouseEvent); + document.querySelector("#clicktarget").style.backgroundColor = "green"; + t.done(); +})); + </script> + </body> +</html> diff --git a/testing/web-platform/tests/uievents/interface/keyboard-accesskey-click-event.html b/testing/web-platform/tests/uievents/interface/keyboard-accesskey-click-event.html new file mode 100644 index 0000000000..f90101e31e --- /dev/null +++ b/testing/web-platform/tests/uievents/interface/keyboard-accesskey-click-event.html @@ -0,0 +1,56 @@ +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="/resources/testdriver.js"></script> +<script src="/resources/testdriver-actions.js"></script> +<script src="/resources/testdriver-vendor.js"></script> +<script src="/resources/accesskey.js"></script> + +<p>Tests that a keyboard access key to press a button will fire only the click event</p> +<button id="button" accesskey="g">Click Me with Shift+Alt+g or on Mac with Control+Option+g</button> +<input id="inputbutton" type="button" accesskey="b" value="Click me with Shift+Alt+b or on Mac with Control+Option+b"> +<label id="label" accesskey="l">Click Me with Shift+Alt+l or on Mac with Control+Option+l</label> + +<script> +let button = document.getElementById("button"); +let inputbutton = document.getElementById("inputbutton"); +let radiobutton = document.getElementById("radiobutton"); +let label = document.getElementById("label"); +let elementList = [button, inputbutton, label]; +let eventLog = []; +const eventList = ["pointerdown", "pointerup", "mousedown", "mouseup", "click"]; +elementList.forEach((el)=>{eventList.forEach((ev)=>el.addEventListener(ev, (e)=>{ + eventLog.push(`${ev}_${el.id}`); + if(ev === "click" && currentTest){ + currentTest.step(()=>{ + if(e instanceof PointerEvent){ + // We want the test to run on all browsers even if click is not a PointerEvent. + assert_equals(e.pointerId, 0, "Click's pointerId has default value"); + assert_equals(e.pointerType, "", "Click's pointerType has default value"); + } + assert_equals(e.screenX, 0, "Click's screenX has default value"); + assert_equals(e.screenY, 0, "Click's screenY has default value"); + assert_equals(e.clientX, 0, "Click's clientX has default value"); + assert_equals(e.clientY, 0, "Click's clientY has default value"); + assert_equals(e.pageX, 0, "Click's pageX has default value"); + assert_equals(e.pageY, 0, "Click's pageY has default value"); + // https://github.com/w3c/csswg-drafts/issues/1070 + assert_equals(e.offsetX, 0, "Click's offsetX should have default value"); + assert_equals(e.offsetY, 0, "Click's offsetY should have default value"); + }); + } +}));}); +let currentTest; +let testElements = [button, inputbutton, label]; +let accesskeyMap = new Map([[button, "g"], [inputbutton, "b"], [label, "l"]]); +testElements.forEach((el)=>promise_test((test)=> new Promise(async (resolve,reject)=>{ + currentTest = test; + eventLog = []; + var eventWatcher = new EventWatcher(test, el, ['click']); + let waitForClick = eventWatcher.wait_for('click'); + await pressAccessKey(accesskeyMap.get(el)); + await waitForClick; + + assert_array_equals(eventLog, [`click_${el.id}`], "The Keyboard generated click only sends the click event."); + resolve(); +}), `Test that the Keyboard generated click does not fire pointer or mouse events for ${el.id}`)); +</script> diff --git a/testing/web-platform/tests/uievents/interface/keyboard-click-event.html b/testing/web-platform/tests/uievents/interface/keyboard-click-event.html new file mode 100644 index 0000000000..2b5e06d9c1 --- /dev/null +++ b/testing/web-platform/tests/uievents/interface/keyboard-click-event.html @@ -0,0 +1,50 @@ +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="/resources/testdriver.js"></script> +<script src="/resources/testdriver-actions.js"></script> +<script src="/resources/testdriver-vendor.js"></script> + +<p>Tests that a button pressed by using Space or Enter will fire only the click event</p> +<button id="button">Click Me by pressing Enter or Space</button> +<input id="inputbutton" type="button" value="Click me by pressing Enter or Space"> + +<script> +let button = document.getElementById("button"); +let inputbutton = document.getElementById("inputbutton"); +let radiobutton = document.getElementById("radiobutton"); +let elementList = [button, inputbutton]; +let eventLog = []; +const enterKey = '\uE006'; +const spaceKey = ' '; +let keys = [spaceKey, enterKey]; +const eventList = ["pointerdown", "pointerup", "mousedown", "mouseup", "click"]; +elementList.forEach((el)=>{eventList.forEach((ev)=>el.addEventListener(ev, (e)=>{ + eventLog.push(`${ev}_${el.id}`); + if(ev === "click" && currentTest){ + currentTest.step(()=>{ + if(e instanceof PointerEvent){ + // We want the test to run on all browsers even if click is not a PointerEvent. + assert_equals(e.pointerId, -1, "Click's pointerId has reserved value"); + assert_equals(e.pointerType, "", "Click's pointerType has default value"); + } + }); + } +}));}); +let currentTest; +let testElements = [button, inputbutton]; +let keyNameMap = new Map([[spaceKey, "space"], [enterKey, "enter"]]); +keys.forEach((key)=>testElements.forEach((el)=>promise_test((test)=> new Promise(async (resolve,reject)=>{ + currentTest = test; + eventLog = []; + var eventWatcher = new EventWatcher(test, el, ['click']); + let waitForClick = eventWatcher.wait_for('click'); + el.focus(); + let actions = new test_driver.Actions(); + await test_driver + .send_keys(el, key); + await waitForClick; + + assert_array_equals(eventLog, [`click_${el.id}`], "The Keyboard generated click only sends the click event."); + resolve(); +}), `Test that the Keyboard generated click does not fire pointer or mouse events for ${el.id} when pressing ${keyNameMap.get(key)} key`))); +</script> |