Index: chrome/browser/net/chrome_network_delegate_unittest.cc |
diff --git a/chrome/browser/net/chrome_network_delegate_unittest.cc b/chrome/browser/net/chrome_network_delegate_unittest.cc |
index edecbe6a5fb7ef84ffd2b5b6a3d2323ad5d8a7cb..f5690227d9d9629a4860cee8dd2031ae00979581 100644 |
--- a/chrome/browser/net/chrome_network_delegate_unittest.cc |
+++ b/chrome/browser/net/chrome_network_delegate_unittest.cc |
@@ -235,6 +235,56 @@ TEST_F(ChromeNetworkDelegateTest, ReportOffTheRecordDataUseToAggregator) { |
fake_aggregator.off_the_record_rx_bytes()); |
} |
+TEST_F(ChromeNetworkDelegateTest, HttpRequestCompletionErrorCodes) { |
+ Initialize(); |
+ |
+ const struct { |
+ const GURL url; |
+ int net_error; |
+ bool is_main_frame; |
+ int expected_sample_bucket; |
+ int expected_request_completion_count; |
+ int expected_request_completion_main_frame_count; |
+ } tests[] = { |
asanka
2017/03/08 21:23:30
kTests
|
+ {GURL("http://example.com"), net::OK, true, std::abs(net::OK), 1, 1}, |
+ {GURL("http://example.com"), net::ERR_ABORTED, true, |
+ std::abs(net::ERR_ABORTED), 1, 1}, |
+ {GURL("http://example.com"), net::OK, false, std::abs(net::OK), 1, 0}, |
+ {GURL("https://example.com"), net::OK, true, std::abs(net::OK), 0, 0}, |
+ }; |
+ |
+ const char http_request_completion_error_code[] = |
asanka
2017/03/08 21:23:30
kHttpRequestCompletionErrorCode for constants.
|
+ "Net.HttpRequestCompletionErrorCodes"; |
+ const char http_request_completion_error_code_main_frame[] = |
asanka
2017/03/08 21:23:30
kHttpRequestCompletionErrorCodeMainFrame
|
+ "Net.HttpRequestCompletionErrorCodes.MainFrame"; |
+ |
+ for (const auto& test : tests) { |
+ base::HistogramTester histograms; |
+ |
+ net::TestDelegate test_delegate; |
+ std::unique_ptr<net::URLRequest> request(context()->CreateRequest( |
+ test.url, net::DEFAULT_PRIORITY, &test_delegate)); |
+ if (test.is_main_frame) { |
+ request->SetLoadFlags(request->load_flags() | |
+ net::LOAD_MAIN_FRAME_DEPRECATED); |
+ } |
+ network_delegate()->NotifyCompleted(request.get(), false, test.net_error); |
+ |
+ histograms.ExpectTotalCount(http_request_completion_error_code, |
+ test.expected_request_completion_count); |
+ histograms.ExpectUniqueSample(http_request_completion_error_code, |
+ test.expected_sample_bucket, |
+ test.expected_request_completion_count); |
+ histograms.ExpectTotalCount( |
+ http_request_completion_error_code_main_frame, |
+ test.expected_request_completion_main_frame_count); |
+ histograms.ExpectUniqueSample( |
+ http_request_completion_error_code_main_frame, |
+ test.expected_sample_bucket, |
+ test.expected_request_completion_main_frame_count); |
+ } |
+} |
+ |
class ChromeNetworkDelegatePolicyTest : public testing::Test { |
public: |
ChromeNetworkDelegatePolicyTest() |