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

Side by Side Diff: chrome/test/data/webui/net_internals/bandwidth_view.js

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

Powered by Google App Engine
This is Rietveld 408576698