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

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: Rate limiter 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 5046 matching lines...) Expand 10 before | Expand all | Expand 10 after
5057 5057
5058 Returns: 5058 Returns:
5059 The SSID of the connected network or None if we're not connected. 5059 The SSID of the connected network or None if we're not connected.
5060 """ 5060 """
5061 service_list = self.GetNetworkInfo() 5061 service_list = self.GetNetworkInfo()
5062 connected_service_path = service_list.get('connected_wifi') 5062 connected_service_path = service_list.get('connected_wifi')
5063 if 'wifi_networks' in service_list and \ 5063 if 'wifi_networks' in service_list and \
5064 connected_service_path in service_list['wifi_networks']: 5064 connected_service_path in service_list['wifi_networks']:
5065 return service_list['wifi_networks'][connected_service_path]['name'] 5065 return service_list['wifi_networks'][connected_service_path]['name']
5066 5066
5067 def GetServicePath(self, ssid): 5067 def GetServicePath(self, ssid, encryption=None, timeout=30):
5068 """Returns the service path associated with an SSID. 5068 """Returns the service path associated with an SSID.
Nirnimesh 2012/08/07 23:44:50 Update to mention "Wait until"
stanleyw 2012/08/08 19:29:08 Done.
5069 5069
5070 Args: 5070 Args:
5071 ssid: String defining the SSID we are searching for. 5071 ssid: String defining the SSID we are searching for.
5072 encryption: Encryption type of the network; either None to return the
5073 first instance of network that matches the ssid, '' for
5074 an empty network, 'PSK', 'WEP' or '8021X'.
5075 timeout: Duration to wait for ssid to appear.
5072 5076
5073 Returns: 5077 Returns:
5074 The service path or None if SSID does not exist. 5078 The service path or None if SSID does not exist after timeout period.
5075 """ 5079 """
5076 service_list = self.GetNetworkInfo() 5080 end_time = time.time() + timeout
5077 service_list = service_list.get('wifi_networks', []) 5081 while time.time() < end_time:
Nirnimesh 2012/08/07 23:44:50 Do not reinvent polling loop. Use WaitUntil()
stanleyw 2012/08/08 00:35:17 I did initially. Unfortunately, I need a particul
Nirnimesh 2012/08/08 00:48:26 WaitUntil returns the value that the callable retu
stanleyw 2012/08/08 19:29:08 Re-did WaitUntil to do this. On 2012/08/08 00:48
5078 for service_path, service_obj in service_list.iteritems(): 5082 service_list = self.GetNetworkInfo().get('wifi_networks', [])
5079 if service_obj['name'] == ssid: 5083 for service_path, service_obj in service_list.iteritems():
5080 return service_path 5084 service_encr = 'PSK' if service_obj['encryption'] in ['WPA', 'RSN'] \
5085 else service_obj['encryption']
5086
5087 if service_obj['name'] == ssid and \
5088 (encryption == None or service_encr == encryption):
5089 return service_path
5090 self.NetworkScan()
5091 time.sleep(1)
5081 return None 5092 return None
5082 5093
5083 def NetworkScan(self): 5094 def NetworkScan(self):
5084 """Causes ChromeOS to scan for available wifi networks. 5095 """Causes ChromeOS to scan for available wifi networks.
5085 5096
5086 Blocks until scanning is complete. 5097 Blocks until scanning is complete.
5087 5098
5088 Returns: 5099 Returns:
5089 The new list of networks obtained from GetNetworkInfo(). 5100 The new list of networks obtained from GetNetworkInfo().
5090 5101
(...skipping 1454 matching lines...) Expand 10 before | Expand all | Expand 10 after
6545 successful = result.wasSuccessful() 6556 successful = result.wasSuccessful()
6546 if not successful: 6557 if not successful:
6547 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) 6558 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename)
6548 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ 6559 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \
6549 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) 6560 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL)
6550 sys.exit(not successful) 6561 sys.exit(not successful)
6551 6562
6552 6563
6553 if __name__ == '__main__': 6564 if __name__ == '__main__':
6554 Main() 6565 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