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 } 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 kHttpRequestCompletionErrorCode[] = |
| 257 "Net.HttpRequestCompletionErrorCodes"; |
| 258 const char kHttpRequestCompletionErrorCodeMainFrame[] = |
| 259 "Net.HttpRequestCompletionErrorCodes.MainFrame"; |
| 260 |
| 261 for (const auto& test : kTests) { |
| 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(kHttpRequestCompletionErrorCode, |
| 274 test.expected_request_completion_count); |
| 275 histograms.ExpectUniqueSample(kHttpRequestCompletionErrorCode, |
| 276 test.expected_sample_bucket, |
| 277 test.expected_request_completion_count); |
| 278 histograms.ExpectTotalCount( |
| 279 kHttpRequestCompletionErrorCodeMainFrame, |
| 280 test.expected_request_completion_main_frame_count); |
| 281 histograms.ExpectUniqueSample( |
| 282 kHttpRequestCompletionErrorCodeMainFrame, test.expected_sample_bucket, |
| 283 test.expected_request_completion_main_frame_count); |
| 284 } |
| 285 } |
| 286 |
238 class ChromeNetworkDelegatePolicyTest : public testing::Test { | 287 class ChromeNetworkDelegatePolicyTest : public testing::Test { |
239 public: | 288 public: |
240 ChromeNetworkDelegatePolicyTest() | 289 ChromeNetworkDelegatePolicyTest() |
241 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) { | 290 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) { |
242 #if BUILDFLAG(ENABLE_EXTENSIONS) | 291 #if BUILDFLAG(ENABLE_EXTENSIONS) |
243 forwarder_ = new extensions::EventRouterForwarder(); | 292 forwarder_ = new extensions::EventRouterForwarder(); |
244 #endif | 293 #endif |
245 } | 294 } |
246 | 295 |
247 protected: | 296 protected: |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
583 | 632 |
584 // Files in external storage are allowed. | 633 // Files in external storage are allowed. |
585 base::FilePath external_storage_path; | 634 base::FilePath external_storage_path; |
586 PathService::Get(base::DIR_ANDROID_EXTERNAL_STORAGE, &external_storage_path); | 635 PathService::Get(base::DIR_ANDROID_EXTERNAL_STORAGE, &external_storage_path); |
587 EXPECT_TRUE(IsAccessAllowed( | 636 EXPECT_TRUE(IsAccessAllowed( |
588 external_storage_path.AppendASCII("foo.txt").AsUTF8Unsafe(), "")); | 637 external_storage_path.AppendASCII("foo.txt").AsUTF8Unsafe(), "")); |
589 // The external storage root itself is not allowed. | 638 // The external storage root itself is not allowed. |
590 EXPECT_FALSE(IsAccessAllowed(external_storage_path.AsUTF8Unsafe(), "")); | 639 EXPECT_FALSE(IsAccessAllowed(external_storage_path.AsUTF8Unsafe(), "")); |
591 #endif | 640 #endif |
592 } | 641 } |
OLD | NEW |