| 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, with_ui=False): |
| 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. |
| 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 with_ui: Whether the extension install confirmation UI should be shown. |
| 1730 |
| 1731 Returns: |
| 1732 The ID of the installed extension. |
| 1733 |
| 1734 Raises: |
| 1735 pyauto_errors.JSONInterfaceError if the automation call returns an error. |
| 1736 """ |
| 1737 cmd_dict = { |
| 1738 'command': 'InstallExtension', |
| 1739 'path': extension_path, |
| 1740 'with_ui': with_ui |
| 1741 } |
| 1742 return self._GetResultFromJSONRequest(cmd_dict, windex=-1)['id'] |
| 1743 |
| 1719 def GetExtensionsInfo(self): | 1744 def GetExtensionsInfo(self): |
| 1720 """Returns information about all installed extensions. | 1745 """Returns information about all installed extensions. |
| 1721 | 1746 |
| 1722 Returns: | 1747 Returns: |
| 1723 A list of dictionaries representing each of the installed extensions. | 1748 A list of dictionaries representing each of the installed extensions. |
| 1724 Example: | 1749 Example: |
| 1725 [ { u'api_permissions': [u'bookmarks', u'experimental', u'tabs'], | 1750 [ { u'api_permissions': [u'bookmarks', u'experimental', u'tabs'], |
| 1726 u'background_url': u'', | 1751 u'background_url': u'', |
| 1727 u'description': u'Bookmark Manager', | 1752 u'description': u'Bookmark Manager', |
| 1728 u'effective_host_permissions': [u'chrome://favicon/*', | 1753 u'effective_host_permissions': [u'chrome://favicon/*', |
| 1729 u'chrome://resources/*'], | 1754 u'chrome://resources/*'], |
| 1730 u'host_permissions': [u'chrome://favicon/*', u'chrome://resources/*'], | 1755 u'host_permissions': [u'chrome://favicon/*', u'chrome://resources/*'], |
| 1731 u'id': u'eemcgdkfndhakfknompkggombfjjjeno', | 1756 u'id': u'eemcgdkfndhakfknompkggombfjjjeno', |
| 1757 u'is_component': True, |
| 1758 u'is_internal': False, |
| 1732 u'name': u'Bookmark Manager', | 1759 u'name': u'Bookmark Manager', |
| 1733 u'options_url': u'', | 1760 u'options_url': u'', |
| 1734 u'public_key': u'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDQcByy+eN9jza\ | 1761 u'public_key': u'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDQcByy+eN9jza\ |
| 1735 zWF/DPn7NW47sW7lgmpk6eKc0BQM18q8hvEM3zNm2n7HkJv/R6f\ | 1762 zWF/DPn7NW47sW7lgmpk6eKc0BQM18q8hvEM3zNm2n7HkJv/R6f\ |
| 1736 U+X5mtqkDuKvq5skF6qqUF4oEyaleWDFhd1xFwV7JV+/DU7bZ00\ | 1763 U+X5mtqkDuKvq5skF6qqUF4oEyaleWDFhd1xFwV7JV+/DU7bZ00\ |
| 1737 w2+6gzqsabkerFpoP33ZRIw7OviJenP0c0uWqDWF8EGSyMhB3tx\ | 1764 w2+6gzqsabkerFpoP33ZRIw7OviJenP0c0uWqDWF8EGSyMhB3tx\ |
| 1738 qhOtiQIDAQAB', | 1765 qhOtiQIDAQAB', |
| 1739 u'version': u'0.1' }, | 1766 u'version': u'0.1' }, |
| 1740 { u'api_permissions': [...], | 1767 { u'api_permissions': [...], |
| 1741 u'background_url': u'chrome-extension://\ | 1768 u'background_url': u'chrome-extension://\ |
| 1742 lkdedmbpkaiahjjibfdmpoefffnbdkli/\ | 1769 lkdedmbpkaiahjjibfdmpoefffnbdkli/\ |
| 1743 background.html', | 1770 background.html', |
| 1744 u'description': u'Extension which lets you read your Facebook news \ | 1771 u'description': u'Extension which lets you read your Facebook news \ |
| 1745 feed and wall. You can also post status updates.', | 1772 feed and wall. You can also post status updates.', |
| 1746 u'effective_host_permissions': [...], | 1773 u'effective_host_permissions': [...], |
| 1747 u'host_permissions': [...], | 1774 u'host_permissions': [...], |
| 1748 u'id': u'lkdedmbpkaiahjjibfdmpoefffnbdkli', | 1775 u'id': u'lkdedmbpkaiahjjibfdmpoefffnbdkli', |
| 1749 u'name': u'Facebook for Google Chrome', | 1776 u'name': u'Facebook for Google Chrome', |
| 1750 u'options_url': u'', | 1777 u'options_url': u'', |
| 1751 u'public_key': u'...', | 1778 u'public_key': u'...', |
| 1752 u'version': u'2.0.9' | 1779 u'version': u'2.0.9' |
| 1753 u'is_enabled': True, | 1780 u'is_enabled': True, |
| 1754 u'allowed_in_incognito': True} ] | 1781 u'allowed_in_incognito': True} ] |
| 1755 """ | 1782 """ |
| 1756 cmd_dict = { # Prepare command for the json interface | 1783 cmd_dict = { # Prepare command for the json interface |
| 1757 'command': 'GetExtensionsInfo' | 1784 'command': 'GetExtensionsInfo' |
| 1758 } | 1785 } |
| 1759 return self._GetResultFromJSONRequest(cmd_dict)['extensions'] | 1786 return self._GetResultFromJSONRequest(cmd_dict, windex=-1)['extensions'] |
| 1760 | 1787 |
| 1761 def UninstallExtensionById(self, id): | 1788 def UninstallExtensionById(self, id): |
| 1762 """Uninstall the extension with the given id. | 1789 """Uninstall the extension with the given id. |
| 1763 | 1790 |
| 1764 Args: | 1791 Args: |
| 1765 id: The string id of the extension. | 1792 id: The string id of the extension. |
| 1766 | 1793 |
| 1767 Returns: | 1794 Returns: |
| 1768 True, if the extension was successfully uninstalled, or | 1795 True, if the extension was successfully uninstalled, or |
| 1769 False, otherwise. | 1796 False, otherwise. |
| (...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2403 'tab_index': tab_index, | 2430 'tab_index': tab_index, |
| 2404 } | 2431 } |
| 2405 self._GetResultFromJSONRequest(cmd_dict, windex=windex) | 2432 self._GetResultFromJSONRequest(cmd_dict, windex=windex) |
| 2406 | 2433 |
| 2407 def SetTheme(self, crx_file_path): | 2434 def SetTheme(self, crx_file_path): |
| 2408 """Installs the given theme synchronously. | 2435 """Installs the given theme synchronously. |
| 2409 | 2436 |
| 2410 A theme file is a file with a .crx suffix, like an extension. The theme | 2437 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 | 2438 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. | 2439 the theme is installed and will trigger the "theme installed" infobar. |
| 2440 If the install is unsuccessful, will throw an exception. |
| 2413 | 2441 |
| 2414 Uses InstallExtension(). | 2442 Uses InstallExtension(). |
| 2415 | 2443 |
| 2416 Returns: | 2444 Returns: |
| 2417 The ID of the installed theme, on success. The empty string, otherwise. | 2445 The ID of the installed theme. |
| 2446 |
| 2447 Raises: |
| 2448 pyauto_errors.JSONInterfaceError if the automation call returns an error. |
| 2418 """ | 2449 """ |
| 2419 return self.InstallExtension(crx_file_path, True) | 2450 return self.InstallExtension(crx_file_path, True) |
| 2420 | 2451 |
| 2421 def WaitUntilDownloadedThemeSet(self, theme_name): | 2452 def WaitUntilDownloadedThemeSet(self, theme_name): |
| 2422 """Waits until the theme has been set. | 2453 """Waits until the theme has been set. |
| 2423 | 2454 |
| 2424 This should not be called after SetTheme(). It only needs to be called after | 2455 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). | 2456 downloading a theme file (which will automatically set the theme). |
| 2426 | 2457 |
| 2427 Uses WaitUntil so timeout is capped by automation timeout. | 2458 Uses WaitUntil so timeout is capped by automation timeout. |
| (...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3096 """ | 3127 """ |
| 3097 cmd_dict = { | 3128 cmd_dict = { |
| 3098 'command': 'GetNTPInfo', | 3129 'command': 'GetNTPInfo', |
| 3099 } | 3130 } |
| 3100 return self._GetResultFromJSONRequest(cmd_dict) | 3131 return self._GetResultFromJSONRequest(cmd_dict) |
| 3101 | 3132 |
| 3102 def _CheckNTPThumbnailShown(self, thumbnail): | 3133 def _CheckNTPThumbnailShown(self, thumbnail): |
| 3103 if self.GetNTPThumbnailIndex(thumbnail) == -1: | 3134 if self.GetNTPThumbnailIndex(thumbnail) == -1: |
| 3104 raise NTPThumbnailNotShownError() | 3135 raise NTPThumbnailNotShownError() |
| 3105 | 3136 |
| 3106 def InstallApp(self, app_crx_file_path): | |
| 3107 """Installs the specified app synchronously. | |
| 3108 | |
| 3109 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 | |
| 3111 return until the app is installed. | |
| 3112 | |
| 3113 Returns: | |
| 3114 The ID of the installed app, on success. The empty string, otherwise. | |
| 3115 """ | |
| 3116 return self.InstallExtension(app_crx_file_path, False) | |
| 3117 | |
| 3118 def UninstallApp(self, app_id): | |
| 3119 """Uninstalls the specified app synchronously. | |
| 3120 | |
| 3121 Args: | |
| 3122 app_id: The string ID of the app to uninstall. It can be retrieved | |
| 3123 through the call to GetNTPApps above. | |
| 3124 | |
| 3125 Returns: | |
| 3126 True, if the app was successfully uninstalled, or | |
| 3127 False, otherwise. | |
| 3128 """ | |
| 3129 return self.UninstallExtensionById(app_id) | |
| 3130 | |
| 3131 def LaunchApp(self, app_id, windex=0): | 3137 def LaunchApp(self, app_id, windex=0): |
| 3132 """Opens the New Tab Page and launches the specified app from it. | 3138 """Opens the New Tab Page and launches the specified app from it. |
| 3133 | 3139 |
| 3134 This method will not return until after the contents of a new tab for the | 3140 This method will not return until after the contents of a new tab for the |
| 3135 launched app have stopped loading. | 3141 launched app have stopped loading. |
| 3136 | 3142 |
| 3137 Args: | 3143 Args: |
| 3138 app_id: The string ID of the app to launch. | 3144 app_id: The string ID of the app to launch. |
| 3139 windex: The index of the browser window to work on. Defaults to 0 (the | 3145 windex: The index of the browser window to work on. Defaults to 0 (the |
| 3140 first window). | 3146 first window). |
| (...skipping 1641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4782 successful = result.wasSuccessful() | 4788 successful = result.wasSuccessful() |
| 4783 if not successful: | 4789 if not successful: |
| 4784 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) | 4790 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) |
| 4785 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ | 4791 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ |
| 4786 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) | 4792 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) |
| 4787 sys.exit(not successful) | 4793 sys.exit(not successful) |
| 4788 | 4794 |
| 4789 | 4795 |
| 4790 if __name__ == '__main__': | 4796 if __name__ == '__main__': |
| 4791 Main() | 4797 Main() |
| OLD | NEW |