summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorerikkay@chromium.org <erikkay@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-12 20:14:04 +0000
committererikkay@chromium.org <erikkay@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-12 20:14:04 +0000
commit2468fc57ba4b174cb315ca88067905fd45a78533 (patch)
tree73d4dee5a992615ff80f4b46425a7191772fcd8a
parent0335b08e730b0ba14e2125da6bcdd8bc826b6853 (diff)
downloadchromium_src-2468fc57ba4b174cb315ca88067905fd45a78533.zip
chromium_src-2468fc57ba4b174cb315ca88067905fd45a78533.tar.gz
chromium_src-2468fc57ba4b174cb315ca88067905fd45a78533.tar.bz2
Move benchmark extension example to new location and clean it up to use browser actions rather than toolstrips.
BUG=26106 TEST=none Review URL: http://codereview.chromium.org/384065 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31815 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/app/chrome_dll_main.cc3
-rw-r--r--chrome/common/extensions/docs/examples/extensions/benchmark/README.txt (renamed from chrome/test/data/extensions/samples/benchmark/README)36
-rw-r--r--chrome/common/extensions/docs/examples/extensions/benchmark/background.html (renamed from chrome/test/data/extensions/samples/benchmark/toolstrip.html)63
-rw-r--r--chrome/common/extensions/docs/examples/extensions/benchmark/jst/jsevalcontext.js (renamed from chrome/test/data/extensions/samples/benchmark/jst/jsevalcontext.js)0
-rw-r--r--chrome/common/extensions/docs/examples/extensions/benchmark/jst/jstemplate.js (renamed from chrome/test/data/extensions/samples/benchmark/jst/jstemplate.js)0
-rw-r--r--chrome/common/extensions/docs/examples/extensions/benchmark/jst/jstemplate_test.js (renamed from chrome/test/data/extensions/samples/benchmark/jst/jstemplate_test.js)0
-rw-r--r--chrome/common/extensions/docs/examples/extensions/benchmark/jst/util.js (renamed from chrome/test/data/extensions/samples/benchmark/jst/util.js)0
-rw-r--r--chrome/common/extensions/docs/examples/extensions/benchmark/manifest.json (renamed from chrome/test/data/extensions/samples/benchmark/manifest.json)9
-rw-r--r--chrome/common/extensions/docs/examples/extensions/benchmark/options.html (renamed from chrome/test/data/extensions/samples/benchmark/options.html)20
-rw-r--r--chrome/common/extensions/docs/examples/extensions/benchmark/script.js (renamed from chrome/test/data/extensions/samples/benchmark/script.js)0
-rw-r--r--chrome/common/extensions/docs/examples/extensions/benchmark/stopwatch.jpg (renamed from chrome/test/data/extensions/samples/benchmark/stopwatch.jpg)bin947 -> 947 bytes
-rw-r--r--webkit/extensions/v8/benchmarking_extension.cc2
12 files changed, 70 insertions, 63 deletions
diff --git a/chrome/app/chrome_dll_main.cc b/chrome/app/chrome_dll_main.cc
index bc9f4a3..8d2c141 100644
--- a/chrome/app/chrome_dll_main.cc
+++ b/chrome/app/chrome_dll_main.cc
@@ -457,7 +457,8 @@ int ChromeMain(int argc, char** argv) {
// of the process. It is not cleaned up.
// TODO(port): we probably need to shut this down correctly to avoid
// leaking shared memory regions on posix platforms.
- if (parsed_command_line.HasSwitch(switches::kEnableStatsTable)) {
+ if (parsed_command_line.HasSwitch(switches::kEnableStatsTable) ||
+ parsed_command_line.HasSwitch(switches::kEnableBenchmarking)) {
std::string statsfile = StringPrintf("%s-%lld", chrome::kStatsFilename,
static_cast<int64>(browser_pid));
StatsTable *stats_table = new StatsTable(statsfile,
diff --git a/chrome/test/data/extensions/samples/benchmark/README b/chrome/common/extensions/docs/examples/extensions/benchmark/README.txt
index f9be2c2..8136ab3 100644
--- a/chrome/test/data/extensions/samples/benchmark/README
+++ b/chrome/common/extensions/docs/examples/extensions/benchmark/README.txt
@@ -1,18 +1,18 @@
-Benchmark Extension
--------------------
-This extension provides basic page-level benchmarking into the browser.
-
-With the extension installed you can test web pages and then compare
-results in a subwindow.
-
-Between each page load you can optionally clear idle http connections and
-clear the cache so that page loads are more like the user experience
-when first connecting to a site.
-
-To use this benchmark, you'll need to run chrome with the the
-"--enable-benchmarking" flag. This flag enables a v8-extension so that
-the benchmark can clear idle connections and the cache.
-
-The code found in the jst/ subdirectory is JSTemplate code from
-http://code.google.com/p/google-jstemplate/
-
+Benchmark Extension
+-------------------
+This extension provides basic page-level benchmarking into the browser.
+
+With the extension installed you can test web pages and then compare
+results in a subwindow.
+
+Between each page load you can optionally clear idle http connections and
+clear the cache so that page loads are more like the user experience
+when first connecting to a site.
+
+To use this benchmark, you'll need to run chrome with the the
+"--enable-benchmarking" flag. This flag enables a v8-extension so that
+the benchmark can clear idle connections and the cache.
+
+The code found in the jst/ subdirectory is JSTemplate code from
+http://code.google.com/p/google-jstemplate/
+
diff --git a/chrome/test/data/extensions/samples/benchmark/toolstrip.html b/chrome/common/extensions/docs/examples/extensions/benchmark/background.html
index 01e8dc4..37cfc30 100644
--- a/chrome/test/data/extensions/samples/benchmark/toolstrip.html
+++ b/chrome/common/extensions/docs/examples/extensions/benchmark/background.html
@@ -37,24 +37,29 @@ window.results.data = new Array();
window.testUrl = "";
window.windowId = 0;
-var optionsForm = 0;
function show_options() {
- // This functionality is a bit fragile, probably due to the extension API.
- // If we open the window from within the getSelected() callback, then the
- // window opens in a new window rather than a new tab (is that a bug?).
- // If we open the window before we call getSelected(), then the selected
- // tab URL will be NULL, because the page won't have loaded yet, but it will
- // be the selected tab. So, we do this weird thing where we first call
- // get selected, knowing that it is asynchronous. Then we open the window,
- // and finally when the callback occurs for getSelected, the window will
- // be created and we can use it.
- chrome.tabs.getSelected(windowId, function(tab) {
+ chrome.tabs.getSelected(null, function(tab) {
window.testUrl = tab.url;
- optionsForm.setUrl(window.testUrl);
+ var tabs = chrome.extension.getExtensionTabs();
+ if (tabs && tabs.length) {
+ 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++) {
+ if (all[i].url == optionsUrl) {
+ chrome.tabs.update(all[i].id, {selected: true });
+ return;
+ }
+ }
+ });
+ } else {
+ chrome.tabs.create({"url":"options.html"});
+ }
});
- optionsForm = window.open("options.html", "optionswindow");
}
+chrome.browserAction.onClicked.addListener(show_options);
+
function Benchmark() {
var runCount_ = 0;
var count_;
@@ -110,19 +115,27 @@ function Benchmark() {
// push the result
window.results.data.push(current_);
current_ = 0;
-
- // show the latest
- show_options();
}
// Update the UI after a test run.
this.displayResults = function() {
- var span = document.getElementById("result");
var score = 0;
if (count_ > 0) {
score = totalTime_ / count_;
+ var text = score.toFixed(1) + "ms avg";
+ chrome.browserAction.setTitle({"title": text});
+ }
+ if (runCount_) {
+ chrome.browserAction.setBadgeText({"text": "" + runCount_});
+ chrome.browserAction.setBadgeBackgroundColor({"color": [255, 0, 0, 255]});
+ } else {
+ chrome.browserAction.setBadgeText({"text": "" + score.toFixed()});
+ chrome.browserAction.setBadgeBackgroundColor({"color": [0, 255, 0, 255]});
+ var tabs = chrome.extension.getExtensionTabs();
+ if (tabs && tabs.length) {
+ tabs[0].location.reload();
+ }
}
- span.innerHTML = score.toFixed(1) + " (" + (runCount_) + ")";
}
// Run a single page in the benchmark
@@ -184,7 +197,6 @@ chrome.extension.onConnect.addListener(function(port) {
});
function run() {
- show_options();
var urls = testUrl.split(",");
for (var i = 0; i < urls.length; i++) {
var benchmark = new Benchmark();
@@ -198,16 +210,3 @@ chrome.windows.getCurrent(function(currentWindow) {
window.windowId = currentWindow.id;
});
</script>
-
-<style>
-#result {
- color: green;
- text-align: center;
- vertical-align: center;
-}
-</style>
-
-<div id="bench">
-<img src="stopwatch.jpg" height="25" width="25" align=top onclick="show_options()">
-<span id="result"></span>
-</div>
diff --git a/chrome/test/data/extensions/samples/benchmark/jst/jsevalcontext.js b/chrome/common/extensions/docs/examples/extensions/benchmark/jst/jsevalcontext.js
index 4f2a5ee..4f2a5ee 100644
--- a/chrome/test/data/extensions/samples/benchmark/jst/jsevalcontext.js
+++ b/chrome/common/extensions/docs/examples/extensions/benchmark/jst/jsevalcontext.js
diff --git a/chrome/test/data/extensions/samples/benchmark/jst/jstemplate.js b/chrome/common/extensions/docs/examples/extensions/benchmark/jst/jstemplate.js
index d2cc386..d2cc386 100644
--- a/chrome/test/data/extensions/samples/benchmark/jst/jstemplate.js
+++ b/chrome/common/extensions/docs/examples/extensions/benchmark/jst/jstemplate.js
diff --git a/chrome/test/data/extensions/samples/benchmark/jst/jstemplate_test.js b/chrome/common/extensions/docs/examples/extensions/benchmark/jst/jstemplate_test.js
index b9653e1..b9653e1 100644
--- a/chrome/test/data/extensions/samples/benchmark/jst/jstemplate_test.js
+++ b/chrome/common/extensions/docs/examples/extensions/benchmark/jst/jstemplate_test.js
diff --git a/chrome/test/data/extensions/samples/benchmark/jst/util.js b/chrome/common/extensions/docs/examples/extensions/benchmark/jst/util.js
index 570c71f..570c71f 100644
--- a/chrome/test/data/extensions/samples/benchmark/jst/util.js
+++ b/chrome/common/extensions/docs/examples/extensions/benchmark/jst/util.js
diff --git a/chrome/test/data/extensions/samples/benchmark/manifest.json b/chrome/common/extensions/docs/examples/extensions/benchmark/manifest.json
index 101c27f..886f40a 100644
--- a/chrome/test/data/extensions/samples/benchmark/manifest.json
+++ b/chrome/common/extensions/docs/examples/extensions/benchmark/manifest.json
@@ -2,9 +2,12 @@
"name": "Page Benchmarker",
"version": "1.0",
"description": "Chromium Page Benchmarker.",
- "toolstrips": [
- "toolstrip.html"
- ],
+ "background_page": "background.html",
+ "browser_action": {
+ "default_title": "Benchmark page load time",
+ "default_icon": "stopwatch.jpg"
+ },
+ "options_page": "options.html",
"content_scripts": [
{
"matches": ["http://*/*"],
diff --git a/chrome/test/data/extensions/samples/benchmark/options.html b/chrome/common/extensions/docs/examples/extensions/benchmark/options.html
index c806551..41d5e70 100644
--- a/chrome/test/data/extensions/samples/benchmark/options.html
+++ b/chrome/common/extensions/docs/examples/extensions/benchmark/options.html
@@ -8,7 +8,7 @@
<style>
body {
font-size: 84%;
- font-family: Arial, Helvetica, sans-serif;
+ font-family: Helvetica, Arial, sans-serif;
padding: 0.75em;
margin: 0;
min-width: 45em;
@@ -149,8 +149,10 @@ function computeResults(data) {
}
function jsinit() {
+ var extension = chrome.extension.getBackgroundPage();
+
// Run the template to show results
- var data = window.opener.results;
+ var data = extension.results;
computeResults(data);
var context = new JsEvalContext(data);
@@ -160,11 +162,10 @@ function jsinit() {
jstProcess(context, template);
// Set the options
- var extension = window.opener;
document.getElementById("iterations").value = extension.iterations;
document.getElementById("clearconns").checked = extension.clearConnections;
document.getElementById("clearcache").checked = extension.clearCache;
- document.getElementById("testurl").value = extension.testUrl;
+ setUrl(extension.testUrl);
}
function getWidth(mean, max_width) {
@@ -173,7 +174,7 @@ function getWidth(mean, max_width) {
// Apply configuration back to our extension
function config() {
- var extension = window.opener;
+ var extension = chrome.extension.getBackgroundPage();
var iterations = parseInt(document.getElementById("iterations").value);
var clearConnections = document.getElementById("clearconns").checked;
var clearCache = document.getElementById("clearcache").checked;
@@ -187,11 +188,13 @@ function config() {
// Set the url in the benchmark url box.
function setUrl(url) {
document.getElementById("testurl").value = url;
+ console.log(url);
+ console.log(document.getElementById("testurl").value);
}
// Start the benchmark.
function run() {
- var extension = window.opener;
+ var extension = chrome.extension.getBackgroundPage();
var testUrl = document.getElementById("testurl").value;
extension.testUrl = testUrl;
extension.run();
@@ -199,7 +202,8 @@ function run() {
// Clear the results
function clearResults() {
- window.opener.results.data = new Array();
+ var extension = chrome.extension.getBackgroundPage();
+ extension.results.data = new Array();
jsinit();
}
</script>
@@ -218,7 +222,7 @@ function clearResults() {
Clear Connections?<input id="clearconns" type="checkbox">
Clear Cache?<input id="clearcache" type="checkbox">
<input type="button" value="OK" onclick="config();"><P>
-URL to load <input type="text" id="testurl" size=100 value="http://www.google.com/"></input>
+URL to load <input type="text" id="testurl" size=100>
<input type="button" value="Run" onclick="run();"><P>
<p>
diff --git a/chrome/test/data/extensions/samples/benchmark/script.js b/chrome/common/extensions/docs/examples/extensions/benchmark/script.js
index 75e07a4..75e07a4 100644
--- a/chrome/test/data/extensions/samples/benchmark/script.js
+++ b/chrome/common/extensions/docs/examples/extensions/benchmark/script.js
diff --git a/chrome/test/data/extensions/samples/benchmark/stopwatch.jpg b/chrome/common/extensions/docs/examples/extensions/benchmark/stopwatch.jpg
index 60628b1..60628b1 100644
--- a/chrome/test/data/extensions/samples/benchmark/stopwatch.jpg
+++ b/chrome/common/extensions/docs/examples/extensions/benchmark/stopwatch.jpg
Binary files differ
diff --git a/webkit/extensions/v8/benchmarking_extension.cc b/webkit/extensions/v8/benchmarking_extension.cc
index 501d483..4823718 100644
--- a/webkit/extensions/v8/benchmarking_extension.cc
+++ b/webkit/extensions/v8/benchmarking_extension.cc
@@ -64,7 +64,7 @@ class BenchmarkingWrapper : public v8::Extension {
}
static v8::Handle<v8::Value> GetCounter(const v8::Arguments& args) {
- if (!args.Length() || !args[0]->IsString())
+ if (!args.Length() || !args[0]->IsString() || !StatsTable::current())
return v8::Undefined();
// Extract the name argument