tor-browser

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

performance-timeline-utils.js (1976B)


      1 /*
      2 author: W3C http://www.w3.org/
      3 help: http://www.w3.org/TR/navigation-timing/#sec-window.performance-attribute
      4 */
      5 var performanceNamespace = window.performance;
      6 var namespace_check = false;
      7 function wp_test(func, msg, properties)
      8 {
      9  // only run the namespace check once
     10  if (!namespace_check)
     11  {
     12    namespace_check = true;
     13 
     14    if (performanceNamespace === undefined || performanceNamespace == null)
     15    {
     16      // show a single error that window.performance is undefined
     17      // The window.performance attribute provides a hosting area for performance related attributes.
     18      test(function() { assert_true(performanceNamespace !== undefined && performanceNamespace != null, "window.performance is defined and not null"); }, "window.performance is defined and not null.");
     19    }
     20  }
     21 
     22  test(func, msg, properties);
     23 }
     24 
     25 function test_true(value, msg, properties)
     26 {
     27  wp_test(function () { assert_true(value, msg); }, msg, properties);
     28 }
     29 
     30 function test_equals(value, equals, msg, properties)
     31 {
     32  wp_test(function () { assert_equals(value, equals, msg); }, msg, properties);
     33 }
     34 
     35 // assert for every entry in `expectedEntries`, there is a matching entry _somewhere_ in `actualEntries`
     36 function test_entries(actualEntries, expectedEntries) {
     37  test_equals(actualEntries.length, expectedEntries.length)
     38  expectedEntries.forEach(function (expectedEntry) {
     39    var foundEntry = actualEntries.find(function (actualEntry) {
     40      return typeof Object.keys(expectedEntry).find(function (key) {
     41            return actualEntry[key] !== expectedEntry[key]
     42          }) === 'undefined'
     43    })
     44    test_true(!!foundEntry, `Entry ${JSON.stringify(expectedEntry)} could not be found.`)
     45    if (foundEntry) {
     46      assert_object_equals(foundEntry.toJSON(), expectedEntry)
     47    }
     48  })
     49 }
     50 
     51 function delayedLoadListener(callback) {
     52  window.addEventListener('load', function() {
     53    // TODO(cvazac) Remove this setTimeout when spec enforces sync entries.
     54    step_timeout(callback, 0)
     55  })
     56 }