summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorbeeps@chromium.org <beeps@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-09-18 04:35:38 +0000
committerbeeps@chromium.org <beeps@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-09-18 04:35:38 +0000
commit7f1ed2450574b02ebb955f18e834436dced65f4e (patch)
tree1f99394e6cac3830ec7ef784c56c6452af27ca0b /chrome
parent11feec32b991ffac983d2a9781c70df4b987b67f (diff)
downloadchromium_src-7f1ed2450574b02ebb955f18e834436dced65f4e.zip
chromium_src-7f1ed2450574b02ebb955f18e834436dced65f4e.tar.gz
chromium_src-7f1ed2450574b02ebb955f18e834436dced65f4e.tar.bz2
Enables us to setproxysettings through the chromeos options UI and have it propogate to the system.
TestingAutomationProvider Get/SetProxySettings: 1. uses profile on shell 2. handles shared proxy settings through internetoptionshandler 3. changed setproxysettings from a browserhandler call to handler call Pyauto.py: 1. Gets servicepath and network type for sharedproxysettings call 2. uses network_type parameter (used to be windex) to get network information, since setproxysettings is now a handler call. Chromeos_proxy.py: 1. changed to check value in result dictionary instead of presence of key 2. navigate to url and perform setup needed to setproxysettings TEST=functional/chromeos_proxy.py BUG=27040 Review URL: https://chromiumcodereview.appspot.com/10829388 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@157295 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/automation/automation_util.cc53
-rw-r--r--chrome/browser/automation/automation_util.h5
-rw-r--r--chrome/browser/automation/testing_automation_provider.cc23
-rw-r--r--chrome/browser/automation/testing_automation_provider.h12
-rw-r--r--chrome/browser/automation/testing_automation_provider_chromeos.cc96
-rw-r--r--chrome/chrome_tests.gypi28
-rw-r--r--chrome/test/functional/PYAUTO_TESTS2
-rwxr-xr-xchrome/test/functional/chromeos_login.py95
-rwxr-xr-xchrome/test/functional/chromeos_proxy.py52
-rwxr-xr-xchrome/test/pyautolib/pyauto.py181
-rw-r--r--chrome/test/pyautolib/pyautolib.i8
11 files changed, 475 insertions, 80 deletions
diff --git a/chrome/browser/automation/automation_util.cc b/chrome/browser/automation/automation_util.cc
index 5a35aef..82b67c2 100644
--- a/chrome/browser/automation/automation_util.cc
+++ b/chrome/browser/automation/automation_util.cc
@@ -6,6 +6,8 @@
#include <string>
+#include "ash/shell.h"
+#include "ash/shell_delegate.h"
#include "base/bind.h"
#include "base/memory/scoped_ptr.h"
#include "base/string_number_conversions.h"
@@ -39,10 +41,25 @@
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_getter.h"
+#if defined(OS_CHROMEOS)
+#include "chrome/browser/chromeos/login/existing_user_controller.h"
+#include "chrome/browser/chromeos/login/login_display.h"
+#include "chrome/browser/chromeos/login/login_display_host.h"
+#include "chrome/browser/chromeos/login/webui_login_display.h"
+#include "chrome/browser/chromeos/login/webui_login_display_host.h"
+#include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h"
+#endif
+
using content::BrowserThread;
using content::RenderViewHost;
using content::WebContents;
+#if defined(OS_CHROMEOS)
+using chromeos::ExistingUserController;
+using chromeos::User;
+using chromeos::UserManager;
+#endif
+
namespace {
void GetCookiesCallback(base::WaitableEvent* event,
@@ -150,6 +167,42 @@ WebContents* GetWebContentsAt(int browser_index, int tab_index) {
return chrome::GetWebContentsAt(browser, tab_index);
}
+#if defined(OS_CHROMEOS)
+Profile* GetCurrentProfileOnChromeOS(std::string* error_message) {
+ const UserManager* user_manager = UserManager::Get();
+ if (!user_manager) {
+ *error_message = "No user manager.";
+ return NULL;
+ }
+ if (!user_manager->IsUserLoggedIn()) {
+ ExistingUserController* controller =
+ ExistingUserController::current_controller();
+ if (!controller) {
+ *error_message = "Cannot get controller though user is not logged in.";
+ return NULL;
+ }
+ chromeos::WebUILoginDisplayHost* webui_login_display_host =
+ static_cast<chromeos::WebUILoginDisplayHost*>(
+ controller->login_display_host());
+ content::WebUI* web_ui = webui_login_display_host->GetOobeUI()->web_ui();
+ if (!web_ui) {
+ *error_message = "Unable to get webui from login display host.";
+ return NULL;
+ }
+ return Profile::FromWebUI(web_ui);
+ } else {
+ ash::Shell* shell = ash::Shell::GetInstance();
+ if (!shell || !shell->delegate()) {
+ *error_message = "Unable to get shell delegate.";
+ return NULL;
+ }
+ return Profile::FromBrowserContext(
+ shell->delegate()->GetCurrentBrowserContext());
+ }
+ return NULL;
+}
+#endif // defined(OS_CHROMEOS)
+
Browser* GetBrowserForTab(WebContents* tab) {
BrowserList::const_iterator browser_iter = BrowserList::begin();
for (; browser_iter != BrowserList::end(); ++browser_iter) {
diff --git a/chrome/browser/automation/automation_util.h b/chrome/browser/automation/automation_util.h
index 9ccd971..e895108 100644
--- a/chrome/browser/automation/automation_util.h
+++ b/chrome/browser/automation/automation_util.h
@@ -45,6 +45,11 @@ Browser* GetBrowserAt(int index);
// |BrowserList|. If any of these indices are invalid, NULL will be returned.
content::WebContents* GetWebContentsAt(int browser_index, int tab_index);
+#if defined(OS_CHROMEOS)
+// Returns the appropriate profile depending on signed in state of user.
+Profile* GetCurrentProfileOnChromeOS(std::string* error_message);
+#endif
+
// Returns the browser that contains the given tab, or NULL if none exists.
Browser* GetBrowserForTab(content::WebContents* tab);
diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc
index 50bef18..21454cc 100644
--- a/chrome/browser/automation/testing_automation_provider.cc
+++ b/chrome/browser/automation/testing_automation_provider.cc
@@ -1875,7 +1875,19 @@ void TestingAutomationProvider::BuildJSONHandlerMaps() {
handler_map_["SetMute"] = &TestingAutomationProvider::SetMute;
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_["CaptureProfilePhoto"] =
+ &TestingAutomationProvider::CaptureProfilePhoto;
+ browser_handler_map_["GetTimeInfo"] =
+ &TestingAutomationProvider::GetTimeInfo;
#endif // defined(OS_CHROMEOS)
browser_handler_map_["DisablePlugin"] =
@@ -2014,17 +2026,6 @@ void TestingAutomationProvider::BuildJSONHandlerMaps() {
&TestingAutomationProvider::AcceptCurrentFullscreenOrMouseLockRequest;
browser_handler_map_["DenyCurrentFullscreenOrMouseLockRequest"] =
&TestingAutomationProvider::DenyCurrentFullscreenOrMouseLockRequest;
-
-#if defined(OS_CHROMEOS)
- browser_handler_map_["CaptureProfilePhoto"] =
- &TestingAutomationProvider::CaptureProfilePhoto;
- browser_handler_map_["GetTimeInfo"] =
- &TestingAutomationProvider::GetTimeInfo;
- browser_handler_map_["GetProxySettings"] =
- &TestingAutomationProvider::GetProxySettings;
- browser_handler_map_["SetProxySettings"] =
- &TestingAutomationProvider::SetProxySettings;
-#endif // defined(OS_CHROMEOS)
}
scoped_ptr<DictionaryValue> TestingAutomationProvider::ParseJSONRequestCommand(
diff --git a/chrome/browser/automation/testing_automation_provider.h b/chrome/browser/automation/testing_automation_provider.h
index 33e1633..426ec83 100644
--- a/chrome/browser/automation/testing_automation_provider.h
+++ b/chrome/browser/automation/testing_automation_provider.h
@@ -1496,14 +1496,18 @@ class TestingAutomationProvider : public AutomationProvider,
void ToggleNetworkDevice(base::DictionaryValue* args,
IPC::Message* reply_message);
- void GetProxySettings(Browser* browser,
- base::DictionaryValue* args,
+ void GetProxySettings(base::DictionaryValue* args,
IPC::Message* reply_message);
- void SetProxySettings(Browser* browser,
- base::DictionaryValue* args,
+ 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 b8115b53..f256a03 100644
--- a/chrome/browser/automation/testing_automation_provider_chromeos.cc
+++ b/chrome/browser/automation/testing_automation_provider_chromeos.cc
@@ -14,6 +14,7 @@
#include "base/utf_string_conversions.h"
#include "chrome/browser/automation/automation_provider_json.h"
#include "chrome/browser/automation/automation_provider_observers.h"
+#include "chrome/browser/automation/automation_util.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/accessibility/accessibility_util.h"
#include "chrome/browser/chromeos/audio/audio_handler.h"
@@ -34,6 +35,7 @@
#include "chrome/browser/chromeos/login/wizard_controller.h"
#include "chrome/browser/chromeos/options/take_photo_dialog.h"
#include "chrome/browser/chromeos/proxy_cros_settings_parser.h"
+#include "chrome/browser/chromeos/proxy_config_service_impl.h"
#include "chrome/browser/chromeos/settings/cros_settings.h"
#include "chrome/browser/chromeos/settings/cros_settings_names.h"
#include "chrome/browser/chromeos/system/timezone_settings.h"
@@ -84,14 +86,13 @@ DictionaryValue* GetWifiInfoDict(const chromeos::WifiNetwork* wifi) {
return item;
}
-base::Value* GetProxySetting(Browser* browser,
- const std::string& setting_name) {
+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(
- browser->profile(), setting_path, &setting)) {
+ profile, setting_path, &setting)) {
scoped_ptr<DictionaryValue> setting_dict(
static_cast<DictionaryValue*>(setting));
base::Value* value;
@@ -619,6 +620,7 @@ void TestingAutomationProvider::GetNetworkInfo(DictionaryValue* args,
DictionaryValue* items = new DictionaryValue;
DictionaryValue* item = GetNetworkInfoDict(ethernet_network);
items->Set(ethernet_network->service_path(), item);
+ items->SetInteger("network_type", chromeos::TYPE_ETHERNET);
return_value->Set("ethernet_networks", items);
}
}
@@ -638,6 +640,7 @@ void TestingAutomationProvider::GetNetworkInfo(DictionaryValue* args,
DictionaryValue* item = GetWifiInfoDict(wifi);
items->Set(wifi->service_path(), item);
}
+ items->SetInteger("network_type", chromeos::TYPE_WIFI);
return_value->Set("wifi_networks", items);
}
@@ -665,6 +668,7 @@ void TestingAutomationProvider::GetNetworkInfo(DictionaryValue* args,
cellular_networks[i]->GetRoamingStateString());
items->Set(cellular_networks[i]->service_path(), item);
}
+ items->SetInteger("network_type", chromeos::TYPE_CELLULAR);
return_value->Set("cellular_networks", items);
}
@@ -679,6 +683,7 @@ void TestingAutomationProvider::GetNetworkInfo(DictionaryValue* args,
DictionaryValue* item = GetWifiInfoDict(wifi);
remembered_wifi_items->Set(wifi->service_path(), item);
}
+ remembered_wifi_items->SetInteger("network_type", chromeos::TYPE_WIFI);
return_value->Set("remembered_wifi", remembered_wifi_items);
AutomationJSONReply(this, reply_message).SendSuccess(return_value.get());
@@ -721,27 +726,83 @@ void TestingAutomationProvider::ToggleNetworkDevice(
}
}
-void TestingAutomationProvider::GetProxySettings(Browser* browser,
- DictionaryValue* args,
+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(browser, settings[i]);
+ base::Value* setting =
+ GetProxySetting(settings[i], profile);
if (setting)
return_value->Set(settings[i], setting);
}
+ reply.SendSuccess(return_value.get());
+}
- AutomationJSONReply(this, reply_message).SendSuccess(return_value.get());
+void TestingAutomationProvider::SetSharedProxies(
+ DictionaryValue* args,
+ IPC::Message* reply_message) {
+
+ AutomationJSONReply reply(this, reply_message);
+ base::Value* value;
+ if (!args->Get("value", &value)) {
+ 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);
+ if (!profile) {
+ reply.SendError(error_message);
+ 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);
+ reply.SendSuccess(NULL);
}
-void TestingAutomationProvider::SetProxySettings(Browser* browser,
- DictionaryValue* args,
+void TestingAutomationProvider::SetProxySettings(DictionaryValue* args,
IPC::Message* reply_message) {
AutomationJSONReply reply(this, reply_message);
std::string key;
@@ -750,13 +811,18 @@ void TestingAutomationProvider::SetProxySettings(Browser* browser,
reply.SendError("Invalid or missing args.");
return;
}
-
+ std::string error_message;
+ Profile* profile =
+ automation_util::GetCurrentProfileOnChromeOS(&error_message);
+ if (!profile) {
+ reply.SendError(error_message);
+ return;
+ }
+ // ProxyCrosSettingsProvider will own the Value* passed to Set().
std::string setting_path = "cros.session.proxy.";
setting_path.append(key);
-
- // ProxyCrosSettingsProvider will own the Value* passed to Set().
chromeos::proxy_cros_settings_parser::SetProxyPrefValue(
- browser->profile(), setting_path, value);
+ profile, setting_path, value);
reply.SendSuccess(NULL);
}
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index bbeacdb..6bcc252 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -9,6 +9,7 @@
'common/automation_constants.h',
'common/pref_names.cc',
'common/pref_names.h',
+ 'browser/chromeos/cros/network_constants.h',
'test/automation/browser_proxy.cc',
'test/automation/browser_proxy.h',
'test/automation/tab_proxy.cc',
@@ -4479,6 +4480,24 @@
],
'actions': [
{
+ 'variables' : {
+ 'swig_args': [ '-I..',
+ '-python',
+ '-c++',
+ '-threads',
+ '-outdir',
+ '<(PRODUCT_DIR)',
+ '-o',
+ '<(INTERMEDIATE_DIR)/pyautolib_wrap.cc',
+ ],
+ 'conditions': [
+ ['chromeos==1', {
+ 'swig_args': [
+ '-DOS_CHROMEOS',
+ ]
+ }],
+ ],
+ },
'action_name': 'pyautolib_swig',
'inputs': [
'test/pyautolib/argc_argv.i',
@@ -4491,14 +4510,7 @@
],
'action': [ 'python',
'../tools/swig/swig.py',
- '-I..',
- '-python',
- '-c++',
- '-threads',
- '-outdir',
- '<(PRODUCT_DIR)',
- '-o',
- '<(INTERMEDIATE_DIR)/pyautolib_wrap.cc',
+ '<@(swig_args)',
'test/pyautolib/pyautolib.i',
],
'message': 'Generating swig wrappers for pyautolib.',
diff --git a/chrome/test/functional/PYAUTO_TESTS b/chrome/test/functional/PYAUTO_TESTS
index 205b300..f37f07d 100644
--- a/chrome/test/functional/PYAUTO_TESTS
+++ b/chrome/test/functional/PYAUTO_TESTS
@@ -623,7 +623,7 @@
'chromeos_oobe',
# crosbug.com/32583
- '-chromeos_login.ChromeosLogin.testCachedCredentials',
+ '-chromeos_login.ChromeosLoginCachedCredentialsUserPod.testCachedCredentialsUserPod',
],
},
diff --git a/chrome/test/functional/chromeos_login.py b/chrome/test/functional/chromeos_login.py
index 79963e1..7b4a56b 100755
--- a/chrome/test/functional/chromeos_login.py
+++ b/chrome/test/functional/chromeos_login.py
@@ -131,15 +131,6 @@ class ChromeosLogin(pyauto.PyUITest):
login_info = self.GetLoginInfo()
self.assertTrue(login_info['is_logged_in'], msg='Login failed.')
- def testCachedCredentials(self):
- """Test that we can login without connectivity if we have so before."""
- self.testGoodLogin()
- self.Logout()
- self.SetProxySettingsOnChromeOS('singlehttp', '10.10.10.10')
- self.testGoodLogin()
- # Reset back to direct proxy
- self.SetProxySettingsOnChromeOS('type', self.PROXY_TYPE_DIRECT)
-
def testNavigateAfterLogin(self):
"""Test that page navigation is successful after logging in."""
self.testGoodLogin()
@@ -284,5 +275,91 @@ class ChromeosLogin(pyauto.PyUITest):
self.assertEqual(3, len(self.GetBrowserInfo()['windows'][0]['tabs']))
+class ChromeosLoginCachedCredentialsAddUser(pyauto.PyUITest):
+ """TestCase for failing to add a user with invalid proxy settings."""
+ assert os.geteuid() == 0, 'Need to run this test as root'
+
+ def ShouldAutoLogin(self):
+ return False
+
+ def setUp(self):
+ # We want a clean session_manager instance for every run,
+ # so restart ui now.
+ cros_ui.stop(allow_fail=True)
+ cryptohome.remove_all_vaults()
+ cros_ui.start(wait_for_login_prompt=False)
+ pyauto.PyUITest.setUp(self)
+
+ def tearDown(self):
+ self.ResetProxySettingsOnChromeOS()
+ pyauto.PyUITest.tearDown(self)
+
+ def _ValidCredentials(self, account_type='test_google_account'):
+ """Obtains a valid username and password from a data file.
+
+ Returns:
+ A dictionary with the keys 'username' and 'password'
+ """
+ return self.GetPrivateInfo()[account_type]
+
+ def testCachedCredentialsAddUser(self):
+ proxy_dict = {
+ 'url_path': 'singlehttp',
+ 'proxy_url': '127.0.0.1',
+ }
+ self.SetProxySettingOnChromeOS(proxy_dict)
+
+ """Test that login fails."""
+ credentials = self._ValidCredentials()
+ self.assertRaises(
+ pyauto_errors.JSONInterfaceError,
+ lambda: self.Login(credentials['username'],
+ credentials['password'])
+ )
+
+class ChromeosLoginCachedCredentialsUserPod(pyauto.PyUITest):
+ """TestCase for Logging into ChromeOS with cached credentials and
+ invalid proxy settings.
+ """
+ assert os.geteuid() == 0, 'Need to run this test as root'
+
+ def ShouldAutoLogin(self):
+ return False
+
+ def setUp(self):
+ # We want a clean session_manager instance for every run,
+ # so restart ui now.
+ cros_ui.stop(allow_fail=True)
+ cryptohome.remove_all_vaults()
+ cros_ui.start(wait_for_login_prompt=False)
+ pyauto.PyUITest.setUp(self)
+
+ def tearDown(self):
+ self.ResetProxySettingsOnChromeOS()
+ pyauto.PyUITest.tearDown(self)
+
+ def _ValidCredentials(self, account_type='test_google_account'):
+ """Obtains a valid username and password from a data file.
+
+ Returns:
+ A dictionary with the keys 'username' and 'password'
+ """
+ return self.GetPrivateInfo()[account_type]
+
+ def testCachedCredentialsUserPod(self):
+ """Test that we can login without connectivity if we have so before.
+
+ This test is currently disabled because testGoodLogin tries to
+ add a user after setting proxies, which is supposed to fail. To
+ make it pass we need a hook that simply calls Login on the delegate
+ in webui_login_display.cc ::ShowSigninScreenForCreds.
+ """
+ self.testGoodLogin()
+ self.Logout()
+ self.SetProxySettingOnChromeOS('singlehttp', '127.0.0.1')
+ self.testGoodLogin()
+ self.ResetProxySettingsOnChromeOS()
+
+
if __name__ == '__main__':
pyauto_functional.Main()
diff --git a/chrome/test/functional/chromeos_proxy.py b/chrome/test/functional/chromeos_proxy.py
index 4aa2949..cbd74f7 100755
--- a/chrome/test/functional/chromeos_proxy.py
+++ b/chrome/test/functional/chromeos_proxy.py
@@ -5,7 +5,9 @@
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.
@@ -34,10 +36,10 @@ class ChromeosProxy(pyauto.PyUITest):
def setUp(self):
pyauto.PyUITest.setUp(self)
- self.SetProxySettingsOnChromeOS('type', self.PROXY_TYPE_DIRECT)
+ self.ResetProxySettingsOnChromeOS()
def tearDown(self):
- self.SetProxySettingsOnChromeOS('type', self.PROXY_TYPE_DIRECT)
+ self.ResetProxySettingsOnChromeOS()
pyauto.PyUITest.tearDown(self)
def _BasicSetManualProxyFieldTest(self, proxy_type, proxy_url,
@@ -50,42 +52,49 @@ class ChromeosProxy(pyauto.PyUITest):
proxy_port: The port number. May be left blank to imply using the default
port. The default ports are defined by self.DEFAULT_PORTS.
"""
- field = ChromeosProxy.MANUAL_PROXY_FIELDS[proxy_type]
- self.SetProxySettingsOnChromeOS(field['url'], proxy_url)
- if proxy_port is not None:
- self.SetProxySettingsOnChromeOS(field['port'], proxy_port)
+ 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(field['url'] in result,
+ self.assertTrue(url_path in result,
'No %s url entry was saved' % proxy_type)
- self.assertEqual(result[field['url']], proxy_url,
+ self.assertEqual(result[url_path], proxy_url,
'Saved proxy url %s does not match user set url %s.' %
- (result[field['url']], proxy_url))
+ (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[field['port']],
+ result[port_path],
'Proxy port %d was used instead of default port %d.' %
- (result[field['port']],
+ (result[port_path],
ChromeosProxy.DEFAULT_PORTS[proxy_type]))
else:
- self.assertEqual(proxy_port, result[field['port']],
+ self.assertEqual(proxy_port, result[port_path],
'Proxy port %d was used instead of user set port %d.' %
- (result[field['port']], proxy_port))
+ (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(val['url'] in result, 'Only %s url should have '
+ 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(val['port'] in result, 'Only %s port should have '
+ self.assertFalse(result.get(val['port']), 'Only %s port should have '
'been set. %s port should have been left blank.' %
(proxy_type, key))
@@ -157,6 +166,13 @@ class ChromeosProxy(pyauto.PyUITest):
"""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)
diff --git a/chrome/test/pyautolib/pyauto.py b/chrome/test/pyautolib/pyauto.py
index 9282a26..596f767 100755
--- a/chrome/test/pyautolib/pyauto.py
+++ b/chrome/test/pyautolib/pyauto.py
@@ -99,7 +99,6 @@ _REMOTE_PROXY = None
_OPTIONS = None
_BROWSER_PID = None
-
class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
"""Base class for UI Test Cases in Python.
@@ -4922,7 +4921,8 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
u'name': u'',
u'service_path':
u'/profile/default/ethernet_abcd',
- u'status': u'Connected'}},
+ u'status': u'Connected'}
+ u'network_type': pyautolib.TYPE_ETHERNET },
u'ip_address': u'11.22.33.44',
u'remembered_wifi':
{ u'/service/wifi_abcd_1234_managed_none':
@@ -4933,6 +4933,7 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
u'name': u'WifiNetworkName1',
u'status': u'Unknown',
u'strength': 0},
+ u'network_type': pyautolib.TYPE_WIFI
},
u'wifi_available': True,
u'wifi_enabled': True,
@@ -4951,7 +4952,8 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
u'ip_address': u'',
u'name': u'WifiNetworkName2',
u'status': u'Idle',
- u'strength': 79}}}
+ u'strength': 79}
+ u'network_type': pyautolib.TYPE_WIFI }}
Raises:
@@ -5087,11 +5089,11 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
self.PROXY_TYPE_PAC: 'Automatic proxy configuration' }
return values[proxy_type]
- def GetProxySettingsOnChromeOS(self, windex=0):
+ def GetProxySettingsOnChromeOS(self):
"""Get current proxy settings on Chrome OS.
Returns:
- A dictionary. See SetProxySettings() below
+ A dictionary. See SetProxySetting() below
for the full list of possible dictionary keys.
Samples:
@@ -5114,15 +5116,131 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
pyauto_errors.JSONInterfaceError if the automation call returns an error.
"""
cmd_dict = { 'command': 'GetProxySettings' }
- return self._GetResultFromJSONRequest(cmd_dict, windex=windex)
+ 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')
- def SetProxySettingsOnChromeOS(self, key, value, windex=0):
- """Set a proxy setting on Chrome OS.
+ 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)
+
+ def _SetProxySettingOnChromeOSCore(self, key, value):
+ """Set a proxy setting.
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.
@@ -5150,15 +5268,19 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
Examples:
# Sets direct internet connection, no proxy.
- self.SetProxySettings('type', self.PROXY_TYPE_DIRECT)
+ self.SetProxySettingOnChromeOS('type', self.PROXY_TYPE_DIRECT)
# Sets manual proxy configuration, same proxy for all protocols.
- self.SetProxySettings('singlehttp', '24.27.78.152')
- self.SetProxySettings('singlehttpport', 1728)
- self.SetProxySettings('ignorelist', ['www.example.com', 'example2.com'])
+ 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.SetProxySettings('pacurl', 'http://example.com/config.pac')
+ self.SetProxySettingOnChromeOS('pacurl', 'http://example.com/config.pac')
+
+ # Sets httpproxy with specified url
+ self.SetProxySettingOnChromeOS('httpurl', 10.10.10)
Raises:
pyauto_errors.JSONInterfaceError if the automation call returns an error.
@@ -5168,7 +5290,38 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
'key': key,
'value': value,
}
- return self._GetResultFromJSONRequest(cmd_dict, windex=windex)
+ return self._GetResultFromJSONRequest(cmd_dict, windex=None)
+
+ def SetSharedProxies(self, value):
+ """Allows shared proxies on the named network.
+
+ Args:
+ value: True/False to set and clear respectively.
+
+ Raises:
+ pyauto_errors.JSONInterfaceError if the automation call returns an error.
+ """
+ cmd_dict = {
+ 'command': 'SetSharedProxies',
+ 'value': value,
+ }
+ 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."""
diff --git a/chrome/test/pyautolib/pyautolib.i b/chrome/test/pyautolib/pyautolib.i
index a807bce..ba9eb84 100644
--- a/chrome/test/pyautolib/pyautolib.i
+++ b/chrome/test/pyautolib/pyautolib.i
@@ -38,12 +38,20 @@
%ignore net::MapNetErrorToCertStatus(int);
%include "net/base/cert_status_flags.h"
+#if defined(OS_CHROMEOS)
+%include "chrome/browser/chromeos/cros/network_constants.h"
+%{
+#include "chrome/browser/chromeos/cros/network_constants.h"
+%}
+#endif
+
%{
#include "chrome/common/automation_constants.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/automation/browser_proxy.h"
#include "chrome/test/automation/tab_proxy.h"
#include "chrome/test/pyautolib/pyautolib.h"
+#include "content/public/common/security_style.h"
#include "net/test/test_server.h"
%}