summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/user-timing/resources/user-timing-helper.js
blob: 8d43768ec2819620bf637c41918e8a6e6bc72181 (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
// Compares a list of performance entries to a predefined one.
// actualEntries is an array of performance entries from the user agent,
// and expectedEntries is an array of performance entries minted by the test.
// The comparison doesn't assert the order of the entries.
function checkEntries(actualEntries, expectedEntries) {
  assert_equals(actualEntries.length, expectedEntries.length,
      `The length of actual and expected entries should match.
      actual: ${JSON.stringify(actualEntries)},
      expected: ${JSON.stringify(expectedEntries)}`);
  const actualEntrySet = new Set(actualEntries.map(ae=>ae.name));
  assert_equals(actualEntrySet.size, actualEntries.length, `Actual entry names are not unique: ${JSON.stringify(actualEntries)}`);
  const expectedEntrySet = new Set(expectedEntries.map(ee=>ee.name));
  assert_equals(expectedEntrySet.size, expectedEntries.length, `Expected entry names are not unique: ${JSON.stringify(expectedEntries)}`);
  actualEntries.forEach(ae=>{
    const expectedEntry = expectedEntries.find(e=>e.name === ae.name);
    assert_true(!!expectedEntry, `Entry name '${ae.name}' was not found.`);
    checkEntry(ae, expectedEntry);
  });
}

function checkEntry(entry, {name, entryType, startTime, detail, duration}) {
  assert_equals(entry.name, name);
  assert_equals(entry.entryType, entryType);
  if (startTime !== undefined)
    assert_equals(entry.startTime, startTime);
  if (detail !== undefined)
    assert_equals(JSON.stringify(entry.detail), JSON.stringify(detail));
  if (duration !== undefined)
    assert_equals(entry.duration, duration);
}