nav2-test-document-open.html (4200B)
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> 11 setup({ single_test: true }); 12 13 var navTiming2Attributes = [ 14 'connectEnd', 15 'connectStart', 16 'decodedBodySize', 17 'domComplete', 18 'domContentLoadedEventEnd', 19 'domContentLoadedEventStart', 20 'domInteractive', 21 'domainLookupEnd', 22 'domainLookupStart', 23 'duration', 24 'encodedBodySize', 25 'entryType', 26 'fetchStart', 27 'initiatorType', 28 'loadEventEnd', 29 'loadEventStart', 30 'name', 31 'redirectCount', 32 'redirectEnd', 33 'redirectStart', 34 'requestStart', 35 'responseEnd', 36 'responseStart', 37 'secureConnectionStart', 38 'transferSize', 39 'type', 40 'unloadEventEnd', 41 'unloadEventStart', 42 'workerStart' 43 ]; 44 45 var originalTiming = {}; 46 var didOpen = false; 47 48 function onload_test() 49 { 50 if (!didOpen) { 51 setTimeout(testTimingWithDocumentOpen, 0); 52 didOpen = true; 53 } 54 } 55 56 function testTimingWithDocumentOpen() 57 { 58 var subcontentWindow = document.getElementById("frameContext").contentWindow; 59 60 var timing = subcontentWindow.performance.getEntriesByType("navigation")[0]; 61 for (i in navTiming2Attributes) { 62 originalTiming[navTiming2Attributes[i]] = timing[navTiming2Attributes[i]]; 63 } 64 65 var subdocument = subcontentWindow.document; 66 subdocument.open(); 67 subdocument.write('<!DOCTYPE HTML>'); 68 subdocument.write('<html>'); 69 subdocument.write('<head>'); 70 subdocument.write('<meta charset="utf-8" />'); 71 subdocument.write('<title><Green Test Page</title>'); 72 subdocument.write('</head>'); 73 subdocument.write('<body style="background-color:#00FF00;">'); 74 subdocument.write('</body>'); 75 subdocument.write('</html>'); 76 subdocument.close(); 77 78 setTimeout(function() { 79 var timing = subcontentWindow.performance.getEntriesByType("navigation")[0]; 80 for (var i in navTiming2Attributes) { 81 assert_equals(originalTiming[navTiming2Attributes[i]], timing[navTiming2Attributes[i]], 82 navTiming2Attributes[i] + " is the same after document open."); 83 } 84 done(); 85 }, 0); 86 } 87 </script> 88 </head> 89 <body> 90 <h1>Description</h1> 91 <p>This test validates window.performance.getEntriesByType("navigation") remains constant when a 92 document is replaced using document.open.</p> 93 94 <p>This page should be loaded with a yellow frame below. It then replaces the 95 document in that frame with a green document.</p> 96 97 <p>The test passes if all of the checks to performance.getEntriesByType("navigation") are correct and 98 the frame below ends with a green background.</p> 99 100 <iframe id="frameContext" onload="onload_test();" src="resources/blank_page_yellow.html" style="width: 250px; height: 250px;"></iframe> 101 </body> 102 </html>