Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Side by Side Diff: chrome/browser/net/chrome_network_delegate_unittest.cc

Issue 387003008: ifdef extensions code in BrowserProcess, IOThread, and ChromeNetworkDelegate. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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(forwarder(), &enable_referrers_));
109 network_delegate->set_force_google_safe_search(&force_google_safe_search_); 116 network_delegate->set_force_google_safe_search(&force_google_safe_search_);
110 return network_delegate.PassAs<net::NetworkDelegate>(); 117 return network_delegate.PassAs<net::NetworkDelegate>();
111 } 118 }
112 119
113 void SetSafeSearch(bool value) { 120 void SetSafeSearch(bool value) {
114 force_google_safe_search_.SetValue(value); 121 force_google_safe_search_.SetValue(value);
115 } 122 }
116 123
117 void SetDelegate(net::NetworkDelegate* delegate) { 124 void SetDelegate(net::NetworkDelegate* delegate) {
118 network_delegate_ = delegate; 125 network_delegate_ = delegate;
(...skipping 11 matching lines...) Expand all
130 net::TestURLRequest request( 137 net::TestURLRequest request(
131 GURL(url_string), net::DEFAULT_PRIORITY, &delegate_, &context_); 138 GURL(url_string), net::DEFAULT_PRIORITY, &delegate_, &context_);
132 139
133 request.Start(); 140 request.Start();
134 base::MessageLoop::current()->RunUntilIdle(); 141 base::MessageLoop::current()->RunUntilIdle();
135 142
136 EXPECT_EQ(expected_query_parameters, request.url().query()); 143 EXPECT_EQ(expected_query_parameters, request.url().query());
137 } 144 }
138 145
139 private: 146 private:
147 extensions::EventRouterForwarder* forwarder() {
148 #if defined(ENABLE_EXTENSIONS)
149 return forwarder_.get();
150 #else
151 return NULL;
152 #endif
153 }
154
140 content::TestBrowserThreadBundle thread_bundle_; 155 content::TestBrowserThreadBundle thread_bundle_;
156 #if defined(ENABLE_EXTENSIONS)
141 scoped_refptr<extensions::EventRouterForwarder> forwarder_; 157 scoped_refptr<extensions::EventRouterForwarder> forwarder_;
158 #endif
142 TestingProfile profile_; 159 TestingProfile profile_;
143 BooleanPrefMember enable_referrers_; 160 BooleanPrefMember enable_referrers_;
144 BooleanPrefMember force_google_safe_search_; 161 BooleanPrefMember force_google_safe_search_;
145 scoped_ptr<net::URLRequest> request_; 162 scoped_ptr<net::URLRequest> request_;
146 net::TestURLRequestContext context_; 163 net::TestURLRequestContext context_;
147 net::NetworkDelegate* network_delegate_; 164 net::NetworkDelegate* network_delegate_;
148 net::TestDelegate delegate_; 165 net::TestDelegate delegate_;
149 }; 166 };
150 167
151 TEST_F(ChromeNetworkDelegateSafeSearchTest, SafeSearchOn) { 168 TEST_F(ChromeNetworkDelegateSafeSearchTest, SafeSearchOn) {
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 // Test the home page with parameters and safe set to active. 295 // Test the home page with parameters and safe set to active.
279 CheckAddedParameters("http://google.com/search?q=google&safe=active", 296 CheckAddedParameters("http://google.com/search?q=google&safe=active",
280 "q=google&safe=active"); 297 "q=google&safe=active");
281 } 298 }
282 299
283 // Privacy Mode disables Channel Id if cookies are blocked (cr223191) 300 // Privacy Mode disables Channel Id if cookies are blocked (cr223191)
284 class ChromeNetworkDelegatePrivacyModeTest : public testing::Test { 301 class ChromeNetworkDelegatePrivacyModeTest : public testing::Test {
285 public: 302 public:
286 ChromeNetworkDelegatePrivacyModeTest() 303 ChromeNetworkDelegatePrivacyModeTest()
287 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), 304 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP),
305 #if defined(ENABLE_EXTENSIONS)
288 forwarder_(new extensions::EventRouterForwarder()), 306 forwarder_(new extensions::EventRouterForwarder()),
307 #endif
289 cookie_settings_(CookieSettings::Factory::GetForProfile(&profile_) 308 cookie_settings_(CookieSettings::Factory::GetForProfile(&profile_)
290 .get()), 309 .get()),
291 kBlockedSite("http://ads.thirdparty.com"), 310 kBlockedSite("http://ads.thirdparty.com"),
292 kAllowedSite("http://good.allays.com"), 311 kAllowedSite("http://good.allays.com"),
293 kFirstPartySite("http://cool.things.com"), 312 kFirstPartySite("http://cool.things.com"),
294 kBlockedFirstPartySite("http://no.thirdparties.com") {} 313 kBlockedFirstPartySite("http://no.thirdparties.com") {}
295 314
296 virtual void SetUp() OVERRIDE { 315 virtual void SetUp() OVERRIDE {
297 ChromeNetworkDelegate::InitializePrefsOnUIThread( 316 ChromeNetworkDelegate::InitializePrefsOnUIThread(
298 &enable_referrers_, NULL, NULL, 317 &enable_referrers_, NULL, NULL,
299 profile_.GetTestingPrefService()); 318 profile_.GetTestingPrefService());
300 } 319 }
301 320
302 protected: 321 protected:
303 scoped_ptr<ChromeNetworkDelegate> CreateNetworkDelegate() { 322 scoped_ptr<ChromeNetworkDelegate> CreateNetworkDelegate() {
304 scoped_ptr<ChromeNetworkDelegate> network_delegate( 323 scoped_ptr<ChromeNetworkDelegate> network_delegate(
305 new ChromeNetworkDelegate(forwarder_.get(), &enable_referrers_)); 324 new ChromeNetworkDelegate(forwarder(), &enable_referrers_));
306 network_delegate->set_cookie_settings(cookie_settings_); 325 network_delegate->set_cookie_settings(cookie_settings_);
307 return network_delegate.Pass(); 326 return network_delegate.Pass();
308 } 327 }
309 328
310 void SetDelegate(net::NetworkDelegate* delegate) { 329 void SetDelegate(net::NetworkDelegate* delegate) {
311 network_delegate_ = delegate; 330 network_delegate_ = delegate;
312 context_.set_network_delegate(network_delegate_); 331 context_.set_network_delegate(network_delegate_);
313 } 332 }
314 333
315 protected: 334 protected:
335 extensions::EventRouterForwarder* forwarder() {
336 #if defined(ENABLE_EXTENSIONS)
337 return forwarder_.get();
338 #else
339 return NULL;
340 #endif
341 }
342
316 content::TestBrowserThreadBundle thread_bundle_; 343 content::TestBrowserThreadBundle thread_bundle_;
344 #if defined(ENABLE_EXTENSIONS)
317 scoped_refptr<extensions::EventRouterForwarder> forwarder_; 345 scoped_refptr<extensions::EventRouterForwarder> forwarder_;
346 #endif
318 TestingProfile profile_; 347 TestingProfile profile_;
319 CookieSettings* cookie_settings_; 348 CookieSettings* cookie_settings_;
320 BooleanPrefMember enable_referrers_; 349 BooleanPrefMember enable_referrers_;
321 scoped_ptr<net::URLRequest> request_; 350 scoped_ptr<net::URLRequest> request_;
322 net::TestURLRequestContext context_; 351 net::TestURLRequestContext context_;
323 net::NetworkDelegate* network_delegate_; 352 net::NetworkDelegate* network_delegate_;
324 353
325 const GURL kBlockedSite; 354 const GURL kBlockedSite;
326 const GURL kAllowedSite; 355 const GURL kAllowedSite;
327 const GURL kEmptyFirstPartySite; 356 const GURL kEmptyFirstPartySite;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 407
379 cookie_settings_->SetCookieSetting( 408 cookie_settings_->SetCookieSetting(
380 ContentSettingsPattern::FromURL(kBlockedFirstPartySite), 409 ContentSettingsPattern::FromURL(kBlockedFirstPartySite),
381 ContentSettingsPattern::Wildcard(), 410 ContentSettingsPattern::Wildcard(),
382 CONTENT_SETTING_BLOCK); 411 CONTENT_SETTING_BLOCK);
383 // Privacy mode is disabled as kAllowedSite is still getting cookies 412 // Privacy mode is disabled as kAllowedSite is still getting cookies
384 EXPECT_FALSE(network_delegate_->CanEnablePrivacyMode(kAllowedSite, 413 EXPECT_FALSE(network_delegate_->CanEnablePrivacyMode(kAllowedSite,
385 kBlockedFirstPartySite)); 414 kBlockedFirstPartySite));
386 } 415 }
387 416
OLDNEW
« no previous file with comments | « chrome/browser/net/chrome_network_delegate.cc ('k') | chrome/browser/profiles/profile_io_data.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698