summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/long-animation-frame/tentative/loaf-blocking-duration.html
blob: e56a98649ec530bafaf1debb8f77af97002bad51 (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
<!DOCTYPE HTML>
<meta charset=utf-8>
<title>Long Animation Frame Timing: basic</title>
<meta name="timeout" content="long">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/utils.js"></script>

<body>
<h1>Long Animation Frame: blocking duration</h1>
<div id="log"></div>
<script>

function loaf_blocking_duration_test(run, label) {
  const OVERHEAD_EPSILON = 5;
  const BLOCKING_THRESHOLD = 50;
  promise_test(async t => {
    let found = false;
    for (let i = 0; i < 10 && !found; ++i) {
      const longtask_promise = new Promise(resolve => new PerformanceObserver(
      (entries, observer) => {
        resolve(entries.getEntries());
        observer.disconnect();
      }).observe({entryTypes: ["longtask"]}));
      const [longtask_entries, loaf_entry] = await Promise.all(
        [longtask_promise, expect_long_frame(run, t)]);
      const overlapping = longtask_entries.filter(longtask =>
        (longtask.startTime >= loaf_entry.startTime &&
          longtask.startTime < (loaf_entry.startTime + loaf_entry.duration) &&
          (!loaf_entry.renderStart ||
          (longtask.startTime < loaf_entry.renderStart - OVERHEAD_EPSILON))));

      const longest_index = overlapping.reduce(
        (max, cur, i) => cur > overlapping[max] ? i : max, 0);
      let expected_blocking_duration = 0;
      overlapping.forEach(({duration}, i) => {
        if (i === longest_index && loaf_entry.renderStart)
          duration += loaf_entry.startTime + loaf_entry.duration -
          loaf_entry.renderStart;
        expected_blocking_duration += Math.max(0, duration - BLOCKING_THRESHOLD);
      });

      if (!overlapping.length && loaf_entry.renderStart) {
        expected_blocking_duration =
          Math.max(0,
            loaf_entry.startTime + loaf_entry.duration - loaf_entry.renderStart -
            BLOCKING_THRESHOLD);
      }

      if (Math.abs(loaf_entry.blockingDuration - expected_blocking_duration) <
          OVERHEAD_EPSILON) {
        found = true;
      }
    }
    assert_true(found);
  }, `LoAF blockingDuration should be equivalent to long tasks: ${label}`);
}

loaf_blocking_duration_test(t => t.step_timeout(busy_wait), "Non-rendering");
loaf_blocking_duration_test(t => t.step_timeout(() => {
  busy_wait();
  requestAnimationFrame(busy_wait);
}), "Rendering");
</script>
</body>