1// META: script=performanceobservers.js 2 3 test(function () { 4 const obs = new PerformanceObserver(() => {}); 5 assert_throws_js(TypeError, function () { 6 obs.observe({entryTypes: "mark"}); 7 }); 8 }, "entryTypes must be a sequence or throw a TypeError"); 9 10 test(function () { 11 const obs = new PerformanceObserver(() => {}); 12 obs.observe({entryTypes: []}); 13 }, "Empty sequence entryTypes does not throw an exception."); 14 15 test(function () { 16 const obs = new PerformanceObserver(() => {}); 17 obs.observe({entryTypes: ["this-cannot-match-an-entryType"]}); 18 obs.observe({entryTypes: ["marks","navigate", "resources"]}); 19 }, "Unknown entryTypes do not throw an exception."); 20 21 test(function () { 22 const obs = new PerformanceObserver(() => {}); 23 obs.observe({entryTypes: ["mark","this-cannot-match-an-entryType"]}); 24 obs.observe({entryTypes: ["this-cannot-match-an-entryType","mark"]}); 25 obs.observe({entryTypes: ["mark"], others: true}); 26 }, "Filter unsupported entryType entryType names within the entryTypes sequence"); 27 28 async_test(function (t) { 29 var finish = t.step_func(function () { t.done(); }); 30 var observer = new PerformanceObserver( 31 function (entryList, obs) { 32 var self = this; 33 t.step(function () { 34 assert_true(entryList instanceof PerformanceObserverEntryList, "first callback parameter must be a PerformanceObserverEntryList instance"); 35 assert_true(obs instanceof PerformanceObserver, "second callback parameter must be a PerformanceObserver instance"); 36 assert_equals(observer, self, "observer is the this value"); 37 assert_equals(observer, obs, "observer is second parameter"); 38 assert_equals(self, obs, "this and second parameter are the same"); 39 observer.disconnect(); 40 finish(); 41 }); 42 } 43 ); 44 self.performance.clearMarks(); 45 observer.observe({entryTypes: ["mark"]}); 46 self.performance.mark("mark1"); 47 }, "Check observer callback parameter and this values"); 48 49 async_test(function (t) { 50 var observer = new PerformanceObserver( 51 t.step_func(function (entryList, obs) { 52 checkEntries(entryList.getEntries(), 53 [{ entryType: "measure", name: "measure1"}]); 54 observer.disconnect(); 55 t.done(); 56 }) 57 ); 58 self.performance.clearMarks(); 59 observer.observe({entryTypes: ["mark"]}); 60 observer.observe({entryTypes: ["measure"]}); 61 self.performance.mark("mark1"); 62 self.performance.measure("measure1"); 63 }, "replace observer if already present"); 64