Check USB device path access when prompting users to select a device.
[chromium-blink-merge.git] / chrome / browser / net / load_timing_browsertest.cc
blob9a51330b60e22cad7bdd9dbdf9986d8fe74bbdad
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
3 // found in the LICENSE file.
5 #include <string>
7 #include "base/basictypes.h"
8 #include "base/bind.h"
9 #include "base/compiler_specific.h"
10 #include "base/files/file_path.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/message_loop/message_loop.h"
14 #include "base/path_service.h"
15 #include "base/strings/stringprintf.h"
16 #include "base/threading/sequenced_worker_pool.h"
17 #include "chrome/browser/ui/browser.h"
18 #include "chrome/browser/ui/tabs/tab_strip_model.h"
19 #include "chrome/common/chrome_paths.h"
20 #include "chrome/test/base/in_process_browser_test.h"
21 #include "chrome/test/base/ui_test_utils.h"
22 #include "content/public/browser/browser_thread.h"
23 #include "content/public/test/browser_test_utils.h"
24 #include "net/base/load_timing_info.h"
25 #include "net/test/spawned_test_server/spawned_test_server.h"
26 #include "net/url_request/url_request_file_job.h"
27 #include "net/url_request/url_request_filter.h"
28 #include "net/url_request/url_request_interceptor.h"
29 #include "url/gurl.h"
31 // This file tests that net::LoadTimingInfo is correctly hooked up to the
32 // NavigationTiming API. It depends on behavior in a large number of files
33 // spread across multiple projects, so is somewhat arbitrarily put in
34 // chrome/browser/net.
36 using content::BrowserThread;
38 namespace {
40 const char kTestDomain[] = "test.com";
41 const char kTestUrl[] = "http://test.com/";
43 // Relative times need to be used because:
44 // 1) ExecuteScriptAndExtractInt does not support 64-bit integers.
45 // 2) Times for tests are set before the request has been started, but need to
46 // be set relative to the start time.
48 // Since some tests need to test negative time deltas (preconnected sockets)
49 // and others need to test NULL times (events that don't apply), this class has
50 // to be able to handle all cases: positive deltas, negative deltas, no
51 // delta, and null times.
52 class RelativeTime {
53 public:
54 // Constructor for null RelativeTimes.
55 RelativeTime() : is_null_(true) {
58 // Constructor for non-null RelativeTimes.
59 explicit RelativeTime(int delta_ms)
60 : is_null_(false),
61 delta_(base::TimeDelta::FromMilliseconds(delta_ms)) {
64 // Given a base time, returns the TimeTicks |this| identifies.
65 base::TimeTicks ToTimeTicks(base::TimeTicks base_time) const {
66 if (is_null_)
67 return base::TimeTicks();
68 return base_time + delta_;
71 bool is_null() const { return is_null_; }
73 base::TimeDelta GetDelta() const {
74 // This allows tests to compare times that shouldn't be null without
75 // explicitly null-testing them all first.
76 EXPECT_FALSE(is_null_);
77 return delta_;
80 private:
81 bool is_null_;
83 // Must be 0 when |is_null| is true.
84 base::TimeDelta delta_;
86 // This class is copyable and assignable.
89 // Structure used for both setting the LoadTimingInfo used by mock requests
90 // and for times retrieved from the renderer process.
92 // Times used for mock requests are all expressed as TimeDeltas relative to
93 // when the Job starts. Null RelativeTimes correspond to null TimeTicks().
95 // Times read from the renderer are expressed relative to fetchStart (Which is
96 // not the same as request_start). Null RelativeTimes correspond to times that
97 // either cannot be retrieved (proxy times, send end) or times that are 0 (SSL
98 // time when no new SSL connection was established).
99 struct TimingDeltas {
100 RelativeTime proxy_resolve_start;
101 RelativeTime proxy_resolve_end;
102 RelativeTime dns_start;
103 RelativeTime dns_end;
104 RelativeTime connect_start;
105 RelativeTime ssl_start;
106 RelativeTime connect_end;
107 RelativeTime send_start;
108 RelativeTime send_end;
110 // Must be non-negative and greater than all other times. May only be null if
111 // all other times are as well.
112 RelativeTime receive_headers_end;
115 // Mock UrlRequestJob that returns the contents of a specified file and
116 // provides the specified load timing information when queried.
117 class MockUrlRequestJobWithTiming : public net::URLRequestFileJob {
118 public:
119 MockUrlRequestJobWithTiming(net::URLRequest* request,
120 net::NetworkDelegate* network_delegate,
121 const base::FilePath& path,
122 const TimingDeltas& load_timing_deltas)
123 : net::URLRequestFileJob(
124 request, network_delegate, path,
125 content::BrowserThread::GetBlockingPool()->
126 GetTaskRunnerWithShutdownBehavior(
127 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)),
128 load_timing_deltas_(load_timing_deltas),
129 weak_factory_(this) {}
131 // net::URLRequestFileJob implementation:
132 void Start() override {
133 base::TimeDelta time_to_wait;
134 start_time_ = base::TimeTicks::Now();
135 if (!load_timing_deltas_.receive_headers_end.is_null()) {
136 // Need to delay starting until the largest of the times has elapsed.
137 // Wait a little longer than necessary, to be on the safe side.
138 time_to_wait = load_timing_deltas_.receive_headers_end.GetDelta() +
139 base::TimeDelta::FromMilliseconds(100);
142 base::MessageLoop::current()->PostDelayedTask(
143 FROM_HERE,
144 base::Bind(&MockUrlRequestJobWithTiming::DelayedStart,
145 weak_factory_.GetWeakPtr()),
146 time_to_wait);
149 void GetLoadTimingInfo(net::LoadTimingInfo* load_timing_info) const override {
150 // Make sure enough time has elapsed since start was called. If this
151 // fails, the test fixture itself is flaky.
152 if (!load_timing_deltas_.receive_headers_end.is_null()) {
153 EXPECT_LE(
154 start_time_ + load_timing_deltas_.receive_headers_end.GetDelta(),
155 base::TimeTicks::Now());
158 // 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
160 // information the test checks, just done for completeness.
161 load_timing_info->socket_reused = false;
162 if (load_timing_deltas_.connect_start.is_null() &&
163 !load_timing_deltas_.receive_headers_end.is_null()) {
164 load_timing_info->socket_reused = true;
167 load_timing_info->proxy_resolve_start =
168 load_timing_deltas_.proxy_resolve_start.ToTimeTicks(start_time_);
169 load_timing_info->proxy_resolve_end =
170 load_timing_deltas_.proxy_resolve_end.ToTimeTicks(start_time_);
172 load_timing_info->connect_timing.dns_start =
173 load_timing_deltas_.dns_start.ToTimeTicks(start_time_);
174 load_timing_info->connect_timing.dns_end =
175 load_timing_deltas_.dns_end.ToTimeTicks(start_time_);
176 load_timing_info->connect_timing.connect_start =
177 load_timing_deltas_.connect_start.ToTimeTicks(start_time_);
178 load_timing_info->connect_timing.ssl_start =
179 load_timing_deltas_.ssl_start.ToTimeTicks(start_time_);
180 load_timing_info->connect_timing.connect_end =
181 load_timing_deltas_.connect_end.ToTimeTicks(start_time_);
183 // 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
185 // no need to test the case when the values are both non-NULL and different.
186 if (!load_timing_deltas_.ssl_start.is_null()) {
187 load_timing_info->connect_timing.ssl_end =
188 load_timing_info->connect_timing.connect_end;
191 load_timing_info->send_start =
192 load_timing_deltas_.send_start.ToTimeTicks(start_time_);
193 load_timing_info->send_end=
194 load_timing_deltas_.send_end.ToTimeTicks(start_time_);
195 load_timing_info->receive_headers_end =
196 load_timing_deltas_.receive_headers_end.ToTimeTicks(start_time_);
199 private:
200 // Parent class is reference counted, so need to have a private destructor.
201 ~MockUrlRequestJobWithTiming() override {}
203 void DelayedStart() {
204 net::URLRequestFileJob::Start();
207 // Load times to use, relative to |start_time_|.
208 const TimingDeltas load_timing_deltas_;
209 base::TimeTicks start_time_;
211 base::WeakPtrFactory<MockUrlRequestJobWithTiming> weak_factory_;
213 DISALLOW_COPY_AND_ASSIGN(MockUrlRequestJobWithTiming);
216 // AURLRequestInterceptor that returns mock URLRequestJobs that return the
217 // specified file with the given timings. Constructed on the UI thread, but
218 // after that, lives and is destroyed on the IO thread.
219 class TestInterceptor : public net::URLRequestInterceptor {
220 public:
221 TestInterceptor(const base::FilePath& path,
222 const TimingDeltas& load_timing_deltas)
223 : path_(path), load_timing_deltas_(load_timing_deltas) {
224 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI));
227 ~TestInterceptor() override {
228 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO));
231 // Registers |this| with the URLRequestFilter, which takes ownership of it.
232 void Register() {
233 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO));
234 net::URLRequestFilter::GetInstance()->AddHostnameInterceptor(
235 "http", kTestDomain, scoped_ptr<net::URLRequestInterceptor>(this));
238 // Unregisters |this| with the URLRequestFilter, which should then delete
239 // |this|.
240 void Unregister() {
241 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO));
242 net::URLRequestFilter::GetInstance()->RemoveHostnameHandler(
243 "http", kTestDomain);
246 // net::URLRequestJobFactory::ProtocolHandler implementation:
247 net::URLRequestJob* MaybeInterceptRequest(
248 net::URLRequest* request,
249 net::NetworkDelegate* network_delegate) const override {
250 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO));
252 return new MockUrlRequestJobWithTiming(request, network_delegate, path_,
253 load_timing_deltas_);
256 private:
257 // Path of the file to use as the response body.
258 const base::FilePath path_;
260 // Load times for each request to use, relative to when the Job starts.
261 const TimingDeltas load_timing_deltas_;
263 DISALLOW_COPY_AND_ASSIGN(TestInterceptor);
266 class LoadTimingBrowserTest : public InProcessBrowserTest {
267 public:
268 LoadTimingBrowserTest() {
271 ~LoadTimingBrowserTest() override {}
273 // Navigates to |url| and writes the resulting navigation timings to
274 // |navigation_deltas|.
275 void RunTestWithUrl(const GURL& url, TimingDeltas* navigation_deltas) {
276 ui_test_utils::NavigateToURL(browser(), url);
277 GetResultDeltas(navigation_deltas);
280 // Navigates to a url that returns the timings indicated by
281 // |load_timing_deltas| and writes the resulting navigation timings to
282 // |navigation_deltas|. Uses a generic test page.
283 void RunTest(const TimingDeltas& load_timing_deltas,
284 TimingDeltas* navigation_deltas) {
285 // None of the tests care about the contents of the test page. Just do
286 // this here because PathService has thread restrictions on some platforms.
287 base::FilePath path;
288 PathService::Get(chrome::DIR_TEST_DATA, &path);
289 path = path.AppendASCII("title1.html");
291 // Create and register request interceptor.
292 TestInterceptor* test_interceptor =
293 new TestInterceptor(path, load_timing_deltas);
294 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
295 base::Bind(&TestInterceptor::Register,
296 base::Unretained(test_interceptor)));
298 // Navigate to the page.
299 RunTestWithUrl(GURL(kTestUrl), navigation_deltas);
301 // Once navigation is complete, unregister the protocol handler.
302 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
303 base::Bind(&TestInterceptor::Unregister,
304 base::Unretained(test_interceptor)));
307 private:
308 // Reads applicable times from performance.timing and writes them to
309 // |navigation_deltas|. Proxy times and send end cannot be read from the
310 // Navigation Timing API, so those are all left as null.
311 void GetResultDeltas(TimingDeltas* navigation_deltas) {
312 *navigation_deltas = TimingDeltas();
314 navigation_deltas->dns_start = GetResultDelta("domainLookupStart");
315 navigation_deltas->dns_end = GetResultDelta("domainLookupEnd");
316 navigation_deltas->connect_start = GetResultDelta("connectStart");
317 navigation_deltas->connect_end = GetResultDelta("connectEnd");
318 navigation_deltas->send_start = GetResultDelta("requestStart");
319 navigation_deltas->receive_headers_end = GetResultDelta("responseStart");
321 // Unlike the above times, secureConnectionStart will be zero when not
322 // applicable. In that case, leave ssl_start as null.
323 bool ssl_start_zero = false;
324 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
325 browser()->tab_strip_model()->GetActiveWebContents(),
326 "window.domAutomationController.send("
327 "performance.timing.secureConnectionStart == 0);",
328 &ssl_start_zero));
329 if (!ssl_start_zero)
330 navigation_deltas->ssl_start = GetResultDelta("secureConnectionStart");
332 // Simple sanity checks. Make sure times that correspond to LoadTimingInfo
333 // occur between fetchStart and loadEventEnd. Relationships between
334 // intervening times are handled by the test bodies.
336 RelativeTime fetch_start = GetResultDelta("fetchStart");
337 // While the input dns_start is sometimes null, when read from the
338 // NavigationTiming API, it's always non-null.
339 EXPECT_LE(fetch_start.GetDelta(), navigation_deltas->dns_start.GetDelta());
341 RelativeTime load_event_end = GetResultDelta("loadEventEnd");
342 EXPECT_LE(navigation_deltas->receive_headers_end.GetDelta(),
343 load_event_end.GetDelta());
346 // Returns the time between performance.timing.fetchStart and the time with
347 // the specified name. This time must be non-negative.
348 RelativeTime GetResultDelta(const std::string& name) {
349 int time_ms = 0;
350 std::string command(base::StringPrintf(
351 "window.domAutomationController.send("
352 "performance.timing.%s - performance.timing.fetchStart);",
353 name.c_str()));
354 EXPECT_TRUE(content::ExecuteScriptAndExtractInt(
355 browser()->tab_strip_model()->GetActiveWebContents(),
356 command.c_str(),
357 &time_ms));
359 // Basic sanity check.
360 EXPECT_GE(time_ms, 0);
362 return RelativeTime(time_ms);
366 // Test case when no times are given, except the request start times. This
367 // happens with FTP, cached responses, responses handled by something other than
368 // the network stack, RedirectJobs, HSTs, etc.
369 IN_PROC_BROWSER_TEST_F(LoadTimingBrowserTest, NoTimes) {
370 TimingDeltas load_timing_deltas;
371 TimingDeltas navigation_deltas;
372 RunTest(load_timing_deltas, &navigation_deltas);
374 // When there are no times, all read times should be the same as fetchStart,
375 // except SSL start, which should be 0.
376 EXPECT_EQ(base::TimeDelta(), navigation_deltas.dns_start.GetDelta());
377 EXPECT_EQ(base::TimeDelta(), navigation_deltas.dns_end.GetDelta());
378 EXPECT_EQ(base::TimeDelta(), navigation_deltas.connect_start.GetDelta());
379 EXPECT_EQ(base::TimeDelta(), navigation_deltas.connect_end.GetDelta());
380 EXPECT_EQ(base::TimeDelta(), navigation_deltas.send_start.GetDelta());
381 EXPECT_EQ(base::TimeDelta(),
382 navigation_deltas.receive_headers_end.GetDelta());
384 EXPECT_TRUE(navigation_deltas.ssl_start.is_null());
387 // Standard case - new socket, no PAC, no preconnect, no SSL.
388 IN_PROC_BROWSER_TEST_F(LoadTimingBrowserTest, Basic) {
389 TimingDeltas load_timing_deltas;
390 load_timing_deltas.dns_start = RelativeTime(0);
391 load_timing_deltas.dns_end = RelativeTime(100);
392 load_timing_deltas.connect_start = RelativeTime(200);
393 load_timing_deltas.connect_end = RelativeTime(300);
394 load_timing_deltas.send_start = RelativeTime(400);
395 load_timing_deltas.send_end = RelativeTime(500);
396 load_timing_deltas.receive_headers_end = RelativeTime(600);
398 TimingDeltas navigation_deltas;
399 RunTest(load_timing_deltas, &navigation_deltas);
401 // Due to potential roundoff issues, never check exact differences.
402 EXPECT_LT(navigation_deltas.dns_start.GetDelta(),
403 navigation_deltas.dns_end.GetDelta());
404 EXPECT_LT(navigation_deltas.dns_end.GetDelta(),
405 navigation_deltas.connect_start.GetDelta());
406 EXPECT_LT(navigation_deltas.connect_start.GetDelta(),
407 navigation_deltas.connect_end.GetDelta());
408 EXPECT_LT(navigation_deltas.connect_end.GetDelta(),
409 navigation_deltas.send_start.GetDelta());
410 EXPECT_LT(navigation_deltas.send_start.GetDelta(),
411 navigation_deltas.receive_headers_end.GetDelta());
413 EXPECT_TRUE(navigation_deltas.ssl_start.is_null());
416 // Basic SSL case.
417 IN_PROC_BROWSER_TEST_F(LoadTimingBrowserTest, Ssl) {
418 TimingDeltas load_timing_deltas;
419 load_timing_deltas.dns_start = RelativeTime(0);
420 load_timing_deltas.dns_end = RelativeTime(100);
421 load_timing_deltas.connect_start = RelativeTime(200);
422 load_timing_deltas.ssl_start = RelativeTime(300);
423 load_timing_deltas.connect_end = RelativeTime(400);
424 load_timing_deltas.send_start = RelativeTime(500);
425 load_timing_deltas.send_end = RelativeTime(600);
426 load_timing_deltas.receive_headers_end = RelativeTime(700);
428 TimingDeltas navigation_deltas;
429 RunTest(load_timing_deltas, &navigation_deltas);
431 // Due to potential roundoff issues, never check exact differences.
432 EXPECT_LT(navigation_deltas.dns_start.GetDelta(),
433 navigation_deltas.dns_end.GetDelta());
434 EXPECT_LT(navigation_deltas.dns_end.GetDelta(),
435 navigation_deltas.connect_start.GetDelta());
436 EXPECT_LT(navigation_deltas.connect_start.GetDelta(),
437 navigation_deltas.ssl_start.GetDelta());
438 EXPECT_LT(navigation_deltas.ssl_start.GetDelta(),
439 navigation_deltas.connect_end.GetDelta());
440 EXPECT_LT(navigation_deltas.connect_end.GetDelta(),
441 navigation_deltas.send_start.GetDelta());
442 EXPECT_LT(navigation_deltas.send_start.GetDelta(),
443 navigation_deltas.receive_headers_end.GetDelta());
446 // All times are the same.
447 IN_PROC_BROWSER_TEST_F(LoadTimingBrowserTest, EverythingAtOnce) {
448 TimingDeltas load_timing_deltas;
449 load_timing_deltas.dns_start = RelativeTime(100);
450 load_timing_deltas.dns_end = RelativeTime(100);
451 load_timing_deltas.connect_start = RelativeTime(100);
452 load_timing_deltas.ssl_start = RelativeTime(100);
453 load_timing_deltas.connect_end = RelativeTime(100);
454 load_timing_deltas.send_start = RelativeTime(100);
455 load_timing_deltas.send_end = RelativeTime(100);
456 load_timing_deltas.receive_headers_end = RelativeTime(100);
458 TimingDeltas navigation_deltas;
459 RunTest(load_timing_deltas, &navigation_deltas);
461 EXPECT_EQ(navigation_deltas.dns_start.GetDelta(),
462 navigation_deltas.dns_end.GetDelta());
463 EXPECT_EQ(navigation_deltas.dns_end.GetDelta(),
464 navigation_deltas.connect_start.GetDelta());
465 EXPECT_EQ(navigation_deltas.connect_start.GetDelta(),
466 navigation_deltas.ssl_start.GetDelta());
467 EXPECT_EQ(navigation_deltas.ssl_start.GetDelta(),
468 navigation_deltas.connect_end.GetDelta());
469 EXPECT_EQ(navigation_deltas.connect_end.GetDelta(),
470 navigation_deltas.send_start.GetDelta());
471 EXPECT_EQ(navigation_deltas.send_start.GetDelta(),
472 navigation_deltas.receive_headers_end.GetDelta());
475 // Reuse case.
476 IN_PROC_BROWSER_TEST_F(LoadTimingBrowserTest, ReuseSocket) {
477 TimingDeltas load_timing_deltas;
478 load_timing_deltas.send_start = RelativeTime(0);
479 load_timing_deltas.send_end = RelativeTime(100);
480 load_timing_deltas.receive_headers_end = RelativeTime(200);
482 TimingDeltas navigation_deltas;
483 RunTest(load_timing_deltas, &navigation_deltas);
485 // Connect times should all be the same as fetchStart.
486 EXPECT_EQ(base::TimeDelta(), navigation_deltas.dns_start.GetDelta());
487 EXPECT_EQ(base::TimeDelta(), navigation_deltas.dns_end.GetDelta());
488 EXPECT_EQ(base::TimeDelta(), navigation_deltas.connect_start.GetDelta());
489 EXPECT_EQ(base::TimeDelta(), navigation_deltas.connect_end.GetDelta());
491 // Connect end may be less than send start, since connect end defaults to
492 // fetchStart, which is often less than request_start.
493 EXPECT_LE(navigation_deltas.connect_end.GetDelta(),
494 navigation_deltas.send_start.GetDelta());
496 EXPECT_LT(navigation_deltas.send_start.GetDelta(),
497 navigation_deltas.receive_headers_end.GetDelta());
499 EXPECT_TRUE(navigation_deltas.ssl_start.is_null());
502 // Preconnect case. Connect times are all before the request was started.
503 IN_PROC_BROWSER_TEST_F(LoadTimingBrowserTest, Preconnect) {
504 TimingDeltas load_timing_deltas;
505 load_timing_deltas.dns_start = RelativeTime(-1000300);
506 load_timing_deltas.dns_end = RelativeTime(-1000200);
507 load_timing_deltas.connect_start = RelativeTime(-1000100);
508 load_timing_deltas.connect_end = RelativeTime(-1000000);
509 load_timing_deltas.send_start = RelativeTime(0);
510 load_timing_deltas.send_end = RelativeTime(100);
511 load_timing_deltas.receive_headers_end = RelativeTime(200);
513 TimingDeltas navigation_deltas;
514 RunTest(load_timing_deltas, &navigation_deltas);
516 // Connect times should all be the same as request_start.
517 EXPECT_EQ(navigation_deltas.dns_start.GetDelta(),
518 navigation_deltas.dns_end.GetDelta());
519 EXPECT_EQ(navigation_deltas.dns_start.GetDelta(),
520 navigation_deltas.connect_start.GetDelta());
521 EXPECT_EQ(navigation_deltas.dns_start.GetDelta(),
522 navigation_deltas.connect_end.GetDelta());
524 EXPECT_LE(navigation_deltas.dns_start.GetDelta(),
525 navigation_deltas.send_start.GetDelta());
527 EXPECT_LT(navigation_deltas.send_start.GetDelta(),
528 navigation_deltas.receive_headers_end.GetDelta());
529 EXPECT_LT(navigation_deltas.send_start.GetDelta(),
530 navigation_deltas.receive_headers_end.GetDelta());
532 EXPECT_TRUE(navigation_deltas.ssl_start.is_null());
535 // Preconnect case with a proxy. Connect times are all before the proxy lookup
536 // finished (Or at the same time).
537 IN_PROC_BROWSER_TEST_F(LoadTimingBrowserTest, PreconnectProxySsl) {
538 TimingDeltas load_timing_deltas;
539 load_timing_deltas.proxy_resolve_start = RelativeTime(0);
540 load_timing_deltas.proxy_resolve_end = RelativeTime(100);
541 load_timing_deltas.dns_start = RelativeTime(-3000000);
542 load_timing_deltas.dns_end = RelativeTime(-2000000);
543 load_timing_deltas.connect_start = RelativeTime(-1000000);
544 load_timing_deltas.ssl_start = RelativeTime(0);
545 load_timing_deltas.connect_end = RelativeTime(100);
546 load_timing_deltas.send_start = RelativeTime(100);
547 load_timing_deltas.send_end = RelativeTime(200);
548 load_timing_deltas.receive_headers_end = RelativeTime(300);
550 TimingDeltas navigation_deltas;
551 RunTest(load_timing_deltas, &navigation_deltas);
553 // Connect times should all be the same as proxy_end, which is also the
554 // same as send_start.
555 EXPECT_EQ(navigation_deltas.dns_start.GetDelta(),
556 navigation_deltas.dns_end.GetDelta());
557 EXPECT_EQ(navigation_deltas.dns_start.GetDelta(),
558 navigation_deltas.connect_start.GetDelta());
559 EXPECT_EQ(navigation_deltas.dns_start.GetDelta(),
560 navigation_deltas.ssl_start.GetDelta());
561 EXPECT_EQ(navigation_deltas.dns_start.GetDelta(),
562 navigation_deltas.connect_end.GetDelta());
563 EXPECT_EQ(navigation_deltas.dns_start.GetDelta(),
564 navigation_deltas.send_start.GetDelta());
566 EXPECT_LT(navigation_deltas.send_start.GetDelta(),
567 navigation_deltas.receive_headers_end.GetDelta());
568 EXPECT_LT(navigation_deltas.send_start.GetDelta(),
569 navigation_deltas.receive_headers_end.GetDelta());
572 // Integration test with a real network response.
573 IN_PROC_BROWSER_TEST_F(LoadTimingBrowserTest, Integration) {
574 ASSERT_TRUE(test_server()->Start());
575 TimingDeltas navigation_deltas;
576 RunTestWithUrl(test_server()->GetURL("chunked?waitBeforeHeaders=100"),
577 &navigation_deltas);
579 // Due to potential roundoff issues, never check exact differences.
580 EXPECT_LE(navigation_deltas.dns_start.GetDelta(),
581 navigation_deltas.dns_end.GetDelta());
582 EXPECT_LE(navigation_deltas.dns_end.GetDelta(),
583 navigation_deltas.connect_start.GetDelta());
584 EXPECT_LE(navigation_deltas.connect_start.GetDelta(),
585 navigation_deltas.connect_end.GetDelta());
586 EXPECT_LE(navigation_deltas.connect_end.GetDelta(),
587 navigation_deltas.send_start.GetDelta());
588 // The only times that are guaranteed to be distinct are send_start and
589 // received_headers_end.
590 EXPECT_LT(navigation_deltas.send_start.GetDelta(),
591 navigation_deltas.receive_headers_end.GetDelta());
593 EXPECT_TRUE(navigation_deltas.ssl_start.is_null());
596 } // namespace