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

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

Issue 10828245: Final set of conversions of automation calls 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/browser_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 1507 matching lines...) Expand 10 before | Expand all | Expand 10 after
1518 """Return the bookmark model as a BookmarkModel object. 1518 """Return the bookmark model as a BookmarkModel object.
1519 1519
1520 This is a snapshot of the bookmark model; it is not a proxy and 1520 This is a snapshot of the bookmark model; it is not a proxy and
1521 does not get updated as the bookmark model changes. 1521 does not get updated as the bookmark model changes.
1522 """ 1522 """
1523 bookmarks_as_json = self._GetBookmarksAsJSON(windex) 1523 bookmarks_as_json = self._GetBookmarksAsJSON(windex)
1524 if not bookmarks_as_json: 1524 if not bookmarks_as_json:
1525 raise JSONInterfaceError('Could not resolve browser proxy.') 1525 raise JSONInterfaceError('Could not resolve browser proxy.')
1526 return bookmark_model.BookmarkModel(bookmarks_as_json) 1526 return bookmark_model.BookmarkModel(bookmarks_as_json)
1527 1527
1528 def _GetBookmarksAsJSON(self, windex=0):
1529 """Get bookmarks as a JSON dictionary; used by GetBookmarkModel()."""
1530 cmd_dict = {
1531 'command': 'GetBookmarksAsJSON',
1532 'windex': windex,
1533 }
1534 self.WaitForBookmarkModelToLoad(windex)
1535 return self._GetResultFromJSONRequest(cmd_dict,
1536 windex=None)['bookmarks_as_json']
1537
1538 def WaitForBookmarkModelToLoad(self, windex=0):
1539 """Gets the status of the bookmark bar as a dictionary.
1540
1541 Args:
1542 windex: Integer index of the browser window to use; defaults to the first
1543 window.
1544
1545 Raises:
1546 pyauto_errors.JSONInterfaceError if the automation call returns an error.
1547 """
1548 cmd_dict = {
1549 'command': 'WaitForBookmarkModelToLoad',
1550 'windex': windex,
1551 }
1552 return self._GetResultFromJSONRequest(cmd_dict, windex=None)
1553
1554 def GetBookmarkBarStatus(self, windex=0):
1555 """Gets the status of the bookmark bar as a dictionary.
1556
1557 Args:
1558 windex: Integer index of the browser window to use; defaults to the first
1559 window.
1560
1561 Returns:
1562 A dictionary.
1563 Example:
1564 { u'visible': True,
1565 u'animating': False,
1566 u'detached': False, }
1567
1568 Raises:
1569 pyauto_errors.JSONInterfaceError if the automation call returns an error.
1570 """
1571 cmd_dict = {
1572 'command': 'GetBookmarkBarStatus',
1573 'windex': windex,
1574 }
1575 return self._GetResultFromJSONRequest(cmd_dict, windex=None)
1576
1577 def GetBookmarkBarStatus(self, windex=0):
1578 """Gets the status of the bookmark bar as a dictionary.
1579
1580 Args:
1581 windex: Integer index of the browser window to use; defaults to the first
1582 window.
1583
1584 Returns:
1585 A dictionary.
1586 Example:
1587 { u'visible': True,
1588 u'animating': False,
1589 u'detached': False, }
1590
1591 Raises:
1592 pyauto_errors.JSONInterfaceError if the automation call returns an error.
1593 """
1594 cmd_dict = {
1595 'command': 'GetBookmarkBarStatus',
1596 'windex': windex,
1597 }
1598 return self._GetResultFromJSONRequest(cmd_dict, windex=None)
1599
1600 def GetBookmarkBarStatus(self, windex=0):
1601 """Gets the status of the bookmark bar as a dictionary.
1602
1603 Args:
1604 windex: Integer index of the browser window to use; defaults to the first
1605 window.
1606
1607 Returns:
1608 A dictionary.
1609 Example:
1610 { u'visible': True,
1611 u'animating': False,
1612 u'detached': False, }
1613
1614 Raises:
1615 pyauto_errors.JSONInterfaceError if the automation call returns an error.
1616 """
1617 cmd_dict = {
1618 'command': 'GetBookmarkBarStatus',
1619 'windex': windex,
1620 }
1621 return self._GetResultFromJSONRequest(cmd_dict, windex=None)
1622
1623 def GetBookmarkBarVisibility(self, windex=0):
1624 """Returns the visibility of the bookmark bar.
1625
1626 Args:
1627 windex: Integer index of the browser window to use; defaults to the first
1628 window.
1629
1630 Returns:
1631 True if the bookmark bar is visible, false otherwise.
1632
1633 Raises:
1634 pyauto_errors.JSONInterfaceError if the automation call returns an error.
1635 """
1636 return self.GetBookmarkBarStatus(windex)['visible']
1637
1638 def IsBookmarkBarDetached(self, windex=0):
1639 """Returns whether the bookmark bar is detached.
1640
1641 Args:
1642 windex: Integer index of the browser window to use; defaults to the first
1643 window.
1644
1645 Returns:
1646 True if the bookmark bar is detached, false otherwise.
1647
1648 Raises:
1649 pyauto_errors.JSONInterfaceError if the automation call returns an error.
1650 """
1651 return self.GetBookmarkBarStatus(windex)['detached']
1652
1653 def WaitForBookmarkBarVisibilityChange(self, wait_for_open, windex=0):
1654 """Waits until the bookmark bar is either visible or not visible.
1655
1656 Args:
1657 wait_for_open: If True, wait until bookmark bar is visible; otherwise wait
1658 until bookmark bar is not visible.
1659 windex: Integer index of the browser window to use; defaults to the first
1660 window.
1661
1662 Raises:
1663 pyauto_errors.JSONInterfaceError if the automation call returns an error.
1664 """
1665 def IsChanged(wait_for_open, windex):
1666 status = self.GetBookmarkBarStatus(windex)
1667 return status['visible'] == wait_for_open and not status['animating']
1668 return self.WaitUntil(lambda: IsChanged(wait_for_open, windex))
1669
1670 def AddBookmarkGroup(self, parent_id, index, title, windex=0):
1671 """Adds a bookmark folder.
1672
1673 Args:
1674 parent_id: The parent bookmark folder.
1675 index: The location in the parent's list to insert this bookmark folder.
1676 title: The name of the bookmark folder.
1677 windex: Integer index of the browser window to use; defaults to the first
1678 window.
1679
1680 Returns:
1681 True if the bookmark bar is detached, false otherwise.
1682
1683 Raises:
1684 pyauto_errors.JSONInterfaceError if the automation call returns an error.
1685 """
1686 if isinstance(parent_id, basestring):
1687 parent_id = int(parent_id)
1688 cmd_dict = {
1689 'command': 'AddBookmark',
1690 'parent_id': parent_id,
1691 'index': index,
1692 'title': title,
1693 'is_folder': True,
1694 'windex': windex,
1695 }
1696 self.WaitForBookmarkModelToLoad(windex)
1697 self._GetResultFromJSONRequest(cmd_dict, windex=None)
1698
1699 def AddBookmarkURL(self, parent_id, index, title, url, windex=0):
1700 """Add a bookmark URL.
1701
1702 Args:
1703 parent_id: The parent bookmark folder.
1704 index: The location in the parent's list to insert this bookmark.
1705 title: The name of the bookmark.
1706 url: The url of the bookmark.
1707 windex: Integer index of the browser window to use; defaults to the first
1708 window.
1709
1710 Raises:
1711 pyauto_errors.JSONInterfaceError if the automation call returns an error.
1712 """
1713 if isinstance(parent_id, basestring):
1714 parent_id = int(parent_id)
1715 cmd_dict = {
1716 'command': 'AddBookmark',
1717 'parent_id': parent_id,
1718 'index': index,
1719 'title': title,
1720 'url': url,
1721 'is_folder': False,
1722 'windex': windex,
1723 }
1724 self.WaitForBookmarkModelToLoad(windex)
1725 self._GetResultFromJSONRequest(cmd_dict, windex=None)
1726
1727 def ReparentBookmark(self, id, new_parent_id, index, windex=0):
1728 """Move a bookmark.
1729
1730 Args:
1731 id: The bookmark to move.
1732 new_parent_id: The new parent bookmark folder.
1733 index: The location in the parent's list to insert this bookmark.
1734 windex: Integer index of the browser window to use; defaults to the first
1735 window.
1736
1737 Raises:
1738 pyauto_errors.JSONInterfaceError if the automation call returns an error.
1739 """
1740 if isinstance(id, basestring):
1741 id = int(id)
1742 if isinstance(new_parent_id, basestring):
1743 new_parent_id = int(new_parent_id)
1744 cmd_dict = {
1745 'command': 'ReparentBookmark',
1746 'id': id,
1747 'new_parent_id': new_parent_id,
1748 'index': index,
1749 'windex': windex,
1750 }
1751 self.WaitForBookmarkModelToLoad(windex)
1752 self._GetResultFromJSONRequest(cmd_dict, windex=None)
1753
1754 def SetBookmarkTitle(self, id, title, windex=0):
1755 """Change the title of a bookmark.
1756
1757 Args:
1758 id: The bookmark to rename.
1759 title: The new title for the bookmark.
1760 windex: Integer index of the browser window to use; defaults to the first
1761 window.
1762
1763 Raises:
1764 pyauto_errors.JSONInterfaceError if the automation call returns an error.
1765 """
1766 if isinstance(id, basestring):
1767 id = int(id)
1768 cmd_dict = {
1769 'command': 'SetBookmarkTitle',
1770 'id': id,
1771 'title': title,
1772 'windex': windex,
1773 }
1774 self.WaitForBookmarkModelToLoad(windex)
1775 self._GetResultFromJSONRequest(cmd_dict, windex=None)
1776
1777 def SetBookmarkURL(self, id, url, windex=0):
1778 """Change the URL of a bookmark.
1779
1780 Args:
1781 id: The bookmark to change.
1782 url: The new url for the bookmark.
1783 windex: Integer index of the browser window to use; defaults to the first
1784 window.
1785
1786 Raises:
1787 pyauto_errors.JSONInterfaceError if the automation call returns an error.
1788 """
1789 if isinstance(id, basestring):
1790 id = int(id)
1791 cmd_dict = {
1792 'command': 'SetBookmarkURL',
1793 'id': id,
1794 'url': url,
1795 'windex': windex,
1796 }
1797 self.WaitForBookmarkModelToLoad(windex)
1798 self._GetResultFromJSONRequest(cmd_dict, windex=None)
1799
1800 def RemoveBookmark(self, id, windex=0):
1801 """Remove a bookmark.
1802
1803 Args:
1804 id: The bookmark to remove.
1805 windex: Integer index of the browser window to use; defaults to the first
1806 window.
1807
1808 Raises:
1809 pyauto_errors.JSONInterfaceError if the automation call returns an error.
1810 """
1811 if isinstance(id, basestring):
1812 id = int(id)
1813 cmd_dict = {
1814 'command': 'RemoveBookmark',
1815 'id': id,
1816 'windex': windex,
1817 }
1818 self.WaitForBookmarkModelToLoad(windex)
1819 self._GetResultFromJSONRequest(cmd_dict, windex=None)
1820
1528 def GetDownloadsInfo(self, windex=0): 1821 def GetDownloadsInfo(self, windex=0):
1529 """Return info about downloads. 1822 """Return info about downloads.
1530 1823
1531 This includes all the downloads recognized by the history system. 1824 This includes all the downloads recognized by the history system.
1532 1825
1533 Returns: 1826 Returns:
1534 an instance of downloads_info.DownloadInfo 1827 an instance of downloads_info.DownloadInfo
1535 """ 1828 """
1536 return download_info.DownloadInfo( 1829 return download_info.DownloadInfo(
1537 self._SendJSONRequest( 1830 self._SendJSONRequest(
(...skipping 5122 matching lines...) Expand 10 before | Expand all | Expand 10 after
6660 successful = result.wasSuccessful() 6953 successful = result.wasSuccessful()
6661 if not successful: 6954 if not successful:
6662 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) 6955 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename)
6663 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ 6956 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \
6664 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) 6957 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL)
6665 sys.exit(not successful) 6958 sys.exit(not successful)
6666 6959
6667 6960
6668 if __name__ == '__main__': 6961 if __name__ == '__main__':
6669 Main() 6962 Main()
OLDNEW
« no previous file with comments | « chrome/test/automation/browser_proxy.cc ('k') | chrome/test/pyautolib/pyautolib.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698