summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/animation-worklet/common.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/web-platform/tests/animation-worklet/common.js
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/animation-worklet/common.js')
-rw-r--r--testing/web-platform/tests/animation-worklet/common.js61
1 files changed, 61 insertions, 0 deletions
diff --git a/testing/web-platform/tests/animation-worklet/common.js b/testing/web-platform/tests/animation-worklet/common.js
new file mode 100644
index 0000000000..ceb430b718
--- /dev/null
+++ b/testing/web-platform/tests/animation-worklet/common.js
@@ -0,0 +1,61 @@
+'use strict';
+
+function registerPassthroughAnimator() {
+ return runInAnimationWorklet(`
+ registerAnimator('passthrough', class {
+ animate(currentTime, effect) {
+ effect.localTime = currentTime;
+ }
+ });
+ `);
+}
+
+function registerConstantLocalTimeAnimator(localTime) {
+ return runInAnimationWorklet(`
+ registerAnimator('constant_time', class {
+ animate(currentTime, effect) { effect.localTime = ${localTime}; }
+ });
+ `);
+}
+
+function runInAnimationWorklet(code) {
+ return CSS.animationWorklet.addModule(
+ URL.createObjectURL(new Blob([code], {type: 'text/javascript'}))
+ );
+}
+
+function approxEquals(actual, expected){
+ // precision in ms
+ const epsilon = 0.005;
+ const lowerBound = (expected - epsilon) < actual;
+ const upperBound = (expected + epsilon) > actual;
+ return lowerBound && upperBound;
+}
+
+function waitForAsyncAnimationFrames(count) {
+ // In Chrome, waiting for N+1 main thread frames guarantees that compositor has produced
+ // at least N frames.
+ // TODO(majidvp): re-evaluate this choice once other browsers have implemented
+ // AnimationWorklet.
+ return waitForAnimationFrames(count + 1);
+}
+
+async function waitForAnimationFrameWithCondition(condition) {
+ do {
+ await new Promise(window.requestAnimationFrame);
+ } while (!condition())
+}
+
+async function waitForDocumentTimelineAdvance() {
+ const timeAtStart = document.timeline.currentTime;
+ do {
+ await new Promise(window.requestAnimationFrame);
+ } while (timeAtStart === document.timeline.currentTime)
+}
+
+// Wait until animation's effect has a non-null localTime.
+async function waitForNotNullLocalTime(animation) {
+ await waitForAnimationFrameWithCondition(_ => {
+ return animation.effect.getComputedTiming().localTime !== null;
+ });
+} \ No newline at end of file