diff options
Diffstat (limited to 'chrome/browser')
5 files changed, 154 insertions, 132 deletions
diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc index 6f71e26..eeeb9c9 100644 --- a/chrome/browser/automation/testing_automation_provider.cc +++ b/chrome/browser/automation/testing_automation_provider.cc @@ -1841,12 +1841,8 @@ void TestingAutomationProvider::BuildJSONHandlerMaps() { handler_map_["OpenCrosh"] = &TestingAutomationProvider::OpenCrosh; handler_map_["SetProxySettings"] = &TestingAutomationProvider::SetProxySettings; - handler_map_["GetProxySettings"] = - &TestingAutomationProvider::GetProxySettings; handler_map_["SetSharedProxies"] = &TestingAutomationProvider::SetSharedProxies; - handler_map_["RefreshInternetDetails"] = - &TestingAutomationProvider::RefreshInternetDetails; browser_handler_map_["GetTimeInfo"] = &TestingAutomationProvider::GetTimeInfo; diff --git a/chrome/browser/automation/testing_automation_provider.h b/chrome/browser/automation/testing_automation_provider.h index 28ecce3..7ba1660 100644 --- a/chrome/browser/automation/testing_automation_provider.h +++ b/chrome/browser/automation/testing_automation_provider.h @@ -1346,18 +1346,12 @@ class TestingAutomationProvider : public AutomationProvider, void ToggleNetworkDevice(base::DictionaryValue* args, IPC::Message* reply_message); - void GetProxySettings(base::DictionaryValue* args, - IPC::Message* reply_message); - void SetProxySettings(base::DictionaryValue* args, IPC::Message* reply_message); void SetSharedProxies(base::DictionaryValue* args, IPC::Message* reply_message); - void RefreshInternetDetails(base::DictionaryValue* args, - IPC::Message* reply_message); - void ConnectToCellularNetwork(base::DictionaryValue* args, IPC::Message* reply_message); diff --git a/chrome/browser/automation/testing_automation_provider_chromeos.cc b/chrome/browser/automation/testing_automation_provider_chromeos.cc index 357c034..189b417 100644 --- a/chrome/browser/automation/testing_automation_provider_chromeos.cc +++ b/chrome/browser/automation/testing_automation_provider_chromeos.cc @@ -80,23 +80,6 @@ DictionaryValue* GetWifiInfoDict(const chromeos::WifiNetwork* wifi) { return item; } -base::Value* GetProxySetting(const std::string& setting_name, - Profile* profile) { - std::string setting_path = "cros.session.proxy."; - setting_path.append(setting_name); - base::Value* setting; - if (chromeos::proxy_cros_settings_parser::GetProxyPrefValue( - profile, setting_path, &setting)) { - scoped_ptr<DictionaryValue> setting_dict( - static_cast<DictionaryValue*>(setting)); - base::Value* value; - if (setting_dict->Remove("value", &value)) - return value; - } - - return NULL; -} - const char* UpdateStatusToString( UpdateEngineClient::UpdateStatusOperation status) { switch (status) { @@ -681,31 +664,6 @@ void TestingAutomationProvider::ToggleNetworkDevice( } } -void TestingAutomationProvider::GetProxySettings(DictionaryValue* args, - IPC::Message* reply_message) { - const char* settings[] = { "pacurl", "singlehttp", "singlehttpport", - "httpurl", "httpport", "httpsurl", "httpsport", - "type", "single", "ftpurl", "ftpport", - "socks", "socksport", "ignorelist" }; - AutomationJSONReply reply(this, reply_message); - scoped_ptr<DictionaryValue> return_value(new DictionaryValue); - - std::string error_message; - Profile* profile = - automation_util::GetCurrentProfileOnChromeOS(&error_message); - if (!profile) { - reply.SendError(error_message); - return; - } - for (size_t i = 0; i < arraysize(settings); ++i) { - base::Value* setting = - GetProxySetting(settings[i], profile); - if (setting) - return_value->Set(settings[i], setting); - } - reply.SendSuccess(return_value.get()); -} - void TestingAutomationProvider::SetSharedProxies( DictionaryValue* args, IPC::Message* reply_message) { @@ -716,8 +674,6 @@ void TestingAutomationProvider::SetSharedProxies( reply.SendError("Invalid or missing value argument."); return; } - std::string proxy_setting_type; - std::string setting_path = prefs::kUseSharedProxies; std::string error_message; Profile* profile = automation_util::GetCurrentProfileOnChromeOS(&error_message); @@ -726,58 +682,29 @@ void TestingAutomationProvider::SetSharedProxies( return; } PrefService* pref_service = profile->GetPrefs(); - pref_service->Set(setting_path.c_str(), *value); - reply.SendSuccess(NULL); -} - -void TestingAutomationProvider::RefreshInternetDetails( - DictionaryValue* args, - IPC::Message* reply_message) { - - AutomationJSONReply reply(this, reply_message); - std::string service_path; - if (!args->GetString("service path", &service_path)) { - reply.SendError("missing service path."); - return; - } - std::string error_message; - Profile* profile = - automation_util::GetCurrentProfileOnChromeOS(&error_message); - if (!profile) { - reply.SendError(error_message); - return; - } - chromeos::ProxyConfigServiceImpl* config_service = - profile->GetProxyConfigTracker(); - if (!config_service) { - reply.SendError("Unable to get proxy configuration."); - return; - } - config_service->UISetCurrentNetwork(service_path); + pref_service->Set(prefs::kUseSharedProxies, *value); reply.SendSuccess(NULL); } void TestingAutomationProvider::SetProxySettings(DictionaryValue* args, IPC::Message* reply_message) { AutomationJSONReply reply(this, reply_message); - std::string key; - base::Value* value; - if (!args->GetString("key", &key) || !args->Get("value", &value)) { + std::string proxy_config; + if (!args->GetString("proxy_config", &proxy_config)) { reply.SendError("Invalid or missing args."); return; } - std::string error_message; - Profile* profile = - automation_util::GetCurrentProfileOnChromeOS(&error_message); - if (!profile) { - reply.SendError(error_message); + + NetworkLibrary* network_library = CrosLibrary::Get()->GetNetworkLibrary(); + chromeos::Network* network = + const_cast<chromeos::Network*>(network_library->active_network()); + + if (!network) { + reply.SendError("No network connected."); return; } - // ProxyCrosSettingsProvider will own the Value* passed to Set(). - std::string setting_path = "cros.session.proxy."; - setting_path.append(key); - chromeos::proxy_cros_settings_parser::SetProxyPrefValue( - profile, setting_path, value); + + network->SetProxyConfig(proxy_config); reply.SendSuccess(NULL); } diff --git a/chrome/browser/ui/webui/options/preferences_browsertest.cc b/chrome/browser/ui/webui/options/preferences_browsertest.cc index 8703fcb..6eb5a2e 100644 --- a/chrome/browser/ui/webui/options/preferences_browsertest.cc +++ b/chrome/browser/ui/webui/options/preferences_browsertest.cc @@ -33,9 +33,13 @@ #include "testing/gtest/include/gtest/gtest.h" #if defined(OS_CHROMEOS) +#include "chrome/browser/chromeos/cros/cros_library.h" +#include "chrome/browser/chromeos/cros/network_library.h" #include "chrome/browser/chromeos/proxy_cros_settings_parser.h" #include "chrome/browser/chromeos/settings/cros_settings.h" #include "chrome/browser/chromeos/settings/cros_settings_names.h" +#include "chrome/browser/prefs/proxy_config_dictionary.h" +#include "chromeos/network/onc/onc_utils.h" #endif using testing::AllOf; @@ -77,6 +81,10 @@ PreferencesBrowserTest::~PreferencesBrowserTest() { void PreferencesBrowserTest::SetUpOnMainThread() { ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUISettingsFrameURL)); + SetUpPrefs(); +} + +void PreferencesBrowserTest::SetUpPrefs() { content::WebContents* web_contents = browser()->tab_strip_model()->GetActiveWebContents(); ASSERT_TRUE(web_contents); @@ -321,6 +329,23 @@ void PreferencesBrowserTest::SetupJavaScriptTestEnvironment( render_view_host_, javascript.str(), observed_json)); } +void PreferencesBrowserTest::SetPref(const std::string& name, + const std::string& type, + const base::Value* value, + bool commit, + std::string* observed_json) { + scoped_ptr<base::Value> commit_ptr(new base::FundamentalValue(commit)); + std::stringstream javascript; + javascript << "testEnv.runAndReply(function() {" + << " Preferences.set" << type << "Pref(" + << " '" << name << "'," + << " " << *value << "," + << " " << *commit_ptr << ");" + << "});"; + ASSERT_TRUE(content::ExecuteScriptAndExtractString( + render_view_host_, javascript.str(), observed_json)); +} + void PreferencesBrowserTest::VerifySetPref(const std::string& name, const std::string& type, const base::Value* value, @@ -329,20 +354,8 @@ void PreferencesBrowserTest::VerifySetPref(const std::string& name, ExpectSetCommit(name, value); else ExpectNoCommit(name); - scoped_ptr<base::Value> commit_ptr(new base::FundamentalValue(commit)); - std::string value_json; - std::string commit_json; - base::JSONWriter::Write(value, &value_json); - base::JSONWriter::Write(commit_ptr.get(), &commit_json); - std::stringstream javascript; - javascript << "testEnv.runAndReply(function() {" - << " Preferences.set" << type.c_str() << "Pref(" - << " '" << name.c_str() << "'," - << " " << value_json.c_str() << "," - << " " << commit_json.c_str() << ");});"; std::string observed_json; - ASSERT_TRUE(content::ExecuteScriptAndExtractString( - render_view_host_, javascript.str(), &observed_json)); + SetPref(name, type, value, commit, &observed_json); VerifyObservedPref(observed_json, name, value, std::string(), false, !commit); VerifyAndClearExpectations(); } @@ -694,49 +707,129 @@ IN_PROC_BROWSER_TEST_F(PreferencesBrowserTest, ChromeOSDeviceFetchPrefs) { STLDeleteElements(&decorated_non_default_values); } -// Verifies that initializing the JavaScript Preferences class fires the correct -// notifications in JavaScript for pref values handled by the Chrome OS proxy -// settings parser. -IN_PROC_BROWSER_TEST_F(PreferencesBrowserTest, ChromeOSProxyFetchPrefs) { - std::string observed_json; +class ProxyPreferencesBrowserTest : public PreferencesBrowserTest { + public: + virtual void SetUpOnMainThread() OVERRIDE { + scoped_ptr<base::DictionaryValue> proxy_config_dict( + ProxyConfigDictionary::CreateFixedServers( + "127.0.0.1:8080", + "*.google.com, 1.2.3.4:22")); + + std::string proxy_config; + base::JSONWriter::Write(proxy_config_dict.get(), &proxy_config); + + GetActiveNetwork()->SetProxyConfig(proxy_config); + + ui_test_utils::NavigateToURL(browser(), + GURL(chrome::kChromeUIProxySettingsURL)); + SetUpPrefs(); + } + + protected: + chromeos::Network* GetActiveNetwork() { + chromeos::NetworkLibrary* network_library = + chromeos::CrosLibrary::Get()->GetNetworkLibrary(); + return const_cast<chromeos::Network*>(network_library->active_network()); + } + + void SetProxyPref(const std::string& name, const base::Value& value) { + std::string type; + switch (value.GetType()) { + case base::Value::TYPE_BOOLEAN: + type = "Boolean"; + break; + case base::Value::TYPE_INTEGER: + type = "Integer"; + break; + case base::Value::TYPE_STRING: + type = "String"; + break; + default: + ASSERT_TRUE(false); + } + + std::string observed_json; + SetPref(name, type, &value, true, &observed_json); + } + + void VerifyCurrentProxyServer(const std::string& expected_server) { + scoped_ptr<base::DictionaryValue> proxy_config = + chromeos::onc::ReadDictionaryFromJson( + GetActiveNetwork()->proxy_config()); + ProxyConfigDictionary proxy_dict(proxy_config.get()); + std::string actual_proxy_server; + EXPECT_TRUE(proxy_dict.GetProxyServer(&actual_proxy_server)); + EXPECT_EQ(expected_server, actual_proxy_server); + } +}; + +// Verifies that proxy settings are correctly pushed to JavaScript during +// initialization of the proxy settings page. +IN_PROC_BROWSER_TEST_F(ProxyPreferencesBrowserTest, + ChromeOSInitializeProxy) { // Boolean pref. pref_names_.push_back(chromeos::kProxySingle); - default_values_.push_back(new base::FundamentalValue(false)); non_default_values_.push_back(new base::FundamentalValue(true)); // Integer pref. pref_names_.push_back(chromeos::kProxySingleHttpPort); - default_values_.push_back(new base::StringValue("")); non_default_values_.push_back(new base::FundamentalValue(8080)); // String pref. pref_names_.push_back(chromeos::kProxySingleHttp); - default_values_.push_back(new base::StringValue("")); non_default_values_.push_back(new base::StringValue("127.0.0.1")); // List pref. pref_names_.push_back(chromeos::kProxyIgnoreList); - default_values_.push_back(new base::ListValue()); base::ListValue* list = new base::ListValue(); - list->Append(new base::StringValue("www.google.com")); - list->Append(new base::StringValue("example.com")); + list->Append(new base::StringValue("*.google.com")); + list->Append(new base::StringValue("1.2.3.4:22")); non_default_values_.push_back(list); - // Verify notifications when default values are in effect. - SetupJavaScriptTestEnvironment(pref_names_, &observed_json); - VerifyObservedPrefs(observed_json, pref_names_, default_values_, - "", false, false); - - // Verify notifications when user-modified values are in effect. - Profile* profile = browser()->profile(); - // Do not set the Boolean pref. It will toogle automatically. - for (size_t i = 1; i < pref_names_.size(); ++i) - chromeos::proxy_cros_settings_parser::SetProxyPrefValue( - profile, pref_names_[i], non_default_values_[i]->DeepCopy()); + std::string observed_json; SetupJavaScriptTestEnvironment(pref_names_, &observed_json); VerifyObservedPrefs(observed_json, pref_names_, non_default_values_, "", false, false); } +// Verifies that modifications to the proxy settings are correctly pushed from +// JavaScript to the ProxyConfig property stored in the network configuration. +IN_PROC_BROWSER_TEST_F(ProxyPreferencesBrowserTest, ChromeOSSetProxy) { + ASSERT_NO_FATAL_FAILURE(SetupJavaScriptTestEnvironment(pref_names_, NULL)); + + SetProxyPref(chromeos::kProxySingleHttpPort, base::FundamentalValue(123)); + SetProxyPref(chromeos::kProxySingleHttp, base::StringValue("www.adomain.xy")); + + VerifyCurrentProxyServer("www.adomain.xy:123"); +} + +// Verify that default proxy ports are used and that ports can be updated +// without affecting the previously set hosts. +IN_PROC_BROWSER_TEST_F(ProxyPreferencesBrowserTest, ChromeOSProxyDefaultPorts) { + ASSERT_NO_FATAL_FAILURE(SetupJavaScriptTestEnvironment(pref_names_, NULL)); + + // Set to manual, per scheme proxy. + SetProxyPref(chromeos::kProxySingle, base::FundamentalValue(false)); + + // Set hosts but no ports. + SetProxyPref(chromeos::kProxyHttpUrl, base::StringValue("a.com")); + SetProxyPref(chromeos::kProxyHttpsUrl, base::StringValue("4.3.2.1")); + SetProxyPref(chromeos::kProxyFtpUrl, base::StringValue("c.com")); + SetProxyPref(chromeos::kProxySocks, base::StringValue("d.com")); + + // Verify default ports. + VerifyCurrentProxyServer( + "http=a.com:80;https=4.3.2.1:80;ftp=c.com:80;socks=socks4://d.com:1080"); + + // Set and verify the ports. + SetProxyPref(chromeos::kProxyHttpPort, base::FundamentalValue(1)); + SetProxyPref(chromeos::kProxyHttpsPort, base::FundamentalValue(2)); + SetProxyPref(chromeos::kProxyFtpPort, base::FundamentalValue(3)); + SetProxyPref(chromeos::kProxySocksPort, base::FundamentalValue(4)); + + VerifyCurrentProxyServer( + "http=a.com:1;https=4.3.2.1:2;ftp=c.com:3;socks=socks4://d.com:4"); +} + #endif diff --git a/chrome/browser/ui/webui/options/preferences_browsertest.h b/chrome/browser/ui/webui/options/preferences_browsertest.h index 3d5fb21..f8445d4 100644 --- a/chrome/browser/ui/webui/options/preferences_browsertest.h +++ b/chrome/browser/ui/webui/options/preferences_browsertest.h @@ -45,6 +45,8 @@ class PreferencesBrowserTest : public InProcessBrowserTest { protected: MOCK_METHOD1(OnCommit, void(const PrefService::Preference*)); + void SetUpPrefs(); + // InProcessBrowserTest implementation: virtual void SetUpInProcessBrowserTestFixture() OVERRIDE; virtual void TearDownInProcessBrowserTestFixture() OVERRIDE; @@ -108,9 +110,19 @@ class PreferencesBrowserTest : public InProcessBrowserTest { void SetupJavaScriptTestEnvironment( const std::vector<std::string>& pref_names, std::string* observed_json) const; + + // Sets a value through the JavaScript Preferences class as if the user had + // modified it. Returns the observation which can be verified using the + // VerifyObserved* methods. + void SetPref(const std::string& name, + const std::string& type, + const base::Value* value, + bool commit, + std::string* observed_json); + // Verifies that setting a user-modified pref value through the JavaScript - // Preferences class fires the correct notification in JavaScript and does - // respectively does not cause the change to be committed to the C++ backend. + // Preferences class fires the correct notification in JavaScript and commits + // the change to C++ if |commit| is true. void VerifySetPref(const std::string& name, const std::string& type, const base::Value* value, |