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 1698 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1709 """ | 1709 """ |
| 1710 cmd_dict = { # Prepare command for the json interface | 1710 cmd_dict = { # Prepare command for the json interface |
| 1711 'command': 'SelectTranslateOption', | 1711 'command': 'SelectTranslateOption', |
| 1712 'tab_index': tab_index, | 1712 'tab_index': tab_index, |
| 1713 'option': 'set_target_language', | 1713 'option': 'set_target_language', |
| 1714 'target_language': new_language | 1714 'target_language': new_language |
| 1715 } | 1715 } |
| 1716 return self._GetResultFromJSONRequest( | 1716 return self._GetResultFromJSONRequest( |
| 1717 cmd_dict, windex=window_index)['translation_success'] | 1717 cmd_dict, windex=window_index)['translation_success'] |
| 1718 | 1718 |
| 1719 def InstallExtension(self, extension_path): | |
| 1720 """Installs an extension from the given path. | |
| 1721 | |
| 1722 The path must be absolute and may be a crx file or an unpacked extension | |
| 1723 directory. Returns the extension ID if successfully installed and loaded. | |
| 1724 Otherwise, throws an exception. The extension must not already be installed. | |
|
dennis_jeffrey
2011/11/22 23:32:16
Mention the possibility of an exception in the "Ra
kkania
2011/11/23 17:31:23
Done.
| |
| 1725 | |
| 1726 Args: | |
| 1727 extension_path: The absolute path to the extension to install. If the | |
| 1728 extension is packed, it must have a .crx extension. | |
| 1729 | |
| 1730 Returns: | |
| 1731 The ID of the extension. | |
|
dennis_jeffrey
2011/11/22 23:32:16
'of the installed extension'
kkania
2011/11/23 17:31:23
Done.
| |
| 1732 """ | |
| 1733 cmd_dict = { | |
| 1734 'command': 'InstallExtension', | |
| 1735 'path': extension_path | |
| 1736 } | |
| 1737 return self._GetResultFromJSONRequest(cmd_dict, windex=-1)['id'] | |
| 1738 | |
| 1719 def GetExtensionsInfo(self): | 1739 def GetExtensionsInfo(self): |
| 1720 """Returns information about all installed extensions. | 1740 """Returns information about all installed extensions. |
| 1721 | 1741 |
| 1722 Returns: | 1742 Returns: |
| 1723 A list of dictionaries representing each of the installed extensions. | 1743 A list of dictionaries representing each of the installed extensions. |
| 1724 Example: | 1744 Example: |
|
dennis_jeffrey
2011/11/22 23:32:16
Maybe we could modify this example now that there
kkania
2011/11/23 17:31:23
Done.
| |
| 1725 [ { u'api_permissions': [u'bookmarks', u'experimental', u'tabs'], | 1745 [ { u'api_permissions': [u'bookmarks', u'experimental', u'tabs'], |
| 1726 u'background_url': u'', | 1746 u'background_url': u'', |
| 1727 u'description': u'Bookmark Manager', | 1747 u'description': u'Bookmark Manager', |
| 1728 u'effective_host_permissions': [u'chrome://favicon/*', | 1748 u'effective_host_permissions': [u'chrome://favicon/*', |
| 1729 u'chrome://resources/*'], | 1749 u'chrome://resources/*'], |
| 1730 u'host_permissions': [u'chrome://favicon/*', u'chrome://resources/*'], | 1750 u'host_permissions': [u'chrome://favicon/*', u'chrome://resources/*'], |
| 1731 u'id': u'eemcgdkfndhakfknompkggombfjjjeno', | 1751 u'id': u'eemcgdkfndhakfknompkggombfjjjeno', |
| 1732 u'name': u'Bookmark Manager', | 1752 u'name': u'Bookmark Manager', |
| 1733 u'options_url': u'', | 1753 u'options_url': u'', |
| 1734 u'public_key': u'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDQcByy+eN9jza\ | 1754 u'public_key': u'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDQcByy+eN9jza\ |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 1749 u'name': u'Facebook for Google Chrome', | 1769 u'name': u'Facebook for Google Chrome', |
| 1750 u'options_url': u'', | 1770 u'options_url': u'', |
| 1751 u'public_key': u'...', | 1771 u'public_key': u'...', |
| 1752 u'version': u'2.0.9' | 1772 u'version': u'2.0.9' |
| 1753 u'is_enabled': True, | 1773 u'is_enabled': True, |
| 1754 u'allowed_in_incognito': True} ] | 1774 u'allowed_in_incognito': True} ] |
| 1755 """ | 1775 """ |
| 1756 cmd_dict = { # Prepare command for the json interface | 1776 cmd_dict = { # Prepare command for the json interface |
| 1757 'command': 'GetExtensionsInfo' | 1777 'command': 'GetExtensionsInfo' |
| 1758 } | 1778 } |
| 1759 return self._GetResultFromJSONRequest(cmd_dict)['extensions'] | 1779 return self._GetResultFromJSONRequest(cmd_dict, windex=-1)['extensions'] |
| 1760 | 1780 |
| 1761 def UninstallExtensionById(self, id): | 1781 def UninstallExtensionById(self, id): |
| 1762 """Uninstall the extension with the given id. | 1782 """Uninstall the extension with the given id. |
| 1763 | 1783 |
| 1764 Args: | 1784 Args: |
| 1765 id: The string id of the extension. | 1785 id: The string id of the extension. |
| 1766 | 1786 |
| 1767 Returns: | 1787 Returns: |
| 1768 True, if the extension was successfully uninstalled, or | 1788 True, if the extension was successfully uninstalled, or |
| 1769 False, otherwise. | 1789 False, otherwise. |
| (...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2403 'tab_index': tab_index, | 2423 'tab_index': tab_index, |
| 2404 } | 2424 } |
| 2405 self._GetResultFromJSONRequest(cmd_dict, windex=windex) | 2425 self._GetResultFromJSONRequest(cmd_dict, windex=windex) |
| 2406 | 2426 |
| 2407 def SetTheme(self, crx_file_path): | 2427 def SetTheme(self, crx_file_path): |
| 2408 """Installs the given theme synchronously. | 2428 """Installs the given theme synchronously. |
| 2409 | 2429 |
| 2410 A theme file is a file with a .crx suffix, like an extension. The theme | 2430 A theme file is a file with a .crx suffix, like an extension. The theme |
| 2411 file must be specified with an absolute path. This method call waits until | 2431 file must be specified with an absolute path. This method call waits until |
| 2412 the theme is installed and will trigger the "theme installed" infobar. | 2432 the theme is installed and will trigger the "theme installed" infobar. |
| 2433 If the install is unsuccessful, will throw an exception. | |
|
dennis_jeffrey
2011/11/22 23:32:16
Mention this in the "Raises:" section of this docs
kkania
2011/11/23 17:31:23
Done.
| |
| 2413 | 2434 |
| 2414 Uses InstallExtension(). | 2435 Uses InstallExtension(). |
| 2415 | 2436 |
| 2416 Returns: | 2437 Returns: |
| 2417 The ID of the installed theme, on success. The empty string, otherwise. | 2438 The ID of the installed theme. |
| 2418 """ | 2439 """ |
| 2419 return self.InstallExtension(crx_file_path, True) | 2440 return self.InstallExtension(crx_file_path) |
| 2420 | 2441 |
| 2421 def WaitUntilDownloadedThemeSet(self, theme_name): | 2442 def WaitUntilDownloadedThemeSet(self, theme_name): |
| 2422 """Waits until the theme has been set. | 2443 """Waits until the theme has been set. |
| 2423 | 2444 |
| 2424 This should not be called after SetTheme(). It only needs to be called after | 2445 This should not be called after SetTheme(). It only needs to be called after |
| 2425 downloading a theme file (which will automatically set the theme). | 2446 downloading a theme file (which will automatically set the theme). |
| 2426 | 2447 |
| 2427 Uses WaitUntil so timeout is capped by automation timeout. | 2448 Uses WaitUntil so timeout is capped by automation timeout. |
| 2428 | 2449 |
| 2429 Args: | 2450 Args: |
| (...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3096 """ | 3117 """ |
| 3097 cmd_dict = { | 3118 cmd_dict = { |
| 3098 'command': 'GetNTPInfo', | 3119 'command': 'GetNTPInfo', |
| 3099 } | 3120 } |
| 3100 return self._GetResultFromJSONRequest(cmd_dict) | 3121 return self._GetResultFromJSONRequest(cmd_dict) |
| 3101 | 3122 |
| 3102 def _CheckNTPThumbnailShown(self, thumbnail): | 3123 def _CheckNTPThumbnailShown(self, thumbnail): |
| 3103 if self.GetNTPThumbnailIndex(thumbnail) == -1: | 3124 if self.GetNTPThumbnailIndex(thumbnail) == -1: |
| 3104 raise NTPThumbnailNotShownError() | 3125 raise NTPThumbnailNotShownError() |
| 3105 | 3126 |
| 3106 def InstallApp(self, app_crx_file_path): | 3127 def InstallApp(self, app_crx_file_path): |
|
dennis_jeffrey
2011/11/22 23:32:16
I think we should get rid of this function now (an
kkania
2011/11/23 17:31:23
Done.
| |
| 3107 """Installs the specified app synchronously. | 3128 """Installs the specified app synchronously. |
| 3108 | 3129 |
| 3109 An app file is a file with a .crx suffix, like an extension or theme. The | 3130 An app file is a file with a .crx suffix, like an extension or theme. The |
| 3110 app file must be specified with an absolute path. This method will not | 3131 app file must be specified with an absolute path. This method will not |
| 3111 return until the app is installed. | 3132 return until the app is installed. |
| 3112 | 3133 |
| 3113 Returns: | 3134 Returns: |
| 3114 The ID of the installed app, on success. The empty string, otherwise. | 3135 The ID of the installed app, on success. The empty string, otherwise. |
| 3115 """ | 3136 """ |
| 3116 return self.InstallExtension(app_crx_file_path, False) | 3137 return self.InstallExtension(app_crx_file_path, False) |
| (...skipping 1665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4782 successful = result.wasSuccessful() | 4803 successful = result.wasSuccessful() |
| 4783 if not successful: | 4804 if not successful: |
| 4784 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) | 4805 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) |
| 4785 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ | 4806 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ |
| 4786 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) | 4807 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) |
| 4787 sys.exit(not successful) | 4808 sys.exit(not successful) |
| 4788 | 4809 |
| 4789 | 4810 |
| 4790 if __name__ == '__main__': | 4811 if __name__ == '__main__': |
| 4791 Main() | 4812 Main() |
| OLD | NEW |