Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 'use strict'; | 5 'use strict'; |
| 6 | 6 |
| 7 // Allow a function to be provided by tests, which will be called when | |
| 8 // the page has been populated with site engagement details. | |
| 9 var pagePopulatedCallback = null; | |
| 10 var isPagePopulated = false; | |
| 11 | |
| 12 function setPagePopulatedCallbackForTest(callback) { | |
|
Bernhard Bauer
2017/03/31 13:04:59
This looks like you could use Promises (https://de
calamity
2017/04/03 04:38:52
Indeed!
I think something like
var populatedReso
Wez
2017/04/05 20:49:37
Done.
Note that the downside is that we're alloca
Bernhard Bauer
2017/04/06 15:20:47
I personally don't think it's a big issue, but you
Wez
2017/04/06 23:48:06
The problem is then that the page might have compl
| |
| 13 if (isPagePopulated) { | |
| 14 callback(); | |
| 15 } else { | |
| 16 pagePopulatedCallback = callback; | |
| 17 } | |
| 18 } | |
| 19 | |
| 20 function notifyPagePopulated() { | |
| 21 isPagePopulated = true; | |
| 22 if (pagePopulatedCallback) { | |
| 23 pagePopulatedCallback(); | |
| 24 pagePopulatedCallback = null; | |
| 25 } | |
| 26 } | |
| 27 | |
| 7 define('main', [ | 28 define('main', [ |
| 8 'chrome/browser/engagement/site_engagement.mojom', | 29 'chrome/browser/engagement/site_engagement.mojom', |
| 9 'content/public/renderer/frame_interfaces', | 30 'content/public/renderer/frame_interfaces', |
| 10 ], function(siteEngagementMojom, frameInterfaces) { | 31 ], function(siteEngagementMojom, frameInterfaces) { |
| 11 return function() { | 32 return function() { |
| 12 var uiHandler = new siteEngagementMojom.SiteEngagementUIHandlerPtr( | 33 var uiHandler = new siteEngagementMojom.SiteEngagementUIHandlerPtr( |
| 13 frameInterfaces.getInterface( | 34 frameInterfaces.getInterface( |
| 14 siteEngagementMojom.SiteEngagementUIHandler.name)); | 35 siteEngagementMojom.SiteEngagementUIHandler.name)); |
| 15 | 36 |
| 16 var engagementTableBody = $('engagement-table-body'); | 37 var engagementTableBody = $('engagement-table-body'); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 148 * Regenerates the engagement table from |info|. | 169 * Regenerates the engagement table from |info|. |
| 149 */ | 170 */ |
| 150 function renderTable() { | 171 function renderTable() { |
| 151 clearTable(); | 172 clearTable(); |
| 152 sortInfo(); | 173 sortInfo(); |
| 153 // Round each score to 2 decimal places. | 174 // Round each score to 2 decimal places. |
| 154 info.forEach(function(info) { | 175 info.forEach(function(info) { |
| 155 info.score = Number(Math.round(info.score * 100) / 100); | 176 info.score = Number(Math.round(info.score * 100) / 100); |
| 156 engagementTableBody.appendChild(createRow(info)); | 177 engagementTableBody.appendChild(createRow(info)); |
| 157 }); | 178 }); |
| 179 | |
| 180 notifyPagePopulated(); | |
|
calamity
2017/04/03 04:38:52
I think this should move to line 191 so that the p
Wez
2017/04/05 20:49:37
The browser test is actually verifying that there
| |
| 158 } | 181 } |
| 159 | 182 |
| 160 /** | 183 /** |
| 161 * Retrieve site engagement info and render the engagement table. | 184 * Retrieve site engagement info and render the engagement table. |
| 162 */ | 185 */ |
| 163 function updateEngagementTable() { | 186 function updateEngagementTable() { |
| 164 // Populate engagement table. | 187 // Populate engagement table. |
| 165 uiHandler.getSiteEngagementInfo().then(function(response) { | 188 uiHandler.getSiteEngagementInfo().then(function(response) { |
| 166 info = response.info; | 189 info = response.info; |
| 167 renderTable(info); | 190 renderTable(info); |
| 168 }); | 191 }); |
| 169 }; | 192 }; |
| 170 | 193 |
| 171 updateEngagementTable(); | 194 updateEngagementTable(); |
| 172 enableAutoupdate(); | 195 enableAutoupdate(); |
| 173 }; | 196 }; |
| 174 }); | 197 }); |
| OLD | NEW |