OLD | NEW |
(Empty) | |
| 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 __set_cookie("__pc_load_time", ""); |
| 34 } |
| 35 |
| 36 // The function |__onload| is used by the DHTML tests. |
| 37 window.__onload = function() { |
| 38 // window.storeCreated is used by the Indexed DB tests. |
| 39 if ((!__install_onload_handler || window.storeCreated) && |
| 40 !performance.timing.loadEventEnd) |
| 41 return; |
| 42 |
| 43 var unused = document.body.offsetHeight; // force layout |
| 44 |
| 45 __set_cookie("__pc_load_time", window.performance.now()); |
| 46 }; |
| 47 |
| 48 // The function |testComplete| is used by the Indexed DB tests. |
| 49 window.testComplete = __onload; |
| 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 addEventListener("load", __onload); |
| 58 addEventListener("beforeunload", __onbeforeunload); |
| 59 } |
| 60 })(); |
OLD | NEW |