performance_timeline_main_test.html (4387B)
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 <meta charset="utf-8"> 10 <link rel="stylesheet" href="/tests/SimpleTest/test.css?performance-timeline-main-test"/> 11 <script type="application/javascript"> 12 13 function ok(cond, message) { 14 window.opener.ok(cond, message) 15 } 16 17 function is(received, expected, message) { 18 window.opener.is(received, expected, message); 19 } 20 21 function isnot(received, notExpected, message) { 22 window.opener.isnot(received, notExpected, message); 23 } 24 25 var receivedBufferFullEvents = 0; 26 window.performance.onresourcetimingbufferfull = () => { 27 receivedBufferFullEvents++; 28 } 29 30 window.onload = () => { 31 // Here, we should have 4 entries (1 css, 3 png) since the image was loaded. 32 var nEntries = window.performance.getEntries().length; 33 ok(nEntries >= 4, "Performance.getEntries() returned wrong number of entries."); 34 35 window.performance.setResourceTimingBufferSize(5); 36 window.performance.mark("test-start"); 37 window.performance.mark("test-end"); 38 39 // The URI should be the address of a resource will be loaded later to be used on getEntriesByName. 40 window.performance.measure("http://mochi.test:8888/tests/dom/tests/mochitest/general/test-data2.json", 41 "test-start", "test-end"); 42 43 is(window.performance.getEntries().length, nEntries + 3, "User Timing APIs should never be affected by setResourceTimingBufferSize."); 44 is(window.performance.getEntriesByType("resource").length, 4, "The number of PerformanceResourceTiming should be 4."); 45 is(window.performance.getEntriesByType("mark").length, 2, "The number of PerformanceMark entries should be 2."); 46 is(window.performance.getEntriesByType("measure").length, 1, "The number of PerformanceMeasure entries should be 1."); 47 48 is(receivedBufferFullEvents, 0, "onresourcetimingbufferfull should never be called."); 49 50 makeXhr("test-data2.json", firstCheck); 51 } 52 53 function makeXhr(aUrl, aCallback) { 54 var xmlhttp = new XMLHttpRequest(); 55 xmlhttp.onload = aCallback; 56 xmlhttp.open("get", aUrl, true); 57 xmlhttp.send(); 58 } 59 60 function firstCheck() { 61 SpecialPowers.executeSoon(() => { 62 is(window.performance.getEntriesByType("resource").length, 5, 63 "The number of PerformanceResourceTiming should be 5."); 64 is(receivedBufferFullEvents, 0, 65 "onresourcetimingbufferfull should not have been called yet."); 66 makeXhr("test-data2.json", secondCheck); 67 }, window); 68 } 69 70 function secondCheck() { 71 SpecialPowers.executeSoon(() => { 72 is(window.performance.getEntriesByType("resource").length, 5, "The number of PerformanceResourceTiming should be 5."); 73 is(receivedBufferFullEvents, 1, "onresourcetimingbufferfull should have been called since the last call."); 74 checkOrder(window.performance.getEntries(), "All PerformanceEntry"); 75 checkOrder(window.performance.getEntriesByType("resource"), "PerformanceResourceTiming"); 76 checkOrder(window.performance.getEntriesByType("mark"), "PerformanceMark"); 77 checkOrder(window.performance.getEntriesByType("measure"), "PerformanceMeasure"); 78 79 is(window.performance.getEntriesByName("http://mochi.test:8888/tests/dom/tests/mochitest/general/test-data2.json").length, 2, "Both PerformanceMeasure and XMLHttpRequest resource should be included."); 80 checkOrder(window.performance.getEntriesByName("http://mochi.test:8888/tests/dom/tests/mochitest/general/test-data2.json"), "Entry with performance.getEntrieByName()"); 81 window.opener.finishTests(); 82 }, window); 83 } 84 85 function checkOrder(entries, name) { 86 for (var i = 0; i < entries.length - 1; i++) { 87 ok(entries[i].startTime <= entries[i + 1].startTime, name + " should be sorted by startTime."); 88 } 89 } 90 91 </script> 92 </head> 93 <body> 94 <a target="_blank" 95 href="https://bugzilla.mozilla.org/show_bug.cgi?id=1158731" 96 title="Buffer for Performance APIs (Resource Timing, User Timing) should be separeted"> 97 Bug #1158731 - Buffer for Performance APIs (Resource Timing, User Timing) should be separeted 98 </a> 99 <p id="display"></p> 100 <div id="content"> 101 <img src="http://mochi.test:8888/tests/image/test/mochitest/over.png"> 102 <object data="http://mochi.test:8888/tests/image/test/mochitest/clear.png" type="image/png"></object> 103 <embed src="http://mochi.test:8888/tests/image/test/mochitest/green.png" type="image/png"/> 104 </div> 105 </body> 106 </html>