tor-browser

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

animation-range-ignored.html (9152B)


      1 <!DOCTYPE html>
      2 <html>
      3 <head>
      4 <meta charset="utf-8">
      5 <link rel="help" src="https://www.w3.org/TR/scroll-animations-1/#named-range-animation-declaration">
      6 <script src="/resources/testharness.js"></script>
      7 <script src="/resources/testharnessreport.js"></script>
      8 <script src="/web-animations/testcommon.js"></script>
      9 <script src="/web-animations/resources/keyframe-utils.js"></script>
     10 <script src="support/testcommon.js"></script>
     11 <script src="/scroll-animations/scroll-timelines/testcommon.js"></script>
     12 <title>Programmatic API overrides animation-range-*</title>
     13 </head>
     14 <style type="text/css">
     15  #scroller {
     16    border:  10px solid lightgray;
     17    overflow-y: scroll;
     18    overflow-x: hidden;
     19    width: 300px;
     20    height: 200px;
     21  }
     22  @keyframes anim {
     23    from { margin-left: 0px; }
     24    to { margin-left: 100px; }
     25  }
     26  #target {
     27    margin: 800px 0px;
     28    width: 100px;
     29    height: 100px;
     30    z-index: -1;
     31    background-color: green;
     32  }
     33  .animate {
     34    animation:  anim auto linear;
     35    view-timeline:  --timeline;
     36    animation-timeline:  --timeline;
     37    animation-range-start:  entry 0%;
     38    animation-range-end:  entry 100%;
     39  }
     40 </style>
     41 <body>
     42  <div id=scroller>
     43    <div id=target></div>
     44  </div>
     45 </body>
     46 <script type="text/javascript">
     47  async function runTest() {
     48    function startAnimation(t) {
     49      target.classList.add('animate');
     50      t.add_cleanup(async () => {
     51        target.classList.remove('animate');
     52        await waitForNextFrame();
     53      });
     54      return target.getAnimations()[0];
     55    }
     56 
     57    promise_test(async t => {
     58      // Points of interest:
     59      // entry 0% @ 600
     60      // entry 100% / contain 0% @ 700
     61      // exit 0% / contain 100% @ 800
     62      // exit 100% @ 900
     63      const anim = startAnimation(t);
     64      await anim.ready;
     65 
     66      await runAndWaitForFrameUpdate(() => {
     67        scroller.scrollTop = 650;
     68      });
     69 
     70      // Timline time = (scroll pos - cover 0%) / (cover 100% - cover 0%) * 100%
     71      //              = (650 - 600)/(900 - 600) * 100% = 100/6%
     72      assert_percents_equal(anim.timeline.currentTime, 100/6,
     73                            'timeline\'s current time before style change');
     74      assert_percents_equal(anim.startTime, 0,
     75                            'animation\'s start time before style change');
     76      // Range start of entry 0% aligns with timeline start. Thus, animation's
     77      // and timeline's current time are equal.
     78      assert_percents_equal(anim.currentTime, 100/6,
     79                            'animation\'s current time before style change');
     80      // Iteration duration =
     81      //     (range end - range start) / (cover 100% - cover 0%) * 100%
     82      //   = (700 - 600) / (900 - 600) = 33.3333%
     83      assert_percents_equal(anim.effect.getComputedTiming().duration,
     84                            100/3,
     85                            'iteration duration before first style change');
     86      assert_equals(getComputedStyle(target).marginLeft, '50px',
     87                    'margin-left before style change');
     88 
     89      // Step 1: Set the range end programmatically and range start via CSS.
     90      // The start time will be respected since not previously set via the
     91      // animation API.
     92      await runAndWaitForFrameUpdate(() => {
     93        anim.rangeEnd = 'contain 100%';
     94        target.style.animationRangeStart = 'entry 50%';
     95      });
     96 
     97      // Animation range does not affect timeline's currentTime.
     98      assert_percents_equal(
     99          anim.timeline.currentTime, 100/6,
    100          'timeline\'s current time after first set of range updates');
    101      assert_percents_equal(
    102          anim.startTime, 100/6,
    103          'animation\'s start time after first set of range updates');
    104      // Scroll position aligns with range start.
    105      assert_percents_equal(
    106          anim.currentTime, 0,
    107          'animation\'s current time after first set of range updates');
    108      // Iteration duration =
    109      //     (range end - range start) / (cover 100% - cover 0%) * 100%
    110      //   = (800 - 650) / (900 - 600) = 50%
    111      assert_percents_equal(
    112          anim.effect.getComputedTiming().duration, 50,
    113          'iteration duration after first style change');
    114      assert_equals(getComputedStyle(target).marginLeft, '0px',
    115        'margin-left after first set of range updates');
    116 
    117      // Step 2: Programmatically set the range start.
    118      // Scroll position is current at entry 50%, thus the animation's current
    119      // time is negative.
    120      await runAndWaitForFrameUpdate(() => {
    121        anim.rangeStart = 'contain 0%';
    122      });
    123      // animation current time =
    124      //     (scroll pos - range start) / (cover 100% - cover 0%) * 100%
    125      //   = (650 - 700) / (900 - 600) * 100% = -100/6%
    126      assert_percents_equal(
    127        anim.currentTime, -100/6,
    128        'animation\'s current time after second set of range updates');
    129      // Iteration duration =
    130      //     (range end - range start) / (cover 100% - cover 0%) * 100%
    131      //   = (800 - 700) / (900 - 600) = 33.3333%
    132      assert_percents_equal(
    133          anim.effect.getComputedTiming().duration, 100/3,
    134          'iteration duration after second style change');
    135      assert_equals(getComputedStyle(target).marginLeft, '0px',
    136        'margin-left after second set of range updates');
    137 
    138      // Jump to contain / cover 50%
    139      scroller.scrollTop = 750;
    140      await waitForNextFrame();
    141 
    142      // animation current time =
    143      //     (scroll pos - range start) / (cover 100% - cover 0%) * 100%
    144      //   = (750 - 700) / (900 - 600) * 100% =  100/6%
    145      assert_percents_equal(
    146          anim.currentTime, 100/6,
    147          'animation\'s current time after bumping scroll position');
    148      assert_approx_equals(parseFloat(getComputedStyle(target).marginLeft), 50, 0.125);
    149 
    150      // Step 3: Try to update the range start via CSS.  This change must be
    151      // ignored since previously set programmatically.
    152      await runAndWaitForFrameUpdate(() => {
    153        target.style.animationRangeStart = "entry 50%";
    154      });
    155      assert_percents_equal(
    156          anim.currentTime, 100/6,
    157          'Current time unchanged after change to ignored CSS property');
    158      assert_approx_equals(parseFloat(getComputedStyle(target).marginLeft), 50, 0.125,
    159          'Margin-left unaffected by change to ignored CSS property');
    160 
    161    }, 'Animation API call rangeStart overrides animation-range-start');
    162 
    163    promise_test(async t => {
    164      const anim = startAnimation(t);
    165      await anim.ready;
    166 
    167      scroller.scrollTop = 650;
    168      await waitForNextFrame();
    169 
    170      // Step 1: Set the range start programmatically and range end via CSS.
    171      // The start time will be respected since not previously set via the
    172      // animation API.
    173      await runAndWaitForFrameUpdate(() => {
    174        anim.rangeStart = "entry 50%";
    175        target.style.animationRangeEnd = "contain 100%";
    176      });
    177 
    178      assert_percents_equal(
    179          anim.timeline.currentTime, 100/6,
    180          'timeline\'s current time after first set of range updates');
    181      assert_percents_equal(
    182          anim.startTime, 100/6,
    183          'animation\'s start time after first set of range updates');
    184      assert_percents_equal(
    185          anim.currentTime, 0,
    186          'animation\'s current time after first set of range updates');
    187      assert_percents_equal(
    188          anim.effect.getComputedTiming().duration, 50,
    189          'iteration duration after first style change');
    190      assert_equals(getComputedStyle(target).marginLeft, "0px",
    191        'margin-left after first set of range updates');
    192 
    193      // Step 2: Programmatically set the range.
    194      // Scroll position is current at entry 50%, thus the animation's current
    195      // time is negative.
    196      await runAndWaitForFrameUpdate(() => {
    197        anim.rangeStart = "contain 0%";
    198        anim.rangeEnd = "contain 100%";
    199      });
    200 
    201      assert_percents_equal(
    202        anim.currentTime, -100/6,
    203        'animation\'s current time after second set of range updates');
    204      assert_percents_equal(
    205          anim.effect.getComputedTiming().duration, 100/3,
    206          'iteration duration after second style change');
    207      assert_equals(getComputedStyle(target).marginLeft, "0px",
    208        'margin-left after second set of range updates');
    209 
    210      // Jump to contain / cover 50%
    211      scroller.scrollTop = 750;
    212      await waitForNextFrame();
    213 
    214      assert_percents_equal(
    215          anim.currentTime, 100/6,
    216          'animation\'s current time after bumping scroll position');
    217      assert_approx_equals(parseFloat(getComputedStyle(target).marginLeft), 50, 0.125);
    218 
    219      // Step 3: Try to update the range end via CSS. This change must be
    220      // ignored since previously set programmatically.
    221      await runAndWaitForFrameUpdate(() => {
    222        target.style.animationRangeEnd = "cover 100%";
    223      });
    224      assert_percents_equal(
    225          anim.currentTime, 100/6,
    226          'Current time unchanged after change to ignored CSS property');
    227      assert_approx_equals(parseFloat(getComputedStyle(target).marginLeft), 50, 0.125,
    228          'Margin-left unaffected by change to ignored CSS property');
    229 
    230    }, 'Animation API call rangeEnd overrides animation-range-end');
    231  }
    232 
    233  window.onload = runTest;
    234 </script>