| 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 17 matching lines...) Expand all Loading... |
| 28 #include "components/data_usage/core/data_use_aggregator.h" | 28 #include "components/data_usage/core/data_use_aggregator.h" |
| 29 #include "components/data_usage/core/data_use_amortizer.h" | 29 #include "components/data_usage/core/data_use_amortizer.h" |
| 30 #include "components/data_usage/core/data_use_annotator.h" | 30 #include "components/data_usage/core/data_use_annotator.h" |
| 31 #include "components/data_use_measurement/core/data_use_user_data.h" | 31 #include "components/data_use_measurement/core/data_use_user_data.h" |
| 32 #include "components/prefs/pref_member.h" | 32 #include "components/prefs/pref_member.h" |
| 33 #include "components/sync_preferences/testing_pref_service_syncable.h" | 33 #include "components/sync_preferences/testing_pref_service_syncable.h" |
| 34 #include "content/public/browser/resource_request_info.h" | 34 #include "content/public/browser/resource_request_info.h" |
| 35 #include "content/public/common/content_switches.h" | 35 #include "content/public/common/content_switches.h" |
| 36 #include "content/public/common/resource_type.h" | 36 #include "content/public/common/resource_type.h" |
| 37 #include "content/public/test/test_browser_thread_bundle.h" | 37 #include "content/public/test/test_browser_thread_bundle.h" |
| 38 #include "extensions/features/features.h" |
| 38 #include "net/base/request_priority.h" | 39 #include "net/base/request_priority.h" |
| 39 #include "net/http/http_request_headers.h" | 40 #include "net/http/http_request_headers.h" |
| 40 #include "net/socket/socket_test_util.h" | 41 #include "net/socket/socket_test_util.h" |
| 41 #include "net/url_request/url_request.h" | 42 #include "net/url_request/url_request.h" |
| 42 #include "net/url_request/url_request_test_util.h" | 43 #include "net/url_request/url_request_test_util.h" |
| 43 #include "testing/gtest/include/gtest/gtest.h" | 44 #include "testing/gtest/include/gtest/gtest.h" |
| 44 #include "url/gurl.h" | 45 #include "url/gurl.h" |
| 45 | 46 |
| 46 #if defined(ENABLE_EXTENSIONS) | 47 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 47 #include "chrome/browser/extensions/event_router_forwarder.h" | 48 #include "chrome/browser/extensions/event_router_forwarder.h" |
| 48 #endif | 49 #endif |
| 49 | 50 |
| 50 namespace { | 51 namespace { |
| 51 | 52 |
| 52 // This function requests a URL, and makes it return a known response. If | 53 // This function requests a URL, and makes it return a known response. If |
| 53 // |from_user| is true, it attaches a ResourceRequestInfo to the URLRequest, | 54 // |from_user| is true, it attaches a ResourceRequestInfo to the URLRequest, |
| 54 // because requests from users have this info. If |from_user| is false, the | 55 // because requests from users have this info. If |from_user| is false, the |
| 55 // request is presumed to be from a service, and the service name is set in the | 56 // request is presumed to be from a service, and the service name is set in the |
| 56 // request's user data. (As an example suggestions service tag is attached). if | 57 // request's user data. (As an example suggestions service tag is attached). if |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 int64_t off_the_record_rx_bytes_; | 138 int64_t off_the_record_rx_bytes_; |
| 138 }; | 139 }; |
| 139 | 140 |
| 140 } // namespace | 141 } // namespace |
| 141 | 142 |
| 142 class ChromeNetworkDelegateTest : public testing::Test { | 143 class ChromeNetworkDelegateTest : public testing::Test { |
| 143 public: | 144 public: |
| 144 ChromeNetworkDelegateTest() | 145 ChromeNetworkDelegateTest() |
| 145 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), | 146 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), |
| 146 context_(new net::TestURLRequestContext(true)) { | 147 context_(new net::TestURLRequestContext(true)) { |
| 147 #if defined(ENABLE_EXTENSIONS) | 148 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 148 forwarder_ = new extensions::EventRouterForwarder(); | 149 forwarder_ = new extensions::EventRouterForwarder(); |
| 149 #endif | 150 #endif |
| 150 } | 151 } |
| 151 | 152 |
| 152 void SetUp() override { | 153 void SetUp() override { |
| 153 ChromeNetworkDelegate::InitializePrefsOnUIThread( | 154 ChromeNetworkDelegate::InitializePrefsOnUIThread( |
| 154 &enable_referrers_, nullptr, nullptr, nullptr, nullptr, | 155 &enable_referrers_, nullptr, nullptr, nullptr, nullptr, |
| 155 profile_.GetTestingPrefService()); | 156 profile_.GetTestingPrefService()); |
| 156 profile_manager_.reset( | 157 profile_manager_.reset( |
| 157 new TestingProfileManager(TestingBrowserProcess::GetGlobal())); | 158 new TestingProfileManager(TestingBrowserProcess::GetGlobal())); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 169 | 170 |
| 170 net::TestURLRequestContext* context() { return context_.get(); } | 171 net::TestURLRequestContext* context() { return context_.get(); } |
| 171 net::NetworkDelegate* network_delegate() { return network_delegate_.get(); } | 172 net::NetworkDelegate* network_delegate() { return network_delegate_.get(); } |
| 172 net::MockClientSocketFactory* socket_factory() { return &socket_factory_; } | 173 net::MockClientSocketFactory* socket_factory() { return &socket_factory_; } |
| 173 | 174 |
| 174 ChromeNetworkDelegate* chrome_network_delegate() { | 175 ChromeNetworkDelegate* chrome_network_delegate() { |
| 175 return network_delegate_.get(); | 176 return network_delegate_.get(); |
| 176 } | 177 } |
| 177 | 178 |
| 178 extensions::EventRouterForwarder* forwarder() { | 179 extensions::EventRouterForwarder* forwarder() { |
| 179 #if defined(ENABLE_EXTENSIONS) | 180 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 180 return forwarder_.get(); | 181 return forwarder_.get(); |
| 181 #else | 182 #else |
| 182 return nullptr; | 183 return nullptr; |
| 183 #endif | 184 #endif |
| 184 } | 185 } |
| 185 | 186 |
| 186 private: | 187 private: |
| 187 std::unique_ptr<TestingProfileManager> profile_manager_; | 188 std::unique_ptr<TestingProfileManager> profile_manager_; |
| 188 content::TestBrowserThreadBundle thread_bundle_; | 189 content::TestBrowserThreadBundle thread_bundle_; |
| 189 #if defined(ENABLE_EXTENSIONS) | 190 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 190 scoped_refptr<extensions::EventRouterForwarder> forwarder_; | 191 scoped_refptr<extensions::EventRouterForwarder> forwarder_; |
| 191 #endif | 192 #endif |
| 192 TestingProfile profile_; | 193 TestingProfile profile_; |
| 193 BooleanPrefMember enable_referrers_; | 194 BooleanPrefMember enable_referrers_; |
| 194 std::unique_ptr<ChromeNetworkDelegate> network_delegate_; | 195 std::unique_ptr<ChromeNetworkDelegate> network_delegate_; |
| 195 net::MockClientSocketFactory socket_factory_; | 196 net::MockClientSocketFactory socket_factory_; |
| 196 std::unique_ptr<net::TestURLRequestContext> context_; | 197 std::unique_ptr<net::TestURLRequestContext> context_; |
| 197 }; | 198 }; |
| 198 | 199 |
| 199 // Test that the total data use consumed by Chrome is recorded correctly. | 200 // Test that the total data use consumed by Chrome is recorded correctly. |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 EXPECT_EQ(request->GetTotalSentBytes(), | 359 EXPECT_EQ(request->GetTotalSentBytes(), |
| 359 fake_aggregator.off_the_record_tx_bytes()); | 360 fake_aggregator.off_the_record_tx_bytes()); |
| 360 EXPECT_EQ(request->GetTotalReceivedBytes(), | 361 EXPECT_EQ(request->GetTotalReceivedBytes(), |
| 361 fake_aggregator.off_the_record_rx_bytes()); | 362 fake_aggregator.off_the_record_rx_bytes()); |
| 362 } | 363 } |
| 363 | 364 |
| 364 class ChromeNetworkDelegatePolicyTest : public testing::Test { | 365 class ChromeNetworkDelegatePolicyTest : public testing::Test { |
| 365 public: | 366 public: |
| 366 ChromeNetworkDelegatePolicyTest() | 367 ChromeNetworkDelegatePolicyTest() |
| 367 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) { | 368 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) { |
| 368 #if defined(ENABLE_EXTENSIONS) | 369 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 369 forwarder_ = new extensions::EventRouterForwarder(); | 370 forwarder_ = new extensions::EventRouterForwarder(); |
| 370 #endif | 371 #endif |
| 371 } | 372 } |
| 372 | 373 |
| 373 protected: | 374 protected: |
| 374 void SetDelegate(net::NetworkDelegate* delegate) { | 375 void SetDelegate(net::NetworkDelegate* delegate) { |
| 375 context_.set_network_delegate(delegate); | 376 context_.set_network_delegate(delegate); |
| 376 } | 377 } |
| 377 | 378 |
| 378 extensions::EventRouterForwarder* forwarder() { | 379 extensions::EventRouterForwarder* forwarder() { |
| 379 #if defined(ENABLE_EXTENSIONS) | 380 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 380 return forwarder_.get(); | 381 return forwarder_.get(); |
| 381 #else | 382 #else |
| 382 return nullptr; | 383 return nullptr; |
| 383 #endif | 384 #endif |
| 384 } | 385 } |
| 385 | 386 |
| 386 content::TestBrowserThreadBundle thread_bundle_; | 387 content::TestBrowserThreadBundle thread_bundle_; |
| 387 #if defined(ENABLE_EXTENSIONS) | 388 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 388 scoped_refptr<extensions::EventRouterForwarder> forwarder_; | 389 scoped_refptr<extensions::EventRouterForwarder> forwarder_; |
| 389 #endif | 390 #endif |
| 390 TestingProfile profile_; | 391 TestingProfile profile_; |
| 391 BooleanPrefMember enable_referrers_; | 392 BooleanPrefMember enable_referrers_; |
| 392 net::TestURLRequestContext context_; | 393 net::TestURLRequestContext context_; |
| 393 net::TestDelegate delegate_; | 394 net::TestDelegate delegate_; |
| 394 DISALLOW_COPY_AND_ASSIGN(ChromeNetworkDelegatePolicyTest); | 395 DISALLOW_COPY_AND_ASSIGN(ChromeNetworkDelegatePolicyTest); |
| 395 }; | 396 }; |
| 396 | 397 |
| 397 class ChromeNetworkDelegateSafeSearchTest : | 398 class ChromeNetworkDelegateSafeSearchTest : |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 std::unique_ptr<net::NetworkDelegate> delegate(CreateNetworkDelegate()); | 552 std::unique_ptr<net::NetworkDelegate> delegate(CreateNetworkDelegate()); |
| 552 SetDelegate(delegate.get()); | 553 SetDelegate(delegate.get()); |
| 553 CheckAllowedDomainsHeaders("google.com", GURL("http://example.com"), false); | 554 CheckAllowedDomainsHeaders("google.com", GURL("http://example.com"), false); |
| 554 } | 555 } |
| 555 | 556 |
| 556 // Privacy Mode disables Channel Id if cookies are blocked (cr223191) | 557 // Privacy Mode disables Channel Id if cookies are blocked (cr223191) |
| 557 class ChromeNetworkDelegatePrivacyModeTest : public testing::Test { | 558 class ChromeNetworkDelegatePrivacyModeTest : public testing::Test { |
| 558 public: | 559 public: |
| 559 ChromeNetworkDelegatePrivacyModeTest() | 560 ChromeNetworkDelegatePrivacyModeTest() |
| 560 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), | 561 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), |
| 561 #if defined(ENABLE_EXTENSIONS) | 562 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 562 forwarder_(new extensions::EventRouterForwarder()), | 563 forwarder_(new extensions::EventRouterForwarder()), |
| 563 #endif | 564 #endif |
| 564 cookie_settings_(CookieSettingsFactory::GetForProfile(&profile_).get()), | 565 cookie_settings_(CookieSettingsFactory::GetForProfile(&profile_).get()), |
| 565 kBlockedSite("http://ads.thirdparty.com"), | 566 kBlockedSite("http://ads.thirdparty.com"), |
| 566 kAllowedSite("http://good.allays.com"), | 567 kAllowedSite("http://good.allays.com"), |
| 567 kFirstPartySite("http://cool.things.com"), | 568 kFirstPartySite("http://cool.things.com"), |
| 568 kBlockedFirstPartySite("http://no.thirdparties.com") { | 569 kBlockedFirstPartySite("http://no.thirdparties.com") { |
| 569 } | 570 } |
| 570 | 571 |
| 571 void SetUp() override { | 572 void SetUp() override { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 583 return network_delegate; | 584 return network_delegate; |
| 584 } | 585 } |
| 585 | 586 |
| 586 void SetDelegate(net::NetworkDelegate* delegate) { | 587 void SetDelegate(net::NetworkDelegate* delegate) { |
| 587 network_delegate_ = delegate; | 588 network_delegate_ = delegate; |
| 588 context_.set_network_delegate(network_delegate_); | 589 context_.set_network_delegate(network_delegate_); |
| 589 } | 590 } |
| 590 | 591 |
| 591 protected: | 592 protected: |
| 592 extensions::EventRouterForwarder* forwarder() { | 593 extensions::EventRouterForwarder* forwarder() { |
| 593 #if defined(ENABLE_EXTENSIONS) | 594 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 594 return forwarder_.get(); | 595 return forwarder_.get(); |
| 595 #else | 596 #else |
| 596 return NULL; | 597 return NULL; |
| 597 #endif | 598 #endif |
| 598 } | 599 } |
| 599 | 600 |
| 600 content::TestBrowserThreadBundle thread_bundle_; | 601 content::TestBrowserThreadBundle thread_bundle_; |
| 601 #if defined(ENABLE_EXTENSIONS) | 602 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 602 scoped_refptr<extensions::EventRouterForwarder> forwarder_; | 603 scoped_refptr<extensions::EventRouterForwarder> forwarder_; |
| 603 #endif | 604 #endif |
| 604 TestingProfile profile_; | 605 TestingProfile profile_; |
| 605 content_settings::CookieSettings* cookie_settings_; | 606 content_settings::CookieSettings* cookie_settings_; |
| 606 BooleanPrefMember enable_referrers_; | 607 BooleanPrefMember enable_referrers_; |
| 607 std::unique_ptr<net::URLRequest> request_; | 608 std::unique_ptr<net::URLRequest> request_; |
| 608 net::TestURLRequestContext context_; | 609 net::TestURLRequestContext context_; |
| 609 net::NetworkDelegate* network_delegate_; | 610 net::NetworkDelegate* network_delegate_; |
| 610 | 611 |
| 611 const GURL kBlockedSite; | 612 const GURL kBlockedSite; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 658 | 659 |
| 659 EXPECT_FALSE(network_delegate_->CanEnablePrivacyMode(kAllowedSite, | 660 EXPECT_FALSE(network_delegate_->CanEnablePrivacyMode(kAllowedSite, |
| 660 kBlockedFirstPartySite)); | 661 kBlockedFirstPartySite)); |
| 661 | 662 |
| 662 cookie_settings_->SetCookieSetting(kBlockedFirstPartySite, | 663 cookie_settings_->SetCookieSetting(kBlockedFirstPartySite, |
| 663 CONTENT_SETTING_BLOCK); | 664 CONTENT_SETTING_BLOCK); |
| 664 // Privacy mode is disabled as kAllowedSite is still getting cookies | 665 // Privacy mode is disabled as kAllowedSite is still getting cookies |
| 665 EXPECT_FALSE(network_delegate_->CanEnablePrivacyMode(kAllowedSite, | 666 EXPECT_FALSE(network_delegate_->CanEnablePrivacyMode(kAllowedSite, |
| 666 kBlockedFirstPartySite)); | 667 kBlockedFirstPartySite)); |
| 667 } | 668 } |
| OLD | NEW |