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

Side by Side Diff: chrome/browser/ui/webui/options/preferences_browsertest.cc

Issue 16398005: Extract common per-network proxy configuration functions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Nit. Created 7 years, 6 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/ui/webui/options/preferences_browsertest.h" 5 #include "chrome/browser/ui/webui/options/preferences_browsertest.h"
6 6
7 #include <iostream> 7 #include <iostream>
8 #include <sstream> 8 #include <sstream>
9 9
10 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
(...skipping 15 matching lines...) Expand all
26 #include "content/public/browser/notification_details.h" 26 #include "content/public/browser/notification_details.h"
27 #include "content/public/browser/notification_source.h" 27 #include "content/public/browser/notification_source.h"
28 #include "content/public/browser/render_view_host.h" 28 #include "content/public/browser/render_view_host.h"
29 #include "content/public/browser/web_contents.h" 29 #include "content/public/browser/web_contents.h"
30 #include "content/public/test/browser_test_utils.h" 30 #include "content/public/test/browser_test_utils.h"
31 #include "googleurl/src/gurl.h" 31 #include "googleurl/src/gurl.h"
32 #include "policy/policy_constants.h" 32 #include "policy/policy_constants.h"
33 #include "testing/gtest/include/gtest/gtest.h" 33 #include "testing/gtest/include/gtest/gtest.h"
34 34
35 #if defined(OS_CHROMEOS) 35 #if defined(OS_CHROMEOS)
36 #include "chrome/browser/chromeos/cros/cros_library.h" 36 #include "base/stringprintf.h"
37 #include "chrome/browser/chromeos/cros/network_library.h" 37 #include "chrome/browser/chromeos/net/proxy_config_handler.h"
38 #include "chrome/browser/chromeos/proxy_cros_settings_parser.h" 38 #include "chrome/browser/chromeos/proxy_cros_settings_parser.h"
39 #include "chrome/browser/chromeos/settings/cros_settings.h" 39 #include "chrome/browser/chromeos/settings/cros_settings.h"
40 #include "chrome/browser/chromeos/settings/cros_settings_names.h" 40 #include "chrome/browser/chromeos/settings/cros_settings_names.h"
41 #include "chrome/browser/prefs/proxy_config_dictionary.h" 41 #include "chrome/browser/prefs/proxy_config_dictionary.h"
42 #include "chromeos/network/onc/onc_utils.h" 42 #include "chromeos/network/network_state.h"
43 #include "chromeos/network/network_state_handler.h"
43 #endif 44 #endif
44 45
45 using testing::AllOf; 46 using testing::AllOf;
46 using testing::AnyNumber; 47 using testing::AnyNumber;
47 using testing::Mock; 48 using testing::Mock;
48 using testing::Property; 49 using testing::Property;
49 using testing::Return; 50 using testing::Return;
50 using testing::_; 51 using testing::_;
51 52
52 namespace base { 53 namespace base {
(...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after
708 } 709 }
709 710
710 class ProxyPreferencesBrowserTest : public PreferencesBrowserTest { 711 class ProxyPreferencesBrowserTest : public PreferencesBrowserTest {
711 public: 712 public:
712 virtual void SetUpOnMainThread() OVERRIDE { 713 virtual void SetUpOnMainThread() OVERRIDE {
713 scoped_ptr<base::DictionaryValue> proxy_config_dict( 714 scoped_ptr<base::DictionaryValue> proxy_config_dict(
714 ProxyConfigDictionary::CreateFixedServers( 715 ProxyConfigDictionary::CreateFixedServers(
715 "127.0.0.1:8080", 716 "127.0.0.1:8080",
716 "*.google.com, 1.2.3.4:22")); 717 "*.google.com, 1.2.3.4:22"));
717 718
718 std::string proxy_config; 719 ProxyConfigDictionary proxy_config(proxy_config_dict.get());
719 base::JSONWriter::Write(proxy_config_dict.get(), &proxy_config);
720 720
721 chromeos::Network* network = GetActiveNetwork(); 721 const chromeos::NetworkState* network = GetDefaultNetwork();
722 network->SetProxyConfig(proxy_config); 722 chromeos::proxy_config::SetProxyConfigForNetwork(
723 proxy_config, *network);
723 724
724 std::string url = chrome::kChromeUIProxySettingsURL; 725 std::string url = base::StringPrintf("%s?network=%s",
725 url += "?network="; 726 chrome::kChromeUIProxySettingsURL,
726 url += network->service_path(); 727 network->path().c_str());
727 728
728 ui_test_utils::NavigateToURL(browser(), GURL(url)); 729 ui_test_utils::NavigateToURL(browser(), GURL(url));
729 SetUpPrefs(); 730 SetUpPrefs();
730 } 731 }
731 732
732 protected: 733 protected:
733 chromeos::Network* GetActiveNetwork() { 734 const chromeos::NetworkState* GetDefaultNetwork() {
734 chromeos::NetworkLibrary* network_library = 735 return chromeos::NetworkHandler::Get()->network_state_handler()->
735 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); 736 DefaultNetwork();
736 return const_cast<chromeos::Network*>(network_library->active_network());
737 } 737 }
738 738
739 void SetProxyPref(const std::string& name, const base::Value& value) { 739 void SetProxyPref(const std::string& name, const base::Value& value) {
740 std::string type; 740 std::string type;
741 switch (value.GetType()) { 741 switch (value.GetType()) {
742 case base::Value::TYPE_BOOLEAN: 742 case base::Value::TYPE_BOOLEAN:
743 type = "Boolean"; 743 type = "Boolean";
744 break; 744 break;
745 case base::Value::TYPE_INTEGER: 745 case base::Value::TYPE_INTEGER:
746 type = "Integer"; 746 type = "Integer";
747 break; 747 break;
748 case base::Value::TYPE_STRING: 748 case base::Value::TYPE_STRING:
749 type = "String"; 749 type = "String";
750 break; 750 break;
751 default: 751 default:
752 ASSERT_TRUE(false); 752 ASSERT_TRUE(false);
753 } 753 }
754 754
755 std::string observed_json; 755 std::string observed_json;
756 SetPref(name, type, &value, true, &observed_json); 756 SetPref(name, type, &value, true, &observed_json);
757 } 757 }
758 758
759 void VerifyCurrentProxyServer(const std::string& expected_server) { 759 void VerifyCurrentProxyServer(const std::string& expected_server) {
760 scoped_ptr<base::DictionaryValue> proxy_config = 760 scoped_ptr<ProxyConfigDictionary> proxy_dict(
761 chromeos::onc::ReadDictionaryFromJson( 761 chromeos::proxy_config::GetProxyConfigForNetwork(*GetDefaultNetwork()));
762 GetActiveNetwork()->proxy_config());
763
764 ProxyConfigDictionary proxy_dict(proxy_config.get());
765 std::string actual_proxy_server; 762 std::string actual_proxy_server;
766 EXPECT_TRUE(proxy_dict.GetProxyServer(&actual_proxy_server)); 763 EXPECT_TRUE(proxy_dict->GetProxyServer(&actual_proxy_server));
767 EXPECT_EQ(expected_server, actual_proxy_server); 764 EXPECT_EQ(expected_server, actual_proxy_server);
768 } 765 }
769 }; 766 };
770 767
771 // Verifies that proxy settings are correctly pushed to JavaScript during 768 // Verifies that proxy settings are correctly pushed to JavaScript during
772 // initialization of the proxy settings page. 769 // initialization of the proxy settings page.
773 IN_PROC_BROWSER_TEST_F(ProxyPreferencesBrowserTest, 770 IN_PROC_BROWSER_TEST_F(ProxyPreferencesBrowserTest,
774 ChromeOSInitializeProxy) { 771 ChromeOSInitializeProxy) {
775 // Boolean pref. 772 // Boolean pref.
776 pref_names_.push_back(chromeos::kProxySingle); 773 pref_names_.push_back(chromeos::kProxySingle);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
830 SetProxyPref(chromeos::kProxyHttpPort, base::FundamentalValue(1)); 827 SetProxyPref(chromeos::kProxyHttpPort, base::FundamentalValue(1));
831 SetProxyPref(chromeos::kProxyHttpsPort, base::FundamentalValue(2)); 828 SetProxyPref(chromeos::kProxyHttpsPort, base::FundamentalValue(2));
832 SetProxyPref(chromeos::kProxyFtpPort, base::FundamentalValue(3)); 829 SetProxyPref(chromeos::kProxyFtpPort, base::FundamentalValue(3));
833 SetProxyPref(chromeos::kProxySocksPort, base::FundamentalValue(4)); 830 SetProxyPref(chromeos::kProxySocksPort, base::FundamentalValue(4));
834 831
835 VerifyCurrentProxyServer( 832 VerifyCurrentProxyServer(
836 "http=a.com:1;https=4.3.2.1:2;ftp=c.com:3;socks=socks4://d.com:4"); 833 "http=a.com:1;https=4.3.2.1:2;ftp=c.com:3;socks=socks4://d.com:4");
837 } 834 }
838 835
839 #endif 836 #endif
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/chromeos/login/network_state_informer.cc ('k') | chrome/chrome_browser_chromeos.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698