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 // window.storeCreated is used by the Indexed DB tests.
37 if ((!__install_onload_handler || window.storeCreated) &&
38 !performance.timing.loadEventEnd)
41 var unused = document.body.offsetHeight; // force layout
43 testComplete(window.performance.now());
46 // The function |testComplete| is used by the Indexed DB tests.
47 window.testComplete = function(time) {
48 window.__pc_load_time = time;
51 // The function |__eval_later| now is only used by the DHTML tests.
52 window.__eval_later = function(expression) {
53 setTimeout(expression, __test_timeout);
56 if (window.parent == window) { // Ignore subframes.
57 window.__pc_load_time = null;
58 addEventListener("load", __onload);
59 addEventListener("beforeunload", __onbeforeunload);