Chromium Code Reviews| Index: chrome/test/data/webui/net_internals/bandwidth_view.js |
| diff --git a/chrome/test/data/webui/net_internals/bandwidth_view.js b/chrome/test/data/webui/net_internals/bandwidth_view.js |
| index c9571c37c3d31bf9d9bbc7a5a8ce550f26baccee..6d8b56a60efa8c23994ef506e6dafdd98d71f19d 100644 |
| --- a/chrome/test/data/webui/net_internals/bandwidth_view.js |
| +++ b/chrome/test/data/webui/net_internals/bandwidth_view.js |
| @@ -29,6 +29,23 @@ function BandwidthTask(expectedLength, faviconLength) { |
| this.historicVerified = false; |
| } |
| +/** |
| + * The task loads data reduction proxy info. |
| + * |
| + * Checks that we see all relevant events and update the corresponding elements. |
| + * |
| + * @param {boolean} isEnabled The desired state of the data reduction proxy. |
| + * @extends {NetInternalsTest.Task} |
| + * @constructor |
| + */ |
| +function DataReductionProxyTask(isEnabled) { |
| + NetInternalsTest.Task.call(this); |
| + this.enabled_ = isEnabled; |
| + this.dataReductionProxyInfoVerified_ = false; |
| + this.proxySettingsReceived_ = false; |
| + this.badProxyChangesReceived_ = false; |
| +} |
| + |
| BandwidthTask.prototype = { |
| __proto__: NetInternalsTest.Task.prototype, |
| @@ -52,7 +69,7 @@ BandwidthTask.prototype = { |
| */ |
| getBandwidthTableCell_: function(row, col) { |
| return parseFloat(NetInternalsTest.getTbodyText( |
| - BandwidthView.MAIN_BOX_ID, row, col)); |
| + BandwidthView.STATS_BOX_ID, row, col)); |
| }, |
| /** |
| @@ -87,7 +104,7 @@ BandwidthTask.prototype = { |
| completeIfDone: function() { |
| if (this.historicVerified && this.sessionVerified) { |
| // Check number of rows in the table. |
| - NetInternalsTest.checkTbodyRows(BandwidthView.MAIN_BOX_ID, 4); |
| + NetInternalsTest.checkTbodyRows(BandwidthView.STATS_BOX_ID, 4); |
| this.onTaskDone(); |
| } |
| }, |
| @@ -136,6 +153,91 @@ BandwidthTask.prototype = { |
| } |
| }; |
| +DataReductionProxyTask.prototype = { |
| + __proto__: NetInternalsTest.Task.prototype, |
| + |
| + /** |
| + * Switches to the bandwidth tab and waits for arrival of data reduction |
| + * proxy information. |
| + */ |
| + start: function() { |
| + chrome.send('enableDataReductionProxy', [this.enabled_]); |
| + g_browser.addDataReductionProxyInfoObserver(this, true); |
| + g_browser.addProxySettingsObserver(this, true); |
| + g_browser.addBadProxiesObserver(this, true); |
| + NetInternalsTest.switchToView('bandwidth'); |
| + }, |
| + |
| + /** |
| + * A task is complete only when session and historic counters have been |
| + * verified to reflect the expected number of bytes received. |
| + */ |
| + completeIfDone: function() { |
| + if (this.dataReductionProxyInfoVerified_) { |
| + this.onTaskDone(); |
| + } |
| + }, |
| + |
| + /** |
| + * ProxySettingsObserver function. |
| + * |
| + * @param {object} proxySettings Proxy settings. |
| + */ |
| + onProxySettingsChanged: function(proxySettings) { |
| + if (this.isDone() || this.proxySettingsReceived_) |
| + return; |
| + |
| + this.proxySettingsReceived_ = true; |
| + }, |
| + |
| + /** |
| + * BadProxiesObserver function. |
| + * |
| + * @param {object} badProxies Bad proxies. |
| + */ |
| + onBadProxiesChanged: function(badProxies) { |
| + if (this.isDone() || this.badProxyChangesReceived_) |
| + return; |
| + |
| + this.badProxyChangesReceived_ = true; |
| + }, |
| + |
| + /** |
| + * DataReductionProxyInfoObserver function. Sanity checks the received data |
| + * and constructed table. |
| + |
| + * @param {object} info State of the data reduction proxy. |
| + */ |
| + onDataReductionProxyInfoChanged: function(info) { |
| + if (this.isDone() || |
| + this.dataReductionProxyInfoVerified_ || |
| + !this.proxySettingsReceived_) |
| + return; |
|
mmenke
2014/12/09 21:58:53
use braces
jeremyim
2014/12/09 23:14:28
Done.
|
| + |
| + if (info) { |
| + expectEquals(this.enabled_, info.enabled); |
| + if (this.enabled_) { |
| + expectEquals("Enabled", $(BandwidthView.ENABLED_ID).innerText); |
| + expectNotEquals('', $(BandwidthView.PRIMARY_PROXY_ID).innerText); |
| + expectNotEquals('', $(BandwidthView.SECONDARY_PROXY_ID).innerText); |
| + } else { |
| + expectEquals("Disabled", $(BandwidthView.ENABLED_ID).innerText); |
| + expectEquals('', $(BandwidthView.PRIMARY_PROXY_ID).innerText); |
| + expectEquals('', $(BandwidthView.SECONDARY_PROXY_ID).innerText); |
| + // Each event results in 2 rows, and we get 2 events since the startup |
| + // event starts as disabled, and we subsequently manually set it to the |
| + // disabled state. |
| + expectEquals( |
| + 4, NetInternalsTest.getTbodyNumRows(BandwidthView.EVENTS_TBODY_ID)); |
|
mmenke
2014/12/09 21:58:52
+4 indent
jeremyim
2014/12/09 23:14:28
Done.
|
| + } |
| + |
| + this.dataReductionProxyInfoVerified_ = true; |
| + this.completeIfDone(); |
| + } |
| + |
|
mmenke
2014/12/09 21:58:52
remove blank line.
jeremyim
2014/12/09 23:14:28
Done.
|
| + } |
| +}; |
| + |
| /** |
| * Loads a page and checks bandwidth statistics. |
| */ |
| @@ -148,4 +250,23 @@ TEST_F('NetInternalsTest', 'netInternalsSessionBandwidthSucceed', function() { |
| taskQueue.run(); |
| }); |
| +/** |
| + * Checks data reduction proxy info when it is enabled. |
| + */ |
| +TEST_F('NetInternalsTest', 'netInternalsDataReductionProxyEnabled', function() { |
| + var taskQueue = new NetInternalsTest.TaskQueue(true); |
| + taskQueue.addTask(new DataReductionProxyTask(true)); |
| + taskQueue.run(); |
| +}); |
| + |
| +/** |
| + * Checks data reduction proxy info when it is disabled. |
| + */ |
| +TEST_F('NetInternalsTest', |
| + 'netInternalsDataReductionProxyDisabled', function() { |
| + var taskQueue = new NetInternalsTest.TaskQueue(true); |
| + taskQueue.addTask(new DataReductionProxyTask(false)); |
| + taskQueue.run(); |
| +}); |
| + |
| })(); // Anonymous namespace |