Index: chrome/test/pyautolib/pyauto.py |
=================================================================== |
--- chrome/test/pyautolib/pyauto.py (revision 79305) |
+++ chrome/test/pyautolib/pyauto.py (working copy) |
@@ -422,32 +422,36 @@ |
time.sleep(retry_sleep) |
return False |
- class CmdExecutionTimeoutChanger(object): |
- """Facilitate temporary changes to command_execution_timeout_ms. |
- Automatically resets to original timeout when object is destroyed. |
- """ |
- _saved_timeout = -1 # Saved value for command_execution_timeout_ms |
+ def _GetResultFromJSONRequest(self, cmd_dict, windex=0): |
+ """Issue call over the JSON automation channel and fetch output. |
- def __init__(self, ui_test, new_timeout): |
- """Initialize. |
+ This method packages the given dictionary into a json string, sends it |
+ over the JSON automation channel, loads the json output string returned, |
+ and returns it back as a dictionary. |
- Args: |
- ui_test: a PyUITest object |
- new_timeout: new timeout to use (in milli secs) |
- """ |
- self._saved_timeout = ui_test.command_execution_timeout_ms() |
- if new_timeout != self._saved_timeout: |
- ui_test.set_command_execution_timeout_ms(new_timeout) |
- self._ui_test = ui_test |
+ Args: |
+ cmd_dict: the command dictionary. It must have a 'command' key |
+ Sample: |
+ { |
+ 'command': 'SetOmniboxText', |
+ 'text': text, |
+ } |
+ windex: 0-based window index on which to work. Default: 0 (first window) |
+ Use -ve windex if the automation command does not apply to a |
+ browser window. example: chromeos login |
- def __del__(self): |
- """Reset command_execution_timeout_ms to original value.""" |
- if self._ui_test.command_execution_timeout_ms() != self._saved_timeout: |
- self._ui_test.set_command_execution_timeout_ms(self._saved_timeout) |
+ Returns: |
+ a dictionary for the output returned by the automation channel. |
+ Raises: |
+ pyauto_errors.JSONInterfaceError if the automation call returns an error. |
+ """ |
+ return self._GetResultFromJSONRequest( |
+ cmd_dict, windex, timeout=self.action_max_timeout_ms()) |
- def _GetResultFromJSONRequest(self, cmd_dict, windex=0): |
+ |
+ def _GetResultFromJSONRequest(self, cmd_dict, windex=0, timeout=-1): |
"""Issue call over the JSON automation channel and fetch output. |
This method packages the given dictionary into a json string, sends it |
@@ -465,13 +469,18 @@ |
Use -ve windex if the automation command does not apply to a |
browser window. example: chromeos login |
+ timeout: request timeout |
+ |
Returns: |
a dictionary for the output returned by the automation channel. |
Raises: |
pyauto_errors.JSONInterfaceError if the automation call returns an error. |
""" |
- ret_dict = json.loads(self._SendJSONRequest(windex, json.dumps(cmd_dict))) |
+ if timeout == -1: # Default |
+ timeout = self.action_max_timeout_ms() |
Paweł Hajdan Jr.
2011/03/26 10:55:12
Similarly to action_max_timeout, you can add acces
|
+ ret_dict = json.loads(self._SendJSONRequest( |
+ windex, json.dumps(cmd_dict), timeout)) |
if ret_dict.has_key('error'): |
raise JSONInterfaceError(ret_dict['error']) |
return ret_dict |
@@ -755,13 +764,19 @@ |
self._GetResultFromJSONRequest(cmd_dict) |
def WaitForAllDownloadsToComplete(self, windex=0): |
+ self.WaitForAllDownloads( |
+ self, windex=0, timeout=self.action_max_timeout_ms()) |
+ |
+ def WaitForAllDownloadsToComplete(self, windex=0, timeout=-1): |
"""Wait for all downloads to complete. |
Note: This method does not work for dangerous downloads. Use |
WaitForGivenDownloadsToComplete (below) instead. |
""" |
+ if timeout == -1: # Default |
+ timeout = self.action_max_timeout_ms() |
cmd_dict = {'command': 'WaitForAllDownloadsToComplete'} |
- self._GetResultFromJSONRequest(cmd_dict, windex=windex) |
+ self._GetResultFromJSONRequest(cmd_dict, windex=windex, timeout=timeout) |
def WaitForDownloadToComplete(self, download_path, timeout=-1): |
"""Wait for the given downloads to complete. |