nav2-test-timing-persistent.html (4202B)
1 <!DOCTYPE HTML> 2 <html> 3 4 <head> 5 <meta charset=utf-8> 6 <title>PerformanceNavigationTiming timing remains after iframe removed</title> 7 <script src="/resources/testharness.js"></script> 8 <script src="/resources/testharnessreport.js"></script> 9 <script src="/common/get-host-info.sub.js"></script> 10 </head> 11 12 <body> 13 <script> 14 const start_page = "/navigation-timing/resources/blank_page_green.html"; 15 const end_page = "/navigation-timing/resources/blank_page_yellow.html"; 16 const host_info = get_host_info(); 17 18 const same_origin_redirect_chain = () => { 19 let url = host_info["ORIGIN"]; 20 url += "/common/redirect.py"; 21 url += "?location="; 22 url += host_info["ORIGIN"]; 23 url += end_page; 24 return url; 25 }; 26 27 const timingAttributes = [ 28 'domComplete', 29 'domContentLoadedEventEnd', 30 'domContentLoadedEventStart', 31 'domInteractive', 32 //'criticalCHRestart' is not supported in iframe. 33 'unloadEventStart', 34 'unloadEventEnd', 35 'loadEventStart', 36 'loadEventEnd', 37 'redirectCount', 38 'redirectStart', 39 'redirectEnd', 40 'fetchStart', 41 'responseEnd', 42 ]; 43 44 function verify_timing(pnt, description) { 45 for (const att of timingAttributes) { 46 assert_greater_than(pnt[att], 0, `${description} ${att}`); 47 } 48 } 49 50 promise_test(async function (t) { 51 const iframe = document.createElement("iframe"); 52 document.body.appendChild(iframe); 53 54 // Navigate from one location to another, then redirect. As a result, the tested fields contain non-zero values. 55 await new Promise(resolve => { 56 iframe.onload = function () { 57 step_timeout(() => { iframe.contentWindow.location.href = same_origin_redirect_chain(); }, 10); 58 iframe.onload = resolve; 59 } 60 iframe.src = start_page; 61 }); 62 63 await new Promise(resolve => { 64 const entries = iframe.contentWindow.performance.getEntriesByType("navigation"); 65 assert_equals(entries.length, 1, "Only one navigation time entry"); 66 const pnt = entries[0]; 67 assert_equals(pnt.name, iframe.contentWindow.location.toString(), "navigation name matches the window.location"); 68 assert_true(pnt.name.endsWith("blank_page_yellow.html"), "navigation name is blank_page_yellow.html"); 69 verify_timing(pnt, "timing values should be positive numbers:") 70 iframe.remove(); 71 verify_timing(pnt, "timing values should remain positive numbers after iframe is removed:") 72 resolve(); 73 }) 74 }, "iframe navigation times are persistent after the iframe is removed. Part 1."); 75 76 function getOutOfLoadEventHandler(t) { 77 return new Promise(resolve => t.step_timeout(resolve, 0)); 78 } 79 80 function waitForLoad(obj) { 81 return new Promise(resolve => { 82 obj.addEventListener("load", resolve, { once: true }); 83 }); 84 } 85 86 // 'type' entry should be persistent. 87 promise_test(async function (t) { 88 const iframe = document.createElement("iframe"); 89 document.body.appendChild(iframe); 90 91 iframe.src = start_page; 92 await waitForLoad(iframe); 93 await getOutOfLoadEventHandler(t); 94 iframe.contentWindow.location.href = end_page; 95 await waitForLoad(iframe); 96 97 iframe.contentWindow.history.back(); 98 await waitForLoad(iframe); 99 100 await new Promise(resolve => { 101 const entries = iframe.contentWindow.performance.getEntriesByType("navigation"); 102 assert_equals(entries.length, 1, "Only one navigation time entry"); 103 const pnt = entries[0]; 104 assert_equals(pnt.name, iframe.contentWindow.location.toString(), "navigation name matches the window.location"); 105 assert_true(pnt.name.endsWith("blank_page_green.html"), "navigation name is blank_page_green.html"); 106 assert_equals(pnt.type, "back_forward", "type should be back_forward after going back to history"); 107 iframe.remove(); 108 assert_equals(pnt.type, "back_forward", "type should remain back_forward after iframe is removed"); 109 resolve(); 110 }) 111 }, "iframe navigation times are persistent after the iframe is removed Part 2."); 112 113 </script> 114 </body> 115 116 </html>