summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/semantics/interactive-elements/the-dialog-element/synthetic-click-inert.html
blob: 3be8213cd4a4237fb0264709d6c6d9bd0291231a (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
35
36
37
38
39
40
<!DOCTYPE html>
<link rel=author href="mailto:jarhar@chromium.org">
<link rel=author href="mailto:falken@chromium.org">
<link rel=help href="https://html.spec.whatwg.org/multipage/interactive-elements.html#the-dialog-element">
<link rel=help href="https://bugs.chromium.org/p/chromium/issues/detail?id=241699">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<style>
dialog {
  width: 50px;
}
</style>

<button>Click me</button>
<div id="div">Click me too</div>
<dialog></dialog>

<script>
test(() => {
  dialog = document.querySelector('dialog');
  dialog.showModal();

  const button = document.querySelector('button');
  const div = document.getElementById('div');
  let clicked = false;

  [button, div].forEach(function(element) {
    element.addEventListener('click', () => clicked = true);

    clicked = false;
    element.click();
    assert_true(clicked, 'Calling click() on ' + element.tagName);

    clicked = false;
    element.dispatchEvent(new Event('click'));
    assert_true(clicked, 'Calling dispatchEvent() on ' + element.tagName);
  });
}, 'Test that inert nodes still get programmatic click events');
</script>