summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/web-animations/resources/effect-tests.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
commit0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch)
treea31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /testing/web-platform/tests/web-animations/resources/effect-tests.js
parentInitial commit. (diff)
downloadfirefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.tar.xz
firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.zip
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/web-animations/resources/effect-tests.js')
-rw-r--r--testing/web-platform/tests/web-animations/resources/effect-tests.js75
1 files changed, 75 insertions, 0 deletions
diff --git a/testing/web-platform/tests/web-animations/resources/effect-tests.js b/testing/web-platform/tests/web-animations/resources/effect-tests.js
new file mode 100644
index 0000000000..8a18ab13c6
--- /dev/null
+++ b/testing/web-platform/tests/web-animations/resources/effect-tests.js
@@ -0,0 +1,75 @@
+'use strict';
+
+// Common utility methods for testing animation effects
+
+// Tests the |property| member of |animation's| target effect's computed timing
+// at the various points indicated by |values|.
+//
+// |values| has the format:
+//
+// {
+// before, // value to test during before phase
+// activeBoundary, // value to test at the very beginning of the active
+// // phase when playing forwards, or the very end of
+// // the active phase when playing backwards.
+// // This should be undefined if the active duration of
+// // the effect is zero.
+// after, // value to test during the after phase or undefined if the
+// // active duration is infinite
+// }
+//
+function assert_computed_timing_for_each_phase(animation, property, values) {
+ // Some computed timing properties (e.g. 'progress') require floating-point
+ // comparison, whilst exact equality suffices for others.
+ const assert_property_equals =
+ (property === 'progress') ? assert_times_equal : assert_equals;
+
+ const effect = animation.effect;
+ const timing = effect.getComputedTiming();
+
+ // The following calculations are based on the definitions here:
+ // https://drafts.csswg.org/web-animations/#animation-effect-phases-and-states
+ const beforeActive = Math.max(Math.min(timing.delay, timing.endTime), 0);
+ const activeAfter =
+ Math.max(Math.min(timing.delay + timing.activeDuration, timing.endTime), 0);
+ const direction = animation.playbackRate < 0 ? 'backwards' : 'forwards';
+
+ // Before phase
+ if (direction === 'forwards') {
+ animation.currentTime = beforeActive - 1;
+ } else {
+ animation.currentTime = beforeActive;
+ }
+ assert_property_equals(effect.getComputedTiming()[property], values.before,
+ `Value of ${property} in the before phase`);
+
+ // Active phase
+ if (effect.getComputedTiming().activeDuration > 0) {
+ if (direction === 'forwards') {
+ animation.currentTime = beforeActive;
+ } else {
+ animation.currentTime = activeAfter;
+ }
+ assert_property_equals(effect.getComputedTiming()[property], values.activeBoundary,
+ `Value of ${property} at the boundary of the active phase`);
+ } else {
+ assert_equals(values.activeBoundary, undefined,
+ 'Test specifies a value to check during the active phase but'
+ + ' the animation has a zero duration');
+ }
+
+ // After phase
+ if (effect.getComputedTiming().activeDuration !== Infinity) {
+ if (direction === 'forwards') {
+ animation.currentTime = activeAfter;
+ } else {
+ animation.currentTime = activeAfter + 1;
+ }
+ assert_property_equals(effect.getComputedTiming()[property], values.after,
+ `Value of ${property} in the after phase`);
+ } else {
+ assert_equals(values.after, undefined,
+ 'Test specifies a value to check during the after phase but'
+ + ' the animation has an infinite duration');
+ }
+}