summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/scroll-animations/css/animation-timeline-ignored.tentative.html
blob: 32cb89c4ef8ba42416be57ca015215557451c559 (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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<!DOCTYPE html>
<link rel="help" src="https://github.com/w3c/csswg-drafts/pull/5666">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/web-animations/testcommon.js"></script>
<style>
  main {
    overflow: hidden;
    height: 0px;
  }
  main > div {
    overflow: hidden;
    width: 100px;
    height: 100px;
  }
  main > div > div {
    height: 200px;
  }
  @keyframes expand {
    from { width: 100px; }
    to { width: 200px; }
  }
  #scroller1 {
    scroll-timeline: timeline1;
  }
  #scroller2 {
    scroll-timeline: timeline2;
  }
  #scroller3 {
    scroll-timeline: timeline3;
  }
  #element {
    width: 0px;
    height: 20px;
    animation-name: expand;
    animation-duration: 1000s;
    animation-timing-function: linear;
    animation-timeline: timeline1;
  }
  /* Ensure stable expectations if feature is not supported */
  @supports not (animation-timeline:foo) {
    #element { animation-play-state: paused; }
  }
</style>
<main>
  <div id=scroller1><div></div></div>
  <div id=scroller2><div></div></div>
  <div id=scroller3><div></div></div>
  <div id=scroller4><div></div></div>
  <div id=container></div>
</main>
<script>
  // Force layout of scrollers.
  scroller1.offsetTop;
  scroller2.offsetTop;
  scroller3.offsetTop;
  scroller4.offsetTop;

  scroller1.scrollTop = 20;
  scroller2.scrollTop = 40;
  scroller3.scrollTop = 60;
  scroller4.scrollTop = 80;

  // Create #element in #container, run |func|, then clean up afterwards.
  function test_animation_timeline(func, description) {
    promise_test(async () => {
      try {
        let element = document.createElement('element');
        element.setAttribute('id', 'element');
        container.append(element);
        await func();
      } finally {
        while (container.firstChild)
          container.firstChild.remove();
      }
    }, description);
  }

  test_animation_timeline(async () => {
    await waitForNextFrame();
    assert_equals(getComputedStyle(element).width, '120px');
    element.style = 'animation-timeline:timeline2';
    assert_equals(getComputedStyle(element).width, '140px');
  }, 'Changing animation-timeline changes the timeline (sanity check)');

  test_animation_timeline(async () => {
    await waitForNextFrame();
    assert_equals(getComputedStyle(element).width, '120px');

    // Set a (non-CSS) ScrollTimeline on the CSSAnimation.
    let timeline4 = new ScrollTimeline({
      source: scroller4,
      scrollOffsets: [CSS.px(0), CSS.px(100)]
    });

    element.getAnimations()[0].timeline = timeline4;
    assert_equals(getComputedStyle(element).width, '180px');

    // Changing the animation-timeline property should have no effect.
    element.style = 'animation-timeline:timeline2';
    assert_equals(getComputedStyle(element).width, '180px');
  }, 'animation-timeline ignored after setting timeline with JS (ScrollTimeline from JS)');

  test_animation_timeline(async () => {
    await waitForNextFrame();
    assert_equals(getComputedStyle(element).width, '120px');
    let animation = element.getAnimations()[0];
    let timeline1 = animation.timeline;

    element.style = 'animation-timeline:timeline2';
    assert_equals(getComputedStyle(element).width, '140px');

    animation.timeline = timeline1;
    assert_equals(getComputedStyle(element).width, '120px');

    // Should have no effect.
    element.style = 'animation-timeline:timeline3';
    assert_equals(getComputedStyle(element).width, '120px');
  }, 'animation-timeline ignored after setting timeline with JS (ScrollTimeline from CSS)');

  test_animation_timeline(async () => {
    await waitForNextFrame();
    assert_equals(getComputedStyle(element).width, '120px');
    element.getAnimations()[0].timeline = document.timeline;

    // (The animation continues from where the previous timeline left it).
    assert_equals(getComputedStyle(element).width, '120px');

    // Changing the animation-timeline property should have no effect.
    element.style = 'animation-timeline:timeline2';
    assert_equals(getComputedStyle(element).width, '120px');
  }, 'animation-timeline ignored after setting timeline with JS (document timeline)');

  test_animation_timeline(async () => {
    await waitForNextFrame();
    assert_equals(getComputedStyle(element).width, '120px');
    element.getAnimations()[0].timeline = null;
    assert_equals(getComputedStyle(element).width, '0px');

    // Changing the animation-timeline property should have no effect.
    element.style = 'animation-timeline:timeline2';
    assert_equals(getComputedStyle(element).width, '0px');
  }, 'animation-timeline ignored after setting timeline with JS (null)');

</script>