summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/uievents/click/click_events_on_input.html
blob: 2f380eb4514bc79df891b409c9007271c7f66923 (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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Clicking with primary vs non-primary buttons</title>
    <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>
  </head>
  <body>
    <h1>Clicking on input type=text element when placeholder changes</h1>
    <input id="target" onfocus="this.placeholder = ++focusCount;" placeholder="initial">
    <input id="other">
    <script>
    var focusCount = 0;
    var target = document.querySelector('#target');
    document.addEventListener('contextmenu', event => { event.preventDefault(); });

    var test_click = async_test("Test click and auxclick on input element");

    // The test is on purpose rather vague, since auxclick handling on
    // touchscreens isn't well defined.
    // But at least there should be 'click'
    var didGetClick = false;
    async function testClick(type, mouseButton) {
      return new Promise((resolve) => {
        target.addEventListener(type, event => {
          event.preventDefault();
          didGetClick = didGetClick || event.type == "click";
          test_click.step(() => {
            assert_equals(event.type, type, 'Should have got an event.');
          });
        }, {once: true});

        // Inject mouse click events.
        var actions = new test_driver.Actions();
        document.getElementById("other").focus();
        actions.pointerMove(0, 0, {origin: target})
               .pointerDown({button: mouseButton})
               .pointerUp({button: mouseButton})
               .send()
               .then(resolve);
      });
    }

    async function testClicks() {
      var buttonType = test_driver.Actions.prototype.ButtonType;
      await testClick("click", buttonType.LEFT);
      await testClick("auxclick", buttonType.MIDDLE);
      await testClick("auxclick", buttonType.RIGHT);
      test_click.step(() => {
          assert_true(didGetClick, 'Should have got at least "click".');
        });
      test_click.done();
    }

    testClicks();
    </script>
  </body>
</html>