Commit 1500c78c authored by Liquan(Max) Gu's avatar Liquan(Max) Gu Committed by Commit Bot

[UserTimingL3] Refactor entry list comparison logic in custom-user-timing/

In the original comparison logic of performance entries, entries are identified
based on entryType, name, detail (if listed) and startTime (if listed). An entry
is set to be found only when all of the attributes match. If any of the
attribute is not found, the test would just said the entry is not found. But
the developer wouldn't know which attribute cause the comparison to fail.

In a new logic, we use the name as the identifier for entries. Once the entry
is found, we then compare their attributes. In this way, developers would know
which attribute caused the failure by the error message.

Another benefit of the refactoring is that it factors out the logic of single
entry comparison. The logic will be useful for test cases in later patches.

Bug: 758385
Change-Id: Ib5721367228f32567efa74cd14a75688fbb34af7
Reviewed-on: https://chromium-review.googlesource.com/c/1346913
Commit-Queue: Liquan (Max) Gǔ <maxlg@chromium.org>
Reviewed-by: default avatarNicolás Peña Moreno <npm@chromium.org>
Cr-Commit-Position: refs/heads/master@{#610314}
parent 2141c235
// Compares a list of performance entries to a predefined one.
// perfEntriesToCheck is an array of performance entries from the user agent,
// actualEntries is an array of performance entries from the user agent,
// and expectedEntries is an array of performance entries minted by the test.
function checkEntries(perfEntriesToCheck, expectedEntries) {
function findMatch(pe) {
// We match based on entryType, name, detail (if listed) and
// startTime (if listed).
for (let i = 0; i < expectedEntries.length; i++) {
const ex = expectedEntries[i];
if (ex.entryType === pe.entryType && ex.name === pe.name &&
(ex.detail === undefined ||
JSON.stringify(ex.detail) === JSON.stringify(pe.detail)) &&
(ex.startTime === undefined || ex.startTime === pe.startTime) &&
(ex.duration === undefined || ex.duration === pe.duration)) {
return ex;
}
}
return null;
}
assert_equals(perfEntriesToCheck.length, expectedEntries.length,
"performance entries must match");
perfEntriesToCheck.forEach(function(pe) {
assert_not_equals(findMatch(pe), null, "Entry matches. Entry:" + JSON.stringify(pe) + ", All:" + JSON.stringify(expectedEntries));
// 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);
});
}
\ No newline at end of file
}
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);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment