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

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: Created 8 years, 5 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
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 1349 matching lines...) Expand 10 before | Expand all | Expand 10 after
1360 1360
1361 Args: 1361 Args:
1362 windex: the index of the browser window to work on. 1362 windex: the index of the browser window to work on.
1363 Default: 0 (first window) 1363 Default: 0 (first window)
1364 """ 1364 """
1365 cmd_dict = { 1365 cmd_dict = {
1366 'command': 'OmniboxAcceptInput', 1366 'command': 'OmniboxAcceptInput',
1367 } 1367 }
1368 self._GetResultFromJSONRequest(cmd_dict, windex=windex) 1368 self._GetResultFromJSONRequest(cmd_dict, windex=windex)
1369 1369
1370 def GetCookie(self, url, windex=0, tab_index=0):
1371 """Get the value of the cookie at url for the specified tab.
1372
1373 Args:
1374 windex: The index of the browser window to work on. Defaults to the first
1375 window.
1376
1377 Raises:
1378 pyauto_errors.JSONInterfaceError if the automation call returns an error.
1379 """
1380 if isinstance(url, GURL):
1381 url = url.spec()
1382 cmd_dict = {
1383 'command': 'GetTabCookies',
1384 'url': url,
1385 'tab_index': tab_index,
1386 'windex': windex,
1387 }
1388 return self._GetResultFromJSONRequest(cmd_dict, windex=windex)['cookies']
Nirnimesh 2012/07/20 22:16:20 this should probably be windex=None?
craigdh 2012/07/20 23:23:42 Done.
1389
1390 def DeleteCookie(self, url, cookie_name, windex=0, tab_index=0):
1391 """Delete the the cookie at url with name cookie_name for the given tab.
1392
1393 Args:
1394 windex: The index of the browser window to work on. Defaults to the first
1395 window.
1396
1397 Raises:
1398 pyauto_errors.JSONInterfaceError if the automation call returns an error.
1399 """
1400 if isinstance(url, GURL):
1401 url = url.spec()
1402 cmd_dict = {
1403 'command': 'DeleteTabCookie',
1404 'url': url,
1405 'cookie_name': cookie_name,
1406 'tab_index': tab_index,
1407 'windex': windex,
1408 }
1409 self._GetResultFromJSONRequest(cmd_dict, windex=windex)
1410
1411 def SetCookie(self, url, value, windex=0, tab_index=0):
1412 """Set the value of the cookie at url to value for the specified tab.
1413
1414 Args:
1415 windex: The index of the browser window to work on. Defaults to the first
1416 window.
1417
1418 Raises:
1419 pyauto_errors.JSONInterfaceError if the automation call returns an error.
1420 """
1421 if isinstance(url, GURL):
1422 url = url.spec()
1423 cmd_dict = {
1424 'command': 'SetTabCookie',
1425 'url': url,
1426 'value': value,
1427 'windex': windex,
1428 'tab_index': tab_index,
1429 }
1430 self._GetResultFromJSONRequest(cmd_dict, windex=windex)
1431
1370 def GetInstantInfo(self): 1432 def GetInstantInfo(self):
1371 """Return info about the instant overlay tab. 1433 """Return info about the instant overlay tab.
1372 1434
1373 Returns: 1435 Returns:
1374 A dictionary. 1436 A dictionary.
1375 Examples: 1437 Examples:
1376 { u'enabled': True, 1438 { u'enabled': True,
1377 u'active': True, 1439 u'active': True,
1378 u'current': True, 1440 u'current': True,
1379 u'loading': True, 1441 u'loading': True,
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
1674 'unmodifiedText': char, 1736 'unmodifiedText': char,
1675 'nativeKeyCode': 0, 1737 'nativeKeyCode': 0,
1676 'windowsKeyCode': ord((char).upper()), 1738 'windowsKeyCode': ord((char).upper()),
1677 'modifiers': 0, 1739 'modifiers': 0,
1678 'windex': windex, 1740 'windex': windex,
1679 'tab_index': tab_index, 1741 'tab_index': tab_index,
1680 } 1742 }
1681 # Sending request for a char. 1743 # Sending request for a char.
1682 self._GetResultFromJSONRequest(cmd_dict, windex=None) 1744 self._GetResultFromJSONRequest(cmd_dict, windex=None)
1683 1745
1746 def SetDownloadShelfVisible(self, is_visible, windex=0):
1747 """Set download shelf visibility for the specified browser window.
1748
1749 Args:
1750 is_visible: A boolean indicating the desired shelf visibility.
1751 windex: The window index, defaults to 0 (the first window).
1752
1753 Raises:
1754 pyauto_errors.JSONInterfaceError if the automation call returns an error.
1755 """
1756 cmd_dict = {
1757 'command': 'SetDownloadShelfVisible',
1758 'is_visible': is_visible,
1759 'windex': windex,
1760 }
1761 self._GetResultFromJSONRequest(cmd_dict, windex=None)
1762
1763 def IsDownloadShelfVisible(self, windex=0):
1764 """Determine whether the download shelf is visible in the given window.
1765
1766 Args:
1767 windex: The window index, defaults to 0 (the first window).
1768
1769 Returns:
1770 A boolean indicating the shelf visibility.
1771
1772 Raises:
1773 pyauto_errors.JSONInterfaceError if the automation call returns an error.
1774 """
1775 cmd_dict = {
1776 'command': 'IsDownloadShelfVisible',
1777 'windex': windex,
1778 }
1779 return self._GetResultFromJSONRequest(cmd_dict, windex=None)['is_visible']
1780
1781 def GetDownloadDirectory(self, tab_index=None, windex=0):
1782 """Get the path to the download directory.
1783
1784 Warning: Depending on the concept of an active tab is dangerous as it can
1785 change during the test. Always supply a tab_index explicitly.
1786
1787 Args:
1788 tab_index: The index of the tab to work on. Defaults to the active tab.
1789 windex: The index of the browser window to work on. Defaults to 0.
1790
1791 Returns:
1792 The path to the download directory as a FilePath object.
1793
1794 Raises:
1795 pyauto_errors.JSONInterfaceError if the automation call returns an error.
1796 """
1797 if tab_index is None:
1798 tab_index = self.GetActiveTabIndex(windex)
1799 cmd_dict = {
1800 'command': 'GetDownloadDirectory',
1801 'tab_index': tab_index,
1802 'windex': windex,
1803 }
1804 return FilePath(self._GetResultFromJSONRequest(cmd_dict,
1805 windex=None)['path'])
1806
1684 def WaitForAllDownloadsToComplete(self, pre_download_ids=[], windex=0, 1807 def WaitForAllDownloadsToComplete(self, pre_download_ids=[], windex=0,
1685 timeout=-1): 1808 timeout=-1):
1686 """Wait for all pending downloads to complete. 1809 """Wait for all pending downloads to complete.
1687 1810
1688 This function assumes that any downloads to wait for have already been 1811 This function assumes that any downloads to wait for have already been
1689 triggered and have started (it is ok if those downloads complete before this 1812 triggered and have started (it is ok if those downloads complete before this
1690 function is called). 1813 function is called).
1691 1814
1692 Args: 1815 Args:
1693 pre_download_ids: A list of numbers representing the IDs of downloads that 1816 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
6196 successful = result.wasSuccessful() 6319 successful = result.wasSuccessful()
6197 if not successful: 6320 if not successful:
6198 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) 6321 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename)
6199 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ 6322 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \
6200 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) 6323 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL)
6201 sys.exit(not successful) 6324 sys.exit(not successful)
6202 6325
6203 6326
6204 if __name__ == '__main__': 6327 if __name__ == '__main__':
6205 Main() 6328 Main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698