Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 | 2 |
| 3 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 """PyAuto: Python Interface to Chromium's Automation Proxy. | 7 """PyAuto: Python Interface to Chromium's Automation Proxy. |
| 8 | 8 |
| 9 PyAuto uses swig to expose Automation Proxy interfaces to Python. | 9 PyAuto uses swig to expose Automation Proxy interfaces to Python. |
| 10 For complete documentation on the functionality available, | 10 For complete documentation on the functionality available, |
| (...skipping 1028 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1039 'unmodifiedText': char, | 1039 'unmodifiedText': char, |
| 1040 'nativeKeyCode': 0, | 1040 'nativeKeyCode': 0, |
| 1041 'windowsKeyCode': ord((char).upper()), | 1041 'windowsKeyCode': ord((char).upper()), |
| 1042 'modifiers': 0, | 1042 'modifiers': 0, |
| 1043 'windex': windex, | 1043 'windex': windex, |
| 1044 'tab_index': tab_index, | 1044 'tab_index': tab_index, |
| 1045 } | 1045 } |
| 1046 # Sending request for a char. | 1046 # Sending request for a char. |
| 1047 self._GetResultFromJSONRequest(cmd_dict, windex=-1) | 1047 self._GetResultFromJSONRequest(cmd_dict, windex=-1) |
| 1048 | 1048 |
| 1049 def WaitForAllDownloadsToComplete(self, windex=0, timeout=-1): | 1049 def WaitForAllDownloadsToComplete(self, pre_download_ids, windex=0, |
|
Nirnimesh
2011/08/08 17:26:17
pre_download_ids should default to [] so that most
dennis_jeffrey
2011/08/08 22:29:51
Great idea.
| |
| 1050 """Wait for all downloads to complete. | 1050 timeout=-1): |
| 1051 """Wait for all pending downloads to complete. | |
| 1051 | 1052 |
| 1052 Note: This method does not work for dangerous downloads. Use | 1053 This function assumes that any downloads to wait for have already been |
| 1053 WaitForGivenDownloadsToComplete (below) instead. | 1054 triggered and have started (it is ok if those downloads complete before this |
| 1054 """ | 1055 function is called). |
| 1055 cmd_dict = {'command': 'WaitForAllDownloadsToComplete'} | |
| 1056 self._GetResultFromJSONRequest(cmd_dict, windex=windex, timeout=timeout) | |
| 1057 | |
| 1058 def WaitForDownloadToComplete(self, download_path, timeout=-1): | |
| 1059 """Wait for the given downloads to complete. | |
| 1060 | |
| 1061 This method works for dangerous downloads as well as regular downloads. | |
| 1062 | 1056 |
| 1063 Args: | 1057 Args: |
| 1064 download_path: The path to the final download. This is only necessary for | 1058 pre_download_ids: A list of numbers representing the IDs of downloads that |
| 1065 the workaround described in the comments below and should | 1059 exist *before* downloads to wait for have been |
| 1066 be removed when downloads are re-implemented. | 1060 triggered. Use GetDownloadsInfo() to get these IDs. |
| 1067 timeout: The timeout to use - default is WaitUntil's default timeout. | 1061 windex: The window index, defaults to 0 (the first window). |
| 1062 timeout: The maximum amount of time (in milliseconds) to wait for | |
| 1063 downloads to complete. | |
| 1068 """ | 1064 """ |
| 1069 # TODO(alyssad): Remove this wait when downloads are re-implemented in a | 1065 cmd_dict = { |
| 1070 # testable way. | 1066 'command': 'WaitForAllDownloadsToComplete', |
| 1071 self.WaitUntil(lambda path: os.path.exists(path), timeout=timeout, | 1067 'pre_download_ids': pre_download_ids, |
| 1072 args=[download_path]) | 1068 } |
| 1069 self._GetResultFromJSONRequest(cmd_dict, windex=windex, timeout=timeout) | |
| 1073 | 1070 |
| 1074 def PerformActionOnDownload(self, id, action, window_index=0): | 1071 def PerformActionOnDownload(self, id, action, window_index=0): |
| 1075 """Perform the given action on the download with the given id. | 1072 """Perform the given action on the download with the given id. |
| 1076 | 1073 |
| 1077 Args: | 1074 Args: |
| 1078 id: The id of the download. | 1075 id: The id of the download. |
| 1079 action: The action to perform on the download. | 1076 action: The action to perform on the download. |
| 1080 Possible actions: | 1077 Possible actions: |
| 1081 'open': Opens the download (waits until it has completed first). | 1078 'open': Opens the download (waits until it has completed first). |
| 1082 'toggle_open_files_like_this': Toggles the 'Always Open Files | 1079 'toggle_open_files_like_this': Toggles the 'Always Open Files |
| (...skipping 3112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4195 successful = result.wasSuccessful() | 4192 successful = result.wasSuccessful() |
| 4196 if not successful: | 4193 if not successful: |
| 4197 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) | 4194 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) |
| 4198 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ | 4195 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ |
| 4199 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) | 4196 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) |
| 4200 sys.exit(not successful) | 4197 sys.exit(not successful) |
| 4201 | 4198 |
| 4202 | 4199 |
| 4203 if __name__ == '__main__': | 4200 if __name__ == '__main__': |
| 4204 Main() | 4201 Main() |
| OLD | NEW |