diff options
author | pneubeck@chromium.org <pneubeck@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-29 11:49:10 +0000 |
---|---|---|
committer | pneubeck@chromium.org <pneubeck@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-29 11:49:10 +0000 |
commit | 537a42eb0eac0303d8a9ee98b55bc32eb697c71f (patch) | |
tree | 16b890a3375571c6c00721ac5a2c6ab1aecb14ff | |
parent | 2a9d2c1d0978bb0452c90d3261dcd73461556469 (diff) | |
download | chromium_src-537a42eb0eac0303d8a9ee98b55bc32eb697c71f.zip chromium_src-537a42eb0eac0303d8a9ee98b55bc32eb697c71f.tar.gz chromium_src-537a42eb0eac0303d8a9ee98b55bc32eb697c71f.tar.bz2 |
Migrate auto_tests about proxy configuration to browser_tests.
At the same time this
- removes a lot of unnecessary code testing_automation_provider* and pyauto,
- removes the dependency of testing_automation_provider* on ProxyConfigServiceImpl.
BUG=234982
TEST=New browser_tests. Ran pyauto test testCachedCredentialsAddUser locally.
Review URL: https://chromiumcodereview.appspot.com/16045005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@202849 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/automation/testing_automation_provider.cc | 4 | ||||
-rw-r--r-- | chrome/browser/automation/testing_automation_provider.h | 6 | ||||
-rw-r--r-- | chrome/browser/automation/testing_automation_provider_chromeos.cc | 97 | ||||
-rw-r--r-- | chrome/browser/ui/webui/options/preferences_browsertest.cc | 163 | ||||
-rw-r--r-- | chrome/browser/ui/webui/options/preferences_browsertest.h | 16 | ||||
-rwxr-xr-x | chrome/test/functional/chromeos_login.py | 18 | ||||
-rwxr-xr-x | chrome/test/functional/chromeos_proxy.py | 206 | ||||
-rwxr-xr-x | chrome/test/functional/chromeos_wifi_sanity.py | 13 | ||||
-rwxr-xr-x | chrome/test/pyautolib/pyauto.py | 217 |
9 files changed, 176 insertions, 564 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, diff --git a/chrome/test/functional/chromeos_login.py b/chrome/test/functional/chromeos_login.py index 7b4a56b..786b071 100755 --- a/chrome/test/functional/chromeos_login.py +++ b/chrome/test/functional/chromeos_login.py @@ -303,11 +303,12 @@ class ChromeosLoginCachedCredentialsAddUser(pyauto.PyUITest): return self.GetPrivateInfo()[account_type] def testCachedCredentialsAddUser(self): - proxy_dict = { - 'url_path': 'singlehttp', - 'proxy_url': '127.0.0.1', + self.SetSharedProxies(True) + proxy_config = { + 'mode': 'fixed_servers', + 'server': '127.0.0.1' } - self.SetProxySettingOnChromeOS(proxy_dict) + self.SetProxySettingOnChromeOS(proxy_config); """Test that login fails.""" credentials = self._ValidCredentials() @@ -317,7 +318,7 @@ class ChromeosLoginCachedCredentialsAddUser(pyauto.PyUITest): credentials['password']) ) -class ChromeosLoginCachedCredentialsUserPod(pyauto.PyUITest): +class ChromeosLoginCachedCredentialsUserPod(ChromeosLogin): """TestCase for Logging into ChromeOS with cached credentials and invalid proxy settings. """ @@ -356,7 +357,12 @@ class ChromeosLoginCachedCredentialsUserPod(pyauto.PyUITest): """ self.testGoodLogin() self.Logout() - self.SetProxySettingOnChromeOS('singlehttp', '127.0.0.1') + self.SetSharedProxies(True) + proxy_config = { + 'mode': 'fixed_servers', + 'server': '127.0.0.1' + } + self.SetProxySettingOnChromeOS(proxy_config); self.testGoodLogin() self.ResetProxySettingsOnChromeOS() diff --git a/chrome/test/functional/chromeos_proxy.py b/chrome/test/functional/chromeos_proxy.py deleted file mode 100755 index cbd74f7..0000000 --- a/chrome/test/functional/chromeos_proxy.py +++ /dev/null @@ -1,206 +0,0 @@ -#!/usr/bin/env python -# Copyright (c) 2011 The Chromium Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -import pyauto_functional -import pyauto -import re -from pyauto_errors import AutomationCommandTimeout -from pyauto_errors import JSONInterfaceError - -class ChromeosProxy(pyauto.PyUITest): - """Tests for ChromeOS proxy. - - The following tests are for UI testing to verify the user defined - proxy settings can be set and saved. The proxy addresses used in these - tests are not real proxies and are used for testing purposes. - """ - - # The list of the default ports by protocol. The default ports - # for https and ftp are both 80 as explained in crosbug.com/14390#c3. - DEFAULT_PORTS = { - 'http' : 80, - 'https': 80, - 'ftp' : 80, - 'socks' : 1080, - } - - # Defines the translation used for entering fields. - MANUAL_PROXY_FIELDS = { - 'http' : { 'url' : 'httpurl', 'port' : 'httpport' }, - 'https' : { 'url' : 'httpsurl', 'port' : 'httpsport' }, - 'ftp' : { 'url' : 'ftpurl', 'port' : 'ftpport' }, - 'socks' : { 'url' : 'socks', 'port' : 'socksport' }, - } - - def setUp(self): - pyauto.PyUITest.setUp(self) - self.ResetProxySettingsOnChromeOS() - - def tearDown(self): - self.ResetProxySettingsOnChromeOS() - pyauto.PyUITest.tearDown(self) - - def _BasicSetManualProxyFieldTest(self, proxy_type, proxy_url, - proxy_port=None): - """Basic test for setting one manual port field and verifying it is saved - - Args: - proxy_type: One of http, https, ftp, or socks. - proxy_url: The URL of the proxy server. - proxy_port: The port number. May be left blank to imply using the default - port. The default ports are defined by self.DEFAULT_PORTS. - """ - if proxy_type == 'socks': - url_path = proxy_type - else: - url_path = proxy_type + 'url' - port_path = proxy_type + 'port' - proxy_dict = { - 'url_path': url_path, - 'port_path': port_path, - 'proxy_url': proxy_url, - 'proxy_port': proxy_port, - } - - self.SetProxySettingOnChromeOS(proxy_dict) - result = self.GetProxySettingsOnChromeOS() - - self.assertEqual(result['type'], self.PROXY_TYPE_MANUAL, 'Proxy type ' - 'should be Manual but instead we got %s.' % - self.GetProxyTypeName(result['type'])) - self.assertTrue(url_path in result, - 'No %s url entry was saved' % proxy_type) - self.assertEqual(result[url_path], proxy_url, - 'Saved proxy url %s does not match user set url %s.' % - (result[url_path], proxy_url)) - # Verify the port. If proxy_port is empty, we verify the - # default port is used - if proxy_port is None: - self.assertEqual(ChromeosProxy.DEFAULT_PORTS[proxy_type], - result[port_path], - 'Proxy port %d was used instead of default port %d.' % - (result[port_path], - ChromeosProxy.DEFAULT_PORTS[proxy_type])) - else: - self.assertEqual(proxy_port, result[port_path], - 'Proxy port %d was used instead of user set port %d.' % - (result[port_path], proxy_port)) - - # Verify that all other proxy fields are not set. - for key, val in self.MANUAL_PROXY_FIELDS.iteritems(): - if proxy_type != key: - self.assertFalse(result.get(val['url']), 'Only %s url should have ' - 'been set. %s url should have been left blank.' % - (proxy_type, key)) - self.assertFalse(result.get(val['port']), 'Only %s port should have ' - 'been set. %s port should have been left blank.' % - (proxy_type, key)) - - def testSetHTTPProxySettingsDefaultPort(self): - """Set the http proxy without a port and verify it saves. - - If http proxy is provided but the port is not, the default port - should be used. - """ - self._BasicSetManualProxyFieldTest('http', '192.168.1.1') - - def testSetHTTPProxySettingsDefaultPortByDomain(self): - """Set the http proxy by domain without a port and verify it saves. - - If http proxy is provided but the port is not, the default port - should be used. - """ - self._BasicSetManualProxyFieldTest('http', 'test_proxy.google.com') - - def testSetHTTPSProxySettingsDefaultPort(self): - """Set https proxy without a port and verify it saves. - - If https proxy is provided but the port is not, the default port - should be used. - """ - self._BasicSetManualProxyFieldTest('https', '192.168.1.1') - - def testSetHTTPSProxySettingsDefaultPortByDomain(self): - """Set the https proxy by domain without a port and verify it saves. - - If https proxy is provided but the port is not, the default port - should be used. - """ - self._BasicSetManualProxyFieldTest('https', 'test_proxy.google.com') - - def testSetFTPProxySettingsDefaultPort(self): - """Set ftp proxy without a port and verify it saves. - - If ftp proxy is provided but the port is not, the default port - should be used. - """ - self._BasicSetManualProxyFieldTest('ftp', '192.168.1.1') - - def testSetFTPSProxySettingsDefaultPortByDomain(self): - """Set the ftp proxy by domain without a port and verify it saves. - - If ftp proxy is provided but the port is not, the default port - should be used. - """ - self._BasicSetManualProxyFieldTest('ftp', 'test_proxy.google.com') - - def testSetSocksProxySettingsDefaultPort(self): - """Set socks proxy without a port and verify it saves. - - If socks proxy is provided but the port is not, the default port - should be used. - """ - self._BasicSetManualProxyFieldTest('socks', '192.168.1.1') - - def testSetSocksProxySettingsDefaultPortByDomain(self): - """Set socks proxy without a port and verify it saves. - - If socks proxy is provided but the port is not, the default port - should be used. - """ - self._BasicSetManualProxyFieldTest('socks', 'test_proxy.google.com') - - def testSetHTTPProxySettings(self): - """Set the http proxy and verify it saves.""" - self._BasicSetManualProxyFieldTest('http', '192.168.1.1', 3128) - - def testSetHTTPProxySettingsAndNavigate(self): - """Set an invalid httpurl and verify that we cant navigate.""" - invalid_url='10.10' - self._BasicSetManualProxyFieldTest('http', invalid_url, 3128) - self.assertRaises(AutomationCommandTimeout, - lambda: self.NavigateToURL('http://www.google.com')) - - def testSetHTTPProxySettingsByDomain(self): - """Set the http proxy by domain name and verify it saves.""" - self._BasicSetManualProxyFieldTest('http', 'test_proxy.google.com', 3128) - - def testSetHTTPSProxySettings(self): - """Set the https proxy and verify it saves.""" - self._BasicSetManualProxyFieldTest('https', '192.168.1.1', 6000) - - def testSetHTTPSProxySettingsByDomain(self): - """Set the https proxy by domain name and verify it saves.""" - self._BasicSetManualProxyFieldTest('https', 'test_proxy.google.com', 6000) - - def testSetFtpProxySettingsByDomain(self): - """Set the ftpproxy by domain name and verify it saves.""" - self._BasicSetManualProxyFieldTest('ftp', 'test_proxy.google.com', 7000) - - def testSetFTPProxySettings(self): - """Set the ftp proxy and verify it saves.""" - self._BasicSetManualProxyFieldTest('ftp', '192.168.1.1', 7000) - - def testSetSocksProxySettings(self): - """Set the socks proxy and verify it saves.""" - self._BasicSetManualProxyFieldTest('socks', '192.168.1.1', 3128) - - def testSetSocksProxySettingsByDomain(self): - """Set the Socks proxy by domain name and verify it saves.""" - self._BasicSetManualProxyFieldTest('socks', 'test_proxy.google.com', 3128) - - -if __name__ == '__main__': - pyauto_functional.Main() diff --git a/chrome/test/functional/chromeos_wifi_sanity.py b/chrome/test/functional/chromeos_wifi_sanity.py index 037397b..ebebc25 100755 --- a/chrome/test/functional/chromeos_wifi_sanity.py +++ b/chrome/test/functional/chromeos_wifi_sanity.py @@ -12,19 +12,6 @@ import chromeos_network # pyauto_functional must come before chromeos_network class ChromeosWifiSanity(chromeos_network.PyNetworkUITest): """Tests for ChromeOS network related functions.""" - def testNetworkInfoAndScan(self): - """Get basic info on networks.""" - # NetworkScan will also call GetNetworkInfo and return the results. - result = self.NetworkScan() - self.assertTrue(result) - logging.debug(result) - - def testGetProxySettings(self): - """Print some information about proxy settings.""" - result = self.GetProxySettingsOnChromeOS() - self.assertTrue(result) - logging.debug(result) - def testToggleNetworkDevice(self): """Sanity check to make sure wifi can be disabled and reenabled.""" self.ToggleNetworkDevice('wifi', False) diff --git a/chrome/test/pyautolib/pyauto.py b/chrome/test/pyautolib/pyauto.py index 9dba93c..a0fa464 100755 --- a/chrome/test/pyautolib/pyauto.py +++ b/chrome/test/pyautolib/pyauto.py @@ -4744,217 +4744,36 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase): return self.WaitUntil(_GotWifiNetwork, timeout=timeout, retry_sleep=1) - def GetProxyTypeName(self, proxy_type): - values = { self.PROXY_TYPE_DIRECT: 'Direct Internet connection', - self.PROXY_TYPE_MANUAL: 'Manual proxy configuration', - self.PROXY_TYPE_PAC: 'Automatic proxy configuration' } - return values[proxy_type] - - def GetProxySettingsOnChromeOS(self): - """Get current proxy settings on Chrome OS. - - Returns: - A dictionary. See SetProxySetting() below - for the full list of possible dictionary keys. - - Samples: - { u'ignorelist': [], - u'single': False, - u'type': 1} - - { u'ignorelist': [u'www.example.com', u'www.example2.com'], - u'single': True, - u'singlehttp': u'24.27.78.152', - u'singlehttpport': 1728, - u'type': 2} - - { u'ignorelist': [], - u'pacurl': u'http://example.com/config.pac', - u'single': False, - u'type': 3} - - Raises: - pyauto_errors.JSONInterfaceError if the automation call returns an error. - """ - cmd_dict = { 'command': 'GetProxySettings' } - return self._GetResultFromJSONRequest(cmd_dict, windex=None) - - def _FindNamedNetwork(self, network_dict, name): - """Finds a network by name. - - Args: - network_dict: network settings as returned by GetNetworkInfo. - name: name of network we want to set proxy settings on. - - Returns: - A dictionary with service_path and network_type of the - named network, when given a dictionary with all system - network information as returned by GetNetworkInfo. - - See GetNetworkInfo for a description of the input dictionary. - - Samples: - { u'network_type': 'wifi_networks', - u'service_path': '/service/700'} - """ - for (key, value) in network_dict.iteritems(): - if isinstance(value, dict): - if 'name' in value: - if value['name'] == name: - network_info = {'service_path': key} - return network_info - else: - # if key is a dict but it doesnt have a 'name' entry, go deeper - network_info = self._FindNamedNetwork(value, name) - # if only service path set, set type from networking dictionary - if network_info != None and 'network_type' not in network_info: - network_info['network_type'] = value['network_type'] - return network_info - return None - - def _GetNamedNetworkInfo(self, network_name): - """Gets settings needed to enable shared proxies for the named network. - - Args: - network_name: name of network we want to set proxy settings on. - - Returns: - A dictionary with network_type and service_path. - Samples: - { u'network_type': '1', - u'service_path': '/service/0'} - - Raises: - AutomationCommandFail if network name isn't found. - """ - net = self.GetNetworkInfo() - if network_name == 'NAME_UNKNOWN': - if net.get('ethernet_available'): - service_path = net.get('connected_ethernet') - network_type = str(pyautolib.TYPE_ETHERNET) - elif net.get('wifi_available'): - service_path = net.get('connected_wifi') - network_type = str(pyautolib.TYPE_WIFI) - elif net.get('cellular_available'): - service_path = net.get('connected_cellular') - network_type = str(pyautolib.TYPE_CELLULAR) - else: - raise AutomationCommandFail('No network available.') - else: - named_network_info = self._FindNamedNetwork(net, network_name) - if named_network_info == None: - raise AutomationCommandFail('%s not found.' % network_name) - service_path = named_network_info['service_path'] - network_type = named_network_info['network_type'] - - if not network_type: - raise AutomationCommandFail('network type not found.') - if not service_path: - raise AutomationCommandFail('service path not found.') - network_info = {'network type': network_type, 'service path': service_path} - return network_info - - def SetProxySettingOnChromeOS(self, proxy_dict): - """Public wrapper around _SetProxySettingOnChromeOSCore, performs - state setup and error checking. - - Args: - proxy_dict: dictionary of proxy settings, valid entries of which are - what one would supply _SetProxySettingOnChromeOSCore - - Raises: - AutomationCommandFail if a necessary dictionary entries aren't found. - """ - url_path = proxy_dict.get('url_path') - proxy_url = proxy_dict.get('proxy_url') - port_path = proxy_dict.get('port_path') - proxy_port = proxy_dict.get('proxy_port') - - if proxy_url is not None: - if url_path is None: - raise AutomationCommandFail('url_path needed to set proxy_url.') - return - self.SetSharedProxies(True) - self.RefreshInternetDetails() - self._SetProxySettingOnChromeOSCore('type', self.PROXY_TYPE_MANUAL) - self._SetProxySettingOnChromeOSCore(url_path, proxy_url) - - if proxy_port is not None: - if port_path is None: - raise AutomationCommandFail('port_path needed to set proxy_port.') - return - self._SetProxySettingOnChromeOSCore(port_path, proxy_port) - def ResetProxySettingsOnChromeOS(self): """Public wrapper around proxysettings teardown functions.""" self.SetSharedProxies(False) - self.RefreshInternetDetails() - self._SetProxySettingOnChromeOSCore('type', self.PROXY_TYPE_DIRECT) + proxy_dict = { + 'mode': 'direct' + } + self.SetProxySettingOnChromeOS(proxy_dict) - def _SetProxySettingOnChromeOSCore(self, key, value): - """Set a proxy setting. + def SetProxySettingOnChromeOS(self, proxy_config): + """Set the proxy config of the current network. Owner must be logged in for these to persist. If user is not logged in or is logged in as non-owner or guest, proxy settings do not persist across browser restarts or login/logout. Args: - key: string describing type of proxy preference. - value: value of proxy preference. - - Valid settings are: - 'type': int - Type of proxy. Should be one of: - PROXY_TYPE_DIRECT, PROXY_TYPE_MANUAL, PROXY_TYPE_PAC. - 'ignorelist': list - The list of hosts and domains to ignore. - - These settings set 'type' to PROXY_TYPE_MANUAL: - 'single': boolean - Whether to use the same proxy for all protocols. - - These settings set 'single' to True: - 'singlehttp': string - If single is true, the proxy address to use. - 'singlehttpport': int - If single is true, the proxy port to use. - - These settings set 'single' to False: - 'httpurl': string - HTTP proxy address. - 'httpport': int - HTTP proxy port. - 'httpsurl': string - Secure HTTP proxy address. - 'httpsport': int - Secure HTTP proxy port. - 'ftpurl': string - FTP proxy address. - 'ftpport': int - FTP proxy port. - 'socks': string - SOCKS host address. - 'socksport': int - SOCKS host port. - - This setting sets 'type' to PROXY_TYPE_PAC: - 'pacurl': string - Autoconfiguration URL. - - Examples: - # Sets direct internet connection, no proxy. - self.SetProxySettingOnChromeOS('type', self.PROXY_TYPE_DIRECT) - - # Sets manual proxy configuration, same proxy for all protocols. - self.SetProxySettingOnChromeOS('singlehttp', '24.27.78.152') - self.SetProxySettingOnChromeOS('singlehttpport', 1728) - self.SetProxySettingOnChromeOS('ignorelist', - ['www.example.com', 'example2.com']) - - # Sets automatic proxy configuration with the specified PAC url. - self.SetProxySettingOnChromeOS('pacurl', 'http://example.com/config.pac') - - # Sets httpproxy with specified url - self.SetProxySettingOnChromeOS('httpurl', 10.10.10) + proxy_config: A dictionary following the format described in + prefs/proxy_config_dictionary.h. Raises: pyauto_errors.JSONInterfaceError if the automation call returns an error. """ cmd_dict = { 'command': 'SetProxySettings', - 'key': key, - 'value': value, + 'proxy_config': json.dumps(proxy_config) } return self._GetResultFromJSONRequest(cmd_dict, windex=None) def SetSharedProxies(self, value): - """Allows shared proxies on the named network. + """Allows proxies on the shared networks. Args: value: True/False to set and clear respectively. @@ -4968,22 +4787,6 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase): } return self._GetResultFromJSONRequest(cmd_dict, windex=None) - def RefreshInternetDetails(self, network_name='NAME_UNKNOWN'): - """Updates network information - - Args: - network_name: name of the network we want to refresh settings for. - - Raises: - pyauto_errors.JSONInterfaceError if the automation call returns an error. - """ - network_info = self._GetNamedNetworkInfo(network_name) - cmd_dict = { - 'command': 'RefreshInternetDetails', - 'service path': network_info.get('service path'), - } - return self._GetResultFromJSONRequest(cmd_dict, None) - def ForgetAllRememberedNetworks(self): """Forgets all networks that the device has marked as remembered.""" for service in self.GetNetworkInfo()['remembered_wifi']: |