OLD | NEW |
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 "net/url_request/url_request_http_job.h" | 5 #include "net/url_request/url_request_http_job.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <cstddef> | 9 #include <cstddef> |
10 #include <memory> | 10 #include <memory> |
11 | 11 |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
16 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
17 #include "base/strings/string_split.h" | 17 #include "base/strings/string_split.h" |
| 18 #include "base/test/histogram_tester.h" |
18 #include "net/base/auth.h" | 19 #include "net/base/auth.h" |
19 #include "net/base/request_priority.h" | 20 #include "net/base/request_priority.h" |
20 #include "net/base/sdch_observer.h" | 21 #include "net/base/sdch_observer.h" |
21 #include "net/cookies/cookie_store_test_helpers.h" | 22 #include "net/cookies/cookie_store_test_helpers.h" |
22 #include "net/http/http_transaction_factory.h" | 23 #include "net/http/http_transaction_factory.h" |
23 #include "net/http/http_transaction_test_util.h" | 24 #include "net/http/http_transaction_test_util.h" |
24 #include "net/log/net_log_event_type.h" | 25 #include "net/log/net_log_event_type.h" |
25 #include "net/log/test_net_log.h" | 26 #include "net/log/test_net_log.h" |
26 #include "net/log/test_net_log_entry.h" | 27 #include "net/log/test_net_log_entry.h" |
27 #include "net/log/test_net_log_util.h" | 28 #include "net/log/test_net_log_util.h" |
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
609 request->Cancel(); | 610 request->Cancel(); |
610 base::RunLoop().RunUntilIdle(); | 611 base::RunLoop().RunUntilIdle(); |
611 | 612 |
612 EXPECT_THAT(delegate.request_status(), IsError(ERR_ABORTED)); | 613 EXPECT_THAT(delegate.request_status(), IsError(ERR_ABORTED)); |
613 EXPECT_EQ(0, request->received_response_content_length()); | 614 EXPECT_EQ(0, request->received_response_content_length()); |
614 EXPECT_EQ(0, request->GetTotalSentBytes()); | 615 EXPECT_EQ(0, request->GetTotalSentBytes()); |
615 EXPECT_EQ(0, request->GetTotalReceivedBytes()); | 616 EXPECT_EQ(0, request->GetTotalReceivedBytes()); |
616 EXPECT_EQ(0, network_delegate_.total_network_bytes_received()); | 617 EXPECT_EQ(0, network_delegate_.total_network_bytes_received()); |
617 } | 618 } |
618 | 619 |
| 620 TEST_F(URLRequestHttpJobWithMockSocketsTest, TestHttpTimeToFirstByte) { |
| 621 base::HistogramTester histograms; |
| 622 MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)}; |
| 623 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n" |
| 624 "Content-Length: 12\r\n\r\n"), |
| 625 MockRead("Test Content")}; |
| 626 |
| 627 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, |
| 628 arraysize(writes)); |
| 629 socket_factory_.AddSocketDataProvider(&socket_data); |
| 630 |
| 631 TestDelegate delegate; |
| 632 std::unique_ptr<URLRequest> request = context_->CreateRequest( |
| 633 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate); |
| 634 histograms.ExpectTotalCount("Net.HttpTimeToFirstByte", 0); |
| 635 |
| 636 request->Start(); |
| 637 base::RunLoop().Run(); |
| 638 |
| 639 EXPECT_THAT(delegate.request_status(), IsOk()); |
| 640 histograms.ExpectTotalCount("Net.HttpTimeToFirstByte", 1); |
| 641 } |
| 642 |
| 643 TEST_F(URLRequestHttpJobWithMockSocketsTest, |
| 644 TestHttpTimeToFirstByteForCancelledTask) { |
| 645 base::HistogramTester histograms; |
| 646 MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)}; |
| 647 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n" |
| 648 "Content-Length: 12\r\n\r\n"), |
| 649 MockRead("Test Content")}; |
| 650 |
| 651 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, |
| 652 arraysize(writes)); |
| 653 socket_factory_.AddSocketDataProvider(&socket_data); |
| 654 |
| 655 TestDelegate delegate; |
| 656 std::unique_ptr<URLRequest> request = context_->CreateRequest( |
| 657 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate); |
| 658 |
| 659 request->Start(); |
| 660 request->Cancel(); |
| 661 base::RunLoop().Run(); |
| 662 |
| 663 EXPECT_THAT(delegate.request_status(), IsError(ERR_ABORTED)); |
| 664 histograms.ExpectTotalCount("Net.HttpTimeToFirstByte", 0); |
| 665 } |
| 666 |
619 TEST_F(URLRequestHttpJobTest, TestCancelWhileReadingCookies) { | 667 TEST_F(URLRequestHttpJobTest, TestCancelWhileReadingCookies) { |
620 DelayedCookieMonster cookie_monster; | 668 DelayedCookieMonster cookie_monster; |
621 TestURLRequestContext context(true); | 669 TestURLRequestContext context(true); |
622 context.set_cookie_store(&cookie_monster); | 670 context.set_cookie_store(&cookie_monster); |
623 context.Init(); | 671 context.Init(); |
624 | 672 |
625 TestDelegate delegate; | 673 TestDelegate delegate; |
626 std::unique_ptr<URLRequest> request = context.CreateRequest( | 674 std::unique_ptr<URLRequest> request = context.CreateRequest( |
627 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate); | 675 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate); |
628 | 676 |
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1142 base::RunLoop().RunUntilIdle(); | 1190 base::RunLoop().RunUntilIdle(); |
1143 EXPECT_THAT(delegate_.request_status(), IsError(ERR_IO_PENDING)); | 1191 EXPECT_THAT(delegate_.request_status(), IsError(ERR_IO_PENDING)); |
1144 EXPECT_TRUE(fake_handshake_stream->initialize_stream_was_called()); | 1192 EXPECT_TRUE(fake_handshake_stream->initialize_stream_was_called()); |
1145 } | 1193 } |
1146 | 1194 |
1147 #endif // BUILDFLAG(ENABLE_WEBSOCKETS) | 1195 #endif // BUILDFLAG(ENABLE_WEBSOCKETS) |
1148 | 1196 |
1149 } // namespace | 1197 } // namespace |
1150 | 1198 |
1151 } // namespace net | 1199 } // namespace net |
OLD | NEW |