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

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):
Nirnimesh 2012/04/13 18:28:04 nit: need a blank line before this
939 """Same as _GetResultFromJSONRequest without throwing a timeout exception.
940
941 This method is used to diagnose if a command returns without causing a
942 timout exception to be thrown. This should be used for debugging purposes
943 only.
944
945 Returns:
946 True if the request returned; False if it timed out.
947 """
948 result = self._SendJSONRequest(-1,
949 json.dumps({'command': 'GetBrowserInfo',}),
950 self.action_max_timeout_ms())
951 if not result:
952 # The diagnostic command did not complete, Chrome is probably in a bad
953 # state
954 return False
955 return True
938 956
939 def _GetResultFromJSONRequest(self, cmd_dict, windex=0, timeout=-1): 957 def _GetResultFromJSONRequest(self, cmd_dict, windex=0, timeout=-1):
940 """Issue call over the JSON automation channel and fetch output. 958 """Issue call over the JSON automation channel and fetch output.
941 959
942 This method packages the given dictionary into a json string, sends it 960 This method packages the given dictionary into a json string, sends it
943 over the JSON automation channel, loads the json output string returned, 961 over the JSON automation channel, loads the json output string returned,
944 and returns it back as a dictionary. 962 and returns it back as a dictionary.
945 963
946 Args: 964 Args:
947 cmd_dict: the command dictionary. It must have a 'command' key 965 cmd_dict: the command dictionary. It must have a 'command' key
(...skipping 16 matching lines...) Expand all
964 """ 982 """
965 if timeout == -1: # Default 983 if timeout == -1: # Default
966 timeout = self.action_max_timeout_ms() 984 timeout = self.action_max_timeout_ms()
967 if windex is None: # Do not target any window 985 if windex is None: # Do not target any window
968 windex = -1 986 windex = -1
969 result = self._SendJSONRequest(windex, json.dumps(cmd_dict), timeout) 987 result = self._SendJSONRequest(windex, json.dumps(cmd_dict), timeout)
970 if not result: 988 if not result:
971 additional_info = 'No information available.' 989 additional_info = 'No information available.'
972 # Windows does not support os.kill until Python 2.7. 990 # Windows does not support os.kill until Python 2.7.
973 if not self.IsWin() and _BROWSER_PID: 991 if not self.IsWin() and _BROWSER_PID:
974 additional_info = ('The browser process ID %d still exists. ' 992 browser_pid_exists = True
975 'It is possible that it is hung.' % _BROWSER_PID) 993 # Does the browser PID exist?
976 try: 994 try:
977 # Does not actually kill the process 995 # Does not actually kill the process
978 os.kill(int(_BROWSER_PID), 0) 996 os.kill(int(_BROWSER_PID), 0)
979 except OSError: 997 except OSError:
980 additional_info = ('The browser process ID %d no longer exists.' % 998 browser_pid_exists = False
981 _BROWSER_PID) 999 if browser_pid_exists:
1000 if self._GetResultFromJSONRequestDiagnostics():
1001 # Browser info, worked, that means this hook had a problem
1002 additional_info = ('The browser process ID %d still exists. '
1003 'PyAuto was able to get obtain browser info. It '
1004 'is possible this hook is broken.'
1005 % _BROWSER_PID)
1006 else:
1007 additional_info = ('The browser process ID %d still exists. '
1008 'PyAuto was not able to obtain browser info. '
1009 'It is possible the browser is hung.'
1010 % _BROWSER_PID)
1011 else:
1012 additional_info = ('The browser process ID %d no longer exists. '
1013 'Perhaps the browser crashed.' % _BROWSER_PID)
982 elif not _BROWSER_PID: 1014 elif not _BROWSER_PID:
983 additional_info = ('The browser PID was not obtained. Does this test ' 1015 additional_info = ('The browser PID was not obtained. Does this test '
984 'have a unique startup configuration?') 1016 'have a unique startup configuration?')
985 # Mask private data if it is in the JSON dictionary 1017 # Mask private data if it is in the JSON dictionary
986 cmd_dict_copy = copy.copy(cmd_dict) 1018 cmd_dict_copy = copy.copy(cmd_dict)
987 if 'password' in cmd_dict_copy.keys(): 1019 if 'password' in cmd_dict_copy.keys():
988 cmd_dict_copy['password'] = '**********' 1020 cmd_dict_copy['password'] = '**********'
989 if 'username' in cmd_dict_copy.keys(): 1021 if 'username' in cmd_dict_copy.keys():
990 cmd_dict_copy['username'] = 'removed_username' 1022 cmd_dict_copy['username'] = 'removed_username'
991 raise JSONInterfaceError('Automation call %s received empty response. ' 1023 raise JSONInterfaceError('Automation call %s received empty response. '
(...skipping 4356 matching lines...) Expand 10 before | Expand all | Expand 10 after
5348 successful = result.wasSuccessful() 5380 successful = result.wasSuccessful()
5349 if not successful: 5381 if not successful:
5350 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) 5382 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename)
5351 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ 5383 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \
5352 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) 5384 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL)
5353 sys.exit(not successful) 5385 sys.exit(not successful)
5354 5386
5355 5387
5356 if __name__ == '__main__': 5388 if __name__ == '__main__':
5357 Main() 5389 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