11cb0ef41Sopenharmony_ci<!DOCTYPE HTML> 21cb0ef41Sopenharmony_ci<meta charset=utf-8> 31cb0ef41Sopenharmony_ci<title>PerformanceObservers: PerformanceObserverInit.buffered</title> 41cb0ef41Sopenharmony_ci<meta name="timeout" content="long"> 51cb0ef41Sopenharmony_ci<script src="/resources/testharness.js"></script> 61cb0ef41Sopenharmony_ci<script src="/resources/testharnessreport.js"></script> 71cb0ef41Sopenharmony_ci<script src="performanceobservers.js"></script> 81cb0ef41Sopenharmony_ci<h1>PerformanceObservers: PerformanceObserverInit.buffered</h1> 91cb0ef41Sopenharmony_ci<p> 101cb0ef41Sopenharmony_ciPerformanceObserverInit.buffered should retrieve previously buffered entries 111cb0ef41Sopenharmony_ci</p> 121cb0ef41Sopenharmony_ci<div id="log"></div> 131cb0ef41Sopenharmony_ci<script> 141cb0ef41Sopenharmony_ci async_test(function (t) { 151cb0ef41Sopenharmony_ci function initTest() { 161cb0ef41Sopenharmony_ci new PerformanceObserver(function (entryList, observer) { 171cb0ef41Sopenharmony_ci entryList.getEntries().forEach(function(entry) { 181cb0ef41Sopenharmony_ci if (shouldExclude(entry)) { 191cb0ef41Sopenharmony_ci return; 201cb0ef41Sopenharmony_ci } 211cb0ef41Sopenharmony_ci 221cb0ef41Sopenharmony_ci observedEntries.push(entry); 231cb0ef41Sopenharmony_ci if (observedEntries.length === entryTypes.length) { 241cb0ef41Sopenharmony_ci observer.disconnect(); 251cb0ef41Sopenharmony_ci runTest(); 261cb0ef41Sopenharmony_ci } 271cb0ef41Sopenharmony_ci }); 281cb0ef41Sopenharmony_ci }).observe({entryTypes}); 291cb0ef41Sopenharmony_ci 301cb0ef41Sopenharmony_ci // creates a `resource` entry 311cb0ef41Sopenharmony_ci var img = document.createElement("img"); 321cb0ef41Sopenharmony_ci img.src = "./resources/square.png"; 331cb0ef41Sopenharmony_ci document.body.appendChild(img); 341cb0ef41Sopenharmony_ci 351cb0ef41Sopenharmony_ci performance.mark("markName"); // creates a `mark` entry 361cb0ef41Sopenharmony_ci performance.measure("measureName"); // creates a `measure` entry 371cb0ef41Sopenharmony_ci } 381cb0ef41Sopenharmony_ci function shouldExclude(entry) { 391cb0ef41Sopenharmony_ci // exclude all `resource` entries that aren't for "square.png" 401cb0ef41Sopenharmony_ci return entry.entryType === "resource" && 411cb0ef41Sopenharmony_ci entry.name.indexOf("square.png") === -1; 421cb0ef41Sopenharmony_ci } 431cb0ef41Sopenharmony_ci function runTest() { 441cb0ef41Sopenharmony_ci // this PerformanceObserver is a nop because we've already been notified about all of our `entryTypes` 451cb0ef41Sopenharmony_ci var po_nop = new PerformanceObserver(function (entryList, observer) { 461cb0ef41Sopenharmony_ci if (entryList.getEntries().find(function(entry) { 471cb0ef41Sopenharmony_ci return !shouldExclude(entry); 481cb0ef41Sopenharmony_ci })) { 491cb0ef41Sopenharmony_ci assert_unreached("this PerformanceObserver callback should never be called"); 501cb0ef41Sopenharmony_ci } 511cb0ef41Sopenharmony_ci }); 521cb0ef41Sopenharmony_ci po_nop.observe({ 531cb0ef41Sopenharmony_ci entryTypes, 541cb0ef41Sopenharmony_ci }); 551cb0ef41Sopenharmony_ci 561cb0ef41Sopenharmony_ci // this PerformanceObserver should be notified about the previously 571cb0ef41Sopenharmony_ci // buffered mark entry only 581cb0ef41Sopenharmony_ci const bufferedEntries = []; 591cb0ef41Sopenharmony_ci new PerformanceObserver(function (entryList, observer) { 601cb0ef41Sopenharmony_ci entryList.getEntries().forEach(function(entry) { 611cb0ef41Sopenharmony_ci if (shouldExclude(entry)) { 621cb0ef41Sopenharmony_ci return; 631cb0ef41Sopenharmony_ci } 641cb0ef41Sopenharmony_ci 651cb0ef41Sopenharmony_ci bufferedEntries.push(entry); 661cb0ef41Sopenharmony_ci if (bufferedEntries.length === 1) { 671cb0ef41Sopenharmony_ci observer.disconnect(); 681cb0ef41Sopenharmony_ci po_nop.disconnect(); 691cb0ef41Sopenharmony_ci for (i = 0; i < bufferedEntries.length; i++) { 701cb0ef41Sopenharmony_ci assert_equals(bufferedEntries[i].entryType, "mark") 711cb0ef41Sopenharmony_ci } 721cb0ef41Sopenharmony_ci t.done(); 731cb0ef41Sopenharmony_ci } 741cb0ef41Sopenharmony_ci }); 751cb0ef41Sopenharmony_ci }).observe({ 761cb0ef41Sopenharmony_ci type: "mark", 771cb0ef41Sopenharmony_ci buffered: true 781cb0ef41Sopenharmony_ci }); 791cb0ef41Sopenharmony_ci } 801cb0ef41Sopenharmony_ci 811cb0ef41Sopenharmony_ci const entryTypes = ["navigation", "resource", "mark", "measure"]; 821cb0ef41Sopenharmony_ci const observedEntries = []; 831cb0ef41Sopenharmony_ci initTest(); 841cb0ef41Sopenharmony_ci }, "PerformanceObserverInit.buffered should retrieve previously buffered entries"); 851cb0ef41Sopenharmony_ci 861cb0ef41Sopenharmony_ci</script> 87