OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 | 2 |
3 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2010 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 1612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1623 # to evaluate invalid javascript like ""arg"". | 1623 # to evaluate invalid javascript like ""arg"". |
1624 converted_arg = '"' + arg.replace('"', '\\"') + '"' | 1624 converted_arg = '"' + arg.replace('"', '\\"') + '"' |
1625 else: | 1625 else: |
1626 # Convert it to a string so that we can use |join| later. | 1626 # Convert it to a string so that we can use |join| later. |
1627 converted_arg = str(arg) | 1627 converted_arg = str(arg) |
1628 converted_args += [converted_arg] | 1628 converted_args += [converted_arg] |
1629 js = '%s(%s)' % (function, ', '.join(converted_args)) | 1629 js = '%s(%s)' % (function, ', '.join(converted_args)) |
1630 logging.debug('Executing javascript: ', js) | 1630 logging.debug('Executing javascript: ', js) |
1631 return self.ExecuteJavascript(js, windex, tab_index) | 1631 return self.ExecuteJavascript(js, windex, tab_index) |
1632 | 1632 |
| 1633 def SignInToSync(self, username, password): |
| 1634 """Signs in to sync using the given username and password. |
| 1635 |
| 1636 Args: |
| 1637 username: The account with which to sign in. Example: "user@gmail.com". |
| 1638 password: Password for the above account. Example: "pa$$w0rd". |
| 1639 |
| 1640 Returns: |
| 1641 True, on success. |
| 1642 |
| 1643 Raises: |
| 1644 pyauto_errors.JSONInterfaceError if the automation call returns an error. |
| 1645 """ |
| 1646 cmd_dict = { |
| 1647 'command': 'SignInToSync', |
| 1648 'username': username, |
| 1649 'password': password, |
| 1650 } |
| 1651 return self._GetResultFromJSONRequest(cmd_dict)['success'] |
| 1652 |
| 1653 def GetSyncInfo(self): |
| 1654 """Returns info about sync. |
| 1655 |
| 1656 Returns: |
| 1657 A dictionary of info about sync. |
| 1658 Example dictionaries: |
| 1659 {u'summary': u'SYNC DISABLED'} |
| 1660 |
| 1661 { u'authenticated': True, |
| 1662 u'last synced': u'Just now', |
| 1663 u'summary': u'READY', |
| 1664 u'sync url': u'clients4.google.com', |
| 1665 u'synced datatypes': [ u'Bookmarks', |
| 1666 u'Preferences', |
| 1667 u'Passwords', |
| 1668 u'Autofill', |
| 1669 u'Themes', |
| 1670 u'Extensions', |
| 1671 u'Apps']} |
| 1672 |
| 1673 Raises: |
| 1674 pyauto_errors.JSONInterfaceError if the automation call returns an error. |
| 1675 """ |
| 1676 cmd_dict = { |
| 1677 'command': 'GetSyncInfo', |
| 1678 } |
| 1679 return self._GetResultFromJSONRequest(cmd_dict)['sync_info'] |
| 1680 |
| 1681 def AwaitSyncCycleCompletion(self): |
| 1682 """Waits for the ongoing sync cycle to complete. Must be signed in to sync |
| 1683 before calling this method. |
| 1684 |
| 1685 Returns: |
| 1686 True, on success. |
| 1687 |
| 1688 Raises: |
| 1689 pyauto_errors.JSONInterfaceError if the automation call returns an error. |
| 1690 """ |
| 1691 cmd_dict = { |
| 1692 'command': 'AwaitSyncCycleCompletion', |
| 1693 } |
| 1694 return self._GetResultFromJSONRequest(cmd_dict)['success'] |
| 1695 |
| 1696 def EnableSyncForDatatypes(self, datatypes): |
| 1697 """Enables sync for a given list of sync datatypes. Must be signed in to |
| 1698 sync before calling this method. |
| 1699 |
| 1700 Args: |
| 1701 datatypes: A list of strings indicating the datatypes for which to enable |
| 1702 sync. Strings that can be in the list are: |
| 1703 Bookmarks, Preferences, Passwords, Autofill, Themes, |
| 1704 Typed URLs, Extensions, Encryption keys, Sessions, Apps, All. |
| 1705 For an updated list of valid sync datatypes, refer to the |
| 1706 function ModelTypeToString() in the file |
| 1707 chrome/browser/sync/syncable/model_type.cc. |
| 1708 Examples: |
| 1709 ['Bookmarks', 'Preferences', 'Passwords'] |
| 1710 ['All'] |
| 1711 |
| 1712 Returns: |
| 1713 True, on success. |
| 1714 |
| 1715 Raises: |
| 1716 pyauto_errors.JSONInterfaceError if the automation call returns an error. |
| 1717 """ |
| 1718 cmd_dict = { |
| 1719 'command': 'EnableSyncForDatatypes', |
| 1720 'datatypes': datatypes, |
| 1721 } |
| 1722 return self._GetResultFromJSONRequest(cmd_dict)['success'] |
| 1723 |
| 1724 def DisableSyncForDatatypes(self, datatypes): |
| 1725 """Disables sync for a given list of sync datatypes. Must be signed in to |
| 1726 sync before calling this method. |
| 1727 |
| 1728 Args: |
| 1729 datatypes: A list of strings indicating the datatypes for which to |
| 1730 disable sync. Strings that can be in the list are: |
| 1731 Bookmarks, Preferences, Passwords, Autofill, Themes, |
| 1732 Typed URLs, Extensions, Encryption keys, Sessions, Apps, All. |
| 1733 For an updated list of valid sync datatypes, refer to the |
| 1734 function ModelTypeToString() in the file |
| 1735 chrome/browser/sync/syncable/model_type.cc. |
| 1736 Examples: |
| 1737 ['Bookmarks', 'Preferences', 'Passwords'] |
| 1738 ['All'] |
| 1739 |
| 1740 Returns: |
| 1741 True, on success. |
| 1742 |
| 1743 Raises: |
| 1744 pyauto_errors.JSONInterfaceError if the automation call returns an error. |
| 1745 """ |
| 1746 cmd_dict = { |
| 1747 'command': 'DisableSyncForDatatypes', |
| 1748 'datatypes': datatypes, |
| 1749 } |
| 1750 return self._GetResultFromJSONRequest(cmd_dict)['success'] |
1633 | 1751 |
1634 class PyUITestSuite(pyautolib.PyUITestSuiteBase, unittest.TestSuite): | 1752 class PyUITestSuite(pyautolib.PyUITestSuiteBase, unittest.TestSuite): |
1635 """Base TestSuite for PyAuto UI tests.""" | 1753 """Base TestSuite for PyAuto UI tests.""" |
1636 | 1754 |
1637 def __init__(self, args): | 1755 def __init__(self, args): |
1638 pyautolib.PyUITestSuiteBase.__init__(self, args) | 1756 pyautolib.PyUITestSuiteBase.__init__(self, args) |
1639 | 1757 |
1640 # Figure out path to chromium binaries | 1758 # Figure out path to chromium binaries |
1641 browser_dir = os.path.normpath(os.path.dirname(pyautolib.__file__)) | 1759 browser_dir = os.path.normpath(os.path.dirname(pyautolib.__file__)) |
1642 logging.debug('Loading pyauto libs from %s', browser_dir) | 1760 logging.debug('Loading pyauto libs from %s', browser_dir) |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1932 if self._options.verbose: | 2050 if self._options.verbose: |
1933 verbosity = 2 | 2051 verbosity = 2 |
1934 result = PyAutoTextTestRuner(verbosity=verbosity).run(pyauto_suite) | 2052 result = PyAutoTextTestRuner(verbosity=verbosity).run(pyauto_suite) |
1935 del loaded_tests # Need to destroy test cases before the suite | 2053 del loaded_tests # Need to destroy test cases before the suite |
1936 del pyauto_suite | 2054 del pyauto_suite |
1937 sys.exit(not result.wasSuccessful()) | 2055 sys.exit(not result.wasSuccessful()) |
1938 | 2056 |
1939 | 2057 |
1940 if __name__ == '__main__': | 2058 if __name__ == '__main__': |
1941 Main() | 2059 Main() |
OLD | NEW |