unload-event-same-origin-check.html (6985B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="utf-8" /> 5 <title>Navigation Timing 2 WPT</title> 6 <link rel="author" title="Google" href="http://www.google.com/" /> 7 <link rel="help" href="http://www.w3.org/TR/navigation-timing-2/#sec-PerformanceNavigationTiming"/> 8 <script src="/resources/testharness.js"></script> 9 <script src="/resources/testharnessreport.js"></script> 10 <script src="/common/get-host-info.sub.js"></script> 11 </head> 12 <body> 13 <script> 14 15 const start_page = "/navigation-timing/resources/blank_page_green.html"; 16 const end_page = "/navigation-timing/resources/blank_page_yellow.html"; 17 const host_info = get_host_info(); 18 const redirect_chain_partial_tao = () => { 19 let url = host_info["HTTP_REMOTE_ORIGIN"]; 20 url += "/common/redirect.py"; 21 url += "?location="; 22 url += host_info["HTTP_REMOTE_ORIGIN"]; 23 url += "/common/redirect-opt-in.py"; 24 url += "?location="; 25 url += host_info["ORIGIN"]; 26 url += end_page; 27 return url; 28 }; 29 const redirect_chain_full_tao = () => { 30 let url = host_info["HTTP_REMOTE_ORIGIN"]; 31 url += "/common/redirect-opt-in.py"; 32 url += "?location="; 33 url += host_info["ORIGIN"]; 34 url += end_page; 35 return url; 36 }; 37 const redirect_chain_no_tao = () => { 38 let url = host_info["HTTP_REMOTE_ORIGIN"]; 39 url += "/common/redirect.py"; 40 url += "?location="; 41 url += host_info["ORIGIN"]; 42 url += end_page; 43 return url; 44 }; 45 const same_origin_redirect_chain = () => { 46 let url = host_info["ORIGIN"]; 47 url += "/common/redirect.py"; 48 url += "?location="; 49 url += host_info["ORIGIN"]; 50 url += end_page; 51 return url; 52 }; 53 const cross_origin_start = host_info["HTTP_REMOTE_ORIGIN"] + start_page; 54 const test_cases = [ 55 { start_url : start_page, end_url: redirect_chain_partial_tao(), unload_exposed: false, redirects: 0, name: "Redirect chain with a partial TAO opt-in" }, 56 { start_url : start_page, end_url: redirect_chain_full_tao(), unload_exposed: false, redirects: 0, name: "Redirect chain with full TAO opt-in" }, 57 { start_url : start_page, end_url: redirect_chain_no_tao(), unload_exposed: false, redirects: 0, name: "Same-cross-same redirect chain with no TAO opt-in" }, 58 { start_url : cross_origin_start, end_url: redirect_chain_no_tao(), unload_exposed: false, redirects: 0, name: "cross-cross-same Redirect chain with no TAO opt-in" }, 59 { start_url : cross_origin_start, end_url: end_page, unload_exposed: false, redirects: 0, name: "Previous document cross origin" }, 60 { start_url : start_page, end_url: end_page, unload_exposed: true, redirects: 0, name: "Previous document same origin" }, 61 { start_url : start_page, end_url: null, unload_exposed: false, redirects: 0, name: "No previous document" }, 62 { start_url : start_page, end_url: same_origin_redirect_chain(), unload_exposed: true, redirects: 1, name: "Same origin previous document with same origin redirect" }, 63 { start_url : same_origin_redirect_chain(), end_url: null, unload_exposed: false, redirects: 1, name: "No previous document with same origin redirect" }, 64 { start_url : redirect_chain_no_tao(), end_url: null, unload_exposed: false, redirects: 0, name: "No previous document with cross origin redirect" }, 65 { start_url : redirect_chain_full_tao(), end_url: null, unload_exposed: false, redirects: 0, name: "No previous document with cross origin redirect with partial TAO" }, 66 { start_url : redirect_chain_partial_tao(), end_url: null, unload_exposed: false, redirects: 0, name: "No previous document with cross origin redirect with TAO" }, 67 ]; 68 69 const frame_id = "frameContext"; 70 const create_frame = (start_url, end_url) => { 71 return new Promise(resolve => { 72 let frame = document.getElementById("frameContext"); 73 if (frame) { 74 document.body.removeChild(frame); 75 } 76 frame = document.createElement("iframe"); 77 frame.onload = () => { 78 if (end_url) { 79 frame.onload = resolve; 80 step_timeout(() => {frame.contentWindow.location.href = end_url;}, 10); 81 } else { 82 resolve(); 83 } 84 }; 85 frame.id = "frameContext"; 86 frame.src = start_url; 87 document.body.appendChild(frame); 88 }); 89 }; 90 91 const run_test = (unload_exposed, redirects) => { 92 const entry = document.getElementById("frameContext").contentWindow.performance.getEntriesByType("navigation")[0]; 93 assert_equals(entry.type, "navigate", "Expected navigation type to be navigate."); 94 if (!unload_exposed) { 95 assert_equals(entry.unloadEventStart, 0, "Expected unloadEventStart to be 0."); 96 assert_equals(entry.unloadEventEnd, 0, "Expected unloadEventEnd to be 0."); 97 } else { 98 assert_greater_than(entry.unloadEventStart, 0, "Expected unloadEventStart to not be 0."); 99 assert_greater_than(entry.unloadEventEnd, 0, "Expected unloadEventEnd to not be 0."); 100 } 101 assert_equals(entry.redirectCount, redirects, "Expected redirectCount to be " + redirects); 102 }; 103 104 const create_test = async test_case => { 105 return new Promise(async (resolve, reject) => { 106 await create_frame(test_case.start_url, test_case.end_url); 107 try { 108 run_test(test_case.unload_exposed, test_case.redirects); 109 resolve(); 110 } catch (e) { 111 reject(e); 112 } 113 }); 114 }; 115 116 for (const test_case of test_cases) { 117 promise_test(() => { return create_test(test_case)}, test_case.name); 118 } 119 120 121 </script> 122 <h1>Description</h1> 123 <p>This test validates that the values of window.performance.getEntriesByType("navigation")[0].(type/unloadEventEnd/unloadEventStart) are only exposed when the same-origin test passes.</p> 124 </body> 125 </html>