blob: 3eb1b215b7a20a82c70f5089e075fe6d03ca7fe6 [file] [log] [blame]
graouts@webkit.org080fdf12022-05-19 13:08:33 +00001<!DOCTYPE html>
2<body>
3<script src="../resources/testharness.js"></script>
4<script src="../resources/testharnessreport.js"></script>
5<style>
6
7div {
8 position: absolute;
9 left: 0;
10 top: 0;
11 width: 100px;
12 height: 100px;
13 background-color: black;
14}
15
16</style>
17<script>
18
19const createDiv = test => {
20 const div = document.createElement("div");
21 test.add_cleanup(() => div.remove());
22 return document.body.appendChild(div);
23}
24
25const animationReadyToAnimateAccelerated = async animation => {
26 await animation.ready;
27 await new Promise(requestAnimationFrame);
28 await new Promise(requestAnimationFrame);
29 await new Promise(requestAnimationFrame);
30}
31
32const duration = 1000 * 1000; // 1000s.
33
34promise_test(async test => {
35 const target = createDiv(test);
36
37 // Set offset on the underlying style.
38 target.style.offset = "path('M10,10 H10')";
39
40 // Add a transform animation that could be accelerated by itself.
41 const animation = target.animate(
42 { transform: "translateX(100px)" },
43 { duration }
44 );
45 await animationReadyToAnimateAccelerated(animation);
46 assert_equals(internals.acceleratedAnimationsForElement(target).length, 0);
47}, "Setting 'offset' on the underlying style prevents a 'transform' animation from being accelerated.");
48
49promise_test(async test => {
50 const target = createDiv(test);
51
52 // Add a transform animation that can be accelerated by itself.
53 const animation = target.animate(
54 { transform: "translateX(100px)" },
55 { duration }
56 );
57 await animationReadyToAnimateAccelerated(animation);
58 assert_equals(internals.acceleratedAnimationsForElement(target).length, 1);
59
60 // Set offset on the underlying style.
61 target.style.offset = "path('M10,10 H10')";
62 await animationReadyToAnimateAccelerated(animation);
63 assert_equals(internals.acceleratedAnimationsForElement(target).length, 0);
64
65 // Remove offset on the underlying style.
66 target.style.removeProperty("offset");
67 await animationReadyToAnimateAccelerated(animation);
68 assert_equals(internals.acceleratedAnimationsForElement(target).length, 1);
69}, "Toggling 'offset' dynamically on the underlying style toggles the ability for a 'transform' animation to be accelerated.");
70
71promise_test(async test => {
72 const target = createDiv(test);
73
74 const animation = target.animate(
75 { transform: "translateX(100px)", cssOffset: ["path('M10,10 H10')", "path('M10,10 H20')"] },
76 { duration }
77 );
78 await animationReadyToAnimateAccelerated(animation);
79 assert_equals(internals.acceleratedAnimationsForElement(target).length, 0);
80}, "Animating both 'offset' and 'transform' on the same animation prevents acceleration.");
81
82promise_test(async test => {
83 const target = createDiv(test);
84 const animations = [];
85
86 // First add a transform animation that could be accelerated by itself.
87 animations.push(target.animate(
88 { transform: "translateX(100px)" },
89 { duration }
90 ));
91 await Promise.all(animations.map(animation => animationReadyToAnimateAccelerated(animation)));
92 assert_equals(internals.acceleratedAnimationsForElement(target).length, 1);
93
94 // Then, add an offset animation that prevents the whole stack from being accelerated.
95 animations.push(target.animate(
96 { cssOffset: ["path('M10,10 H10')", "path('M10,10 H20')"] },
97 { duration }
98 ));
99 await Promise.all(animations.map(animation => animationReadyToAnimateAccelerated(animation)));
100 assert_equals(internals.acceleratedAnimationsForElement(target).length, 0);
101
102 // Canceling the offset animation will no longer prevent the stack from being accelerated.
103 animations.at(-1).cancel();
104 await Promise.all(animations.map(animation => animationReadyToAnimateAccelerated(animation)));
105 assert_equals(internals.acceleratedAnimationsForElement(target).length, 1);
106}, "Animating both 'offset' and 'transform' on different animations prevents acceleration.");
107
108promise_test(async test => {
109 const target = createDiv(test);
110
111 const animation = target.animate(
112 { transform: "translateX(100px)" },
113 { duration }
114 );
115 await animationReadyToAnimateAccelerated(animation);
116 assert_equals(internals.acceleratedAnimationsForElement(target).length, 1);
117
118 animation.effect.setKeyframes(
119 { transform: "translateX(100px)", cssOffset: ["path('M10,10 H10')", "path('M10,10 H20')"] }
120 );
121 await animationReadyToAnimateAccelerated(animation);
122 assert_equals(internals.acceleratedAnimationsForElement(target).length, 0);
123}, "Setting keyframes on an animation to include 'offset' on top of 'transform' prevents acceleration.");
124
125</script>
126</body>