Index: chrome/test/pyautolib/pyauto.py |
=================================================================== |
--- chrome/test/pyautolib/pyauto.py (revision 131795) |
+++ chrome/test/pyautolib/pyauto.py (working copy) |
@@ -935,7 +935,28 @@ |
return self._ui_test.ExecuteJavascriptInRenderView(script, |
self.view, |
self.frame_xpath) |
+ def _GetResultFromJSONRequestDiagnostics(self, cmd_dict, windex=0, |
+ timeout=-1): |
+ """Same as _GetResultFromJSONRequest without throwing a timeout exception. |
+ This method is used to diagnose if a command returns without causing a |
+ timout exception to be thrown. This should be used for debugging purposes |
+ only. |
+ |
+ Returns: |
+ True if the request returned; False if it timed out. |
+ """ |
+ if timeout == -1: # Default |
+ timeout = self.action_max_timeout_ms() |
+ if windex is None: # Do not target any window |
+ windex = -1 |
+ result = self._SendJSONRequest(windex, json.dumps(cmd_dict), timeout) |
+ if not result: |
+ # The diagnostic command did not complete, Chrome is probably in a bad |
+ # state |
+ return False |
+ return True |
+ |
def _GetResultFromJSONRequest(self, cmd_dict, windex=0, timeout=-1): |
"""Issue call over the JSON automation channel and fetch output. |
@@ -971,14 +992,29 @@ |
additional_info = 'No information available.' |
# Windows does not support os.kill until Python 2.7. |
if not self.IsWin() and _BROWSER_PID: |
- additional_info = ('The browser process ID %d still exists. ' |
- 'It is possible that it is hung.' % _BROWSER_PID) |
+ browser_pid_exists = True |
+ # Does the browser PID exist? |
try: |
# Does not actually kill the process |
os.kill(int(_BROWSER_PID), 0) |
except OSError: |
- additional_info = ('The browser process ID %d no longer exists.' % |
- _BROWSER_PID) |
+ browser_pid_exists = False |
+ if browser_pid_exists: |
+ info = GetBrowserInfo(self, performing_diagnostics=True) |
+ if info: |
+ # Browser info, worked, that means this hook had a problem |
+ additional_info = ('The browser process ID %d still exists. ' |
+ 'PyAuto was able to get obtain browser info. It ' |
+ 'is possible this hook is broken.' |
Nirnimesh
2012/04/12 23:04:07
add a name to the hook: cmd_dict.get('command')
|
+ % _BROWSER_PID) |
+ else: |
+ additional_info = ('The browser process ID %d still exists. ' |
+ 'PyAuto was not able to obtain browser info. ' |
+ 'It is possible the browser is hung.' |
+ % _BROWSER_PID) |
+ else: |
+ additional_info = ('The browser process ID %d no longer exists. ' |
+ 'Perhaps the browser crashed.' % _BROWSER_PID) |
elif not _BROWSER_PID: |
additional_info = ('The browser PID was not obtained. Does this test ' |
'have a unique startup configuration?') |
@@ -1594,7 +1630,7 @@ |
raise JSONInterfaceError('Invalid action %s' % action) |
self._GetResultFromJSONRequest(cmd_dict, windex=windex) |
- def GetBrowserInfo(self): |
+ 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
|
"""Return info about the browser. |
This includes things like the version number, the executable name, |
@@ -1603,6 +1639,10 @@ |
For notification pid info, see 'GetActiveNotifications'. |
+ Args: |
+ performing_diagnostics: This is only used when we are trying to debug why |
+ the previous hook failed to return. |
+ |
Returns: |
a dictionary |
@@ -1681,6 +1721,10 @@ |
cmd_dict = { # Prepare command for the json interface |
'command': 'GetBrowserInfo', |
} |
+ if performing_diagnostics: |
+ self._GetResultFromJSONRequestDiagnostics(cmd_dict, windex=None) |
Nirnimesh
2012/04/12 23:04:07
return the output of this call
|
+ return |
+ |
return self._GetResultFromJSONRequest(cmd_dict, windex=None) |
def IsAura(self): |