| 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.h" | 9 #include "base/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" | 12 #include "chrome/browser/extensions/event_router_forwarder.h" |
| 13 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
| 14 #include "chrome/common/url_constants.h" | 14 #include "chrome/common/url_constants.h" |
| 15 #include "chrome/test/base/testing_pref_service_syncable.h" | 15 #include "chrome/test/base/testing_pref_service_syncable.h" |
| 16 #include "chrome/test/base/testing_profile.h" | 16 #include "chrome/test/base/testing_profile.h" |
| 17 #include "content/public/test/test_browser_thread.h" | 17 #include "content/public/test/test_browser_thread_bundle.h" |
| 18 #include "net/base/completion_callback.h" | 18 #include "net/base/completion_callback.h" |
| 19 #include "net/url_request/url_request.h" | 19 #include "net/url_request/url_request.h" |
| 20 #include "net/url_request/url_request_test_util.h" | 20 #include "net/url_request/url_request_test_util.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 22 | 22 |
| 23 class ChromeNetworkDelegateTest : public testing::Test { | 23 class ChromeNetworkDelegateTest : public testing::Test { |
| 24 protected: | 24 protected: |
| 25 ChromeNetworkDelegateTest() | 25 ChromeNetworkDelegateTest() |
| 26 : forwarder_(new extensions::EventRouterForwarder()) { | 26 : forwarder_(new extensions::EventRouterForwarder()) { |
| 27 } | 27 } |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 BooleanPrefMember pref_member_; | 84 BooleanPrefMember pref_member_; |
| 85 }; | 85 }; |
| 86 | 86 |
| 87 TEST_F(ChromeNetworkDelegateTest, NeverThrottleLogic) { | 87 TEST_F(ChromeNetworkDelegateTest, NeverThrottleLogic) { |
| 88 NeverThrottleLogicImpl(); | 88 NeverThrottleLogicImpl(); |
| 89 } | 89 } |
| 90 | 90 |
| 91 class ChromeNetworkDelegateSafeSearchTest : public testing::Test { | 91 class ChromeNetworkDelegateSafeSearchTest : public testing::Test { |
| 92 public: | 92 public: |
| 93 ChromeNetworkDelegateSafeSearchTest() | 93 ChromeNetworkDelegateSafeSearchTest() |
| 94 : ui_thread_(content::BrowserThread::UI, &message_loop_), | 94 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), |
| 95 io_thread_(content::BrowserThread::IO, &message_loop_), | |
| 96 forwarder_(new extensions::EventRouterForwarder()) { | 95 forwarder_(new extensions::EventRouterForwarder()) { |
| 97 } | 96 } |
| 98 | 97 |
| 99 virtual void SetUp() OVERRIDE { | 98 virtual void SetUp() OVERRIDE { |
| 100 ChromeNetworkDelegate::InitializePrefsOnUIThread( | 99 ChromeNetworkDelegate::InitializePrefsOnUIThread( |
| 101 &enable_referrers_, NULL, &force_google_safe_search_, | 100 &enable_referrers_, NULL, &force_google_safe_search_, |
| 102 profile_.GetTestingPrefService()); | 101 profile_.GetTestingPrefService()); |
| 103 } | 102 } |
| 104 | 103 |
| 105 protected: | 104 protected: |
| (...skipping 24 matching lines...) Expand all Loading... |
| 130 net::TestURLRequest request( | 129 net::TestURLRequest request( |
| 131 GURL(url_string), &delegate_, &context_, network_delegate_); | 130 GURL(url_string), &delegate_, &context_, network_delegate_); |
| 132 | 131 |
| 133 request.Start(); | 132 request.Start(); |
| 134 base::MessageLoop::current()->RunUntilIdle(); | 133 base::MessageLoop::current()->RunUntilIdle(); |
| 135 | 134 |
| 136 EXPECT_EQ(expected_query_parameters, request.url().query()); | 135 EXPECT_EQ(expected_query_parameters, request.url().query()); |
| 137 } | 136 } |
| 138 | 137 |
| 139 private: | 138 private: |
| 140 base::MessageLoopForIO message_loop_; | 139 content::TestBrowserThreadBundle thread_bundle_; |
| 141 content::TestBrowserThread ui_thread_; | |
| 142 content::TestBrowserThread io_thread_; | |
| 143 scoped_refptr<extensions::EventRouterForwarder> forwarder_; | 140 scoped_refptr<extensions::EventRouterForwarder> forwarder_; |
| 144 TestingProfile profile_; | 141 TestingProfile profile_; |
| 145 BooleanPrefMember enable_referrers_; | 142 BooleanPrefMember enable_referrers_; |
| 146 BooleanPrefMember force_google_safe_search_; | 143 BooleanPrefMember force_google_safe_search_; |
| 147 scoped_ptr<net::URLRequest> request_; | 144 scoped_ptr<net::URLRequest> request_; |
| 148 net::TestURLRequestContext context_; | 145 net::TestURLRequestContext context_; |
| 149 net::NetworkDelegate* network_delegate_; | 146 net::NetworkDelegate* network_delegate_; |
| 150 net::TestDelegate delegate_; | 147 net::TestDelegate delegate_; |
| 151 }; | 148 }; |
| 152 | 149 |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 | 276 |
| 280 // Test the home page with parameters and safe set to active. | 277 // Test the home page with parameters and safe set to active. |
| 281 CheckAddedParameters("http://google.com/search?q=google&safe=active", | 278 CheckAddedParameters("http://google.com/search?q=google&safe=active", |
| 282 "q=google&safe=active"); | 279 "q=google&safe=active"); |
| 283 } | 280 } |
| 284 | 281 |
| 285 // Privacy Mode disables Channel Id if cookies are blocked (cr223191) | 282 // Privacy Mode disables Channel Id if cookies are blocked (cr223191) |
| 286 class ChromeNetworkDelegatePrivacyModeTest : public testing::Test { | 283 class ChromeNetworkDelegatePrivacyModeTest : public testing::Test { |
| 287 public: | 284 public: |
| 288 ChromeNetworkDelegatePrivacyModeTest() | 285 ChromeNetworkDelegatePrivacyModeTest() |
| 289 : ui_thread_(content::BrowserThread::UI, &message_loop_), | 286 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), |
| 290 io_thread_(content::BrowserThread::IO, &message_loop_), | |
| 291 forwarder_(new extensions::EventRouterForwarder()), | 287 forwarder_(new extensions::EventRouterForwarder()), |
| 292 cookie_settings_(CookieSettings::Factory::GetForProfile(&profile_)), | 288 cookie_settings_(CookieSettings::Factory::GetForProfile(&profile_)), |
| 293 kBlockedSite("http://ads.thirdparty.com"), | 289 kBlockedSite("http://ads.thirdparty.com"), |
| 294 kAllowedSite("http://good.allays.com"), | 290 kAllowedSite("http://good.allays.com"), |
| 295 kFirstPartySite("http://cool.things.com"), | 291 kFirstPartySite("http://cool.things.com"), |
| 296 kBlockedFirstPartySite("http://no.thirdparties.com") { | 292 kBlockedFirstPartySite("http://no.thirdparties.com") { |
| 297 } | 293 } |
| 298 | 294 |
| 299 virtual void SetUp() OVERRIDE { | 295 virtual void SetUp() OVERRIDE { |
| 300 ChromeNetworkDelegate::InitializePrefsOnUIThread( | 296 ChromeNetworkDelegate::InitializePrefsOnUIThread( |
| 301 &enable_referrers_, NULL, NULL, | 297 &enable_referrers_, NULL, NULL, |
| 302 profile_.GetTestingPrefService()); | 298 profile_.GetTestingPrefService()); |
| 303 } | 299 } |
| 304 | 300 |
| 305 protected: | 301 protected: |
| 306 scoped_ptr<ChromeNetworkDelegate> CreateNetworkDelegate() { | 302 scoped_ptr<ChromeNetworkDelegate> CreateNetworkDelegate() { |
| 307 scoped_ptr<ChromeNetworkDelegate> network_delegate( | 303 scoped_ptr<ChromeNetworkDelegate> network_delegate( |
| 308 new ChromeNetworkDelegate(forwarder_.get(), &enable_referrers_)); | 304 new ChromeNetworkDelegate(forwarder_.get(), &enable_referrers_)); |
| 309 network_delegate->set_cookie_settings(cookie_settings_); | 305 network_delegate->set_cookie_settings(cookie_settings_); |
| 310 return network_delegate.Pass(); | 306 return network_delegate.Pass(); |
| 311 } | 307 } |
| 312 | 308 |
| 313 void SetDelegate(net::NetworkDelegate* delegate) { | 309 void SetDelegate(net::NetworkDelegate* delegate) { |
| 314 network_delegate_ = delegate; | 310 network_delegate_ = delegate; |
| 315 context_.set_network_delegate(network_delegate_); | 311 context_.set_network_delegate(network_delegate_); |
| 316 } | 312 } |
| 317 | 313 |
| 318 protected: | 314 protected: |
| 319 base::MessageLoopForIO message_loop_; | 315 content::TestBrowserThreadBundle thread_bundle_; |
| 320 content::TestBrowserThread ui_thread_; | |
| 321 content::TestBrowserThread io_thread_; | |
| 322 scoped_refptr<extensions::EventRouterForwarder> forwarder_; | 316 scoped_refptr<extensions::EventRouterForwarder> forwarder_; |
| 323 TestingProfile profile_; | 317 TestingProfile profile_; |
| 324 CookieSettings* cookie_settings_; | 318 CookieSettings* cookie_settings_; |
| 325 BooleanPrefMember enable_referrers_; | 319 BooleanPrefMember enable_referrers_; |
| 326 scoped_ptr<net::URLRequest> request_; | 320 scoped_ptr<net::URLRequest> request_; |
| 327 net::TestURLRequestContext context_; | 321 net::TestURLRequestContext context_; |
| 328 net::NetworkDelegate* network_delegate_; | 322 net::NetworkDelegate* network_delegate_; |
| 329 | 323 |
| 330 const GURL kBlockedSite; | 324 const GURL kBlockedSite; |
| 331 const GURL kAllowedSite; | 325 const GURL kAllowedSite; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 | 377 |
| 384 cookie_settings_->SetCookieSetting( | 378 cookie_settings_->SetCookieSetting( |
| 385 ContentSettingsPattern::FromURL(kBlockedFirstPartySite), | 379 ContentSettingsPattern::FromURL(kBlockedFirstPartySite), |
| 386 ContentSettingsPattern::Wildcard(), | 380 ContentSettingsPattern::Wildcard(), |
| 387 CONTENT_SETTING_BLOCK); | 381 CONTENT_SETTING_BLOCK); |
| 388 // Privacy mode is disabled as kAllowedSite is still getting cookies | 382 // Privacy mode is disabled as kAllowedSite is still getting cookies |
| 389 EXPECT_FALSE(network_delegate_->CanEnablePrivacyMode(kAllowedSite, | 383 EXPECT_FALSE(network_delegate_->CanEnablePrivacyMode(kAllowedSite, |
| 390 kBlockedFirstPartySite)); | 384 kBlockedFirstPartySite)); |
| 391 } | 385 } |
| 392 | 386 |
| OLD | NEW |