Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(85)

Side by Side Diff: client/site_tests/desktopui_WindowManagerHotkeys/desktopui_WindowManagerHotkeys.py

Issue 1565001: test: Clean up site_login.py a bit. (Closed)
Patch Set: update one more call to attempt_logout() Created 10 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import os, random, time 5 import os, random, time
6 from autotest_lib.client.bin import site_login, test 6 from autotest_lib.client.bin import site_ui_test, site_utils, test
7 from autotest_lib.client.common_lib import error 7 from autotest_lib.client.common_lib import error
8 8
9 class desktopui_WindowManagerHotkeys(test.test): 9 class desktopui_WindowManagerHotkeys(site_ui_test.UITest):
10 version = 1 10 version = 1
11 11
12 def setup(self):
13 site_login.setup_autox(self)
14
15 # TODO: This would be useful for other tests; put it somewhere else.
16 def __poll_for_condition(
17 self, condition, desc='', timeout=10, sleep_interval=0.1):
18 """Poll until a condition becomes true.
19
20 condition: function taking no args and returning bool
21 desc: str description of the condition
22 timeout: maximum number of seconds to wait
23 sleep_interval: time to sleep between polls
24
25 Raises:
26 error.TestFail: if the condition doesn't become true
27 """
28 start_time = time.time()
29 while True:
30 if condition():
31 return
32 if time.time() + sleep_interval - start_time > timeout:
33 raise error.TestFail(
34 'Timed out waiting for condition: %s' % desc)
35 time.sleep(sleep_interval)
36
37 def run_once(self): 12 def run_once(self):
38 import autox 13 import autox
39 14
40 # TODO: This should be abstracted out.
41 if not site_login.logged_in():
42 if not site_login.attempt_login(self, 'autox_script.json'):
43 raise error.TestError('Could not log in')
44 if not site_login.wait_for_window_manager():
45 raise error.TestError('Window manager didn\'t start')
46 # TODO: This is awful. We need someone (Chrome, the WM, etc.) to
47 # announce when login is "done" -- that is, the initial Chrome
48 # window isn't going to pop onscreen in the middle of the test.
49 # For now, we just sleep a really long time.
50 time.sleep(20)
51
52 # TODO: Set these in a single, standard place for all tests. 15 # TODO: Set these in a single, standard place for all tests.
53 os.environ['DISPLAY'] = ':0' 16 os.environ['DISPLAY'] = ':0'
54 os.environ['XAUTHORITY'] = '/home/chronos/.Xauthority' 17 os.environ['XAUTHORITY'] = '/home/chronos/.Xauthority'
55 ax = autox.AutoX() 18 ax = autox.AutoX()
56 19
57 # Start a terminal and wait for it to get the focus. 20 # Start a terminal and wait for it to get the focus.
58 # TODO: This is a bit of a hack. To watch for the terminal getting 21 # TODO: This is a bit of a hack. To watch for the terminal getting
59 # the focus, we create a new window, wait for it to get the focus, 22 # the focus, we create a new window, wait for it to get the focus,
60 # and then launch the terminal and wait for our window to lose the 23 # and then launch the terminal and wait for our window to lose the
61 # focus (AutoX isn't notified about focus events on the terminal 24 # focus (AutoX isn't notified about focus events on the terminal
62 # window itself). It's maybe cleaner to add a method to AutoX to 25 # window itself). It's maybe cleaner to add a method to AutoX to
63 # get the currently-focused window and then just poll that after 26 # get the currently-focused window and then just poll that after
64 # starting the terminal until it changes. 27 # starting the terminal until it changes.
65 win = ax.create_and_map_window() 28 win = ax.create_and_map_window()
66 info = ax.get_window_info(win.id) 29 info = ax.get_window_info(win.id)
67 ax.await_condition( 30 ax.await_condition(
68 lambda: info.is_focused, 31 lambda: info.is_focused,
69 desc='Waiting for window to get focus') 32 desc='Waiting for window to get focus')
70 ax.send_hotkey('Ctrl-Alt-t') 33 ax.send_hotkey('Ctrl-Alt-t')
71 ax.await_condition( 34 ax.await_condition(
72 lambda: not info.is_focused, 35 lambda: not info.is_focused,
73 desc='Waiting for window to lose focus') 36 desc='Waiting for window to lose focus')
74 37
75 # Type in it to create a file in /tmp and exit. 38 # Type in it to create a file in /tmp and exit.
76 temp_filename = '/tmp/desktopup_WindowManagerHotkeys_%d' % time.time() 39 temp_filename = '/tmp/desktopup_WindowManagerHotkeys_%d' % time.time()
77 ax.send_text('touch %s\n' % temp_filename) 40 ax.send_text('touch %s\n' % temp_filename)
78 ax.send_text('exit\n') 41 ax.send_text('exit\n')
79 self.__poll_for_condition( 42 site_utils.poll_for_condition(
80 lambda: os.access(temp_filename, os.F_OK), 43 lambda: os.access(temp_filename, os.F_OK),
81 desc='Waiting for %s to be created from terminal' % temp_filename) 44 error.TestFail(
45 'Waiting for %s to be created from terminal' % temp_filename))
82 os.remove(temp_filename) 46 os.remove(temp_filename)
83 47
84 # Press the Print Screen key and check that a screenshot is written. 48 # Press the Print Screen key and check that a screenshot is written.
85 screenshot_filename = '/home/chronos/user/screenshot.png' 49 screenshot_filename = '/home/chronos/user/screenshot.png'
86 if os.access(screenshot_filename, os.F_OK): 50 if os.access(screenshot_filename, os.F_OK):
87 os.remove(screenshot_filename) 51 os.remove(screenshot_filename)
88 ax.send_hotkey('Print') 52 ax.send_hotkey('Print')
89 self.__poll_for_condition( 53 site_utils.poll_for_condition(
90 lambda: os.access(screenshot_filename, os.F_OK), 54 lambda: os.access(screenshot_filename, os.F_OK),
91 desc='Waiting for screenshot at %s' % screenshot_filename) 55 error.TestFail(
56 'Waiting for screenshot at %s' % screenshot_filename))
92 os.remove(screenshot_filename) 57 os.remove(screenshot_filename)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698