| 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 739 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 750 if ret_dict.has_key('error'): | 750 if ret_dict.has_key('error'): |
| 751 raise JSONInterfaceError(ret_dict['error']) | 751 raise JSONInterfaceError(ret_dict['error']) |
| 752 try: | 752 try: |
| 753 f = open(filename) | 753 f = open(filename) |
| 754 all_data = f.read() | 754 all_data = f.read() |
| 755 f.close() | 755 f.close() |
| 756 return all_data | 756 return all_data |
| 757 finally: | 757 finally: |
| 758 shutil.rmtree(tempdir) | 758 shutil.rmtree(tempdir) |
| 759 | 759 |
| 760 def ImportSettings(self, import_from, first_run, import_items): |
| 761 """Import the specified import items from the specified browser. |
| 762 |
| 763 Implements the features available in the "Import Settings" part of the |
| 764 first-run UI dialog. |
| 765 |
| 766 Args: |
| 767 import_from: A string indicating which browser to import from. Possible |
| 768 strings (depending on which browsers are installed on the |
| 769 machine) are: 'Mozilla Firefox', 'Google Toolbar', |
| 770 'Microsoft Internet Explorer', 'Safari' |
| 771 first_run: A boolean indicating whether this is the first run of |
| 772 the browser. |
| 773 If it is not the first run then: |
| 774 1) Bookmarks are only imported to the bookmarks bar if there |
| 775 aren't already bookmarks. |
| 776 2) The bookmark bar is shown. |
| 777 import_items: A list of strings indicating which items to import. |
| 778 Strings that can be in the list are: |
| 779 HISTORY, FAVORITES, PASSWORDS, SEARCH_ENGINES, HOME_PAGE, |
| 780 ALL (note: COOKIES is not supported by the browser yet) |
| 781 Raises: |
| 782 pyauto_errors.JSONInterfaceError if the automation call returns an error. |
| 783 """ |
| 784 cmd_dict = { # Prepare command for the json interface |
| 785 'command': 'ImportSettings', |
| 786 'import_from': import_from, |
| 787 'first_run': first_run, |
| 788 'import_items': import_items |
| 789 } |
| 790 ret_dict = json.loads(self._SendJSONRequest(0, json.dumps(cmd_dict))) |
| 791 if ret_dict.has_key('error'): |
| 792 raise JSONInterfaceError(ret_dict['error']) |
| 793 return ret_dict |
| 794 |
| 760 def ClearBrowsingData(self, to_remove, time_period): | 795 def ClearBrowsingData(self, to_remove, time_period): |
| 761 """Clear the specified browsing data. Implements the features available in | 796 """Clear the specified browsing data. Implements the features available in |
| 762 the "ClearBrowsingData" UI. | 797 the "ClearBrowsingData" UI. |
| 763 | 798 |
| 764 Args: | 799 Args: |
| 765 to_remove: a list of strings indicating which types of browsing data | 800 to_remove: a list of strings indicating which types of browsing data |
| 766 should be removed. Strings that can be in the list are: | 801 should be removed. Strings that can be in the list are: |
| 767 HISTORY, DOWNLOADS, COOKIES, PASSWORDS, FORM_DATA, CACHE | 802 HISTORY, DOWNLOADS, COOKIES, PASSWORDS, FORM_DATA, CACHE |
| 768 time_period: a string indicating the time period for the removal. | 803 time_period: a string indicating the time period for the removal. |
| 769 Possible strings are: | 804 Possible strings are: |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1080 if self._options.verbose: | 1115 if self._options.verbose: |
| 1081 verbosity = 2 | 1116 verbosity = 2 |
| 1082 result = unittest.TextTestRunner(verbosity=verbosity).run(pyauto_suite) | 1117 result = unittest.TextTestRunner(verbosity=verbosity).run(pyauto_suite) |
| 1083 del loaded_tests # Need to destroy test cases before the suite | 1118 del loaded_tests # Need to destroy test cases before the suite |
| 1084 del pyauto_suite | 1119 del pyauto_suite |
| 1085 sys.exit(not result.wasSuccessful()) | 1120 sys.exit(not result.wasSuccessful()) |
| 1086 | 1121 |
| 1087 | 1122 |
| 1088 if __name__ == '__main__': | 1123 if __name__ == '__main__': |
| 1089 Main() | 1124 Main() |
| OLD | NEW |