File: start-time-compat.html

package info (click to toggle)
firefox 144.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,637,504 kB
  • sloc: cpp: 7,576,692; javascript: 6,430,831; ansic: 3,748,119; python: 1,398,978; xml: 628,810; asm: 438,679; java: 186,194; sh: 63,212; makefile: 19,159; objc: 13,086; perl: 12,986; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 53; csh: 10
file content (84 lines) | stat: -rw-r--r-- 3,001 bytes parent folder | download | duplicates (3)
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
<!DOCTYPE html>
<meta charset=utf-8>
<title>Start time compatibility</title>
<link rel="help"
      href="https://www.w3.org/TR/web-animations-1/#waiting-for-the-associated-effect">
<!-- Strictly speaking, this test is asserting timing behavior that is more
     strict than required by spec. It tests that the start time of animations
     created during a page rendering update match that update's timeline time.
     This behavior is now consistent across browsers.
     See https://bugs.webkit.org/show_bug.cgi?id=290993 -->
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/web-animations/testcommon.js"></script>
<script src="/web-animations/resources/timing-override.js"></script>
<body>
<div id="log"></div>
<script>
'use strict';

promise_test(async t => {
  await waitForCompositorReady();

  const timeout_promise = () => {
    return new Promise(resolve => setTimeout(resolve));
  };

  const expected_start_this_frame = () => {
    return document.timeline.currentTime;
  }

  const expected_start_next_frame = () => {
    return new Promise(resolve => {
      requestAnimationFrame(() => {
        resolve(document.timeline.currentTime);
      })
    });
  }

  const promises = [];

  const make_animation = (description, expected_start_time) => {
    const anim = createDiv(t).animate(null, 100 * MS_PER_SEC);
    promises.push(
        new Promise(resolve => {
          Promise.all([anim.ready, expected_start_time]).then(responses => {
            assert_times_equal(anim.startTime, responses[1], description);
            resolve();
          });
        }));
  }

  // rAF align the start of the test.
  await waitForAnimationFrames(2);

  // Create an animation during the page rendering update.
  // This animation should be aligned with the rAF time.
  make_animation('during the first page rendering update',
                 expected_start_this_frame());

  // Wait for a new JS call frame and start another animation. This animation
  // should have its start time set to the timeline time of the next page
  // rendering update.
  await timeout_promise();
  make_animation('after waiting for a new JS call frame',
                 expected_start_next_frame());

  // Wait for another new JS call frame and start another animation. This
  // animation, like the previous one, should have its start time set to
  // the timeline time of the next page rendering update.
  await timeout_promise();
  make_animation('after waiting for a another JS call frame',
                 expected_start_next_frame());


  // Now wait until the next page rendering update and ensure we are aligned
  // with the rAF time.
  await waitForAnimationFrames(1);
  make_animation('during the second page rendering update',
                 expected_start_this_frame());

  await Promise.all(promises);
}, `Checking the start time of animations started at various times between ` +
   'two page rendering updates');
</script>