user-timing-tojson.html (1397B)
1 <!doctype html> 2 <html> 3 <head> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 </head> 7 <body> 8 <script> 9 const keys = [ 10 'name', 11 'entryType', 12 'startTime', 13 'duration', 14 ]; 15 test(() => { 16 performance.mark('a'); 17 const markEntries = performance.getEntriesByType('mark'); 18 assert_equals(1, markEntries.length); 19 const markEntry = markEntries[0]; 20 assert_equals(markEntry.entryType, 'mark'); 21 assert_equals(typeof(markEntry.toJSON), 'function'); 22 const markJSON = markEntry.toJSON(); 23 assert_equals(typeof(markJSON), 'object'); 24 for (const key of keys) { 25 assert_equals(markJSON[key], markEntry[key], `PerformanceMark ${key} entry does not match its toJSON value`); 26 } 27 }, 'Test toJSON() in PerformanceMark'); 28 29 test(() => { 30 performance.measure('m'); 31 const measureEntries = performance.getEntriesByType('measure'); 32 assert_equals(1, measureEntries.length); 33 const measureEntry = measureEntries[0]; 34 assert_equals(measureEntry.entryType, 'measure'); 35 assert_equals(typeof(measureEntry.toJSON), 'function'); 36 const measureJSON = measureEntry.toJSON(); 37 assert_equals(typeof(measureJSON), 'object'); 38 for (const key of keys) { 39 assert_equals(measureJSON[key], measureEntry[key], `PerformanceMeasure ${key} entry does not match its toJSON value`); 40 } 41 }, 'Test toJSON() in PerformanceMeasure'); 42 </script> 43 </body> 44 </html>