Index: client/site_tests/desktopui_WindowManagerHotkeys/desktopui_WindowManagerHotkeys.py |
diff --git a/client/site_tests/desktopui_WindowManagerHotkeys/desktopui_WindowManagerHotkeys.py b/client/site_tests/desktopui_WindowManagerHotkeys/desktopui_WindowManagerHotkeys.py |
index b8308c5828186275cfefae7a46bfa21c2ff19fdd..0048b150ae71f6d16cf080398901c47459e4f28d 100644 |
--- a/client/site_tests/desktopui_WindowManagerHotkeys/desktopui_WindowManagerHotkeys.py |
+++ b/client/site_tests/desktopui_WindowManagerHotkeys/desktopui_WindowManagerHotkeys.py |
@@ -3,52 +3,15 @@ |
# found in the LICENSE file. |
import os, random, time |
-from autotest_lib.client.bin import site_login, test |
+from autotest_lib.client.bin import site_ui_test, site_utils, test |
from autotest_lib.client.common_lib import error |
-class desktopui_WindowManagerHotkeys(test.test): |
+class desktopui_WindowManagerHotkeys(site_ui_test.UITest): |
version = 1 |
- def setup(self): |
- site_login.setup_autox(self) |
- |
- # TODO: This would be useful for other tests; put it somewhere else. |
- def __poll_for_condition( |
- self, condition, desc='', timeout=10, sleep_interval=0.1): |
- """Poll until a condition becomes true. |
- |
- condition: function taking no args and returning bool |
- desc: str description of the condition |
- timeout: maximum number of seconds to wait |
- sleep_interval: time to sleep between polls |
- |
- Raises: |
- error.TestFail: if the condition doesn't become true |
- """ |
- start_time = time.time() |
- while True: |
- if condition(): |
- return |
- if time.time() + sleep_interval - start_time > timeout: |
- raise error.TestFail( |
- 'Timed out waiting for condition: %s' % desc) |
- time.sleep(sleep_interval) |
- |
def run_once(self): |
import autox |
- # TODO: This should be abstracted out. |
- if not site_login.logged_in(): |
- if not site_login.attempt_login(self, 'autox_script.json'): |
- raise error.TestError('Could not log in') |
- if not site_login.wait_for_window_manager(): |
- raise error.TestError('Window manager didn\'t start') |
- # TODO: This is awful. We need someone (Chrome, the WM, etc.) to |
- # announce when login is "done" -- that is, the initial Chrome |
- # window isn't going to pop onscreen in the middle of the test. |
- # For now, we just sleep a really long time. |
- time.sleep(20) |
- |
# TODO: Set these in a single, standard place for all tests. |
os.environ['DISPLAY'] = ':0' |
os.environ['XAUTHORITY'] = '/home/chronos/.Xauthority' |
@@ -76,9 +39,10 @@ class desktopui_WindowManagerHotkeys(test.test): |
temp_filename = '/tmp/desktopup_WindowManagerHotkeys_%d' % time.time() |
ax.send_text('touch %s\n' % temp_filename) |
ax.send_text('exit\n') |
- self.__poll_for_condition( |
+ site_utils.poll_for_condition( |
lambda: os.access(temp_filename, os.F_OK), |
- desc='Waiting for %s to be created from terminal' % temp_filename) |
+ error.TestFail( |
+ 'Waiting for %s to be created from terminal' % temp_filename)) |
os.remove(temp_filename) |
# Press the Print Screen key and check that a screenshot is written. |
@@ -86,7 +50,8 @@ class desktopui_WindowManagerHotkeys(test.test): |
if os.access(screenshot_filename, os.F_OK): |
os.remove(screenshot_filename) |
ax.send_hotkey('Print') |
- self.__poll_for_condition( |
+ site_utils.poll_for_condition( |
lambda: os.access(screenshot_filename, os.F_OK), |
- desc='Waiting for screenshot at %s' % screenshot_filename) |
+ error.TestFail( |
+ 'Waiting for screenshot at %s' % screenshot_filename)) |
os.remove(screenshot_filename) |