1// Compares a performance entry to a predefined one 2// perfEntriesToCheck is an array of performance entries from the user agent 3// expectedEntries is an array of performance entries minted by the test 4function checkEntries(perfEntriesToCheck, expectedEntries) { 5 function findMatch(pe) { 6 // we match based on entryType and name 7 for (var i = expectedEntries.length - 1; i >= 0; i--) { 8 var ex = expectedEntries[i]; 9 if (ex.entryType === pe.entryType && ex.name === pe.name) { 10 return ex; 11 } 12 } 13 return null; 14 } 15 16 assert_equals(perfEntriesToCheck.length, expectedEntries.length, "performance entries must match"); 17 18 perfEntriesToCheck.forEach(function (pe1) { 19 assert_not_equals(findMatch(pe1), null, "Entry matches"); 20 }); 21} 22 23// Waits for performance.now to advance. Since precision reduction might 24// cause it to return the same value across multiple calls. 25function wait() { 26 var now = performance.now(); 27 while (now === performance.now()) 28 continue; 29} 30 31// Ensure the entries list is sorted by startTime. 32function checkSorted(entries) { 33 assert_not_equals(entries.length, 0, "entries list must not be empty"); 34 if (!entries.length) 35 return; 36 37 var sorted = false; 38 var lastStartTime = entries[0].startTime; 39 for (var i = 1; i < entries.length; ++i) { 40 var currStartTime = entries[i].startTime; 41 assert_less_than_equal(lastStartTime, currStartTime, "entry list must be sorted by startTime"); 42 lastStartTime = currStartTime; 43 } 44} 45