switch to autox.py and robustify login/logout code
This CL switches from using the autox binary to using autox.py. This includes backwards
incompatible changes to site_login.py, and I haven't had a chance to fix the affected callsites
yet.
I've also made the login/logout code a little more robust. Now it'll make sure that the login
manager is running under a NEW pid, that X is running, and that at a window is visible before
assuming we're ready to log in.
All of the wait loops have been refactored into wait_for(...), which spits out logging.info()
messages that could be parsed later to determine how long the operations are actually taking.
Perhaps this could make it into a different, non-login specific library soonish.
I'm out of the office for the next few days, but wanted to get this out there before the
trunk totally passed it by. I'll return on Wednesday to finish the job.
Review URL: http://codereview.chromium.org/1534001
diff --git a/client/bin/chromeos_constants.py b/client/bin/chromeos_constants.py
index 18d1f3b..a7c9e48 100644
--- a/client/bin/chromeos_constants.py
+++ b/client/bin/chromeos_constants.py
@@ -12,7 +12,7 @@
CRYPTOHOME_MOUNT_PT = USER_DATA_DIR+'/user'
BROWSER = 'chrome'
-
+SESSION_MANAGER = 'session_manager'
WINDOW_MANAGER = 'chromeos-wm'
LOGGED_IN_MAGIC_FILE = '/var/run/state/logged-in'
@@ -21,3 +21,8 @@
'/var/run/state/windowmanager/initial-chrome-window-mapped'
DISABLE_BROWSER_RESTART_MAGIC_FILE = '/tmp/disable_chrome_restart'
+
+CREDENTIALS = {
+ '$default': ['performance.test.account@gmail.com', 'perfsmurf'],
+ '$backdoor': ['chronos@gmail.com', 'chronos'],
+}
diff --git a/client/bin/site_login.py b/client/bin/site_login.py
index b2c1c1b..15fa786 100644
--- a/client/bin/site_login.py
+++ b/client/bin/site_login.py
@@ -2,22 +2,75 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
-import logging, os, utils, signal, time
+import logging, os, utils, signal, subprocess, time
from autotest_lib.client.bin import chromeos_constants, site_cryptohome
from autotest_lib.client.bin import site_utils, test
from autotest_lib.client.common_lib import error, site_ui
class TimeoutError(error.TestError):
- """Error returned if we time out while waiting on a condition."""
- pass
+ """Error raised when we time out while waiting on a condition."""
+ pass
-def setup_autox(test):
- test.job.setup_dep(['autox'])
- # create a empty srcdir to prevent the error that checks .version file
- if not os.path.exists(test.srcdir):
- os.mkdir(test.srcdir)
+class UnexpectedCondition(error.TestError):
+ """Error raised when an expected precondition is not met."""
+ pass
+
+
+def __get_session_manager_pid():
+ """Determine the pid of the session manager.
+
+ Returns:
+ An integer indicating the current session manager pid, or None if
+ it is not running.
+ """
+
+ p = subprocess.Popen(["pgrep", "^%s$" % chromeos_constants.SESSION_MANAGER],
+ stdout=subprocess.PIPE)
+ ary = p.communicate()[0].split()
+ return int(ary[0]) if ary else None
+
+
+def __session_manager_restarted(oldpid):
+ """Detect if the session manager has restarted.
+
+ Args:
+ oldpid: Integer indicating the last known pid of the session_manager.
+
+ Returns:
+ True if the session manager is running under a pid other than
+ 'oldpid', X is running, and there is a window displayed.
+ """
+ import autox
+
+ newpid = __get_session_manager_pid()
+ if newpid and newpid != oldpid:
+ try:
+ ax = site_ui.get_autox()
+ except autox.Xlib.error.DisplayConnectionError:
+ return False
+
+ # When the session manager starts up there is a moment where we can
+ # make a connection with autox, but there is no window displayed. If
+ # we start sending keystrokes at this point they get lost. If we wait
+ # for this window to show up, things go much smoother.
+ wid = ax.get_top_window_id_at_point(0, 0)
+ if not wid:
+ return False
+
+ # The login manager displays its widgetry in a second window centered
+ # on the screen. Waiting for this window to show up is also helpful.
+ # TODO: perhaps the login manager should emit some more trustworthy
+ # signal when it's ready to accept credentials.
+ x, y = ax.get_screen_size()
+ wid2 = ax.get_top_window_id_at_point(x / 2, y / 2)
+ if wid == wid2:
+ return False
+
+ return True
+
+ return False
def logged_in():
@@ -26,8 +79,7 @@
return os.path.exists(chromeos_constants.LOGGED_IN_MAGIC_FILE)
-# TODO: Update this to use the Python-based autox instead.
-def attempt_login(test, script_file, timeout=10):
+def attempt_login(username, password, timeout=20):
"""Attempt to log in.
Args:
@@ -35,32 +87,38 @@
timeout: float number of seconds to wait
Raises:
- error.TestFail: autox program exited with failure
TimeoutError: login didn't complete before timeout
+ UnexpectedCondition: login manager is not running, or user is already
+ logged in.
"""
- dep = 'autox'
- dep_dir = os.path.join(test.autodir, 'deps', dep)
- test.job.install_pkg(dep, 'dep', dep_dir)
+ logging.info("Attempting to login using autox.py and (%s, %s)" %
+ (username, password))
- autox_binary = '%s/%s' % (dep_dir, 'autox')
- autox_script = os.path.join(test.job.configdir, script_file)
+ if not __get_session_manager_pid():
+ raise UnexpectedCondition("Session manager is not running")
- # TODO: Use something more robust that checks whether the login window is
- # mapped.
- wait_for_browser()
- try:
- utils.system(site_ui.xcommand('%s %s' % (autox_binary, autox_script)))
- except error.CmdError, e:
- logging.debug(e)
- raise error.TestFail('AutoX program failed to login for test user')
+ if logged_in():
+ raise UnexpectedCondition("Already logged in")
+
+ ax = site_ui.get_autox()
+ # navigate to login screen
+ ax.send_hotkey("Ctrl+Alt+L")
+ # focus username
+ ax.send_hotkey("Alt+U")
+ ax.send_text(username)
+ # TODO(rginda): remove Tab after http://codereview.chromium.org/1390003
+ ax.send_hotkey("Tab")
+ # focus password
+ ax.send_hotkey("Alt+P")
+ ax.send_text(password)
+ ax.send_hotkey("Return")
site_utils.poll_for_condition(
- lambda: logged_in(),
- TimeoutError('Timed out while waiting to be logged in'),
+ logged_in, TimeoutError('Timed out waiting for login'),
timeout=timeout)
-def attempt_logout(timeout=10):
+def attempt_logout(timeout=20):
"""Attempt to log out by killing Chrome.
Args:
@@ -68,14 +126,20 @@
Raises:
TimeoutError: logout didn't complete before timeout
+ UnexpectedCondition: user is not logged in
"""
- # Gracefully exiting chrome causes the user's session to end.
- wait_for_initial_chrome_window()
- utils.system('pkill -TERM -o ^%s$' % chromeos_constants.BROWSER)
+ if not logged_in():
+ raise UnexpectedCondition('Already logged out')
+
+ oldpid = __get_session_manager_pid()
+
+ # Gracefully exiting the session manager causes the user's session to end.
+ utils.system('pkill -TERM -o ^%s$' % chromeos_constants.SESSION_MANAGER)
+
site_utils.poll_for_condition(
- lambda: not logged_in(),
- TimeoutError('Timed out while waiting for logout'),
- timeout=timeout)
+ lambda: __session_manager_restarted(oldpid),
+ TimeoutError('Timed out waiting for logout'),
+ timeout)
def wait_for_browser(timeout=10):
@@ -118,8 +182,8 @@
TimeoutError: xscreensaver didn't respond before timeout
"""
site_utils.poll_for_condition(
- lambda: os.system(
- site_ui.xcommand('xscreensaver-command -version')) == 0,
+ lambda: site_ui.xsystem('xscreensaver-command -version',
+ ignore_status=True) == 0,
TimeoutError('Timed out waiting for xscreensaver to respond'),
timeout=timeout)
diff --git a/client/bin/site_ui_test.py b/client/bin/site_ui_test.py
index e860877..33737cb 100644
--- a/client/bin/site_ui_test.py
+++ b/client/bin/site_ui_test.py
@@ -2,33 +2,166 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+from autotest_lib.client.bin import chromeos_constants
from autotest_lib.client.bin import site_login, test as bin_test
-from autotest_lib.client.common_lib import error
+from autotest_lib.client.common_lib import error, site_ui
class UITest(bin_test.test):
- """
- Tests that require the user to be logged in should subclass this test
- This script by default logs in using the default remote account, however,
- tests can override this by setting script="your_script" in the control
- file running the test
+ """Base class for tests that drive some portion of the user interface.
+
+ By default subclasses will use the default remote credentials before
+ the run_once method is invoked, and will log out at the completion
+ of the test case even if an exception is thrown.
+
+ Subclasses can opt out of the automatic login by setting the member
+ variable 'auto_login' to False.
+
+ Subclasses can log in with arbitrary credentials by passing
+ the 'creds' parameter in their control file. See the documentation of
+ UITest.initialize for more details.
+
+ If your subclass overrides the initialize() or cleanup() methods, it
+ should make sure to invoke this class' version of those methods as well.
+ The standard super(...) function cannot be used for this, since the base
+ test class is not a 'new style' Python class.
"""
version = 1
-
- def setup(self):
- site_login.setup_autox(self)
+ auto_login = True
+ username = None
+ password = None
- def initialize(self, script='autox_script.json'):
- # Clean up past state and assume logged out before logging in.
+ def __is_screensaver(self, status):
+ """Returns True if xscreensaver reports a matching status.
+
+ This function matches the output of `xscreensaver -time` against the
+ specified status. It does no sanity checking or framing of the status
+ value, so use with caution.
+
+ Args:
+ status: String representing the status to match against.
+ """
+ return self.xsystem('xscreensaver-command -time | ' +
+ 'egrep -q "%s"' % status, ignore_status=True) == 0
+
+
+ def is_screensaver_locked(self):
+ """Returns True if the screensaver is locked, false otherwise.
+
+ The screensaver has more than two potential states, do not assume
+ that the screensaver is completely deactivated if this returns False,
+ use is_screensaver_unlocked() for that.
+ """
+ return self.__is_screensaver('locked|no saver status')
+
+
+ def is_screensaver_unlocked(self):
+ """Returns True if the screensaver is unlocked, false otherwise.
+
+ The screensaver has more than two potential states, do not assume
+ that the screensaver is completely locked if this returns False,
+ use is_screensaver_locked() for that.
+ """
+ return self.__is_screensaver('non-blanked')
+
+
+ def xsystem(self, cmd, timeout=None, ignore_status=False):
+ """Convenience wrapper around site_ui.xsystem, to save you an import.
+ """
+ return site_ui.xsystem(cmd, timeout, ignore_status)
+
+
+ def wait_for_screensaver(self, timeout=10):
+ """Convenience wrapper around site_login.wait_for_screensaver, to save
+ you an import.
+ """
+ site_login.wait_for_screensaver(timeout=timeout)
+
+
+ def initialize(self, creds='$default'):
+ """Overridden from test.initialize() to log out and (maybe) log in.
+
+ If self.auto_login is True, this will automatically log in using the
+ credentials specified by 'creds' at startup, otherwise login will not
+ happen.
+
+ Regardless of the state of self.auto_login, the self.username and
+ self.password properties will be set to the credentials specified
+ by 'creds'.
+
+ Args:
+ creds: String specifying the credentials for this test case. Can
+ be a named set of credentials as defined by
+ chromeos_constants.CREDENTIALS, or a 'username:password' pair.
+ Defaults to '$default'.
+ """
if site_login.logged_in():
site_login.attempt_logout()
- # Test account information embedded into json file.
- site_login.attempt_login(self, script)
- site_login.wait_for_initial_chrome_window()
+ (self.username, self.password) = self.__resolve_creds(creds)
+
+ if self.auto_login:
+ self.login(self.username, self.password)
+
+
+ def __resolve_creds(self, creds):
+ if creds[0] == '$':
+ if creds not in chromeos_constants.CREDENTIALS:
+ raise error.TestFail('Unknown credentials: %s' % creds)
+
+ return chromeos_constants.CREDENTIALS[creds]
+
+ return creds.split(':')
+
+
+ def login(self, username=None, password=None):
+ """Log in with a set of credentials.
+
+ Args:
+ username: String representing the username to log in as, defaults
+ to self.username.
+ password: String representing the password to log in with, defaults
+ to self.password.
+
+ This method is called from UITest.initialize(), so you won't need it
+ unless your testcase has cause to log in multiple times. This
+ DOES NOT affect self.username or self.password.
+
+ Forces a log out if the test is already logged in.
+
+ Raises:
+ Exceptions raised by site_login.attempt_login
+ """
+
+ if site_login.logged_in():
+ site_login.attempt_logout(timeout=10)
+
+ site_login.attempt_login(username or self.username,
+ password or self.password)
+
+
+ def logout(self):
+ """Log out.
+
+ This method is called from UITest.cleanup(), so you won't need it
+ unless your testcase needs to test functionality while logged out.
+ """
+ site_login.attempt_logout()
+
+
+ def get_autox(self):
+ """Return a new autox instance.
+
+ Explicitly cache this in your testcase if you want to reuse the
+ object, but beware that logging out will invalidate any existing
+ sessions.
+ """
+ return site_ui.get_autox()
def cleanup(self):
- """Logs out when object is deleted"""
- site_login.attempt_logout()
+ """Overridden from test.cleanup() to log out when the test is complete.
+ """
+ if site_login.logged_in():
+ self.logout()
diff --git a/client/bin/site_utils.py b/client/bin/site_utils.py
index 50a0bdf..2e3caf3 100644
--- a/client/bin/site_utils.py
+++ b/client/bin/site_utils.py
@@ -6,23 +6,35 @@
from autotest_lib.client.common_lib import error
+class TimeoutError(error.TestError):
+ """Error raised when we time out when waiting on a condition."""
+
+
def poll_for_condition(
- condition, exception=None, timeout=10, sleep_interval=0.1):
+ condition, exception=None, timeout=10, sleep_interval=0.1, desc=None):
"""Poll until a condition becomes true.
condition: function taking no args and returning bool
exception: exception to throw if condition doesn't become true
timeout: maximum number of seconds to wait
sleep_interval: time to sleep between polls
+ desc: description of default TimeoutError used if 'exception' is None
Raises:
- 'exception' arg if supplied; error.TestError otherwise
+ 'exception' arg if supplied; site_utils.TimeoutError otherwise
"""
start_time = time.time()
while True:
if condition():
return
if time.time() + sleep_interval - start_time > timeout:
- raise exception if exception else error.TestError(
- 'Timed out waiting for condition')
+ if exception:
+ raise exception
+
+ if desc:
+ desc = 'Timed out waiting for condition: %s' % desc
+ else:
+ desc = 'Timed out waiting for unnamed condition'
+ raise error.TestError(desc)
+
time.sleep(sleep_interval)
diff --git a/client/common_lib/site_ui.py b/client/common_lib/site_ui.py
index ffc515e..bdd0b35 100644
--- a/client/common_lib/site_ui.py
+++ b/client/common_lib/site_ui.py
@@ -2,7 +2,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
-import logging, shutil
+import logging, os, shutil
from autotest_lib.client.common_lib import site_httpd, utils
@@ -44,6 +44,16 @@
ignore_status=ignore_status)
+def get_autox():
+ """Return a new autox instance."""
+ # we're running as root, but need to connect to chronos' X session
+ os.environ.setdefault('XAUTHORITY', '/home/chronos/.Xauthority')
+ os.environ.setdefault('DISPLAY', ':0.0')
+
+ import autox
+ return autox.AutoX()
+
+
class ChromeSession(object):
"""
A class to start and close Chrome sessions.
diff --git a/client/deps/autox/README b/client/deps/autox/README
deleted file mode 100644
index dfaa0d4..0000000
--- a/client/deps/autox/README
+++ /dev/null
@@ -1,8 +0,0 @@
-# Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-This deps brings install ChromeOS autox into an image. Tests that depend
-on autox should add this as a dep in the setup. It leverages the
-Chrome OS build system and installs the debian package that gets created
-for autox.
\ No newline at end of file
diff --git a/client/deps/autox/autox.py b/client/deps/autox/autox.py
deleted file mode 100755
index 21a863e..0000000
--- a/client/deps/autox/autox.py
+++ /dev/null
@@ -1,17 +0,0 @@
-#!/usr/bin/python
-
-# Copyright (c) 2010 The Chromium OS 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 common, commands, logging, os, shutil
-from autotest_lib.client.bin import utils
-
-version = 1
-
-def setup(top_dir):
- autox_bin = os.environ['SYSROOT'] + '/usr/bin/autox'
- shutil.copyfile(autox_bin, top_dir + '/autox')
-
-pwd = os.getcwd()
-utils.update_version(pwd + '/src', False, version, setup, pwd)
diff --git a/client/deps/autox/common.py b/client/deps/autox/common.py
deleted file mode 100644
index ac26b5d..0000000
--- a/client/deps/autox/common.py
+++ /dev/null
@@ -1,12 +0,0 @@
-# Copyright (c) 2010 The Chromium OS 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 os, sys
-dirname = os.path.dirname(sys.modules[__name__].__file__)
-client_dir = os.path.abspath(os.path.join(dirname, "../../"))
-sys.path.insert(0, client_dir)
-import setup_modules
-sys.path.pop(0)
-setup_modules.setup(base_path=client_dir,
- root_module_name="autotest_lib.client")
diff --git a/client/deps/autox/control b/client/deps/autox/control
deleted file mode 100644
index 86b2577..0000000
--- a/client/deps/autox/control
+++ /dev/null
@@ -1,5 +0,0 @@
-# Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-job.setup_dep(['autox'])
diff --git a/client/site_tests/desktopui_DoLogin/control b/client/site_tests/desktopui_DoLogin/control
index 8f54890..0c71020 100644
--- a/client/site_tests/desktopui_DoLogin/control
+++ b/client/site_tests/desktopui_DoLogin/control
@@ -13,5 +13,5 @@
This is a helper test that will login a system through the login manager
"""
-job.run_test('desktopui_DoLogin', script='autox_script.json', tag='remote')
-job.run_test('desktopui_DoLogin', script='backdoor_creds.json', tag='local')
+job.run_test('desktopui_DoLogin', tag='remote')
+job.run_test('desktopui_DoLogin', creds='$backdoor', tag='local')
diff --git a/client/site_tests/desktopui_DoLogin/desktopui_DoLogin.py b/client/site_tests/desktopui_DoLogin/desktopui_DoLogin.py
index 487bba6..49ec782 100644
--- a/client/site_tests/desktopui_DoLogin/desktopui_DoLogin.py
+++ b/client/site_tests/desktopui_DoLogin/desktopui_DoLogin.py
@@ -7,7 +7,7 @@
class desktopui_DoLogin(site_ui_test.UITest):
version = 1
-
- def run_once(self):
- time.sleep(10) # Local login is so fast, it needs to be slowed down.
\ No newline at end of file
+
+ def run_once(self):
+ time.sleep(10) # Local login is so fast, it needs to be slowed down.
diff --git a/client/site_tests/desktopui_FailedLogin/desktopui_FailedLogin.py b/client/site_tests/desktopui_FailedLogin/desktopui_FailedLogin.py
index 594c206..ce4b2f3 100644
--- a/client/site_tests/desktopui_FailedLogin/desktopui_FailedLogin.py
+++ b/client/site_tests/desktopui_FailedLogin/desktopui_FailedLogin.py
@@ -3,28 +3,19 @@
# found in the LICENSE file.
import os, time
-from autotest_lib.client.bin import site_login, test
+from autotest_lib.client.bin import site_ui_test, site_login
from autotest_lib.client.common_lib import error
-class desktopui_FailedLogin(test.test):
+class desktopui_FailedLogin(site_ui_test.UITest):
version = 1
- def setup(self):
- site_login.setup_autox(self)
+ auto_login = False
- def run_once(self, script):
- # Can't test login while logged in, so logout.
- if site_login.logged_in():
- site_login.attempt_logout()
-
- # Test account information embedded into json file.
+ def run_once(self):
# TODO(cmasone): find better way to determine login has failed.
try:
- site_login.attempt_login(self, script)
+ self.login('bogus@bogus.gmail.com', 'bogus')
except site_login.TimeoutError:
pass
else:
raise error.TestFail('Should not have logged in')
-
- # Re-set to a good state
- site_login.nuke_login_manager()
diff --git a/client/site_tests/desktopui_ScreenSaverUnlock/desktopui_ScreenSaverUnlock.py b/client/site_tests/desktopui_ScreenSaverUnlock/desktopui_ScreenSaverUnlock.py
index 1ee7c77..30b0c78 100644
--- a/client/site_tests/desktopui_ScreenSaverUnlock/desktopui_ScreenSaverUnlock.py
+++ b/client/site_tests/desktopui_ScreenSaverUnlock/desktopui_ScreenSaverUnlock.py
@@ -2,32 +2,31 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
-import logging, os, time, utils
-from autotest_lib.client.bin import site_login, site_ui_test, test
-from autotest_lib.client.common_lib import error
-from autotest_lib.client.bin import chromeos_constants
+import time
+from autotest_lib.client.bin import site_ui_test, site_utils
+
class desktopui_ScreenSaverUnlock(site_ui_test.UITest):
version = 1
- def system_as(self, cmd, user='chronos'):
- utils.system('su %s -c \'%s\'' % (user, cmd))
def run_once(self):
- site_login.wait_for_screensaver()
- self.system_as('DISPLAY=:0.0 xscreensaver-command -lock')
+ self.wait_for_screensaver()
+ self.xsystem('xscreensaver-command -lock')
- # some sleep to let the screen lock
- # TODO: Sleeping is unreliable and slow. Do something better to
- # wait for the screen to be locked.
- time.sleep(5)
- self.system_as('DISPLAY=:0.0 xscreensaver-command -time | ' +
- 'grep -q locked')
+ site_utils.poll_for_condition(
+ lambda: self.is_screensaver_locked(),
+ desc='screensaver lock')
- time.sleep(10)
- site_login.attempt_login(self, 'autox_unlock.json')
+ ax = self.get_autox()
+ ax.send_hotkey('Return')
+ # wait for the screensaver to wakeup and present the login dialog
+ # TODO: a less brittle way to do this would be nice
+ time.sleep(2)
+ ax.send_text(self.password)
+ ax.send_hotkey('Return')
# wait for screen to unlock
- time.sleep(5)
- self.system_as('DISPLAY=:0.0 xscreensaver-command -time | ' +
- 'grep -q non-blanked')
+ site_utils.poll_for_condition(
+ lambda: self.is_screensaver_unlocked(),
+ desc='screensaver unlock')
diff --git a/client/site_tests/desktopui_WindowManagerFocusNewWindows/desktopui_WindowManagerFocusNewWindows.py b/client/site_tests/desktopui_WindowManagerFocusNewWindows/desktopui_WindowManagerFocusNewWindows.py
index cddf505..e5b18f2 100644
--- a/client/site_tests/desktopui_WindowManagerFocusNewWindows/desktopui_WindowManagerFocusNewWindows.py
+++ b/client/site_tests/desktopui_WindowManagerFocusNewWindows/desktopui_WindowManagerFocusNewWindows.py
@@ -44,12 +44,7 @@
'Timed out on condition: %s' % exception.__str__())
def run_once(self):
- import autox
-
- # TODO: Set these in a single, standard place for all tests.
- os.environ['DISPLAY'] = ':0'
- os.environ['XAUTHORITY'] = '/home/chronos/.Xauthority'
- self.autox = autox.AutoX()
+ self.autox = self.get_autox()
# Create a window and check that we switch to it.
win = self.autox.create_and_map_window(
diff --git a/client/site_tests/desktopui_WindowManagerHotkeys/desktopui_WindowManagerHotkeys.py b/client/site_tests/desktopui_WindowManagerHotkeys/desktopui_WindowManagerHotkeys.py
index 0048b15..08edd8a 100644
--- a/client/site_tests/desktopui_WindowManagerHotkeys/desktopui_WindowManagerHotkeys.py
+++ b/client/site_tests/desktopui_WindowManagerHotkeys/desktopui_WindowManagerHotkeys.py
@@ -10,12 +10,7 @@
version = 1
def run_once(self):
- import autox
-
- # TODO: Set these in a single, standard place for all tests.
- os.environ['DISPLAY'] = ':0'
- os.environ['XAUTHORITY'] = '/home/chronos/.Xauthority'
- ax = autox.AutoX()
+ ax = self.get_autox()
# Start a terminal and wait for it to get the focus.
# TODO: This is a bit of a hack. To watch for the terminal getting
diff --git a/client/site_tests/login_ChromeProfileSanitary/login_ChromeProfileSanitary.py b/client/site_tests/login_ChromeProfileSanitary/login_ChromeProfileSanitary.py
index 988fab6..257e35c 100644
--- a/client/site_tests/login_ChromeProfileSanitary/login_ChromeProfileSanitary.py
+++ b/client/site_tests/login_ChromeProfileSanitary/login_ChromeProfileSanitary.py
@@ -4,7 +4,7 @@
import logging, os, stat, time, utils
from autotest_lib.client.bin import chromeos_constants, site_cryptohome
-from autotest_lib.client.bin import site_login, test
+from autotest_lib.client.bin import site_login, site_ui_test
from autotest_lib.client.common_lib import error, site_httpd, site_ui
def respond_with_cookies(handler, url_args):
@@ -19,10 +19,10 @@
handler.wfile.write('%s:\n' % url_args)
-class login_ChromeProfileSanitary(test.test):
+class login_ChromeProfileSanitary(site_ui_test.UITest):
version = 1
- def __wait_for_login_profile(self, timeout = 10):
+ def __wait_for_login_profile(self, timeout=10):
start_time = time.time()
while time.time() - start_time < timeout:
if os.path.exists(chromeos_constants.LOGIN_PROFILE + '/Cookies'):
@@ -32,7 +32,7 @@
raise error.TestError('Login Profile took too long to populate')
- def initialize(self):
+ def initialize(self, creds='$default'):
spec = 'http://localhost:8000'
path = '/set_cookie'
self._wait_path = '/test_over'
@@ -41,22 +41,15 @@
self._testServer.add_url_handler('/set_cookie', respond_with_cookies)
self._testServer.run()
-
- def setup(self):
- site_login.setup_autox(self)
+ site_ui_test.UITest.initialize(self, creds)
def cleanup(self):
self._testServer.stop()
+ site_ui_test.UITest.cleanup(self)
- def run_once(self, script = 'autox_script.json', timeout = 10):
- logged_in = site_login.logged_in()
-
- if not logged_in:
- # Test account information embedded into json file.
- site_login.attempt_login(self, script)
-
+ def run_once(self, timeout = 10):
# Get Default/Cookies mtime.
cookies_info = os.stat(chromeos_constants.LOGIN_PROFILE + '/Cookies')
cookies_mtime = cookies_info[stat.ST_MTIME]
@@ -78,8 +71,8 @@
latch.wait(timeout)
# Ensure chrome writes state to disk.
- site_login.attempt_logout()
- site_login.attempt_login(self, script)
+ self.logout()
+ self.login()
if not latch.is_set():
raise error.TestError('Never received callback from browser.')
@@ -91,7 +84,3 @@
# do so until http://crosbug.com/1967 is fixed.
if cookies_mtime != cookies_info[stat.ST_MTIME]:
raise error.TestFail('Cookies in Default profile changed!')
-
- # If we started logged out, log back out.
- if not logged_in:
- site_login.attempt_logout()
diff --git a/client/site_tests/login_CryptohomeUnmounted/login_CryptohomeUnmounted.py b/client/site_tests/login_CryptohomeUnmounted/login_CryptohomeUnmounted.py
index 4fbca86..10c3bf7 100644
--- a/client/site_tests/login_CryptohomeUnmounted/login_CryptohomeUnmounted.py
+++ b/client/site_tests/login_CryptohomeUnmounted/login_CryptohomeUnmounted.py
@@ -3,32 +3,18 @@
# found in the LICENSE file.
import os, time
-from autotest_lib.client.bin import site_cryptohome, site_login, test
+from autotest_lib.client.bin import site_cryptohome, site_ui_test
from autotest_lib.client.common_lib import error
-class login_CryptohomeUnmounted(test.test):
+class login_CryptohomeUnmounted(site_ui_test.UITest):
version = 1
- def setup(self):
- site_login.setup_autox(self)
-
- def run_once(self, script = 'autox_script.json', is_control = False):
- logged_in = site_login.logged_in()
-
- # Require that the cryptohome is mounted before testing that
- # logging out will unmount it. This requires logging in.
- if not logged_in:
- site_login.attempt_login(self, script)
-
+ def run_once(self, is_control=False):
if not site_cryptohome.is_mounted(allow_fail = is_control):
raise error.TestFail('Expected cryptohome to be mounted')
- site_login.attempt_logout()
+ self.logout()
# allow the command to fail, so we can handle the error here
if site_cryptohome.is_mounted(allow_fail = True):
raise error.TestFail('Expected cryptohome NOT to be mounted')
-
- # If we started logged in, reset the state.
- if logged_in:
- site_login.attempt_login(self, script)
diff --git a/client/site_tests/login_LogoutProcessCleanup/login_LogoutProcessCleanup.py b/client/site_tests/login_LogoutProcessCleanup/login_LogoutProcessCleanup.py
index bc5180c..16e4b80 100644
--- a/client/site_tests/login_LogoutProcessCleanup/login_LogoutProcessCleanup.py
+++ b/client/site_tests/login_LogoutProcessCleanup/login_LogoutProcessCleanup.py
@@ -3,10 +3,10 @@
# found in the LICENSE file.
import logging, os, time, utils
-from autotest_lib.client.bin import site_login, test
+from autotest_lib.client.bin import site_ui_test
from autotest_lib.client.common_lib import error
-class login_LogoutProcessCleanup(test.test):
+class login_LogoutProcessCleanup(site_ui_test.UITest):
version = 1
def __get_session_manager_pid(self):
@@ -79,18 +79,7 @@
return False
- def setup(self):
- site_login.setup_autox(self)
-
-
- def run_once(self, script='autox_script.json', is_control=False,
- timeout=10):
- logged_in = site_login.logged_in()
-
- # Require that we start the test logged in
- if not logged_in:
- site_login.attempt_login(self, script)
-
+ def run_once(self, is_control=False, timeout=10):
# Start a process as chronos. This should get killed when logging out.
bg_job = utils.BgJob('su chronos -c "sleep 3600"')
@@ -102,7 +91,7 @@
raise error.TestFail('Expected to find processes owned by chronos '
'that were not started by the session manager while logged in.')
- site_login.attempt_logout()
+ self.logout()
logging.info('Logged out, searching for processes that should be dead')
@@ -120,7 +109,3 @@
raise error.TestFail('Expected NOT to find processes owned by '
'chronos that were not started by the session manager '
'while logged out.')
-
- # Reset the logged in state to how we started
- if logged_in:
- site_login.attempt_login(self, script)
diff --git a/client/site_tests/platform_ProcessPrivileges/platform_ProcessPrivileges.py b/client/site_tests/platform_ProcessPrivileges/platform_ProcessPrivileges.py
index a4d9927..8cbbc02 100644
--- a/client/site_tests/platform_ProcessPrivileges/platform_ProcessPrivileges.py
+++ b/client/site_tests/platform_ProcessPrivileges/platform_ProcessPrivileges.py
@@ -3,15 +3,13 @@
# found in the LICENSE file.
import time
-from autotest_lib.client.bin import site_login, test, utils
+from autotest_lib.client.bin import site_login, site_ui_test, utils
from autotest_lib.client.common_lib import error
-class platform_ProcessPrivileges(test.test):
+class platform_ProcessPrivileges(site_ui_test.UITest):
version = 1
- def setup(self):
- site_login.setup_autox(self)
-
+ auto_login = False
def run_once(self, process='X', user=None, run_as_root=False,
do_login=False, any=False):
@@ -24,67 +22,58 @@
do_login: login before getting process information?
any: Test succeeds if any of processes satisfy the conditions.
"""
- logged_in = site_login.logged_in()
-
- if do_login and not logged_in:
- # Test account information embedded into json file.
- site_login.attempt_login(self, 'autox_script.json')
+ if do_login:
+ self.login()
# Wait for processes for user-session are started.
time.sleep(10)
- try:
- # Get the process information
- pscmd = 'ps -o f,euser,ruser,suser,fuser,comm -C %s --no-headers'
- ps = utils.system_output(pscmd % process, retain_output=True)
+ # Get the process information
+ pscmd = 'ps -o f,euser,ruser,suser,fuser,comm -C %s --no-headers'
+ ps = utils.system_output(pscmd % process, retain_output=True)
- pslines = ps.splitlines()
+ pslines = ps.splitlines()
- # Fail if process is not running
- if not len(pslines):
- raise error.TestFail('Process %s is not running' % process)
+ # Fail if process is not running
+ if not len(pslines):
+ raise error.TestFail('Process %s is not running' % process)
- # Check all instances of the process
- for psline in pslines:
- ps = psline.split()
+ # Check all instances of the process
+ for psline in pslines:
+ ps = psline.split()
- # Assume process meets conditions until proven otherwise
- user_satisfied = True
- run_as_root_satisfied = True
+ # Assume process meets conditions until proven otherwise
+ user_satisfied = True
+ run_as_root_satisfied = True
- # Fail if not running as the specified user
- if user is not None:
- for uid in ps[1:5]:
- if uid != user:
- if any:
- user_satisfied = False
- break
- raise error.TestFail(
- 'Process %s running as %s; expected %s' %
- (process, uid, user))
-
- # Check if process has super-user privileges
- if not run_as_root:
- # TODO(yusukes): Uncomment this once issue 2253 is resolved
- # if int(ps[0]) & 0x04:
- # raise error.TestFail(
- # 'Process %s running with super-user flag' %
- # process)
- if 'root' in ps:
+ # Fail if not running as the specified user
+ if user is not None:
+ for uid in ps[1:5]:
+ if uid != user:
if any:
- run_as_root_satisfied = False
- continue
+ user_satisfied = False
+ break
raise error.TestFail(
- 'Process %s running as root' % process)
+ 'Process %s running as %s; expected %s' %
+ (process, uid, user))
- # Check if conditions are met for "any" mode.
- if any and user_satisfied and run_as_root_satisfied:
- break
- else:
- if any:
+ # Check if process has super-user privileges
+ if not run_as_root:
+ # TODO(yusukes): Uncomment this once issue 2253 is resolved
+ # if int(ps[0]) & 0x04:
+ # raise error.TestFail(
+ # 'Process %s running with super-user flag' %
+ # process)
+ if 'root' in ps:
+ if any:
+ run_as_root_satisfied = False
+ continue
raise error.TestFail(
- 'Conditions are not met for any process %s' % process)
+ 'Process %s running as root' % process)
- finally:
- # If we started logged out, log back out.
- if do_login and not logged_in:
- site_login.attempt_logout()
+ # Check if conditions are met for "any" mode.
+ if any and user_satisfied and run_as_root_satisfied:
+ break
+ else:
+ if any:
+ raise error.TestFail(
+ 'Conditions are not met for any process %s' % process)