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

Side by Side Diff: chrome/test/pyautolib/pyauto.py

Issue 10053019: Add more diagnostic tracing when a JSON call doesn't return. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """PyAuto: Python Interface to Chromium's Automation Proxy. 6 """PyAuto: Python Interface to Chromium's Automation Proxy.
7 7
8 PyAuto uses swig to expose Automation Proxy interfaces to Python. 8 PyAuto uses swig to expose Automation Proxy interfaces to Python.
9 For complete documentation on the functionality available, 9 For complete documentation on the functionality available,
10 run pydoc on this file. 10 run pydoc on this file.
(...skipping 917 matching lines...) Expand 10 before | Expand all | Expand 10 after
928 """ 928 """
929 self._ui_test = ui_test 929 self._ui_test = ui_test
930 self.view = view 930 self.view = view
931 self.frame_xpath = frame_xpath 931 self.frame_xpath = frame_xpath
932 932
933 def Execute(self, script): 933 def Execute(self, script):
934 """Execute script in the render view.""" 934 """Execute script in the render view."""
935 return self._ui_test.ExecuteJavascriptInRenderView(script, 935 return self._ui_test.ExecuteJavascriptInRenderView(script,
936 self.view, 936 self.view,
937 self.frame_xpath) 937 self.frame_xpath)
938 def _GetResultFromJSONRequestDiagnostics(self, cmd_dict, windex=0,
939 timeout=-1):
940 """Same as _GetResultFromJSONRequest without throwing a timeout exception.
941
942 This method is used to diagnose if a command returns without causing a
943 timout exception to be thrown. This should be used for debugging purposes
944 only.
945
946 Returns:
947 True if the request returned; False if it timed out.
948 """
949 if timeout == -1: # Default
950 timeout = self.action_max_timeout_ms()
951 if windex is None: # Do not target any window
952 windex = -1
953 result = self._SendJSONRequest(windex, json.dumps(cmd_dict), timeout)
954 if not result:
955 # The diagnostic command did not complete, Chrome is probably in a bad
956 # state
957 return False
958 return True
938 959
939 def _GetResultFromJSONRequest(self, cmd_dict, windex=0, timeout=-1): 960 def _GetResultFromJSONRequest(self, cmd_dict, windex=0, timeout=-1):
940 """Issue call over the JSON automation channel and fetch output. 961 """Issue call over the JSON automation channel and fetch output.
941 962
942 This method packages the given dictionary into a json string, sends it 963 This method packages the given dictionary into a json string, sends it
943 over the JSON automation channel, loads the json output string returned, 964 over the JSON automation channel, loads the json output string returned,
944 and returns it back as a dictionary. 965 and returns it back as a dictionary.
945 966
946 Args: 967 Args:
947 cmd_dict: the command dictionary. It must have a 'command' key 968 cmd_dict: the command dictionary. It must have a 'command' key
(...skipping 16 matching lines...) Expand all
964 """ 985 """
965 if timeout == -1: # Default 986 if timeout == -1: # Default
966 timeout = self.action_max_timeout_ms() 987 timeout = self.action_max_timeout_ms()
967 if windex is None: # Do not target any window 988 if windex is None: # Do not target any window
968 windex = -1 989 windex = -1
969 result = self._SendJSONRequest(windex, json.dumps(cmd_dict), timeout) 990 result = self._SendJSONRequest(windex, json.dumps(cmd_dict), timeout)
970 if not result: 991 if not result:
971 additional_info = 'No information available.' 992 additional_info = 'No information available.'
972 # Windows does not support os.kill until Python 2.7. 993 # Windows does not support os.kill until Python 2.7.
973 if not self.IsWin() and _BROWSER_PID: 994 if not self.IsWin() and _BROWSER_PID:
974 additional_info = ('The browser process ID %d still exists. ' 995 browser_pid_exists = True
975 'It is possible that it is hung.' % _BROWSER_PID) 996 # Does the browser PID exist?
976 try: 997 try:
977 # Does not actually kill the process 998 # Does not actually kill the process
978 os.kill(int(_BROWSER_PID), 0) 999 os.kill(int(_BROWSER_PID), 0)
979 except OSError: 1000 except OSError:
980 additional_info = ('The browser process ID %d no longer exists.' % 1001 browser_pid_exists = False
981 _BROWSER_PID) 1002 if browser_pid_exists:
1003 info = GetBrowserInfo(self, performing_diagnostics=True)
1004 if info:
1005 # Browser info, worked, that means this hook had a problem
1006 additional_info = ('The browser process ID %d still exists. '
1007 'PyAuto was able to get obtain browser info. It '
1008 'is possible this hook is broken.'
Nirnimesh 2012/04/12 23:04:07 add a name to the hook: cmd_dict.get('command')
1009 % _BROWSER_PID)
1010 else:
1011 additional_info = ('The browser process ID %d still exists. '
1012 'PyAuto was not able to obtain browser info. '
1013 'It is possible the browser is hung.'
1014 % _BROWSER_PID)
1015 else:
1016 additional_info = ('The browser process ID %d no longer exists. '
1017 'Perhaps the browser crashed.' % _BROWSER_PID)
982 elif not _BROWSER_PID: 1018 elif not _BROWSER_PID:
983 additional_info = ('The browser PID was not obtained. Does this test ' 1019 additional_info = ('The browser PID was not obtained. Does this test '
984 'have a unique startup configuration?') 1020 'have a unique startup configuration?')
985 # Mask private data if it is in the JSON dictionary 1021 # Mask private data if it is in the JSON dictionary
986 cmd_dict_copy = copy.copy(cmd_dict) 1022 cmd_dict_copy = copy.copy(cmd_dict)
987 if 'password' in cmd_dict_copy.keys(): 1023 if 'password' in cmd_dict_copy.keys():
988 cmd_dict_copy['password'] = '**********' 1024 cmd_dict_copy['password'] = '**********'
989 if 'username' in cmd_dict_copy.keys(): 1025 if 'username' in cmd_dict_copy.keys():
990 cmd_dict_copy['username'] = 'removed_username' 1026 cmd_dict_copy['username'] = 'removed_username'
991 raise JSONInterfaceError('Automation call %s received empty response. ' 1027 raise JSONInterfaceError('Automation call %s received empty response. '
(...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after
1587 cmd_dict = { 1623 cmd_dict = {
1588 'command': 'PerformActionOnInfobar', 1624 'command': 'PerformActionOnInfobar',
1589 'action': action, 1625 'action': action,
1590 'infobar_index': infobar_index, 1626 'infobar_index': infobar_index,
1591 'tab_index': tab_index, 1627 'tab_index': tab_index,
1592 } 1628 }
1593 if action not in ('dismiss', 'accept', 'cancel'): 1629 if action not in ('dismiss', 'accept', 'cancel'):
1594 raise JSONInterfaceError('Invalid action %s' % action) 1630 raise JSONInterfaceError('Invalid action %s' % action)
1595 self._GetResultFromJSONRequest(cmd_dict, windex=windex) 1631 self._GetResultFromJSONRequest(cmd_dict, windex=windex)
1596 1632
1597 def GetBrowserInfo(self): 1633 def GetBrowserInfo(self, performing_diagnostics=False):
Nirnimesh 2012/04/12 23:04:07 I don't like that you're picking between the 2 met
1598 """Return info about the browser. 1634 """Return info about the browser.
1599 1635
1600 This includes things like the version number, the executable name, 1636 This includes things like the version number, the executable name,
1601 executable path, pid info about the renderer/plugin/extension processes, 1637 executable path, pid info about the renderer/plugin/extension processes,
1602 window dimensions. (See sample below) 1638 window dimensions. (See sample below)
1603 1639
1604 For notification pid info, see 'GetActiveNotifications'. 1640 For notification pid info, see 'GetActiveNotifications'.
1605 1641
1642 Args:
1643 performing_diagnostics: This is only used when we are trying to debug why
1644 the previous hook failed to return.
1645
1606 Returns: 1646 Returns:
1607 a dictionary 1647 a dictionary
1608 1648
1609 Sample: 1649 Sample:
1610 { u'browser_pid': 93737, 1650 { u'browser_pid': 93737,
1611 # Child processes are the processes for plugins and other workers. 1651 # Child processes are the processes for plugins and other workers.
1612 u'child_process_path': u'.../Chromium.app/Contents/' 1652 u'child_process_path': u'.../Chromium.app/Contents/'
1613 'Versions/6.0.412.0/Chromium Helper.app/' 1653 'Versions/6.0.412.0/Chromium Helper.app/'
1614 'Contents/MacOS/Chromium Helper', 1654 'Contents/MacOS/Chromium Helper',
1615 u'child_processes': [ { u'name': u'Shockwave Flash', 1655 u'child_processes': [ { u'name': u'Shockwave Flash',
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1674 u'width': 925, 1714 u'width': 925,
1675 u'x': 26, 1715 u'x': 26,
1676 u'y': 44}]} 1716 u'y': 44}]}
1677 1717
1678 Raises: 1718 Raises:
1679 pyauto_errors.JSONInterfaceError if the automation call returns an error. 1719 pyauto_errors.JSONInterfaceError if the automation call returns an error.
1680 """ 1720 """
1681 cmd_dict = { # Prepare command for the json interface 1721 cmd_dict = { # Prepare command for the json interface
1682 'command': 'GetBrowserInfo', 1722 'command': 'GetBrowserInfo',
1683 } 1723 }
1724 if performing_diagnostics:
1725 self._GetResultFromJSONRequestDiagnostics(cmd_dict, windex=None)
Nirnimesh 2012/04/12 23:04:07 return the output of this call
1726 return
1727
1684 return self._GetResultFromJSONRequest(cmd_dict, windex=None) 1728 return self._GetResultFromJSONRequest(cmd_dict, windex=None)
1685 1729
1686 def IsAura(self): 1730 def IsAura(self):
1687 """Is this Aura?""" 1731 """Is this Aura?"""
1688 return self.GetBrowserInfo()['properties']['aura'] 1732 return self.GetBrowserInfo()['properties']['aura']
1689 1733
1690 def GetProcessInfo(self): 1734 def GetProcessInfo(self):
1691 """Returns information about browser-related processes that currently exist. 1735 """Returns information about browser-related processes that currently exist.
1692 1736
1693 This will also return information about other currently-running browsers 1737 This will also return information about other currently-running browsers
(...skipping 3654 matching lines...) Expand 10 before | Expand all | Expand 10 after
5348 successful = result.wasSuccessful() 5392 successful = result.wasSuccessful()
5349 if not successful: 5393 if not successful:
5350 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) 5394 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename)
5351 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ 5395 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \
5352 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) 5396 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL)
5353 sys.exit(not successful) 5397 sys.exit(not successful)
5354 5398
5355 5399
5356 if __name__ == '__main__': 5400 if __name__ == '__main__':
5357 Main() 5401 Main()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698