chromium/third_party/blink/web_tests/animations/animationworklet/worklet-animation-currentTime.html

<!DOCTYPE html>
<title>Test current time in worklet scope reflects the animation currentTime.</title>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>

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

<script id="passthrough" type="text/worklet">
registerAnimator("passthrough_animator", class {
  animate(currentTime, effect) {
    effect.localTime = currentTime;
  }
});
</script>
<div id="target"></div>
<script src="resources/animation-worklet-tests.js"></script>
<script>
promise_test(async t => {
  await runInAnimationWorklet(document.getElementById('passthrough').textContent);

  const effect = new KeyframeEffect(target, [{ width: 100 }], { duration: 1000 });
  const animation = new WorkletAnimation('passthrough_animator', effect);
  animation.play();

  // Wait for one async animation frame to ensure animation is running.
  await waitForAsyncAnimationFrame();
  await waitForDocumentTimelineAdvance();

  // TODO(majidvp): Currently with threaded animation the
  // WorkletAnimation.currentTime on main thread is not guaranteed to match the
  // currentTime passed to animator in the worklet scope. This is because both
  // the timeline time and the animation start time may differ between
  // compositor and main. For now this test uses 'width' to force being on main
  // thread until we decide to sync the start time and the timeline time.
  // http://crbug.com/937382
  assert_approx_equals(effect.getComputedTiming().localTime, animation.currentTime, 0.001);
}, 'The animator instance in the worklet scope gets currentTime that is equal to WorkletAnimation.currentTime.');

promise_test(async t => {
  await runInAnimationWorklet(document.getElementById('passthrough').textContent);
  const effect = new KeyframeEffect(target, [{ width: 100 }], { duration: 1000 });
  const animation = new WorkletAnimation('passthrough_animator', effect);
  animation.pause();
  assert_equals(animation.currentTime, 0);
}, 'Initial current time pausing an idle animation worklet.');

promise_test(async t => {
  await runInAnimationWorklet(document.getElementById('passthrough').textContent);
  const effect = new KeyframeEffect(target, [{ width: 100 }], { duration: 1000 });
  const animation = new WorkletAnimation('passthrough_animator', effect);
  animation.play();
  animation.pause();
  assert_equals(animation.currentTime, 0);
}, 'Initial current time pausing a play-pending animation worklet.');

</script>