nav2-test-attributes-values.html (5949B)
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 <h1>Description</h1> 14 <p>This test validates that the values of nav timing 2 instance's timing-related attributes are in certain order and the others are of expected values.</p> 15 16 <script> 17 // Host names and ports may be configured at test execution time. The 18 // web-platform-tests server offers two mechanisms for retrieving these 19 // values dynamically: direct text substitution and the `get-host-info` 20 // script. The former is inapproprate for this test because it 21 // influences the size of the document, and this test includes static 22 // assertions for that value. 23 var host_info = get_host_info(); 24 var expectedUrl = "http://" + host_info.ORIGINAL_HOST + ":" + 25 host_info.HTTP_PORT + 26 "/navigation-timing/nav2-test-attributes-values.html"; 27 var navTiming2EventOrder1 = [ 28 'startTime', 29 'redirectStart', 30 //'unloadEventStart', 31 'redirectEnd', 32 //'unloadEventEnd', 33 'fetchStart', 34 'domainLookupStart', 35 'domainLookupEnd', 36 'connectStart', 37 //'secureConnectionStart', 38 'connectEnd', 39 'requestStart', 40 'responseStart', 41 'responseEnd', 42 'domInteractive', 43 'domContentLoadedEventStart', 44 'domContentLoadedEventEnd', 45 'domComplete', 46 'loadEventStart', 47 'loadEventEnd' 48 ]; 49 50 var navTiming2EventOrder2 = [ 51 'redirectStart', 52 'unloadEventStart', 53 'redirectEnd', 54 'unloadEventEnd', 55 'fetchStart' 56 ]; 57 58 var navTiming2EventOrder3 = [ 59 'connectStart', 60 'secureConnectionStart', 61 'connectEnd' 62 ]; 63 64 // Navigation Timing attributes for comparison. 65 var navTiming1EventOrder = [ 66 'fetchStart', 67 'domainLookupStart', 68 'domainLookupEnd', 69 'connectStart', 70 'connectEnd', 71 'requestStart', 72 'responseStart', 73 'responseEnd', 74 'domInteractive', 75 'domContentLoadedEventStart', 76 'domContentLoadedEventEnd', 77 'domComplete', 78 'loadEventStart', 79 'loadEventEnd' 80 ]; 81 82 function verifyTimingEventOrder(eventOrder, timingEntry) { 83 for (var i = 0; i < eventOrder.length - 1; i++) { 84 assert_true(timingEntry[eventOrder[i]] <= timingEntry[eventOrder[i + 1]], 85 "Expected " + eventOrder[i] + " to be no greater than " + eventOrder[i + 1] + "."); 86 } 87 } 88 89 async_test(function (t) { 90 var observer = new PerformanceObserver( 91 t.step_func(function (entryList) { 92 var entries = entryList.getEntries(); 93 assert_equals(entries[0].entryType, "navigation", 94 "Expected entryType to be: navigation."); 95 assert_equals(entries[0].name, expectedUrl); 96 assert_equals(entries[0].startTime, 0, 97 "Expected startTime to be: 0."); 98 assert_equals(entries[0].duration, entries[0].loadEventEnd, 99 "Expected duration to be equal to loadEventEnd."); 100 assert_equals(entries[0].initiatorType, "navigation", 101 "Expected initiatorType to be: navigation."); 102 assert_equals(entries[0].nextHopProtocol, "http/1.1"); 103 // This test may fail when response is from cach. Disable or clean cach before 104 // running this test. 105 assert_true(entries[0].transferSize > entries[0].encodedBodySize, 106 "Expected transferSize to be greater than encodedBodySize in uncached navigation."); 107 assert_equals(entries[0].encodedBodySize, 5949); 108 assert_equals(entries[0].decodedBodySize, 5949); 109 verifyTimingEventOrder(entries[0], navTiming2EventOrder1); 110 // Verify if the reported timing is not that different 111 // from what is reported by Navigation Timing 1. 112 navTiming1EventOrder.forEach( 113 function(event) { 114 if (window.performance.timing[event] - 115 window.performance.timing.navigationStart > 0) { 116 assert_greater_than(entries[0][event], 0, 117 "Expected " + event + " to be greater than 0"); 118 } 119 }); 120 // When unloadEvent happens 121 if (entries[0]["unloadEventStart"] != 0) { 122 verifyTimingEventOrder(entries[0], navTiming2EventOrder2); 123 } 124 // When a secure transport is used 125 if (entries[0]["secureConnectionStart"] != 0) { 126 verifyTimingEventOrder(entries[0], navTiming2EventOrder3); 127 } 128 observer.disconnect(); 129 t.done(); 130 }) 131 ); 132 observer.observe({entryTypes: ["navigation"]}); 133 134 }, "Performance navigation timing instance's value is reasonable."); 135 </script> 136 </body> 137 </html>