OLD | NEW |
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 dbus, logging, os, shutil, socket, sys, time | 5 import dbus, logging, os, shutil, socket, sys, time |
6 from autotest_lib.client.bin import chromeos_constants | 6 from autotest_lib.client.bin import chromeos_constants |
7 from autotest_lib.client.bin import site_login, site_utils, test as bin_test | 7 from autotest_lib.client.bin import site_login, site_utils, test as bin_test |
8 from autotest_lib.client.common_lib import error, site_ui | 8 from autotest_lib.client.common_lib import error, site_ui |
9 from autotest_lib.client.common_lib import site_auth_server, site_dns_server | 9 from autotest_lib.client.common_lib import site_auth_server, site_dns_server |
| 10 from dbus.mainloop.glib import DBusGMainLoop |
10 | 11 |
11 # Workaround so flimflam.py doesn't need to be installed in the chroot. | 12 # Workaround so flimflam.py doesn't need to be installed in the chroot. |
12 sys.path.append(os.environ.get('SYSROOT', '') + '/usr/lib/flimflam/test') | 13 sys.path.append(os.environ.get('SYSROOT', '') + '/usr/lib/flimflam/test') |
13 # NB: /usr/local is temporary for compatibility | 14 # NB: /usr/local is temporary for compatibility |
14 sys.path.append(os.environ.get('SYSROOT', '') + '/usr/local/lib/flimflam/test') | 15 sys.path.append(os.environ.get('SYSROOT', '') + '/usr/local/lib/flimflam/test') |
15 import flimflam | 16 import flimflam |
16 | 17 |
17 | 18 |
18 class UITest(bin_test.test): | 19 class UITest(bin_test.test): |
19 """Base class for tests that drive some portion of the user interface. | 20 """Base class for tests that drive some portion of the user interface. |
(...skipping 17 matching lines...) Expand all Loading... |
37 version = 1 | 38 version = 1 |
38 | 39 |
39 auto_login = True | 40 auto_login = True |
40 username = None | 41 username = None |
41 password = None | 42 password = None |
42 | 43 |
43 def __init__(self, job, bindir, outputdir): | 44 def __init__(self, job, bindir, outputdir): |
44 self._dns = {} # for saving/restoring dns entries | 45 self._dns = {} # for saving/restoring dns entries |
45 bin_test.test.__init__(self, job, bindir, outputdir) | 46 bin_test.test.__init__(self, job, bindir, outputdir) |
46 | 47 |
47 def __is_screensaver(self, status): | |
48 """Returns True if xscreensaver reports a matching status. | |
49 | |
50 This function matches the output of `xscreensaver -time` against the | |
51 specified status. It does no sanity checking or framing of the status | |
52 value, so use with caution. | |
53 | |
54 Args: | |
55 status: String representing the status to match against. | |
56 """ | |
57 return self.xsystem('xscreensaver-command -time | ' + | |
58 'egrep -q "%s"' % status, ignore_status=True) == 0 | |
59 | |
60 | |
61 def is_screensaver_locked(self): | |
62 """Returns True if the screensaver is locked, false otherwise. | |
63 | |
64 The screensaver has more than two potential states, do not assume | |
65 that the screensaver is completely deactivated if this returns False, | |
66 use is_screensaver_unlocked() for that. | |
67 """ | |
68 return self.__is_screensaver('locked|no saver status') | |
69 | |
70 | |
71 def is_screensaver_unlocked(self): | |
72 """Returns True if the screensaver is unlocked, false otherwise. | |
73 | |
74 The screensaver has more than two potential states, do not assume | |
75 that the screensaver is completely locked if this returns False, | |
76 use is_screensaver_locked() for that. | |
77 """ | |
78 return self.__is_screensaver('non-blanked') | |
79 | |
80 | |
81 def xsystem(self, cmd, timeout=None, ignore_status=False): | 48 def xsystem(self, cmd, timeout=None, ignore_status=False): |
82 """Convenience wrapper around site_ui.xsystem, to save you an import. | 49 """Convenience wrapper around site_ui.xsystem, to save you an import. |
83 """ | 50 """ |
84 return site_ui.xsystem(cmd, timeout, ignore_status) | 51 return site_ui.xsystem(cmd, timeout, ignore_status) |
85 | 52 |
86 | 53 def listen_to_signal(self, callback, signal, interface): |
87 def wait_for_screensaver(self, timeout=site_login._DEFAULT_TIMEOUT): | 54 """Listens to the given |signal| that is sent to power manager. |
88 """Convenience wrapper around site_login.wait_for_screensaver, to save | |
89 you an import. | |
90 """ | 55 """ |
91 site_login.wait_for_screensaver(timeout=timeout) | 56 self._system_bus.add_signal_receiver( |
92 | 57 handler_function=callback, |
| 58 signal_name=signal, |
| 59 dbus_interface=interface, |
| 60 bus_name=None, |
| 61 path='/') |
93 | 62 |
94 def __attempt_resolve(self, hostname, ip, expected=True): | 63 def __attempt_resolve(self, hostname, ip, expected=True): |
95 try: | 64 try: |
96 return (socket.gethostbyname(hostname) == ip) == expected | 65 return (socket.gethostbyname(hostname) == ip) == expected |
97 except socket.gaierror, error: | 66 except socket.gaierror, error: |
98 logging.error(error) | 67 logging.error(error) |
99 | 68 |
100 | |
101 def use_local_dns(self, dns_port=53): | 69 def use_local_dns(self, dns_port=53): |
102 """Set all devices to use our in-process mock DNS server. | 70 """Set all devices to use our in-process mock DNS server. |
103 """ | 71 """ |
104 self._dnsServer = site_dns_server.LocalDns(local_port=dns_port) | 72 self._dnsServer = site_dns_server.LocalDns(local_port=dns_port) |
105 self._dnsServer.run() | 73 self._dnsServer.run() |
106 | 74 self._bus_loop = DBusGMainLoop(set_as_default=True) |
107 self._flim = flimflam.FlimFlam(dbus.SystemBus()) | 75 self._system_bus = dbus.SystemBus(mainloop=self._bus_loop) |
| 76 self._flim = flimflam.FlimFlam(self._system_bus) |
108 for device in self._flim.GetObjectList('Device'): | 77 for device in self._flim.GetObjectList('Device'): |
109 properties = device.GetProperties() | 78 properties = device.GetProperties() |
110 for path in properties['IPConfigs']: | 79 for path in properties['IPConfigs']: |
111 ipconfig = self._flim.GetObjectInterface('IPConfig', path) | 80 ipconfig = self._flim.GetObjectInterface('IPConfig', path) |
112 | 81 |
113 servers = ipconfig.GetProperties().get('NameServers', None) | 82 servers = ipconfig.GetProperties().get('NameServers', None) |
114 if servers != None: | 83 if servers != None: |
115 self._dns[path] = ','.join(servers) | 84 self._dns[path] = ','.join(servers) |
116 ipconfig.SetProperty('NameServers', '127.0.0.1') | 85 ipconfig.SetProperty('NameServers', '127.0.0.1') |
117 | 86 |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 self.logout() | 251 self.logout() |
283 | 252 |
284 self.stop_authserver() | 253 self.stop_authserver() |
285 | 254 |
286 | 255 |
287 def get_auth_endpoint_misses(self): | 256 def get_auth_endpoint_misses(self): |
288 if hasattr(self, '_authServer'): | 257 if hasattr(self, '_authServer'): |
289 return self._authServer.get_endpoint_misses() | 258 return self._authServer.get_endpoint_misses() |
290 else: | 259 else: |
291 return {} | 260 return {} |
OLD | NEW |