OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 | 2 |
3 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2010 The Chromium Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 """PyAuto: Python Interface to Chromium's Automation Proxy. | 7 """PyAuto: Python Interface to Chromium's Automation Proxy. |
8 | 8 |
9 PyAuto uses swig to expose Automation Proxy interfaces to Python. | 9 PyAuto uses swig to expose Automation Proxy interfaces to Python. |
10 For complete documentation on the functionality available, | 10 For complete documentation on the functionality available, |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 contents = open(data_file).read() | 248 contents = open(data_file).read() |
249 try: | 249 try: |
250 ret = eval(contents, {'__builtins__': None}, None) | 250 ret = eval(contents, {'__builtins__': None}, None) |
251 except: | 251 except: |
252 print >>sys.stderr, '%s is an invalid data file.' % data_file | 252 print >>sys.stderr, '%s is an invalid data file.' % data_file |
253 raise | 253 raise |
254 return ret | 254 return ret |
255 | 255 |
256 @staticmethod | 256 @staticmethod |
257 def Kill(pid): | 257 def Kill(pid): |
258 """Terminate the given pid.""" | 258 """Terminate the given pid. |
| 259 |
| 260 If the pid refers to a renderer, use KillRendererProcess instead. |
| 261 """ |
259 if PyUITest.IsWin(): | 262 if PyUITest.IsWin(): |
260 subprocess.call(['taskkill.exe', '/T', '/F', '/PID', str(pid)]) | 263 subprocess.call(['taskkill.exe', '/T', '/F', '/PID', str(pid)]) |
261 else: | 264 else: |
262 os.kill(pid, signal.SIGTERM) | 265 os.kill(pid, signal.SIGTERM) |
263 | 266 |
264 def GetPrivateInfo(self): | 267 def GetPrivateInfo(self): |
265 """Fetch info from private_tests_info.txt in private dir. | 268 """Fetch info from private_tests_info.txt in private dir. |
266 | 269 |
267 Returns: | 270 Returns: |
268 a dictionary of items from private_tests_info.txt | 271 a dictionary of items from private_tests_info.txt |
(...skipping 1690 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1959 """ | 1962 """ |
1960 cmd_dict = { | 1963 cmd_dict = { |
1961 'command': 'GetNTPInfo', | 1964 'command': 'GetNTPInfo', |
1962 } | 1965 } |
1963 return self._GetResultFromJSONRequest(cmd_dict) | 1966 return self._GetResultFromJSONRequest(cmd_dict) |
1964 | 1967 |
1965 def _CheckNTPThumbnailShown(self, thumbnail): | 1968 def _CheckNTPThumbnailShown(self, thumbnail): |
1966 if self.GetNTPThumbnailIndex(thumbnail) == -1: | 1969 if self.GetNTPThumbnailIndex(thumbnail) == -1: |
1967 raise NTPThumbnailNotShownError() | 1970 raise NTPThumbnailNotShownError() |
1968 | 1971 |
| 1972 def KillRendererProcess(self, pid): |
| 1973 """Kills the given renderer process. |
| 1974 |
| 1975 This will return only after the browser has received notice of the renderer |
| 1976 close. |
| 1977 |
| 1978 Args: |
| 1979 pid: the process id of the renderer to kill |
| 1980 |
| 1981 Raises: |
| 1982 pyauto_errors.JSONInterfaceError if the automation call returns an error. |
| 1983 """ |
| 1984 cmd_dict = { |
| 1985 'command': 'KillRendererProcess', |
| 1986 'pid': pid |
| 1987 } |
| 1988 return self._GetResultFromJSONRequest(cmd_dict) |
| 1989 |
1969 | 1990 |
1970 class PyUITestSuite(pyautolib.PyUITestSuiteBase, unittest.TestSuite): | 1991 class PyUITestSuite(pyautolib.PyUITestSuiteBase, unittest.TestSuite): |
1971 """Base TestSuite for PyAuto UI tests.""" | 1992 """Base TestSuite for PyAuto UI tests.""" |
1972 | 1993 |
1973 def __init__(self, args): | 1994 def __init__(self, args): |
1974 pyautolib.PyUITestSuiteBase.__init__(self, args) | 1995 pyautolib.PyUITestSuiteBase.__init__(self, args) |
1975 | 1996 |
1976 # Figure out path to chromium binaries | 1997 # Figure out path to chromium binaries |
1977 browser_dir = os.path.normpath(os.path.dirname(pyautolib.__file__)) | 1998 browser_dir = os.path.normpath(os.path.dirname(pyautolib.__file__)) |
1978 logging.debug('Loading pyauto libs from %s', browser_dir) | 1999 logging.debug('Loading pyauto libs from %s', browser_dir) |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2268 if self._options.verbose: | 2289 if self._options.verbose: |
2269 verbosity = 2 | 2290 verbosity = 2 |
2270 result = PyAutoTextTestRuner(verbosity=verbosity).run(pyauto_suite) | 2291 result = PyAutoTextTestRuner(verbosity=verbosity).run(pyauto_suite) |
2271 del loaded_tests # Need to destroy test cases before the suite | 2292 del loaded_tests # Need to destroy test cases before the suite |
2272 del pyauto_suite | 2293 del pyauto_suite |
2273 sys.exit(not result.wasSuccessful()) | 2294 sys.exit(not result.wasSuccessful()) |
2274 | 2295 |
2275 | 2296 |
2276 if __name__ == '__main__': | 2297 if __name__ == '__main__': |
2277 Main() | 2298 Main() |
OLD | NEW |