test-document-open.html (2592B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="utf-8" /> 5 <title>window.performance.timing for dynamically created documents</title> 6 <link rel="author" title="Microsoft" href="http://www.microsoft.com/" /> 7 <link rel="help" href="http://www.w3.org/TR/navigation-timing/#sec-navigation-timing-interface"/> 8 <script src="/resources/testharness.js"></script> 9 <script src="/resources/testharnessreport.js"></script> 10 <script src="/common/performance-timeline-utils.js"></script> 11 <script src="resources/webperftestharness.js"></script> 12 <script> 13 setup({explicit_done: true}); 14 15 // explicitly test the namespace before we start testing 16 test_namespace(); 17 18 var originalTiming = {}; 19 var didOpen = false; 20 21 function onload_test() { 22 if (!didOpen) { 23 step_timeout(testTimingWithDocumentOpen, 0); 24 didOpen = true; 25 } 26 } 27 28 function testTimingWithDocumentOpen() { 29 var subcontentWindow = document.getElementById("frameContext").contentWindow; 30 31 if (subcontentWindow.performance === undefined) 32 { 33 // avoid script errors 34 done(); 35 return; 36 } 37 38 var timing = subcontentWindow.performance.timing; 39 for (i in timingAttributes) { 40 originalTiming[timingAttributes[i]] = timing[timingAttributes[i]]; 41 } 42 43 var subdocument = subcontentWindow.document; 44 subdocument.open(); 45 subdocument.write('<!DOCTYPE HTML>'); 46 subdocument.write('<html>'); 47 subdocument.write('<head>'); 48 subdocument.write('<meta charset="utf-8" />'); 49 subdocument.write('<title><Green Test Page</title>'); 50 subdocument.write('</head>'); 51 subdocument.write('<body style="background-color:#00FF00;">'); 52 subdocument.write('</body>'); 53 subdocument.write('</html>'); 54 subdocument.close(); 55 56 step_timeout(function() { 57 var timing = subcontentWindow.performance.timing; 58 for (var i in timingAttributes) { 59 test_equals(timing[timingAttributes[i]], 60 originalTiming[timingAttributes[i]], 61 timingAttributes[i] + " is the same after document open."); 62 } 63 done(); 64 }, 0); 65 } 66 </script> 67 </head> 68 <body> 69 <h1>Description</h1> 70 <p>This test validates window.performance.timing remains constant when a 71 document is replaced using document.open.</p> 72 73 <p>This page should be loaded with a yellow frame below. It then replaces the 74 document in that frame with a green document.</p> 75 76 <p>The test passes if all of the checks to performance.timing are correct and 77 the frame below ends with a green background.</p> 78 79 <div id="log"></div> 80 <br /> 81 <iframe id="frameContext" onload="onload_test();" src="resources/blank_page_yellow.html" style="width: 250px; height: 250px;"></iframe> 82 </body> 83 </html>