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

Side by Side Diff: chrome/common/extensions/docs/examples/api/messaging/timer/popup.html

Issue 9289057: Changing manifest to v2 extension samples (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Adding zip files after rebasing with master Created 8 years, 10 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 unified diff | Download patch
OLDNEW
1 <head> 1 <head>
2 <style> 2 <style>
3 tr { 3 tr {
4 white-space: nowrap; 4 white-space: nowrap;
5 } 5 }
6 .results { 6 .results {
7 text-align: right; 7 text-align: right;
8 min-width: 6em; 8 min-width: 6em;
9 color: black; 9 color: black;
10 } 10 }
11 </style> 11 </style>
12 <script> 12 <script src="popup.js"></script>
13 if (!chrome.benchmarking) {
14 alert("Warning: Looks like you forgot to run chrome with " +
15 " --enable-benchmarking set.");
16 return;
17 }
18
19 function setChildTextNode(elementId, text) {
20 document.getElementById(elementId).innerText = text;
21 }
22
23 // Tests the roundtrip time of sendRequest().
24 function testRequest() {
25 setChildTextNode("resultsRequest", "running...");
26
27 chrome.tabs.getSelected(null, function(tab) {
28 var timer = new chrome.Interval();
29 timer.start();
30
31 chrome.tabs.sendRequest(tab.id, {counter: 1}, function handler(response) {
32 if (response.counter < 1000) {
33 chrome.tabs.sendRequest(tab.id, {counter: response.counter}, handler);
34 } else {
35 timer.stop();
36 var usec = Math.round(timer.microseconds() / response.counter);
37 setChildTextNode("resultsRequest", usec + "usec");
38 }
39 });
40 });
41 }
42
43 // Tests the roundtrip time of Port.postMessage() after opening a channel.
44 function testConnect() {
45 setChildTextNode("resultsConnect", "running...");
46
47 chrome.tabs.getSelected(null, function(tab) {
48 var timer = new chrome.Interval();
49 timer.start();
50
51 var port = chrome.tabs.connect(tab.id);
52 port.postMessage({counter: 1});
53 port.onMessage.addListener(function getResp(response) {
54 if (response.counter < 1000) {
55 port.postMessage({counter: response.counter});
56 } else {
57 timer.stop();
58 var usec = Math.round(timer.microseconds() / response.counter);
59 setChildTextNode("resultsConnect", usec + "usec");
60 }
61 });
62 });
63 }
64 </script>
65 </head> 13 </head>
66 <body> 14 <body>
67 <table> 15 <table>
68 <tr> 16 <tr>
69 <td><button onclick="testRequest()">Measure sendRequest</button></td> 17 <td><button id="testRequest">Measure sendRequest</button></td>
70 <td id="resultsRequest" class="results">(results)</td> 18 <td id="resultsRequest" class="results">(results)</td>
71 </tr> 19 </tr>
72 <tr> 20 <tr>
73 <td><button onclick="testConnect()">Measure postMessage</button></td> 21 <td><button id="testConnect">Measure postMessage</button></td>
74 <td id="resultsConnect" class="results">(results)</td> 22 <td id="resultsConnect" class="results">(results)</td>
75 </tr> 23 </tr>
76 </table> 24 </table>
77 </body> 25 </body>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698