summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/scroll-animations/css/scroll-timeline-with-percent-delay.tentative.html
blob: 4f2e1761de29d80c8377926f734e0cfbfe831a8c (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
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
88
89
90
91
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="help" src="https://drafts.csswg.org/scroll-animations-1/#named-timeline-range">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/web-animations/testcommon.js"></script>
<script src="support/testcommon.js"></script>
<title>Animation range and delay</title>
</head>
<style type="text/css">
  @keyframes anim {
    from { opacity: 0 }
    to { opacity: 1 }
  }
  #scroller {
    border:  10px solid lightgray;
    overflow-y: scroll;
    width: 300px;
    height: 200px;
  }
  #target {
    margin: 800px 0px;
    width: 100px;
    height: 100px;
    z-index: -1;
    background-color: green;
    animation:  anim auto linear;
    animation-timeline: scroll();
    /* Sentinel value when in before or after phase of the animation. */
    opacity: 0.96875;
  }
</style>
<body>
  <div id=scroller>
    <div id=target></div>
  </div>
</body>
<script type="text/javascript">
  async function runTest() {

    function assert_opacity_equals(expected, errorMessage) {
      assert_approx_equals(
          parseFloat(getComputedStyle(target).opacity), expected, 1e-6,
                     errorMessage);
    }

    promise_test(async t => {
      await waitForNextFrame();
      const anim = document.getAnimations()[0];
      await anim.ready;

      await waitForNextFrame();
      scroller.scrollTop =
          (scroller.scrollHeight - scroller.clientHeight) / 2;
      await waitForNextFrame();

      const baseOpacity = 0.96875;
      // Delays are percentages.
      const testData = [
         { delay: 0, endDelay: 0, opacity: 0.5 },
         { delay: 20, endDelay: 0, opacity: 0.375 },
         { delay: 0, endDelay: 20, opacity: 0.625 },
         { delay: 20, endDelay: 20, opacity: 0.5 },
         // // Negative delays.
         { delay: -25, endDelay: 0, opacity: 0.6 },
         { delay: 0, endDelay: -25, opacity: 0.4 },
         { delay: -25, endDelay: -25, opacity: 0.5 },
         // Stress tests with >= 100% total delay. Verify effect is inactive.
         { delay: 100, endDelay: 0, opacity: baseOpacity },
         { delay: 0, endDelay: 100, opacity: baseOpacity },
         { delay: 100, endDelay: 100, opacity: baseOpacity }
      ];

      testData.forEach(test => {
        anim.effect.updateTiming({
          delay: CSS.percent(test.delay),
          endDelay: CSS.percent(test.endDelay)
        });
        assert_opacity_equals(
            test.opacity,
            `Opacity when delay=${test.delay} and endDelay=${test.endDelay}`);
      });
    }, 'ScrollTimeline with animation delays as percentages');
  }

  window.onload = runTest;

</script>
</html>