5 new PerformanceObserver();
7 "PerformanceObserver constructor should throw TypeError if no argument is specified."
11 { name: "TypeError" },
13 new PerformanceObserver({});
15 "PerformanceObserver constructor should throw TypeError if the argument is not a function."
17 }, "Test that PerformanceObserver constructor throws exception");
20 var observer = new PerformanceObserver(() => {});
23 { name: "TypeError" },
27 "observe() should throw TypeError exception if no option specified."
31 { name: "TypeError" },
33 observer.observe({ unsupportedAttribute: "unsupported" });
35 "obsrve() should throw TypeError exception if the option has no 'entryTypes' attribute."
40 observer.observe({ entryTypes: [] }),
41 "observe() should silently ignore empty 'entryTypes' sequence."
45 { name: "TypeError" },
47 observer.observe({ entryTypes: null });
49 "obsrve() should throw TypeError exception if 'entryTypes' attribute is null."
54 observer.observe({ entryTypes: ["invalid"] }),
55 "observe() should silently ignore invalid 'entryTypes' values."
57 }, "Test that PerformanceObserver.observe throws exception");
59 function promiseObserve(test, options) {
60 return new Promise(resolve => {
61 performance.clearMarks();
62 performance.clearMeasures();
64 var observer = new PerformanceObserver(list => resolve(list));
65 observer.observe(options);
66 test.add_cleanup(() => observer.disconnect());
71 var promise = promiseObserve(t, { entryTypes: ["mark", "measure"] });
73 performance.mark("test-start");
74 performance.mark("test-end");
75 performance.measure("test-measure", "test-start", "test-end");
77 return promise.then(list => {
79 list.getEntries().length,
81 "There should be three observed entries."
84 var markEntries = list.getEntries().filter(entry => {
85 return entry.entryType == "mark";
89 performance.getEntriesByType("mark"),
90 "Observed 'mark' entries should equal to entries obtained by getEntriesByType."
93 var measureEntries = list.getEntries().filter(entry => {
94 return entry.entryType == "measure";
98 performance.getEntriesByType("measure"),
99 "Observed 'measure' entries should equal to entries obtained by getEntriesByType."
102 }, "Test for user-timing with PerformanceObserver");
105 var promise = new Promise((resolve, reject) => {
106 performance.clearMarks();
107 performance.clearMeasures();
109 var observer = new PerformanceObserver(list => reject(list));
110 observer.observe({ entryTypes: ["mark", "measure"] });
111 observer.disconnect();
112 t.step_timeout(resolve, 100);
115 performance.mark("test-start");
116 performance.mark("test-end");
117 performance.measure("test-measure", "test-start", "test-end");
121 assert_equals(performance.getEntriesByType("mark").length, 2);
122 assert_equals(performance.getEntriesByType("measure").length, 1);
125 assert_unreached("Observer callback should never be called.");
128 }, "Nothing should be notified after disconnecting observer");
131 var promise = promiseObserve(t, { entryTypes: ["mark"] });
133 performance.mark("test");
135 return promise.then(list => {
137 list.getEntries({ entryType: "mark" }),
138 performance.getEntriesByType("mark"),
139 "getEntries with entryType filter should return correct results."
143 list.getEntries({ name: "test" }),
144 performance.getEntriesByName("test"),
145 "getEntries with name filter should return correct results."
149 list.getEntries({ name: "test", entryType: "mark" }),
150 performance.getEntriesByName("test"),
151 "getEntries with name and entryType filter should return correct results."
155 list.getEntries({ name: "invalid" }),
157 "getEntries with non-existent name filter should return an empty array."
161 list.getEntries({ name: "test", entryType: "measure" }),
163 "getEntries with name filter and non-existent entryType should return an empty array."
167 list.getEntries({ name: "invalid", entryType: "mark" }),
169 "getEntries with non-existent name and entryType filter should return an empty array."
173 list.getEntries({ initiatorType: "xmlhttprequest" }),
175 "getEntries with initiatorType filter should return an empty array."
178 }, "Test for PerformanceObserverEntryList.getEntries");
181 var promise = promiseObserve(t, { entryTypes: ["mark", "measure"] });
183 performance.mark("test");
184 performance.measure("test-measure", "test", "test");
186 return promise.then(list => {
188 list.getEntriesByType("mark"),
189 performance.getEntriesByType("mark")
192 list.getEntriesByType("measure"),
193 performance.getEntriesByType("measure")
196 }, "Test for PerformanceObserverEntryList.getEntriesByType");
199 var promise = promiseObserve(t, { entryTypes: ["mark", "measure"] });
201 performance.mark("test");
202 performance.measure("test-measure", "test", "test");
204 return promise.then(list => {
206 list.getEntriesByName("test"),
207 performance.getEntriesByName("test")
210 list.getEntriesByName("test-measure"),
211 performance.getEntriesByName("test-measure")
214 }, "Test for PerformanceObserverEntryList.getEntriesByName");
217 var promise = new Promise(resolve => {
218 performance.clearMarks();
219 performance.clearMeasures();
221 var observer = new PerformanceObserver(list => resolve(list));
222 observer.observe({ entryTypes: ["mark", "measure"] });
223 observer.observe({ entryTypes: ["mark", "measure"] });
224 t.add_cleanup(() => observer.disconnect());
227 performance.mark("test-start");
228 performance.mark("test-end");
229 performance.measure("test-measure", "test-start", "test-end");
231 return promise.then(list => {
233 list.getEntries().length,
235 "Observed user timing entries should have only three entries."
238 }, "Test that invoking observe method twice affects nothing");
241 var promise = new Promise(resolve => {
242 performance.clearMarks();
243 performance.clearMeasures();
245 var observer = new PerformanceObserver(list => resolve(list));
246 observer.observe({ entryTypes: ["mark", "measure"] });
247 observer.observe({ entryTypes: ["mark"] });
248 t.add_cleanup(() => observer.disconnect());
251 performance.mark("test-start");
252 performance.mark("test-end");
253 performance.measure("test-measure", "test-start", "test-end");
255 return promise.then(list => {
257 list.getEntries().length,
259 "Observed user timing entries should have only two entries."
262 }, "Test that observing filter is replaced by a new filter");
265 var promise = new Promise(resolve => {
266 performance.clearMarks();
267 performance.clearMeasures();
269 var observer = new PerformanceObserver(list => resolve(list));
270 observer.observe({ entryTypes: ["mark"] });
271 observer.observe({ entryTypes: ["measure"] });
272 t.add_cleanup(() => observer.disconnect());
275 performance.mark("test-start");
276 performance.mark("test-end");
277 performance.measure("test-measure", "test-start", "test-end");
279 return promise.then(list => {
281 list.getEntries().length,
283 "Observed user timing entries should have only 1 entries."
286 }, "Test that observing filter is replaced by a new filter");