diff options
author | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-21 17:10:20 +0000 |
---|---|---|
committer | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-21 17:10:20 +0000 |
commit | 831fe580967810a1f4d0ac57f23aec56c82afd49 (patch) | |
tree | 9003698cfcc593ddd35d6d990d14ef1ec80f1ebe /chrome/test/ui | |
parent | 0f43b4a799e778fac0ecb6bdb3a129096e156a90 (diff) | |
download | chromium_src-831fe580967810a1f4d0ac57f23aec56c82afd49.zip chromium_src-831fe580967810a1f4d0ac57f23aec56c82afd49.tar.gz chromium_src-831fe580967810a1f4d0ac57f23aec56c82afd49.tar.bz2 |
GTTF: Make ui_tests more reliable by using a temporary profile directory
for each test.
TEST=ui_tests
BUG=none
Review URL: http://codereview.chromium.org/2856047
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@53202 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/ui')
-rw-r--r-- | chrome/test/ui/ui_test.cc | 50 | ||||
-rw-r--r-- | chrome/test/ui/ui_test.h | 8 |
2 files changed, 29 insertions, 29 deletions
diff --git a/chrome/test/ui/ui_test.cc b/chrome/test/ui/ui_test.cc index 90e1550..3b92b99 100644 --- a/chrome/test/ui/ui_test.cc +++ b/chrome/test/ui/ui_test.cc @@ -21,6 +21,7 @@ #include "base/platform_thread.h" #include "base/process_util.h" #include "base/scoped_ptr.h" +#include "base/scoped_temp_dir.h" #include "base/string_util.h" #include "base/test/test_file_util.h" #include "base/time.h" @@ -125,7 +126,8 @@ UITestBase::UITestBase() action_timeout_ms_(kWaitForActionMsec), action_max_timeout_ms_(kWaitForActionMaxMsec), sleep_timeout_ms_(kWaitForActionMsec), - terminate_timeout_ms_(kWaitForTerminateMsec) { + terminate_timeout_ms_(kWaitForTerminateMsec), + temp_profile_dir_(new ScopedTempDir()) { PathService::Get(chrome::DIR_APP, &browser_directory_); PathService::Get(chrome::DIR_TEST_DATA, &test_data_directory_); } @@ -359,37 +361,25 @@ void UITestBase::StopHttpServer() { void UITestBase::LaunchBrowser(const CommandLine& arguments, bool clear_profile) { -#if defined(OS_POSIX) - const char* alternative_userdir = getenv("CHROME_UI_TESTS_USER_DATA_DIR"); -#else - const FilePath::StringType::value_type* const alternative_userdir = NULL; -#endif - - if (alternative_userdir) { - user_data_dir_ = FilePath(alternative_userdir); - } else { - PathService::Get(chrome::DIR_USER_DATA, &user_data_dir_); + if (clear_profile || !temp_profile_dir_->IsValid()) { + temp_profile_dir_.reset(new ScopedTempDir()); + ASSERT_TRUE(temp_profile_dir_->CreateUniqueTempDir()); + + // Update the information about user data directory location on the ui_test + // side. Using PathService seems to be the most reliable, consistent way + // to do that. + ASSERT_TRUE(PathService::Override(chrome::DIR_USER_DATA, user_data_dir())); } - // Clear user data directory to make sure test environment is consistent - // We balk on really short (absolute) user_data_dir directory names, because - // we're worried that they'd accidentally be root or something. - ASSERT_LT(10, static_cast<int>(user_data_dir_.value().size())) << - "The user data directory name passed into this test was too " - "short to delete safely. Please check the user-data-dir " - "argument and try again."; - if (clear_profile) - ASSERT_TRUE(file_util::DieFileDie(user_data_dir_, true)); - if (!template_user_data_.empty()) { // Recursively copy the template directory to the user_data_dir. ASSERT_TRUE(file_util::CopyRecursiveDirNoCache( template_user_data_, - user_data_dir_)); + user_data_dir())); // If we're using the complex theme data, we need to write the // user_data_dir_ to our preferences file. if (profile_type_ == UITestBase::COMPLEX_THEME) { - RewritePreferencesFile(user_data_dir_); + RewritePreferencesFile(user_data_dir()); } // Update the history file to include recent dates. @@ -1024,6 +1014,11 @@ void UITestBase::RewritePreferencesFile(const FilePath& user_data_dir) { file_util::EvictFileFromSystemCache(pref_path); } +FilePath UITestBase::user_data_dir() const { + EXPECT_TRUE(temp_profile_dir_->IsValid()); + return temp_profile_dir_->path(); +} + // static FilePath UITestBase::ComputeTypicalUserDataSource(ProfileType profile_type) { FilePath source_history_file; @@ -1126,6 +1121,10 @@ bool UITestBase::LaunchBrowserHelper(const CommandLine& arguments, command_line.AppendSwitchWithValue(switches::kTestType, ASCIIToWide(kUITestType)); + // Tell the browser to use a temporary directory just for this test. + command_line.AppendSwitchWithValue(switches::kUserDataDir, + user_data_dir().ToWStringHack()); + // We need cookies on file:// for things like the page cycler. if (enable_file_cookies_) command_line.AppendSwitch(switches::kEnableFileCookies); @@ -1162,9 +1161,6 @@ bool UITestBase::LaunchBrowserHelper(const CommandLine& arguments, // Don't try to fetch web resources during UI testing. command_line.AppendSwitch(switches::kDisableWebResources); - if (!user_data_dir_.empty()) - command_line.AppendSwitchWithValue(switches::kUserDataDir, - user_data_dir_.ToWStringHack()); if (!js_flags_.empty()) command_line.AppendSwitchWithValue(switches::kJavaScriptFlags, js_flags_); @@ -1231,7 +1227,7 @@ void UITestBase::UpdateHistoryDates() { // actual thumbnails on the NTP. sql::Connection db; FilePath history = - user_data_dir_.AppendASCII("Default").AppendASCII("History"); + user_data_dir().AppendASCII("Default").AppendASCII("History"); // Not all test profiles have a history file. if (!file_util::PathExists(history)) return; diff --git a/chrome/test/ui/ui_test.h b/chrome/test/ui/ui_test.h index 783f637..859c2bb 100644 --- a/chrome/test/ui/ui_test.h +++ b/chrome/test/ui/ui_test.h @@ -36,6 +36,7 @@ class BrowserProxy; class DictionaryValue; class FilePath; class GURL; +class ScopedTempDir; class TabProxy; // Base class for UI Tests. This implements the core of the functions. @@ -398,7 +399,7 @@ class UITestBase { // Return the user data directory being used by the browser instance in // UITest::SetUp(). - FilePath user_data_dir() const { return user_data_dir_; } + FilePath user_data_dir() const; // Return the process id of the browser process (-1 on error). base::ProcessId browser_process_id() const { return process_id_; } @@ -565,7 +566,6 @@ class UITestBase { FilePath template_user_data_; // See set_template_user_data(). base::ProcessHandle process_; // Handle to the first Chrome process. base::ProcessId process_id_; // PID of |process_| (for debugging). - FilePath user_data_dir_; // User data directory used for the test static bool in_process_renderer_; // true if we're in single process mode bool show_window_; // Determines if the window is shown or // hidden. Defaults to hidden. @@ -618,6 +618,10 @@ class UITestBase { int terminate_timeout_ms_; std::wstring ui_test_name_; + + // We use a temporary directory for profile to avoid issues with being + // unable to delete some files because they're in use, etc. + scoped_ptr<ScopedTempDir> temp_profile_dir_; }; class UITest : public UITestBase, public PlatformTest { |