1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 (function() { 6 // The Mozilla DHTML performance tests need to explicitly call a function to 7 // trigger the next page visit, rather than directly using the onload handler. 8 // To meet needs of the DHTML performance tests without forking this head.js 9 // file, use a variable |__install_onload_handler| to indicate whether the 10 // |__onload| handler should be added to onload event listener. 11 // Install |__onload| by default if there is no pre-configuration. 12 if (typeof(__install_onload_handler) == 'undefined') 13 var __install_onload_handler = true; 14 15 // This is the timeout used in setTimeout inside the DHTML tests. Chrome has 16 // a much more accurate timer resolution than other browsers do. This results 17 // in Chrome running these tests much faster than other browsers. In order to 18 // compare Chrome with other browsers on DHTML performance alone, set this 19 // value to ~15. 20 var __test_timeout = 0; 21 22 function __set_cookie(name, value) { 23 document.cookie = name + "=" + value + "; path=/"; 24 } 25 26 function __onbeforeunload() { 27 // Call GC twice to cleanup JS heap before starting a new test. 28 if (window.gc) { 29 window.gc(); 30 window.gc(); 31 } 32 } 33 34 // The function |__onload| is used by the DHTML tests. 35 window.__onload = function() { 36 // window.storeCreated is used by the Indexed DB tests. 37 if ((!__install_onload_handler || window.storeCreated) && 38 !performance.timing.loadEventEnd) 39 return; 40 41 var unused = document.body.offsetHeight; // force layout 42 43 testComplete(window.performance.now()); 44 }; 45 46 // The function |testComplete| is used by the Indexed DB tests. 47 window.testComplete = function(time) { 48 window.__pc_load_time = time; 49 }; 50 51 // The function |__eval_later| now is only used by the DHTML tests. 52 window.__eval_later = function(expression) { 53 setTimeout(expression, __test_timeout); 54 }; 55 56 if (window.parent == window) { // Ignore subframes. 57 window.__pc_load_time = null; 58 addEventListener("load", __onload); 59 addEventListener("beforeunload", __onbeforeunload); 60 } 61 })(); 62