| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // Include test fixture. | 5 // Include test fixture. |
| 6 GEN_INCLUDE(['net_internals_test.js']); | 6 GEN_INCLUDE(['net_internals_test.js']); |
| 7 | 7 |
| 8 // Anonymous namespace | 8 // Anonymous namespace |
| 9 (function() { | 9 (function() { |
| 10 | 10 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 /** | 52 /** |
| 53 * Switches to the bandwidth tab, loads a page in the background, and waits | 53 * Switches to the bandwidth tab, loads a page in the background, and waits |
| 54 * for the arrival of network statistics. | 54 * for the arrival of network statistics. |
| 55 * | 55 * |
| 56 * @param {string} url URL to be fetched. | 56 * @param {string} url URL to be fetched. |
| 57 */ | 57 */ |
| 58 start: function(url) { | 58 start: function(url) { |
| 59 assertEquals('string', typeof url); | 59 assertEquals('string', typeof url); |
| 60 this.url_ = url; | 60 this.url_ = url; |
| 61 g_browser.addSessionNetworkStatsObserver(this, true); | 61 g_browser.addSessionNetworkStatsObserver(this, true); |
| 62 g_browser.addHistoricNetworkStatsObserver(this, false); | 62 g_browser.addHistoricNetworkStatsObserver(this, true); |
| 63 NetInternalsTest.switchToView('bandwidth'); | 63 NetInternalsTest.switchToView('bandwidth'); |
| 64 chrome.send('loadPage', [this.url_]); | 64 chrome.send('loadPage', [this.url_]); |
| 65 }, | 65 }, |
| 66 | 66 |
| 67 /** | 67 /** |
| 68 * Returns the float value the specified cell of the bandwidth table. | 68 * Returns the float value the specified cell of the bandwidth table. |
| 69 */ | 69 */ |
| 70 getBandwidthTableCell_: function(row, col) { | 70 getBandwidthTableCell_: function(row, col) { |
| 71 return parseFloat(NetInternalsTest.getTbodyText( | 71 return parseFloat(NetInternalsTest.getTbodyText( |
| 72 BandwidthView.STATS_BOX_ID, row, col)); | 72 BandwidthView.STATS_BOX_ID, row, col)); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 } | 109 } |
| 110 }, | 110 }, |
| 111 | 111 |
| 112 /** | 112 /** |
| 113 * SessionNetworkStatsObserver function. Sanity checks the received data | 113 * SessionNetworkStatsObserver function. Sanity checks the received data |
| 114 * and constructed table. | 114 * and constructed table. |
| 115 | 115 |
| 116 * @param {object} networkStats State of the network session. | 116 * @param {object} networkStats State of the network session. |
| 117 */ | 117 */ |
| 118 onSessionNetworkStatsChanged: function(networkStats) { | 118 onSessionNetworkStatsChanged: function(networkStats) { |
| 119 if (this.isDone() || this.sessionVerified) | 119 if (this.isDone()) |
| 120 return; | 120 return; |
| 121 // Wait until the received content length is at least the size of | 121 // Wait until the received content length is at least the size of |
| 122 // our test page and favicon. | 122 // our test page and favicon. |
| 123 var expectedLength = this.expectedLength_ + this.faviconLength_; | 123 var expectedLength = this.expectedLength_ + this.faviconLength_; |
| 124 if (networkStats.session_received_content_length >= expectedLength) { | 124 if (networkStats.session_received_content_length >= expectedLength) { |
| 125 expectLE(expectedLength, networkStats.session_original_content_length); | 125 expectLE(expectedLength, networkStats.session_original_content_length); |
| 126 // Column 1 contains session information. | 126 // Column 1 contains session information. |
| 127 this.validateBandwidthTableColumn_(1, expectedLength, expectedLength); | 127 this.validateBandwidthTableColumn_(1, expectedLength, expectedLength); |
| 128 this.sessionVerified = true; | 128 this.sessionVerified = true; |
| 129 this.completeIfDone(); | 129 this.completeIfDone(); |
| 130 } | 130 } |
| 131 }, | 131 }, |
| 132 | 132 |
| 133 /** | 133 /** |
| 134 * HistoricNetworkStatsObserver function. Sanity checks the received data | 134 * HistoricNetworkStatsObserver function. Sanity checks the received data |
| 135 * and constructed table. | 135 * and constructed table. |
| 136 | 136 |
| 137 * @param {object} networkStats State of the network session. | 137 * @param {object} networkStats State of the network session. |
| 138 */ | 138 */ |
| 139 onHistoricNetworkStatsChanged: function(networkStats) { | 139 onHistoricNetworkStatsChanged: function(networkStats) { |
| 140 if (this.isDone() || this.historicVerified) | 140 if (this.isDone()) |
| 141 return; | 141 return; |
| 142 // The received content length should be zero since the historic | 142 // Wait until the received content length is at least the size of |
| 143 // information only updates every hour. | 143 // our test page and favicon. |
| 144 var expectedLength = 0; | 144 var expectedLength = this.expectedLength_ + this.faviconLength_; |
| 145 // Wait until the table has changed, otherwise the columns will be NaN | 145 if (networkStats.historic_received_content_length >= expectedLength) { |
| 146 if (!isNaN(this.getBandwidthTableCell_(0, 2))) { | |
| 147 expectLE(expectedLength, networkStats.historic_original_content_length); | 146 expectLE(expectedLength, networkStats.historic_original_content_length); |
| 148 // Column 2 contains historic information. | 147 // Column 2 contains historic information. The expected length should |
| 148 // only be what has been collected in this session, because previously |
| 149 // there was no history |
| 149 this.validateBandwidthTableColumn_(2, expectedLength, expectedLength); | 150 this.validateBandwidthTableColumn_(2, expectedLength, expectedLength); |
| 150 this.historicVerified = true; | 151 this.historicVerified = true; |
| 151 this.completeIfDone(); | 152 this.completeIfDone(); |
| 152 } | 153 } |
| 153 } | 154 } |
| 154 }; | 155 }; |
| 155 | 156 |
| 156 DataReductionProxyTask.prototype = { | 157 DataReductionProxyTask.prototype = { |
| 157 __proto__: NetInternalsTest.Task.prototype, | 158 __proto__: NetInternalsTest.Task.prototype, |
| 158 | 159 |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 */ | 267 */ |
| 267 TEST_F('NetInternalsTest', | 268 TEST_F('NetInternalsTest', |
| 268 'DISABLED_netInternalsDataReductionProxyDisabled', | 269 'DISABLED_netInternalsDataReductionProxyDisabled', |
| 269 function() { | 270 function() { |
| 270 var taskQueue = new NetInternalsTest.TaskQueue(true); | 271 var taskQueue = new NetInternalsTest.TaskQueue(true); |
| 271 taskQueue.addTask(new DataReductionProxyTask(false)); | 272 taskQueue.addTask(new DataReductionProxyTask(false)); |
| 272 taskQueue.run(); | 273 taskQueue.run(); |
| 273 }); | 274 }); |
| 274 | 275 |
| 275 })(); // Anonymous namespace | 276 })(); // Anonymous namespace |
| OLD | NEW |