11cb0ef41Sopenharmony_ci// Compares a list of performance entries to a predefined one. 21cb0ef41Sopenharmony_ci// actualEntries is an array of performance entries from the user agent, 31cb0ef41Sopenharmony_ci// and expectedEntries is an array of performance entries minted by the test. 41cb0ef41Sopenharmony_ci// The comparison doesn't assert the order of the entries. 51cb0ef41Sopenharmony_cifunction checkEntries(actualEntries, expectedEntries) { 61cb0ef41Sopenharmony_ci assert_equals(actualEntries.length, expectedEntries.length, 71cb0ef41Sopenharmony_ci `The length of actual and expected entries should match. 81cb0ef41Sopenharmony_ci actual: ${JSON.stringify(actualEntries)}, 91cb0ef41Sopenharmony_ci expected: ${JSON.stringify(expectedEntries)}`); 101cb0ef41Sopenharmony_ci const actualEntrySet = new Set(actualEntries.map(ae=>ae.name)); 111cb0ef41Sopenharmony_ci assert_equals(actualEntrySet.size, actualEntries.length, `Actual entry names are not unique: ${JSON.stringify(actualEntries)}`); 121cb0ef41Sopenharmony_ci const expectedEntrySet = new Set(expectedEntries.map(ee=>ee.name)); 131cb0ef41Sopenharmony_ci assert_equals(expectedEntrySet.size, expectedEntries.length, `Expected entry names are not unique: ${JSON.stringify(expectedEntries)}`); 141cb0ef41Sopenharmony_ci actualEntries.forEach(ae=>{ 151cb0ef41Sopenharmony_ci const expectedEntry = expectedEntries.find(e=>e.name === ae.name); 161cb0ef41Sopenharmony_ci assert_true(!!expectedEntry, `Entry name '${ae.name}' was not found.`); 171cb0ef41Sopenharmony_ci checkEntry(ae, expectedEntry); 181cb0ef41Sopenharmony_ci }); 191cb0ef41Sopenharmony_ci} 201cb0ef41Sopenharmony_ci 211cb0ef41Sopenharmony_cifunction checkEntry(entry, {name, entryType, startTime, detail, duration}) { 221cb0ef41Sopenharmony_ci assert_equals(entry.name, name); 231cb0ef41Sopenharmony_ci assert_equals(entry.entryType, entryType); 241cb0ef41Sopenharmony_ci if (startTime !== undefined) 251cb0ef41Sopenharmony_ci assert_equals(entry.startTime, startTime); 261cb0ef41Sopenharmony_ci if (detail !== undefined) 271cb0ef41Sopenharmony_ci assert_equals(JSON.stringify(entry.detail), JSON.stringify(detail)); 281cb0ef41Sopenharmony_ci if (duration !== undefined) 291cb0ef41Sopenharmony_ci assert_equals(entry.duration, duration); 301cb0ef41Sopenharmony_ci} 31