| Index: chrome/common/extensions/docs/examples/extensions/benchmark/background.js
|
| diff --git a/chrome/common/extensions/docs/examples/extensions/benchmark/background.html b/chrome/common/extensions/docs/examples/extensions/benchmark/background.js
|
| similarity index 96%
|
| copy from chrome/common/extensions/docs/examples/extensions/benchmark/background.html
|
| copy to chrome/common/extensions/docs/examples/extensions/benchmark/background.js
|
| index 6c9ef51de620c777ed1104657bb4f38ca037b83b..1d11a94f361df400f965dbd75cbf2ad0e79a8ca1 100644
|
| --- a/chrome/common/extensions/docs/examples/extensions/benchmark/background.html
|
| +++ b/chrome/common/extensions/docs/examples/extensions/benchmark/background.js
|
| @@ -1,17 +1,7 @@
|
| -<style>
|
| -#options {
|
| - position: absolute;
|
| - background-color: #FFFFCC;
|
| - display: none;
|
| - font-family: "Courier New";
|
| - font-size: 9pt;
|
| - padding: 5px;
|
| - border: 1px solid #CCCC88;
|
| - z-index: 3;
|
| -}
|
| -</style>
|
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
|
|
| -<script>
|
| // Round a number to the 1's place.
|
| function formatNumber(str) {
|
| str += '';
|
| @@ -90,10 +80,10 @@ function benchmarkStillRunning() {
|
| function findBenchmark(url) {
|
| for (var index = 0; index < benchmarks.length; ++index) {
|
| // One common redirection case: if the url ends without a slash and refers
|
| - // to a directory, it actually would be redirected to the correct one
|
| + // to a directory, it actually would be redirected to the correct one
|
| // (with a slash). In this case, the url returned by the JS and the one
|
| - // stored locally do not match.
|
| - if ((benchmarks[index].url() == url) ||
|
| + // stored locally do not match.
|
| + if ((benchmarks[index].url() == url) ||
|
| (benchmarks[index].url() + '/' == url)) {
|
| return benchmarks[index];
|
| }
|
| @@ -111,13 +101,13 @@ function show_options() {
|
| if (window.testUrl == "") {
|
| window.testUrl = tab.url;
|
| }
|
| - var tabs = chrome.extension.getExtensionTabs();
|
| + var tabs = chrome.extension.getViews({"type": "tab"});
|
| if (tabs && tabs.length) {
|
| - // To avoid "Uncaught TypeError: Object Window has no method
|
| + // To avoid "Uncaught TypeError: Object Window has no method
|
| // 'setUrl' ". Sometimes tabs are not the desired extension tabs.
|
| if (tabs[0].$suburl != undefined) {
|
| tabs[0].setUrl(testUrl);
|
| - }
|
| + }
|
| var optionsUrl = chrome.extension.getURL("options.html");
|
| chrome.tabs.getAllInWindow(null, function(all) {
|
| for (var i = 0; i < all.length; i++) {
|
| @@ -173,7 +163,7 @@ function Benchmark() {
|
| current_.KbytesRead = new Array();
|
| current_.KbytesWritten = new Array();
|
| current_.readbpsResults = new Array();
|
| - current_.writebpsResults = new Array();
|
| + current_.writebpsResults = new Array();
|
| current_.totalTime = 0;
|
| current_.iterations = 0;
|
| current_.requests = new Array();
|
| @@ -183,12 +173,12 @@ function Benchmark() {
|
| current_.maxDepth = 0;
|
| current_.minDepth = 0;
|
| current_.avgDepth = 0;
|
| - }
|
| + };
|
|
|
| // Is the benchmark currently in progress.
|
| this.isRunning = function() {
|
| return runCount_ > 0;
|
| - }
|
| + };
|
|
|
| // The url which this benchmark is running.
|
| this.url = function() { return current_.url; }
|
| @@ -203,7 +193,7 @@ function Benchmark() {
|
| benchmarkWindow = 0;
|
| show_options();
|
| }
|
| - }
|
| + };
|
|
|
| // Update the UI after a test run.
|
| this.displayResults = function() {
|
| @@ -221,12 +211,12 @@ function Benchmark() {
|
| chrome.browserAction.setBadgeBackgroundColor({"color": [0, 255, 0, 255]});
|
| }
|
|
|
| - // Reload the page after each run to show immediate results.
|
| - var tabs = chrome.extension.getExtensionTabs();
|
| + // Reload the page after each run to show immediate results.
|
| + var tabs = chrome.extension.getViews({"type": "tab"});
|
| if (tabs && tabs.length) {
|
| tabs[0].location.reload(true);
|
| }
|
| - }
|
| + };
|
|
|
| // Called before starting a page load.
|
| this.pageStart = function() {
|
| @@ -235,7 +225,7 @@ function Benchmark() {
|
| initialRequestCount_ = chrome.benchmarking.counter(kRequestCount);
|
| initialConnectCount_ = chrome.benchmarking.counter(kConnectCount);
|
| initialSpdySessionCount_ = chrome.benchmarking.counter(kSpdySessionCount);
|
| - }
|
| + };
|
|
|
| this.openNextPage = function() {
|
| var benchmark = nextBenchmark();
|
| @@ -247,7 +237,7 @@ function Benchmark() {
|
| // not the ones opened by the user.
|
| chrome.tabs.executeScript(tab.id, {file: "script.js"});
|
| });
|
| - }
|
| + };
|
|
|
| this.prepareToOpenPage = function() {
|
| // After the previous page is closed, this function will apply
|
| @@ -271,36 +261,36 @@ function Benchmark() {
|
|
|
| // Go back to the browser so that tasks can run.
|
| setTimeout(me_.openNextPage, window.interval);
|
| - }
|
| + };
|
|
|
| this.closePage = function() {
|
| chrome.tabs.remove(benchmarkWindow.id, function() {
|
| me_.prepareToOpenPage();
|
| });
|
| - }
|
| + };
|
|
|
| // Run a single page in the benchmark
|
| this.runPage = function() {
|
| if (benchmarkWindow) {
|
| // To avoid the error "Error during tabs.remove: No tab with id xx"
|
| - // while debugging, due to user manually closing the benchmark tab.
|
| + // while debugging, due to user manually closing the benchmark tab.
|
| chrome.tabs.getAllInWindow(null, function(all) {
|
| for (var i = 0; i < all.length; i++) {
|
| if (all[i].id == benchmarkWindow.id) {
|
| me_.closePage();
|
| return;
|
| - };
|
| + };
|
| };
|
| me_.prepareToOpenPage();
|
| });
|
| } else {
|
| me_.prepareToOpenPage();
|
| }
|
| - }
|
| + };
|
|
|
| // Called when a page finishes loading.
|
| this.pageFinished = function(load_times, domNum, depths) {
|
| -
|
| +
|
| // Make sure the content can be fetched via spdy if it is enabled.
|
| if (window.enableSpdy && !load_times.wasFetchedViaSpdy) {
|
| alert("Can not fetch current url via spdy.\n" +
|
| @@ -336,7 +326,7 @@ function Benchmark() {
|
| }
|
| return;
|
| }
|
| -
|
| +
|
| var requested = load_times.requestTime;
|
| var started = load_times.startLoadTime;
|
| var startLoadTime =
|
| @@ -369,7 +359,7 @@ function Benchmark() {
|
| // Get the index of current benchmarked page in the result array.
|
| var currIndex;
|
| currIndex = window.results.data.indexOf(current_, 0);
|
| -
|
| +
|
| // Record the result
|
| current_.viaSpdy = load_times.wasFetchedViaSpdy;
|
| current_.iterations++;
|
| @@ -380,7 +370,7 @@ function Benchmark() {
|
| current_.totalResults.push(totalTime);
|
| var bytesRead = chrome.benchmarking.counter(kTCPReadBytes) -
|
| initialReadBytes_;
|
| - var bytesWrite = chrome.benchmarking.counter(kTCPWriteBytes) -
|
| + var bytesWrite = chrome.benchmarking.counter(kTCPWriteBytes) -
|
| initialWriteBytes_;
|
| current_.KbytesRead.push(bytesRead / 1024);
|
| current_.KbytesWritten.push(bytesWrite / 1024);
|
| @@ -397,7 +387,7 @@ function Benchmark() {
|
| current_.maxDepth = depths[0];
|
| current_.minDepth = depths[1];
|
| current_.avgDepth = depths[2];
|
| -
|
| +
|
| // Insert or update the result data after each run.
|
| if (currIndex == -1) {
|
| window.results.data.push(current_);
|
| @@ -419,7 +409,7 @@ function Benchmark() {
|
|
|
| // Update the UI
|
| me_.displayResults();
|
| - }
|
| + };
|
| }
|
|
|
| chrome.extension.onConnect.addListener(function(port) {
|
| @@ -454,17 +444,17 @@ function run() {
|
| benchmarks = [];
|
| var urls = testUrl.split(",");
|
| for (var i = 0; i < urls.length; i++) {
|
| -
|
| +
|
| // Remove extra space at the beginning or end of a url.
|
| urls[i] = removeSpace(urls[i]);
|
|
|
| - // Alert about and ignore blank page which does not get loaded.
|
| + // Alert about and ignore blank page which does not get loaded.
|
| if (urls[i] == "about:blank") {
|
| alert("blank page loaded!");
|
| } else if (!checkScheme(urls[i])) {
|
| // Alert about url that is not in scheme http:// or https://.
|
| alert(urls[i] + " does not start with http:// or https://.");
|
| - } else {
|
| + } else {
|
| var benchmark = new Benchmark();
|
| benchmark.start(urls[i]); // XXXMB - move to constructor
|
| }
|
| @@ -490,15 +480,14 @@ function checkScheme(url) {
|
| var httpsStr = "https://";
|
| var urlSubStr1 = url.substring(0, httpStr.length);
|
| var urlSubStr2 = url.substring(0, httpsStr.length);
|
| -
|
| +
|
| if ( (urlSubStr1 == httpStr) || (urlSubStr2 == httpsStr) ) {
|
| return true;
|
| - }
|
| - return false;
|
| + }
|
| + return false;
|
| }
|
|
|
| // Run at startup
|
| chrome.windows.getCurrent(function(currentWindow) {
|
| window.windowId = currentWindow.id;
|
| });
|
| -</script>
|
|
|