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

Side by Side Diff: chrome/test/pyautolib/pyauto.py

Issue 7544026: Fix for flakiness in pyauto automation hook WaitForDownloadsToComplete. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merged with trunk; awaiting green trybots. Created 9 years, 4 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 | « chrome/test/pyautolib/download_info.py ('k') | 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/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
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,
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. Defaults to []; use GetDownloadsInfo() to get
1067 timeout: The timeout to use - default is WaitUntil's default timeout. 1061 these IDs (only necessary if a test previously
1062 downloaded files).
1063 windex: The window index, defaults to 0 (the first window).
1064 timeout: The maximum amount of time (in milliseconds) to wait for
1065 downloads to complete.
1068 """ 1066 """
1069 # TODO(alyssad): Remove this wait when downloads are re-implemented in a 1067 cmd_dict = {
1070 # testable way. 1068 'command': 'WaitForAllDownloadsToComplete',
1071 self.WaitUntil(lambda path: os.path.exists(path), timeout=timeout, 1069 'pre_download_ids': pre_download_ids,
1072 args=[download_path]) 1070 }
1071 self._GetResultFromJSONRequest(cmd_dict, windex=windex, timeout=timeout)
1073 1072
1074 def PerformActionOnDownload(self, id, action, window_index=0): 1073 def PerformActionOnDownload(self, id, action, window_index=0):
1075 """Perform the given action on the download with the given id. 1074 """Perform the given action on the download with the given id.
1076 1075
1077 Args: 1076 Args:
1078 id: The id of the download. 1077 id: The id of the download.
1079 action: The action to perform on the download. 1078 action: The action to perform on the download.
1080 Possible actions: 1079 Possible actions:
1081 'open': Opens the download (waits until it has completed first). 1080 'open': Opens the download (waits until it has completed first).
1082 'toggle_open_files_like_this': Toggles the 'Always Open Files 1081 'toggle_open_files_like_this': Toggles the 'Always Open Files
(...skipping 3112 matching lines...) Expand 10 before | Expand all | Expand 10 after
4195 successful = result.wasSuccessful() 4194 successful = result.wasSuccessful()
4196 if not successful: 4195 if not successful:
4197 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) 4196 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename)
4198 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ 4197 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \
4199 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) 4198 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL)
4200 sys.exit(not successful) 4199 sys.exit(not successful)
4201 4200
4202 4201
4203 if __name__ == '__main__': 4202 if __name__ == '__main__':
4204 Main() 4203 Main()
OLDNEW
« no previous file with comments | « chrome/test/pyautolib/download_info.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698