summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/web-animations/resources/timing-utils.js
blob: fba62a1f6d89e5811c7ed4ef79ae1046e1001971 (plain)
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
'use strict';

// =======================================
//
// Utility functions for testing timing
//
// =======================================


// ------------------------------
//  Helper functions
// ------------------------------

// Utility function to check that a subset of timing properties have their
// default values.
function assert_default_timing_except(effect, propertiesToSkip) {
  const defaults = {
    delay: 0,
    endDelay: 0,
    fill: 'auto',
    iterationStart: 0,
    iterations: 1,
    duration: 'auto',
    direction: 'normal',
    easing: 'linear',
  };

  for (const prop of Object.keys(defaults)) {
    if (propertiesToSkip.includes(prop)) {
      continue;
    }

    assert_equals(
      effect.getTiming()[prop],
      defaults[prop],
      `${prop} parameter has default value:`
    );
  }
}

function waitForAnimationTime(animation, time) {
  return new Promise((resolve) => {
    function raf() {
      if (animation.currentTime < time) {
        requestAnimationFrame(raf);
      } else {
        resolve();
      }
    }
    requestAnimationFrame(raf);
  });
}