| 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/chromeos/proxy_config_service_impl.h" | 5 #include "chrome/browser/chromeos/proxy_config_service_impl.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
| 10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 13 #include "base/prefs/testing_pref_service.h" | 13 #include "base/prefs/testing_pref_service.h" |
| 14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
| 15 #include "chrome/browser/chromeos/net/proxy_config_handler.h" | 15 #include "chrome/browser/chromeos/net/proxy_config_handler.h" |
| 16 #include "chrome/browser/chromeos/settings/cros_settings.h" | 16 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 17 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 17 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
| 18 #include "chrome/browser/chromeos/ui_proxy_config.h" | 18 #include "chrome/browser/chromeos/ui_proxy_config.h" |
| 19 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
| 20 #include "chromeos/dbus/dbus_thread_manager.h" | 20 #include "chromeos/dbus/dbus_thread_manager.h" |
| 21 #include "chromeos/dbus/shill_profile_client.h" | 21 #include "chromeos/dbus/shill_profile_client.h" |
| 22 #include "chromeos/dbus/shill_service_client.h" | 22 #include "chromeos/dbus/shill_service_client.h" |
| 23 #include "chromeos/network/network_handler.h" | 23 #include "chromeos/network/network_handler.h" |
| 24 #include "chromeos/network/network_profile_handler.h" | 24 #include "chromeos/network/network_profile_handler.h" |
| 25 #include "chromeos/network/network_state.h" | 25 #include "chromeos/network/network_state.h" |
| 26 #include "chromeos/network/network_state_handler.h" | 26 #include "chromeos/network/network_state_handler.h" |
| 27 #include "chromeos/network/onc/onc_utils.h" | 27 #include "chromeos/network/onc/onc_utils.h" |
| 28 #include "components/pref_registry/testing_pref_service_syncable.h" | 28 #include "components/pref_registry/testing_pref_service_syncable.h" |
| 29 #include "components/proxy_config/proxy_config_pref_names.h" |
| 29 #include "content/public/test/test_browser_thread.h" | 30 #include "content/public/test/test_browser_thread.h" |
| 30 #include "net/proxy/proxy_config.h" | 31 #include "net/proxy/proxy_config.h" |
| 31 #include "net/proxy/proxy_config_service_common_unittest.h" | 32 #include "net/proxy/proxy_config_service_common_unittest.h" |
| 32 #include "testing/gtest/include/gtest/gtest.h" | 33 #include "testing/gtest/include/gtest/gtest.h" |
| 33 #include "third_party/cros_system_api/dbus/service_constants.h" | 34 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 34 | 35 |
| 35 using content::BrowserThread; | 36 using content::BrowserThread; |
| 36 | 37 |
| 37 namespace chromeos { | 38 namespace chromeos { |
| 38 | 39 |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 base::DictionaryValue managed_config; | 435 base::DictionaryValue managed_config; |
| 435 InitConfigWithTestInput(managed_params.input, &managed_config); | 436 InitConfigWithTestInput(managed_params.input, &managed_config); |
| 436 base::DictionaryValue recommended_config; | 437 base::DictionaryValue recommended_config; |
| 437 InitConfigWithTestInput(recommended_params.input, &recommended_config); | 438 InitConfigWithTestInput(recommended_params.input, &recommended_config); |
| 438 base::DictionaryValue network_config; | 439 base::DictionaryValue network_config; |
| 439 InitConfigWithTestInput(network_params.input, &network_config); | 440 InitConfigWithTestInput(network_params.input, &network_config); |
| 440 | 441 |
| 441 // Managed proxy pref should take effect over recommended proxy and | 442 // Managed proxy pref should take effect over recommended proxy and |
| 442 // non-existent network proxy. | 443 // non-existent network proxy. |
| 443 SetUserConfigInShill(nullptr); | 444 SetUserConfigInShill(nullptr); |
| 444 pref_service_.SetManagedPref(prefs::kProxy, managed_config.DeepCopy()); | 445 pref_service_.SetManagedPref(ProxyPrefs::prefs::kProxy, |
| 445 pref_service_.SetRecommendedPref(prefs::kProxy, | 446 managed_config.DeepCopy()); |
| 447 pref_service_.SetRecommendedPref(ProxyPrefs::prefs::kProxy, |
| 446 recommended_config.DeepCopy()); | 448 recommended_config.DeepCopy()); |
| 447 net::ProxyConfig actual_config; | 449 net::ProxyConfig actual_config; |
| 448 SyncGetLatestProxyConfig(&actual_config); | 450 SyncGetLatestProxyConfig(&actual_config); |
| 449 EXPECT_EQ(managed_params.auto_detect, actual_config.auto_detect()); | 451 EXPECT_EQ(managed_params.auto_detect, actual_config.auto_detect()); |
| 450 EXPECT_EQ(managed_params.pac_url, actual_config.pac_url()); | 452 EXPECT_EQ(managed_params.pac_url, actual_config.pac_url()); |
| 451 EXPECT_TRUE(managed_params.proxy_rules.Matches( | 453 EXPECT_TRUE(managed_params.proxy_rules.Matches( |
| 452 actual_config.proxy_rules())); | 454 actual_config.proxy_rules())); |
| 453 | 455 |
| 454 // Recommended proxy pref should take effect when managed proxy pref is | 456 // Recommended proxy pref should take effect when managed proxy pref is |
| 455 // removed. | 457 // removed. |
| 456 pref_service_.RemoveManagedPref(prefs::kProxy); | 458 pref_service_.RemoveManagedPref(ProxyPrefs::prefs::kProxy); |
| 457 SyncGetLatestProxyConfig(&actual_config); | 459 SyncGetLatestProxyConfig(&actual_config); |
| 458 EXPECT_EQ(recommended_params.auto_detect, actual_config.auto_detect()); | 460 EXPECT_EQ(recommended_params.auto_detect, actual_config.auto_detect()); |
| 459 EXPECT_EQ(recommended_params.pac_url, actual_config.pac_url()); | 461 EXPECT_EQ(recommended_params.pac_url, actual_config.pac_url()); |
| 460 EXPECT_TRUE(recommended_params.proxy_rules.Matches( | 462 EXPECT_TRUE(recommended_params.proxy_rules.Matches( |
| 461 actual_config.proxy_rules())); | 463 actual_config.proxy_rules())); |
| 462 | 464 |
| 463 // Network proxy should take take effect over recommended proxy pref. | 465 // Network proxy should take take effect over recommended proxy pref. |
| 464 SetUserConfigInShill(&network_config); | 466 SetUserConfigInShill(&network_config); |
| 465 SyncGetLatestProxyConfig(&actual_config); | 467 SyncGetLatestProxyConfig(&actual_config); |
| 466 EXPECT_EQ(network_params.auto_detect, actual_config.auto_detect()); | 468 EXPECT_EQ(network_params.auto_detect, actual_config.auto_detect()); |
| 467 EXPECT_EQ(network_params.pac_url, actual_config.pac_url()); | 469 EXPECT_EQ(network_params.pac_url, actual_config.pac_url()); |
| 468 EXPECT_TRUE(network_params.proxy_rules.Matches( | 470 EXPECT_TRUE(network_params.proxy_rules.Matches( |
| 469 actual_config.proxy_rules())); | 471 actual_config.proxy_rules())); |
| 470 | 472 |
| 471 // Managed proxy pref should take effect over network proxy. | 473 // Managed proxy pref should take effect over network proxy. |
| 472 pref_service_.SetManagedPref(prefs::kProxy, managed_config.DeepCopy()); | 474 pref_service_.SetManagedPref(ProxyPrefs::prefs::kProxy, |
| 475 managed_config.DeepCopy()); |
| 473 SyncGetLatestProxyConfig(&actual_config); | 476 SyncGetLatestProxyConfig(&actual_config); |
| 474 EXPECT_EQ(managed_params.auto_detect, actual_config.auto_detect()); | 477 EXPECT_EQ(managed_params.auto_detect, actual_config.auto_detect()); |
| 475 EXPECT_EQ(managed_params.pac_url, actual_config.pac_url()); | 478 EXPECT_EQ(managed_params.pac_url, actual_config.pac_url()); |
| 476 EXPECT_TRUE(managed_params.proxy_rules.Matches( | 479 EXPECT_TRUE(managed_params.proxy_rules.Matches( |
| 477 actual_config.proxy_rules())); | 480 actual_config.proxy_rules())); |
| 478 | 481 |
| 479 // Network proxy should take effect over recommended proxy pref when managed | 482 // Network proxy should take effect over recommended proxy pref when managed |
| 480 // proxy pref is removed. | 483 // proxy pref is removed. |
| 481 pref_service_.RemoveManagedPref(prefs::kProxy); | 484 pref_service_.RemoveManagedPref(ProxyPrefs::prefs::kProxy); |
| 482 SyncGetLatestProxyConfig(&actual_config); | 485 SyncGetLatestProxyConfig(&actual_config); |
| 483 EXPECT_EQ(network_params.auto_detect, actual_config.auto_detect()); | 486 EXPECT_EQ(network_params.auto_detect, actual_config.auto_detect()); |
| 484 EXPECT_EQ(network_params.pac_url, actual_config.pac_url()); | 487 EXPECT_EQ(network_params.pac_url, actual_config.pac_url()); |
| 485 EXPECT_TRUE(network_params.proxy_rules.Matches( | 488 EXPECT_TRUE(network_params.proxy_rules.Matches( |
| 486 actual_config.proxy_rules())); | 489 actual_config.proxy_rules())); |
| 487 | 490 |
| 488 // Removing recommended proxy pref should have no effect on network proxy. | 491 // Removing recommended proxy pref should have no effect on network proxy. |
| 489 pref_service_.RemoveRecommendedPref(prefs::kProxy); | 492 pref_service_.RemoveRecommendedPref(ProxyPrefs::prefs::kProxy); |
| 490 SyncGetLatestProxyConfig(&actual_config); | 493 SyncGetLatestProxyConfig(&actual_config); |
| 491 EXPECT_EQ(network_params.auto_detect, actual_config.auto_detect()); | 494 EXPECT_EQ(network_params.auto_detect, actual_config.auto_detect()); |
| 492 EXPECT_EQ(network_params.pac_url, actual_config.pac_url()); | 495 EXPECT_EQ(network_params.pac_url, actual_config.pac_url()); |
| 493 EXPECT_TRUE(network_params.proxy_rules.Matches( | 496 EXPECT_TRUE(network_params.proxy_rules.Matches( |
| 494 actual_config.proxy_rules())); | 497 actual_config.proxy_rules())); |
| 495 } | 498 } |
| 496 } | 499 } |
| 497 | 500 |
| 498 // Tests whether the proxy settings from user policy are used for ethernet even | 501 // Tests whether the proxy settings from user policy are used for ethernet even |
| 499 // if 'UseSharedProxies' is set to false. | 502 // if 'UseSharedProxies' is set to false. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 514 network_configs.release()); | 517 network_configs.release()); |
| 515 | 518 |
| 516 net::ProxyConfig actual_config; | 519 net::ProxyConfig actual_config; |
| 517 SyncGetLatestProxyConfig(&actual_config); | 520 SyncGetLatestProxyConfig(&actual_config); |
| 518 net::ProxyConfig expected_config = | 521 net::ProxyConfig expected_config = |
| 519 net::ProxyConfig::CreateFromCustomPacURL(GURL("http://domain.com/x")); | 522 net::ProxyConfig::CreateFromCustomPacURL(GURL("http://domain.com/x")); |
| 520 EXPECT_TRUE(expected_config.Equals(actual_config)); | 523 EXPECT_TRUE(expected_config.Equals(actual_config)); |
| 521 } | 524 } |
| 522 | 525 |
| 523 } // namespace chromeos | 526 } // namespace chromeos |
| OLD | NEW |