tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

timing-utils.js (1102B)


      1 'use strict';
      2 
      3 // =======================================
      4 //
      5 // Utility functions for testing timing
      6 //
      7 // =======================================
      8 
      9 
     10 // ------------------------------
     11 //  Helper functions
     12 // ------------------------------
     13 
     14 // Utility function to check that a subset of timing properties have their
     15 // default values.
     16 function assert_default_timing_except(effect, propertiesToSkip) {
     17  const defaults = {
     18    delay: 0,
     19    endDelay: 0,
     20    fill: 'auto',
     21    iterationStart: 0,
     22    iterations: 1,
     23    duration: 'auto',
     24    direction: 'normal',
     25    easing: 'linear',
     26  };
     27 
     28  for (const prop of Object.keys(defaults)) {
     29    if (propertiesToSkip.includes(prop)) {
     30      continue;
     31    }
     32 
     33    assert_equals(
     34      effect.getTiming()[prop],
     35      defaults[prop],
     36      `${prop} parameter has default value:`
     37    );
     38  }
     39 }
     40 
     41 function waitForAnimationTime(animation, time) {
     42  return new Promise((resolve) => {
     43    function raf() {
     44      if (animation.currentTime < time) {
     45        requestAnimationFrame(raf);
     46      } else {
     47        resolve();
     48      }
     49    }
     50    requestAnimationFrame(raf);
     51  });
     52 }