Infobar material design refresh: bg color
[chromium-blink-merge.git] / tools / page_cycler / common / head.js
blobdddaa7ee0ac2454a0336334e0fdbc8a056ef986d
1 // Copyright (c) 2012 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.
5 var __c = ""; // that's good enough for me.
6 var __td;
7 var __tf;
8 var __tl;
9 var __iterations;
10 var __cycle;
11 var __results = false;
12 var __page;
13 var __TIMEOUT = 15;
14 function __get_cookie(name) {
15 var cookies = document.cookie.split("; ");
16 for (var i = 0; i < cookies.length; ++i) {
17 var t = cookies[i].split("=");
18 if (t[0] == name && t[1])
19 return t[1];
21 return "";
23 function __pages() { // fetch lazily
24 if (!("data" in this))
25 this.data = __get_cookie("__pc_pages").split(",");
26 return this.data;
28 function __get_timings() {
29 if (sessionStorage != null &&
30 sessionStorage.getItem("__pc_timings") != null) {
31 return sessionStorage["__pc_timings"];
32 } else {
33 return __get_cookie("__pc_timings");
36 function __set_timings(timings) {
37 if (sessionStorage == null)
38 document.cookie = "__pc_timings=" + timings + "; path=/";
39 else
40 sessionStorage["__pc_timings"]=timings;
42 function __ontimeout() {
43 var doc;
45 // Call GC twice to cleanup JS heap before starting a new test.
46 if (window.gc) {
47 window.gc();
48 window.gc();
51 var timings = __tl;
52 var oldTimings = __get_timings();
53 if (oldTimings != "") {
54 timings = oldTimings + "," + timings;
56 __set_timings(timings);
58 var ts = (new Date()).getTime();
59 var tlag = (ts - __te) - __TIMEOUT;
60 if (tlag > 0)
61 __tf = __tf + tlag;
62 if (__cycle == (__pages().length * __iterations)) {
63 document.cookie = "__pc_done=1; path=/";
64 doc = "../../common/report.html";
65 if (window.console) {
66 console.log("Pages: [" + __get_cookie('__pc_pages') + "]");
67 console.log("times: [" + __get_timings() + "]");
69 } else {
70 doc = "../" + __pages()[__page] + "/index.html";
73 var url = doc + "?n=" + __iterations + "&i=" + __cycle + "&p=" + __page +
74 "&ts=" + ts + "&td=" + __td + "&tf=" + __tf;
75 document.location.href = url;
77 function __onload() {
78 if (__results) {
79 // Set a variable to indicate that the result report page is loaded.
80 document.cookie = "__navigated_to_report=1; path=/";
81 return;
83 var unused = document.body.offsetHeight; // force layout
85 var ts = 0, td = 0, te = (new Date()).getTime(), tf = 0;
87 var s = document.location.search;
88 if (s) {
89 var params = s.substring(1).split('&');
90 for (var i = 0; i < params.length; ++i) {
91 var f = params[i].split('=');
92 switch (f[0]) {
93 case 'skip':
94 // No calculation, just viewing
95 return;
96 case 'n':
97 __iterations = f[1];
98 break;
99 case 'i':
100 __cycle = (f[1] - 0) + 1;
101 break;
102 case 'p':
103 __page = ((f[1] - 0) + 1) % __pages().length;
104 break;
105 case 'ts':
106 ts = (f[1] - 0);
107 break;
108 case 'td':
109 td = (f[1] - 0);
110 break;
111 case 'tf':
112 tf = (f[1] - 0);
113 break;
117 __tl = (te - ts);
118 __td = td + __tl;
119 __te = te;
120 __tf = tf; // record t-fudge
122 setTimeout("__ontimeout()", __TIMEOUT);
125 if (window.attachEvent)
126 window.attachEvent("onload", __onload);
127 else
128 addEventListener("load", __onload, false);