test-timing-attributes-dependent-on-document-load.html (3224B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="utf-8" /> 5 <title>Navigation Timing 2 WPT</title> 6 <script src="/resources/testharness.js"></script> 7 <script src="/resources/testharnessreport.js"></script> 8 <script> 9 setup({ single_test: true }); 10 var reload_frame; 11 12 // Array of navigation timing entries dependent on Document Load Timing. 13 var navTimingAttributes = [ 14 'fetchStart', 15 'loadEventEnd', 16 'loadEventStart', 17 'redirectCount', 18 'redirectEnd', 19 'redirectStart', 20 'responseEnd', 21 'unloadEventEnd', 22 'unloadEventStart', 23 ]; 24 25 // Function to run the test when the page loads. 26 function onload_test() { 27 reload_frame = document.getElementById("frameContext"); 28 reload_frame.onload = function() { 29 step_timeout(do_test, 0); 30 } 31 step_timeout(reload_the_frame, 0); 32 } 33 34 /* 35 Function to reload the iframe and observe values for navigation timing entries: 36 redirectStart, redirectEnd and redirectCount dependent on Document Load Timing. 37 */ 38 function reload_the_frame() { 39 reload_frame.contentWindow.location.href = 40 "/common/redirect.py?location=/navigation-timing/resources/blank-page-green.html"; 41 } 42 43 /* 44 Function to obtain navigation timing entries and, 45 check if the values are greater than 0. 46 */ 47 function do_test() { 48 var nav_frame = document.getElementById("frameContext").contentWindow; 49 var pnt1 = nav_frame.performance.getEntriesByType("navigation")[0]; 50 for (i in navTimingAttributes) { 51 assert_greater_than(pnt1[navTimingAttributes[i]], 0, 52 `Expected navigation timing entries: ${navTimingAttributes[i]} greater than 0`); 53 } 54 step_timeout(remove, 0); 55 done(); // Avoids scripting errors 56 } 57 58 /* 59 Function to remove the iframe from the parent body and, 60 check if the navigation timing entries of detached iframe are 0. 61 */ 62 function remove() { 63 var nav_frame = document.getElementById("frameContext").contentWindow; 64 var pnt1 = nav_frame.performance.getEntriesByType("navigation")[0]; 65 document.body.removeChild(document.getElementById("frameContext")); 66 for (i in navTimingAttributes) { 67 assert_equals(pnt1[navTimingAttributes[i]], 0, 68 `${navTimingAttributes[i]} dependent on Document Load Timing: returns 0`); 69 } 70 } 71 </script> 72 </head> 73 <body onload="onload_test();"> 74 <h1>Description</h1> 75 <p>This test observes values of navigation timing entries,</p> 76 <p>dependent on Document Load Timing for a detached iframe.</p> 77 <br /> 78 <p>This page should be loaded with a green background frame below,</p> 79 <p>which disappears after the iframe is detached.</p> 80 <br /> 81 <iframe id="frameContext" 82 src="/navigation-timing/resources/blank-page-green.html" 83 style="width: 250px; height: 250px;"></iframe> 84 </body> 85 </html>