Chromium Code Reviews| Index: chrome/browser/profiles/profile_manager_unittest.cc |
| =================================================================== |
| --- chrome/browser/profiles/profile_manager_unittest.cc (revision 110703) |
| +++ chrome/browser/profiles/profile_manager_unittest.cc (working copy) |
| @@ -5,6 +5,7 @@ |
| #include <string> |
| #include "base/command_line.h" |
| +#include "base/file_util.h" |
| #include "base/message_loop.h" |
| #include "base/path_service.h" |
| #include "base/scoped_temp_dir.h" |
| @@ -44,6 +45,35 @@ |
| } // namespace |
| +namespace testing { |
| + |
| +class ProfileManager : public ::ProfileManagerWithoutInit { |
| + public: |
| + explicit ProfileManager(const FilePath& user_data_dir) |
| + : ::ProfileManagerWithoutInit(user_data_dir) {} |
| + |
| + protected: |
| + virtual Profile* CreateProfile(const FilePath& file_path) { |
| + if (!file_util::PathExists(file_path)) { |
| + if (!file_util::CreateDirectory(file_path)) |
| + return NULL; |
| + } |
| + return new TestingProfile(file_path, NULL); |
| + } |
| + |
| + virtual Profile* CreateAsyncProfile(const FilePath& path, |
| + Delegate* delegate) { |
| + // This is safe while all file operations are done on the FILE thread. |
| + BrowserThread::PostTask(BrowserThread::FILE, |
| + FROM_HERE, |
| + NewRunnableFunction(&file_util::CreateDirectory, |
| + path)); |
| + return new TestingProfile(path, this); |
|
Miranda Callahan
2011/11/21 15:31:31
Could there be any race conditions with immediatel
rpetterson
2011/11/21 22:59:30
Currently in the ProfileManager we call
ProfileInf
|
| + } |
| +}; |
| + |
| +} // namespace testing |
| + |
| class ProfileManagerTest : public testing::Test { |
| protected: |
| ProfileManagerTest() |
| @@ -65,7 +95,7 @@ |
| virtual void SetUp() { |
| // Create a new temporary directory, and store the path |
| ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| - profile_manager_.reset(new ProfileManagerWithoutInit(temp_dir_.path())); |
| + profile_manager_.reset(new testing::ProfileManager(temp_dir_.path())); |
| } |
| virtual void TearDown() { |
| @@ -95,6 +125,7 @@ |
| content::TestBrowserThread ui_thread_; |
| content::TestBrowserThread db_thread_; |
| content::TestBrowserThread file_thread_; |
| + // IOThread is necessary for the creation of some services below. |
| IOThread io_thread_; |
| scoped_ptr<base::SystemMonitor> system_monitor_dummy_; |
| @@ -162,15 +193,16 @@ |
| FilePath dest_path2 = temp_dir_.path(); |
| dest_path2 = dest_path2.Append(FILE_PATH_LITERAL("New Profile 2")); |
| - Profile* profile1; |
| - Profile* profile2; |
| - |
| // Successfully create the profiles. |
| - profile1 = profile_manager_->GetProfile(dest_path1); |
| + TestingProfile* profile1 = |
| + static_cast<TestingProfile*>(profile_manager_->GetProfile(dest_path1)); |
| ASSERT_TRUE(profile1); |
| + profile1->set_enable_lazy_service_initialization(true); |
| - profile2 = profile_manager_->GetProfile(dest_path2); |
| + TestingProfile* profile2 = |
| + static_cast<TestingProfile*>(profile_manager_->GetProfile(dest_path2)); |
| ASSERT_TRUE(profile2); |
| + profile2->set_enable_lazy_service_initialization(true); |
| // Force lazy-init of some profile services to simulate use. |
| EXPECT_TRUE(profile1->GetHistoryService(Profile::EXPLICIT_ACCESS)); |