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

Unified Diff: chrome/browser/net/chrome_network_delegate_unittest.cc

Issue 2715393002: Add tests for HttpRequestCompletionErrorCodes (Closed)
Patch Set: Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..c1e6cba46c573fea8815c08e53b3a0ea78bb0ada 100644
--- a/chrome/browser/net/chrome_network_delegate_unittest.cc
+++ b/chrome/browser/net/chrome_network_delegate_unittest.cc
@@ -50,6 +50,11 @@
namespace {
+const char* const kHttpRequestCompletionErrorCodes =
+ "Net.HttpRequestCompletionErrorCodes";
asanka 2017/03/07 19:15:47 Use something like: const char kHttpRequestComple
Amey J 2017/03/08 02:05:18 Acknowledged.
+const char* const kHttpRequestCompletionErrorCodesMainFrame =
+ "Net.HttpRequestCompletionErrorCodes.MainFrame";
+
// This function requests a URL, and makes it return a known response.
// ResourceRequestInfo is attached to the URLRequest, to represent this request
// as an user initiated.
@@ -235,6 +240,52 @@ 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 main_frame;
asanka 2017/03/07 19:15:47 is_main_frame
Amey J 2017/03/08 02:05:18 Acknowledged.
+ int expected_sample_bucket;
+ int expected_request_completion_count;
+ int expected_request_completion_main_frame_count;
+ } tests[] = {
+ {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},
+ };
+
+ for (size_t i = 0; i < arraysize(tests); ++i) {
asanka 2017/03/07 19:15:47 use a range based iterator. I.e. something like:
Amey J 2017/03/08 02:05:18 Sweet! Somehow, I always thought that range based
+ base::HistogramTester histograms;
+
+ net::TestDelegate test_delegate;
+ std::unique_ptr<net::URLRequest> request(context()->CreateRequest(
+ tests[i].url, net::DEFAULT_PRIORITY, &test_delegate));
+ if (tests[i].main_frame) {
+ request->SetLoadFlags(request->load_flags() |
+ net::LOAD_MAIN_FRAME_DEPRECATED);
+ }
+ network_delegate()->NotifyCompleted(request.get(), false,
+ tests[i].net_error);
+
+ histograms.ExpectTotalCount(kHttpRequestCompletionErrorCodes,
+ tests[i].expected_request_completion_count);
+ histograms.ExpectUniqueSample(kHttpRequestCompletionErrorCodes,
+ tests[i].expected_sample_bucket,
+ tests[i].expected_request_completion_count);
+ histograms.ExpectTotalCount(
+ kHttpRequestCompletionErrorCodesMainFrame,
+ tests[i].expected_request_completion_main_frame_count);
+ histograms.ExpectUniqueSample(
+ kHttpRequestCompletionErrorCodesMainFrame,
+ tests[i].expected_sample_bucket,
+ tests[i].expected_request_completion_main_frame_count);
+ }
+}
+
class ChromeNetworkDelegatePolicyTest : public testing::Test {
public:
ChromeNetworkDelegatePolicyTest()
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698