tor-browser

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

loaf-first-ui-event.html (3011B)


      1 <!DOCTYPE HTML>
      2 <meta charset=utf-8>
      3 <title>Long Animation Frame Timing: first UI Event</title>
      4 <meta name="timeout" content="long">
      5 <script src=/resources/testdriver.js></script>
      6 <script src=/resources/testdriver-actions.js></script>
      7 <script src=/resources/testdriver-vendor.js></script>
      8 <script src="/resources/testharness.js"></script>
      9 <script src="/resources/testharnessreport.js"></script>
     10 <script src="resources/utils.js"></script>
     11 
     12 <body>
     13 <h1>Long Animation Frame: First UI Event</h1>
     14 <div id="log"></div>
     15 <script>
     16 
     17 promise_test(async t => {
     18  const button = document.createElement("button");
     19  button.innerText = "Click";
     20  document.body.appendChild(button);
     21  t.add_cleanup(() => button.remove());
     22  let busy_wait = null;
     23  let event_ts = 0;
     24  const entryPromise = expect_long_frame_with_script((t, busy_wait) => {
     25    button.addEventListener("click", event => {
     26      busy_wait();
     27      event_ts = event.timeStamp;
     28    });
     29    test_driver.click(button);
     30  }, s => s.invoker === "BUTTON.onclick", t);
     31  await new Promise(resolve => t.step_timeout(resolve, 0));
     32  const [entry] = await entryPromise;
     33  assert_equals(entry.firstUIEventTimestamp, event_ts);
     34 }, "LoAF should expose firstUIEventTimestamp for click events");
     35 
     36 promise_test(async t => {
     37  const button = document.createElement("button");
     38  button.innerText = "Hover";
     39  document.body.appendChild(button);
     40  t.add_cleanup(() => button.remove());
     41  let expectedTimestamp = null;
     42  const entryPromise = expect_long_frame_with_script(async (t, busy_wait) => {
     43    const eventPromise = new Promise(resolve => button.addEventListener("pointermove", event => {
     44      busy_wait();
     45      expectedTimestamp = event.timeStamp;
     46      resolve();
     47    }));
     48 
     49    const actions = new test_driver.Actions()
     50       .pointerMove(0, 0, {origin: button})
     51       .pointerDown()
     52       .pointerUp();
     53    await actions.send();
     54    await eventPromise;
     55  }, (script, entry) =>
     56      script.invoker === "BUTTON.onpointermove" &&
     57      entry.firstUIEventTimestamp === expectedTimestamp, t);
     58 }, "LoAF should expose firstUIEventTimestamp for pointermove events");
     59 
     60 promise_test(async t => {
     61  const button = document.createElement("button");
     62  button.innerText = "Click";
     63  document.body.appendChild(button);
     64  t.add_cleanup(() => button.remove());
     65  let firstUIEventTimestamp = null;
     66  let busy_wait = null;
     67  const eventPromise = new Promise(resolve => button.addEventListener("click", event => {
     68    if (firstUIEventTimestamp)
     69      resolve(event);
     70    else {
     71      firstUIEventTimestamp = event.timeStamp;
     72      busy_wait();
     73    }
     74  }));
     75  const entryPromise = expect_long_frame_with_script(async (t, busy_wait_func) => {
     76    busy_wait = busy_wait_func;
     77    await test_driver.click(button);
     78  }, s => s.invoker === "BUTTON.onclick", t);
     79  const [event, [entry]] = await Promise.all([eventPromise, entryPromise]);
     80  assert_equals(entry.firstUIEventTimestamp, firstUIEventTimestamp);
     81 }, "firstUIEventTimestamp doesn't have to come from a long script");
     82 </script>
     83 </body>