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

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

Issue 10829203: GetServicePath should perform a scan (Closed) Base URL: https://git.chromium.org/git/chromium/src@master
Patch Set: WaitUntil only returns retval 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
« 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 776 matching lines...) Expand 10 before | Expand all | Expand 10 after
787 retry_sleep: the sleep interval (in secs) before retrying |function|. 787 retry_sleep: the sleep interval (in secs) before retrying |function|.
788 Defaults to 0.25 secs. 788 Defaults to 0.25 secs.
789 args: the args to pass to |function| 789 args: the args to pass to |function|
790 expect_retval: the expected return value for |function|. This forms the 790 expect_retval: the expected return value for |function|. This forms the
791 exit criteria. In case this is None (the default), 791 exit criteria. In case this is None (the default),
792 |function|'s return value is checked for truth, 792 |function|'s return value is checked for truth,
793 so 'non-empty-string' should match with True 793 so 'non-empty-string' should match with True
794 debug: if True, displays debug info at each retry. 794 debug: if True, displays debug info at each retry.
795 795
796 Returns: 796 Returns:
797 True, if returning when |function| evaluated to True 797 The return value of the calling function when |function| evaluates to
798 True.
Nirnimesh 2012/08/08 21:58:31 append: (or matches expect_retval)
798 False, when returning due to timeout 799 False, when returning due to timeout
799 """ 800 """
800 if timeout == -1: # Default 801 if timeout == -1: # Default
801 timeout = self.action_max_timeout_ms() / 1000.0 802 timeout = self.action_max_timeout_ms() / 1000.0
802 assert callable(function), "function should be a callable" 803 assert callable(function), "function should be a callable"
803 begin = time.time() 804 begin = time.time()
804 debug_begin = begin 805 debug_begin = begin
805 while timeout is None or time.time() - begin <= timeout: 806 while timeout is None or time.time() - begin <= timeout:
806 retval = function(*args) 807 retval = function(*args)
807 if (expect_retval is None and retval) or expect_retval == retval: 808 if (expect_retval is None and retval) or \
808 return True 809 (expect_retval is not None and expect_retval == retval):
810 return retval
809 if debug and time.time() - debug_begin > 5: 811 if debug and time.time() - debug_begin > 5:
810 debug_begin += 5 812 debug_begin += 5
811 if function.func_name == (lambda: True).func_name: 813 if function.func_name == (lambda: True).func_name:
812 function_info = inspect.getsource(function).strip() 814 function_info = inspect.getsource(function).strip()
813 else: 815 else:
814 function_info = '%s()' % function.func_name 816 function_info = '%s()' % function.func_name
815 logging.debug('WaitUntil(%s:%d %s) still waiting. ' 817 logging.debug('WaitUntil(%s:%d %s) still waiting. '
816 'Expecting %s. Last returned %s.', 818 'Expecting %s. Last returned %s.',
817 os.path.basename(inspect.getsourcefile(function)), 819 os.path.basename(inspect.getsourcefile(function)),
818 inspect.getsourcelines(function)[1], 820 inspect.getsourcelines(function)[1],
(...skipping 4352 matching lines...) Expand 10 before | Expand all | Expand 10 after
5171 5173
5172 Returns: 5174 Returns:
5173 The SSID of the connected network or None if we're not connected. 5175 The SSID of the connected network or None if we're not connected.
5174 """ 5176 """
5175 service_list = self.GetNetworkInfo() 5177 service_list = self.GetNetworkInfo()
5176 connected_service_path = service_list.get('connected_wifi') 5178 connected_service_path = service_list.get('connected_wifi')
5177 if 'wifi_networks' in service_list and \ 5179 if 'wifi_networks' in service_list and \
5178 connected_service_path in service_list['wifi_networks']: 5180 connected_service_path in service_list['wifi_networks']:
5179 return service_list['wifi_networks'][connected_service_path]['name'] 5181 return service_list['wifi_networks'][connected_service_path]['name']
5180 5182
5181 def GetServicePath(self, ssid): 5183 def GetServicePath(self, ssid, encryption=None, timeout=30):
5182 """Returns the service path associated with an SSID. 5184 """Waits until the SSID is observed and returns its service path.
5183 5185
5184 Args: 5186 Args:
5185 ssid: String defining the SSID we are searching for. 5187 ssid: String defining the SSID we are searching for.
5188 encryption: Encryption type of the network; either None to return the
5189 first instance of network that matches the ssid, '' for
5190 an empty network, 'PSK', 'WEP' or '8021X'.
5191 timeout: Duration to wait for ssid to appear.
5186 5192
5187 Returns: 5193 Returns:
5188 The service path or None if SSID does not exist. 5194 The service path or None if SSID does not exist after timeout period.
5189 """ 5195 """
5190 service_list = self.GetNetworkInfo() 5196 def _get_service_path():
5191 service_list = service_list.get('wifi_networks', []) 5197 service_list = self.GetNetworkInfo().get('wifi_networks', [])
5192 for service_path, service_obj in service_list.iteritems(): 5198 for service_path, service_obj in service_list.iteritems():
5193 if service_obj['name'] == ssid: 5199 service_encr = 'PSK' if service_obj['encryption'] in ['WPA', 'RSN'] \
5194 return service_path 5200 else service_obj['encryption']
5195 return None 5201
5202 if service_obj['name'] == ssid and \
5203 (encryption == None or service_encr == encryption):
5204 return service_path
5205 self.NetworkScan()
5206 return None
5207
5208 service_path = self.WaitUntil(_get_service_path, timeout=timeout,
5209 retry_sleep=1)
5210 return service_path or None
5196 5211
5197 def NetworkScan(self): 5212 def NetworkScan(self):
5198 """Causes ChromeOS to scan for available wifi networks. 5213 """Causes ChromeOS to scan for available wifi networks.
5199 5214
5200 Blocks until scanning is complete. 5215 Blocks until scanning is complete.
5201 5216
5202 Returns: 5217 Returns:
5203 The new list of networks obtained from GetNetworkInfo(). 5218 The new list of networks obtained from GetNetworkInfo().
5204 5219
5205 Raises: 5220 Raises:
(...skipping 1453 matching lines...) Expand 10 before | Expand all | Expand 10 after
6659 successful = result.wasSuccessful() 6674 successful = result.wasSuccessful()
6660 if not successful: 6675 if not successful:
6661 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) 6676 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename)
6662 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ 6677 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \
6663 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) 6678 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL)
6664 sys.exit(not successful) 6679 sys.exit(not successful)
6665 6680
6666 6681
6667 if __name__ == '__main__': 6682 if __name__ == '__main__':
6668 Main() 6683 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