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

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

Issue 10264012: Move WaitUntilWifiNetworkAvailable and GetServicePath to pyauto so it can be reached from autotest (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 7 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 | « chrome/test/pyautolib/chromeos_network.py ('k') | 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 4215 matching lines...) Expand 10 before | Expand all | Expand 10 after
4226 4226
4227 # Remembered networks do not have /service/ prepended to the service path 4227 # Remembered networks do not have /service/ prepended to the service path
4228 # even though wifi_networks does. We want this prepended to allow for 4228 # even though wifi_networks does. We want this prepended to allow for
4229 # consistency and easy string comparison with wifi_networks. 4229 # consistency and easy string comparison with wifi_networks.
4230 remembered_wifi = {} 4230 remembered_wifi = {}
4231 network_info['remembered_wifi'] = dict([('/service/' + k, v) for k, v in 4231 network_info['remembered_wifi'] = dict([('/service/' + k, v) for k, v in
4232 network_info['remembered_wifi'].iteritems()]) 4232 network_info['remembered_wifi'].iteritems()])
4233 4233
4234 return network_info 4234 return network_info
4235 4235
4236 def GetConnectedWifi(self):
4237 """Returns the SSID of the currently connected wifi network.
dtu 2012/04/30 21:26:05 Add "on ChromeOS" or something like that. Same wit
4238
4239 Returns:
4240 The SSID of the connected network or None if we're not connected.
4241 """
4242 service_list = self.GetNetworkInfo()
4243 connected_service_path = service_list.get('connected_wifi')
4244 if 'wifi_networks' in service_list and \
4245 connected_service_path in service_list['wifi_networks']:
4246 return service_list['wifi_networks'][connected_service_path]['name']
4247
4248 def GetServicePath(self, ssid):
4249 """Returns the service path associated with an SSID.
4250
4251 Args:
4252 ssid: String defining the SSID we are searching for.
4253
4254 Returns:
4255 The service path or None if SSID does not exist.
4256 """
4257 service_list = self.GetNetworkInfo()
4258 service_list = service_list.get('wifi_networks', [])
4259 for service_path, service_obj in service_list.iteritems():
4260 if service_obj['name'] == ssid:
4261 return service_path
4262 return None
4263
4236 def NetworkScan(self): 4264 def NetworkScan(self):
4237 """Causes ChromeOS to scan for available wifi networks. 4265 """Causes ChromeOS to scan for available wifi networks.
4238 4266
4239 Blocks until scanning is complete. 4267 Blocks until scanning is complete.
4240 4268
4241 Returns: 4269 Returns:
4242 The new list of networks obtained from GetNetworkInfo(). 4270 The new list of networks obtained from GetNetworkInfo().
4243 4271
4244 Raises: 4272 Raises:
4245 pyauto_errors.JSONInterfaceError if the automation call returns an error. 4273 pyauto_errors.JSONInterfaceError if the automation call returns an error.
(...skipping 14 matching lines...) Expand all
4260 'command': 'ToggleNetworkDevice', 4288 'command': 'ToggleNetworkDevice',
4261 'device': device, 4289 'device': device,
4262 'enable': enable, 4290 'enable': enable,
4263 } 4291 }
4264 return self._GetResultFromJSONRequest(cmd_dict, windex=None) 4292 return self._GetResultFromJSONRequest(cmd_dict, windex=None)
4265 4293
4266 PROXY_TYPE_DIRECT = 1 4294 PROXY_TYPE_DIRECT = 1
4267 PROXY_TYPE_MANUAL = 2 4295 PROXY_TYPE_MANUAL = 2
4268 PROXY_TYPE_PAC = 3 4296 PROXY_TYPE_PAC = 3
4269 4297
4298 def WaitUntilWifiNetworkAvailable(self, ssid, timeout=60, is_hidden=False):
4299 """Waits until the given network is available.
4300
4301 Routers that are just turned on may take up to 1 minute upon turning them
4302 on to broadcast their SSID.
4303
4304 Args:
4305 ssid: SSID of the service we want to connect to.
4306 timeout: timeout (in seconds)
4307
4308 Raises:
4309 Exception if timeout duration has been hit before wifi router is seen.
4310
4311 Returns:
4312 True, when the wifi network is seen within the timout period.
4313 False, otherwise.
4314 """
4315 def _GotWifiNetwork():
4316 # Returns non-empty array if desired SSID is available.
4317 try:
4318 return [wifi for wifi in
4319 self.NetworkScan().get('wifi_networks', {}).values()
4320 if wifi.get('name') == ssid]
4321 except pyauto_errors.JSONInterfaceError:
4322 # Temporary fix until crosbug.com/14174 is fixed.
4323 # NetworkScan is only used in updating the list of networks so errors
4324 # thrown by it are not critical to the results of wifi tests that use
4325 # this method.
4326 return False
4327
4328 # The hidden AP's will always be on, thus we will assume it is ready to
4329 # connect to.
4330 if is_hidden:
4331 return bool(_GotWifiNetwork())
4332
4333 return self.WaitUntil(_GotWifiNetwork, timeout=timeout, retry_sleep=1)
4334
4270 def GetProxyTypeName(self, proxy_type): 4335 def GetProxyTypeName(self, proxy_type):
4271 values = { self.PROXY_TYPE_DIRECT: 'Direct Internet connection', 4336 values = { self.PROXY_TYPE_DIRECT: 'Direct Internet connection',
4272 self.PROXY_TYPE_MANUAL: 'Manual proxy configuration', 4337 self.PROXY_TYPE_MANUAL: 'Manual proxy configuration',
4273 self.PROXY_TYPE_PAC: 'Automatic proxy configuration' } 4338 self.PROXY_TYPE_PAC: 'Automatic proxy configuration' }
4274 return values[proxy_type] 4339 return values[proxy_type]
4275 4340
4276 def GetProxySettingsOnChromeOS(self, windex=0): 4341 def GetProxySettingsOnChromeOS(self, windex=0):
4277 """Get current proxy settings on Chrome OS. 4342 """Get current proxy settings on Chrome OS.
4278 4343
4279 Returns: 4344 Returns:
(...skipping 1151 matching lines...) Expand 10 before | Expand all | Expand 10 after
5431 successful = result.wasSuccessful() 5496 successful = result.wasSuccessful()
5432 if not successful: 5497 if not successful:
5433 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) 5498 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename)
5434 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ 5499 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \
5435 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) 5500 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL)
5436 sys.exit(not successful) 5501 sys.exit(not successful)
5437 5502
5438 5503
5439 if __name__ == '__main__': 5504 if __name__ == '__main__':
5440 Main() 5505 Main()
OLDNEW
« no previous file with comments | « chrome/test/pyautolib/chromeos_network.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698