summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/animation-worklet/worklet-animation-get-timing-on-worklet-thread.https.html
blob: 4ba68d79e4de5544d36c826ad3b41613d9e3f289 (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
<html class="reftest-wait">
<title>Animation Worklet should have access to effect timing from within the worklet thread</title>
<link rel="help" href="https://drafts.css-houdini.org/css-animationworklet/">
<meta name="assert" content="Animation Worklet should have access to effect timing from within the worklet thread">
<link rel="match" href="references/translated-box-ref.html">

<script src="/web-animations/testcommon.js"></script>
<script src="/common/reftest-wait.js"></script>
<script src="common.js"></script>

<style>
  #box{
    height: 100px;
    width: 100px;
    background-color: green;
  }
</style>

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

<script id="get_timing_animator"  type="text/worklet">
  registerAnimator('get_timing', class {
    animate(currentTime, effect){
      effect.localTime = effect.getTiming().delay + (effect.getTiming().duration / 2);
    }
  });
</script>

<script>
  runInAnimationWorklet(
    document.getElementById('get_timing_animator').textContent
  ).then(() => {
    const box = document.getElementById("box");
    const effect = new KeyframeEffect(
      box,
      [
        {transform: 'translateY(0)'},
        {transform: 'translateY(200px)'}
      ],
      {
        delay: 2000,
        duration: 1000
      }
    );

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

    waitForAsyncAnimationFrames(1).then(_ => {
      takeScreenshot();
    });
  });
</script>
</html>