diff options
author | nirnimesh@chromium.org <nirnimesh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-19 17:38:46 +0000 |
---|---|---|
committer | nirnimesh@chromium.org <nirnimesh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-19 17:38:46 +0000 |
commit | 0f4df150382b049652815cccc7f968b5c0d8b4d4 (patch) | |
tree | 78ede3ac638669cf51c584ff3e1e7c0ce3054403 /chrome/test/pyautolib | |
parent | 2a8b33a89f9e4e68a8909cb45e716f4cb80f8238 (diff) | |
download | chromium_src-0f4df150382b049652815cccc7f968b5c0d8b4d4.zip chromium_src-0f4df150382b049652815cccc7f968b5c0d8b4d4.tar.gz chromium_src-0f4df150382b049652815cccc7f968b5c0d8b4d4.tar.bz2 |
testFileRenaming: Test file renaming when downloading a already-existing file
Also, fix download problem when downloading a file. Since we use NavigateToURL() to trigger a download, it might take a while for it to actually start downloading and doing WaitForAllDownloadsToComplete() won't work until downloads actually start. Used WaitUntil for this. (WaitUntil has been reviewed earlier in http://codereview.chromium.org/1541009).
Review URL: http://codereview.chromium.org/1575043
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@44924 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/pyautolib')
-rw-r--r-- | chrome/test/pyautolib/pyauto.py | 45 | ||||
-rw-r--r-- | chrome/test/pyautolib/pyautolib.i | 5 |
2 files changed, 50 insertions, 0 deletions
diff --git a/chrome/test/pyautolib/pyauto.py b/chrome/test/pyautolib/pyauto.py index 41e7889..cae280d 100644 --- a/chrome/test/pyautolib/pyauto.py +++ b/chrome/test/pyautolib/pyauto.py @@ -30,6 +30,7 @@ import optparse import os import re import sys +import time import types import unittest @@ -137,6 +138,50 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase): """Returns the path to the data dir chrome/test/data.""" return os.path.join(os.path.dirname(__file__), os.pardir, "data") + def WaitUntil(self, function, timeout=-1, retry_sleep=0.25, args=[]): + """Poll on a condition until timeout. + + Waits until the |function| evalues to True or until |timeout| secs, + whichever occurs earlier. + + This is better than using a sleep, since it waits (almost) only as much + as needed. + + WARNING: This method call should be avoided as far as possible in favor + of a real wait from chromium (like wait-until-page-loaded). + Only use in case there's really no better option. + + EXAMPLES:- + Wait for "file.txt" to get created: + WaitUntil(os.path.exists, args=["file.txt"]) + + Same as above, but using lambda: + WaitUntil(lambda: os.path.exists("file.txt")) + + Args: + function: the function whose truth value is to be evaluated + timeout: the max timeout (in secs) for which to wait. The default + action is to wait for 60secs, and can be changed by + changing kWaitForActionMaxMsec in ui_test.cc. + Use None to wait indefinitely. + retry_sleep: the sleep interval (in secs) before retrying |function|. + Deaults to 0.25 secs. + args: the args to pass to |function| + + Returns: + True, if returning when |function| evaluated to True + False, when returning due to timeout + """ + if timeout == -1: # Default + timeout = self.action_max_timeout_ms()/1000.0 + assert callable(function), "function should be a callable" + begin = time.time() + while timeout is None or time.time() - begin <= timeout: + if function(*args): + return True + time.sleep(retry_sleep) + return False + def GetBookmarkModel(self): """Return the bookmark model as a BookmarkModel object. diff --git a/chrome/test/pyautolib/pyautolib.i b/chrome/test/pyautolib/pyautolib.i index 885bea8..3fdddc4 100644 --- a/chrome/test/pyautolib/pyautolib.i +++ b/chrome/test/pyautolib/pyautolib.i @@ -179,6 +179,11 @@ class PyUITestBase { "Closes all windows and destroys the browser.") TearDown; virtual void TearDown(); + %feature("docstring", "Timeout (in milli secs) for an action. " + "This value is also used as default for the WaitUntil() method.") + action_max_timeout_ms; + int action_max_timeout_ms() const; + %feature("docstring", "Launches the browser and IPC testing server.") LaunchBrowserAndServer; void LaunchBrowserAndServer(); |