summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/long-animation-frame/tentative/loaf-first-ui-event.html
blob: 47a3a51de215e47add78b96047d431b13eb89257 (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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<!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.name === "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;
  }, s => s.name === "BUTTON.onpointermove", t);
  const [entry] = await entryPromise;
  assert_equals(entry.firstUIEventTimestamp, expectedTimestamp);
}, "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.name === "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");


promise_test(async t => {
  const entryPromise = expect_long_frame_with_script(() => {
    const img = document.createElement("img");
    img.src = "/images/green.png";
    const promise = new Promise(resolve =>
      img.addEventListener("load", event => {
        busy_wait();
        resolve();
      }));
    document.body.appendChild(img);
    t.add_cleanup(() => img.remove());
    return promise;
  }, s => s.name === "IMG[src=/images/green.png].onload", t);

  const [entry, script] = await entryPromise;
  assert_not_equals(entry.firstUIEventTimestamp, script.desiredExecutionStart);
}, "Non-UI events don't affect firstUIEventTimestamp");

</script>
</body>