11cb0ef41Sopenharmony_ci// META: script=resources/user-timing-helper.js 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_cifunction cleanupPerformanceTimeline() { 41cb0ef41Sopenharmony_ci performance.clearMarks(); 51cb0ef41Sopenharmony_ci performance.clearMeasures(); 61cb0ef41Sopenharmony_ci} 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ciasync_test(function (t) { 91cb0ef41Sopenharmony_ci this.add_cleanup(cleanupPerformanceTimeline); 101cb0ef41Sopenharmony_ci let measureEntries = []; 111cb0ef41Sopenharmony_ci const timeStamp1 = 784.4; 121cb0ef41Sopenharmony_ci const timeStamp2 = 1234.5; 131cb0ef41Sopenharmony_ci const timeStamp3 = 66.6; 141cb0ef41Sopenharmony_ci const timeStamp4 = 5566; 151cb0ef41Sopenharmony_ci const expectedEntries = 161cb0ef41Sopenharmony_ci [{ entryType: "measure", name: "measure1", detail: null, startTime: 0 }, 171cb0ef41Sopenharmony_ci { entryType: "measure", name: "measure2", detail: null, startTime: 0 }, 181cb0ef41Sopenharmony_ci { entryType: "measure", name: "measure3", detail: null, startTime: 0 }, 191cb0ef41Sopenharmony_ci { entryType: "measure", name: "measure4", detail: null }, 201cb0ef41Sopenharmony_ci { entryType: "measure", name: "measure5", detail: null, startTime: 0 }, 211cb0ef41Sopenharmony_ci { entryType: "measure", name: "measure6", detail: null, startTime: timeStamp1 }, 221cb0ef41Sopenharmony_ci { entryType: "measure", name: "measure7", detail: null, startTime: timeStamp1, duration: timeStamp2 - timeStamp1 }, 231cb0ef41Sopenharmony_ci { entryType: "measure", name: "measure8", detail: null, startTime: 0 }, 241cb0ef41Sopenharmony_ci { entryType: "measure", name: "measure9", detail: null, startTime: 0 }, 251cb0ef41Sopenharmony_ci { entryType: "measure", name: "measure10", detail: null, startTime: timeStamp1 }, 261cb0ef41Sopenharmony_ci { entryType: "measure", name: "measure11", detail: null, startTime: timeStamp3 }, 271cb0ef41Sopenharmony_ci { entryType: "measure", name: "measure12", detail: null, startTime: 0 }, 281cb0ef41Sopenharmony_ci { entryType: "measure", name: "measure13", detail: null, startTime: 0 }, 291cb0ef41Sopenharmony_ci { entryType: "measure", name: "measure14", detail: null, startTime: timeStamp3, duration: timeStamp1 - timeStamp3 }, 301cb0ef41Sopenharmony_ci { entryType: "measure", name: "measure15", detail: null, startTime: timeStamp1, duration: timeStamp2 - timeStamp1 }, 311cb0ef41Sopenharmony_ci { entryType: "measure", name: "measure16", detail: null, startTime: timeStamp1 }, 321cb0ef41Sopenharmony_ci { entryType: "measure", name: "measure17", detail: { customInfo: 159 }, startTime: timeStamp3, duration: timeStamp2 - timeStamp3 }, 331cb0ef41Sopenharmony_ci { entryType: "measure", name: "measure18", detail: null, startTime: timeStamp1, duration: timeStamp2 - timeStamp1 }, 341cb0ef41Sopenharmony_ci { entryType: "measure", name: "measure19", detail: null, startTime: timeStamp1, duration: timeStamp2 - timeStamp1 }, 351cb0ef41Sopenharmony_ci { entryType: "measure", name: "measure20", detail: null, startTime: 0 }, 361cb0ef41Sopenharmony_ci { entryType: "measure", name: "measure21", detail: null, startTime: 0 }, 371cb0ef41Sopenharmony_ci { entryType: "measure", name: "measure22", detail: null, startTime: 0 }, 381cb0ef41Sopenharmony_ci { entryType: "measure", name: "measure23", detail: null, startTime: 0 }]; 391cb0ef41Sopenharmony_ci const observer = new PerformanceObserver( 401cb0ef41Sopenharmony_ci t.step_func(function (entryList, obs) { 411cb0ef41Sopenharmony_ci measureEntries = 421cb0ef41Sopenharmony_ci measureEntries.concat(entryList.getEntries()); 431cb0ef41Sopenharmony_ci if (measureEntries.length >= expectedEntries.length) { 441cb0ef41Sopenharmony_ci checkEntries(measureEntries, expectedEntries); 451cb0ef41Sopenharmony_ci observer.disconnect(); 461cb0ef41Sopenharmony_ci t.done(); 471cb0ef41Sopenharmony_ci } 481cb0ef41Sopenharmony_ci }) 491cb0ef41Sopenharmony_ci ); 501cb0ef41Sopenharmony_ci observer.observe({ entryTypes: ["measure"] }); 511cb0ef41Sopenharmony_ci self.performance.mark("mark1", { detail: { randomInfo: 3 }, startTime: timeStamp1 }); 521cb0ef41Sopenharmony_ci self.performance.mark("mark2", { startTime: timeStamp2 }); 531cb0ef41Sopenharmony_ci 541cb0ef41Sopenharmony_ci const returnedEntries = []; 551cb0ef41Sopenharmony_ci returnedEntries.push(self.performance.measure("measure1")); 561cb0ef41Sopenharmony_ci returnedEntries.push(self.performance.measure("measure2", undefined)); 571cb0ef41Sopenharmony_ci returnedEntries.push(self.performance.measure("measure3", null)); 581cb0ef41Sopenharmony_ci returnedEntries.push(self.performance.measure("measure4", 'mark1')); 591cb0ef41Sopenharmony_ci returnedEntries.push( 601cb0ef41Sopenharmony_ci self.performance.measure("measure5", null, 'mark1')); 611cb0ef41Sopenharmony_ci returnedEntries.push( 621cb0ef41Sopenharmony_ci self.performance.measure("measure6", 'mark1', undefined)); 631cb0ef41Sopenharmony_ci returnedEntries.push( 641cb0ef41Sopenharmony_ci self.performance.measure("measure7", 'mark1', 'mark2')); 651cb0ef41Sopenharmony_ci returnedEntries.push( 661cb0ef41Sopenharmony_ci self.performance.measure("measure8", {})); 671cb0ef41Sopenharmony_ci returnedEntries.push( 681cb0ef41Sopenharmony_ci self.performance.measure("measure9", { start: undefined })); 691cb0ef41Sopenharmony_ci returnedEntries.push( 701cb0ef41Sopenharmony_ci self.performance.measure("measure10", { start: 'mark1' })); 711cb0ef41Sopenharmony_ci returnedEntries.push( 721cb0ef41Sopenharmony_ci self.performance.measure("measure11", { start: timeStamp3 })); 731cb0ef41Sopenharmony_ci returnedEntries.push( 741cb0ef41Sopenharmony_ci self.performance.measure("measure12", { end: undefined })); 751cb0ef41Sopenharmony_ci returnedEntries.push( 761cb0ef41Sopenharmony_ci self.performance.measure("measure13", { end: 'mark1' })); 771cb0ef41Sopenharmony_ci returnedEntries.push( 781cb0ef41Sopenharmony_ci self.performance.measure("measure14", { start: timeStamp3, end: 'mark1' })); 791cb0ef41Sopenharmony_ci returnedEntries.push( 801cb0ef41Sopenharmony_ci self.performance.measure("measure15", { start: timeStamp1, end: timeStamp2, detail: undefined })); 811cb0ef41Sopenharmony_ci returnedEntries.push( 821cb0ef41Sopenharmony_ci self.performance.measure("measure16", { start: 'mark1', end: undefined, detail: null })); 831cb0ef41Sopenharmony_ci returnedEntries.push( 841cb0ef41Sopenharmony_ci self.performance.measure("measure17", { start: timeStamp3, end: 'mark2', detail: { customInfo: 159 }})); 851cb0ef41Sopenharmony_ci returnedEntries.push( 861cb0ef41Sopenharmony_ci self.performance.measure("measure18", { start: timeStamp1, duration: timeStamp2 - timeStamp1 })); 871cb0ef41Sopenharmony_ci returnedEntries.push( 881cb0ef41Sopenharmony_ci self.performance.measure("measure19", { duration: timeStamp2 - timeStamp1, end: timeStamp2 })); 891cb0ef41Sopenharmony_ci // {}, null, undefined, invalid-dict passed to startOrOptions are interpreted as start time being 0. 901cb0ef41Sopenharmony_ci returnedEntries.push(self.performance.measure("measure20", {}, 'mark1')); 911cb0ef41Sopenharmony_ci returnedEntries.push(self.performance.measure("measure21", null, 'mark1')); 921cb0ef41Sopenharmony_ci returnedEntries.push(self.performance.measure("measure22", undefined, 'mark1')); 931cb0ef41Sopenharmony_ci returnedEntries.push(self.performance.measure("measure23", { invalidDict:1 }, 'mark1')); 941cb0ef41Sopenharmony_ci checkEntries(returnedEntries, expectedEntries); 951cb0ef41Sopenharmony_ci}, "measure entries' detail and start/end are customizable"); 961cb0ef41Sopenharmony_ci 971cb0ef41Sopenharmony_citest(function() { 981cb0ef41Sopenharmony_ci this.add_cleanup(cleanupPerformanceTimeline); 991cb0ef41Sopenharmony_ci assert_throws_js(TypeError, function() { 1001cb0ef41Sopenharmony_ci self.performance.measure("optionsAndNumberEnd", {'start': 2}, 12); 1011cb0ef41Sopenharmony_ci }, "measure should throw a TypeError when passed an options object and an end time"); 1021cb0ef41Sopenharmony_ci assert_throws_js(TypeError, function() { 1031cb0ef41Sopenharmony_ci self.performance.measure("optionsAndMarkEnd", {'start': 2}, 'mark1'); 1041cb0ef41Sopenharmony_ci }, "measure should throw a TypeError when passed an options object and an end mark"); 1051cb0ef41Sopenharmony_ci assert_throws_js(TypeError, function() { 1061cb0ef41Sopenharmony_ci self.performance.measure("negativeStartInOptions", {'start': -1}); 1071cb0ef41Sopenharmony_ci }, "measure cannot have a negative time stamp."); 1081cb0ef41Sopenharmony_ci assert_throws_js(TypeError, function() { 1091cb0ef41Sopenharmony_ci self.performance.measure("negativeEndInOptions", {'end': -1}); 1101cb0ef41Sopenharmony_ci }, "measure cannot have a negative time stamp for end."); 1111cb0ef41Sopenharmony_ci}, "measure should throw a TypeError when passed an invalid argument combination"); 1121cb0ef41Sopenharmony_ci 113