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

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

Issue 10804038: Convert cookie and download automation commands to the JSON interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 4 months 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
« no previous file with comments | « chrome/test/automation/tab_proxy.cc ('k') | chrome/test/pyautolib/pyautolib.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1512 matching lines...) Expand 10 before | Expand all | Expand 10 after
1523 1523
1524 Args: 1524 Args:
1525 windex: the index of the browser window to work on. 1525 windex: the index of the browser window to work on.
1526 Default: 0 (first window) 1526 Default: 0 (first window)
1527 """ 1527 """
1528 cmd_dict = { 1528 cmd_dict = {
1529 'command': 'OmniboxAcceptInput', 1529 'command': 'OmniboxAcceptInput',
1530 } 1530 }
1531 self._GetResultFromJSONRequest(cmd_dict, windex=windex) 1531 self._GetResultFromJSONRequest(cmd_dict, windex=windex)
1532 1532
1533 def GetCookie(self, url, windex=0):
1534 """Get the value of the cookie at url in context of the specified browser.
1535
1536 Args:
1537 url: Either a GURL object or url string specifing the cookie url.
1538 windex: The index of the browser window to work on. Defaults to the first
1539 window.
1540
1541 Raises:
1542 pyauto_errors.JSONInterfaceError if the automation call returns an error.
1543 """
1544 if isinstance(url, GURL):
1545 url = url.spec()
1546 cmd_dict = {
1547 'command': 'GetCookiesInBrowserContext',
1548 'url': url,
1549 'windex': windex,
1550 }
1551 return self._GetResultFromJSONRequest(cmd_dict, windex=None)['cookies']
1552
1553 def DeleteCookie(self, url, cookie_name, windex=0):
1554 """Delete the cookie at url with name cookie_name.
1555
1556 Args:
1557 url: Either a GURL object or url string specifing the cookie url.
1558 cookie_name: The name of the cookie to delete as a string.
1559 windex: The index of the browser window to work on. Defaults to the first
1560 window.
1561
1562 Raises:
1563 pyauto_errors.JSONInterfaceError if the automation call returns an error.
1564 """
1565 if isinstance(url, GURL):
1566 url = url.spec()
1567 cmd_dict = {
1568 'command': 'DeleteCookieInBrowserContext',
1569 'url': url,
1570 'cookie_name': cookie_name,
1571 'windex': windex,
1572 }
1573 self._GetResultFromJSONRequest(cmd_dict, windex=None)
1574
1575 def SetCookie(self, url, value, windex=0):
1576 """Set the value of the cookie at url to value in the context of a browser.
1577
1578 Args:
1579 url: Either a GURL object or url string specifing the cookie url.
1580 value: A string to set as the cookie's value.
1581 windex: The index of the browser window to work on. Defaults to the first
1582 window.
1583
1584 Raises:
1585 pyauto_errors.JSONInterfaceError if the automation call returns an error.
1586 """
1587 if isinstance(url, GURL):
1588 url = url.spec()
1589 cmd_dict = {
1590 'command': 'SetCookieInBrowserContext',
1591 'url': url,
1592 'value': value,
1593 'windex': windex,
1594 }
1595 self._GetResultFromJSONRequest(cmd_dict, windex=None)
1596
1533 def GetInstantInfo(self): 1597 def GetInstantInfo(self):
1534 """Return info about the instant overlay tab. 1598 """Return info about the instant overlay tab.
1535 1599
1536 Returns: 1600 Returns:
1537 A dictionary. 1601 A dictionary.
1538 Examples: 1602 Examples:
1539 { u'enabled': True, 1603 { u'enabled': True,
1540 u'active': True, 1604 u'active': True,
1541 u'current': True, 1605 u'current': True,
1542 u'loading': True, 1606 u'loading': True,
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
1837 'unmodifiedText': char, 1901 'unmodifiedText': char,
1838 'nativeKeyCode': 0, 1902 'nativeKeyCode': 0,
1839 'windowsKeyCode': ord((char).upper()), 1903 'windowsKeyCode': ord((char).upper()),
1840 'modifiers': 0, 1904 'modifiers': 0,
1841 'windex': windex, 1905 'windex': windex,
1842 'tab_index': tab_index, 1906 'tab_index': tab_index,
1843 } 1907 }
1844 # Sending request for a char. 1908 # Sending request for a char.
1845 self._GetResultFromJSONRequest(cmd_dict, windex=None) 1909 self._GetResultFromJSONRequest(cmd_dict, windex=None)
1846 1910
1911 def SetDownloadShelfVisible(self, is_visible, windex=0):
1912 """Set download shelf visibility for the specified browser window.
1913
1914 Args:
1915 is_visible: A boolean indicating the desired shelf visibility.
1916 windex: The window index, defaults to 0 (the first window).
1917
1918 Raises:
1919 pyauto_errors.JSONInterfaceError if the automation call returns an error.
1920 """
1921 cmd_dict = {
1922 'command': 'SetDownloadShelfVisible',
1923 'is_visible': is_visible,
1924 'windex': windex,
1925 }
1926 self._GetResultFromJSONRequest(cmd_dict, windex=None)
1927
1928 def IsDownloadShelfVisible(self, windex=0):
1929 """Determine whether the download shelf is visible in the given window.
1930
1931 Args:
1932 windex: The window index, defaults to 0 (the first window).
1933
1934 Returns:
1935 A boolean indicating the shelf visibility.
1936
1937 Raises:
1938 pyauto_errors.JSONInterfaceError if the automation call returns an error.
1939 """
1940 cmd_dict = {
1941 'command': 'IsDownloadShelfVisible',
1942 'windex': windex,
1943 }
1944 return self._GetResultFromJSONRequest(cmd_dict, windex=None)['is_visible']
1945
1946 def GetDownloadDirectory(self, tab_index=None, windex=0):
1947 """Get the path to the download directory.
1948
1949 Warning: Depending on the concept of an active tab is dangerous as it can
1950 change during the test. Always supply a tab_index explicitly.
1951
1952 Args:
1953 tab_index: The index of the tab to work on. Defaults to the active tab.
1954 windex: The index of the browser window to work on. Defaults to 0.
1955
1956 Returns:
1957 The path to the download directory as a FilePath object.
1958
1959 Raises:
1960 pyauto_errors.JSONInterfaceError if the automation call returns an error.
1961 """
1962 if tab_index is None:
1963 tab_index = self.GetActiveTabIndex(windex)
1964 cmd_dict = {
1965 'command': 'GetDownloadDirectory',
1966 'tab_index': tab_index,
1967 'windex': windex,
1968 }
1969 return FilePath(self._GetResultFromJSONRequest(cmd_dict,
1970 windex=None)['path'])
1971
1847 def WaitForAllDownloadsToComplete(self, pre_download_ids=[], windex=0, 1972 def WaitForAllDownloadsToComplete(self, pre_download_ids=[], windex=0,
1848 timeout=-1): 1973 timeout=-1):
1849 """Wait for all pending downloads to complete. 1974 """Wait for all pending downloads to complete.
1850 1975
1851 This function assumes that any downloads to wait for have already been 1976 This function assumes that any downloads to wait for have already been
1852 triggered and have started (it is ok if those downloads complete before this 1977 triggered and have started (it is ok if those downloads complete before this
1853 function is called). 1978 function is called).
1854 1979
1855 Args: 1980 Args:
1856 pre_download_ids: A list of numbers representing the IDs of downloads that 1981 pre_download_ids: A list of numbers representing the IDs of downloads that
(...skipping 4502 matching lines...) Expand 10 before | Expand all | Expand 10 after
6359 successful = result.wasSuccessful() 6484 successful = result.wasSuccessful()
6360 if not successful: 6485 if not successful:
6361 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) 6486 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename)
6362 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ 6487 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \
6363 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) 6488 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL)
6364 sys.exit(not successful) 6489 sys.exit(not successful)
6365 6490
6366 6491
6367 if __name__ == '__main__': 6492 if __name__ == '__main__':
6368 Main() 6493 Main()
OLDNEW
« no previous file with comments | « chrome/test/automation/tab_proxy.cc ('k') | chrome/test/pyautolib/pyautolib.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698