| 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 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 return ret_dict | 381 return ret_dict |
| 382 | 382 |
| 383 def GetBookmarkModel(self): | 383 def GetBookmarkModel(self): |
| 384 """Return the bookmark model as a BookmarkModel object. | 384 """Return the bookmark model as a BookmarkModel object. |
| 385 | 385 |
| 386 This is a snapshot of the bookmark model; it is not a proxy and | 386 This is a snapshot of the bookmark model; it is not a proxy and |
| 387 does not get updated as the bookmark model changes. | 387 does not get updated as the bookmark model changes. |
| 388 """ | 388 """ |
| 389 return bookmark_model.BookmarkModel(self._GetBookmarksAsJSON()) | 389 return bookmark_model.BookmarkModel(self._GetBookmarksAsJSON()) |
| 390 | 390 |
| 391 def GetDownloadsInfo(self): | 391 def GetDownloadsInfo(self, windex=0): |
| 392 """Return info about downloads. | 392 """Return info about downloads. |
| 393 | 393 |
| 394 This includes all the downloads recognized by the history system. | 394 This includes all the downloads recognized by the history system. |
| 395 | 395 |
| 396 Returns: | 396 Returns: |
| 397 an instance of downloads_info.DownloadInfo | 397 an instance of downloads_info.DownloadInfo |
| 398 """ | 398 """ |
| 399 return download_info.DownloadInfo( | 399 return download_info.DownloadInfo( |
| 400 self._SendJSONRequest(0, json.dumps({'command': 'GetDownloadsInfo'}))) | 400 self._SendJSONRequest( |
| 401 windex, json.dumps({'command': 'GetDownloadsInfo'}))) |
| 401 | 402 |
| 402 def GetOmniboxInfo(self, windex=0): | 403 def GetOmniboxInfo(self, windex=0): |
| 403 """Return info about Omnibox. | 404 """Return info about Omnibox. |
| 404 | 405 |
| 405 This represents a snapshot of the omnibox. If you expect changes | 406 This represents a snapshot of the omnibox. If you expect changes |
| 406 you need to call this method again to get a fresh snapshot. | 407 you need to call this method again to get a fresh snapshot. |
| 407 Note that this DOES NOT shift focus to the omnibox; you've to ensure that | 408 Note that this DOES NOT shift focus to the omnibox; you've to ensure that |
| 408 the omnibox is in focus or else you won't get any interesting info. | 409 the omnibox is in focus or else you won't get any interesting info. |
| 409 | 410 |
| 410 It's OK to call this even when the omnibox popup is not showing. In this | 411 It's OK to call this even when the omnibox popup is not showing. In this |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 right key. It's useful to dump the preferences first to determine | 651 right key. It's useful to dump the preferences first to determine |
| 651 what type is expected for a particular preference path. | 652 what type is expected for a particular preference path. |
| 652 """ | 653 """ |
| 653 cmd_dict = { | 654 cmd_dict = { |
| 654 'command': 'SetPrefs', | 655 'command': 'SetPrefs', |
| 655 'path': path, | 656 'path': path, |
| 656 'value': value, | 657 'value': value, |
| 657 } | 658 } |
| 658 self._GetResultFromJSONRequest(cmd_dict) | 659 self._GetResultFromJSONRequest(cmd_dict) |
| 659 | 660 |
| 660 def WaitForAllDownloadsToComplete(self): | 661 def WaitForAllDownloadsToComplete(self, windex=0): |
| 661 """Wait for all downloads to complete. | 662 """Wait for all downloads to complete. |
| 662 | 663 |
| 663 Note: This method does not work for dangerous downloads. Use | 664 Note: This method does not work for dangerous downloads. Use |
| 664 WaitForGivenDownloadsToComplete (below) instead. | 665 WaitForGivenDownloadsToComplete (below) instead. |
| 665 """ | 666 """ |
| 666 self._GetResultFromJSONRequest({'command': 'WaitForAllDownloadsToComplete'}) | 667 cmd_dict = {'command': 'WaitForAllDownloadsToComplete'} |
| 668 self._GetResultFromJSONRequest(cmd_dict, windex=windex) |
| 667 | 669 |
| 668 def WaitForDownloadToComplete(self, download_path, timeout=-1): | 670 def WaitForDownloadToComplete(self, download_path, timeout=-1): |
| 669 """Wait for the given downloads to complete. | 671 """Wait for the given downloads to complete. |
| 670 | 672 |
| 671 This method works for dangerous downloads as well as regular downloads. | 673 This method works for dangerous downloads as well as regular downloads. |
| 672 | 674 |
| 673 Args: | 675 Args: |
| 674 download_path: The path to the final download. This is only necessary for | 676 download_path: The path to the final download. This is only necessary for |
| 675 the workaround described in the comments below and should | 677 the workaround described in the comments below and should |
| 676 be removed when downloads are re-implemented. | 678 be removed when downloads are re-implemented. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 721 u'url': u'file://url/to/file.txt' | 723 u'url': u'file://url/to/file.txt' |
| 722 } | 724 } |
| 723 """ | 725 """ |
| 724 cmd_dict = { # Prepare command for the json interface | 726 cmd_dict = { # Prepare command for the json interface |
| 725 'command': 'PerformActionOnDownload', | 727 'command': 'PerformActionOnDownload', |
| 726 'id': id, | 728 'id': id, |
| 727 'action': action | 729 'action': action |
| 728 } | 730 } |
| 729 return self._GetResultFromJSONRequest(cmd_dict, windex=window_index) | 731 return self._GetResultFromJSONRequest(cmd_dict, windex=window_index) |
| 730 | 732 |
| 731 def DownloadAndWaitForStart(self, file_url): | 733 def DownloadAndWaitForStart(self, file_url, windex=0): |
| 732 """Trigger download for the given url and wait for downloads to start. | 734 """Trigger download for the given url and wait for downloads to start. |
| 733 | 735 |
| 734 It waits for download by looking at the download info from Chrome, so | 736 It waits for download by looking at the download info from Chrome, so |
| 735 anything which isn't registered by the history service won't be noticed. | 737 anything which isn't registered by the history service won't be noticed. |
| 736 This is not thread-safe, but it's fine to call this method to start | 738 This is not thread-safe, but it's fine to call this method to start |
| 737 downloading multiple files in parallel. That is after starting a | 739 downloading multiple files in parallel. That is after starting a |
| 738 download, it's fine to start another one even if the first one hasn't | 740 download, it's fine to start another one even if the first one hasn't |
| 739 completed. | 741 completed. |
| 740 """ | 742 """ |
| 741 num_downloads = len(self.GetDownloadsInfo().Downloads()) | 743 try: |
| 742 self.NavigateToURL(file_url) # Trigger download. | 744 num_downloads = len(self.GetDownloadsInfo(windex).Downloads()) |
| 745 except JSONInterfaceError: |
| 746 num_downloads = 0 |
| 747 |
| 748 self.NavigateToURL(file_url, windex) # Trigger download. |
| 743 # It might take a while for the download to kick in, hold on until then. | 749 # It might take a while for the download to kick in, hold on until then. |
| 744 self.assertTrue(self.WaitUntil( | 750 self.assertTrue(self.WaitUntil( |
| 745 lambda: len(self.GetDownloadsInfo().Downloads()) == num_downloads + 1)) | 751 lambda: len(self.GetDownloadsInfo(windex).Downloads()) > |
| 752 num_downloads)) |
| 746 | 753 |
| 747 def SetWindowDimensions( | 754 def SetWindowDimensions( |
| 748 self, x=None, y=None, width=None, height=None, windex=0): | 755 self, x=None, y=None, width=None, height=None, windex=0): |
| 749 """Set window dimensions. | 756 """Set window dimensions. |
| 750 | 757 |
| 751 All args are optional and current values will be preserved. | 758 All args are optional and current values will be preserved. |
| 752 Arbitrarily large values will be handled gracefully by the browser. | 759 Arbitrarily large values will be handled gracefully by the browser. |
| 753 | 760 |
| 754 Args: | 761 Args: |
| 755 x: window origin x | 762 x: window origin x |
| (...skipping 1601 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2357 if self._options.verbose: | 2364 if self._options.verbose: |
| 2358 verbosity = 2 | 2365 verbosity = 2 |
| 2359 result = PyAutoTextTestRuner(verbosity=verbosity).run(pyauto_suite) | 2366 result = PyAutoTextTestRuner(verbosity=verbosity).run(pyauto_suite) |
| 2360 del loaded_tests # Need to destroy test cases before the suite | 2367 del loaded_tests # Need to destroy test cases before the suite |
| 2361 del pyauto_suite | 2368 del pyauto_suite |
| 2362 sys.exit(not result.wasSuccessful()) | 2369 sys.exit(not result.wasSuccessful()) |
| 2363 | 2370 |
| 2364 | 2371 |
| 2365 if __name__ == '__main__': | 2372 if __name__ == '__main__': |
| 2366 Main() | 2373 Main() |
| OLD | NEW |