toJSON.html (1485B)
1 <!DOCTYPE HTML> 2 <meta charset=utf-8> 3 <title>Event Timing: toJSON</title> 4 <body> 5 <script src=/resources/testharness.js></script> 6 <script src=/resources/testharnessreport.js></script> 7 <script src=/resources/testdriver.js></script> 8 <script src=/resources/testdriver-vendor.js></script> 9 <script src=resources/event-timing-test-utils.js></script> 10 <button id='button'>Generate a 'click' event</button> 11 <script> 12 async_test(function (t) { 13 assert_implements(window.PerformanceEventTiming, 'Event Timing is not supported.'); 14 const observer = new PerformanceObserver( 15 t.step_func_done(function(entryList) { 16 const entry = entryList.getEntries()[0]; 17 assert_equals(typeof(entry.toJSON), 'function'); 18 const json = entry.toJSON(); 19 assert_equals(typeof(json), 'object'); 20 const keys = [ 21 // PerformanceEntry 22 'name', 23 'entryType', 24 'startTime', 25 'duration', 26 // PerformanceEventTiming 27 'processingStart', 28 'processingEnd', 29 'cancelable', 30 ]; 31 for (const key of keys) { 32 assert_equals(json[key], entry[key], 33 'PerformanceEventTiming ${key} entry does not match its toJSON value'); 34 } 35 assert_equals(json['target'], undefined, 'toJSON should not include target'); 36 }) 37 ); 38 observer.observe({type: 'event'}); 39 clickAndBlockMain('button'); 40 }, 'Test toJSON() in PerformanceEventTiming.'); 41 </script> 42 </body>