File: content-visibility-animation-in-auto-subtree.html

package info (click to toggle)
firefox-esr 140.3.1esr-2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 4,539,016 kB
  • sloc: cpp: 7,380,478; javascript: 6,388,099; ansic: 3,710,142; python: 1,393,715; xml: 628,165; asm: 426,918; java: 184,025; sh: 65,742; makefile: 19,302; objc: 13,059; perl: 12,912; yacc: 4,583; cs: 3,846; pascal: 3,352; lex: 1,720; ruby: 1,226; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10
file content (239 lines) | stat: -rw-r--r-- 8,685 bytes parent folder | download | duplicates (13)
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
<!DOCTYPE html>
<meta charset=utf8>
<title>Test getComputedStyle on a CSS animation in a content visibility subtree using content-visibility: auto</title>
<link rel="help" href="https://drafts.csswg.org/css-contain-2/">
<script src="/web-animations/testcommon.js"></script>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
#container {
  content-visibility: auto;
}
@keyframes fade {
  from { opacity: 1; }
  to { opacity: 0;  }
}
#target {
  background: green;
  height: 100px;
  width: 100px;
}
.animate {
  animation: fade 1s linear 2 alternate;
}
.transition {
  transition: opacity 1s linear;
}
</style>
<body>
  <div id="spacer"></div>
  <div id="container"></div>
</body>
<script>
"use strict";

function reset() {
  const container = document.getElementById('container');
  const target = document.getElementById('target');
  container.style = '';
  container.removeChild(target);
}

function createAnimatingElement(test, name) {
  const container = document.getElementById('container');
  const target = document.createElement('div');
  container.appendChild(target);
  target.id = 'target';
  target.className = name;
  test.add_cleanup(() => {
    reset();
  });
  return target;
}

promise_test(async t => {
  const container = document.getElementById('container');
  const target = createAnimatingElement(t, 'animate');
  let animationIterationEvent = false;
  const animation = target.getAnimations()[0];
  await animation.ready;
  await waitForAnimationFrames(1);
  document.getElementById("spacer").style.height = "300vh";
  await waitForAnimationFrames(1);
  target.addEventListener('animationiteration', () => {
    animationIterationEvent = true;
  });
  animation.currentTime = 1500;
  assert_approx_equals(
      parseFloat(getComputedStyle(target).opacity), 0.5, 1e-6,
      'Computed style is updated even when the animation is running in a ' +
      'content visibility subtree');
  await waitForAnimationFrames(2);
  assert_false(animationIterationEvent,
               'Animation events do not fire while the animation is ' +
               'running in a content visibility subtree');
  document.getElementById("spacer").style.height = "0vh";
  await waitForAnimationFrames(2);
  assert_true(animationIterationEvent,
              'The animationiteration event fires once the animation is ' +
              'no longer content visibility');
}, 'Animation events do not fire for a CSS animation running in a content ' +
   'visibility subtree');

promise_test(async t => {
  const container = document.getElementById('container');
  const target = createAnimatingElement(t, 'animate');
  const animation = target.getAnimations()[0];
  await animation.ready;
  let finishedWhileDisplayLocked = false;
  animation.finished.then(() => {
    finishedWhileDisplayLocked =
        getComputedStyle(target).height == '0px';
  });
  await waitForAnimationFrames(1);
  document.getElementById("spacer").style.height = "300vh";
  // Advance to just shy of the effect end.
  animation.currentTime = 1999;
  assert_approx_equals(
      parseFloat(getComputedStyle(target).opacity), 0.999, 1e-6,
                'Computed style is updated even when the animation is ' +
                'running in a content visibility subtree');
  // Advancing frames should not resolve the finished promise.
  await waitForAnimationFrames(3);
  document.getElementById("spacer").style.height = "0vh";
  // Now we can resolve the finished promise.
  await animation.finished;
  assert_equals(finishedWhileDisplayLocked, false);
}, 'The finished promise does not resolve due to the normal passage of time  ' +
   'for a CSS animation in a content visibility subtree');

