OLD | NEW |
---|---|
(Empty) | |
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 | |
3 # found in the LICENSE file. | |
4 | |
5 import os, time | |
6 from autotest_lib.client.bin import site_login, test | |
7 from autotest_lib.client.common_lib import error | |
8 | |
9 class desktopui_WindowManagerFocusNewWindows(test.test): | |
10 version = 1 | |
11 | |
12 def setup(self): | |
13 site_login.setup_autox(self) | |
14 | |
15 def __check_active_window(self, id, info): | |
16 """Check that a particular window is active. | |
17 | |
18 Args: | |
19 id: int window ID | |
20 info: AutoX.WindowInfo object corresponding to 'id' | |
21 | |
22 Raises: | |
23 error.TestFail: if a condition timed out | |
24 """ | |
25 try: | |
26 self.autox.await_condition( | |
27 lambda: info.is_focused, | |
28 desc='Waiting for window 0x%x to be focused' % id) | |
29 self.autox.await_condition( | |
30 lambda: self.autox.get_active_window_property() == id, | |
31 desc='Waiting for _NET_ACTIVE_WINDOW to contain 0x%x' % id) | |
32 | |
33 # get_geometry() returns a tuple, so we need to construct a tuple to | |
34 # compare against it. | |
35 fullscreen_dimensions = \ | |
36 tuple([0, 0] + list(self.autox.get_screen_size())) | |
37 self.autox.await_condition( | |
38 lambda: info.get_geometry() == fullscreen_dimensions, | |
39 desc='Waiting for window 0x%x to fill the screen' % id) | |
40 | |
41 self.autox.await_condition( | |
42 lambda: self.autox.get_top_window_id_at_point(200, 200) == id, | |
43 desc='Waiting for window 0x%x to be on top' % id) | |
44 | |
45 except self.autox.ConditionTimeoutError as exception: | |
46 raise error.TestFail( | |
47 'Timed out on condition: %s' % exception.__str__()) | |
48 | |
49 def run_once(self): | |
50 import autox | |
51 | |
52 # TODO: This should be abstracted out. | |
53 if not site_login.logged_in(): | |
54 if not site_login.attempt_login(self, 'autox_script.json'): | |
55 raise error.TestError('Could not log in') | |
56 if not site_login.wait_for_window_manager(): | |
57 raise error.TestError('Window manager didn\'t start') | |
58 # TODO: This is awful. We need someone (Chrome, the WM, etc.) to | |
59 # announce when login is "done" -- that is, the initial Chrome | |
60 # window isn't going to pop onscreen in the middle of the test. | |
61 # For now, we just sleep a really long time. | |
Daniel Erat
2010/03/26 01:27:00
I opened http://crosbug.com/2264 to track this.
kmixter1
2010/03/26 02:30:08
Can we just wait for cryptohome to be mounted or i
| |
62 time.sleep(20) | |
63 | |
64 # TODO: Set these in a single, standard place for all tests. | |
Chris Masone
2010/03/26 07:03:44
Perhaps autox.AutoX() can do it, and take params f
| |
65 os.environ['DISPLAY'] = ':0' | |
66 os.environ['XAUTHORITY'] = '/home/chronos/.Xauthority' | |
67 self.autox = autox.AutoX() | |
68 | |
69 # Create a window and check that we switch to it. | |
70 win = self.autox.create_and_map_window( | |
71 width=200, height=200, title='test') | |
72 info = self.autox.get_window_info(win.id) | |
73 self.__check_active_window(win.id, info) | |
74 | |
75 # Create a second window. | |
76 win2 = self.autox.create_and_map_window( | |
77 width=200, height=200, title='test 2') | |
78 info2 = self.autox.get_window_info(win2.id) | |
79 self.__check_active_window(win2.id, info2) | |
80 | |
81 # Cycle backwards to the first window. | |
82 self.autox.send_hotkey('Alt-Shift-Tab') | |
83 self.__check_active_window(win.id, info) | |
84 | |
85 # Cycle forwards to the second window. | |
86 self.autox.send_hotkey('Alt-Tab') | |
87 self.__check_active_window(win2.id, info2) | |
88 | |
89 # Now destroy the second window and check that the WM goes back | |
90 # to the first window. | |
91 win2.destroy() | |
92 self.__check_active_window(win.id, info) | |
OLD | NEW |