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/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) { | 132 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) { |
133 #if defined(ENABLE_EXTENSIONS) | 133 #if defined(ENABLE_EXTENSIONS) |
134 forwarder_ = new extensions::EventRouterForwarder(); | 134 forwarder_ = new extensions::EventRouterForwarder(); |
135 #endif | 135 #endif |
136 } | 136 } |
137 | 137 |
138 void SetUp() override { | 138 void SetUp() override { |
139 ChromeNetworkDelegate::InitializePrefsOnUIThread( | 139 ChromeNetworkDelegate::InitializePrefsOnUIThread( |
140 &enable_referrers_, | 140 &enable_referrers_, |
141 NULL, | 141 NULL, |
142 &force_safe_search_, | |
143 &force_google_safe_search_, | 142 &force_google_safe_search_, |
144 &force_youtube_safety_mode_, | 143 &force_youtube_safety_mode_, |
145 profile_.GetTestingPrefService()); | 144 profile_.GetTestingPrefService()); |
146 } | 145 } |
147 | 146 |
148 protected: | 147 protected: |
149 scoped_ptr<net::NetworkDelegate> CreateNetworkDelegate() { | 148 scoped_ptr<net::NetworkDelegate> CreateNetworkDelegate() { |
150 scoped_ptr<ChromeNetworkDelegate> network_delegate( | 149 scoped_ptr<ChromeNetworkDelegate> network_delegate( |
151 new ChromeNetworkDelegate(forwarder(), &enable_referrers_)); | 150 new ChromeNetworkDelegate(forwarder(), &enable_referrers_)); |
152 network_delegate->set_force_safe_search(&force_safe_search_); | |
153 network_delegate->set_force_google_safe_search(&force_google_safe_search_); | 151 network_delegate->set_force_google_safe_search(&force_google_safe_search_); |
154 network_delegate->set_force_youtube_safety_mode( | 152 network_delegate->set_force_youtube_safety_mode( |
155 &force_youtube_safety_mode_); | 153 &force_youtube_safety_mode_); |
156 return network_delegate.Pass(); | 154 return network_delegate.Pass(); |
157 } | 155 } |
158 | 156 |
159 void SetSafeSearch(bool safe_search, | 157 void SetSafeSearch(bool google_safe_search, |
160 bool google_safe_search, | |
161 bool youtube_safety_mode) { | 158 bool youtube_safety_mode) { |
162 force_safe_search_.SetValue(safe_search); | |
163 force_google_safe_search_.SetValue(google_safe_search); | 159 force_google_safe_search_.SetValue(google_safe_search); |
164 force_youtube_safety_mode_.SetValue(youtube_safety_mode); | 160 force_youtube_safety_mode_.SetValue(youtube_safety_mode); |
165 } | 161 } |
166 | 162 |
167 void SetDelegate(net::NetworkDelegate* delegate) { | 163 void SetDelegate(net::NetworkDelegate* delegate) { |
168 network_delegate_ = delegate; | 164 network_delegate_ = delegate; |
169 context_.set_network_delegate(network_delegate_); | 165 context_.set_network_delegate(network_delegate_); |
170 } | 166 } |
171 | 167 |
172 // Does a request to an arbitrary URL and verifies that the SafeSearch | 168 // Does a request to an arbitrary URL and verifies that the SafeSearch |
(...skipping 23 matching lines...) Expand all Loading... |
196 return NULL; | 192 return NULL; |
197 #endif | 193 #endif |
198 } | 194 } |
199 | 195 |
200 content::TestBrowserThreadBundle thread_bundle_; | 196 content::TestBrowserThreadBundle thread_bundle_; |
201 #if defined(ENABLE_EXTENSIONS) | 197 #if defined(ENABLE_EXTENSIONS) |
202 scoped_refptr<extensions::EventRouterForwarder> forwarder_; | 198 scoped_refptr<extensions::EventRouterForwarder> forwarder_; |
203 #endif | 199 #endif |
204 TestingProfile profile_; | 200 TestingProfile profile_; |
205 BooleanPrefMember enable_referrers_; | 201 BooleanPrefMember enable_referrers_; |
206 BooleanPrefMember force_safe_search_; | |
207 BooleanPrefMember force_google_safe_search_; | 202 BooleanPrefMember force_google_safe_search_; |
208 BooleanPrefMember force_youtube_safety_mode_; | 203 BooleanPrefMember force_youtube_safety_mode_; |
209 scoped_ptr<net::URLRequest> request_; | 204 scoped_ptr<net::URLRequest> request_; |
210 net::TestURLRequestContext context_; | 205 net::TestURLRequestContext context_; |
211 net::NetworkDelegate* network_delegate_; | 206 net::NetworkDelegate* network_delegate_; |
212 net::TestDelegate delegate_; | 207 net::TestDelegate delegate_; |
213 }; | 208 }; |
214 | 209 |
215 TEST_F(ChromeNetworkDelegateSafeSearchTest, SafeSearch) { | 210 TEST_F(ChromeNetworkDelegateSafeSearchTest, SafeSearch) { |
216 scoped_ptr<net::NetworkDelegate> delegate(CreateNetworkDelegate()); | 211 scoped_ptr<net::NetworkDelegate> delegate(CreateNetworkDelegate()); |
217 SetDelegate(delegate.get()); | 212 SetDelegate(delegate.get()); |
218 | 213 |
219 // Loop over all combinations of the three policies. | 214 // Loop over all combinations of the two policies. |
220 for (int i = 0; i < 8; i++) { | 215 for (int i = 0; i < 4; i++) { |
221 bool safe_search = i % 2; | 216 bool google_safe_search = i % 2; |
222 bool google_safe_search = (i / 2) % 2; | 217 bool youtube_safety_mode = i / 2; |
223 bool youtube_safety_mode = i / 4; | 218 SetSafeSearch(google_safe_search, youtube_safety_mode); |
224 SetSafeSearch(safe_search, google_safe_search, youtube_safety_mode); | |
225 | 219 |
226 // The old "SafeSearch" policy implies both Google and YouTube. | 220 QueryURL(google_safe_search, youtube_safety_mode); |
227 bool expect_google_safe_search = safe_search || google_safe_search; | |
228 bool expect_youtube_safety_mode = safe_search || youtube_safety_mode; | |
229 QueryURL(expect_google_safe_search, expect_youtube_safety_mode); | |
230 } | 221 } |
231 } | 222 } |
232 | 223 |
233 // Privacy Mode disables Channel Id if cookies are blocked (cr223191) | 224 // Privacy Mode disables Channel Id if cookies are blocked (cr223191) |
234 class ChromeNetworkDelegatePrivacyModeTest : public testing::Test { | 225 class ChromeNetworkDelegatePrivacyModeTest : public testing::Test { |
235 public: | 226 public: |
236 ChromeNetworkDelegatePrivacyModeTest() | 227 ChromeNetworkDelegatePrivacyModeTest() |
237 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), | 228 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), |
238 #if defined(ENABLE_EXTENSIONS) | 229 #if defined(ENABLE_EXTENSIONS) |
239 forwarder_(new extensions::EventRouterForwarder()), | 230 forwarder_(new extensions::EventRouterForwarder()), |
240 #endif | 231 #endif |
241 cookie_settings_(CookieSettings::Factory::GetForProfile(&profile_) | 232 cookie_settings_(CookieSettings::Factory::GetForProfile(&profile_) |
242 .get()), | 233 .get()), |
243 kBlockedSite("http://ads.thirdparty.com"), | 234 kBlockedSite("http://ads.thirdparty.com"), |
244 kAllowedSite("http://good.allays.com"), | 235 kAllowedSite("http://good.allays.com"), |
245 kFirstPartySite("http://cool.things.com"), | 236 kFirstPartySite("http://cool.things.com"), |
246 kBlockedFirstPartySite("http://no.thirdparties.com") {} | 237 kBlockedFirstPartySite("http://no.thirdparties.com") {} |
247 | 238 |
248 void SetUp() override { | 239 void SetUp() override { |
249 ChromeNetworkDelegate::InitializePrefsOnUIThread( | 240 ChromeNetworkDelegate::InitializePrefsOnUIThread( |
250 &enable_referrers_, NULL, NULL, NULL, NULL, | 241 &enable_referrers_, NULL, NULL, NULL, |
251 profile_.GetTestingPrefService()); | 242 profile_.GetTestingPrefService()); |
252 } | 243 } |
253 | 244 |
254 protected: | 245 protected: |
255 scoped_ptr<ChromeNetworkDelegate> CreateNetworkDelegate() { | 246 scoped_ptr<ChromeNetworkDelegate> CreateNetworkDelegate() { |
256 scoped_ptr<ChromeNetworkDelegate> network_delegate( | 247 scoped_ptr<ChromeNetworkDelegate> network_delegate( |
257 new ChromeNetworkDelegate(forwarder(), &enable_referrers_)); | 248 new ChromeNetworkDelegate(forwarder(), &enable_referrers_)); |
258 network_delegate->set_cookie_settings(cookie_settings_); | 249 network_delegate->set_cookie_settings(cookie_settings_); |
259 return network_delegate.Pass(); | 250 return network_delegate.Pass(); |
260 } | 251 } |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 kBlockedFirstPartySite)); | 330 kBlockedFirstPartySite)); |
340 | 331 |
341 cookie_settings_->SetCookieSetting( | 332 cookie_settings_->SetCookieSetting( |
342 ContentSettingsPattern::FromURL(kBlockedFirstPartySite), | 333 ContentSettingsPattern::FromURL(kBlockedFirstPartySite), |
343 ContentSettingsPattern::Wildcard(), | 334 ContentSettingsPattern::Wildcard(), |
344 CONTENT_SETTING_BLOCK); | 335 CONTENT_SETTING_BLOCK); |
345 // Privacy mode is disabled as kAllowedSite is still getting cookies | 336 // Privacy mode is disabled as kAllowedSite is still getting cookies |
346 EXPECT_FALSE(network_delegate_->CanEnablePrivacyMode(kAllowedSite, | 337 EXPECT_FALSE(network_delegate_->CanEnablePrivacyMode(kAllowedSite, |
347 kBlockedFirstPartySite)); | 338 kBlockedFirstPartySite)); |
348 } | 339 } |
OLD | NEW |