summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/long-animation-frame/tentative/loaf-first-ui-event.html
blob: 7e32010189023859a5a078e2faf88a0a329cd743 (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<!DOCTYPE HTML>
<meta charset=utf-8>
<title>Long Animation Frame Timing: first UI Event</title>
<meta name="timeout" content="long">
<script src=/resources/testdriver.js></script>
<script src=/resources/testdriver-actions.js></script>
<script src=/resources/testdriver-vendor.js></script>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/utils.js"></script>

<body>
<h1>Long Animation Frame: First UI Event</h1>
<div id="log"></div>
<script>

promise_test(async t => {
  const button = document.createElement("button");
  button.innerText = "Click";
  document.body.appendChild(button);
  t.add_cleanup(() => button.remove());
  const eventPromise = new Promise(resolve => button.addEventListener("click", event => {
    busy_wait();
    resolve(event);
  }));
  const entryPromise = expect_long_frame_with_script(() => {
    test_driver.click(button);
  }, s => s.invoker === "BUTTON.onclick", t);
  await new Promise(resolve => t.step_timeout(resolve, 0));
  const event = await eventPromise;
  const [entry] = await entryPromise;
  assert_equals(entry.firstUIEventTimestamp, event.timeStamp);
}, "LoAF should expose firstUIEventTimestamp for click events");

promise_test(async t => {
  const button = document.createElement("button");
  button.innerText = "Hover";
  document.body.appendChild(button);
  t.add_cleanup(() => button.remove());
  let expectedTimestamp = null;
  const entryPromise = expect_long_frame_with_script(async () => {
    const eventPromise = new Promise(resolve => button.addEventListener("pointermove", event => {
      busy_wait();
      expectedTimestamp = event.timeStamp;
      resolve();
    }));

    const actions = new test_driver.Actions()
       .pointerMove(0, 0, {origin: button})
       .pointerDown()
       .pointerUp();
    await actions.send();
    await eventPromise;
  }, (script, entry) =>
      script.invoker === "BUTTON.onpointermove" &&
      entry.firstUIEventTimestamp === expectedTimestamp, t);
}, "LoAF should expose firstUIEventTimestamp for pointermove events");

promise_test(async t => {
  const button = document.createElement("button");
  button.innerText = "Click";
  document.body.appendChild(button);
  t.add_cleanup(() => button.remove());
  let firstUIEventTimestamp = null;
  const eventPromise = new Promise(resolve => button.addEventListener("click", event => {
    if (firstUIEventTimestamp)
      resolve(event);
    else {
      firstUIEventTimestamp = event.timeStamp;
      busy_wait();
    }
  }));
  const entryPromise = expect_long_frame_with_script(() => {
    test_driver.click(button);
    test_driver.click(button);
  }, s => s.invoker === "BUTTON.onclick", t);
  const [event, [entry]] = await Promise.all([eventPromise, entryPromise]);
  assert_equals(entry.firstUIEventTimestamp, firstUIEventTimestamp);
}, "firstUIEventTimestamp doesn't have to come from a long script");
</script>
</body>