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 |
11 /** | 11 /** |
12 * The task fetches a page as a way of determining if network statistics | 12 * The task fetches a page as a way of determining if network statistics |
13 * (such as the aggregate received content length) change accordingly. | 13 * (such as the aggregate received content length) change accordingly. |
14 * The URL is received from the previous task. | 14 * The URL is received from the previous task. |
15 * | 15 * |
16 * Checks that we see all relevant events and update the corresponding table. | 16 * Checks that we see all relevant events and update the corresponding table. |
17 * | 17 * |
18 * @param {int} expectedLength The length of the content being loaded. | 18 * @param {int} expectedLength The length of the content being loaded. |
19 * @param {int} faviconLength The length a favicon that is received. | 19 * @param {int} faviconLength The length a favicon that is received. |
20 * @extends {NetInternalsTest.Task} | 20 * @extends {NetInternalsTest.Task} |
21 * @constructor | 21 * @constructor |
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.verified = false; |
29 this.historicVerified = false; | |
30 } | 29 } |
31 | 30 |
32 BandwidthTask.prototype = { | 31 BandwidthTask.prototype = { |
33 __proto__: NetInternalsTest.Task.prototype, | 32 __proto__: NetInternalsTest.Task.prototype, |
34 | 33 |
35 /** | 34 /** |
36 * Switches to the bandwidth tab, loads a page in the background, and waits | 35 * Switches to the bandwidth tab, loads a page in the background, and waits |
37 * for the arrival of network statistics. | 36 * for the arrival of network statistics. |
38 * | 37 * |
39 * @param {string} url URL to be fetched. | 38 * @param {string} url URL to be fetched. |
40 */ | 39 */ |
41 start: function(url) { | 40 start: function(url) { |
42 assertEquals('string', typeof url); | 41 assertEquals('string', typeof url); |
43 this.url_ = url; | 42 this.url_ = url; |
44 g_browser.addSessionNetworkStatsObserver(this, true); | 43 g_browser.addSessionNetworkStatsObserver(this, true); |
45 g_browser.addHistoricNetworkStatsObserver(this, true); | |
46 NetInternalsTest.switchToView('bandwidth'); | 44 NetInternalsTest.switchToView('bandwidth'); |
47 chrome.send('loadPage', [this.url_]); | 45 chrome.send('loadPage', [this.url_]); |
48 }, | 46 }, |
49 | 47 |
50 /** | 48 /** |
51 * Returns the float value the specified cell of the bandwidth table. | 49 * Returns the float value the specified cell of the bandwidth table. |
52 */ | 50 */ |
53 getBandwidthTableCell_: function(row, col) { | 51 getBandwidthTableCell_: function(row, col) { |
54 return parseFloat(NetInternalsTest.getTbodyText( | 52 return parseFloat(NetInternalsTest.getTbodyText( |
55 BandwidthView.MAIN_BOX_ID, row, col)); | 53 BandwidthView.MAIN_BOX_ID, row, col)); |
(...skipping 22 matching lines...) Expand all Loading... | |
78 expectLE(expectedReceivedKB, row2); | 76 expectLE(expectedReceivedKB, row2); |
79 expectFalse(isNaN(row3)); | 77 expectFalse(isNaN(row3)); |
80 expectFalse(isNaN(row4)); | 78 expectFalse(isNaN(row4)); |
81 }, | 79 }, |
82 | 80 |
83 /** | 81 /** |
84 * A task is complete only when session and historic counters have been | 82 * A task is complete only when session and historic counters have been |
85 * verified to reflect the expected number of bytes received. | 83 * verified to reflect the expected number of bytes received. |
86 */ | 84 */ |
87 completeIfDone: function() { | 85 completeIfDone: function() { |
88 if (this.historicVerified && this.sessionVerified) { | 86 if (this.verified) { |
89 // Check number of rows in the table. | 87 // Check number of rows in the table. |
90 NetInternalsTest.checkTbodyRows(BandwidthView.MAIN_BOX_ID, 4); | 88 NetInternalsTest.checkTbodyRows(BandwidthView.MAIN_BOX_ID, 4); |
91 this.onTaskDone(); | 89 this.onTaskDone(); |
92 } | 90 } |
93 }, | 91 }, |
94 | 92 |
95 /** | 93 /** |
96 * SessionNetworkStatsObserver function. Sanity checks the received data | 94 * SessionNetworkStatsObserver function. The historic stats and session |
97 * and constructed table. | 95 * stats columns should be updated by the session stats change. Sanity |
96 * checks the received data and constructed table. | |
98 | 97 |
99 * @param {object} networkStats State of the network session. | 98 * @param {object} networkStats State of the network session. |
100 */ | 99 */ |
101 onSessionNetworkStatsChanged: function(networkStats) { | 100 onSessionNetworkStatsChanged: function(networkStats) { |
102 if (this.isDone()) | 101 if (this.isDone()) |
103 return; | 102 return; |
104 // Wait until the received content length is at least the size of | 103 // Wait until the received content length is at least the size of |
105 // our test page and favicon. | 104 // our test page and favicon. |
106 var expectedLength = this.expectedLength_ + this.faviconLength_; | 105 var expectedLength = this.expectedLength_ + this.faviconLength_; |
107 if (networkStats.session_received_content_length >= expectedLength) { | 106 if (networkStats.session_received_content_length >= expectedLength) { |
108 expectLE(expectedLength, networkStats.session_original_content_length); | 107 expectLE(expectedLength, networkStats.session_original_content_length); |
109 // Column 1 contains session information. | 108 // Column 1 contains session information. |
110 this.validateBandwidthTableColumn_(1, expectedLength, expectedLength); | 109 this.validateBandwidthTableColumn_(1, expectedLength, expectedLength); |
111 this.sessionVerified = true; | 110 // Also check column 2, the historic information. |
112 this.completeIfDone(); | |
113 } | |
114 }, | |
115 | |
116 /** | |
117 * HistoricNetworkStatsObserver function. Sanity checks the received data | |
118 * and constructed table. | |
119 | |
120 * @param {object} networkStats State of the network session. | |
121 */ | |
122 onHistoricNetworkStatsChanged: function(networkStats) { | |
123 if (this.isDone()) | |
124 return; | |
125 // Wait until the received content length is at least the size of | |
126 // our test page and favicon. | |
127 var expectedLength = this.expectedLength_ + this.faviconLength_; | |
128 if (networkStats.historic_received_content_length >= expectedLength) { | |
129 expectLE(expectedLength, networkStats.historic_original_content_length); | |
130 // Column 2 contains historic information, and it should be the same as | |
131 // the session information, because previously there was no history. | |
132 this.validateBandwidthTableColumn_(2, expectedLength, expectedLength); | 111 this.validateBandwidthTableColumn_(2, expectedLength, expectedLength); |
133 this.historicVerified = true; | 112 this.verified = true; |
134 this.completeIfDone(); | 113 this.completeIfDone(); |
mmenke
2014/09/15 15:11:02
Shouldn't onHistoricNetworkStatsChanged still be c
megjablon
2014/09/15 18:19:23
The test times out since it waits on the historic
mmenke
2014/09/16 14:18:45
Why can we rely on onSessionNetworkStatsChanged be
| |
135 } | 114 } |
136 } | 115 } |
137 }; | 116 }; |
138 | 117 |
139 /** | 118 /** |
140 * Loads a page and checks bandwidth statistics. | 119 * Loads a page and checks bandwidth statistics. |
141 */ | 120 */ |
142 TEST_F('NetInternalsTest', 'netInternalsSessionBandwidthSucceed', function() { | 121 TEST_F('NetInternalsTest', 'netInternalsSessionBandwidthSucceed', function() { |
143 var taskQueue = new NetInternalsTest.TaskQueue(true); | 122 var taskQueue = new NetInternalsTest.TaskQueue(true); |
144 taskQueue.addTask( | 123 taskQueue.addTask( |
145 new NetInternalsTest.GetTestServerURLTask('files/title1.html')); | 124 new NetInternalsTest.GetTestServerURLTask('files/title1.html')); |
146 // Load a page with a content length of 66 bytes and a 45-byte favicon. | 125 // Load a page with a content length of 66 bytes and a 45-byte favicon. |
147 taskQueue.addTask(new BandwidthTask(66, 45)); | 126 taskQueue.addTask(new BandwidthTask(66, 45)); |
148 taskQueue.run(); | 127 taskQueue.run(); |
149 }); | 128 }); |
150 | 129 |
151 })(); // Anonymous namespace | 130 })(); // Anonymous namespace |
OLD | NEW |