File: worklet-animation-get-computed-timing-progress-on-worklet-thread.https.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 (87 lines) | stat: -rw-r--r-- 3,528 bytes parent folder | download | duplicates (29)
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
<html>
<title>Animation Worklet should update calculated timing whenever localTime changes</title>
<link rel="help" href="https://drafts.css-houdini.org/css-animationworklet/">

<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/web-animations/testcommon.js"></script>
<script src="common.js"></script>

<div id="box"></div>

<script id="get_computed_timing_animator" type="text/worklet">
  registerAnimator('get_computed_timing', class {
    constructor(options, state) {
      this.step = state ? state.step : 0;
    }
    state() {
      return {
        step: 0
      }
    }
    animate(currentTime, effect){
      if (this.step === 0){
        // check calculated timing values before ever setting effect.localTime
        effect.localTime = (effect.getComputedTiming().currentIteration * 100) + (effect.getComputedTiming().progress * 100);
        this.step = 1;
      }
      else if (this.step === 1){
        // set effect.localTime, this should be the first time calculated timing values are computed
        effect.localTime = 420; // 20% of the way through the last iteration

        // using the calculated timing of effect, set effect.localTime.
        effect.localTime = (effect.getComputedTiming().currentIteration * 100) + (effect.getComputedTiming().progress * 100);
        this.step = 2;
      }
      else if (this.step === 2){
        // set effect.localTime to null
        effect.localTime = null;
        effect.localTime = (effect.getComputedTiming().currentIteration * 100) + (effect.getComputedTiming().progress * 100);
        this.step = 3;
      }
      else if (this.step === 3){
        // Check to make sure we can go from null to a valid localTime and that calculated timing values are computed
        effect.localTime = 350; // 50% of the way through second iteration
        effect.localTime = (effect.getComputedTiming().currentIteration * 100) + (effect.getComputedTiming().progress * 100);
        this.step = 4;
      }
    }
  });
</script>

<script>
  promise_test(async t => {
    await runInAnimationWorklet(document.getElementById('get_computed_timing_animator').textContent);

    const box = document.getElementById("box");
    const effect = new KeyframeEffect(
      box,
      [
        { opacity: 0 },
        { opacity: 1 }
      ], {
        delay: 200,
        duration: 100,
        iterations: 3
      }
    );

    const animation = new WorkletAnimation('get_computed_timing', effect);
    animation.play();

    // check calculated timing values before ever setting effect.localTime
    await waitForAnimationFrameWithCondition(() => {return approxEquals(effect.getComputedTiming().localTime, 0)});

    // Check to make sure initial values can be set for computed timing
    await waitForAnimationFrameWithCondition(() => {return approxEquals(effect.getComputedTiming().localTime, 220)});

    // Make sure setting effect.localTime to null causes calculated timing values to be computed
    await waitForAnimationFrameWithCondition(() => {return approxEquals(effect.getComputedTiming().localTime, 0)});

    // Make sure we can go from null to a valid localTime and that calculated timing values are computed
    await waitForAnimationFrameWithCondition(() => {return approxEquals(effect.getComputedTiming().localTime, 150)});

    // Passes if it doesn't timeout
    animation.cancel();
  }, "WorkletAnimation effect should recompute its calculated timing if its local time changes");
</script>