toJSON.html (1568B)
1 <!DOCTYPE HTML> 2 <meta charset=utf-8> 3 <title>Element Timing: toJSON</title> 4 <body> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 <script src="resources/element-timing-helpers.js"></script> 8 <img elementtiming='img' src="resources/square100.png"/> 9 <script> 10 async_test(function (t) { 11 assert_implements(window.PerformanceElementTiming, "PerformanceElementTiming is not implemented"); 12 const observer = new PerformanceObserver( 13 t.step_func_done(function(entryList) { 14 assert_equals(entryList.getEntries().length, 1); 15 const entry = entryList.getEntries()[0]; 16 assert_equals(typeof(entry.toJSON), 'function'); 17 const json = entry.toJSON(); 18 assert_equals(typeof(json), 'object'); 19 const keys = [ 20 // PerformanceEntry 21 'name', 22 'entryType', 23 'startTime', 24 'duration', 25 // PerformanceElementTiming 26 'renderTime', 27 'loadTime', 28 'intersectionRect', 29 'identifier', 30 'naturalWidth', 31 'naturalHeight', 32 'id', 33 'url', 34 ]; 35 for (const key of keys) { 36 assert_equals(json[key], entry[key], 37 'PerformanceElementTiming ${key} entry does not match its toJSON value'); 38 } 39 assert_equals(json['element'], undefined, 'toJSON should not include element'); 40 }) 41 ); 42 observer.observe({type: 'element', buffered: true}); 43 }, 'Test toJSON() in PerformanceElementTiming.'); 44 </script> 45 </body>