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

Unified 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: Fixed WaitUntil to work with GetServicePath 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/pyautolib/pyauto.py
diff --git a/chrome/test/pyautolib/pyauto.py b/chrome/test/pyautolib/pyauto.py
index 7ef8b953fed768b0f43e23ae388d4e24c10b4f56..50f13f3f605615260f6e6813e33b5a4c6d06d739 100755
--- a/chrome/test/pyautolib/pyauto.py
+++ b/chrome/test/pyautolib/pyauto.py
@@ -758,7 +758,7 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
return PyUITest.EvalDataFrom(private_file)
def WaitUntil(self, function, timeout=-1, retry_sleep=0.25, args=[],
- expect_retval=None, debug=True):
+ expect_retval=None, keep_retval=False, debug=True):
"""Poll on a condition until timeout.
Waits until the |function| evalues to |expect_retval| or until |timeout|
@@ -791,10 +791,14 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
exit criteria. In case this is None (the default),
|function|'s return value is checked for truth,
so 'non-empty-string' should match with True
+ keep_retval: Boolean indicating whether to return the retval of the last
+ iteration of |function| that succeeded without a timeout, or
+ True.
debug: if True, displays debug info at each retry.
Returns:
- True, if returning when |function| evaluated to True
+ The return value of the calling function when |function| evaluates to True
+ and the keep_retval is True, or True when keep_retval is false.
False, when returning due to timeout
"""
if timeout == -1: # Default
@@ -804,8 +808,9 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
debug_begin = begin
while timeout is None or time.time() - begin <= timeout:
retval = function(*args)
- if (expect_retval is None and retval) or expect_retval == retval:
- return True
+ if (expect_retval is None and retval) or \
+ (expect_retval is not None and expect_retval == retval):
+ return {True: retval, False: True}[keep_retval]
Nirnimesh 2012/08/08 19:51:13 I think it'll be fine if you just return retval he
stanleyw 2012/08/08 21:38:35 Done.
if debug and time.time() - debug_begin > 5:
debug_begin += 5
if function.func_name == (lambda: True).func_name:
@@ -5178,21 +5183,34 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
connected_service_path in service_list['wifi_networks']:
return service_list['wifi_networks'][connected_service_path]['name']
- def GetServicePath(self, ssid):
- """Returns the service path associated with an SSID.
+ def GetServicePath(self, ssid, encryption=None, timeout=30):
+ """Waits until the SSID is observed and returns its service path.
Args:
ssid: String defining the SSID we are searching for.
+ encryption: Encryption type of the network; either None to return the
+ first instance of network that matches the ssid, '' for
+ an empty network, 'PSK', 'WEP' or '8021X'.
+ timeout: Duration to wait for ssid to appear.
Returns:
- The service path or None if SSID does not exist.
- """
- service_list = self.GetNetworkInfo()
- service_list = service_list.get('wifi_networks', [])
- for service_path, service_obj in service_list.iteritems():
- if service_obj['name'] == ssid:
- return service_path
- return None
+ The service path or None if SSID does not exist after timeout period.
+ """
+ def _get_service_path():
+ service_list = self.GetNetworkInfo().get('wifi_networks', [])
+ for service_path, service_obj in service_list.iteritems():
+ service_encr = 'PSK' if service_obj['encryption'] in ['WPA', 'RSN'] \
+ else service_obj['encryption']
+
+ if service_obj['name'] == ssid and \
+ (encryption == None or service_encr == encryption):
+ return service_path
+ self.NetworkScan()
+ return None
+
+ service_path = self.WaitUntil(_get_service_path, keep_retval=True,
+ timeout=timeout, retry_sleep=1)
+ return service_path or None
def NetworkScan(self):
"""Causes ChromeOS to scan for available wifi networks.
« 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