Fix passwords.PasswordTest.testInfoBarDisappearByNavigatingPage

Revert to the old behavior of WaitUntil such that it returns True when the
callable succeeds (default). Provide a way for it to return the last return
value of the callable if required.

TBR=stanleyw@chromium.org
BUG=

Review URL: https://chromiumcodereview.appspot.com/10854229

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@152368 0039d316-1c4b-4281-b951-d872f2087c98
parent 610f923b
...@@ -785,7 +785,7 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase): ...@@ -785,7 +785,7 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
return PyUITest.EvalDataFrom(private_file) return PyUITest.EvalDataFrom(private_file)
def WaitUntil(self, function, timeout=-1, retry_sleep=0.25, args=[], def WaitUntil(self, function, timeout=-1, retry_sleep=0.25, args=[],
expect_retval=None, debug=True): expect_retval=None, return_retval=False, debug=True):
"""Poll on a condition until timeout. """Poll on a condition until timeout.
Waits until the |function| evalues to |expect_retval| or until |timeout| Waits until the |function| evalues to |expect_retval| or until |timeout|
...@@ -818,11 +818,14 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase): ...@@ -818,11 +818,14 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
exit criteria. In case this is None (the default), exit criteria. In case this is None (the default),
|function|'s return value is checked for truth, |function|'s return value is checked for truth,
so 'non-empty-string' should match with True so 'non-empty-string' should match with True
return_retval: If True, return the value returned by the last call to
|function()|
debug: if True, displays debug info at each retry. debug: if True, displays debug info at each retry.
Returns: Returns:
The return value of the calling function when |function| evaluates to The return value of the |function| (when return_retval == True)
True. True, if returning when |function| evaluated to True (when
return_retval == False)
False, when returning due to timeout False, when returning due to timeout
""" """
if timeout == -1: # Default if timeout == -1: # Default
...@@ -830,11 +833,12 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase): ...@@ -830,11 +833,12 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
assert callable(function), "function should be a callable" assert callable(function), "function should be a callable"
begin = time.time() begin = time.time()
debug_begin = begin debug_begin = begin
retval = None
while timeout is None or time.time() - begin <= timeout: while timeout is None or time.time() - begin <= timeout:
retval = function(*args) retval = function(*args)
if (expect_retval is None and retval) or \ if (expect_retval is None and retval) or \
(expect_retval is not None and expect_retval == retval): (expect_retval is not None and expect_retval == retval):
return retval return retval if return_retval else True
if debug and time.time() - debug_begin > 5: if debug and time.time() - debug_begin > 5:
debug_begin += 5 debug_begin += 5
if function.func_name == (lambda: True).func_name: if function.func_name == (lambda: True).func_name:
...@@ -849,7 +853,7 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase): ...@@ -849,7 +853,7 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
True if expect_retval is None else expect_retval, True if expect_retval is None else expect_retval,
retval) retval)
time.sleep(retry_sleep) time.sleep(retry_sleep)
return False return retval if return_retval else False
def StartSyncServer(self): def StartSyncServer(self):
"""Start a local sync server. """Start a local sync server.
...@@ -5516,7 +5520,7 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase): ...@@ -5516,7 +5520,7 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
Returns: Returns:
The service path or None if SSID does not exist after timeout period. The service path or None if SSID does not exist after timeout period.
""" """
def _get_service_path(): def _GetServicePath():
service_list = self.GetNetworkInfo().get('wifi_networks', []) service_list = self.GetNetworkInfo().get('wifi_networks', [])
for service_path, service_obj in service_list.iteritems(): for service_path, service_obj in service_list.iteritems():
service_encr = 'PSK' if service_obj['encryption'] in ['WPA', 'RSN'] \ service_encr = 'PSK' if service_obj['encryption'] in ['WPA', 'RSN'] \
...@@ -5528,8 +5532,8 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase): ...@@ -5528,8 +5532,8 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
self.NetworkScan() self.NetworkScan()
return None return None
service_path = self.WaitUntil(_get_service_path, timeout=timeout, service_path = self.WaitUntil(_GetServicePath, timeout=timeout,
retry_sleep=1) retry_sleep=1, return_retval=True)
return service_path or None return service_path or None
def NetworkScan(self): def NetworkScan(self):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment