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 1772 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1783 allow_in_incognito: A boolean, allow extension in incognito. | 1783 allow_in_incognito: A boolean, allow extension in incognito. |
1784 """ | 1784 """ |
1785 cmd_dict = { # Prepare command for the json interface | 1785 cmd_dict = { # Prepare command for the json interface |
1786 'command': 'SetExtensionStateById', | 1786 'command': 'SetExtensionStateById', |
1787 'id': id, | 1787 'id': id, |
1788 'enable': enable, | 1788 'enable': enable, |
1789 'allow_in_incognito': allow_in_incognito, | 1789 'allow_in_incognito': allow_in_incognito, |
1790 } | 1790 } |
1791 self._GetResultFromJSONRequest(cmd_dict) | 1791 self._GetResultFromJSONRequest(cmd_dict) |
1792 | 1792 |
| 1793 def TriggerPageActionById(self, id, windex=0): |
| 1794 """Trigger page action asynchronously in the active tab. |
| 1795 |
| 1796 The page action icon must be displayed before invoking this function. |
| 1797 |
| 1798 Args: |
| 1799 id: The string id of the extension. |
| 1800 windex: Integer index of the browser window to use; defaults to 0 |
| 1801 (first window). |
| 1802 """ |
| 1803 cmd_dict = { # Prepare command for the json interface |
| 1804 'command': 'TriggerPageActionById', |
| 1805 'id': id, |
| 1806 'windex': windex, |
| 1807 } |
| 1808 self._GetResultFromJSONRequest(cmd_dict, windex=windex) |
| 1809 |
| 1810 def TriggerBrowserActionById(self, id, windex=0): |
| 1811 """Trigger browser action asynchronously in the active tab. |
| 1812 |
| 1813 Args: |
| 1814 id: The string id of the extension. |
| 1815 windex: Integer index of the browser window to use; defaults to 0 |
| 1816 (first window). |
| 1817 """ |
| 1818 cmd_dict = { # Prepare command for the json interface |
| 1819 'command': 'TriggerBrowserActionById', |
| 1820 'id': id, |
| 1821 'windex': windex, |
| 1822 } |
| 1823 self._GetResultFromJSONRequest(cmd_dict, windex=windex) |
| 1824 |
1793 def UpdateExtensionsNow(self): | 1825 def UpdateExtensionsNow(self): |
1794 """Auto-updates installed extensions. | 1826 """Auto-updates installed extensions. |
1795 | 1827 |
1796 Waits until all extensions are updated, loaded, and ready for use. | 1828 Waits until all extensions are updated, loaded, and ready for use. |
1797 This is equivalent to clicking the "Update extensions now" button on the | 1829 This is equivalent to clicking the "Update extensions now" button on the |
1798 chrome://extensions page. | 1830 chrome://extensions page. |
1799 | 1831 |
1800 Raises: | 1832 Raises: |
1801 pyauto_errors.JSONInterfaceError if the automation returns an error. | 1833 pyauto_errors.JSONInterfaceError if the automation returns an error. |
1802 """ | 1834 """ |
(...skipping 10 matching lines...) Expand all Loading... |
1813 If there are more than one matching extension view, return one at random. | 1845 If there are more than one matching extension view, return one at random. |
1814 Uses WaitUntil so timeout is capped by automation timeout. | 1846 Uses WaitUntil so timeout is capped by automation timeout. |
1815 Refer to extension_view dictionary returned in GetBrowserInfo() | 1847 Refer to extension_view dictionary returned in GetBrowserInfo() |
1816 for sample input/output values. | 1848 for sample input/output values. |
1817 | 1849 |
1818 Args: | 1850 Args: |
1819 name: (optional) Name of the extension. | 1851 name: (optional) Name of the extension. |
1820 extension_id: (optional) ID of the extension. | 1852 extension_id: (optional) ID of the extension. |
1821 url: (optional) URL of the extension view. | 1853 url: (optional) URL of the extension view. |
1822 view_type: (optional) Type of the extension view. | 1854 view_type: (optional) Type of the extension view. |
| 1855 [EXTENSION_BACKGROUND_PAGE|EXTENSION_POPUP|EXTENSION_INFOBAR| |
| 1856 EXTENSION_DIALOG] |
1823 | 1857 |
1824 Returns: | 1858 Returns: |
1825 The 'view' property of the extension view. | 1859 The 'view' property of the extension view. |
1826 None, if no view loaded. | 1860 None, if no view loaded. |
1827 | 1861 |
1828 Raises: | 1862 Raises: |
1829 pyauto_errors.JSONInterfaceError if the automation returns an error. | 1863 pyauto_errors.JSONInterfaceError if the automation returns an error. |
1830 """ | 1864 """ |
1831 def _GetExtensionViewLoaded(): | 1865 def _GetExtensionViewLoaded(): |
1832 extension_views = self.GetBrowserInfo()['extension_views'] | 1866 extension_views = self.GetBrowserInfo()['extension_views'] |
(...skipping 2949 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4782 successful = result.wasSuccessful() | 4816 successful = result.wasSuccessful() |
4783 if not successful: | 4817 if not successful: |
4784 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) | 4818 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) |
4785 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ | 4819 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ |
4786 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) | 4820 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) |
4787 sys.exit(not successful) | 4821 sys.exit(not successful) |
4788 | 4822 |
4789 | 4823 |
4790 if __name__ == '__main__': | 4824 if __name__ == '__main__': |
4791 Main() | 4825 Main() |
OLD | NEW |