promise_test(async t => {
  const container = document.getElementById('container');
  await waitForAnimationFrames(1);
  const target = createAnimatingElement(t, 'transition');
  await waitForAnimationFrames(1);
  target.style.opacity = 0;
  const animation = target.getAnimations()[0];
  await animation.ready;
  let finishedWhileDisplayLocked = false;
  animation.finished.then(() => {
    finishedWhileDisplayLocked =
        getComputedStyle(target).height == '0px';
  });
  await waitForAnimationFrames(1);
  document.getElementById("spacer").style.height = "300vh";
  // Advance to just shy of the effect end.
  animation.currentTime = 999;
  assert_approx_equals(
      parseFloat(getComputedStyle(target).opacity), 0.001, 1e-6,
                'Computed style is updated even when the animation is ' +
                'running in a content visibility subtree');
  // Advancing frames should not resolve the finished promise.
  await waitForAnimationFrames(3);
  document.getElementById("spacer").style.height = "0vh";
  // Now we can resolve the finished promise.
  await animation.finished;
  assert_equals(finishedWhileDisplayLocked, false);
}, 'The finished promise does not resolve due to the normal passage of time  ' +
   'for a CSS transition in a content visibility subtree');

promise_test(async t => {
  const container = document.getElementById('container');
  const target = createAnimatingElement(t, 'animate');
  const animation = target.getAnimations()[0];
  target.className = '';
  document.getElementById("spacer").style.height = "300vh";
  assert_equals(target.getAnimations().length, 0);

  // Though originally a CSS animation, it is no longer associated with
  // CSS rules and no longer has an owning element. It now behaves like a
  // programmatic web animation. Animation playback events (but not CSS
  // animation events) should be dispatched and promises resolved despite
  // being in a content visibility subtree.

  let cssAnimationEndEvent = false;
  target.addEventListener('animationend', () => {
    cssAnimationEndEvent = true;
  });

  let animationFinishEvent = false;
  animation.addEventListener('finish', () => {
    animationFinishEvent = true;
  });

  let animationFinished = false;
  animation.finished.then(() => {
    animationFinished = true;
  });

  animation.play();
  assert_equals(target.getAnimations().length, 1);

  animation.currentTime = 1999;
  await animation.ready;
  await waitForAnimationFrames(2);

  assert_true(animationFinishEvent,
              'Animation event not blocked on content visibility subtree if ' +
              'no owning element');
  assert_true(animationFinished,
              'Finished promise not blocked on content visibility subtree if ' +
              'no owning element');
  assert_false(cssAnimationEndEvent,
              'CSS animation events should not be dispatched if there is no ' +
              'owning element');
}, 'Events and promises are handled normally for animations without an ' +
   'owning element');

promise_test(async t => {
  // The animation is hidden when it is created.
  document.getElementById("spacer").style.height = "300vh";
  const container = document.getElementById('container');
  const target = createAnimatingElement(t, 'animate');
  const animation = target.getAnimations()[0];
  await waitForAnimationFrames(2);
  // Make this animation no longer associated with its owning element.
  target.className = '';
  assert_equals(target.getAnimations().length, 0);

  // Though originally a CSS animation, it is no longer associated with
  // CSS rules and no longer has an owning element. It now behaves like a
  // programmatic web animation. Animation playback events (but not CSS
  // animation events) should be dispatched and promises resolved despite
  // being in a content visibility subtree.

  let cssAnimationEndEvent = false;
  target.addEventListener('animationend', () => {
    cssAnimationEndEvent = true;
  });

  let animationFinishEvent = false;
  animation.addEventListener('finish', () => {
    animationFinishEvent = true;
  });

  let animationFinished = false;
  animation.finished.then(() => {
    animationFinished = true;
  });

  animation.play();
  assert_equals(target.getAnimations().length, 1);

  animation.currentTime = 1999;
  await animation.ready;
  await waitForAnimationFrames(2);

  assert_true(animationFinishEvent,
              'Animation event not blocked on content visibility subtree if ' +
              'no owning element');
  assert_true(animationFinished,
              'Finished promise not blocked on content visibility subtree if ' +
              'no owning element');
  assert_false(cssAnimationEndEvent,
              'CSS animation events should not be dispatched if there is no ' +
              'owning element');
}, 'CSS animations without an owning element should handle events and promises ' +
              'normally, even c-v value does change');

</script>