Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Side by Side Diff: chrome/test/pyautolib/pyauto.py

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

Powered by Google App Engine
This is Rietveld 408576698