OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 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 1470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1481 u'command_line_string': "COMMAND_LINE_STRING --WITH-FLAGS", | 1481 u'command_line_string': "COMMAND_LINE_STRING --WITH-FLAGS", |
1482 u'branding': 'Chromium', | 1482 u'branding': 'Chromium', |
1483 u'is_official': False,} | 1483 u'is_official': False,} |
1484 # The order of the windows and tabs listed here will be the same as | 1484 # The order of the windows and tabs listed here will be the same as |
1485 # what shows up on screen. | 1485 # what shows up on screen. |
1486 u'windows': [ { u'index': 0, | 1486 u'windows': [ { u'index': 0, |
1487 u'height': 1134, | 1487 u'height': 1134, |
1488 u'incognito': False, | 1488 u'incognito': False, |
1489 u'profile_path': u'Default', | 1489 u'profile_path': u'Default', |
1490 u'fullscreen': False, | 1490 u'fullscreen': False, |
| 1491 u'visible_page_actions': |
| 1492 [u'dgcoklnmbeljaehamekjpeidmbicddfj', |
| 1493 u'osfcklnfasdofpcldmalwpicslasdfgd'] |
1491 u'selected_tab': 0, | 1494 u'selected_tab': 0, |
1492 u'tabs': [ { | 1495 u'tabs': [ { |
1493 u'index': 0, | 1496 u'index': 0, |
1494 u'infobars': [], | 1497 u'infobars': [], |
1495 u'pinned': True, | 1498 u'pinned': True, |
1496 u'renderer_pid': 93747, | 1499 u'renderer_pid': 93747, |
1497 u'url': u'http://www.google.com/' }, { | 1500 u'url': u'http://www.google.com/' }, { |
1498 u'index': 1, | 1501 u'index': 1, |
1499 u'infobars': [], | 1502 u'infobars': [], |
1500 u'pinned': False, | 1503 u'pinned': False, |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1830 allow_in_incognito: A boolean, allow extension in incognito. | 1833 allow_in_incognito: A boolean, allow extension in incognito. |
1831 """ | 1834 """ |
1832 cmd_dict = { # Prepare command for the json interface | 1835 cmd_dict = { # Prepare command for the json interface |
1833 'command': 'SetExtensionStateById', | 1836 'command': 'SetExtensionStateById', |
1834 'id': id, | 1837 'id': id, |
1835 'enable': enable, | 1838 'enable': enable, |
1836 'allow_in_incognito': allow_in_incognito, | 1839 'allow_in_incognito': allow_in_incognito, |
1837 } | 1840 } |
1838 self._GetResultFromJSONRequest(cmd_dict) | 1841 self._GetResultFromJSONRequest(cmd_dict) |
1839 | 1842 |
| 1843 def TriggerPageActionById(self, id, windex=0): |
| 1844 """Trigger page action asynchronously in the active tab. |
| 1845 |
| 1846 The page action icon must be displayed before invoking this function. |
| 1847 |
| 1848 Args: |
| 1849 id: The string id of the extension. |
| 1850 windex: Integer index of the browser window to use; defaults to 0 |
| 1851 (first window). |
| 1852 """ |
| 1853 cmd_dict = { # Prepare command for the json interface |
| 1854 'command': 'TriggerPageActionById', |
| 1855 'id': id, |
| 1856 'windex': windex, |
| 1857 } |
| 1858 self._GetResultFromJSONRequest(cmd_dict, windex=windex) |
| 1859 |
| 1860 def TriggerBrowserActionById(self, id, windex=0): |
| 1861 """Trigger browser action asynchronously in the active tab. |
| 1862 |
| 1863 Args: |
| 1864 id: The string id of the extension. |
| 1865 windex: Integer index of the browser window to use; defaults to 0 |
| 1866 (first window). |
| 1867 """ |
| 1868 cmd_dict = { # Prepare command for the json interface |
| 1869 'command': 'TriggerBrowserActionById', |
| 1870 'id': id, |
| 1871 'windex': windex, |
| 1872 } |
| 1873 self._GetResultFromJSONRequest(cmd_dict, windex=windex) |
| 1874 |
1840 def UpdateExtensionsNow(self): | 1875 def UpdateExtensionsNow(self): |
1841 """Auto-updates installed extensions. | 1876 """Auto-updates installed extensions. |
1842 | 1877 |
1843 Waits until all extensions are updated, loaded, and ready for use. | 1878 Waits until all extensions are updated, loaded, and ready for use. |
1844 This is equivalent to clicking the "Update extensions now" button on the | 1879 This is equivalent to clicking the "Update extensions now" button on the |
1845 chrome://extensions page. | 1880 chrome://extensions page. |
1846 | 1881 |
1847 Raises: | 1882 Raises: |
1848 pyauto_errors.JSONInterfaceError if the automation returns an error. | 1883 pyauto_errors.JSONInterfaceError if the automation returns an error. |
1849 """ | 1884 """ |
(...skipping 10 matching lines...) Expand all Loading... |
1860 If there are more than one matching extension view, return one at random. | 1895 If there are more than one matching extension view, return one at random. |
1861 Uses WaitUntil so timeout is capped by automation timeout. | 1896 Uses WaitUntil so timeout is capped by automation timeout. |
1862 Refer to extension_view dictionary returned in GetBrowserInfo() | 1897 Refer to extension_view dictionary returned in GetBrowserInfo() |
1863 for sample input/output values. | 1898 for sample input/output values. |
1864 | 1899 |
1865 Args: | 1900 Args: |
1866 name: (optional) Name of the extension. | 1901 name: (optional) Name of the extension. |
1867 extension_id: (optional) ID of the extension. | 1902 extension_id: (optional) ID of the extension. |
1868 url: (optional) URL of the extension view. | 1903 url: (optional) URL of the extension view. |
1869 view_type: (optional) Type of the extension view. | 1904 view_type: (optional) Type of the extension view. |
| 1905 ['EXTENSION_BACKGROUND_PAGE'|'EXTENSION_POPUP'|'EXTENSION_INFOBAR'| |
| 1906 'EXTENSION_DIALOG'] |
1870 | 1907 |
1871 Returns: | 1908 Returns: |
1872 The 'view' property of the extension view. | 1909 The 'view' property of the extension view. |
1873 None, if no view loaded. | 1910 None, if no view loaded. |
1874 | 1911 |
1875 Raises: | 1912 Raises: |
1876 pyauto_errors.JSONInterfaceError if the automation returns an error. | 1913 pyauto_errors.JSONInterfaceError if the automation returns an error. |
1877 """ | 1914 """ |
1878 def _GetExtensionViewLoaded(): | 1915 def _GetExtensionViewLoaded(): |
1879 extension_views = self.GetBrowserInfo()['extension_views'] | 1916 extension_views = self.GetBrowserInfo()['extension_views'] |
(...skipping 2922 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4802 successful = result.wasSuccessful() | 4839 successful = result.wasSuccessful() |
4803 if not successful: | 4840 if not successful: |
4804 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) | 4841 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) |
4805 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ | 4842 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ |
4806 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) | 4843 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) |
4807 sys.exit(not successful) | 4844 sys.exit(not successful) |
4808 | 4845 |
4809 | 4846 |
4810 if __name__ == '__main__': | 4847 if __name__ == '__main__': |
4811 Main() | 4848 Main() |
OLD | NEW |