Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4366)

Unified Diff: chrome/browser/profiles/profile_manager_unittest.cc

Issue 8565032: Fixing ProfileManagerTest to use the TestingProfile instead of a real profile. This will allow ea... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/profiles/profile_manager_unittest.cc
===================================================================
--- chrome/browser/profiles/profile_manager_unittest.cc (revision 111186)
+++ 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"
@@ -26,6 +27,7 @@
#include "chrome/common/pref_names.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_pref_service.h"
+#include "chrome/test/base/testing_profile.h"
#include "content/public/browser/notification_service.h"
#include "content/test/test_browser_thread.h"
#include "testing/gmock/include/gmock/gmock.h"
@@ -44,6 +46,35 @@
} // namespace
+namespace testing {
+
+class ProfileManager : public ::ProfileManagerWithoutInit {
+ public:
+ explicit ProfileManager(const FilePath& user_data_dir)
+ : ::ProfileManagerWithoutInit(user_data_dir) {}
+
+ protected:
+ virtual Profile* CreateProfileHelper(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* CreateProfileAsyncHelper(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);
+ }
+};
+
+} // namespace testing
+
class ProfileManagerTest : public testing::Test {
protected:
ProfileManagerTest()
@@ -65,7 +96,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()));
#if defined(OS_WIN)
// Force the ProfileInfoCache to be created immediately, so we can
// remove the shortcut manager for testing.
@@ -101,6 +132,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_;
@@ -168,20 +200,23 @@
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);
- profile2 = profile_manager_->GetProfile(dest_path2);
+ TestingProfile* profile2 =
+ static_cast<TestingProfile*>(profile_manager_->GetProfile(dest_path2));
ASSERT_TRUE(profile2);
// Force lazy-init of some profile services to simulate use.
+ profile1->CreateHistoryService(true, false);
EXPECT_TRUE(profile1->GetHistoryService(Profile::EXPLICIT_ACCESS));
+ profile1->CreateBookmarkModel(true);
EXPECT_TRUE(profile1->GetBookmarkModel());
+ profile2->CreateBookmarkModel(true);
EXPECT_TRUE(profile2->GetBookmarkModel());
+ profile2->CreateHistoryService(true, false);
EXPECT_TRUE(profile2->GetHistoryService(Profile::EXPLICIT_ACCESS));
// Make sure any pending tasks run before we destroy the profiles.

Powered by Google App Engine
This is Rietveld 408576698