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 11 matching lines...) Expand all Loading... |
22 */ | 22 */ |
23 function BandwidthTask(expectedLength, faviconLength) { | 23 function BandwidthTask(expectedLength, faviconLength) { |
24 NetInternalsTest.Task.call(this); | 24 NetInternalsTest.Task.call(this); |
25 this.url_ = null; | 25 this.url_ = null; |
26 this.expectedLength_ = expectedLength; | 26 this.expectedLength_ = expectedLength; |
27 this.faviconLength_ = faviconLength; | 27 this.faviconLength_ = faviconLength; |
28 this.sessionVerified = false; | 28 this.sessionVerified = false; |
29 this.historicVerified = false; | 29 this.historicVerified = false; |
30 } | 30 } |
31 | 31 |
| 32 /** |
| 33 * The task loads data reduction proxy info. |
| 34 * |
| 35 * Checks that we see all relevant events and update the corresponding elements. |
| 36 * |
| 37 * @param {boolean} isEnabled The desired state of the data reduction proxy. |
| 38 * @extends {NetInternalsTest.Task} |
| 39 * @constructor |
| 40 */ |
| 41 function DataReductionProxyTask(isEnabled) { |
| 42 NetInternalsTest.Task.call(this); |
| 43 this.enabled_ = isEnabled; |
| 44 this.dataReductionProxyInfoVerified_ = false; |
| 45 } |
| 46 |
32 BandwidthTask.prototype = { | 47 BandwidthTask.prototype = { |
33 __proto__: NetInternalsTest.Task.prototype, | 48 __proto__: NetInternalsTest.Task.prototype, |
34 | 49 |
35 /** | 50 /** |
36 * Switches to the bandwidth tab, loads a page in the background, and waits | 51 * Switches to the bandwidth tab, loads a page in the background, and waits |
37 * for the arrival of network statistics. | 52 * for the arrival of network statistics. |
38 * | 53 * |
39 * @param {string} url URL to be fetched. | 54 * @param {string} url URL to be fetched. |
40 */ | 55 */ |
41 start: function(url) { | 56 start: function(url) { |
42 assertEquals('string', typeof url); | 57 assertEquals('string', typeof url); |
43 this.url_ = url; | 58 this.url_ = url; |
44 g_browser.addSessionNetworkStatsObserver(this, true); | 59 g_browser.addSessionNetworkStatsObserver(this, true); |
45 g_browser.addHistoricNetworkStatsObserver(this, false); | 60 g_browser.addHistoricNetworkStatsObserver(this, false); |
46 NetInternalsTest.switchToView('bandwidth'); | 61 NetInternalsTest.switchToView('bandwidth'); |
47 chrome.send('loadPage', [this.url_]); | 62 chrome.send('loadPage', [this.url_]); |
48 }, | 63 }, |
49 | 64 |
50 /** | 65 /** |
51 * Returns the float value the specified cell of the bandwidth table. | 66 * Returns the float value the specified cell of the bandwidth table. |
52 */ | 67 */ |
53 getBandwidthTableCell_: function(row, col) { | 68 getBandwidthTableCell_: function(row, col) { |
54 return parseFloat(NetInternalsTest.getTbodyText( | 69 return parseFloat(NetInternalsTest.getTbodyText( |
55 BandwidthView.MAIN_BOX_ID, row, col)); | 70 BandwidthView.STATS_BOX_ID, row, col)); |
56 }, | 71 }, |
57 | 72 |
58 /** | 73 /** |
59 * Confirms that the bandwidth usage table displays the expected values. | 74 * Confirms that the bandwidth usage table displays the expected values. |
60 * Does not check exact displayed values, to avoid races, but makes sure | 75 * Does not check exact displayed values, to avoid races, but makes sure |
61 * values are high enough after an event of interest. | 76 * values are high enough after an event of interest. |
62 * | 77 * |
63 * @param {number} col The column of the table to validate, either 1 or 2. | 78 * @param {number} col The column of the table to validate, either 1 or 2. |
64 * @param {number} expectedReceived Expected received content length. | 79 * @param {number} expectedReceived Expected received content length. |
65 * @param {number} expectedOriginal Expected original content length. | 80 * @param {number} expectedOriginal Expected original content length. |
(...skipping 14 matching lines...) Expand all Loading... |
80 expectFalse(isNaN(row4)); | 95 expectFalse(isNaN(row4)); |
81 }, | 96 }, |
82 | 97 |
83 /** | 98 /** |
84 * A task is complete only when session and historic counters have been | 99 * A task is complete only when session and historic counters have been |
85 * verified to reflect the expected number of bytes received. | 100 * verified to reflect the expected number of bytes received. |
86 */ | 101 */ |
87 completeIfDone: function() { | 102 completeIfDone: function() { |
88 if (this.historicVerified && this.sessionVerified) { | 103 if (this.historicVerified && this.sessionVerified) { |
89 // Check number of rows in the table. | 104 // Check number of rows in the table. |
90 NetInternalsTest.checkTbodyRows(BandwidthView.MAIN_BOX_ID, 4); | 105 NetInternalsTest.checkTbodyRows(BandwidthView.STATS_BOX_ID, 4); |
91 this.onTaskDone(); | 106 this.onTaskDone(); |
92 } | 107 } |
93 }, | 108 }, |
94 | 109 |
95 /** | 110 /** |
96 * SessionNetworkStatsObserver function. Sanity checks the received data | 111 * SessionNetworkStatsObserver function. Sanity checks the received data |
97 * and constructed table. | 112 * and constructed table. |
98 | 113 |
99 * @param {object} networkStats State of the network session. | 114 * @param {object} networkStats State of the network session. |
100 */ | 115 */ |
(...skipping 28 matching lines...) Expand all Loading... |
129 if (!isNaN(this.getBandwidthTableCell_(0, 2))) { | 144 if (!isNaN(this.getBandwidthTableCell_(0, 2))) { |
130 expectLE(expectedLength, networkStats.historic_original_content_length); | 145 expectLE(expectedLength, networkStats.historic_original_content_length); |
131 // Column 2 contains historic information. | 146 // Column 2 contains historic information. |
132 this.validateBandwidthTableColumn_(2, expectedLength, expectedLength); | 147 this.validateBandwidthTableColumn_(2, expectedLength, expectedLength); |
133 this.historicVerified = true; | 148 this.historicVerified = true; |
134 this.completeIfDone(); | 149 this.completeIfDone(); |
135 } | 150 } |
136 } | 151 } |
137 }; | 152 }; |
138 | 153 |
| 154 DataReductionProxyTask.prototype = { |
| 155 __proto__: NetInternalsTest.Task.prototype, |
| 156 |
| 157 /** |
| 158 * Switches to the bandwidth tab and waits for arrival of data reduction |
| 159 * proxy information. |
| 160 */ |
| 161 start: function() { |
| 162 chrome.send('enableDataReductionProxy', [this.enabled_]); |
| 163 g_browser.addDataReductionProxyInfoObserver(this, true); |
| 164 NetInternalsTest.switchToView('bandwidth'); |
| 165 }, |
| 166 |
| 167 /** |
| 168 * A task is complete only when session and historic counters have been |
| 169 * verified to reflect the expected number of bytes received. |
| 170 */ |
| 171 completeIfDone: function() { |
| 172 if (this.dataReductionProxyInfoVerified_) { |
| 173 this.onTaskDone(); |
| 174 } |
| 175 }, |
| 176 |
| 177 /** |
| 178 * DataReductionProxyInfoObserver function. Sanity checks the received data |
| 179 * and constructed table. |
| 180 |
| 181 * @param {object} info State of the data reduction proxy. |
| 182 */ |
| 183 onDataReductionProxyInfoChanged: function(info) { |
| 184 if (this.isDone() || this.dataReductionProxyInfoVerified_) |
| 185 return; |
| 186 |
| 187 if (info) { |
| 188 if (this.enabled_) { |
| 189 expectEquals("true", info.enabled); |
| 190 expectEquals("Enabled", $(BandwidthView.ENABLED_ID).innerText); |
| 191 expectNotEquals('', $(BandwidthView.PRIMARY_PROXY_ID).innerText); |
| 192 expectNotEquals('', $(BandwidthView.SECONDARY_PROXY_ID).innerText); |
| 193 } else { |
| 194 expectEquals("false", info.enabled); |
| 195 expectEquals("Disabled", $(BandwidthView.ENABLED_ID).innerText); |
| 196 expectEquals('', $(BandwidthView.PRIMARY_PROXY_ID).innerText); |
| 197 expectEquals('', $(BandwidthView.SECONDARY_PROXY_ID).innerText); |
| 198 // Each event results in 2 rows, and we get 2 events since the startup |
| 199 // event starts as disabled, and we subsequently manually set it to the |
| 200 // disabled state. |
| 201 expectEquals( |
| 202 4, NetInternalsTest.getTbodyNumRows(BandwidthView.EVENTS_TBODY_ID)); |
| 203 } |
| 204 |
| 205 this.dataReductionProxyInfoVerified_ = true; |
| 206 this.completeIfDone(); |
| 207 } |
| 208 |
| 209 } |
| 210 }; |
| 211 |
139 /** | 212 /** |
140 * Loads a page and checks bandwidth statistics. | 213 * Loads a page and checks bandwidth statistics. |
141 */ | 214 */ |
142 TEST_F('NetInternalsTest', 'netInternalsSessionBandwidthSucceed', function() { | 215 TEST_F('NetInternalsTest', 'netInternalsSessionBandwidthSucceed', function() { |
143 var taskQueue = new NetInternalsTest.TaskQueue(true); | 216 var taskQueue = new NetInternalsTest.TaskQueue(true); |
144 taskQueue.addTask( | 217 taskQueue.addTask( |
145 new NetInternalsTest.GetTestServerURLTask('files/title1.html')); | 218 new NetInternalsTest.GetTestServerURLTask('files/title1.html')); |
146 // Load a page with a content length of 66 bytes and a 45-byte favicon. | 219 // Load a page with a content length of 66 bytes and a 45-byte favicon. |
147 taskQueue.addTask(new BandwidthTask(66, 45)); | 220 taskQueue.addTask(new BandwidthTask(66, 45)); |
148 taskQueue.run(); | 221 taskQueue.run(); |
149 }); | 222 }); |
150 | 223 |
| 224 /** |
| 225 * Checks data reduction proxy info when it is enabled. |
| 226 */ |
| 227 TEST_F('NetInternalsTest', 'netInternalsDataReductionProxyEnabled', function() { |
| 228 var taskQueue = new NetInternalsTest.TaskQueue(true); |
| 229 taskQueue.addTask(new DataReductionProxyTask(true)); |
| 230 taskQueue.run(); |
| 231 }); |
| 232 |
| 233 /** |
| 234 * Checks data reduction proxy info when it is disabled. |
| 235 */ |
| 236 TEST_F('NetInternalsTest', |
| 237 'netInternalsDataReductionProxyDisabled', function() { |
| 238 var taskQueue = new NetInternalsTest.TaskQueue(true); |
| 239 taskQueue.addTask(new DataReductionProxyTask(false)); |
| 240 taskQueue.run(); |
| 241 }); |
| 242 |
151 })(); // Anonymous namespace | 243 })(); // Anonymous namespace |
OLD | NEW |