summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/scroll-animations/css/get-animations-inactive-timeline.html
blob: 10bf00fbbc06a18b47deab2eaad69ba516b9ff42 (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
<!DOCTYPE html>
<html>
<meta charset="utf-8">
<title>getAnimations for scroll-linked animations</title>
<link rel="help"
 href="https://www.w3.org/TR/web-animations-1/#animation-effect-phases-and-states">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support/testcommon.js"></script>
<style>
  @keyframes slide {
    from { transform: translateX(100px);  }
    to   { transform: translateX(100px); }
  }

  #container {
    border:  10px solid lightgray;
    overflow-x: scroll;
    height:  200px;
    width: 200px;
    scroll-timeline-name:  timeline;
  }
  #spacer {
    height:  200vh;
  }
  #target {
    background-color:  green;
    height:  100px;
    width:  100px;
    animation:  slide 1s linear;
    animation-timeline: timeline;
  }
</style>
<body>
  <div id="container">
    <div id="spacer"></div>
    <div id="target"></div>
  </div>
</body>
<script type="text/javascript">
  setup(assert_implements_animation_timeline);

  promise_test(async t => {
    // Newly created timeline is inactive,
    let animations = document.getAnimations();
    assert_equals(animations.length, 1,
                  'Single running animation');
    assert_true(animations[0].timeline instanceof ScrollTimeline,
                'Animation associated with a scroll timeline');
    assert_equals(animations[0].timeline.currentTime, null,
                  'Timeline is initially inactive');

    // Canceled animation is no longer current.
    const anim = animations[0];
    animations[0].cancel();

    assert_equals(
        document.getAnimations().length, 0,
        'A canceled animation is no longer returned by getAnimations');

    // Replaying an animation makes it current.
    anim.play();
    assert_equals(
        document.getAnimations().length, 1,
        'A play-pending animation is return by getAnimations');

    // Animation effect is still current even if the timeline's source element
    // cannot be scrolled.
    spacer.style = 'display: none';
    t.add_cleanup(() => {
      spacer.style = '';
    });

    animations = document.getAnimations();
    assert_equals(
        animations.length, 1,
        'Running animation is included in getAnimations list even if ' +
        'currentTime is null');
    assert_true(animations[0].timeline  instanceof ScrollTimeline,
                'Animation has timeline associated with an element that ' +
                'cannot be scrolled');
    assert_equals(animations[0].timeline.currentTime, null,
                  'Inactive timeline when timeline\'s source element cannot ' +
                  'be scrolled');
  }, 'getAnimations includes inactive scroll-linked animations that have not ' +
     'been canceled');
</script>