| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 | 2 |
| 3 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2010 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 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 if ret_dict.has_key('error'): | 276 if ret_dict.has_key('error'): |
| 277 raise JSONInterfaceError(ret_dict['error']) | 277 raise JSONInterfaceError(ret_dict['error']) |
| 278 | 278 |
| 279 def WaitForAllDownloadsToComplete(self): | 279 def WaitForAllDownloadsToComplete(self): |
| 280 """Wait for all downloads to complete.""" | 280 """Wait for all downloads to complete.""" |
| 281 # Implementation detail: uses the generic "JSON command" model | 281 # Implementation detail: uses the generic "JSON command" model |
| 282 # (experimental) | 282 # (experimental) |
| 283 self._SendJSONRequest(0, json.dumps({'command': | 283 self._SendJSONRequest(0, json.dumps({'command': |
| 284 'WaitForAllDownloadsToComplete'})) | 284 'WaitForAllDownloadsToComplete'})) |
| 285 | 285 |
| 286 def DownloadAndWaitForStart(self, file_url): |
| 287 """Trigger download for the given url and wait for downloads to start. |
| 288 |
| 289 It waits for download by looking at the download info from Chrome, so |
| 290 anything which isn't registered by the history service won't be noticed. |
| 291 This is not thread-safe, but it's fine to call this method to start |
| 292 downloading multiple files in parallel. That is after starting a |
| 293 download, it's fine to start another one even if the first one hasn't |
| 294 completed. |
| 295 """ |
| 296 num_downloads = len(self.GetDownloadsInfo().Downloads()) |
| 297 self.NavigateToURL(file_url) # Trigger download. |
| 298 # It might take a while for the download to kick in, hold on until then. |
| 299 self.assertTrue(self.WaitUntil( |
| 300 lambda: len(self.GetDownloadsInfo().Downloads()) == num_downloads + 1)) |
| 301 |
| 286 def GetHistoryInfo(self, search_text=''): | 302 def GetHistoryInfo(self, search_text=''): |
| 287 """Return info about browsing history. | 303 """Return info about browsing history. |
| 288 | 304 |
| 289 Args: | 305 Args: |
| 290 search_text: the string to search in history. Defaults to empty string | 306 search_text: the string to search in history. Defaults to empty string |
| 291 which means that all history would be returned. This is | 307 which means that all history would be returned. This is |
| 292 functionally equivalent to searching for a text in the | 308 functionally equivalent to searching for a text in the |
| 293 chrome://history UI. So partial matches work too. | 309 chrome://history UI. So partial matches work too. |
| 294 When non-empty, the history items returned will contain a | 310 When non-empty, the history items returned will contain a |
| 295 "snippet" field corresponding to the snippet visible in | 311 "snippet" field corresponding to the snippet visible in |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 if self._options.verbose: | 486 if self._options.verbose: |
| 471 verbosity = 2 | 487 verbosity = 2 |
| 472 result = unittest.TextTestRunner(verbosity=verbosity).run(pyauto_suite) | 488 result = unittest.TextTestRunner(verbosity=verbosity).run(pyauto_suite) |
| 473 del loaded_tests # Need to destroy test cases before the suite | 489 del loaded_tests # Need to destroy test cases before the suite |
| 474 del pyauto_suite | 490 del pyauto_suite |
| 475 sys.exit(not result.wasSuccessful()) | 491 sys.exit(not result.wasSuccessful()) |
| 476 | 492 |
| 477 | 493 |
| 478 if __name__ == '__main__': | 494 if __name__ == '__main__': |
| 479 Main() | 495 Main() |
| OLD | NEW |