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 "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/prefs/pref_member.h" | 10 #include "base/prefs/pref_member.h" |
| 11 #include "chrome/browser/content_settings/cookie_settings.h" | 11 #include "chrome/browser/content_settings/cookie_settings.h" |
| 12 #include "chrome/browser/extensions/event_router_forwarder.h" | |
| 13 #include "chrome/common/pref_names.h" | 12 #include "chrome/common/pref_names.h" |
| 14 #include "chrome/common/url_constants.h" | 13 #include "chrome/common/url_constants.h" |
| 15 #include "chrome/test/base/testing_pref_service_syncable.h" | 14 #include "chrome/test/base/testing_pref_service_syncable.h" |
| 16 #include "chrome/test/base/testing_profile.h" | 15 #include "chrome/test/base/testing_profile.h" |
| 17 #include "content/public/test/test_browser_thread_bundle.h" | 16 #include "content/public/test/test_browser_thread_bundle.h" |
| 18 #include "net/base/completion_callback.h" | 17 #include "net/base/completion_callback.h" |
| 19 #include "net/base/request_priority.h" | 18 #include "net/base/request_priority.h" |
| 20 #include "net/url_request/url_request.h" | 19 #include "net/url_request/url_request.h" |
| 21 #include "net/url_request/url_request_test_util.h" | 20 #include "net/url_request/url_request_test_util.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 23 | 22 |
| 23 #if defined(ENABLE_EXTENSIONS) | |
| 24 #include "chrome/browser/extensions/event_router_forwarder.h" | |
| 25 #endif | |
| 26 | |
| 27 #if defined(ENABLE_EXTENSIONS) | |
| 24 class ChromeNetworkDelegateTest : public testing::Test { | 28 class ChromeNetworkDelegateTest : public testing::Test { |
| 25 protected: | 29 protected: |
| 26 ChromeNetworkDelegateTest() | 30 ChromeNetworkDelegateTest() |
| 27 : forwarder_(new extensions::EventRouterForwarder()) { | 31 : forwarder_(new extensions::EventRouterForwarder()) { |
| 28 } | 32 } |
| 29 | 33 |
| 30 virtual void SetUp() OVERRIDE { | 34 virtual void SetUp() OVERRIDE { |
| 31 never_throttle_requests_original_value_ = | 35 never_throttle_requests_original_value_ = |
| 32 ChromeNetworkDelegate::g_never_throttle_requests_; | 36 ChromeNetworkDelegate::g_never_throttle_requests_; |
| 33 ChromeNetworkDelegate::g_never_throttle_requests_ = false; | 37 ChromeNetworkDelegate::g_never_throttle_requests_ = false; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 81 bool never_throttle_requests_original_value_; | 85 bool never_throttle_requests_original_value_; |
| 82 base::MessageLoopForIO message_loop_; | 86 base::MessageLoopForIO message_loop_; |
| 83 | 87 |
| 84 scoped_refptr<extensions::EventRouterForwarder> forwarder_; | 88 scoped_refptr<extensions::EventRouterForwarder> forwarder_; |
| 85 BooleanPrefMember pref_member_; | 89 BooleanPrefMember pref_member_; |
| 86 }; | 90 }; |
| 87 | 91 |
| 88 TEST_F(ChromeNetworkDelegateTest, NeverThrottleLogic) { | 92 TEST_F(ChromeNetworkDelegateTest, NeverThrottleLogic) { |
| 89 NeverThrottleLogicImpl(); | 93 NeverThrottleLogicImpl(); |
| 90 } | 94 } |
| 95 #endif // defined(ENABLE_EXTENSIONS) | |
| 91 | 96 |
| 92 class ChromeNetworkDelegateSafeSearchTest : public testing::Test { | 97 class ChromeNetworkDelegateSafeSearchTest : public testing::Test { |
| 93 public: | 98 public: |
| 94 ChromeNetworkDelegateSafeSearchTest() | 99 ChromeNetworkDelegateSafeSearchTest() |
| 95 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), | 100 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) { |
| 96 forwarder_(new extensions::EventRouterForwarder()) { | 101 #if defined(ENABLE_EXTENSIONS) |
| 102 forwarder_ = new extensions::EventRouterForwarder(); | |
| 103 #endif | |
| 97 } | 104 } |
| 98 | 105 |
| 99 virtual void SetUp() OVERRIDE { | 106 virtual void SetUp() OVERRIDE { |
| 100 ChromeNetworkDelegate::InitializePrefsOnUIThread( | 107 ChromeNetworkDelegate::InitializePrefsOnUIThread( |
| 101 &enable_referrers_, NULL, &force_google_safe_search_, | 108 &enable_referrers_, NULL, &force_google_safe_search_, |
| 102 profile_.GetTestingPrefService()); | 109 profile_.GetTestingPrefService()); |
| 103 } | 110 } |
| 104 | 111 |
| 105 protected: | 112 protected: |
| 106 scoped_ptr<net::NetworkDelegate> CreateNetworkDelegate() { | 113 scoped_ptr<net::NetworkDelegate> CreateNetworkDelegate() { |
| 107 scoped_ptr<ChromeNetworkDelegate> network_delegate( | 114 scoped_ptr<ChromeNetworkDelegate> network_delegate( |
| 108 new ChromeNetworkDelegate(forwarder_.get(), &enable_referrers_)); | 115 new ChromeNetworkDelegate( |
| 116 #if defined(ENABLE_EXTENSIONS) | |
| 117 forwarder_.get(), | |
| 118 #else | |
| 119 NULL, | |
| 120 #endif | |
|
Ryan Sleevi
2014/07/16 20:23:44
Wrap this into a fixture helper?
Lei Zhang
2014/07/18 01:34:24
Done.
| |
| 121 &enable_referrers_)); | |
| 109 network_delegate->set_force_google_safe_search(&force_google_safe_search_); | 122 network_delegate->set_force_google_safe_search(&force_google_safe_search_); |
| 110 return network_delegate.PassAs<net::NetworkDelegate>(); | 123 return network_delegate.PassAs<net::NetworkDelegate>(); |
| 111 } | 124 } |
| 112 | 125 |
| 113 void SetSafeSearch(bool value) { | 126 void SetSafeSearch(bool value) { |
| 114 force_google_safe_search_.SetValue(value); | 127 force_google_safe_search_.SetValue(value); |
| 115 } | 128 } |
| 116 | 129 |
| 117 void SetDelegate(net::NetworkDelegate* delegate) { | 130 void SetDelegate(net::NetworkDelegate* delegate) { |
| 118 network_delegate_ = delegate; | 131 network_delegate_ = delegate; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 131 GURL(url_string), net::DEFAULT_PRIORITY, &delegate_, &context_); | 144 GURL(url_string), net::DEFAULT_PRIORITY, &delegate_, &context_); |
| 132 | 145 |
| 133 request.Start(); | 146 request.Start(); |
| 134 base::MessageLoop::current()->RunUntilIdle(); | 147 base::MessageLoop::current()->RunUntilIdle(); |
| 135 | 148 |
| 136 EXPECT_EQ(expected_query_parameters, request.url().query()); | 149 EXPECT_EQ(expected_query_parameters, request.url().query()); |
| 137 } | 150 } |
| 138 | 151 |
| 139 private: | 152 private: |
| 140 content::TestBrowserThreadBundle thread_bundle_; | 153 content::TestBrowserThreadBundle thread_bundle_; |
| 154 #if defined(ENABLE_EXTENSIONS) | |
| 141 scoped_refptr<extensions::EventRouterForwarder> forwarder_; | 155 scoped_refptr<extensions::EventRouterForwarder> forwarder_; |
| 156 #endif | |
| 142 TestingProfile profile_; | 157 TestingProfile profile_; |
| 143 BooleanPrefMember enable_referrers_; | 158 BooleanPrefMember enable_referrers_; |
| 144 BooleanPrefMember force_google_safe_search_; | 159 BooleanPrefMember force_google_safe_search_; |
| 145 scoped_ptr<net::URLRequest> request_; | 160 scoped_ptr<net::URLRequest> request_; |
| 146 net::TestURLRequestContext context_; | 161 net::TestURLRequestContext context_; |
| 147 net::NetworkDelegate* network_delegate_; | 162 net::NetworkDelegate* network_delegate_; |
| 148 net::TestDelegate delegate_; | 163 net::TestDelegate delegate_; |
| 149 }; | 164 }; |
| 150 | 165 |
| 151 TEST_F(ChromeNetworkDelegateSafeSearchTest, SafeSearchOn) { | 166 TEST_F(ChromeNetworkDelegateSafeSearchTest, SafeSearchOn) { |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 278 // Test the home page with parameters and safe set to active. | 293 // Test the home page with parameters and safe set to active. |
| 279 CheckAddedParameters("http://google.com/search?q=google&safe=active", | 294 CheckAddedParameters("http://google.com/search?q=google&safe=active", |
| 280 "q=google&safe=active"); | 295 "q=google&safe=active"); |
| 281 } | 296 } |
| 282 | 297 |
| 283 // Privacy Mode disables Channel Id if cookies are blocked (cr223191) | 298 // Privacy Mode disables Channel Id if cookies are blocked (cr223191) |
| 284 class ChromeNetworkDelegatePrivacyModeTest : public testing::Test { | 299 class ChromeNetworkDelegatePrivacyModeTest : public testing::Test { |
| 285 public: | 300 public: |
| 286 ChromeNetworkDelegatePrivacyModeTest() | 301 ChromeNetworkDelegatePrivacyModeTest() |
| 287 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), | 302 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), |
| 303 #if defined(ENABLE_EXTENSIONS) | |
| 288 forwarder_(new extensions::EventRouterForwarder()), | 304 forwarder_(new extensions::EventRouterForwarder()), |
| 305 #endif | |
| 289 cookie_settings_(CookieSettings::Factory::GetForProfile(&profile_) | 306 cookie_settings_(CookieSettings::Factory::GetForProfile(&profile_) |
| 290 .get()), | 307 .get()), |
| 291 kBlockedSite("http://ads.thirdparty.com"), | 308 kBlockedSite("http://ads.thirdparty.com"), |
| 292 kAllowedSite("http://good.allays.com"), | 309 kAllowedSite("http://good.allays.com"), |
| 293 kFirstPartySite("http://cool.things.com"), | 310 kFirstPartySite("http://cool.things.com"), |
| 294 kBlockedFirstPartySite("http://no.thirdparties.com") {} | 311 kBlockedFirstPartySite("http://no.thirdparties.com") {} |
| 295 | 312 |
| 296 virtual void SetUp() OVERRIDE { | 313 virtual void SetUp() OVERRIDE { |
| 297 ChromeNetworkDelegate::InitializePrefsOnUIThread( | 314 ChromeNetworkDelegate::InitializePrefsOnUIThread( |
| 298 &enable_referrers_, NULL, NULL, | 315 &enable_referrers_, NULL, NULL, |
| 299 profile_.GetTestingPrefService()); | 316 profile_.GetTestingPrefService()); |
| 300 } | 317 } |
| 301 | 318 |
| 302 protected: | 319 protected: |
| 303 scoped_ptr<ChromeNetworkDelegate> CreateNetworkDelegate() { | 320 scoped_ptr<ChromeNetworkDelegate> CreateNetworkDelegate() { |
| 304 scoped_ptr<ChromeNetworkDelegate> network_delegate( | 321 scoped_ptr<ChromeNetworkDelegate> network_delegate( |
| 305 new ChromeNetworkDelegate(forwarder_.get(), &enable_referrers_)); | 322 new ChromeNetworkDelegate( |
| 323 #if defined(ENABLE_EXTENSIONS) | |
| 324 forwarder_.get(), | |
| 325 #else | |
| 326 NULL, | |
| 327 #endif | |
| 328 &enable_referrers_)); | |
| 306 network_delegate->set_cookie_settings(cookie_settings_); | 329 network_delegate->set_cookie_settings(cookie_settings_); |
| 307 return network_delegate.Pass(); | 330 return network_delegate.Pass(); |
| 308 } | 331 } |
| 309 | 332 |
| 310 void SetDelegate(net::NetworkDelegate* delegate) { | 333 void SetDelegate(net::NetworkDelegate* delegate) { |
| 311 network_delegate_ = delegate; | 334 network_delegate_ = delegate; |
| 312 context_.set_network_delegate(network_delegate_); | 335 context_.set_network_delegate(network_delegate_); |
| 313 } | 336 } |
| 314 | 337 |
| 315 protected: | 338 protected: |
| 316 content::TestBrowserThreadBundle thread_bundle_; | 339 content::TestBrowserThreadBundle thread_bundle_; |
| 340 #if defined(ENABLE_EXTENSIONS) | |
| 317 scoped_refptr<extensions::EventRouterForwarder> forwarder_; | 341 scoped_refptr<extensions::EventRouterForwarder> forwarder_; |
| 342 #endif | |
| 318 TestingProfile profile_; | 343 TestingProfile profile_; |
| 319 CookieSettings* cookie_settings_; | 344 CookieSettings* cookie_settings_; |
| 320 BooleanPrefMember enable_referrers_; | 345 BooleanPrefMember enable_referrers_; |
| 321 scoped_ptr<net::URLRequest> request_; | 346 scoped_ptr<net::URLRequest> request_; |
| 322 net::TestURLRequestContext context_; | 347 net::TestURLRequestContext context_; |
| 323 net::NetworkDelegate* network_delegate_; | 348 net::NetworkDelegate* network_delegate_; |
| 324 | 349 |
| 325 const GURL kBlockedSite; | 350 const GURL kBlockedSite; |
| 326 const GURL kAllowedSite; | 351 const GURL kAllowedSite; |
| 327 const GURL kEmptyFirstPartySite; | 352 const GURL kEmptyFirstPartySite; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 378 | 403 |
| 379 cookie_settings_->SetCookieSetting( | 404 cookie_settings_->SetCookieSetting( |
| 380 ContentSettingsPattern::FromURL(kBlockedFirstPartySite), | 405 ContentSettingsPattern::FromURL(kBlockedFirstPartySite), |
| 381 ContentSettingsPattern::Wildcard(), | 406 ContentSettingsPattern::Wildcard(), |
| 382 CONTENT_SETTING_BLOCK); | 407 CONTENT_SETTING_BLOCK); |
| 383 // Privacy mode is disabled as kAllowedSite is still getting cookies | 408 // Privacy mode is disabled as kAllowedSite is still getting cookies |
| 384 EXPECT_FALSE(network_delegate_->CanEnablePrivacyMode(kAllowedSite, | 409 EXPECT_FALSE(network_delegate_->CanEnablePrivacyMode(kAllowedSite, |
| 385 kBlockedFirstPartySite)); | 410 kBlockedFirstPartySite)); |
| 386 } | 411 } |
| 387 | 412 |
| OLD | NEW |