navigation_timing.html (2546B)
1 <!-- 2 Any copyright is dedicated to the Public Domain. 3 http://creativecommons.org/publicdomain/zero/1.0/ 4 --> 5 6 <!DOCTYPE html> 7 <html> 8 <head> 9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 10 <script type="application/javascript"> 11 12 var timingParams = [ 13 "navigationStart", 14 "unloadEventStart", 15 "unloadEventEnd", 16 "redirectStart", 17 "redirectEnd", 18 "fetchStart", 19 "domainLookupStart", 20 "domainLookupEnd", 21 "connectStart", 22 "connectEnd", 23 "requestStart", 24 "responseStart", 25 "responseEnd", 26 "domLoading", 27 "domInteractive", 28 "domContentLoadedEventStart", 29 "domContentLoadedEventEnd", 30 "domComplete", 31 "loadEventStart", 32 "loadEventEnd" 33 ]; 34 35 function is(received, expected, message) { 36 window.opener.is(received, expected, message); 37 } 38 39 function isnot(received, notExpected, message) { 40 window.opener.isnot(received, notExpected, message); 41 } 42 43 window.onload = function() { 44 if (location.href.includes("_blank")) { 45 test_blank(); 46 return; 47 } 48 49 if (location.href.includes("_self")) { 50 test_self(); 51 } 52 } 53 54 function checkTimingValues(expectedValues) { 55 for (var name of timingParams) { 56 if (name in expectedValues) { 57 is(window.performance.timing[name], expectedValues[name], name+" should be "+expectedValues[name]); 58 } else { 59 isnot(window.performance.timing[name], 0, name+" should not be 0"); 60 } 61 } 62 } 63 64 function test_blank() { 65 // We set a timeout to make sure this is run after onload is called 66 setTimeout(function(){ 67 // When loading the page in _blank, unloadEvent and redirect timestamps should be 0 68 var expectedValues = { "unloadEventStart": 0, "unloadEventEnd": 0, "redirectStart": 0, "redirectEnd": 0 }; 69 checkTimingValues(expectedValues); 70 71 // change location in order to test a _self load 72 window.location.href = "navigation_timing.html?x=1#_self"; 73 }, 0); 74 } 75 76 function test_self() { 77 // We set a timeout to make sure this is run after onload is called 78 setTimeout(function(){ 79 // When simply loading in _self, redirect timestamps should be 0 (unloadEventStart/End != 0) 80 var expectedValues = { "redirectStart": 0, "redirectEnd": 0 }; 81 checkTimingValues(expectedValues); 82 83 window.opener.finishTests(); 84 }, 0); 85 } 86 87 </script> 88 89 </script> 90 </head> 91 <body> 92 <a target="_blank" 93 href="https://bugzilla.mozilla.org/show_bug.cgi?id=1099092" 94 title="Navigation timing"> 95 Bug #1099092 - Navigation Timing has incorrect values when page is load via link with target=_blank attribute 96 </a> 97 <p id="display"></p> 98 </body> 99 </html>