diff options
author | nirnimesh@chromium.org <nirnimesh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-17 21:04:18 +0000 |
---|---|---|
committer | nirnimesh@chromium.org <nirnimesh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-17 21:04:18 +0000 |
commit | b94724ed2d21cae98a0f15ae35a23ae45898b4b7 (patch) | |
tree | 6b4331da5a26c7073c34a19d9bdd045bc2f308af | |
parent | 428c0f261b9fd5aa5435050131a440c6a6ed2fd6 (diff) | |
download | chromium_src-b94724ed2d21cae98a0f15ae35a23ae45898b4b7.zip chromium_src-b94724ed2d21cae98a0f15ae35a23ae45898b4b7.tar.gz chromium_src-b94724ed2d21cae98a0f15ae35a23ae45898b4b7.tar.bz2 |
PyAuto: Flags to forbid cleaning profile dir
Several tests require quitting/killing chromium to test features like
restore. In addition, one might want to use pyauto on an existing profile.
This CL lets pyauto work without cleaning the profile dir.
Also lets specify the homepage to use.
Example: Running this test with CHROME_UI_TESTS_USER_DATA_DIR pointing to a
profile dir will run my script with the given dir as the user-data-dir
without cleaning it up, and also specifies the homepage to use.
class A(PyUITest):
def __init__(self, methodName):
PyUITest.__init__(self, methodName, clear_profile=False,
homepage="http://www.cnn.com")
def testA(self):
pass
BUG=None
TEST=None
Review URL: http://codereview.chromium.org/1007007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@41878 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/test/pyautolib/pyauto.py | 20 | ||||
-rw-r--r-- | chrome/test/pyautolib/pyautolib.cc | 5 | ||||
-rw-r--r-- | chrome/test/pyautolib/pyautolib.h | 5 | ||||
-rw-r--r-- | chrome/test/pyautolib/pyautolib.i | 9 | ||||
-rw-r--r-- | chrome/test/ui/ui_test.h | 12 |
5 files changed, 41 insertions, 10 deletions
diff --git a/chrome/test/pyautolib/pyauto.py b/chrome/test/pyautolib/pyauto.py index d910489..7ddca87 100644 --- a/chrome/test/pyautolib/pyauto.py +++ b/chrome/test/pyautolib/pyauto.py @@ -68,7 +68,7 @@ class PyUITest(pyautolib.PyUITestSuite, unittest.TestCase): self.assertTrue("Google" == self.GetActiveTabTitle()) """ - def __init__(self, methodName='runTest', extra_chrome_flags=None): + def __init__(self, methodName='runTest', **kwargs): """Initialize PyUITest. When redefining __init__ in a derived class, make sure that: @@ -77,12 +77,24 @@ class PyUITest(pyautolib.PyUITestSuite, unittest.TestCase): Args: methodName: the default method name. Internal use by unittest module - extra_chrome_flags: additional flags to pass when launching chrome + + (The rest of the args can be in any order. They can even be skipped in + which case the defaults will be used.) + + extra_chrome_flags: additional flags to pass when launching chrome. + Defaults to None + clear_profile: If True, clean the profile dir before use. Defaults to True + homepage: the home page. Defaults to "about:blank" """ + # Fetch provided keyword args, or fill in defaults. + extra_chrome_flags = kwargs.get('extra_chrome_flags') + clear_profile = kwargs.get('clear_profile', True) + homepage = kwargs.get('homepage', 'about:blank') + args = sys.argv - if extra_chrome_flags is not None: + if extra_chrome_flags: args.append('--extra-chrome-flags=%s' % extra_chrome_flags) - pyautolib.PyUITestSuite.__init__(self, args) + pyautolib.PyUITestSuite.__init__(self, args, clear_profile, homepage) # Figure out path to chromium binaries browser_dir = os.path.normpath(os.path.dirname(pyautolib.__file__)) os.environ['PATH'] = browser_dir + os.pathsep + os.environ['PATH'] diff --git a/chrome/test/pyautolib/pyautolib.cc b/chrome/test/pyautolib/pyautolib.cc index f009549..14e0c8e 100644 --- a/chrome/test/pyautolib/pyautolib.cc +++ b/chrome/test/pyautolib/pyautolib.cc @@ -9,9 +9,12 @@ #include "chrome/test/pyautolib/pyautolib.h" #include "googleurl/src/gurl.h" -PyUITestSuite::PyUITestSuite(int argc, char** argv) +PyUITestSuite::PyUITestSuite( + int argc, char** argv, bool clear_profile, std::wstring homepage) : UITestSuite(argc, argv), UITestBase() { + set_clear_profile(clear_profile); + set_homepage(homepage); } PyUITestSuite::~PyUITestSuite() { diff --git a/chrome/test/pyautolib/pyautolib.h b/chrome/test/pyautolib/pyautolib.h index 154c97c..7e87171 100644 --- a/chrome/test/pyautolib/pyautolib.h +++ b/chrome/test/pyautolib/pyautolib.h @@ -27,7 +27,10 @@ class PyUITestSuite : public UITestSuite, public UITestBase { public: // Only public methods are accessible from swig. - PyUITestSuite(int argc, char** argv); + + // Constructor. Lookup pyauto.py for doc on these args. + PyUITestSuite(int argc, char** argv, bool clear_profile, + std::wstring homepage); ~PyUITestSuite(); // Initialize the setup. Should be called before launching the browser. diff --git a/chrome/test/pyautolib/pyautolib.i b/chrome/test/pyautolib/pyautolib.i index e181a71..51755bb 100644 --- a/chrome/test/pyautolib/pyautolib.i +++ b/chrome/test/pyautolib/pyautolib.i @@ -79,7 +79,8 @@ class FilePath { class PyUITestSuite { public: - PyUITestSuite(int argc, char** argv); + PyUITestSuite(int argc, char** argv, bool clear_profile, + std::wstring homepage); %feature("docstring", "Initialize the entire setup. Should be called " "before launching the browser. For internal use.") Initialize; @@ -130,12 +131,12 @@ class PyUITestSuite { "given or first browser window.") IsDownloadShelfVisible; bool IsDownloadShelfVisible(int window_index=0); - %feature("docstring", "Determine if the bookmark bar is visible. " + %feature("docstring", "Determine if the bookmark bar is visible. " "If the NTP is visible, only return true if attached " - "(to the chrome).") GetBookmarkBarVisibility; + "(to the chrome).") GetBookmarkBarVisibility; bool GetBookmarkBarVisibility(); - %feature("docstring", "Wait for the bookmark bar animation to complete. " + %feature("docstring", "Wait for the bookmark bar animation to complete. " "|wait_for_open| specifies which kind of change we wait for.") WaitForBookmarkBarVisibilityChange; bool WaitForBookmarkBarVisibilityChange(bool wait_for_open); diff --git a/chrome/test/ui/ui_test.h b/chrome/test/ui/ui_test.h index 56c7e9c..334e8b2 100644 --- a/chrome/test/ui/ui_test.h +++ b/chrome/test/ui/ui_test.h @@ -435,6 +435,18 @@ class UITestBase { ui_test_name_ = name; } + // Sets clear_profile_. Should be called before launching browser to have + // any effect. + void set_clear_profile(bool clear_profile) { + clear_profile_ = clear_profile; + } + + // Sets homepage_. Should be called before launching browser to have + // any effect. + void set_homepage(const std::wstring& homepage) { + homepage_ = homepage; + } + // Count the number of active browser processes launched by this test. // The count includes browser sub-processes. int GetBrowserProcessCount(); |