Chromium Code Reviews| Index: chrome/test/pyautolib/pyauto.py |
| =================================================================== |
| --- chrome/test/pyautolib/pyauto.py (revision 79951) |
| +++ chrome/test/pyautolib/pyauto.py (working copy) |
| @@ -422,12 +422,13 @@ |
| time.sleep(retry_sleep) |
| return False |
| - class CmdExecutionTimeoutChanger(object): |
| - """Facilitate temporary changes to command_execution_timeout_ms. |
| + class ActionTimeoutChanger(object): |
| + """Facilitate temporary changes to action_timeout_ms. |
| + |
| Automatically resets to original timeout when object is destroyed. |
| """ |
| - _saved_timeout = -1 # Saved value for command_execution_timeout_ms |
| + _saved_timeout = -1 # Saved value for action_timeout_ms |
| def __init__(self, ui_test, new_timeout): |
| """Initialize. |
| @@ -436,18 +437,18 @@ |
| ui_test: a PyUITest object |
| new_timeout: new timeout to use (in milli secs) |
| """ |
| - self._saved_timeout = ui_test.command_execution_timeout_ms() |
| + self._saved_timeout = ui_test.action_timeout_ms() |
| if new_timeout != self._saved_timeout: |
| - ui_test.set_command_execution_timeout_ms(new_timeout) |
| + ui_test.set_action_timeout_ms(new_timeout) |
| self._ui_test = ui_test |
| 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) |
| + if self._ui_test.action_timeout_ms() != self._saved_timeout: |
| + self._ui_test.set_action_timeout_ms(self._saved_timeout) |
| - 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 +466,17 @@ |
| Use -ve windex if the automation command does not apply to a |
| browser window. example: chromeos login |
| + timeout: request timeout |
|
Nirnimesh
2011/03/31 18:37:56
add "(in milli-secs)"
Huyen
2011/03/31 18:52:19
Done.
|
| + |
| Returns: |
| a dictionary for the output returned by the automation channel. |
| Raises: |
| pyauto_errors.JSONInterfaceError if the automation call returns an error. |
| """ |
| - result = self._SendJSONRequest(windex, json.dumps(cmd_dict)) |
| + if timeout == -1: # Default |
| + timeout = self.action_max_timeout_ms() |
| + result = self._SendJSONRequest(windex, json.dumps(cmd_dict), timeout) |
| if len(result) == 0: |
| raise JSONInterfaceError('Automation call received no response.') |
| ret_dict = json.loads(result) |
| @@ -497,7 +502,8 @@ |
| """ |
| return download_info.DownloadInfo( |
| self._SendJSONRequest( |
| - windex, json.dumps({'command': 'GetDownloadsInfo'}))) |
| + windex, json.dumps({'command': 'GetDownloadsInfo'}), |
| + self.action_max_timeout_ms())) |
| def GetOmniboxInfo(self, windex=0): |
| """Return info about Omnibox. |
| @@ -524,7 +530,8 @@ |
| """ |
| return omnibox_info.OmniboxInfo( |
| self._SendJSONRequest(windex, |
| - json.dumps({'command': 'GetOmniboxInfo'}))) |
| + json.dumps({'command': 'GetOmniboxInfo'}), |
| + self.action_max_timeout_ms())) |
| def SetOmniboxText(self, text, windex=0): |
| """Enter text into the omnibox. This shifts focus to the omnibox. |
| @@ -726,7 +733,8 @@ |
| an instance of prefs_info.PrefsInfo |
| """ |
| return prefs_info.PrefsInfo( |
| - self._SendJSONRequest(0, json.dumps({'command': 'GetPrefsInfo'}))) |
| + self._SendJSONRequest(0, json.dumps({'command': 'GetPrefsInfo'}), |
| + self.action_max_timeout_ms())) |
| def SetPrefs(self, path, value): |
| """Set preference for the given path. |
| @@ -784,14 +792,14 @@ |
| cmd_dict['type'] = 3 # kKeyUpType |
| self._GetResultFromJSONRequest(cmd_dict) |
| - def WaitForAllDownloadsToComplete(self, windex=0): |
| + 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. |
| """ |
| 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. |
| @@ -1086,7 +1094,8 @@ |
| 'search_text': search_text, |
| } |
| return history_info.HistoryInfo( |
| - self._SendJSONRequest(0, json.dumps(cmd_dict))) |
| + self._SendJSONRequest(0, json.dumps(cmd_dict), |
| + self.action_max_timeout_ms())) |
| def GetTranslateInfo(self, tab_index=0, window_index=0): |
| """Returns info about translate for the given page. |
| @@ -1413,7 +1422,8 @@ |
| an instance of plugins_info.PluginsInfo |
| """ |
| return plugins_info.PluginsInfo( |
| - self._SendJSONRequest(0, json.dumps({'command': 'GetPluginsInfo'}))) |
| + self._SendJSONRequest(0, json.dumps({'command': 'GetPluginsInfo'}), |
| + self.action_max_timeout_ms())) |
| def EnablePlugin(self, path): |
| """Enable the plugin at the given path. |