OLD | NEW |
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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 from pyauto_errors import NTPThumbnailNotShownError | 88 from pyauto_errors import NTPThumbnailNotShownError |
89 import pyauto_utils | 89 import pyauto_utils |
90 import simplejson as json # found in third_party | 90 import simplejson as json # found in third_party |
91 | 91 |
92 _CHROME_DRIVER_FACTORY = None | 92 _CHROME_DRIVER_FACTORY = None |
93 _HTTP_SERVER = None | 93 _HTTP_SERVER = None |
94 _REMOTE_PROXY = None | 94 _REMOTE_PROXY = None |
95 _OPTIONS = None | 95 _OPTIONS = None |
96 _BROWSER_PID = None | 96 _BROWSER_PID = None |
97 | 97 |
98 # TODO(bartfab): Remove when crosbug.com/20709 is fixed. | |
99 AUTO_CLEAR_LOCAL_STATE_MAGIC_FILE = '/root/.forget_usernames' | |
100 | |
101 | 98 |
102 class PyUITest(pyautolib.PyUITestBase, unittest.TestCase): | 99 class PyUITest(pyautolib.PyUITestBase, unittest.TestCase): |
103 """Base class for UI Test Cases in Python. | 100 """Base class for UI Test Cases in Python. |
104 | 101 |
105 A browser is created before executing each test, and is destroyed after | 102 A browser is created before executing each test, and is destroyed after |
106 each test irrespective of whether the test passed or failed. | 103 each test irrespective of whether the test passed or failed. |
107 | 104 |
108 You should derive from this class and create methods with 'test' prefix, | 105 You should derive from this class and create methods with 'test' prefix, |
109 and use methods inherited from PyUITestBase (the C++ side). | 106 and use methods inherited from PyUITestBase (the C++ side). |
110 | 107 |
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 def CleanupFlimflamDirsOnChromeOS(): | 474 def CleanupFlimflamDirsOnChromeOS(): |
478 """Clean the contents of flimflam profiles and restart flimflam.""" | 475 """Clean the contents of flimflam profiles and restart flimflam.""" |
479 PyUITest.RunSuperuserActionOnChromeOS('CleanFlimflamDirs') | 476 PyUITest.RunSuperuserActionOnChromeOS('CleanFlimflamDirs') |
480 | 477 |
481 @staticmethod | 478 @staticmethod |
482 def RemoveAllCryptohomeVaultsOnChromeOS(): | 479 def RemoveAllCryptohomeVaultsOnChromeOS(): |
483 """Remove any existing cryptohome vaults.""" | 480 """Remove any existing cryptohome vaults.""" |
484 PyUITest.RunSuperuserActionOnChromeOS('RemoveAllCryptohomeVaults') | 481 PyUITest.RunSuperuserActionOnChromeOS('RemoveAllCryptohomeVaults') |
485 | 482 |
486 @staticmethod | 483 @staticmethod |
487 def TryToDisableLocalStateAutoClearingOnChromeOS(): | |
488 """Disable clearing of the local state on session manager startup. | |
489 | |
490 TODO(bartfab): Remove this method when crosbug.com/20709 is fixed. | |
491 """ | |
492 PyUITest.RunSuperuserActionOnChromeOS('TryToDisableLocalStateAutoClearing') | |
493 | |
494 @staticmethod | |
495 def TryToEnableLocalStateAutoClearingOnChromeOS(): | |
496 """Enable clearing of the local state on session manager startup. | |
497 | |
498 TODO(bartfab): Remove this method when crosbug.com/20709 is fixed. | |
499 """ | |
500 PyUITest.RunSuperuserActionOnChromeOS('TryToEnableLocalStateAutoClearing') | |
501 | |
502 @staticmethod | |
503 def IsLocalStateAutoClearingEnabledOnChromeOS(): | |
504 """Check if the session manager is set to clear the local state on startup. | |
505 | |
506 TODO(bartfab): Remove this method when crosbug.com/20709 is fixed. | |
507 """ | |
508 return os.path.exists(AUTO_CLEAR_LOCAL_STATE_MAGIC_FILE) | |
509 | |
510 @staticmethod | |
511 def _IsInodeNew(path, old_inode): | 484 def _IsInodeNew(path, old_inode): |
512 """Determine whether an inode has changed. POSIX only. | 485 """Determine whether an inode has changed. POSIX only. |
513 | 486 |
514 Args: | 487 Args: |
515 path: The file path to check for changes. | 488 path: The file path to check for changes. |
516 old_inode: The old inode number. | 489 old_inode: The old inode number. |
517 | 490 |
518 Returns: | 491 Returns: |
519 True if the path exists and its inode number is different from old_inode. | 492 True if the path exists and its inode number is different from old_inode. |
520 False otherwise. | 493 False otherwise. |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
765 Returns: | 738 Returns: |
766 A list with the flags. | 739 A list with the flags. |
767 """ | 740 """ |
768 return [ | 741 return [ |
769 '--sync-url=http://127.0.0.1:%s/chromiumsync' % port, | 742 '--sync-url=http://127.0.0.1:%s/chromiumsync' % port, |
770 '--sync-allow-insecure-xmpp-connection', | 743 '--sync-allow-insecure-xmpp-connection', |
771 '--sync-notification-host=127.0.0.1:%s' % xmpp_port, | 744 '--sync-notification-host=127.0.0.1:%s' % xmpp_port, |
772 '--sync-notification-method=p2p', | 745 '--sync-notification-method=p2p', |
773 ] | 746 ] |
774 | 747 |
775 def GetPrivateInfo(self): | 748 @staticmethod |
| 749 def GetPrivateInfo(): |
776 """Fetch info from private_tests_info.txt in private dir. | 750 """Fetch info from private_tests_info.txt in private dir. |
777 | 751 |
778 Returns: | 752 Returns: |
779 a dictionary of items from private_tests_info.txt | 753 a dictionary of items from private_tests_info.txt |
780 """ | 754 """ |
781 private_file = os.path.join( | 755 private_file = os.path.join( |
782 self.DataDir(), 'pyauto_private', 'private_tests_info.txt') | 756 PyUITest.DataDir(), 'pyauto_private', 'private_tests_info.txt') |
783 assert os.path.exists(private_file), '%s missing' % private_file | 757 assert os.path.exists(private_file), '%s missing' % private_file |
784 return self.EvalDataFrom(private_file) | 758 return PyUITest.EvalDataFrom(private_file) |
785 | 759 |
786 def WaitUntil(self, function, timeout=-1, retry_sleep=0.25, args=[], | 760 def WaitUntil(self, function, timeout=-1, retry_sleep=0.25, args=[], |
787 expect_retval=None, debug=True): | 761 expect_retval=None, debug=True): |
788 """Poll on a condition until timeout. | 762 """Poll on a condition until timeout. |
789 | 763 |
790 Waits until the |function| evalues to |expect_retval| or until |timeout| | 764 Waits until the |function| evalues to |expect_retval| or until |timeout| |
791 secs, whichever occurs earlier. | 765 secs, whichever occurs earlier. |
792 | 766 |
793 This is better than using a sleep, since it waits (almost) only as much | 767 This is better than using a sleep, since it waits (almost) only as much |
794 as needed. | 768 as needed. |
(...skipping 5689 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6484 successful = result.wasSuccessful() | 6458 successful = result.wasSuccessful() |
6485 if not successful: | 6459 if not successful: |
6486 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) | 6460 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) |
6487 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ | 6461 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ |
6488 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) | 6462 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) |
6489 sys.exit(not successful) | 6463 sys.exit(not successful) |
6490 | 6464 |
6491 | 6465 |
6492 if __name__ == '__main__': | 6466 if __name__ == '__main__': |
6493 Main() | 6467 Main() |
OLD | NEW |