[chromeos] pyauto tests should auto login by default on chromeos

Tests should auto-login on chromeos by default, since most use cases
begin there. Provide a way to override it.

This helps with non-login pyauto functional tests on chromeos such that if (for
whatever reason) the device gets logged out in the middle of running
pyauto_functional.py, individual tests can still manage to carry on.

BUG=None
TEST=None

R=craigdh@chromium.org

Review URL: https://chromiumcodereview.appspot.com/10836187

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@151311 0039d316-1c4b-4281-b951-d872f2087c98
parent c5ef76fb
...@@ -24,6 +24,9 @@ class AccessibilityTest(pyauto.PyUITest): ...@@ -24,6 +24,9 @@ class AccessibilityTest(pyauto.PyUITest):
""" """
find_test_data_dir = 'find_in_page' find_test_data_dir = 'find_in_page'
def ShouldAutoLogin(self):
return False
def setUp(self): def setUp(self):
# We want a clean session_manager instance for every run, # We want a clean session_manager instance for every run,
# so restart ui now. # so restart ui now.
......
...@@ -24,7 +24,7 @@ class ChromeosDevicePolicy(policy_base.PolicyTestBase): ...@@ -24,7 +24,7 @@ class ChromeosDevicePolicy(policy_base.PolicyTestBase):
self.assertTrue(self.GetLoginInfo()['is_logged_in'], self.assertTrue(self.GetLoginInfo()['is_logged_in'],
msg='Expected to be logged in.') msg='Expected to be logged in.')
def Login(self, user_index, expect_success): def _Login(self, user_index, expect_success):
self.assertFalse(self.GetLoginInfo()['is_logged_in'], self.assertFalse(self.GetLoginInfo()['is_logged_in'],
msg='Expected to be logged out.') msg='Expected to be logged out.')
policy_base.PolicyTestBase.Login(self, policy_base.PolicyTestBase.Login(self,
...@@ -77,7 +77,7 @@ class ChromeosDevicePolicy(policy_base.PolicyTestBase): ...@@ -77,7 +77,7 @@ class ChromeosDevicePolicy(policy_base.PolicyTestBase):
# Log in as a regular so that the pod row contains at least one pod and the # Log in as a regular so that the pod row contains at least one pod and the
# account picker is shown. # account picker is shown.
self.Login(user_index=0, expect_success=True) self._Login(user_index=0, expect_success=True)
self.Logout() self.Logout()
self.SetDevicePolicy({'guest_mode_enabled': True}) self.SetDevicePolicy({'guest_mode_enabled': True})
...@@ -94,7 +94,7 @@ class ChromeosDevicePolicy(policy_base.PolicyTestBase): ...@@ -94,7 +94,7 @@ class ChromeosDevicePolicy(policy_base.PolicyTestBase):
"""Checks that the account picker can be enabled/disabled.""" """Checks that the account picker can be enabled/disabled."""
# Log in as a regular user so that the pod row contains at least one pod and # Log in as a regular user so that the pod row contains at least one pod and
# the account picker can be shown. # the account picker can be shown.
self.Login(user_index=0, expect_success=True) self._Login(user_index=0, expect_success=True)
self.Logout() self.Logout()
self.SetDevicePolicy({'show_user_names': False}) self.SetDevicePolicy({'show_user_names': False})
...@@ -119,42 +119,42 @@ class ChromeosDevicePolicy(policy_base.PolicyTestBase): ...@@ -119,42 +119,42 @@ class ChromeosDevicePolicy(policy_base.PolicyTestBase):
# No whitelist # No whitelist
self.SetDevicePolicy({'allow_new_users': True, self.SetDevicePolicy({'allow_new_users': True,
'show_user_names': False}) 'show_user_names': False})
self.Login(user_index=0, expect_success=True) self._Login(user_index=0, expect_success=True)
self.Logout() self.Logout()
# Empty whitelist # Empty whitelist
self.SetDevicePolicy({'user_whitelist': []}) self.SetDevicePolicy({'user_whitelist': []})
self.Login(user_index=0, expect_success=True) self._Login(user_index=0, expect_success=True)
self.Logout() self.Logout()
self.SetDevicePolicy({'allow_new_users': True, self.SetDevicePolicy({'allow_new_users': True,
'user_whitelist': [], 'user_whitelist': [],
'show_user_names': False}) 'show_user_names': False})
self.Login(user_index=0, expect_success=True) self._Login(user_index=0, expect_success=True)
self.Logout() self.Logout()
# Populated whitelist # Populated whitelist
self.SetDevicePolicy({'user_whitelist': [self._usernames[0]], self.SetDevicePolicy({'user_whitelist': [self._usernames[0]],
'show_user_names': False}) 'show_user_names': False})
self.Login(user_index=0, expect_success=True) self._Login(user_index=0, expect_success=True)
self.Logout() self.Logout()
self.Login(user_index=1, expect_success=False) self._Login(user_index=1, expect_success=False)
self.SetDevicePolicy({'allow_new_users': True, self.SetDevicePolicy({'allow_new_users': True,
'user_whitelist': [self._usernames[0]], 'user_whitelist': [self._usernames[0]],
'show_user_names': False}) 'show_user_names': False})
self.Login(user_index=0, expect_success=True) self._Login(user_index=0, expect_success=True)
self.Logout() self.Logout()
self.Login(user_index=1, expect_success=True) self._Login(user_index=1, expect_success=True)
self.Logout() self.Logout()
# New users not allowed, populated whitelist # New users not allowed, populated whitelist
self.SetDevicePolicy({'allow_new_users': False, self.SetDevicePolicy({'allow_new_users': False,
'user_whitelist': [self._usernames[0]], 'user_whitelist': [self._usernames[0]],
'show_user_names': False}) 'show_user_names': False})
self.Login(user_index=0, expect_success=True) self._Login(user_index=0, expect_success=True)
self.Logout() self.Logout()
self.Login(user_index=1, expect_success=False) self._Login(user_index=1, expect_success=False)
def testUserWhitelistInAccountPicker(self): def testUserWhitelistInAccountPicker(self):
"""Checks that setting a whitelist removes non-whitelisted user pods.""" """Checks that setting a whitelist removes non-whitelisted user pods."""
...@@ -165,9 +165,9 @@ class ChromeosDevicePolicy(policy_base.PolicyTestBase): ...@@ -165,9 +165,9 @@ class ChromeosDevicePolicy(policy_base.PolicyTestBase):
self.WaitForLoginFormReload() self.WaitForLoginFormReload()
# Log in to populate the list of existing users. # Log in to populate the list of existing users.
self.Login(user_index=0, expect_success=True) self._Login(user_index=0, expect_success=True)
self.Logout() self.Logout()
self.Login(user_index=1, expect_success=True) self._Login(user_index=1, expect_success=True)
self.Logout() self.Logout()
# Enable the account picker. # Enable the account picker.
......
...@@ -23,6 +23,9 @@ class ChromeosLogin(pyauto.PyUITest): ...@@ -23,6 +23,9 @@ class ChromeosLogin(pyauto.PyUITest):
assert os.geteuid() == 0, 'Need to run this test as root' assert os.geteuid() == 0, 'Need to run this test as root'
def ShouldAutoLogin(self):
return False
def setUp(self): def setUp(self):
# We want a clean session_manager instance for every run, # We want a clean session_manager instance for every run,
# so restart ui now. # so restart ui now.
......
...@@ -142,6 +142,9 @@ class NetflixTest(pyauto.PyUITest, NetflixTestHelper): ...@@ -142,6 +142,9 @@ class NetflixTest(pyauto.PyUITest, NetflixTestHelper):
pyauto.PyUITest.__init__(self, methodName, **kwargs) pyauto.PyUITest.__init__(self, methodName, **kwargs)
NetflixTestHelper.__init__(self, self) NetflixTestHelper.__init__(self, self)
def ShouldAutoLogin(self):
return False
def _Login(self): def _Login(self):
"""Perform login""" """Perform login"""
credentials = self.GetPrivateInfo()['test_google_account'] credentials = self.GetPrivateInfo()['test_google_account']
......
...@@ -28,15 +28,10 @@ class ChromeosUtils(pyauto.PyUITest): ...@@ -28,15 +28,10 @@ class ChromeosUtils(pyauto.PyUITest):
python chromeos_utils.py \ python chromeos_utils.py \
chromeos_utils.ChromeosUtils.LoginToDefaultAccount chromeos_utils.ChromeosUtils.LoginToDefaultAccount
""" """
if self.GetLoginInfo()['is_logged_in']: # Should auto-login. Nothing to do here.
logging.info('Already logged in as %s.' % self.GetLoginInfo()['email']) # TODO(nirnimesh): Remove this when auto-login feature
return # reaches chromeos such that this helper is not necessary.
creds = constants.CREDENTIALS['$default'] pass
username = creds[0]
passwd = creds[1]
self.Login(username, passwd)
assert self.GetLoginInfo()['is_logged_in']
logging.info('Logged in as %s.' % username)
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -105,6 +105,9 @@ class PolicyTestBase(pyauto.PyUITest): ...@@ -105,6 +105,9 @@ class PolicyTestBase(pyauto.PyUITest):
_auth_server = None _auth_server = None
_dns_server = None _dns_server = None
def ShouldAutoLogin(self):
return False
@staticmethod @staticmethod
def _Call(command, check=False): def _Call(command, check=False):
"""Invokes a subprocess and optionally asserts the return value is zero.""" """Invokes a subprocess and optionally asserts the return value is zero."""
......
...@@ -209,10 +209,18 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase): ...@@ -209,10 +209,18 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
if self.IsChromeOS(): if self.IsChromeOS():
self.WaitUntil(lambda: not self.GetNetworkInfo()['offline_mode']) self.WaitUntil(lambda: not self.GetNetworkInfo()['offline_mode'])
if (self.IsChromeOS() and self.ShouldOOBESkipToLogin() and if (self.IsChromeOS() and not self.GetLoginInfo()['is_logged_in'] and
not self.GetLoginInfo()['is_logged_in'] and self.ShouldOOBESkipToLogin()):
self.GetOOBEScreenInfo()['screen_name'] != 'login'): if self.GetOOBEScreenInfo()['screen_name'] != 'login':
self.SkipToLogin() self.SkipToLogin()
if self.ShouldAutoLogin():
# Login with default creds.
sys.path.append('/usr/local') # to import autotest libs
from autotest.cros import constants
creds = constants.CREDENTIALS['$default']
self.Login(creds[0], creds[1])
assert self.GetLoginInfo()['is_logged_in']
logging.info('Logged in as %s.' % creds[0])
# If we are connected to any RemoteHosts, create PyAuto # If we are connected to any RemoteHosts, create PyAuto
# instances on the remote sides and set them up too. # instances on the remote sides and set them up too.
...@@ -302,6 +310,23 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase): ...@@ -302,6 +310,23 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
assert self.IsChromeOS() assert self.IsChromeOS()
return True return True
def ShouldAutoLogin(self):
"""Determine if we should auto-login on ChromeOS at browser startup.
To be used for tests that expect user to be logged in before running test,
without caring which user. ShouldOOBESkipToLogin() should return True
for this to take effect.
Override and return False to not auto login, for tests where login is part
of the use case.
Returns:
True, if chrome should auto login after startup.
False, otherwise.
"""
assert self.IsChromeOS()
return True
def CloseChromeOnChromeOS(self): def CloseChromeOnChromeOS(self):
"""Gracefully exit chrome on ChromeOS.""" """Gracefully exit chrome on ChromeOS."""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment