OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """PyAuto: Python Interface to Chromium's Automation Proxy. | 6 """PyAuto: Python Interface to Chromium's Automation Proxy. |
7 | 7 |
8 PyAuto uses swig to expose Automation Proxy interfaces to Python. | 8 PyAuto uses swig to expose Automation Proxy interfaces to Python. |
9 For complete documentation on the functionality available, | 9 For complete documentation on the functionality available, |
10 run pydoc on this file. | 10 run pydoc on this file. |
(...skipping 2028 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2039 'command': 'WaitUntilTranslateComplete', | 2039 'command': 'WaitUntilTranslateComplete', |
2040 'tab_index': tab_index | 2040 'tab_index': tab_index |
2041 } | 2041 } |
2042 # TODO(phajdan.jr): We need a solid automation infrastructure to handle | 2042 # TODO(phajdan.jr): We need a solid automation infrastructure to handle |
2043 # these cases. See crbug.com/53647. | 2043 # these cases. See crbug.com/53647. |
2044 return self.WaitUntil( | 2044 return self.WaitUntil( |
2045 lambda tab_index, window_index: self.GetTranslateInfo( | 2045 lambda tab_index, window_index: self.GetTranslateInfo( |
2046 tab_index=tab_index, window_index=window_index)['page_translated'], | 2046 tab_index=tab_index, window_index=window_index)['page_translated'], |
2047 args=[tab_index, window_index]) | 2047 args=[tab_index, window_index]) |
2048 | 2048 |
2049 def InstallExtension(self, extension_path, with_ui=False, windex=0): | 2049 def InstallExtension(self, extension_path, with_ui=False, from_webstore=None, |
| 2050 windex=0): |
2050 """Installs an extension from the given path. | 2051 """Installs an extension from the given path. |
2051 | 2052 |
2052 The path must be absolute and may be a crx file or an unpacked extension | 2053 The path must be absolute and may be a crx file or an unpacked extension |
2053 directory. Returns the extension ID if successfully installed and loaded. | 2054 directory. Returns the extension ID if successfully installed and loaded. |
2054 Otherwise, throws an exception. The extension must not already be installed. | 2055 Otherwise, throws an exception. The extension must not already be installed. |
2055 | 2056 |
2056 Args: | 2057 Args: |
2057 extension_path: The absolute path to the extension to install. If the | 2058 extension_path: The absolute path to the extension to install. If the |
2058 extension is packed, it must have a .crx extension. | 2059 extension is packed, it must have a .crx extension. |
2059 with_ui: Whether the extension install confirmation UI should be shown. | 2060 with_ui: Whether the extension install confirmation UI should be shown. |
| 2061 from_webstore: If True, forces a .crx extension to be recognized as one |
| 2062 from the webstore. Can be used to force install an extension with |
| 2063 'experimental' permissions. |
2060 windex: Integer index of the browser window to use; defaults to 0 | 2064 windex: Integer index of the browser window to use; defaults to 0 |
2061 (first window). | 2065 (first window). |
2062 | 2066 |
2063 Returns: | 2067 Returns: |
2064 The ID of the installed extension. | 2068 The ID of the installed extension. |
2065 | 2069 |
2066 Raises: | 2070 Raises: |
2067 pyauto_errors.JSONInterfaceError if the automation call returns an error. | 2071 pyauto_errors.JSONInterfaceError if the automation call returns an error. |
2068 """ | 2072 """ |
2069 cmd_dict = { | 2073 cmd_dict = { |
2070 'command': 'InstallExtension', | 2074 'command': 'InstallExtension', |
2071 'path': extension_path, | 2075 'path': extension_path, |
2072 'with_ui': with_ui, | 2076 'with_ui': with_ui, |
2073 'windex': windex, | 2077 'windex': windex, |
2074 } | 2078 } |
| 2079 if from_webstore: |
| 2080 cmd_dict['from_webstore'] = True |
2075 return self._GetResultFromJSONRequest(cmd_dict, windex=None)['id'] | 2081 return self._GetResultFromJSONRequest(cmd_dict, windex=None)['id'] |
2076 | 2082 |
2077 def GetExtensionsInfo(self, windex=0): | 2083 def GetExtensionsInfo(self, windex=0): |
2078 """Returns information about all installed extensions. | 2084 """Returns information about all installed extensions. |
2079 | 2085 |
2080 Args: | 2086 Args: |
2081 windex: Integer index of the browser window to use; defaults to 0 | 2087 windex: Integer index of the browser window to use; defaults to 0 |
2082 (first window). | 2088 (first window). |
2083 | 2089 |
2084 Returns: | 2090 Returns: |
(...skipping 3875 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5960 successful = result.wasSuccessful() | 5966 successful = result.wasSuccessful() |
5961 if not successful: | 5967 if not successful: |
5962 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) | 5968 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) |
5963 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ | 5969 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ |
5964 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) | 5970 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) |
5965 sys.exit(not successful) | 5971 sys.exit(not successful) |
5966 | 5972 |
5967 | 5973 |
5968 if __name__ == '__main__': | 5974 if __name__ == '__main__': |
5969 Main() | 5975 Main() |
OLD | NEW |