11cb0ef41Sopenharmony_ci// test data 21cb0ef41Sopenharmony_civar testThreshold = 20; 31cb0ef41Sopenharmony_ci 41cb0ef41Sopenharmony_civar expectedTimes = new Array(); 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_cifunction match_entries(entries, index) 71cb0ef41Sopenharmony_ci{ 81cb0ef41Sopenharmony_ci var entry = entries[index]; 91cb0ef41Sopenharmony_ci var match = self.performance.getEntriesByName("mark")[index]; 101cb0ef41Sopenharmony_ci assert_equals(entry.name, match.name, "entry.name"); 111cb0ef41Sopenharmony_ci assert_equals(entry.startTime, match.startTime, "entry.startTime"); 121cb0ef41Sopenharmony_ci assert_equals(entry.entryType, match.entryType, "entry.entryType"); 131cb0ef41Sopenharmony_ci assert_equals(entry.duration, match.duration, "entry.duration"); 141cb0ef41Sopenharmony_ci} 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_cifunction filter_entries_by_type(entryList, entryType) 171cb0ef41Sopenharmony_ci{ 181cb0ef41Sopenharmony_ci var testEntries = new Array(); 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_ci // filter entryList 211cb0ef41Sopenharmony_ci for (var i in entryList) 221cb0ef41Sopenharmony_ci { 231cb0ef41Sopenharmony_ci if (entryList[i].entryType == entryType) 241cb0ef41Sopenharmony_ci { 251cb0ef41Sopenharmony_ci testEntries.push(entryList[i]); 261cb0ef41Sopenharmony_ci } 271cb0ef41Sopenharmony_ci } 281cb0ef41Sopenharmony_ci 291cb0ef41Sopenharmony_ci return testEntries; 301cb0ef41Sopenharmony_ci} 311cb0ef41Sopenharmony_ci 321cb0ef41Sopenharmony_citest(function () { 331cb0ef41Sopenharmony_ci // create first mark 341cb0ef41Sopenharmony_ci self.performance.mark("mark"); 351cb0ef41Sopenharmony_ci 361cb0ef41Sopenharmony_ci expectedTimes[0] = self.performance.now(); 371cb0ef41Sopenharmony_ci 381cb0ef41Sopenharmony_ci const entries = self.performance.getEntriesByName("mark"); 391cb0ef41Sopenharmony_ci assert_equals(entries.length, 1); 401cb0ef41Sopenharmony_ci}, "Entry 0 is properly created"); 411cb0ef41Sopenharmony_ci 421cb0ef41Sopenharmony_citest(function () { 431cb0ef41Sopenharmony_ci // create second, duplicate mark 441cb0ef41Sopenharmony_ci self.performance.mark("mark"); 451cb0ef41Sopenharmony_ci 461cb0ef41Sopenharmony_ci expectedTimes[1] = self.performance.now(); 471cb0ef41Sopenharmony_ci 481cb0ef41Sopenharmony_ci const entries = self.performance.getEntriesByName("mark"); 491cb0ef41Sopenharmony_ci assert_equals(entries.length, 2); 501cb0ef41Sopenharmony_ci 511cb0ef41Sopenharmony_ci}, "Entry 1 is properly created"); 521cb0ef41Sopenharmony_ci 531cb0ef41Sopenharmony_cifunction test_mark(index) { 541cb0ef41Sopenharmony_ci test(function () { 551cb0ef41Sopenharmony_ci const entries = self.performance.getEntriesByName("mark"); 561cb0ef41Sopenharmony_ci assert_equals(entries[index].name, "mark", "Entry has the proper name"); 571cb0ef41Sopenharmony_ci }, "Entry " + index + " has the proper name"); 581cb0ef41Sopenharmony_ci 591cb0ef41Sopenharmony_ci test(function () { 601cb0ef41Sopenharmony_ci const entries = self.performance.getEntriesByName("mark"); 611cb0ef41Sopenharmony_ci assert_approx_equals(entries[index].startTime, expectedTimes[index], testThreshold); 621cb0ef41Sopenharmony_ci }, "Entry " + index + " startTime is approximately correct (up to " + testThreshold + 631cb0ef41Sopenharmony_ci "ms difference allowed)"); 641cb0ef41Sopenharmony_ci 651cb0ef41Sopenharmony_ci test(function () { 661cb0ef41Sopenharmony_ci const entries = self.performance.getEntriesByName("mark"); 671cb0ef41Sopenharmony_ci assert_equals(entries[index].entryType, "mark"); 681cb0ef41Sopenharmony_ci }, "Entry " + index + " has the proper entryType"); 691cb0ef41Sopenharmony_ci 701cb0ef41Sopenharmony_ci test(function () { 711cb0ef41Sopenharmony_ci const entries = self.performance.getEntriesByName("mark"); 721cb0ef41Sopenharmony_ci assert_equals(entries[index].duration, 0); 731cb0ef41Sopenharmony_ci }, "Entry " + index + " duration == 0"); 741cb0ef41Sopenharmony_ci 751cb0ef41Sopenharmony_ci test(function () { 761cb0ef41Sopenharmony_ci const entries = self.performance.getEntriesByName("mark", "mark"); 771cb0ef41Sopenharmony_ci assert_equals(entries[index].name, "mark"); 781cb0ef41Sopenharmony_ci }, "getEntriesByName(\"mark\", \"mark\")[" + index + "] returns an " + 791cb0ef41Sopenharmony_ci "object containing a \"mark\" mark"); 801cb0ef41Sopenharmony_ci 811cb0ef41Sopenharmony_ci test(function () { 821cb0ef41Sopenharmony_ci const entries = self.performance.getEntriesByName("mark", "mark"); 831cb0ef41Sopenharmony_ci match_entries(entries, index); 841cb0ef41Sopenharmony_ci }, "The mark returned by getEntriesByName(\"mark\", \"mark\")[" + index 851cb0ef41Sopenharmony_ci + "] matches the mark returned by " + 861cb0ef41Sopenharmony_ci "getEntriesByName(\"mark\")[" + index + "]"); 871cb0ef41Sopenharmony_ci 881cb0ef41Sopenharmony_ci test(function () { 891cb0ef41Sopenharmony_ci const entries = filter_entries_by_type(self.performance.getEntries(), "mark"); 901cb0ef41Sopenharmony_ci assert_equals(entries[index].name, "mark"); 911cb0ef41Sopenharmony_ci }, "getEntries()[" + index + "] returns an " + 921cb0ef41Sopenharmony_ci "object containing a \"mark\" mark"); 931cb0ef41Sopenharmony_ci 941cb0ef41Sopenharmony_ci test(function () { 951cb0ef41Sopenharmony_ci const entries = filter_entries_by_type(self.performance.getEntries(), "mark"); 961cb0ef41Sopenharmony_ci match_entries(entries, index); 971cb0ef41Sopenharmony_ci }, "The mark returned by getEntries()[" + index 981cb0ef41Sopenharmony_ci + "] matches the mark returned by " + 991cb0ef41Sopenharmony_ci "getEntriesByName(\"mark\")[" + index + "]"); 1001cb0ef41Sopenharmony_ci 1011cb0ef41Sopenharmony_ci test(function () { 1021cb0ef41Sopenharmony_ci const entries = self.performance.getEntriesByType("mark"); 1031cb0ef41Sopenharmony_ci assert_equals(entries[index].name, "mark"); 1041cb0ef41Sopenharmony_ci }, "getEntriesByType(\"mark\")[" + index + "] returns an " + 1051cb0ef41Sopenharmony_ci "object containing a \"mark\" mark"); 1061cb0ef41Sopenharmony_ci 1071cb0ef41Sopenharmony_ci test(function () { 1081cb0ef41Sopenharmony_ci const entries = self.performance.getEntriesByType("mark"); 1091cb0ef41Sopenharmony_ci match_entries(entries, index); 1101cb0ef41Sopenharmony_ci }, "The mark returned by getEntriesByType(\"mark\")[" + index 1111cb0ef41Sopenharmony_ci + "] matches the mark returned by " + 1121cb0ef41Sopenharmony_ci "getEntriesByName(\"mark\")[" + index + "]"); 1131cb0ef41Sopenharmony_ci 1141cb0ef41Sopenharmony_ci} 1151cb0ef41Sopenharmony_ci 1161cb0ef41Sopenharmony_cifor (var i = 0; i < expectedTimes.length; i++) { 1171cb0ef41Sopenharmony_ci test_mark(i); 1181cb0ef41Sopenharmony_ci} 119