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

Side by Side Diff: chrome/browser/net/load_timing_observer_unittest.cc

Issue 10399083: Make NetLog take in callbacks that return Values (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Update comments Created 8 years, 6 months 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 | Annotate | Revision Log
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 "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/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/stringprintf.h" 10 #include "base/stringprintf.h"
11 #include "base/time.h" 11 #include "base/time.h"
12 #include "content/public/test/test_browser_thread.h" 12 #include "content/public/test/test_browser_thread.h"
13 #include "net/base/load_flags.h" 13 #include "net/base/load_flags.h"
14 #include "net/url_request/url_request_netlog_params.h" 14 #include "net/url_request/url_request_netlog_params.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 16
17 namespace { 17 namespace {
18 18
19 using base::TimeDelta; 19 using base::TimeDelta;
20 using content::BrowserThread; 20 using content::BrowserThread;
21 using net::NetLog; 21 using net::NetLog;
22 22
23 class TestLoadTimingObserver : public LoadTimingObserver {
24 public:
25 TestLoadTimingObserver() {}
26 virtual ~TestLoadTimingObserver() {}
27
28 void IncementTime(base::TimeDelta delta) {
29 current_time_ += delta;
30 }
31
32 virtual base::TimeTicks GetCurrentTime() const OVERRIDE {
33 return current_time_;
34 }
35
36 private:
37 base::TimeTicks current_time_;
38
39 DISALLOW_COPY_AND_ASSIGN(TestLoadTimingObserver);
40 };
41
23 // Serves to identify the current thread as the IO thread. 42 // Serves to identify the current thread as the IO thread.
24 class LoadTimingObserverTest : public testing::Test { 43 class LoadTimingObserverTest : public testing::Test {
25 public: 44 public:
26 LoadTimingObserverTest() : io_thread_(BrowserThread::IO, &message_loop_) { 45 LoadTimingObserverTest() : io_thread_(BrowserThread::IO, &message_loop_) {
27 } 46 }
28 47
48 protected:
49 TestLoadTimingObserver observer_;
50
29 private: 51 private:
30 MessageLoop message_loop_; 52 MessageLoop message_loop_;
31 content::TestBrowserThread io_thread_; 53 content::TestBrowserThread io_thread_;
32 }; 54 };
33 55
34 base::TimeTicks current_time; 56 void AddStartEntry(LoadTimingObserver& observer,
57 const NetLog::Source& source,
58 NetLog::EventType type) {
59 net::NetLog::Entry entry(type,
60 source,
61 NetLog::PHASE_BEGIN,
62 NULL,
63 NetLog::LOG_BASIC);
64 observer.OnAddEntry(entry);
65 }
35 66
36 void AddStartEntry(LoadTimingObserver& observer, 67 void AddStartEntry(LoadTimingObserver& observer,
37 const NetLog::Source& source, 68 const NetLog::Source& source,
38 NetLog::EventType type, 69 NetLog::EventType type,
39 NetLog::EventParameters* params) { 70 const NetLog::ParametersCallback& params_callback) {
40 observer.OnAddEntry(type, current_time, source, NetLog::PHASE_BEGIN, params); 71 net::NetLog::Entry entry(type,
72 source,
73 NetLog::PHASE_BEGIN,
74 &params_callback,
75 NetLog::LOG_BASIC);
76 observer.OnAddEntry(entry);
41 } 77 }
42 78
43 void AddEndEntry(LoadTimingObserver& observer, 79 void AddEndEntry(LoadTimingObserver& observer,
44 const NetLog::Source& source, 80 const NetLog::Source& source,
45 NetLog::EventType type, 81 NetLog::EventType type) {
46 NetLog::EventParameters* params) { 82 net::NetLog::Entry entry(type,
47 observer.OnAddEntry(type, current_time, source, NetLog::PHASE_END, params); 83 source,
84 NetLog::PHASE_END,
85 NULL,
86 NetLog::LOG_BASIC);
87 observer.OnAddEntry(entry);
48 } 88 }
49 89
50 void AddStartURLRequestEntries(LoadTimingObserver& observer, 90 void AddStartURLRequestEntries(LoadTimingObserver& observer,
51 uint32 id, 91 uint32 id,
52 bool request_timing) { 92 bool request_timing) {
53 scoped_refptr<net::URLRequestStartEventParameters> params(
54 new net::URLRequestStartEventParameters(
55 GURL(base::StringPrintf("http://req%d", id)),
56 "GET",
57 request_timing ? net::LOAD_ENABLE_LOAD_TIMING : 0,
58 net::LOW));
59 NetLog::Source source(NetLog::SOURCE_URL_REQUEST, id); 93 NetLog::Source source(NetLog::SOURCE_URL_REQUEST, id);
60 AddStartEntry(observer, source, NetLog::TYPE_REQUEST_ALIVE, NULL); 94 AddStartEntry(observer, source, NetLog::TYPE_REQUEST_ALIVE);
61 AddStartEntry(observer, 95 AddStartEntry(
62 source, 96 observer,
63 NetLog::TYPE_URL_REQUEST_START_JOB, 97 source,
64 params.get()); 98 NetLog::TYPE_URL_REQUEST_START_JOB,
99 base::Bind(&net::NetLogURLRequestStartCallback,
100 GURL(base::StringPrintf("http://req%d", id)),
101 "GET",
102 request_timing ? net::LOAD_ENABLE_LOAD_TIMING : 0,
103 net::LOW));
65 } 104 }
66 105
67 void AddEndURLRequestEntries(LoadTimingObserver& observer, uint32 id) { 106 void AddEndURLRequestEntries(LoadTimingObserver& observer, uint32 id) {
68 NetLog::Source source(NetLog::SOURCE_URL_REQUEST, id); 107 NetLog::Source source(NetLog::SOURCE_URL_REQUEST, id);
69 AddEndEntry(observer, source, NetLog::TYPE_REQUEST_ALIVE, NULL); 108 AddEndEntry(observer, source, NetLog::TYPE_REQUEST_ALIVE);
70 AddEndEntry(observer, 109 AddEndEntry(observer, source, NetLog::TYPE_URL_REQUEST_START_JOB);
71 source,
72 NetLog::TYPE_URL_REQUEST_START_JOB,
73 NULL);
74 } 110 }
75 111
76 void AddStartHTTPStreamJobEntries(LoadTimingObserver& observer, uint32 id) { 112 void AddStartHTTPStreamJobEntries(LoadTimingObserver& observer, uint32 id) {
77 NetLog::Source source(NetLog::SOURCE_HTTP_STREAM_JOB, id); 113 NetLog::Source source(NetLog::SOURCE_HTTP_STREAM_JOB, id);
78 AddStartEntry(observer, source, NetLog::TYPE_HTTP_STREAM_JOB, NULL); 114 AddStartEntry(observer, source, NetLog::TYPE_HTTP_STREAM_JOB);
79 } 115 }
80 116
81 void AddEndHTTPStreamJobEntries(LoadTimingObserver& observer, uint32 id) { 117 void AddEndHTTPStreamJobEntries(LoadTimingObserver& observer, uint32 id) {
82 NetLog::Source source(NetLog::SOURCE_HTTP_STREAM_JOB, id); 118 NetLog::Source source(NetLog::SOURCE_HTTP_STREAM_JOB, id);
83 AddEndEntry(observer, source, NetLog::TYPE_HTTP_STREAM_JOB, NULL); 119 AddEndEntry(observer, source, NetLog::TYPE_HTTP_STREAM_JOB);
84 } 120 }
85 121
86 void AddStartConnectJobEntries(LoadTimingObserver& observer, uint32 id) { 122 void AddStartConnectJobEntries(LoadTimingObserver& observer, uint32 id) {
87 NetLog::Source source(NetLog::SOURCE_CONNECT_JOB, id); 123 NetLog::Source source(NetLog::SOURCE_CONNECT_JOB, id);
88 AddStartEntry(observer, source, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB, NULL); 124 AddStartEntry(observer, source, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB);
89 } 125 }
90 126
91 void AddEndConnectJobEntries(LoadTimingObserver& observer, uint32 id) { 127 void AddEndConnectJobEntries(LoadTimingObserver& observer, uint32 id) {
92 NetLog::Source source(NetLog::SOURCE_CONNECT_JOB, id); 128 NetLog::Source source(NetLog::SOURCE_CONNECT_JOB, id);
93 AddEndEntry(observer, source, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB, NULL); 129 AddEndEntry(observer, source, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB);
94 } 130 }
95 131
96 void AddStartSocketEntries(LoadTimingObserver& observer, uint32 id) { 132 void AddStartSocketEntries(LoadTimingObserver& observer, uint32 id) {
97 NetLog::Source source(NetLog::SOURCE_SOCKET, id); 133 NetLog::Source source(NetLog::SOURCE_SOCKET, id);
98 AddStartEntry(observer, source, NetLog::TYPE_SOCKET_ALIVE, NULL); 134 AddStartEntry(observer, source, NetLog::TYPE_SOCKET_ALIVE);
99 } 135 }
100 136
101 void AddEndSocketEntries(LoadTimingObserver& observer, uint32 id) { 137 void AddEndSocketEntries(LoadTimingObserver& observer, uint32 id) {
102 NetLog::Source source(NetLog::SOURCE_SOCKET, id); 138 NetLog::Source source(NetLog::SOURCE_SOCKET, id);
103 AddEndEntry(observer, source, NetLog::TYPE_SOCKET_ALIVE, NULL); 139 AddEndEntry(observer, source, NetLog::TYPE_SOCKET_ALIVE);
104 } 140 }
105 141
106 void BindURLRequestToHTTPStreamJob(LoadTimingObserver& observer, 142 void BindURLRequestToHTTPStreamJob(LoadTimingObserver& observer,
107 NetLog::Source url_request_source, 143 NetLog::Source url_request_source,
108 NetLog::Source http_stream_job_source) { 144 NetLog::Source http_stream_job_source) {
109 scoped_refptr<net::NetLogSourceParameter> params(
110 new net::NetLogSourceParameter("source_dependency",
111 http_stream_job_source));
112 AddStartEntry(observer, 145 AddStartEntry(observer,
113 url_request_source, 146 url_request_source,
114 NetLog::TYPE_HTTP_STREAM_REQUEST_BOUND_TO_JOB, 147 NetLog::TYPE_HTTP_STREAM_REQUEST_BOUND_TO_JOB,
115 params.get()); 148 http_stream_job_source.ToEventParametersCallback());
116 } 149 }
117 150
118 void BindHTTPStreamJobToConnectJob(LoadTimingObserver& observer, 151 void BindHTTPStreamJobToConnectJob(LoadTimingObserver& observer,
119 NetLog::Source& http_stream_job_source, 152 NetLog::Source& http_stream_job_source,
120 NetLog::Source& connect_source) { 153 NetLog::Source& connect_source) {
121 scoped_refptr<net::NetLogSourceParameter> params(
122 new net::NetLogSourceParameter("source_dependency", connect_source));
123 AddStartEntry(observer, 154 AddStartEntry(observer,
124 http_stream_job_source, 155 http_stream_job_source,
125 NetLog::TYPE_SOCKET_POOL_BOUND_TO_CONNECT_JOB, 156 NetLog::TYPE_SOCKET_POOL_BOUND_TO_CONNECT_JOB,
126 params.get()); 157 connect_source.ToEventParametersCallback());
127 } 158 }
128 159
129 void BindHTTPStreamJobToSocket(LoadTimingObserver& observer, 160 void BindHTTPStreamJobToSocket(LoadTimingObserver& observer,
130 NetLog::Source& http_stream_job_source, 161 NetLog::Source& http_stream_job_source,
131 NetLog::Source& socket_source) { 162 NetLog::Source& socket_source) {
132 scoped_refptr<net::NetLogSourceParameter> params(
133 new net::NetLogSourceParameter("source_dependency", socket_source));
134 AddStartEntry(observer, 163 AddStartEntry(observer,
135 http_stream_job_source, 164 http_stream_job_source,
136 NetLog::TYPE_SOCKET_POOL_BOUND_TO_SOCKET, 165 NetLog::TYPE_SOCKET_POOL_BOUND_TO_SOCKET,
137 params.get()); 166 socket_source.ToEventParametersCallback());
138 } 167 }
139 168
140 } // namespace 169 } // namespace
141 170
142 // Test that net::URLRequest with no load timing flag is not processed. 171 // Test that net::URLRequest with no load timing flag is not processed.
143 TEST_F(LoadTimingObserverTest, NoLoadTimingEnabled) { 172 TEST_F(LoadTimingObserverTest, NoLoadTimingEnabled) {
144 LoadTimingObserver observer; 173 AddStartURLRequestEntries(observer_, 0, false);
145 174 LoadTimingObserver::URLRequestRecord* record =
146 AddStartURLRequestEntries(observer, 0, false); 175 observer_.GetURLRequestRecord(0);
147 LoadTimingObserver::URLRequestRecord* record =
148 observer.GetURLRequestRecord(0);
149 ASSERT_TRUE(record == NULL); 176 ASSERT_TRUE(record == NULL);
150 } 177 }
151 178
152 // Test that URLRequestRecord is created, deleted and is not growing unbound. 179 // Test that URLRequestRecord is created, deleted and is not growing unbound.
153 TEST_F(LoadTimingObserverTest, URLRequestRecord) { 180 TEST_F(LoadTimingObserverTest, URLRequestRecord) {
154 LoadTimingObserver observer;
155
156 // Create record. 181 // Create record.
157 AddStartURLRequestEntries(observer, 0, true); 182 AddStartURLRequestEntries(observer_, 0, true);
158 LoadTimingObserver::URLRequestRecord* record = 183 LoadTimingObserver::URLRequestRecord* record =
159 observer.GetURLRequestRecord(0); 184 observer_.GetURLRequestRecord(0);
160 ASSERT_FALSE(record == NULL); 185 ASSERT_FALSE(record == NULL);
161 186
162 // Collect record. 187 // Collect record.
163 AddEndURLRequestEntries(observer, 0); 188 AddEndURLRequestEntries(observer_, 0);
164 record = observer.GetURLRequestRecord(0); 189 record = observer_.GetURLRequestRecord(0);
165 ASSERT_TRUE(record == NULL); 190 ASSERT_TRUE(record == NULL);
166 191
167 // Check unbound growth. 192 // Check unbound growth.
168 for (size_t i = 1; i < 1100; ++i) 193 for (size_t i = 1; i < 1100; ++i)
169 AddStartURLRequestEntries(observer, i, true); 194 AddStartURLRequestEntries(observer_, i, true);
170 record = observer.GetURLRequestRecord(1); 195 record = observer_.GetURLRequestRecord(1);
171 ASSERT_TRUE(record == NULL); 196 ASSERT_TRUE(record == NULL);
172 } 197 }
173 198
174 // Test that HTTPStreamJobRecord is created, deleted and is not growing unbound. 199 // Test that HTTPStreamJobRecord is created, deleted and is not growing unbound.
175 TEST_F(LoadTimingObserverTest, HTTPStreamJobRecord) { 200 TEST_F(LoadTimingObserverTest, HTTPStreamJobRecord) {
176 LoadTimingObserver observer;
177
178 // Create record. 201 // Create record.
179 AddStartHTTPStreamJobEntries(observer, 0); 202 AddStartHTTPStreamJobEntries(observer_, 0);
180 ASSERT_FALSE(observer.http_stream_job_to_record_.find(0) == 203 ASSERT_FALSE(observer_.http_stream_job_to_record_.find(0) ==
181 observer.http_stream_job_to_record_.end()); 204 observer_.http_stream_job_to_record_.end());
182 205
183 // Collect record. 206 // Collect record.
184 AddEndHTTPStreamJobEntries(observer, 0); 207 AddEndHTTPStreamJobEntries(observer_, 0);
185 ASSERT_TRUE(observer.http_stream_job_to_record_.find(0) == 208 ASSERT_TRUE(observer_.http_stream_job_to_record_.find(0) ==
186 observer.http_stream_job_to_record_.end()); 209 observer_.http_stream_job_to_record_.end());
187 210
188 // Check unbound growth. 211 // Check unbound growth.
189 for (size_t i = 1; i < 1100; ++i) 212 for (size_t i = 1; i < 1100; ++i)
190 AddStartHTTPStreamJobEntries(observer, i); 213 AddStartHTTPStreamJobEntries(observer_, i);
191 ASSERT_TRUE(observer.http_stream_job_to_record_.find(1) == 214 ASSERT_TRUE(observer_.http_stream_job_to_record_.find(1) ==
192 observer.http_stream_job_to_record_.end()); 215 observer_.http_stream_job_to_record_.end());
193 } 216 }
194 217
195 // Test that ConnectJobRecord is created, deleted and is not growing unbound. 218 // Test that ConnectJobRecord is created, deleted and is not growing unbound.
196 TEST_F(LoadTimingObserverTest, ConnectJobRecord) { 219 TEST_F(LoadTimingObserverTest, ConnectJobRecord) {
197 LoadTimingObserver observer;
198
199 // Create record. 220 // Create record.
200 AddStartConnectJobEntries(observer, 0); 221 AddStartConnectJobEntries(observer_, 0);
201 ASSERT_FALSE(observer.connect_job_to_record_.find(0) == 222 ASSERT_FALSE(observer_.connect_job_to_record_.find(0) ==
202 observer.connect_job_to_record_.end()); 223 observer_.connect_job_to_record_.end());
203 224
204 // Collect record. 225 // Collect record.
205 AddEndConnectJobEntries(observer, 0); 226 AddEndConnectJobEntries(observer_, 0);
206 ASSERT_TRUE(observer.connect_job_to_record_.find(0) == 227 ASSERT_TRUE(observer_.connect_job_to_record_.find(0) ==
207 observer.connect_job_to_record_.end()); 228 observer_.connect_job_to_record_.end());
208 229
209 // Check unbound growth. 230 // Check unbound growth.
210 for (size_t i = 1; i < 1100; ++i) 231 for (size_t i = 1; i < 1100; ++i)
211 AddStartConnectJobEntries(observer, i); 232 AddStartConnectJobEntries(observer_, i);
212 ASSERT_TRUE(observer.connect_job_to_record_.find(1) == 233 ASSERT_TRUE(observer_.connect_job_to_record_.find(1) ==
213 observer.connect_job_to_record_.end()); 234 observer_.connect_job_to_record_.end());
214 } 235 }
215 236
216 // Test that SocketRecord is created, deleted and is not growing unbound. 237 // Test that SocketRecord is created, deleted and is not growing unbound.
217 TEST_F(LoadTimingObserverTest, SocketRecord) { 238 TEST_F(LoadTimingObserverTest, SocketRecord) {
218 LoadTimingObserver observer;
219
220 // Create record. 239 // Create record.
221 AddStartSocketEntries(observer, 0); 240 AddStartSocketEntries(observer_, 0);
222 ASSERT_FALSE(observer.socket_to_record_.find(0) == 241 ASSERT_FALSE(observer_.socket_to_record_.find(0) ==
223 observer.socket_to_record_.end()); 242 observer_.socket_to_record_.end());
224 243
225 // Collect record. 244 // Collect record.
226 AddEndSocketEntries(observer, 0); 245 AddEndSocketEntries(observer_, 0);
227 ASSERT_TRUE(observer.socket_to_record_.find(0) == 246 ASSERT_TRUE(observer_.socket_to_record_.find(0) ==
228 observer.socket_to_record_.end()); 247 observer_.socket_to_record_.end());
229
230 248
231 // Check unbound growth. 249 // Check unbound growth.
232 for (size_t i = 1; i < 1100; ++i) 250 for (size_t i = 1; i < 1100; ++i)
233 AddStartSocketEntries(observer, i); 251 AddStartSocketEntries(observer_, i);
234 ASSERT_TRUE(observer.socket_to_record_.find(1) == 252 ASSERT_TRUE(observer_.socket_to_record_.find(1) ==
235 observer.socket_to_record_.end()); 253 observer_.socket_to_record_.end());
236 } 254 }
237 255
238 // Test that basic time is set to the request. 256 // Test that basic time is set to the request.
239 TEST_F(LoadTimingObserverTest, BaseTicks) { 257 TEST_F(LoadTimingObserverTest, BaseTicks) {
240 LoadTimingObserver observer; 258 observer_.IncementTime(TimeDelta::FromSeconds(1));
241 current_time += TimeDelta::FromSeconds(1); 259 AddStartURLRequestEntries(observer_, 0, true);
242 AddStartURLRequestEntries(observer, 0, true); 260
243 261 LoadTimingObserver::URLRequestRecord* record =
244 LoadTimingObserver::URLRequestRecord* record = 262 observer_.GetURLRequestRecord(0);
245 observer.GetURLRequestRecord(0);
246 ASSERT_EQ(1000000, record->base_ticks.ToInternalValue()); 263 ASSERT_EQ(1000000, record->base_ticks.ToInternalValue());
247 } 264 }
248 265
249 // Test proxy time detection. 266 // Test proxy time detection.
250 TEST_F(LoadTimingObserverTest, ProxyTime) { 267 TEST_F(LoadTimingObserverTest, ProxyTime) {
251 LoadTimingObserver observer; 268 observer_.IncementTime(TimeDelta::FromSeconds(1));
252 current_time += TimeDelta::FromSeconds(1); 269
253 270 AddStartURLRequestEntries(observer_, 0, true);
254 AddStartURLRequestEntries(observer, 0, true); 271 NetLog::Source source(NetLog::SOURCE_URL_REQUEST, 0);
255 NetLog::Source source(NetLog::SOURCE_URL_REQUEST, 0); 272
256 273 observer_.IncementTime(TimeDelta::FromSeconds(2));
257 current_time += TimeDelta::FromSeconds(2); 274 AddStartEntry(observer_, source, NetLog::TYPE_PROXY_SERVICE);
258 AddStartEntry(observer, source, NetLog::TYPE_PROXY_SERVICE, NULL); 275 observer_.IncementTime(TimeDelta::FromSeconds(3));
259 current_time += TimeDelta::FromSeconds(3); 276 AddEndEntry(observer_, source, NetLog::TYPE_PROXY_SERVICE);
260 AddEndEntry(observer, source, NetLog::TYPE_PROXY_SERVICE, NULL); 277
261 278 LoadTimingObserver::URLRequestRecord* record =
262 LoadTimingObserver::URLRequestRecord* record = 279 observer_.GetURLRequestRecord(0);
263 observer.GetURLRequestRecord(0);
264 ASSERT_EQ(2000, record->timing.proxy_start); 280 ASSERT_EQ(2000, record->timing.proxy_start);
265 ASSERT_EQ(5000, record->timing.proxy_end); 281 ASSERT_EQ(5000, record->timing.proxy_end);
266 } 282 }
267 283
268 // Test connect time detection. 284 // Test connect time detection.
269 TEST_F(LoadTimingObserverTest, ConnectTime) { 285 TEST_F(LoadTimingObserverTest, ConnectTime) {
270 LoadTimingObserver observer; 286 observer_.IncementTime(TimeDelta::FromSeconds(1));
271 current_time += TimeDelta::FromSeconds(1); 287
272 288 AddStartURLRequestEntries(observer_, 0, true);
273 AddStartURLRequestEntries(observer, 0, true);
274 NetLog::Source source(NetLog::SOURCE_URL_REQUEST, 0); 289 NetLog::Source source(NetLog::SOURCE_URL_REQUEST, 0);
275 290
276 NetLog::Source http_stream_job_source(NetLog::SOURCE_HTTP_STREAM_JOB, 1); 291 NetLog::Source http_stream_job_source(NetLog::SOURCE_HTTP_STREAM_JOB, 1);
277 AddStartHTTPStreamJobEntries(observer, 1); 292 AddStartHTTPStreamJobEntries(observer_, 1);
278 293
279 current_time += TimeDelta::FromSeconds(2); 294 observer_.IncementTime(TimeDelta::FromSeconds(2));
280 AddStartEntry(observer, http_stream_job_source, NetLog::TYPE_SOCKET_POOL, 295 AddStartEntry(observer_, http_stream_job_source, NetLog::TYPE_SOCKET_POOL);
281 NULL); 296 observer_.IncementTime(TimeDelta::FromSeconds(3));
282 current_time += TimeDelta::FromSeconds(3); 297 AddEndEntry(observer_, http_stream_job_source, NetLog::TYPE_SOCKET_POOL);
283 AddEndEntry(observer, http_stream_job_source, NetLog::TYPE_SOCKET_POOL, NULL); 298
284 299 BindURLRequestToHTTPStreamJob(observer_, source, http_stream_job_source);
285 BindURLRequestToHTTPStreamJob(observer, source, http_stream_job_source); 300
286 301 LoadTimingObserver::URLRequestRecord* record =
287 LoadTimingObserver::URLRequestRecord* record = 302 observer_.GetURLRequestRecord(0);
288 observer.GetURLRequestRecord(0);
289 ASSERT_EQ(2000, record->timing.connect_start); 303 ASSERT_EQ(2000, record->timing.connect_start);
290 ASSERT_EQ(5000, record->timing.connect_end); 304 ASSERT_EQ(5000, record->timing.connect_end);
291 } 305 }
292 306
293 // Test dns time detection. 307 // Test dns time detection.
294 TEST_F(LoadTimingObserverTest, DnsTime) { 308 TEST_F(LoadTimingObserverTest, DnsTime) {
295 LoadTimingObserver observer;
296
297 // Start request. 309 // Start request.
298 NetLog::Source source(NetLog::SOURCE_URL_REQUEST, 0); 310 NetLog::Source source(NetLog::SOURCE_URL_REQUEST, 0);
299 AddStartURLRequestEntries(observer, 0, true); 311 AddStartURLRequestEntries(observer_, 0, true);
300 current_time += TimeDelta::FromSeconds(1); 312 observer_.IncementTime(TimeDelta::FromSeconds(1));
301 313
302 // Add resolver entry. 314 // Add resolver entry.
303 AddStartConnectJobEntries(observer, 1); 315 AddStartConnectJobEntries(observer_, 1);
304 NetLog::Source connect_source(NetLog::SOURCE_CONNECT_JOB, 1); 316 NetLog::Source connect_source(NetLog::SOURCE_CONNECT_JOB, 1);
305 AddStartEntry(observer, 317 AddStartEntry(observer_, connect_source, NetLog::TYPE_HOST_RESOLVER_IMPL);
306 connect_source, 318 observer_.IncementTime(TimeDelta::FromSeconds(2));
307 NetLog::TYPE_HOST_RESOLVER_IMPL, 319 AddEndEntry(observer_, connect_source, NetLog::TYPE_HOST_RESOLVER_IMPL);
308 NULL); 320 AddEndConnectJobEntries(observer_, 1);
309 current_time += TimeDelta::FromSeconds(2);
310 AddEndEntry(observer, connect_source, NetLog::TYPE_HOST_RESOLVER_IMPL, NULL);
311 AddEndConnectJobEntries(observer, 1);
312 321
313 NetLog::Source http_stream_job_source(NetLog::SOURCE_HTTP_STREAM_JOB, 2); 322 NetLog::Source http_stream_job_source(NetLog::SOURCE_HTTP_STREAM_JOB, 2);
314 AddStartHTTPStreamJobEntries(observer, 2); 323 AddStartHTTPStreamJobEntries(observer_, 2);
315 324
316 BindHTTPStreamJobToConnectJob(observer, http_stream_job_source, 325 BindHTTPStreamJobToConnectJob(observer_, http_stream_job_source,
317 connect_source); 326 connect_source);
318 BindURLRequestToHTTPStreamJob(observer, source, http_stream_job_source); 327 BindURLRequestToHTTPStreamJob(observer_, source, http_stream_job_source);
319 328
320 LoadTimingObserver::URLRequestRecord* record = 329 LoadTimingObserver::URLRequestRecord* record =
321 observer.GetURLRequestRecord(0); 330 observer_.GetURLRequestRecord(0);
322 ASSERT_EQ(1000, record->timing.dns_start); 331 ASSERT_EQ(1000, record->timing.dns_start);
323 ASSERT_EQ(3000, record->timing.dns_end); 332 ASSERT_EQ(3000, record->timing.dns_end);
324 } 333 }
325 334
326 // Test send time detection. 335 // Test send time detection.
327 TEST_F(LoadTimingObserverTest, SendTime) { 336 TEST_F(LoadTimingObserverTest, SendTime) {
328 LoadTimingObserver observer;
329
330 // Start request. 337 // Start request.
331 NetLog::Source source(NetLog::SOURCE_URL_REQUEST, 0); 338 NetLog::Source source(NetLog::SOURCE_URL_REQUEST, 0);
332 AddStartURLRequestEntries(observer, 0, true); 339 AddStartURLRequestEntries(observer_, 0, true);
333 current_time += TimeDelta::FromSeconds(2); 340 observer_.IncementTime(TimeDelta::FromSeconds(2));
334 341
335 // Add send request entry. 342 // Add send request entry.
336 AddStartEntry(observer, 343 AddStartEntry(observer_, source, NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST);
337 source, 344 observer_.IncementTime(TimeDelta::FromSeconds(5));
338 NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST, 345 AddEndEntry(observer_, source, NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST);
339 NULL); 346
340 current_time += TimeDelta::FromSeconds(5); 347 LoadTimingObserver::URLRequestRecord* record =
341 AddEndEntry(observer, 348 observer_.GetURLRequestRecord(0);
342 source,
343 NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST,
344 NULL);
345
346 LoadTimingObserver::URLRequestRecord* record =
347 observer.GetURLRequestRecord(0);
348 ASSERT_EQ(2000, record->timing.send_start); 349 ASSERT_EQ(2000, record->timing.send_start);
349 ASSERT_EQ(7000, record->timing.send_end); 350 ASSERT_EQ(7000, record->timing.send_end);
350 } 351 }
351 352
352 // Test receive time detection. 353 // Test receive time detection.
353 TEST_F(LoadTimingObserverTest, ReceiveTime) { 354 TEST_F(LoadTimingObserverTest, ReceiveTime) {
354 LoadTimingObserver observer;
355
356 // Start request. 355 // Start request.
357 NetLog::Source source(NetLog::SOURCE_URL_REQUEST, 0); 356 NetLog::Source source(NetLog::SOURCE_URL_REQUEST, 0);
358 AddStartURLRequestEntries(observer, 0, true); 357 AddStartURLRequestEntries(observer_, 0, true);
359 current_time += TimeDelta::FromSeconds(2); 358 observer_.IncementTime(TimeDelta::FromSeconds(2));
360 359
361 // Add send request entry. 360 // Add send request entry.
362 AddStartEntry(observer, 361 AddStartEntry(observer_, source, NetLog::TYPE_HTTP_TRANSACTION_READ_HEADERS);
363 source, 362 observer_.IncementTime(TimeDelta::FromSeconds(5));
364 NetLog::TYPE_HTTP_TRANSACTION_READ_HEADERS, 363 AddEndEntry(observer_, source, NetLog::TYPE_HTTP_TRANSACTION_READ_HEADERS);
365 NULL); 364
366 current_time += TimeDelta::FromSeconds(5); 365 LoadTimingObserver::URLRequestRecord* record =
367 AddEndEntry(observer, 366 observer_.GetURLRequestRecord(0);
368 source,
369 NetLog::TYPE_HTTP_TRANSACTION_READ_HEADERS,
370 NULL);
371
372 LoadTimingObserver::URLRequestRecord* record =
373 observer.GetURLRequestRecord(0);
374 ASSERT_EQ(2000, record->timing.receive_headers_start); 367 ASSERT_EQ(2000, record->timing.receive_headers_start);
375 ASSERT_EQ(7000, record->timing.receive_headers_end); 368 ASSERT_EQ(7000, record->timing.receive_headers_end);
376 } 369 }
377 370
378 // Test ssl time detection. 371 // Test ssl time detection.
379 TEST_F(LoadTimingObserverTest, SslTime) { 372 TEST_F(LoadTimingObserverTest, SslTime) {
380 LoadTimingObserver observer;
381
382 // Start request. 373 // Start request.
383 NetLog::Source source(NetLog::SOURCE_URL_REQUEST, 0); 374 NetLog::Source source(NetLog::SOURCE_URL_REQUEST, 0);
384 AddStartURLRequestEntries(observer, 0, true); 375 AddStartURLRequestEntries(observer_, 0, true);
385 current_time += TimeDelta::FromSeconds(1); 376 observer_.IncementTime(TimeDelta::FromSeconds(1));
386 377
387 // Add resolver entry. 378 // Add resolver entry.
388 AddStartSocketEntries(observer, 1); 379 AddStartSocketEntries(observer_, 1);
389 NetLog::Source socket_source(NetLog::SOURCE_SOCKET, 1); 380 NetLog::Source socket_source(NetLog::SOURCE_SOCKET, 1);
390 AddStartEntry(observer, socket_source, NetLog::TYPE_SSL_CONNECT, NULL); 381 AddStartEntry(observer_, socket_source, NetLog::TYPE_SSL_CONNECT);
391 current_time += TimeDelta::FromSeconds(2); 382 observer_.IncementTime(TimeDelta::FromSeconds(2));
392 AddEndEntry(observer, socket_source, NetLog::TYPE_SSL_CONNECT, NULL); 383 AddEndEntry(observer_, socket_source, NetLog::TYPE_SSL_CONNECT);
393 384
394 NetLog::Source http_stream_job_source(NetLog::SOURCE_HTTP_STREAM_JOB, 2); 385 NetLog::Source http_stream_job_source(NetLog::SOURCE_HTTP_STREAM_JOB, 2);
395 AddStartHTTPStreamJobEntries(observer, 2); 386 AddStartHTTPStreamJobEntries(observer_, 2);
396 387
397 BindHTTPStreamJobToSocket(observer, http_stream_job_source, socket_source); 388 BindHTTPStreamJobToSocket(observer_, http_stream_job_source, socket_source);
398 BindURLRequestToHTTPStreamJob(observer, source, http_stream_job_source); 389 BindURLRequestToHTTPStreamJob(observer_, source, http_stream_job_source);
399 390
400 LoadTimingObserver::URLRequestRecord* record = 391 LoadTimingObserver::URLRequestRecord* record =
401 observer.GetURLRequestRecord(0); 392 observer_.GetURLRequestRecord(0);
402 ASSERT_EQ(1000, record->timing.ssl_start); 393 ASSERT_EQ(1000, record->timing.ssl_start);
403 ASSERT_EQ(3000, record->timing.ssl_end); 394 ASSERT_EQ(3000, record->timing.ssl_end);
404 } 395 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698