tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

worklet-animation-pause.https.html (2026B)


      1 <!DOCTYPE html>
      2 <title>Verify that currentTime and playState are correct when animation is paused</title>
      3 <link rel="help" href="https://drafts.css-houdini.org/css-animationworklet/">
      4 
      5 <script src="/resources/testharness.js"></script>
      6 <script src="/resources/testharnessreport.js"></script>
      7 <script src="/web-animations/testcommon.js"></script>
      8 <script src="common.js"></script>
      9 
     10 <div id="box"></div>
     11 
     12 <script>
     13 
     14 setup(setupAndRegisterTests, {explicit_done: true});
     15 
     16 function createAnimation() {
     17  const box = document.getElementById('box');
     18  const effect = new KeyframeEffect(box,
     19    { transform: ['translateY(100px)', 'translateY(200px)'] },
     20    { duration: 100, iterations: 1 }
     21  );
     22 
     23  return new WorkletAnimation('passthrough', effect);
     24 }
     25 
     26 async function setupAndRegisterTests() {
     27  await registerPassthroughAnimator();
     28 
     29  promise_test(async t => {
     30    const animation = createAnimation();
     31    animation.play();
     32    // Immediately pausing animation should freeze the current time at 0.
     33    animation.pause();
     34    assert_equals(animation.currentTime, 0);
     35    assert_equals(animation.playState, "paused");
     36    // Wait some time to ensure a paused animation actually freezes.
     37   await waitForNextFrame();
     38    assert_equals(animation.currentTime, 0);
     39    assert_equals(animation.playState, "paused");
     40  }, 'pausing an animation freezes its current time');
     41 
     42  promise_test(async t => {
     43    const animation = createAnimation();
     44    animation.pause();
     45    animation.play();
     46    // Allow one async animation frame to pass so that animation is running.
     47    await waitForAsyncAnimationFrames(1);
     48    assert_equals(animation.playState, "running");
     49    // Allow time to advance so that we have a non-zero current time.
     50    await waitForDocumentTimelineAdvance();
     51    const timelineTime = document.timeline.currentTime;
     52    assert_greater_than(animation.currentTime, 0);
     53    assert_times_equal(animation.currentTime, (timelineTime - animation.startTime));
     54  }, 'playing a paused animation should resume it');
     55 
     56  done();
     57 }
     58 
     59 </script>