tor-browser

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

user-timing-helper.js (1596B)


      1 // Compares a list of performance entries to a predefined one.
      2 // actualEntries is an array of performance entries from the user agent,
      3 // and expectedEntries is an array of performance entries minted by the test.
      4 // The comparison doesn't assert the order of the entries.
      5 function checkEntries(actualEntries, expectedEntries) {
      6  assert_equals(actualEntries.length, expectedEntries.length,
      7      `The length of actual and expected entries should match.
      8      actual: ${JSON.stringify(actualEntries)},
      9      expected: ${JSON.stringify(expectedEntries)}`);
     10  const actualEntrySet = new Set(actualEntries.map(ae=>ae.name));
     11  assert_equals(actualEntrySet.size, actualEntries.length, `Actual entry names are not unique: ${JSON.stringify(actualEntries)}`);
     12  const expectedEntrySet = new Set(expectedEntries.map(ee=>ee.name));
     13  assert_equals(expectedEntrySet.size, expectedEntries.length, `Expected entry names are not unique: ${JSON.stringify(expectedEntries)}`);
     14  actualEntries.forEach(ae=>{
     15    const expectedEntry = expectedEntries.find(e=>e.name === ae.name);
     16    assert_true(!!expectedEntry, `Entry name '${ae.name}' was not found.`);
     17    checkEntry(ae, expectedEntry);
     18  });
     19 }
     20 
     21 function checkEntry(entry, {name, entryType, startTime, detail, duration}) {
     22  assert_equals(entry.name, name);
     23  assert_equals(entry.entryType, entryType);
     24  if (startTime !== undefined)
     25    assert_equals(entry.startTime, startTime);
     26  if (detail !== undefined)
     27    assert_equals(JSON.stringify(entry.detail), JSON.stringify(detail));
     28  if (duration !== undefined)
     29    assert_equals(entry.duration, duration);
     30 }