tor-browser

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

programmatic-click-not-observed.html (2100B)


      1 <!DOCTYPE html>
      2 <html>
      3 <meta charset=utf-8 />
      4 <div id='div' onclick='delay()'>Click me</div>
      5 <div id='div2'>No, click me!</div>
      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-vendor.js></script>
     10 
     11 <script src=resources/event-timing-test-utils.js></script>
     12 <script>
     13  let delayCalled = false;
     14  let beforeClick;
     15  function delay() {
     16    const end = performance.now() + 150;
     17    while(performance.now() < end) {}
     18    delayCalled = true;
     19  }
     20  promise_test(function(t) {
     21    assert_implements(window.PerformanceEventTiming, 'Event Timing is not supported.');
     22    let observedPointerDown = false;
     23    const observerPromise = new Promise(resolve => {
     24      const observer = new PerformanceObserver(t.step_func(entryList => {
     25        const pointerDowns = entryList.getEntriesByName('pointerdown');
     26        // Ignore cases in which there is no pointerdown.
     27        if (pointerDowns.length === 0)
     28          return;
     29 
     30        assert_false(observedPointerDown, 'There must only be one pointerdown entry.');
     31        assert_equals(pointerDowns.length, 1);
     32        const entry = pointerDowns[0];
     33        // This ensures that the entry is exposing timing from the second click, i.e.
     34        // the one from the clickAndBlockMain() call.
     35        assert_greater_than_equal(entry.processingStart, beforeClick);
     36        verifyClickEvent(entry, 'div2', true);
     37        observedPointerDown = true;
     38        resolve();
     39      }));
     40      observer.observe({entryTypes: ['event']});
     41    });
     42    document.getElementById('div').click();
     43    // Take the timestamp after the programmatic click but before the next click.
     44    beforeClick = performance.now();
     45    // After the programmatic click, use another input to know when entries have been
     46    // dispatched to the PerformanceObserver callback.
     47    const clickPromise = clickAndBlockMain('div2');
     48    return Promise.all([observerPromise, clickPromise]);
     49  }, "Event Timing: events from programmatic click are not observed");
     50 </script>
     51 </html>