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

Side by Side Diff: net/url_request/url_request_http_job_unittest.cc

Issue 2709613013: Increase test coverage for Net.HttpTimeToFirstByte (Closed)
Patch Set: Created 3 years, 9 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
« AUTHORS ('K') | « AUTHORS ('k') | no next file » | no next file with comments »
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 "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
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 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)),
asanka 2017/02/28 20:32:39 This check is unnecessary.
Amey J 2017/02/28 21:22:16 Acknowledged.
641 request->GetTotalReceivedBytes());
642 histograms.ExpectTotalCount("Net.HttpTimeToFirstByte", 1);
643 }
644
645 TEST_F(URLRequestHttpJobWithMockSocketsTest,
646 TestHttpTimeToFirstByteForCancelledTask) {
647 base::HistogramTester histograms;
648 MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)};
649 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n"
650 "Content-Length: 12\r\n\r\n"),
651 MockRead("Test Content")};
652
653 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes,
654 arraysize(writes));
655 socket_factory_.AddSocketDataProvider(&socket_data);
656
657 TestDelegate delegate;
658 std::unique_ptr<URLRequest> request = context_->CreateRequest(
659 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate);
660
661 request->Start();
662 request->Cancel();
663 base::RunLoop().Run();
664
665 EXPECT_THAT(delegate.request_status(), IsError(ERR_ABORTED));
666 EXPECT_EQ(0, request->GetTotalReceivedBytes());
asanka 2017/02/28 20:32:39 This check is unnecessary.
Amey J 2017/02/28 21:22:16 Acknowledged.
667 histograms.ExpectTotalCount("Net.HttpTimeToFirstByte", 0);
668 }
669
619 TEST_F(URLRequestHttpJobTest, TestCancelWhileReadingCookies) { 670 TEST_F(URLRequestHttpJobTest, TestCancelWhileReadingCookies) {
620 DelayedCookieMonster cookie_monster; 671 DelayedCookieMonster cookie_monster;
621 TestURLRequestContext context(true); 672 TestURLRequestContext context(true);
622 context.set_cookie_store(&cookie_monster); 673 context.set_cookie_store(&cookie_monster);
623 context.Init(); 674 context.Init();
624 675
625 TestDelegate delegate; 676 TestDelegate delegate;
626 std::unique_ptr<URLRequest> request = context.CreateRequest( 677 std::unique_ptr<URLRequest> request = context.CreateRequest(
627 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate); 678 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate);
628 679
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after
1142 base::RunLoop().RunUntilIdle(); 1193 base::RunLoop().RunUntilIdle();
1143 EXPECT_THAT(delegate_.request_status(), IsError(ERR_IO_PENDING)); 1194 EXPECT_THAT(delegate_.request_status(), IsError(ERR_IO_PENDING));
1144 EXPECT_TRUE(fake_handshake_stream->initialize_stream_was_called()); 1195 EXPECT_TRUE(fake_handshake_stream->initialize_stream_was_called());
1145 } 1196 }
1146 1197
1147 #endif // BUILDFLAG(ENABLE_WEBSOCKETS) 1198 #endif // BUILDFLAG(ENABLE_WEBSOCKETS)
1148 1199
1149 } // namespace 1200 } // namespace
1150 1201
1151 } // namespace net 1202 } // namespace net
OLDNEW
« AUTHORS ('K') | « AUTHORS ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698