summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/dom/events/non-cancelable-when-passive/synthetic-events-cancelable.html
blob: 4287770b8d58281c09c8174b9d7757174e51ff29 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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>