tor-browser

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

keyframe-utils.js (1729B)


      1 'use strict';
      2 
      3 // =======================================
      4 //
      5 // Utility functions for testing keyframes
      6 //
      7 // =======================================
      8 
      9 
     10 // ------------------------------
     11 //  Helper functions
     12 // ------------------------------
     13 
     14 /**
     15 * Test equality between two lists of computed keyframes
     16 * @param {Array.<ComputedKeyframe>} a - actual computed keyframes
     17 * @param {Array.<ComputedKeyframe>} b - expected computed keyframes
     18 */
     19 function assert_frame_lists_equal(a, b, message) {
     20  assert_equals(a.length, b.length, `number of frames: ${(message || '')}`);
     21  for (let i = 0; i < Math.min(a.length, b.length); i++) {
     22    assert_frames_equal(a[i], b[i],
     23                        `ComputedKeyframe #${i}: ${(message || '')}`);
     24  }
     25 }
     26 
     27 /** Helper for assert_frame_lists_equal */
     28 function assert_frames_equal(a, b, name) {
     29  assert_equals(Object.keys(a).sort().toString(),
     30                Object.keys(b).sort().toString(),
     31                `properties on ${name} should match`);
     32  // Iterates sorted keys to ensure stable failures.
     33  for (const p of Object.keys(a).sort()) {
     34    if (typeof b[p] == 'number')
     35      assert_approx_equals(a[p], b[p], 1e-6, `value for '${p}' on ${name}`);
     36    else if (typeof b[p] == 'object') {
     37      for (const key in b[p]) {
     38        if (typeof b[p][key] == 'number') {
     39          assert_approx_equals(a[p][key], b[p][key], 1e-6,
     40                               `value for '${p}.${key}' on ${name}`);
     41        } else {
     42          assert_equals((a[p][key] || 'undefined').toString(),
     43                         b[p][key].toString(),
     44                        `value for '${p}.${key}' on ${name}`);
     45        }
     46      }
     47    }
     48    else
     49      assert_equals(a[p], b[p], `value for '${p}' on ${name}`);
     50  }
     51 }