OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/data_reduction_proxy/browser/data_reduction_proxy_settings.
h" | 5 #include "components/data_reduction_proxy/browser/data_reduction_proxy_settings.
h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/md5.h" | 8 #include "base/md5.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
11 #include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h" | 11 #include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h" |
12 #include "components/data_reduction_proxy/browser/data_reduction_proxy_settings_
test_utils.h" | 12 #include "components/data_reduction_proxy/browser/data_reduction_proxy_settings_
test_utils.h" |
13 #include "components/data_reduction_proxy/common/data_reduction_proxy_pref_names
.h" | 13 #include "components/data_reduction_proxy/common/data_reduction_proxy_pref_names
.h" |
14 #include "components/data_reduction_proxy/common/data_reduction_proxy_switches.h
" | 14 #include "components/data_reduction_proxy/common/data_reduction_proxy_switches.h
" |
15 #include "net/http/http_auth.h" | 15 #include "net/http/http_auth.h" |
16 #include "net/http/http_auth_cache.h" | 16 #include "net/http/http_auth_cache.h" |
17 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
19 #include "url/gurl.h" | 19 #include "url/gurl.h" |
20 | 20 |
21 namespace { | 21 namespace { |
22 | 22 |
23 const char kProbeURLWithOKResponse[] = "http://ok.org/"; | 23 const char kProbeURLWithOKResponse[] = "http://ok.org/"; |
24 const char kProbeURLWithBadResponse[] = "http://bad.org/"; | 24 const char kProbeURLWithBadResponse[] = "http://bad.org/"; |
25 const char kProbeURLWithNoResponse[] = "http://no.org/"; | 25 const char kProbeURLWithNoResponse[] = "http://no.org/"; |
26 const char kWarmupURLWithNoContentResponse[] = "http://warm.org/"; | |
27 | 26 |
28 } // namespace | 27 } // namespace |
29 | 28 |
30 namespace data_reduction_proxy { | 29 namespace data_reduction_proxy { |
31 | 30 |
32 class DataReductionProxySettingsTest | 31 class DataReductionProxySettingsTest |
33 : public ConcreteDataReductionProxySettingsTest< | 32 : public ConcreteDataReductionProxySettingsTest< |
34 DataReductionProxySettings> { | 33 DataReductionProxySettings> { |
35 }; | 34 }; |
36 | 35 |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 settings_->data_reduction_proxy_alternative_enabled_.Init( | 232 settings_->data_reduction_proxy_alternative_enabled_.Init( |
234 prefs::kDataReductionProxyAltEnabled, | 233 prefs::kDataReductionProxyAltEnabled, |
235 settings_->GetOriginalProfilePrefs()); | 234 settings_->GetOriginalProfilePrefs()); |
236 | 235 |
237 // TODO(bengr): Test enabling/disabling while a probe is outstanding. | 236 // TODO(bengr): Test enabling/disabling while a probe is outstanding. |
238 base::MessageLoopForUI loop; | 237 base::MessageLoopForUI loop; |
239 // The proxy is enabled and unrestructed initially. | 238 // The proxy is enabled and unrestructed initially. |
240 // Request succeeded but with bad response, expect proxy to be restricted. | 239 // Request succeeded but with bad response, expect proxy to be restricted. |
241 CheckProbe(true, | 240 CheckProbe(true, |
242 kProbeURLWithBadResponse, | 241 kProbeURLWithBadResponse, |
243 kWarmupURLWithNoContentResponse, | |
244 "Bad", | 242 "Bad", |
245 true, | 243 true, |
246 true, | 244 true, |
247 true, | 245 true, |
248 false); | 246 false); |
249 // Request succeeded with valid response, expect proxy to be unrestricted. | 247 // Request succeeded with valid response, expect proxy to be unrestricted. |
250 CheckProbe(true, | 248 CheckProbe(true, |
251 kProbeURLWithOKResponse, | 249 kProbeURLWithOKResponse, |
252 kWarmupURLWithNoContentResponse, | |
253 "OK", | 250 "OK", |
254 true, | 251 true, |
255 true, | 252 true, |
256 false, | 253 false, |
257 false); | 254 false); |
258 // Request failed, expect proxy to be enabled but restricted. | 255 // Request failed, expect proxy to be enabled but restricted. |
259 CheckProbe(true, | 256 CheckProbe(true, |
260 kProbeURLWithNoResponse, | 257 kProbeURLWithNoResponse, |
261 kWarmupURLWithNoContentResponse, | |
262 "", | 258 "", |
263 false, | 259 false, |
264 true, | 260 true, |
265 true, | 261 true, |
266 false); | 262 false); |
267 // The proxy is disabled initially. Probes should not be emitted to change | 263 // The proxy is disabled initially. Probes should not be emitted to change |
268 // state. | 264 // state. |
269 CheckProbe(false, | 265 CheckProbe(false, |
270 kProbeURLWithOKResponse, | 266 kProbeURLWithOKResponse, |
271 kWarmupURLWithNoContentResponse, | |
272 "OK", | 267 "OK", |
273 true, | 268 true, |
274 false, | 269 false, |
275 false, | 270 false, |
276 false); | 271 false); |
277 } | 272 } |
278 | 273 |
279 TEST_F(DataReductionProxySettingsTest, TestOnIPAddressChanged) { | 274 TEST_F(DataReductionProxySettingsTest, TestOnIPAddressChanged) { |
280 base::MessageLoopForUI loop; | 275 base::MessageLoopForUI loop; |
281 // The proxy is enabled initially. | 276 // The proxy is enabled initially. |
282 pref_service_.SetBoolean(prefs::kDataReductionProxyEnabled, true); | 277 pref_service_.SetBoolean(prefs::kDataReductionProxyEnabled, true); |
283 settings_->spdy_proxy_auth_enabled_.Init( | 278 settings_->spdy_proxy_auth_enabled_.Init( |
284 prefs::kDataReductionProxyEnabled, | 279 prefs::kDataReductionProxyEnabled, |
285 settings_->GetOriginalProfilePrefs()); | 280 settings_->GetOriginalProfilePrefs()); |
286 settings_->data_reduction_proxy_alternative_enabled_.Init( | 281 settings_->data_reduction_proxy_alternative_enabled_.Init( |
287 prefs::kDataReductionProxyAltEnabled, | 282 prefs::kDataReductionProxyAltEnabled, |
288 settings_->GetOriginalProfilePrefs()); | 283 settings_->GetOriginalProfilePrefs()); |
289 settings_->enabled_by_user_ = true; | 284 settings_->enabled_by_user_ = true; |
290 settings_->restricted_by_carrier_ = false; | 285 settings_->restricted_by_carrier_ = false; |
291 settings_->SetProxyConfigs(true, false, false, true); | 286 settings_->SetProxyConfigs(true, false, false, true); |
292 // IP address change triggers a probe that succeeds. Proxy remains | 287 // IP address change triggers a probe that succeeds. Proxy remains |
293 // unrestricted. | 288 // unrestricted. |
294 CheckProbeOnIPChange(kProbeURLWithOKResponse, | 289 CheckProbeOnIPChange(kProbeURLWithOKResponse, |
295 kWarmupURLWithNoContentResponse, | |
296 "OK", | 290 "OK", |
297 true, | 291 true, |
298 false, | 292 false, |
299 false); | 293 false); |
300 // IP address change triggers a probe that fails. Proxy is restricted. | 294 // IP address change triggers a probe that fails. Proxy is restricted. |
301 CheckProbeOnIPChange(kProbeURLWithBadResponse, | 295 CheckProbeOnIPChange(kProbeURLWithBadResponse, |
302 kWarmupURLWithNoContentResponse, | |
303 "Bad", | 296 "Bad", |
304 true, | 297 true, |
305 true, | 298 true, |
306 false); | 299 false); |
307 // IP address change triggers a probe that fails. Proxy remains restricted. | 300 // IP address change triggers a probe that fails. Proxy remains restricted. |
308 CheckProbeOnIPChange(kProbeURLWithBadResponse, | 301 CheckProbeOnIPChange(kProbeURLWithBadResponse, |
309 kWarmupURLWithNoContentResponse, | |
310 "Bad", | 302 "Bad", |
311 true, | 303 true, |
312 true, | 304 true, |
313 false); | 305 false); |
314 // IP address change triggers a probe that succeeds. Proxy is unrestricted. | 306 // IP address change triggers a probe that succeeds. Proxy is unrestricted. |
315 CheckProbeOnIPChange(kProbeURLWithOKResponse, | 307 CheckProbeOnIPChange(kProbeURLWithOKResponse, |
316 kWarmupURLWithNoContentResponse, | |
317 "OK", | 308 "OK", |
318 true, | 309 true, |
319 false, | 310 false, |
320 false); | 311 false); |
321 // Simulate a VPN connection. The proxy should be disabled. | 312 // Simulate a VPN connection. The proxy should be disabled. |
322 MockSettings* settings = static_cast<MockSettings*>(settings_.get()); | 313 MockSettings* settings = static_cast<MockSettings*>(settings_.get()); |
323 settings->network_interfaces_.reset(new net::NetworkInterfaceList()); | 314 settings->network_interfaces_.reset(new net::NetworkInterfaceList()); |
324 settings->network_interfaces_->push_back( | 315 settings->network_interfaces_->push_back( |
325 net::NetworkInterface("tun0", /* network interface name */ | 316 net::NetworkInterface("tun0", /* network interface name */ |
326 "tun0", /* network interface friendly name */ | 317 "tun0", /* network interface friendly name */ |
(...skipping 10 matching lines...) Expand all Loading... |
337 settings->network_interfaces_.reset(new net::NetworkInterfaceList()); | 328 settings->network_interfaces_.reset(new net::NetworkInterfaceList()); |
338 settings->network_interfaces_->push_back( | 329 settings->network_interfaces_->push_back( |
339 net::NetworkInterface("eth0", /* network interface name */ | 330 net::NetworkInterface("eth0", /* network interface name */ |
340 "eth0", /* network interface friendly name */ | 331 "eth0", /* network interface friendly name */ |
341 0, /* interface index */ | 332 0, /* interface index */ |
342 net::NetworkChangeNotifier::CONNECTION_WIFI, | 333 net::NetworkChangeNotifier::CONNECTION_WIFI, |
343 net::IPAddressNumber(), | 334 net::IPAddressNumber(), |
344 0 /* network prefix */ | 335 0 /* network prefix */ |
345 )); | 336 )); |
346 CheckProbeOnIPChange(kProbeURLWithOKResponse, | 337 CheckProbeOnIPChange(kProbeURLWithOKResponse, |
347 kWarmupURLWithNoContentResponse, | |
348 "OK", | 338 "OK", |
349 true, | 339 true, |
350 false, | 340 false, |
351 false); | 341 false); |
352 } | 342 } |
353 | 343 |
354 TEST_F(DataReductionProxySettingsTest, TestOnProxyEnabledPrefChange) { | 344 TEST_F(DataReductionProxySettingsTest, TestOnProxyEnabledPrefChange) { |
355 settings_->InitPrefMembers(); | 345 settings_->InitPrefMembers(); |
356 base::MessageLoopForUI loop; | 346 base::MessageLoopForUI loop; |
357 // The proxy is enabled initially. | 347 // The proxy is enabled initially. |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 request_context.get()); | 417 request_context.get()); |
428 settings_->SetOnDataReductionEnabledCallback( | 418 settings_->SetOnDataReductionEnabledCallback( |
429 base::Bind(&DataReductionProxySettingsTestBase:: | 419 base::Bind(&DataReductionProxySettingsTestBase:: |
430 RegisterSyntheticFieldTrialCallback, | 420 RegisterSyntheticFieldTrialCallback, |
431 base::Unretained(this))); | 421 base::Unretained(this))); |
432 | 422 |
433 base::MessageLoop::current()->RunUntilIdle(); | 423 base::MessageLoop::current()->RunUntilIdle(); |
434 } | 424 } |
435 | 425 |
436 } // namespace data_reduction_proxy | 426 } // namespace data_reduction_proxy |
OLD | NEW |