Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/net/chrome_network_delegate.h" | 5 #include "chrome/browser/net/chrome_network_delegate.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 228 RequestURL(context(), socket_factory()); | 228 RequestURL(context(), socket_factory()); |
| 229 | 229 |
| 230 EXPECT_EQ(0, fake_aggregator.on_the_record_tx_bytes()); | 230 EXPECT_EQ(0, fake_aggregator.on_the_record_tx_bytes()); |
| 231 EXPECT_EQ(0, fake_aggregator.on_the_record_rx_bytes()); | 231 EXPECT_EQ(0, fake_aggregator.on_the_record_rx_bytes()); |
| 232 EXPECT_EQ(request->GetTotalSentBytes(), | 232 EXPECT_EQ(request->GetTotalSentBytes(), |
| 233 fake_aggregator.off_the_record_tx_bytes()); | 233 fake_aggregator.off_the_record_tx_bytes()); |
| 234 EXPECT_EQ(request->GetTotalReceivedBytes(), | 234 EXPECT_EQ(request->GetTotalReceivedBytes(), |
| 235 fake_aggregator.off_the_record_rx_bytes()); | 235 fake_aggregator.off_the_record_rx_bytes()); |
| 236 } | 236 } |
| 237 | 237 |
| 238 TEST_F(ChromeNetworkDelegateTest, HttpRequestCompletionErrorCodes) { | |
| 239 Initialize(); | |
| 240 | |
| 241 const struct { | |
| 242 const GURL url; | |
| 243 int net_error; | |
| 244 bool is_main_frame; | |
| 245 int expected_sample_bucket; | |
| 246 int expected_request_completion_count; | |
| 247 int expected_request_completion_main_frame_count; | |
| 248 } tests[] = { | |
|
asanka
2017/03/08 21:23:30
kTests
| |
| 249 {GURL("http://example.com"), net::OK, true, std::abs(net::OK), 1, 1}, | |
| 250 {GURL("http://example.com"), net::ERR_ABORTED, true, | |
| 251 std::abs(net::ERR_ABORTED), 1, 1}, | |
| 252 {GURL("http://example.com"), net::OK, false, std::abs(net::OK), 1, 0}, | |
| 253 {GURL("https://example.com"), net::OK, true, std::abs(net::OK), 0, 0}, | |
| 254 }; | |
| 255 | |
| 256 const char http_request_completion_error_code[] = | |
|
asanka
2017/03/08 21:23:30
kHttpRequestCompletionErrorCode for constants.
| |
| 257 "Net.HttpRequestCompletionErrorCodes"; | |
| 258 const char http_request_completion_error_code_main_frame[] = | |
|
asanka
2017/03/08 21:23:30
kHttpRequestCompletionErrorCodeMainFrame
| |
| 259 "Net.HttpRequestCompletionErrorCodes.MainFrame"; | |
| 260 | |
| 261 for (const auto& test : tests) { | |
| 262 base::HistogramTester histograms; | |
| 263 | |
| 264 net::TestDelegate test_delegate; | |
| 265 std::unique_ptr<net::URLRequest> request(context()->CreateRequest( | |
| 266 test.url, net::DEFAULT_PRIORITY, &test_delegate)); | |
| 267 if (test.is_main_frame) { | |
| 268 request->SetLoadFlags(request->load_flags() | | |
| 269 net::LOAD_MAIN_FRAME_DEPRECATED); | |
| 270 } | |
| 271 network_delegate()->NotifyCompleted(request.get(), false, test.net_error); | |
| 272 | |
| 273 histograms.ExpectTotalCount(http_request_completion_error_code, | |
| 274 test.expected_request_completion_count); | |
| 275 histograms.ExpectUniqueSample(http_request_completion_error_code, | |
| 276 test.expected_sample_bucket, | |
| 277 test.expected_request_completion_count); | |
| 278 histograms.ExpectTotalCount( | |
| 279 http_request_completion_error_code_main_frame, | |
| 280 test.expected_request_completion_main_frame_count); | |
| 281 histograms.ExpectUniqueSample( | |
| 282 http_request_completion_error_code_main_frame, | |
| 283 test.expected_sample_bucket, | |
| 284 test.expected_request_completion_main_frame_count); | |
| 285 } | |
| 286 } | |
| 287 | |
| 238 class ChromeNetworkDelegatePolicyTest : public testing::Test { | 288 class ChromeNetworkDelegatePolicyTest : public testing::Test { |
| 239 public: | 289 public: |
| 240 ChromeNetworkDelegatePolicyTest() | 290 ChromeNetworkDelegatePolicyTest() |
| 241 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) { | 291 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) { |
| 242 #if BUILDFLAG(ENABLE_EXTENSIONS) | 292 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 243 forwarder_ = new extensions::EventRouterForwarder(); | 293 forwarder_ = new extensions::EventRouterForwarder(); |
| 244 #endif | 294 #endif |
| 245 } | 295 } |
| 246 | 296 |
| 247 protected: | 297 protected: |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 583 | 633 |
| 584 // Files in external storage are allowed. | 634 // Files in external storage are allowed. |
| 585 base::FilePath external_storage_path; | 635 base::FilePath external_storage_path; |
| 586 PathService::Get(base::DIR_ANDROID_EXTERNAL_STORAGE, &external_storage_path); | 636 PathService::Get(base::DIR_ANDROID_EXTERNAL_STORAGE, &external_storage_path); |
| 587 EXPECT_TRUE(IsAccessAllowed( | 637 EXPECT_TRUE(IsAccessAllowed( |
| 588 external_storage_path.AppendASCII("foo.txt").AsUTF8Unsafe(), "")); | 638 external_storage_path.AppendASCII("foo.txt").AsUTF8Unsafe(), "")); |
| 589 // The external storage root itself is not allowed. | 639 // The external storage root itself is not allowed. |
| 590 EXPECT_FALSE(IsAccessAllowed(external_storage_path.AsUTF8Unsafe(), "")); | 640 EXPECT_FALSE(IsAccessAllowed(external_storage_path.AsUTF8Unsafe(), "")); |
| 591 #endif | 641 #endif |
| 592 } | 642 } |
| OLD | NEW |