OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 | 2 |
3 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2011 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 15 matching lines...) Expand all Loading... |
26 """ | 26 """ |
27 | 27 |
28 import cStringIO | 28 import cStringIO |
29 import functools | 29 import functools |
30 import hashlib | 30 import hashlib |
31 import inspect | 31 import inspect |
32 import logging | 32 import logging |
33 import optparse | 33 import optparse |
34 import os | 34 import os |
35 import pickle | 35 import pickle |
| 36 import pprint |
36 import shutil | 37 import shutil |
37 import signal | 38 import signal |
38 import socket | 39 import socket |
39 import stat | 40 import stat |
40 import string | 41 import string |
41 import subprocess | 42 import subprocess |
42 import sys | 43 import sys |
43 import tempfile | 44 import tempfile |
44 import time | 45 import time |
45 import types | 46 import types |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 homepage: the home page. Defaults to "about:blank" | 129 homepage: the home page. Defaults to "about:blank" |
129 """ | 130 """ |
130 # Fetch provided keyword args, or fill in defaults. | 131 # Fetch provided keyword args, or fill in defaults. |
131 clear_profile = kwargs.get('clear_profile', True) | 132 clear_profile = kwargs.get('clear_profile', True) |
132 homepage = kwargs.get('homepage', 'about:blank') | 133 homepage = kwargs.get('homepage', 'about:blank') |
133 | 134 |
134 pyautolib.PyUITestBase.__init__(self, clear_profile, homepage) | 135 pyautolib.PyUITestBase.__init__(self, clear_profile, homepage) |
135 self.Initialize(pyautolib.FilePath(self.BrowserPath())) | 136 self.Initialize(pyautolib.FilePath(self.BrowserPath())) |
136 unittest.TestCase.__init__(self, methodName) | 137 unittest.TestCase.__init__(self, methodName) |
137 | 138 |
| 139 # Give all pyauto tests easy access to pprint.PrettyPrinter functions. |
| 140 self.pprint = pprint.pprint |
| 141 self.pformat = pprint.pformat |
| 142 |
138 # Set up remote proxies, if they were requested. | 143 # Set up remote proxies, if they were requested. |
139 self.remotes = [] | 144 self.remotes = [] |
140 self.remote = None | 145 self.remote = None |
141 global _REMOTE_PROXY | 146 global _REMOTE_PROXY |
142 if _REMOTE_PROXY: | 147 if _REMOTE_PROXY: |
143 self.remotes = _REMOTE_PROXY | 148 self.remotes = _REMOTE_PROXY |
144 self.remote = _REMOTE_PROXY[0] | 149 self.remote = _REMOTE_PROXY[0] |
145 | 150 |
146 def __del__(self): | 151 def __del__(self): |
147 pyautolib.PyUITestBase.__del__(self) | 152 pyautolib.PyUITestBase.__del__(self) |
(...skipping 1226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1374 u'y': 44}]} | 1379 u'y': 44}]} |
1375 | 1380 |
1376 Raises: | 1381 Raises: |
1377 pyauto_errors.JSONInterfaceError if the automation call returns an error. | 1382 pyauto_errors.JSONInterfaceError if the automation call returns an error. |
1378 """ | 1383 """ |
1379 cmd_dict = { # Prepare command for the json interface | 1384 cmd_dict = { # Prepare command for the json interface |
1380 'command': 'GetBrowserInfo', | 1385 'command': 'GetBrowserInfo', |
1381 } | 1386 } |
1382 return self._GetResultFromJSONRequest(cmd_dict, windex=-1) | 1387 return self._GetResultFromJSONRequest(cmd_dict, windex=-1) |
1383 | 1388 |
| 1389 def GetProcessInfo(self): |
| 1390 """Returns information about browser-related processes that currently exist. |
| 1391 |
| 1392 This will also return information about other currently-running browsers |
| 1393 besides just Chrome. |
| 1394 |
| 1395 Returns: |
| 1396 A dictionary containing browser-related process information as identified |
| 1397 by class MemoryDetails in src/chrome/browser/memory_details.h. The |
| 1398 dictionary contains a single key 'browsers', mapped to a list of |
| 1399 dictionaries containing information about each browser process name. |
| 1400 Each of those dictionaries contains a key 'processes', mapped to a list |
| 1401 of dictionaries containing the specific information for each process |
| 1402 with the given process name. |
| 1403 |
| 1404 The memory values given in |committed_mem| and |working_set_mem| are in |
| 1405 KBytes. |
| 1406 |
| 1407 Sample: |
| 1408 { 'browsers': [ { 'name': 'Chromium', |
| 1409 'process_name': 'chrome', |
| 1410 'processes': [ { 'child_process_type': 'Browser', |
| 1411 'committed_mem': { 'image': 0, |
| 1412 'mapped': 0, |
| 1413 'priv': 0}, |
| 1414 'is_diagnostics': False, |
| 1415 'num_processes': 1, |
| 1416 'pid': 7770, |
| 1417 'product_name': '', |
| 1418 'renderer_type': 'Unknown', |
| 1419 'titles': [], |
| 1420 'version': '', |
| 1421 'working_set_mem': { 'priv': 43672, |
| 1422 'shareable': 0, |
| 1423 'shared': 59251}}, |
| 1424 { 'child_process_type': 'Tab', |
| 1425 'committed_mem': { 'image': 0, |
| 1426 'mapped': 0, |
| 1427 'priv': 0}, |
| 1428 'is_diagnostics': False, |
| 1429 'num_processes': 1, |
| 1430 'pid': 7791, |
| 1431 'product_name': '', |
| 1432 'renderer_type': 'Tab', |
| 1433 'titles': ['about:blank'], |
| 1434 'version': '', |
| 1435 'working_set_mem': { 'priv': 16768, |
| 1436 'shareable': 0, |
| 1437 'shared': 26256}}, |
| 1438 ...<more processes>...]}]} |
| 1439 |
| 1440 Raises: |
| 1441 pyauto_errors.JSONInterfaceError if the automation call returns an error. |
| 1442 """ |
| 1443 cmd_dict = { # Prepare command for the json interface. |
| 1444 'command': 'GetProcessInfo', |
| 1445 } |
| 1446 return self._GetResultFromJSONRequest(cmd_dict, windex=-1) |
| 1447 |
1384 def GetNavigationInfo(self, tab_index=0, windex=0): | 1448 def GetNavigationInfo(self, tab_index=0, windex=0): |
1385 """Get info about the navigation state of a given tab. | 1449 """Get info about the navigation state of a given tab. |
1386 | 1450 |
1387 Args: | 1451 Args: |
1388 tab_index: The tab index, default is 0. | 1452 tab_index: The tab index, default is 0. |
1389 window_index: The window index, default is 0. | 1453 window_index: The window index, default is 0. |
1390 | 1454 |
1391 Returns: | 1455 Returns: |
1392 a dictionary. | 1456 a dictionary. |
1393 Sample: | 1457 Sample: |
(...skipping 3081 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4475 successful = result.wasSuccessful() | 4539 successful = result.wasSuccessful() |
4476 if not successful: | 4540 if not successful: |
4477 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) | 4541 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) |
4478 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ | 4542 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ |
4479 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) | 4543 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) |
4480 sys.exit(not successful) | 4544 sys.exit(not successful) |
4481 | 4545 |
4482 | 4546 |
4483 if __name__ == '__main__': | 4547 if __name__ == '__main__': |
4484 Main() | 4548 Main() |
OLD | NEW |