Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(102)

Unified Diff: chrome/test/data/extensions/samples/benchmark/script.js

Issue 119361: Add a benchmark extension. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/test/data/extensions/samples/benchmark/script.js
===================================================================
--- chrome/test/data/extensions/samples/benchmark/script.js (revision 0)
+++ chrome/test/data/extensions/samples/benchmark/script.js (revision 0)
@@ -0,0 +1,28 @@
+// The port for communicating back to the extension.
+var benchmarkExtensionPort = chrome.extension.connect();
+
+// The url is what this page is known to the benchmark as.
+// The benchmark uses this id to differentiate the benchmark's
+// results from random pages being browsed.
+
+// TODO(mbelshe): If the page redirects, the location changed and the
+// benchmark stalls.
+var benchmarkExtensionUrl = window.location.toString();
+
+function sendTimesToExtension() {
+ var times = window.chromium.GetLoadTimes();
+ if (times.finishLoadTime != 0) {
+ benchmarkExtensionPort.postMessage({message: "load", url: benchmarkExtensionUrl, values: times});
+ } else {
+ window.setTimeout(sendTimesToExtension, 100);
+ }
+}
+
+function loadComplete() {
+ // Only trigger for top-level frames (e.g. the one we benchmarked)
+ if (window.parent == window) {
+ sendTimesToExtension();
+ }
+}
+
+window.addEventListener("load", loadComplete);

Powered by Google App Engine
This is Rietveld 408576698