tor-browser

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

pointerevent_touch-adjustment_click_target.html (2931B)


      1 <!DOCTYPE html>
      2 <meta charset="utf-8">
      3 <title>Touch-generated events should have the same target</title>
      4 <script src="/resources/testharness.js"></script>
      5 <script src="/resources/testharnessreport.js"></script>
      6 <script src="/resources/testdriver.js"></script>
      7 <script src="/resources/testdriver-vendor.js"></script>
      8 <script src="/resources/testdriver-actions.js"></script>
      9 <p>Touch letter 'O' below to run the test. If a "PASS" result appears the test passes, otherwise it fails</p>
     10 <p><a href="#" id="link">Link</a> <span id="target">O</span></p>
     11 <div id="log"></div>
     12 <script>
     13 let input_gesture;
     14 const target = document.getElementById('target');
     15 const xPosition = Math.ceil(target.offsetLeft + 2);
     16 const yPosition = Math.ceil(target.offsetTop + 2);
     17 
     18 function inject_input() {
     19  let actions = new test_driver.Actions();
     20  return actions
     21        .addPointer("touchPointer", "touch")
     22        .setPointer("touchPointer")
     23        .pointerMove(xPosition, yPosition)
     24        .pointerDown()
     25        .pointerUp()
     26        .send();
     27 }
     28 
     29 promise_test(async t => {
     30    const link = document.getElementById('link');
     31    const expectedEventLog = ['pointerdown-link', 'touchstart-link', 'pointerup-link', 'touchend-link', 'click-link'];
     32    const eventLogRecorder = [];
     33 
     34    await new Promise(resolve => addEventListener("load", resolve));
     35 
     36    const eventNames = ['touchstart', 'touchmove', 'touchend', 'pointerdown', 'pointermove', 'pointerup', 'click'];
     37    for (eventName of eventNames) {
     38        document.addEventListener(eventName, t.step_func(event => {
     39            // TouchEvent and PointerEvent should have the same un-adjusted coordinates.
     40            // click event should have coordinates adjusted to link element.
     41            const eventClientX = event.clientX || (event.touches.length > 0 ? event.touches[0].clientX : 0);
     42            const eventClientY = event.clientY || (event.touches.length > 0 ? event.touches[0].clientY : 0);
     43 
     44            if (event.type === 'click') {
     45                assert_equals(document.elementFromPoint(eventClientX, eventClientY), link,
     46                    'click should have clientX/Y adjusted to link.');
     47            } else if (event.type != 'touchend') {
     48                assert_equals(eventClientX, xPosition,
     49                    `${event.type} should have un-adjusted x coordinates.`);
     50                assert_equals(eventClientY, yPosition,
     51                    `${event.type} should have un-adjusted y coordinates.`);
     52            }
     53 
     54            // All events should have target adjusted to link.
     55            const targetName = event.target.id || event.target.nodeName || '[null]';
     56            eventLogRecorder.push(`${event.type}-${targetName}`);
     57            if (event.type === 'click') {
     58                assert_array_equals(eventLogRecorder, expectedEventLog);
     59                input_gesture.then(() => { t.done(); });
     60            }
     61        }));
     62    }
     63    input_gesture = inject_input();
     64 });
     65 </script>