1// META: script=performanceobservers.js 2 3 async_test(function (t) { 4 var callbackCount = 0; 5 var observer = new PerformanceObserver( 6 t.step_func(function (entryList, obs) { 7 callbackCount++; 8 9 if (callbackCount === 1) { 10 checkEntries(entryList.getEntries(), [ 11 {entryType: "measure", name: "measure1"}, 12 ]); 13 observer.observe({entryTypes: ["mark"]}); 14 self.performance.mark("mark2"); 15 self.performance.measure("measure2"); 16 return; 17 } 18 19 if (callbackCount === 2) { 20 checkEntries(entryList.getEntries(), [ 21 {entryType: "mark", name: "mark2"}, 22 ]); 23 self.performance.mark("mark-before-change-observe-state-to-measure"); 24 self.performance.measure("measure-before-change-observe-state-to-measure"); 25 observer.observe({entryTypes: ["measure"]}); 26 self.performance.mark("mark3"); 27 self.performance.measure("measure3"); 28 return; 29 } 30 31 if (callbackCount === 3) { 32 checkEntries(entryList.getEntries(), [ 33 {entryType: "measure", name: "measure3"}, 34 {entryType: "mark", name: "mark-before-change-observe-state-to-measure"}, 35 ]); 36 self.performance.mark("mark-before-change-observe-state-to-both"); 37 self.performance.measure("measure-before-change-observe-state-to-both"); 38 observer.observe({entryTypes: ["mark", "measure"]}); 39 self.performance.mark("mark4"); 40 self.performance.measure("measure4"); 41 return; 42 } 43 44 if (callbackCount === 4) { 45 checkEntries(entryList.getEntries(), [ 46 {entryType: "measure", name: "measure-before-change-observe-state-to-both"}, 47 {entryType: "measure", name: "measure4"}, 48 {entryType: "mark", name: "mark4"}, 49 ]); 50 self.performance.mark("mark-before-disconnect"); 51 self.performance.measure("measure-before-disconnect"); 52 observer.disconnect(); 53 self.performance.mark("mark-after-disconnect"); 54 self.performance.measure("measure-after-disconnect"); 55 t.done(); 56 return; 57 } 58 59 assert_unreached("The callback must not be invoked after disconnecting"); 60 }) 61 ); 62 63 observer.observe({entryTypes: ["measure"]}); 64 self.performance.mark("mark1"); 65 self.performance.measure("measure1"); 66 }, "PerformanceObserver modifications inside callback should update filtering and not clear buffer"); 67