[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):
"""
find_test_data_dir = 'find_in_page'
def ShouldAutoLogin(self):
return False
def setUp(self):
# We want a clean session_manager instance for every run,
# so restart ui now.
......
......@@ -24,7 +24,7 @@ class ChromeosDevicePolicy(policy_base.PolicyTestBase):
self.assertTrue(self.GetLoginInfo()['is_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'],
msg='Expected to be logged out.')
policy_base.PolicyTestBase.Login(self,
......@@ -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
# account picker is shown.
self.Login(user_index=0, expect_success=True)
self._Login(user_index=0, expect_success=True)
self.Logout()
self.SetDevicePolicy({'guest_mode_enabled': True})
......@@ -94,7 +94,7 @@ class ChromeosDevicePolicy(policy_base.PolicyTestBase):
"""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
# 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.SetDevicePolicy({'show_user_names': False})
......@@ -119,42 +119,42 @@ class ChromeosDevicePolicy(policy_base.PolicyTestBase):
# No whitelist
self.SetDevicePolicy({'allow_new_users': True,
'show_user_names': False})
self.Login(user_index=0, expect_success=True)
self._Login(user_index=0, expect_success=True)
self.Logout()
# Empty whitelist
self.SetDevicePolicy({'user_whitelist': []})
self.Login(user_index=0, expect_success=True)
self._Login(user_index=0, expect_success=True)
self.Logout()
self.SetDevicePolicy({'allow_new_users': True,
'user_whitelist': [],
'show_user_names': False})
self.Login(user_index=0, expect_success=True)
self._Login(user_index=0, expect_success=True)
self.Logout()
# Populated whitelist
self.SetDevicePolicy({'user_whitelist': [self._usernames[0]],
'show_user_names': False})
self.Login(user_index=0, expect_success=True)
self._Login(user_index=0, expect_success=True)
self.Logout()
self.Login(user_index=1, expect_success=False)
self._Login(user_index=1, expect_success=False)
self.SetDevicePolicy({'allow_new_users': True,
'user_whitelist': [self._usernames[0]],
'show_user_names': False})
self.Login(user_index=0, expect_success=True)
self._Login(user_index=0, expect_success=True)
self.Logout()
self.Login(user_index=1, expect_success=True)
self._Login(user_index=1, expect_success=True)
self.Logout()
# New users not allowed, populated whitelist
self.SetDevicePolicy({'allow_new_users': False,
'user_whitelist': [self._usernames[0]],
'show_user_names': False})
self.Login(user_index=0, expect_success=True)
self._Login(user_index=0, expect_success=True)
self.Logout()
self.Login(user_index=1, expect_success=False)
self._Login(user_index=1, expect_success=False)
def testUserWhitelistInAccountPicker(self):
"""Checks that setting a whitelist removes non-whitelisted user pods."""
......@@ -165,9 +165,9 @@ class ChromeosDevicePolicy(policy_base.PolicyTestBase):
self.WaitForLoginFormReload()
# 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.Login(user_index=1, expect_success=True)
self._Login(user_index=1, expect_success=True)
self.Logout()
# Enable the account picker.
......
......@@ -23,6 +23,9 @@ class ChromeosLogin(pyauto.PyUITest):
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.
......
......@@ -142,6 +142,9 @@ class NetflixTest(pyauto.PyUITest, NetflixTestHelper):
pyauto.PyUITest.__init__(self, methodName, **kwargs)
NetflixTestHelper.__init__(self, self)
def ShouldAutoLogin(self):
return False
def _Login(self):
"""Perform login"""
credentials = self.GetPrivateInfo()['test_google_account']
......
......@@ -28,15 +28,10 @@ class ChromeosUtils(pyauto.PyUITest):
python chromeos_utils.py \
chromeos_utils.ChromeosUtils.LoginToDefaultAccount
"""
if self.GetLoginInfo()['is_logged_in']:
logging.info('Already logged in as %s.' % self.GetLoginInfo()['email'])
return
creds = constants.CREDENTIALS['$default']
username = creds[0]
passwd = creds[1]
self.Login(username, passwd)
assert self.GetLoginInfo()['is_logged_in']
logging.info('Logged in as %s.' % username)
# Should auto-login. Nothing to do here.
# TODO(nirnimesh): Remove this when auto-login feature
# reaches chromeos such that this helper is not necessary.
pass
if __name__ == '__main__':
......
......@@ -105,6 +105,9 @@ class PolicyTestBase(pyauto.PyUITest):
_auth_server = None
_dns_server = None
def ShouldAutoLogin(self):
return False
@staticmethod
def _Call(command, check=False):
"""Invokes a subprocess and optionally asserts the return value is zero."""
......
......@@ -209,10 +209,18 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
if self.IsChromeOS():
self.WaitUntil(lambda: not self.GetNetworkInfo()['offline_mode'])
if (self.IsChromeOS() and self.ShouldOOBESkipToLogin() and
not self.GetLoginInfo()['is_logged_in'] and
self.GetOOBEScreenInfo()['screen_name'] != 'login'):
self.SkipToLogin()
if (self.IsChromeOS() and not self.GetLoginInfo()['is_logged_in'] and
self.ShouldOOBESkipToLogin()):
if self.GetOOBEScreenInfo()['screen_name'] != 'login':
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
# instances on the remote sides and set them up too.
......@@ -302,6 +310,23 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
assert self.IsChromeOS()
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):
"""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