tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

click_events_on_input.html (2248B)


      1 <!DOCTYPE html>
      2 <html>
      3  <head>
      4    <meta charset="utf-8">
      5    <title>Clicking with primary vs non-primary buttons</title>
      6    <script src="/resources/testharness.js"></script>
      7    <script src="/resources/testharnessreport.js"></script>
      8    <script src="/resources/testdriver.js"></script>
      9    <script src="/resources/testdriver-actions.js"></script>
     10    <script src="/resources/testdriver-vendor.js"></script>
     11  </head>
     12  <body>
     13    <h1>Clicking on input type=text element when placeholder changes</h1>
     14    <input id="target" onfocus="this.placeholder = ++focusCount;" placeholder="initial">
     15    <input id="other">
     16    <script>
     17    var focusCount = 0;
     18    var target = document.querySelector('#target');
     19    document.addEventListener('contextmenu', event => { event.preventDefault(); });
     20 
     21    var test_click = async_test("Test click and auxclick on input element");
     22 
     23    // The test is on purpose rather vague, since auxclick handling on
     24    // touchscreens isn't well defined.
     25    // But at least there should be 'click'
     26    var didGetClick = false;
     27    async function testClick(type, mouseButton) {
     28      return new Promise((resolve) => {
     29        target.addEventListener(type, event => {
     30          event.preventDefault();
     31          didGetClick = didGetClick || event.type == "click";
     32          test_click.step(() => {
     33            assert_equals(event.type, type, 'Should have got an event.');
     34          });
     35        }, {once: true});
     36 
     37        // Inject mouse click events.
     38        var actions = new test_driver.Actions();
     39        document.getElementById("other").focus();
     40        actions.pointerMove(0, 0, {origin: target})
     41               .pointerDown({button: mouseButton})
     42               .pointerUp({button: mouseButton})
     43               .send()
     44               .then(resolve);
     45      });
     46    }
     47 
     48    async function testClicks() {
     49      var buttonType = test_driver.Actions.prototype.ButtonType;
     50      await testClick("click", buttonType.LEFT);
     51      await testClick("auxclick", buttonType.MIDDLE);
     52      await testClick("auxclick", buttonType.RIGHT);
     53      test_click.step(() => {
     54          assert_true(didGetClick, 'Should have got at least "click".');
     55        });
     56      test_click.done();
     57    }
     58 
     59    testClicks();
     60    </script>
     61  </body>
     62 </html>