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

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

Issue 14625012: net: Return LoadTiming information in the case of a cache hit (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Missed a couple spots Created 7 years, 7 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
« no previous file with comments | « no previous file | net/http/http_cache_transaction.h » ('j') | net/http/http_cache_transaction.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 <string> 5 #include <string>
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 // Must be 0 when |is_null| is true. 82 // Must be 0 when |is_null| is true.
83 base::TimeDelta delta_; 83 base::TimeDelta delta_;
84 84
85 // This class is copyable and assignable. 85 // This class is copyable and assignable.
86 }; 86 };
87 87
88 // Structure used for both setting the LoadTimingInfo used by mock requests 88 // Structure used for both setting the LoadTimingInfo used by mock requests
89 // and for times retrieved from the renderer process. 89 // and for times retrieved from the renderer process.
90 // 90 //
91 // Times used for mock requests are all expressed as TimeDeltas relative to 91 // Times used for mock requests are all expressed as TimeDeltas relative to
92 // request_start. Null RelativeTimes correspond to null TimeTicks(). 92 // when the Job starts. Null RelativeTimes correspond to null TimeTicks().
93 // 93 //
94 // Times read from the renderer are expressed relative to fetchStart (Which is 94 // Times read from the renderer are expressed relative to fetchStart (Which is
95 // not the same as request_start). Null RelativeTimes correspond to times that 95 // not the same as request_start). Null RelativeTimes correspond to times that
96 // either cannot be retrieved (proxy times, send end) or times that are 0 (SSL 96 // either cannot be retrieved (proxy times, send end) or times that are 0 (SSL
97 // time when no new SSL connection was established). 97 // time when no new SSL connection was established).
98 struct TimingDeltas { 98 struct TimingDeltas {
99 RelativeTime proxy_resolve_start; 99 RelativeTime proxy_resolve_start;
100 RelativeTime proxy_resolve_end; 100 RelativeTime proxy_resolve_end;
101 RelativeTime dns_start; 101 RelativeTime dns_start;
102 RelativeTime dns_end; 102 RelativeTime dns_end;
(...skipping 17 matching lines...) Expand all
120 const base::FilePath& path, 120 const base::FilePath& path,
121 const TimingDeltas& load_timing_deltas) 121 const TimingDeltas& load_timing_deltas)
122 : net::URLRequestFileJob(request, network_delegate, path), 122 : net::URLRequestFileJob(request, network_delegate, path),
123 load_timing_deltas_(load_timing_deltas), 123 load_timing_deltas_(load_timing_deltas),
124 weak_factory_(this) { 124 weak_factory_(this) {
125 } 125 }
126 126
127 // net::URLRequestFileJob implementation: 127 // net::URLRequestFileJob implementation:
128 virtual void Start() OVERRIDE { 128 virtual void Start() OVERRIDE {
129 base::TimeDelta time_to_wait; 129 base::TimeDelta time_to_wait;
130 start_time_ = base::TimeTicks::Now();
130 if (!load_timing_deltas_.receive_headers_end.is_null()) { 131 if (!load_timing_deltas_.receive_headers_end.is_null()) {
131 // Need to delay starting until the largest of the times has elapsed. 132 // Need to delay starting until the largest of the times has elapsed.
132 // Wait a little longer than necessary, to be on the safe side. 133 // Wait a little longer than necessary, to be on the safe side.
133 time_to_wait = load_timing_deltas_.receive_headers_end.GetDelta() + 134 time_to_wait = load_timing_deltas_.receive_headers_end.GetDelta() +
134 base::TimeDelta::FromMilliseconds(100); 135 base::TimeDelta::FromMilliseconds(100);
135 } 136 }
136 137
137 MessageLoop::current()->PostDelayedTask( 138 MessageLoop::current()->PostDelayedTask(
138 FROM_HERE, 139 FROM_HERE,
139 base::Bind(&MockUrlRequestJobWithTiming::DelayedStart, 140 base::Bind(&MockUrlRequestJobWithTiming::DelayedStart,
140 weak_factory_.GetWeakPtr()), 141 weak_factory_.GetWeakPtr()),
141 time_to_wait); 142 time_to_wait);
142 } 143 }
143 144
144 virtual void GetLoadTimingInfo( 145 virtual void GetLoadTimingInfo(
145 net::LoadTimingInfo* load_timing_info) const OVERRIDE { 146 net::LoadTimingInfo* load_timing_info) const OVERRIDE {
146 // This should have been set by the URLRequest.
147 base::TimeTicks request_start = load_timing_info->request_start;
148 ASSERT_FALSE(request_start.is_null());
149
150 // Make sure enough time has elapsed since start was called. If this 147 // Make sure enough time has elapsed since start was called. If this
151 // fails, the test fixture itself is flaky. 148 // fails, the test fixture itself is flaky.
152 if (!load_timing_deltas_.receive_headers_end.is_null()) { 149 if (!load_timing_deltas_.receive_headers_end.is_null()) {
153 EXPECT_LE( 150 EXPECT_LE(
154 request_start + load_timing_deltas_.receive_headers_end.GetDelta(), 151 start_time_ + load_timing_deltas_.receive_headers_end.GetDelta(),
155 base::TimeTicks::Now()); 152 base::TimeTicks::Now());
156 } 153 }
157 154
158 // If there are no connect times, but there is a receive headers end time, 155 // If there are no connect times, but there is a receive headers end time,
159 // then assume the socket is reused. This shouldn't affect the load timing 156 // then assume the socket is reused. This shouldn't affect the load timing
160 // information the test checks, just done for completeness. 157 // information the test checks, just done for completeness.
161 load_timing_info->socket_reused = false; 158 load_timing_info->socket_reused = false;
162 if (load_timing_deltas_.connect_start.is_null() && 159 if (load_timing_deltas_.connect_start.is_null() &&
163 !load_timing_deltas_.receive_headers_end.is_null()) { 160 !load_timing_deltas_.receive_headers_end.is_null()) {
164 load_timing_info->socket_reused = true; 161 load_timing_info->socket_reused = true;
165 } 162 }
166 163
167 load_timing_info->proxy_resolve_start = 164 load_timing_info->proxy_resolve_start =
168 load_timing_deltas_.proxy_resolve_start.ToTimeTicks(request_start); 165 load_timing_deltas_.proxy_resolve_start.ToTimeTicks(start_time_);
169 load_timing_info->proxy_resolve_end = 166 load_timing_info->proxy_resolve_end =
170 load_timing_deltas_.proxy_resolve_end.ToTimeTicks(request_start); 167 load_timing_deltas_.proxy_resolve_end.ToTimeTicks(start_time_);
171 168
172 load_timing_info->connect_timing.dns_start = 169 load_timing_info->connect_timing.dns_start =
173 load_timing_deltas_.dns_start.ToTimeTicks(request_start); 170 load_timing_deltas_.dns_start.ToTimeTicks(start_time_);
174 load_timing_info->connect_timing.dns_end = 171 load_timing_info->connect_timing.dns_end =
175 load_timing_deltas_.dns_end.ToTimeTicks(request_start); 172 load_timing_deltas_.dns_end.ToTimeTicks(start_time_);
176 load_timing_info->connect_timing.connect_start = 173 load_timing_info->connect_timing.connect_start =
177 load_timing_deltas_.connect_start.ToTimeTicks(request_start); 174 load_timing_deltas_.connect_start.ToTimeTicks(start_time_);
178 load_timing_info->connect_timing.ssl_start = 175 load_timing_info->connect_timing.ssl_start =
179 load_timing_deltas_.ssl_start.ToTimeTicks(request_start); 176 load_timing_deltas_.ssl_start.ToTimeTicks(start_time_);
180 load_timing_info->connect_timing.connect_end = 177 load_timing_info->connect_timing.connect_end =
181 load_timing_deltas_.connect_end.ToTimeTicks(request_start); 178 load_timing_deltas_.connect_end.ToTimeTicks(start_time_);
182 179
183 // If there's an SSL start time, use connect end as the SSL end time. 180 // If there's an SSL start time, use connect end as the SSL end time.
184 // The NavigationTiming API does not have a corresponding field, and there's 181 // The NavigationTiming API does not have a corresponding field, and there's
185 // no need to test the case when the values are both non-NULL and different. 182 // no need to test the case when the values are both non-NULL and different.
186 if (!load_timing_deltas_.ssl_start.is_null()) { 183 if (!load_timing_deltas_.ssl_start.is_null()) {
187 load_timing_info->connect_timing.ssl_end = 184 load_timing_info->connect_timing.ssl_end =
188 load_timing_info->connect_timing.connect_end; 185 load_timing_info->connect_timing.connect_end;
189 } 186 }
190 187
191 load_timing_info->send_start = 188 load_timing_info->send_start =
192 load_timing_deltas_.send_start.ToTimeTicks(request_start); 189 load_timing_deltas_.send_start.ToTimeTicks(start_time_);
193 load_timing_info->send_end= 190 load_timing_info->send_end=
194 load_timing_deltas_.send_end.ToTimeTicks(request_start); 191 load_timing_deltas_.send_end.ToTimeTicks(start_time_);
195 load_timing_info->receive_headers_end = 192 load_timing_info->receive_headers_end =
196 load_timing_deltas_.receive_headers_end.ToTimeTicks(request_start); 193 load_timing_deltas_.receive_headers_end.ToTimeTicks(start_time_);
197 } 194 }
198 195
199 private: 196 private:
200 // Parent class is reference counted, so need to have a private destructor. 197 // Parent class is reference counted, so need to have a private destructor.
201 virtual ~MockUrlRequestJobWithTiming() {} 198 virtual ~MockUrlRequestJobWithTiming() {}
202 199
203 void DelayedStart() { 200 void DelayedStart() {
204 net::URLRequestFileJob::Start(); 201 net::URLRequestFileJob::Start();
205 } 202 }
206 203
207 // Load times to use, relative to request_start from the URLRequest. 204 // Load times to use, relative to |start_time_|.
208 const TimingDeltas load_timing_deltas_; 205 const TimingDeltas load_timing_deltas_;
206 base::TimeTicks start_time_;
209 207
210 base::WeakPtrFactory<MockUrlRequestJobWithTiming> weak_factory_; 208 base::WeakPtrFactory<MockUrlRequestJobWithTiming> weak_factory_;
211 209
212 DISALLOW_COPY_AND_ASSIGN(MockUrlRequestJobWithTiming); 210 DISALLOW_COPY_AND_ASSIGN(MockUrlRequestJobWithTiming);
213 }; 211 };
214 212
215 // A protocol handler that returns mock URLRequestJobs that return the specified 213 // A protocol handler that returns mock URLRequestJobs that return the specified
216 // file with the given timings. Constructed on the UI thread, but after that, 214 // file with the given timings. Constructed on the UI thread, but after that,
217 // lives and is destroyed on the IO thread. 215 // lives and is destroyed on the IO thread.
218 class TestProtocolHandler : public net::URLRequestJobFactory::ProtocolHandler { 216 class TestProtocolHandler : public net::URLRequestJobFactory::ProtocolHandler {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); 248 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO));
251 249
252 return new MockUrlRequestJobWithTiming(request, network_delegate, path_, 250 return new MockUrlRequestJobWithTiming(request, network_delegate, path_,
253 load_timing_deltas_); 251 load_timing_deltas_);
254 } 252 }
255 253
256 private: 254 private:
257 // Path of the file to use as the response body. 255 // Path of the file to use as the response body.
258 const base::FilePath path_; 256 const base::FilePath path_;
259 257
260 // Load times for each request to use, relative to their request_start times. 258 // Load times for each request to use, relative to when the Job starts.
261 const TimingDeltas load_timing_deltas_; 259 const TimingDeltas load_timing_deltas_;
262 260
263 DISALLOW_COPY_AND_ASSIGN(TestProtocolHandler); 261 DISALLOW_COPY_AND_ASSIGN(TestProtocolHandler);
264 }; 262 };
265 263
266 class LoadTimingBrowserTest : public InProcessBrowserTest { 264 class LoadTimingBrowserTest : public InProcessBrowserTest {
267 public: 265 public:
268 LoadTimingBrowserTest() { 266 LoadTimingBrowserTest() {
269 } 267 }
270 268
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 494
497 EXPECT_LT(navigation_deltas.send_start.GetDelta(), 495 EXPECT_LT(navigation_deltas.send_start.GetDelta(),
498 navigation_deltas.receive_headers_end.GetDelta()); 496 navigation_deltas.receive_headers_end.GetDelta());
499 497
500 EXPECT_TRUE(navigation_deltas.ssl_start.is_null()); 498 EXPECT_TRUE(navigation_deltas.ssl_start.is_null());
501 } 499 }
502 500
503 // Preconnect case. Connect times are all before the request was started. 501 // Preconnect case. Connect times are all before the request was started.
504 IN_PROC_BROWSER_TEST_F(LoadTimingBrowserTest, Preconnect) { 502 IN_PROC_BROWSER_TEST_F(LoadTimingBrowserTest, Preconnect) {
505 TimingDeltas load_timing_deltas; 503 TimingDeltas load_timing_deltas;
506 load_timing_deltas.dns_start = RelativeTime(-100300); 504 load_timing_deltas.dns_start = RelativeTime(-1000300);
eroman 2013/05/15 01:11:50 what is the significance of changing these times?
mmenke 2013/05/15 01:52:38 Paranoia. It used to be that request_start was ti
507 load_timing_deltas.dns_end = RelativeTime(-100200); 505 load_timing_deltas.dns_end = RelativeTime(-1000200);
508 load_timing_deltas.connect_start = RelativeTime(-100100); 506 load_timing_deltas.connect_start = RelativeTime(-1000100);
509 load_timing_deltas.connect_end = RelativeTime(-100000); 507 load_timing_deltas.connect_end = RelativeTime(-1000000);
510 load_timing_deltas.send_start = RelativeTime(0); 508 load_timing_deltas.send_start = RelativeTime(0);
511 load_timing_deltas.send_end = RelativeTime(100); 509 load_timing_deltas.send_end = RelativeTime(100);
512 load_timing_deltas.receive_headers_end = RelativeTime(200); 510 load_timing_deltas.receive_headers_end = RelativeTime(200);
513 511
514 TimingDeltas navigation_deltas; 512 TimingDeltas navigation_deltas;
515 RunTest(load_timing_deltas, &navigation_deltas); 513 RunTest(load_timing_deltas, &navigation_deltas);
516 514
517 // Connect times should all be the same as request_start, which is also the 515 // Connect times should all be the same as request_start.
518 // same as send_start (Since send_start is 0).
519 EXPECT_EQ(navigation_deltas.dns_start.GetDelta(), 516 EXPECT_EQ(navigation_deltas.dns_start.GetDelta(),
520 navigation_deltas.dns_end.GetDelta()); 517 navigation_deltas.dns_end.GetDelta());
521 EXPECT_EQ(navigation_deltas.dns_start.GetDelta(), 518 EXPECT_EQ(navigation_deltas.dns_start.GetDelta(),
522 navigation_deltas.connect_start.GetDelta()); 519 navigation_deltas.connect_start.GetDelta());
523 EXPECT_EQ(navigation_deltas.dns_start.GetDelta(), 520 EXPECT_EQ(navigation_deltas.dns_start.GetDelta(),
524 navigation_deltas.connect_end.GetDelta()); 521 navigation_deltas.connect_end.GetDelta());
525 EXPECT_EQ(navigation_deltas.dns_start.GetDelta(), 522
523 EXPECT_LE(navigation_deltas.dns_start.GetDelta(),
526 navigation_deltas.send_start.GetDelta()); 524 navigation_deltas.send_start.GetDelta());
527 525
528 EXPECT_LT(navigation_deltas.send_start.GetDelta(), 526 EXPECT_LT(navigation_deltas.send_start.GetDelta(),
529 navigation_deltas.receive_headers_end.GetDelta()); 527 navigation_deltas.receive_headers_end.GetDelta());
530 EXPECT_LT(navigation_deltas.send_start.GetDelta(), 528 EXPECT_LT(navigation_deltas.send_start.GetDelta(),
531 navigation_deltas.receive_headers_end.GetDelta()); 529 navigation_deltas.receive_headers_end.GetDelta());
532 530
533 EXPECT_TRUE(navigation_deltas.ssl_start.is_null()); 531 EXPECT_TRUE(navigation_deltas.ssl_start.is_null());
534 } 532 }
535 533
536 // Preconnect case with a proxy. Connect times are all before the proxy lookup 534 // Preconnect case with a proxy. Connect times are all before the proxy lookup
537 // finished (Or at the same time). 535 // finished (Or at the same time).
538 IN_PROC_BROWSER_TEST_F(LoadTimingBrowserTest, PreconnectProxySsl) { 536 IN_PROC_BROWSER_TEST_F(LoadTimingBrowserTest, PreconnectProxySsl) {
539 TimingDeltas load_timing_deltas; 537 TimingDeltas load_timing_deltas;
540 load_timing_deltas.proxy_resolve_start = RelativeTime(0); 538 load_timing_deltas.proxy_resolve_start = RelativeTime(0);
541 load_timing_deltas.proxy_resolve_end = RelativeTime(100); 539 load_timing_deltas.proxy_resolve_end = RelativeTime(100);
542 load_timing_deltas.dns_start = RelativeTime(-300); 540 load_timing_deltas.dns_start = RelativeTime(-3000000);
543 load_timing_deltas.dns_end = RelativeTime(-200); 541 load_timing_deltas.dns_end = RelativeTime(-2000000);
544 load_timing_deltas.connect_start = RelativeTime(-100); 542 load_timing_deltas.connect_start = RelativeTime(-1000000);
545 load_timing_deltas.ssl_start = RelativeTime(0); 543 load_timing_deltas.ssl_start = RelativeTime(0);
546 load_timing_deltas.connect_end = RelativeTime(100); 544 load_timing_deltas.connect_end = RelativeTime(100);
547 load_timing_deltas.send_start = RelativeTime(100); 545 load_timing_deltas.send_start = RelativeTime(100);
548 load_timing_deltas.send_end = RelativeTime(200); 546 load_timing_deltas.send_end = RelativeTime(200);
549 load_timing_deltas.receive_headers_end = RelativeTime(300); 547 load_timing_deltas.receive_headers_end = RelativeTime(300);
550 548
551 TimingDeltas navigation_deltas; 549 TimingDeltas navigation_deltas;
552 RunTest(load_timing_deltas, &navigation_deltas); 550 RunTest(load_timing_deltas, &navigation_deltas);
553 551
554 // Connect times should all be the same as proxy_end, which is also the 552 // Connect times should all be the same as proxy_end, which is also the
(...skipping 25 matching lines...) Expand all
580 // Due to potential roundoff issues, never check exact differences. 578 // Due to potential roundoff issues, never check exact differences.
581 EXPECT_LE(navigation_deltas.dns_start.GetDelta(), 579 EXPECT_LE(navigation_deltas.dns_start.GetDelta(),
582 navigation_deltas.dns_end.GetDelta()); 580 navigation_deltas.dns_end.GetDelta());
583 EXPECT_LE(navigation_deltas.dns_end.GetDelta(), 581 EXPECT_LE(navigation_deltas.dns_end.GetDelta(),
584 navigation_deltas.connect_start.GetDelta()); 582 navigation_deltas.connect_start.GetDelta());
585 EXPECT_LE(navigation_deltas.connect_start.GetDelta(), 583 EXPECT_LE(navigation_deltas.connect_start.GetDelta(),
586 navigation_deltas.connect_end.GetDelta()); 584 navigation_deltas.connect_end.GetDelta());
587 EXPECT_LE(navigation_deltas.connect_end.GetDelta(), 585 EXPECT_LE(navigation_deltas.connect_end.GetDelta(),
588 navigation_deltas.send_start.GetDelta()); 586 navigation_deltas.send_start.GetDelta());
589 // The only times that are guaranteed to be distinct are send_start and 587 // The only times that are guaranteed to be distinct are send_start and
590 // received_headers end. 588 // received_headers_end.
591 EXPECT_LT(navigation_deltas.send_start.GetDelta(), 589 EXPECT_LT(navigation_deltas.send_start.GetDelta(),
592 navigation_deltas.receive_headers_end.GetDelta()); 590 navigation_deltas.receive_headers_end.GetDelta());
593 591
594 EXPECT_TRUE(navigation_deltas.ssl_start.is_null()); 592 EXPECT_TRUE(navigation_deltas.ssl_start.is_null());
595 } 593 }
596 594
597 } // namespace 595 } // namespace
OLDNEW
« no previous file with comments | « no previous file | net/http/http_cache_transaction.h » ('j') | net/http/http_cache_transaction.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698