Home | History | Annotate | Download | only in extension
      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.
      4 
      5 // Returns the sum of all values in the array.
      6 Array.sum = function(array) {
      7   var sum = 0;
      8   for (var i = array.length - 1; i >= 0; i--) {
      9     sum += array[i];
     10   }
     11   return sum;
     12 };
     13 
     14 
     15 function WriteReport(sessionLoader) {
     16   var iterations = window.iterations;
     17   var reportUrl = window.benchmarkConfiguration.reportUrl;
     18   var resultsCollection = sessionLoader.getResultsCollection();
     19   var times = resultsCollection.getTotalTimes();
     20   var pages = resultsCollection.getPages();
     21 
     22   reportUrl += "?n=" + iterations;
     23   reportUrl += "&i=" + iterations * pages.length;  // "cycles"
     24   reportUrl += "&td=" + Array.sum(times);  // total time
     25   reportUrl += "&tf=" + 0;  // fudge time
     26   console.log('reportUrl: ' + reportUrl);
     27   chrome.cookies.set({
     28     "url": reportUrl,
     29     "name": "__pc_done",
     30     "value": "1",
     31     "path": "/",
     32   });
     33   chrome.cookies.set({
     34     "url": reportUrl,
     35     "name": "__pc_pages",
     36     "value": pages.map(function(x) {
     37       return x.replace(/=/g, "%3D");
     38     }).join(","),
     39     "path": "/",
     40   });
     41   chrome.cookies.set({
     42     "url": reportUrl,
     43     "name": "__pc_timings",
     44     "value": times.join(","),
     45     "path": "/",
     46   });
     47 
     48   chrome.tabs.getSelected(null, function(tab) {
     49     console.log("Navigate to the report.");
     50     chrome.tabs.update(tab.id, {"url": reportUrl}, null);
     51   });
     52 }
     53 
     54 AddBenchmarkCallback(WriteReport);
     55