paint-timing-mixin-to-json.html (2552B)
1 <!DOCTYPE html> 2 <head> 3 <title>Performance Paint Timing: Check that paintTime/presentationTime are serialized properly with toJSON</title> 4 </head> 5 <body> 6 <script src="resources/utils.js"></script> 7 <script src="/resources/testharness.js"></script> 8 <script src="/resources/testharnessreport.js"></script> 9 <script> 10 setup({"hide_test_state": true}); 11 promise_test(async t => { 12 assert_implements(window.PerformancePaintTiming, "Paint Timing isn't supported."); 13 assert_implements("paintTime" in window.PerformancePaintTiming.prototype, "Paint Timing doesn't expose `paintTime`"); 14 await new Promise(r => window.addEventListener('load', r)); 15 await assertNoFirstContentfulPaint(t); 16 const img = document.createElement('img'); 17 img.src = 'resources/circles.png'; 18 document.body.append(img); 19 const reference_time = performance.now(); 20 const performance_entry_promise = new Promise(resolve => { 21 new PerformanceObserver(entries => { 22 const [entry] = entries.getEntriesByName("first-contentful-paint"); 23 if (entry) 24 resolve(entry); 25 }).observe({type: "paint"}); 26 }); 27 const entry = await performance_entry_promise; 28 assert_greater_than(entry.paintTime, reference_time); 29 if ("presentationTime" in entry && entry.presentationTime !== null) { 30 assert_greater_than(entry.presentationTime, entry.paintTime); 31 assert_equals(entry.presentationTime, entry.startTime); 32 } else { 33 assert_equals(entry.paintTime, entry.startTime); 34 } 35 36 const json = entry.toJSON(); 37 assert_equals(typeof json, 'object'); 38 // Check that basic PerformanceEntry attributes are serialized. 39 assert_equals(json.name, entry.name, 40 'PerformanceEventTiming "name" attribute does not match its toJSON value'); 41 // Check that the PaintTimingMixin attributes are serialized. 42 assert_equals(json.paintTime, entry.paintTime, 43 'PerformanceEventTiming "paintTime" attribute does not match its toJSON value'); 44 assert_equals(json.presentationTime, entry.presentationTime, 45 'PerformanceEventTiming "presentationTime" attribute does not match its toJSON value'); 46 if ("presentationTime" in entry && entry.presentationTime !== null) { 47 assert_greater_than(json.presentationTime, json.paintTime); 48 assert_equals(json.presentationTime, json.startTime); 49 } else { 50 assert_equals(json.paintTime, json.startTime); 51 } 52 53 }, "Paint timing entries should serialize paintTime and presentationTime with toJSON"); 54 </script> 55 </body> 56 </html>