Skip to content

Commit eb1641e

Browse files
committed
Bug 1932978 [wpt PR 49339] - Update READMEs for animation tests, a=testonly
Automatic update from web-platform-tests Update READMEs for animation tests First in a series of patches to document best practices for animation tests. This patch adds a readme for non-WPT animation tests, and updates the readme for CSS transitions. Each tip was recently used to fix a flake / failure introduced with the migration of css transition tests from using run_web_test.py to run_wpt_test.py. Change-Id: Iaba7ea397c4f55a090b08a71c046b96c64453bd9 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6037955 Reviewed-by: Olga Gerchikov <gerchikomicrosoft.com> Commit-Queue: Kevin Ellis <keverschromium.org> Cr-Commit-Position: refs/heads/main{#1387067} -- wpt-commits: c27cc4faeeb1b4b5ce7f98e29a7f4aba5d6ac6ac wpt-pr: 49339 UltraBlame original commit: 1d3bbbcde9e521bf0e9081d929ab9ba0e05c803b
1 parent 09ca2cb commit eb1641e

File tree

1 file changed

+96
-0
lines changed
  • testing/web-platform/tests/css/css-transitions

1 file changed

+96
-0
lines changed

testing/web-platform/tests/css/css-transitions/README.md

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,102 @@ To make individual tests a bit more readable, a lot of the test-functionality ha
4747
2. disable final cleanup by commenting out `done` and `teardown` callbacks
4848
3. possibly increase the `duration` and disable the `#offscreen` (by simply naming it `#off-screen`)
4949

50+
## Tips to avoid test flakes ##
51+
52+
### Making style update deterministic ####
53+
54+
Timing characteristics vary widely across testing environments, and we need to
55+
be careful about making assumptions about the state of the testing environment
56+
to avoid race conditions.
57+
58+
Here is an example of a test with a race condition.
59+
60+
```css
61+
# target {
62+
color: green;
63+
transition: color 300ms;
64+
transition-delay: -150ms;
65+
}
66+
```
67+
68+
```javascript
69+
test(() => {
70+
target.style.color = 'pink';
71+
assert_equals(getComputedStyle(target).color, ...);
72+
}, ...);
73+
```
74+
The value of color will differ depending on whether the color "change" was
75+
captured as part of the initial style update. We cannot assume style and
76+
layout are clean at the start of a test.
77+
78+
One way to fix this with the benefit of testing that a transition started is
79+
as follows:
80+
81+
```javascript
82+
test(() => {
83+
assert_equals(document.getAnimations().length, 0,
84+
'Initially no running animations');
85+
target.style.color = 'pink';
86+
assert_equals(document.getAnimations().length, 1,
87+
'Color change triggers a CSS transition');
88+
assert_equals(getComputedStyle(target).color, ...);
89+
}, ...);
90+
````
91+
92+
### Reftests and paint holding ###
93+
94+
To avoid the flash of white when a navigating between pages, browsers may
95+
elect to freeze the contents until ready to render the page. All animations,
96+
CSS transitions included, have a ready promise that is resolved when the
97+
user agent has completed any set up and is ready to rendering the animation.
98+
99+
Rather than simply creating the transition and calling takeScreenshot, a safer
100+
approach is as follows:
101+
102+
```javascript
103+
window.onload = async () => {
104+
... test setup including starting any transitions ...
105+
106+
const promises = document.getAnimations().map(anim => anim.ready);
107+
await Promise.all(promises);
108+
requestAnimationFrame(takeScreenshot);
109+
};
110+
```
111+
112+
### Reftests and avoiding animation drift ###
113+
114+
The animation API is largely asynchronous and an extra animation frame can
115+
easily cause misalignment of a reftest with its reference image. One
116+
approach to address the issue is to use a long duration animation with a
117+
negative transition delay to set the position. If using this approach, we can
118+
further reduce the potential for animation drift by using a step easing function
119+
or freeze at the midpoint by using cubic-bezier(0, 1, 1, 0) combined with a
120+
negative transition delay with a magnitude equal to half the duration. Unless
121+
critical for the test to be performed on running transitions, a safe alternative
122+
is to pause the transitions.
123+
124+
```javascript
125+
document.getAnimations().forEach(anim => anim.pause());
126+
```
127+
128+
## Tips to reduce test runtime ##
129+
130+
When testing for transitionend, it is not necessary to let the animation run its
131+
course. It may be tempting just to use a short duration animation, but safer is
132+
to accelerate the animation via the web-animations API. This gives us precise
133+
control over the test conditions.
134+
135+
```javascript
136+
function fastForward(anim, progress) {
137+
anim.currentTime = anim.effect.getTiming().duration * progress;
138+
}
139+
```
140+
141+
If simply wanting to jump to the end of the transition, then calling
142+
anim.finish() does the trick. This fast forwarding trick is also really
143+
useful for sampling a transition curve (testing whether a transition is
144+
discrete or continuous for example).
145+
50146

51147
## Unspecified Behavior ##
52148

0 commit comments

Comments
 (0)