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

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

Issue 411008: Remove use of innerHTML and Toolstrips from example extensions (Closed)
Patch Set: cr changes Created 11 years, 1 month 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 } 10 }
10 </style> 11 </style>
11 <script> 12 <script>
12 // Tests the roundtrip time of sendRquest(). 13 function setChildTextNode(elementId, text) {
14 document.getElementById(elementId).innerText = text;
15 }
16
17 // Tests the roundtrip time of sendRequest().
13 function testRequest() { 18 function testRequest() {
14 var results = document.getElementById("resultsRequest"); 19 setChildTextNode("resultsRequest", "running...");
15 results.innerHTML = "running...";
16 20
17 chrome.tabs.getSelected(null, function(tab) { 21 chrome.tabs.getSelected(null, function(tab) {
18 var timer = new chromium.Interval(); 22 var timer = new chromium.Interval();
19 timer.start(); 23 timer.start();
20 24
21 chrome.tabs.sendRequest(tab.id, {counter: 1}, function handler(response) { 25 chrome.tabs.sendRequest(tab.id, {counter: 1}, function handler(response) {
22 if (response.counter < 1000) { 26 if (response.counter < 1000) {
23 chrome.tabs.sendRequest(tab.id, {counter: response.counter}, handler); 27 chrome.tabs.sendRequest(tab.id, {counter: response.counter}, handler);
24 } else { 28 } else {
25 timer.stop(); 29 timer.stop();
26 var usec = Math.round(timer.microseconds() / response.counter); 30 var usec = Math.round(timer.microseconds() / response.counter);
27 results.innerHTML = usec + "usec"; 31 setChildTextNode("resultsRequest", usec + "usec");
28 } 32 }
29 }); 33 });
30 }); 34 });
31 } 35 }
32 36
33 // Tests the roundtrip time of Port.postMessage() after opening a channel. 37 // Tests the roundtrip time of Port.postMessage() after opening a channel.
34 function testConnect() { 38 function testConnect() {
35 var results = document.getElementById("resultsConnect"); 39 setChildTextNode("resultsConnect", "running...");
36 results.innerHTML = "running...";
37 40
38 chrome.tabs.getSelected(null, function(tab) { 41 chrome.tabs.getSelected(null, function(tab) {
39 var timer = new chromium.Interval(); 42 var timer = new chromium.Interval();
40 timer.start(); 43 timer.start();
41 44
42 var port = chrome.tabs.connect(tab.id); 45 var port = chrome.tabs.connect(tab.id);
43 port.postMessage({counter: 1}); 46 port.postMessage({counter: 1});
44 port.onMessage.addListener(function getResp(response) { 47 port.onMessage.addListener(function getResp(response) {
45 if (response.counter < 1000) { 48 if (response.counter < 1000) {
46 port.postMessage({counter: response.counter}); 49 port.postMessage({counter: response.counter});
47 } else { 50 } else {
48 timer.stop(); 51 timer.stop();
49 var usec = Math.round(timer.microseconds() / response.counter); 52 var usec = Math.round(timer.microseconds() / response.counter);
50 results.innerHTML = usec + "usec"; 53 setChildTextNode("resultsConnect", usec + "usec");
51 } 54 }
52 }); 55 });
53 }); 56 });
54 } 57 }
55 </script> 58 </script>
56 </head> 59 </head>
57 <body> 60 <body>
58 <table> 61 <table>
59 <tr> 62 <tr>
60 <td><button onclick="testRequest()">Measure sendRequest</button></td> 63 <td><button onclick="testRequest()">Measure sendRequest</button></td>
61 <td id="resultsRequest" class="results">(results)</td> 64 <td id="resultsRequest" class="results">(results)</td>
62 </tr> 65 </tr>
63 <tr> 66 <tr>
64 <td><button onclick="testConnect()">Measure postMessage</button></td> 67 <td><button onclick="testConnect()">Measure postMessage</button></td>
65 <td id="resultsConnect" class="results">(results)</td> 68 <td id="resultsConnect" class="results">(results)</td>
66 </tr> 69 </tr>
67 </table> 70 </table>
68 </body> 71 </body>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698