diff options
Diffstat (limited to 'testing/web-platform/tests/dom/events/non-cancelable-when-passive/synthetic-events-cancelable.html')
-rw-r--r-- | testing/web-platform/tests/dom/events/non-cancelable-when-passive/synthetic-events-cancelable.html | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/testing/web-platform/tests/dom/events/non-cancelable-when-passive/synthetic-events-cancelable.html b/testing/web-platform/tests/dom/events/non-cancelable-when-passive/synthetic-events-cancelable.html new file mode 100644 index 0000000000..4287770b8d --- /dev/null +++ b/testing/web-platform/tests/dom/events/non-cancelable-when-passive/synthetic-events-cancelable.html @@ -0,0 +1,34 @@ +<!DOCTYPE html> +<title>Synthetic events are always cancelable by default</title> +<link rel="help" href="https://dom.spec.whatwg.org/#dictdef-eventinit"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script> +const eventsMap = { + wheel: 'WheelEvent', + mousewheel: 'WheelEvent', + touchstart: 'TouchEvent', + touchmove: 'TouchEvent', + touchend: 'TouchEvent', + touchcancel: 'TouchEvent', +} +function isCancelable(eventName, interfaceName) { + test(() => { + assert_implements(interfaceName in self, `${interfaceName} should be supported`); + let defaultPrevented = null; + addEventListener(eventName, event => { + event.preventDefault(); + defaultPrevented = event.defaultPrevented; + }); + const event = new self[interfaceName](eventName); + assert_false(event.cancelable, 'cancelable'); + const dispatchEventReturnValue = dispatchEvent(event); + assert_false(defaultPrevented, 'defaultPrevented'); + assert_true(dispatchEventReturnValue, 'dispatchEvent() return value'); + }, `Synthetic ${eventName} event with interface ${interfaceName} is not cancelable`); +} +for (const eventName in eventsMap) { + isCancelable(eventName, eventsMap[eventName]); + isCancelable(eventName, 'Event'); +} +</script> |