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

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

Issue 10854229: Fix passwords.PasswordTest.testInfoBarDisappearByNavigatingPage (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . 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 | « no previous file | no next file » | 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 767 matching lines...) Expand 10 before | Expand all | Expand 10 after
778 778
779 Returns: 779 Returns:
780 a dictionary of items from private_tests_info.txt 780 a dictionary of items from private_tests_info.txt
781 """ 781 """
782 private_file = os.path.join( 782 private_file = os.path.join(
783 PyUITest.DataDir(), 'pyauto_private', 'private_tests_info.txt') 783 PyUITest.DataDir(), 'pyauto_private', 'private_tests_info.txt')
784 assert os.path.exists(private_file), '%s missing' % private_file 784 assert os.path.exists(private_file), '%s missing' % private_file
785 return PyUITest.EvalDataFrom(private_file) 785 return PyUITest.EvalDataFrom(private_file)
786 786
787 def WaitUntil(self, function, timeout=-1, retry_sleep=0.25, args=[], 787 def WaitUntil(self, function, timeout=-1, retry_sleep=0.25, args=[],
788 expect_retval=None, debug=True): 788 expect_retval=None, return_retval=False, debug=True):
789 """Poll on a condition until timeout. 789 """Poll on a condition until timeout.
790 790
791 Waits until the |function| evalues to |expect_retval| or until |timeout| 791 Waits until the |function| evalues to |expect_retval| or until |timeout|
792 secs, whichever occurs earlier. 792 secs, whichever occurs earlier.
793 793
794 This is better than using a sleep, since it waits (almost) only as much 794 This is better than using a sleep, since it waits (almost) only as much
795 as needed. 795 as needed.
796 796
797 WARNING: This method call should be avoided as far as possible in favor 797 WARNING: This method call should be avoided as far as possible in favor
798 of a real wait from chromium (like wait-until-page-loaded). 798 of a real wait from chromium (like wait-until-page-loaded).
(...skipping 12 matching lines...) Expand all
811 action is to wait for kWaitForActionMaxMsec, as set in 811 action is to wait for kWaitForActionMaxMsec, as set in
812 ui_test.cc 812 ui_test.cc
813 Use None to wait indefinitely. 813 Use None to wait indefinitely.
814 retry_sleep: the sleep interval (in secs) before retrying |function|. 814 retry_sleep: the sleep interval (in secs) before retrying |function|.
815 Defaults to 0.25 secs. 815 Defaults to 0.25 secs.
816 args: the args to pass to |function| 816 args: the args to pass to |function|
817 expect_retval: the expected return value for |function|. This forms the 817 expect_retval: the expected return value for |function|. This forms the
818 exit criteria. In case this is None (the default), 818 exit criteria. In case this is None (the default),
819 |function|'s return value is checked for truth, 819 |function|'s return value is checked for truth,
820 so 'non-empty-string' should match with True 820 so 'non-empty-string' should match with True
821 return_retval: If True, return the value returned by the last call to
822 |function()|
821 debug: if True, displays debug info at each retry. 823 debug: if True, displays debug info at each retry.
822 824
823 Returns: 825 Returns:
824 The return value of the calling function when |function| evaluates to 826 The return value of the |function| (when return_retval == True)
825 True. 827 True, if returning when |function| evaluated to True (when
828 return_retval == False)
826 False, when returning due to timeout 829 False, when returning due to timeout
827 """ 830 """
828 if timeout == -1: # Default 831 if timeout == -1: # Default
829 timeout = self.action_max_timeout_ms() / 1000.0 832 timeout = self.action_max_timeout_ms() / 1000.0
830 assert callable(function), "function should be a callable" 833 assert callable(function), "function should be a callable"
831 begin = time.time() 834 begin = time.time()
832 debug_begin = begin 835 debug_begin = begin
836 retval = None
833 while timeout is None or time.time() - begin <= timeout: 837 while timeout is None or time.time() - begin <= timeout:
834 retval = function(*args) 838 retval = function(*args)
835 if (expect_retval is None and retval) or \ 839 if (expect_retval is None and retval) or \
836 (expect_retval is not None and expect_retval == retval): 840 (expect_retval is not None and expect_retval == retval):
837 return retval 841 return retval if return_retval else True
838 if debug and time.time() - debug_begin > 5: 842 if debug and time.time() - debug_begin > 5:
839 debug_begin += 5 843 debug_begin += 5
840 if function.func_name == (lambda: True).func_name: 844 if function.func_name == (lambda: True).func_name:
841 function_info = inspect.getsource(function).strip() 845 function_info = inspect.getsource(function).strip()
842 else: 846 else:
843 function_info = '%s()' % function.func_name 847 function_info = '%s()' % function.func_name
844 logging.debug('WaitUntil(%s:%d %s) still waiting. ' 848 logging.debug('WaitUntil(%s:%d %s) still waiting. '
845 'Expecting %s. Last returned %s.', 849 'Expecting %s. Last returned %s.',
846 os.path.basename(inspect.getsourcefile(function)), 850 os.path.basename(inspect.getsourcefile(function)),
847 inspect.getsourcelines(function)[1], 851 inspect.getsourcelines(function)[1],
848 function_info, 852 function_info,
849 True if expect_retval is None else expect_retval, 853 True if expect_retval is None else expect_retval,
850 retval) 854 retval)
851 time.sleep(retry_sleep) 855 time.sleep(retry_sleep)
852 return False 856 return retval if return_retval else False
853 857
854 def StartSyncServer(self): 858 def StartSyncServer(self):
855 """Start a local sync server. 859 """Start a local sync server.
856 860
857 Adds a dictionary attribute 'ports' in returned object. 861 Adds a dictionary attribute 'ports' in returned object.
858 862
859 Returns: 863 Returns:
860 A handle to Sync Server, an instance of TestServer 864 A handle to Sync Server, an instance of TestServer
861 """ 865 """
862 sync_server = pyautolib.TestServer(pyautolib.TestServer.TYPE_SYNC, 866 sync_server = pyautolib.TestServer(pyautolib.TestServer.TYPE_SYNC,
(...skipping 4646 matching lines...) Expand 10 before | Expand all | Expand 10 after
5509 Args: 5513 Args:
5510 ssid: String defining the SSID we are searching for. 5514 ssid: String defining the SSID we are searching for.
5511 encryption: Encryption type of the network; either None to return the 5515 encryption: Encryption type of the network; either None to return the
5512 first instance of network that matches the ssid, '' for 5516 first instance of network that matches the ssid, '' for
5513 an empty network, 'PSK', 'WEP' or '8021X'. 5517 an empty network, 'PSK', 'WEP' or '8021X'.
5514 timeout: Duration to wait for ssid to appear. 5518 timeout: Duration to wait for ssid to appear.
5515 5519
5516 Returns: 5520 Returns:
5517 The service path or None if SSID does not exist after timeout period. 5521 The service path or None if SSID does not exist after timeout period.
5518 """ 5522 """
5519 def _get_service_path(): 5523 def _GetServicePath():
5520 service_list = self.GetNetworkInfo().get('wifi_networks', []) 5524 service_list = self.GetNetworkInfo().get('wifi_networks', [])
5521 for service_path, service_obj in service_list.iteritems(): 5525 for service_path, service_obj in service_list.iteritems():
5522 service_encr = 'PSK' if service_obj['encryption'] in ['WPA', 'RSN'] \ 5526 service_encr = 'PSK' if service_obj['encryption'] in ['WPA', 'RSN'] \
5523 else service_obj['encryption'] 5527 else service_obj['encryption']
5524 5528
5525 if service_obj['name'] == ssid and \ 5529 if service_obj['name'] == ssid and \
5526 (encryption == None or service_encr == encryption): 5530 (encryption == None or service_encr == encryption):
5527 return service_path 5531 return service_path
5528 self.NetworkScan() 5532 self.NetworkScan()
5529 return None 5533 return None
5530 5534
5531 service_path = self.WaitUntil(_get_service_path, timeout=timeout, 5535 service_path = self.WaitUntil(_GetServicePath, timeout=timeout,
5532 retry_sleep=1) 5536 retry_sleep=1, return_retval=True)
5533 return service_path or None 5537 return service_path or None
5534 5538
5535 def NetworkScan(self): 5539 def NetworkScan(self):
5536 """Causes ChromeOS to scan for available wifi networks. 5540 """Causes ChromeOS to scan for available wifi networks.
5537 5541
5538 Blocks until scanning is complete. 5542 Blocks until scanning is complete.
5539 5543
5540 Returns: 5544 Returns:
5541 The new list of networks obtained from GetNetworkInfo(). 5545 The new list of networks obtained from GetNetworkInfo().
5542 5546
(...skipping 1455 matching lines...) Expand 10 before | Expand all | Expand 10 after
6998 successful = result.wasSuccessful() 7002 successful = result.wasSuccessful()
6999 if not successful: 7003 if not successful:
7000 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) 7004 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename)
7001 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ 7005 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \
7002 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) 7006 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL)
7003 sys.exit(not successful) 7007 sys.exit(not successful)
7004 7008
7005 7009
7006 if __name__ == '__main__': 7010 if __name__ == '__main__':
7007 Main() 7011 Main()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698