Index: chrome/common/extensions/docs/examples/api/messaging/timer/popup.html |
=================================================================== |
--- chrome/common/extensions/docs/examples/api/messaging/timer/popup.html (revision 57339) |
+++ chrome/common/extensions/docs/examples/api/messaging/timer/popup.html (working copy) |
@@ -1,71 +1,77 @@ |
-<head> |
-<style> |
-tr { |
- white-space: nowrap; |
-} |
-.results { |
- text-align: right; |
- min-width: 6em; |
- color: black; |
-} |
-</style> |
-<script> |
-function setChildTextNode(elementId, text) { |
- document.getElementById(elementId).innerText = text; |
-} |
- |
-// Tests the roundtrip time of sendRequest(). |
-function testRequest() { |
- setChildTextNode("resultsRequest", "running..."); |
- |
- chrome.tabs.getSelected(null, function(tab) { |
- var timer = new chromium.Interval(); |
- timer.start(); |
- |
- chrome.tabs.sendRequest(tab.id, {counter: 1}, function handler(response) { |
- if (response.counter < 1000) { |
- chrome.tabs.sendRequest(tab.id, {counter: response.counter}, handler); |
- } else { |
- timer.stop(); |
- var usec = Math.round(timer.microseconds() / response.counter); |
- setChildTextNode("resultsRequest", usec + "usec"); |
- } |
- }); |
- }); |
-} |
- |
-// Tests the roundtrip time of Port.postMessage() after opening a channel. |
-function testConnect() { |
- setChildTextNode("resultsConnect", "running..."); |
- |
- chrome.tabs.getSelected(null, function(tab) { |
- var timer = new chromium.Interval(); |
- timer.start(); |
- |
- var port = chrome.tabs.connect(tab.id); |
- port.postMessage({counter: 1}); |
- port.onMessage.addListener(function getResp(response) { |
- if (response.counter < 1000) { |
- port.postMessage({counter: response.counter}); |
- } else { |
- timer.stop(); |
- var usec = Math.round(timer.microseconds() / response.counter); |
- setChildTextNode("resultsConnect", usec + "usec"); |
- } |
- }); |
- }); |
-} |
-</script> |
-</head> |
-<body> |
-<table> |
- <tr> |
- <td><button onclick="testRequest()">Measure sendRequest</button></td> |
- <td id="resultsRequest" class="results">(results)</td> |
- </tr> |
- <tr> |
- <td><button onclick="testConnect()">Measure postMessage</button></td> |
- <td id="resultsConnect" class="results">(results)</td> |
- </tr> |
-</table> |
-</body> |
+<head> |
+<style> |
+tr { |
+ white-space: nowrap; |
+} |
+.results { |
+ text-align: right; |
+ min-width: 6em; |
+ color: black; |
+} |
+</style> |
+<script> |
+if (!chrome.benchmarking) { |
+ alert("Warning: Looks like you forgot to run chrome with " + |
+ " --enable-benchmarking set."); |
+ return; |
+} |
+ |
+function setChildTextNode(elementId, text) { |
+ document.getElementById(elementId).innerText = text; |
+} |
+ |
+// Tests the roundtrip time of sendRequest(). |
+function testRequest() { |
+ setChildTextNode("resultsRequest", "running..."); |
+ |
+ chrome.tabs.getSelected(null, function(tab) { |
+ var timer = new chrome.Interval(); |
+ timer.start(); |
+ |
+ chrome.tabs.sendRequest(tab.id, {counter: 1}, function handler(response) { |
+ if (response.counter < 1000) { |
+ chrome.tabs.sendRequest(tab.id, {counter: response.counter}, handler); |
+ } else { |
+ timer.stop(); |
+ var usec = Math.round(timer.microseconds() / response.counter); |
+ setChildTextNode("resultsRequest", usec + "usec"); |
+ } |
+ }); |
+ }); |
+} |
+ |
+// Tests the roundtrip time of Port.postMessage() after opening a channel. |
+function testConnect() { |
+ setChildTextNode("resultsConnect", "running..."); |
+ |
+ chrome.tabs.getSelected(null, function(tab) { |
+ var timer = new chrome.Interval(); |
+ timer.start(); |
+ |
+ var port = chrome.tabs.connect(tab.id); |
+ port.postMessage({counter: 1}); |
+ port.onMessage.addListener(function getResp(response) { |
+ if (response.counter < 1000) { |
+ port.postMessage({counter: response.counter}); |
+ } else { |
+ timer.stop(); |
+ var usec = Math.round(timer.microseconds() / response.counter); |
+ setChildTextNode("resultsConnect", usec + "usec"); |
+ } |
+ }); |
+ }); |
+} |
+</script> |
+</head> |
+<body> |
+<table> |
+ <tr> |
+ <td><button onclick="testRequest()">Measure sendRequest</button></td> |
+ <td id="resultsRequest" class="results">(results)</td> |
+ </tr> |
+ <tr> |
+ <td><button onclick="testConnect()">Measure postMessage</button></td> |
+ <td id="resultsConnect" class="results">(results)</td> |
+ </tr> |
+</table> |
+</body> |