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.
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;
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
20 var __test_timeout = 0;
22 function __set_cookie(name, value) {
23 document.cookie = name + "=" + value + "; path=/";
26 function __onbeforeunload() {
27 // Call GC twice to cleanup JS heap before starting a new test.
34 // The function |__onload| is used by the DHTML tests.
35 window.__onload = function() {
36 if (!__install_onload_handler && !performance.timing.loadEventEnd)
39 var unused = document.body.offsetHeight; // force layout
41 window.__pc_load_time = window.performance.now();
44 // The function |__eval_later| now is only used by the DHTML tests.
45 window.__eval_later = function(expression) {
46 setTimeout(expression, __test_timeout);
49 if (window.parent == window) { // Ignore subframes.
50 window.__pc_load_time = null;
51 addEventListener("load", __onload);
52 addEventListener("beforeunload", __onbeforeunload);