OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/net/load_timing_observer.h" | 5 #include "chrome/browser/net/load_timing_observer.h" |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/format_macros.h" | 8 #include "base/format_macros.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/time.h" | 10 #include "base/time.h" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 | 76 |
77 void AddEndSocketEntries(LoadTimingObserver& observer, uint32 id) { | 77 void AddEndSocketEntries(LoadTimingObserver& observer, uint32 id) { |
78 NetLog::Source source(NetLog::SOURCE_SOCKET, id); | 78 NetLog::Source source(NetLog::SOURCE_SOCKET, id); |
79 AddEndEntry(observer, source, NetLog::TYPE_SOCKET_ALIVE, NULL); | 79 AddEndEntry(observer, source, NetLog::TYPE_SOCKET_ALIVE, NULL); |
80 } | 80 } |
81 | 81 |
82 } // namespace | 82 } // namespace |
83 | 83 |
84 // Test that URLRequest with no load timing flag is not processed. | 84 // Test that URLRequest with no load timing flag is not processed. |
85 TEST(LoadTimingObserverTest, NoLoadTimingEnabled) { | 85 TEST(LoadTimingObserverTest, NoLoadTimingEnabled) { |
| 86 MessageLoop message_loop; |
| 87 BrowserThread io_thread(BrowserThread::IO, &message_loop); |
86 LoadTimingObserver observer; | 88 LoadTimingObserver observer; |
87 | 89 |
88 AddStartURLRequestEntries(observer, 0, false); | 90 AddStartURLRequestEntries(observer, 0, false); |
89 LoadTimingObserver::URLRequestRecord* record = | 91 LoadTimingObserver::URLRequestRecord* record = |
90 observer.GetURLRequestRecord(0); | 92 observer.GetURLRequestRecord(0); |
91 ASSERT_TRUE(record == NULL); | 93 ASSERT_TRUE(record == NULL); |
92 } | 94 } |
93 | 95 |
94 // Test that URLRequestRecord is created, deleted and is not growing unbound. | 96 // Test that URLRequestRecord is created, deleted and is not growing unbound. |
95 TEST(LoadTimingObserverTest, URLRequestRecord) { | 97 TEST(LoadTimingObserverTest, URLRequestRecord) { |
| 98 MessageLoop message_loop; |
| 99 BrowserThread io_thread(BrowserThread::IO, &message_loop); |
96 LoadTimingObserver observer; | 100 LoadTimingObserver observer; |
97 | 101 |
98 // Create record. | 102 // Create record. |
99 AddStartURLRequestEntries(observer, 0, true); | 103 AddStartURLRequestEntries(observer, 0, true); |
100 LoadTimingObserver::URLRequestRecord* record = | 104 LoadTimingObserver::URLRequestRecord* record = |
101 observer.GetURLRequestRecord(0); | 105 observer.GetURLRequestRecord(0); |
102 ASSERT_FALSE(record == NULL); | 106 ASSERT_FALSE(record == NULL); |
103 | 107 |
104 // Collect record. | 108 // Collect record. |
105 AddEndURLRequestEntries(observer, 0); | 109 AddEndURLRequestEntries(observer, 0); |
106 record = observer.GetURLRequestRecord(0); | 110 record = observer.GetURLRequestRecord(0); |
107 ASSERT_TRUE(record == NULL); | 111 ASSERT_TRUE(record == NULL); |
108 | 112 |
109 // Check unbound growth. | 113 // Check unbound growth. |
110 for (size_t i = 1; i < 1100; ++i) | 114 for (size_t i = 1; i < 1100; ++i) |
111 AddStartURLRequestEntries(observer, i, true); | 115 AddStartURLRequestEntries(observer, i, true); |
112 record = observer.GetURLRequestRecord(1); | 116 record = observer.GetURLRequestRecord(1); |
113 ASSERT_TRUE(record == NULL); | 117 ASSERT_TRUE(record == NULL); |
114 } | 118 } |
115 | 119 |
116 // Test that ConnectJobRecord is created, deleted and is not growing unbound. | 120 // Test that ConnectJobRecord is created, deleted and is not growing unbound. |
117 TEST(LoadTimingObserverTest, ConnectJobRecord) { | 121 TEST(LoadTimingObserverTest, ConnectJobRecord) { |
| 122 MessageLoop message_loop; |
| 123 BrowserThread io_thread(BrowserThread::IO, &message_loop); |
118 LoadTimingObserver observer; | 124 LoadTimingObserver observer; |
119 | 125 |
120 // Create record. | 126 // Create record. |
121 AddStartConnectJobEntries(observer, 0); | 127 AddStartConnectJobEntries(observer, 0); |
122 ASSERT_FALSE(observer.connect_job_to_record_.find(0) == | 128 ASSERT_FALSE(observer.connect_job_to_record_.find(0) == |
123 observer.connect_job_to_record_.end()); | 129 observer.connect_job_to_record_.end()); |
124 | 130 |
125 // Collect record. | 131 // Collect record. |
126 AddEndConnectJobEntries(observer, 0); | 132 AddEndConnectJobEntries(observer, 0); |
127 ASSERT_TRUE(observer.connect_job_to_record_.find(0) == | 133 ASSERT_TRUE(observer.connect_job_to_record_.find(0) == |
128 observer.connect_job_to_record_.end()); | 134 observer.connect_job_to_record_.end()); |
129 | 135 |
130 // Check unbound growth. | 136 // Check unbound growth. |
131 for (size_t i = 1; i < 1100; ++i) | 137 for (size_t i = 1; i < 1100; ++i) |
132 AddStartConnectJobEntries(observer, i); | 138 AddStartConnectJobEntries(observer, i); |
133 ASSERT_TRUE(observer.connect_job_to_record_.find(1) == | 139 ASSERT_TRUE(observer.connect_job_to_record_.find(1) == |
134 observer.connect_job_to_record_.end()); | 140 observer.connect_job_to_record_.end()); |
135 } | 141 } |
136 | 142 |
137 // Test that SocketRecord is created, deleted and is not growing unbound. | 143 // Test that SocketRecord is created, deleted and is not growing unbound. |
138 TEST(LoadTimingObserverTest, SocketRecord) { | 144 TEST(LoadTimingObserverTest, SocketRecord) { |
| 145 MessageLoop message_loop; |
| 146 BrowserThread io_thread(BrowserThread::IO, &message_loop); |
139 LoadTimingObserver observer; | 147 LoadTimingObserver observer; |
140 | 148 |
141 // Create record. | 149 // Create record. |
142 AddStartSocketEntries(observer, 0); | 150 AddStartSocketEntries(observer, 0); |
143 ASSERT_FALSE(observer.socket_to_record_.find(0) == | 151 ASSERT_FALSE(observer.socket_to_record_.find(0) == |
144 observer.socket_to_record_.end()); | 152 observer.socket_to_record_.end()); |
145 | 153 |
146 // Collect record. | 154 // Collect record. |
147 AddEndSocketEntries(observer, 0); | 155 AddEndSocketEntries(observer, 0); |
148 ASSERT_TRUE(observer.socket_to_record_.find(0) == | 156 ASSERT_TRUE(observer.socket_to_record_.find(0) == |
149 observer.socket_to_record_.end()); | 157 observer.socket_to_record_.end()); |
150 | 158 |
151 | 159 |
152 // Check unbound growth. | 160 // Check unbound growth. |
153 for (size_t i = 1; i < 1100; ++i) | 161 for (size_t i = 1; i < 1100; ++i) |
154 AddStartSocketEntries(observer, i); | 162 AddStartSocketEntries(observer, i); |
155 ASSERT_TRUE(observer.socket_to_record_.find(1) == | 163 ASSERT_TRUE(observer.socket_to_record_.find(1) == |
156 observer.socket_to_record_.end()); | 164 observer.socket_to_record_.end()); |
157 } | 165 } |
158 | 166 |
159 // Test that basic time is set to the request. | 167 // Test that basic time is set to the request. |
160 TEST(LoadTimingObserverTest, BaseTicks) { | 168 TEST(LoadTimingObserverTest, BaseTicks) { |
| 169 MessageLoop message_loop; |
| 170 BrowserThread io_thread(BrowserThread::IO, &message_loop); |
161 LoadTimingObserver observer; | 171 LoadTimingObserver observer; |
162 current_time += TimeDelta::FromSeconds(1); | 172 current_time += TimeDelta::FromSeconds(1); |
163 AddStartURLRequestEntries(observer, 0, true); | 173 AddStartURLRequestEntries(observer, 0, true); |
164 | 174 |
165 LoadTimingObserver::URLRequestRecord* record = | 175 LoadTimingObserver::URLRequestRecord* record = |
166 observer.GetURLRequestRecord(0); | 176 observer.GetURLRequestRecord(0); |
167 ASSERT_EQ(1000000, record->base_ticks.ToInternalValue()); | 177 ASSERT_EQ(1000000, record->base_ticks.ToInternalValue()); |
168 } | 178 } |
169 | 179 |
170 // Test proxy time detection. | 180 // Test proxy time detection. |
171 TEST(LoadTimingObserverTest, ProxyTime) { | 181 TEST(LoadTimingObserverTest, ProxyTime) { |
| 182 MessageLoop message_loop; |
| 183 BrowserThread io_thread(BrowserThread::IO, &message_loop); |
172 LoadTimingObserver observer; | 184 LoadTimingObserver observer; |
173 current_time += TimeDelta::FromSeconds(1); | 185 current_time += TimeDelta::FromSeconds(1); |
174 | 186 |
175 AddStartURLRequestEntries(observer, 0, true); | 187 AddStartURLRequestEntries(observer, 0, true); |
176 NetLog::Source source(NetLog::SOURCE_URL_REQUEST, 0); | 188 NetLog::Source source(NetLog::SOURCE_URL_REQUEST, 0); |
177 | 189 |
178 current_time += TimeDelta::FromSeconds(2); | 190 current_time += TimeDelta::FromSeconds(2); |
179 AddStartEntry(observer, source, NetLog::TYPE_PROXY_SERVICE, NULL); | 191 AddStartEntry(observer, source, NetLog::TYPE_PROXY_SERVICE, NULL); |
180 current_time += TimeDelta::FromSeconds(3); | 192 current_time += TimeDelta::FromSeconds(3); |
181 AddEndEntry(observer, source, NetLog::TYPE_PROXY_SERVICE, NULL); | 193 AddEndEntry(observer, source, NetLog::TYPE_PROXY_SERVICE, NULL); |
182 | 194 |
183 LoadTimingObserver::URLRequestRecord* record = | 195 LoadTimingObserver::URLRequestRecord* record = |
184 observer.GetURLRequestRecord(0); | 196 observer.GetURLRequestRecord(0); |
185 ASSERT_EQ(2000, record->timing.proxy_start); | 197 ASSERT_EQ(2000, record->timing.proxy_start); |
186 ASSERT_EQ(5000, record->timing.proxy_end); | 198 ASSERT_EQ(5000, record->timing.proxy_end); |
187 } | 199 } |
188 | 200 |
189 // Test connect time detection. | 201 // Test connect time detection. |
190 TEST(LoadTimingObserverTest, ConnectTime) { | 202 TEST(LoadTimingObserverTest, ConnectTime) { |
| 203 MessageLoop message_loop; |
| 204 BrowserThread io_thread(BrowserThread::IO, &message_loop); |
191 LoadTimingObserver observer; | 205 LoadTimingObserver observer; |
192 current_time += TimeDelta::FromSeconds(1); | 206 current_time += TimeDelta::FromSeconds(1); |
193 | 207 |
194 AddStartURLRequestEntries(observer, 0, true); | 208 AddStartURLRequestEntries(observer, 0, true); |
195 NetLog::Source source(NetLog::SOURCE_URL_REQUEST, 0); | 209 NetLog::Source source(NetLog::SOURCE_URL_REQUEST, 0); |
196 | 210 |
197 current_time += TimeDelta::FromSeconds(2); | 211 current_time += TimeDelta::FromSeconds(2); |
198 AddStartEntry(observer, source, NetLog::TYPE_SOCKET_POOL, NULL); | 212 AddStartEntry(observer, source, NetLog::TYPE_SOCKET_POOL, NULL); |
199 current_time += TimeDelta::FromSeconds(3); | 213 current_time += TimeDelta::FromSeconds(3); |
200 AddEndEntry(observer, source, NetLog::TYPE_SOCKET_POOL, NULL); | 214 AddEndEntry(observer, source, NetLog::TYPE_SOCKET_POOL, NULL); |
201 | 215 |
202 LoadTimingObserver::URLRequestRecord* record = | 216 LoadTimingObserver::URLRequestRecord* record = |
203 observer.GetURLRequestRecord(0); | 217 observer.GetURLRequestRecord(0); |
204 ASSERT_EQ(2000, record->timing.connect_start); | 218 ASSERT_EQ(2000, record->timing.connect_start); |
205 ASSERT_EQ(5000, record->timing.connect_end); | 219 ASSERT_EQ(5000, record->timing.connect_end); |
206 } | 220 } |
207 | 221 |
208 // Test dns time detection. | 222 // Test dns time detection. |
209 TEST(LoadTimingObserverTest, DnsTime) { | 223 TEST(LoadTimingObserverTest, DnsTime) { |
| 224 MessageLoop message_loop; |
| 225 BrowserThread io_thread(BrowserThread::IO, &message_loop); |
210 LoadTimingObserver observer; | 226 LoadTimingObserver observer; |
211 | 227 |
212 // Start request. | 228 // Start request. |
213 NetLog::Source source(NetLog::SOURCE_URL_REQUEST, 0); | 229 NetLog::Source source(NetLog::SOURCE_URL_REQUEST, 0); |
214 AddStartURLRequestEntries(observer, 0, true); | 230 AddStartURLRequestEntries(observer, 0, true); |
215 current_time += TimeDelta::FromSeconds(1); | 231 current_time += TimeDelta::FromSeconds(1); |
216 | 232 |
217 // Add resolver entry. | 233 // Add resolver entry. |
218 AddStartConnectJobEntries(observer, 1); | 234 AddStartConnectJobEntries(observer, 1); |
219 NetLog::Source connect_source(NetLog::SOURCE_CONNECT_JOB, 1); | 235 NetLog::Source connect_source(NetLog::SOURCE_CONNECT_JOB, 1); |
(...skipping 14 matching lines...) Expand all Loading... |
234 params.get()); | 250 params.get()); |
235 | 251 |
236 LoadTimingObserver::URLRequestRecord* record = | 252 LoadTimingObserver::URLRequestRecord* record = |
237 observer.GetURLRequestRecord(0); | 253 observer.GetURLRequestRecord(0); |
238 ASSERT_EQ(1000, record->timing.dns_start); | 254 ASSERT_EQ(1000, record->timing.dns_start); |
239 ASSERT_EQ(3000, record->timing.dns_end); | 255 ASSERT_EQ(3000, record->timing.dns_end); |
240 } | 256 } |
241 | 257 |
242 // Test send time detection. | 258 // Test send time detection. |
243 TEST(LoadTimingObserverTest, SendTime) { | 259 TEST(LoadTimingObserverTest, SendTime) { |
| 260 MessageLoop message_loop; |
| 261 BrowserThread io_thread(BrowserThread::IO, &message_loop); |
244 LoadTimingObserver observer; | 262 LoadTimingObserver observer; |
245 | 263 |
246 // Start request. | 264 // Start request. |
247 NetLog::Source source(NetLog::SOURCE_URL_REQUEST, 0); | 265 NetLog::Source source(NetLog::SOURCE_URL_REQUEST, 0); |
248 AddStartURLRequestEntries(observer, 0, true); | 266 AddStartURLRequestEntries(observer, 0, true); |
249 current_time += TimeDelta::FromSeconds(2); | 267 current_time += TimeDelta::FromSeconds(2); |
250 | 268 |
251 // Add send request entry. | 269 // Add send request entry. |
252 AddStartEntry(observer, | 270 AddStartEntry(observer, |
253 source, | 271 source, |
254 NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST, | 272 NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST, |
255 NULL); | 273 NULL); |
256 current_time += TimeDelta::FromSeconds(5); | 274 current_time += TimeDelta::FromSeconds(5); |
257 AddEndEntry(observer, | 275 AddEndEntry(observer, |
258 source, | 276 source, |
259 NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST, | 277 NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST, |
260 NULL); | 278 NULL); |
261 | 279 |
262 LoadTimingObserver::URLRequestRecord* record = | 280 LoadTimingObserver::URLRequestRecord* record = |
263 observer.GetURLRequestRecord(0); | 281 observer.GetURLRequestRecord(0); |
264 ASSERT_EQ(2000, record->timing.send_start); | 282 ASSERT_EQ(2000, record->timing.send_start); |
265 ASSERT_EQ(7000, record->timing.send_end); | 283 ASSERT_EQ(7000, record->timing.send_end); |
266 } | 284 } |
267 | 285 |
268 // Test receive time detection. | 286 // Test receive time detection. |
269 TEST(LoadTimingObserverTest, ReceiveTime) { | 287 TEST(LoadTimingObserverTest, ReceiveTime) { |
| 288 MessageLoop message_loop; |
| 289 BrowserThread io_thread(BrowserThread::IO, &message_loop); |
270 LoadTimingObserver observer; | 290 LoadTimingObserver observer; |
271 | 291 |
272 // Start request. | 292 // Start request. |
273 NetLog::Source source(NetLog::SOURCE_URL_REQUEST, 0); | 293 NetLog::Source source(NetLog::SOURCE_URL_REQUEST, 0); |
274 AddStartURLRequestEntries(observer, 0, true); | 294 AddStartURLRequestEntries(observer, 0, true); |
275 current_time += TimeDelta::FromSeconds(2); | 295 current_time += TimeDelta::FromSeconds(2); |
276 | 296 |
277 // Add send request entry. | 297 // Add send request entry. |
278 AddStartEntry(observer, | 298 AddStartEntry(observer, |
279 source, | 299 source, |
280 NetLog::TYPE_HTTP_TRANSACTION_READ_HEADERS, | 300 NetLog::TYPE_HTTP_TRANSACTION_READ_HEADERS, |
281 NULL); | 301 NULL); |
282 current_time += TimeDelta::FromSeconds(5); | 302 current_time += TimeDelta::FromSeconds(5); |
283 AddEndEntry(observer, | 303 AddEndEntry(observer, |
284 source, | 304 source, |
285 NetLog::TYPE_HTTP_TRANSACTION_READ_HEADERS, | 305 NetLog::TYPE_HTTP_TRANSACTION_READ_HEADERS, |
286 NULL); | 306 NULL); |
287 | 307 |
288 LoadTimingObserver::URLRequestRecord* record = | 308 LoadTimingObserver::URLRequestRecord* record = |
289 observer.GetURLRequestRecord(0); | 309 observer.GetURLRequestRecord(0); |
290 ASSERT_EQ(2000, record->timing.receive_headers_start); | 310 ASSERT_EQ(2000, record->timing.receive_headers_start); |
291 ASSERT_EQ(7000, record->timing.receive_headers_end); | 311 ASSERT_EQ(7000, record->timing.receive_headers_end); |
292 } | 312 } |
293 | 313 |
294 // Test ssl time detection. | 314 // Test ssl time detection. |
295 TEST(LoadTimingObserverTest, SslTime) { | 315 TEST(LoadTimingObserverTest, SslTime) { |
| 316 MessageLoop message_loop; |
| 317 BrowserThread io_thread(BrowserThread::IO, &message_loop); |
296 LoadTimingObserver observer; | 318 LoadTimingObserver observer; |
297 | 319 |
298 // Start request. | 320 // Start request. |
299 NetLog::Source source(NetLog::SOURCE_URL_REQUEST, 0); | 321 NetLog::Source source(NetLog::SOURCE_URL_REQUEST, 0); |
300 AddStartURLRequestEntries(observer, 0, true); | 322 AddStartURLRequestEntries(observer, 0, true); |
301 current_time += TimeDelta::FromSeconds(1); | 323 current_time += TimeDelta::FromSeconds(1); |
302 | 324 |
303 // Add resolver entry. | 325 // Add resolver entry. |
304 AddStartSocketEntries(observer, 1); | 326 AddStartSocketEntries(observer, 1); |
305 NetLog::Source socket_source(NetLog::SOURCE_SOCKET, 1); | 327 NetLog::Source socket_source(NetLog::SOURCE_SOCKET, 1); |
306 AddStartEntry(observer, socket_source, NetLog::TYPE_SSL_CONNECT, NULL); | 328 AddStartEntry(observer, socket_source, NetLog::TYPE_SSL_CONNECT, NULL); |
307 current_time += TimeDelta::FromSeconds(2); | 329 current_time += TimeDelta::FromSeconds(2); |
308 AddEndEntry(observer, socket_source, NetLog::TYPE_SSL_CONNECT, NULL); | 330 AddEndEntry(observer, socket_source, NetLog::TYPE_SSL_CONNECT, NULL); |
309 | 331 |
310 // Bind to connect job. | 332 // Bind to connect job. |
311 scoped_refptr<net::NetLogSourceParameter> params( | 333 scoped_refptr<net::NetLogSourceParameter> params( |
312 new net::NetLogSourceParameter("socket", socket_source)); | 334 new net::NetLogSourceParameter("socket", socket_source)); |
313 AddStartEntry(observer, | 335 AddStartEntry(observer, |
314 source, | 336 source, |
315 NetLog::TYPE_SOCKET_POOL_BOUND_TO_SOCKET, | 337 NetLog::TYPE_SOCKET_POOL_BOUND_TO_SOCKET, |
316 params.get()); | 338 params.get()); |
317 | 339 |
318 LoadTimingObserver::URLRequestRecord* record = | 340 LoadTimingObserver::URLRequestRecord* record = |
319 observer.GetURLRequestRecord(0); | 341 observer.GetURLRequestRecord(0); |
320 ASSERT_EQ(1000, record->timing.ssl_start); | 342 ASSERT_EQ(1000, record->timing.ssl_start); |
321 ASSERT_EQ(3000, record->timing.ssl_end); | 343 ASSERT_EQ(3000, record->timing.ssl_end); |
322 } | 344 } |
OLD | NEW |