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 24 matching lines...) Expand all Loading... | |
35 /** | 35 /** |
36 * Switches to the bandwidth tab, loads a page in the background, and waits | 36 * Switches to the bandwidth tab, loads a page in the background, and waits |
37 * for the arrival of network statistics. | 37 * for the arrival of network statistics. |
38 * | 38 * |
39 * @param {string} url URL to be fetched. | 39 * @param {string} url URL to be fetched. |
40 */ | 40 */ |
41 start: function(url) { | 41 start: function(url) { |
42 assertEquals('string', typeof url); | 42 assertEquals('string', typeof url); |
43 this.url_ = url; | 43 this.url_ = url; |
44 g_browser.addSessionNetworkStatsObserver(this, true); | 44 g_browser.addSessionNetworkStatsObserver(this, true); |
45 g_browser.addHistoricNetworkStatsObserver(this, true); | 45 g_browser.addHistoricNetworkStatsObserver(this, false); |
mmenke
2014/09/18 14:54:46
Hrm...Really not sure why this is needed - we shou
| |
46 NetInternalsTest.switchToView('bandwidth'); | 46 NetInternalsTest.switchToView('bandwidth'); |
47 chrome.send('loadPage', [this.url_]); | 47 chrome.send('loadPage', [this.url_]); |
48 }, | 48 }, |
49 | 49 |
50 /** | 50 /** |
51 * Returns the float value the specified cell of the bandwidth table. | 51 * Returns the float value the specified cell of the bandwidth table. |
52 */ | 52 */ |
53 getBandwidthTableCell_: function(row, col) { | 53 getBandwidthTableCell_: function(row, col) { |
54 return parseFloat(NetInternalsTest.getTbodyText( | 54 return parseFloat(NetInternalsTest.getTbodyText( |
55 BandwidthView.MAIN_BOX_ID, row, col)); | 55 BandwidthView.MAIN_BOX_ID, row, col)); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
113 } | 113 } |
114 }, | 114 }, |
115 | 115 |
116 /** | 116 /** |
117 * HistoricNetworkStatsObserver function. Sanity checks the received data | 117 * HistoricNetworkStatsObserver function. Sanity checks the received data |
118 * and constructed table. | 118 * and constructed table. |
119 | 119 |
120 * @param {object} networkStats State of the network session. | 120 * @param {object} networkStats State of the network session. |
121 */ | 121 */ |
122 onHistoricNetworkStatsChanged: function(networkStats) { | 122 onHistoricNetworkStatsChanged: function(networkStats) { |
123 if (this.isDone()) | 123 if (this.isDone() || this.historicVerified) |
mmenke
2014/09/18 14:54:46
nit: May as well "|| this.sessionVerified" to the
| |
124 return; | 124 return; |
125 // Wait until the received content length is at least the size of | 125 console.log("checking network stats"); |
mmenke
2014/09/18 14:54:46
nit: Remove logging.
| |
126 // our test page and favicon. | 126 // The received content length should be zero since the historic |
127 var expectedLength = this.expectedLength_ + this.faviconLength_; | 127 // information only updates every hour. |
128 if (networkStats.historic_received_content_length >= expectedLength) { | 128 var expectedLength = 0; |
129 // Wait until the table has changed, otherwise the columns will be NaN | |
130 if (!isNaN(this.getBandwidthTableCell_(0, 2))) { | |
129 expectLE(expectedLength, networkStats.historic_original_content_length); | 131 expectLE(expectedLength, networkStats.historic_original_content_length); |
130 // Column 2 contains historic information, and it should be the same as | 132 // Column 2 contains historic information. |
131 // the session information, because previously there was no history. | |
132 this.validateBandwidthTableColumn_(2, expectedLength, expectedLength); | 133 this.validateBandwidthTableColumn_(2, expectedLength, expectedLength); |
133 this.historicVerified = true; | 134 this.historicVerified = true; |
134 this.completeIfDone(); | 135 this.completeIfDone(); |
135 } | 136 } |
136 } | 137 } |
137 }; | 138 }; |
138 | 139 |
139 /** | 140 /** |
140 * Loads a page and checks bandwidth statistics. | 141 * Loads a page and checks bandwidth statistics. |
141 */ | 142 */ |
142 TEST_F('NetInternalsTest', 'netInternalsSessionBandwidthSucceed', function() { | 143 TEST_F('NetInternalsTest', 'netInternalsSessionBandwidthSucceed', function() { |
143 var taskQueue = new NetInternalsTest.TaskQueue(true); | 144 var taskQueue = new NetInternalsTest.TaskQueue(true); |
144 taskQueue.addTask( | 145 taskQueue.addTask( |
145 new NetInternalsTest.GetTestServerURLTask('files/title1.html')); | 146 new NetInternalsTest.GetTestServerURLTask('files/title1.html')); |
146 // Load a page with a content length of 66 bytes and a 45-byte favicon. | 147 // Load a page with a content length of 66 bytes and a 45-byte favicon. |
147 taskQueue.addTask(new BandwidthTask(66, 45)); | 148 taskQueue.addTask(new BandwidthTask(66, 45)); |
148 taskQueue.run(); | 149 taskQueue.run(); |
149 }); | 150 }); |
150 | 151 |
151 })(); // Anonymous namespace | 152 })(); // Anonymous namespace |
OLD | NEW |