| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/profiles/profile_manager.h" | 12 #include "chrome/browser/profiles/profile_manager.h" |
| 13 #include "chrome/common/chrome_constants.h" | 13 #include "chrome/common/chrome_constants.h" |
| 14 #include "chrome/common/chrome_paths.h" | 14 #include "chrome/common/chrome_paths.h" |
| 15 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
| 16 #include "chrome/common/notification_service.h" | 16 #include "chrome/common/notification_service.h" |
| 17 #include "content/browser/browser_thread.h" | 17 #include "content/browser/browser_thread.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 19 #include "ui/base/system_monitor/system_monitor.h" | 19 #include "ui/base/system_monitor/system_monitor.h" |
| 20 | 20 |
| 21 class ProfileManagerTest : public testing::Test { | 21 class ProfileManagerTest : public testing::Test { |
| 22 protected: | 22 protected: |
| 23 ProfileManagerTest() : ui_thread_(BrowserThread::UI, &message_loop_) { | 23 ProfileManagerTest() |
| 24 : ui_thread_(BrowserThread::UI, &message_loop_), |
| 25 file_thread_(BrowserThread::FILE, &message_loop_) { |
| 24 } | 26 } |
| 25 | 27 |
| 26 virtual void SetUp() { | 28 virtual void SetUp() { |
| 27 // Name a subdirectory of the temp directory. | 29 // Name a subdirectory of the temp directory. |
| 28 ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &test_dir_)); | 30 ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &test_dir_)); |
| 29 test_dir_ = test_dir_.Append(FILE_PATH_LITERAL("ProfileManagerTest")); | 31 test_dir_ = test_dir_.Append(FILE_PATH_LITERAL("ProfileManagerTest")); |
| 30 | 32 |
| 31 // Create a fresh, empty copy of this directory. | 33 // Create a fresh, empty copy of this directory. |
| 32 file_util::Delete(test_dir_, true); | 34 file_util::Delete(test_dir_, true); |
| 33 file_util::CreateDirectory(test_dir_); | 35 file_util::CreateDirectory(test_dir_); |
| 34 } | 36 } |
| 35 virtual void TearDown() { | 37 virtual void TearDown() { |
| 36 // Clean up test directory | 38 // Clean up test directory |
| 37 ASSERT_TRUE(file_util::Delete(test_dir_, true)); | 39 ASSERT_TRUE(file_util::Delete(test_dir_, true)); |
| 38 ASSERT_FALSE(file_util::PathExists(test_dir_)); | 40 ASSERT_FALSE(file_util::PathExists(test_dir_)); |
| 39 } | 41 } |
| 40 | 42 |
| 41 MessageLoopForUI message_loop_; | 43 MessageLoopForUI message_loop_; |
| 42 BrowserThread ui_thread_; | 44 BrowserThread ui_thread_; |
| 45 BrowserThread file_thread_; |
| 43 | 46 |
| 44 // the path to temporary directory used to contain the test operations | 47 // the path to temporary directory used to contain the test operations |
| 45 FilePath test_dir_; | 48 FilePath test_dir_; |
| 46 }; | 49 }; |
| 47 | 50 |
| 48 TEST_F(ProfileManagerTest, CreateProfile) { | 51 TEST_F(ProfileManagerTest, CreateProfile) { |
| 49 FilePath source_path; | 52 FilePath source_path; |
| 50 PathService::Get(chrome::DIR_TEST_DATA, &source_path); | 53 PathService::Get(chrome::DIR_TEST_DATA, &source_path); |
| 51 source_path = source_path.Append(FILE_PATH_LITERAL("profiles")); | 54 source_path = source_path.Append(FILE_PATH_LITERAL("profiles")); |
| 52 source_path = source_path.Append(FILE_PATH_LITERAL("sample")); | 55 source_path = source_path.Append(FILE_PATH_LITERAL("sample")); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 ASSERT_TRUE(profile1.get()); | 136 ASSERT_TRUE(profile1.get()); |
| 134 | 137 |
| 135 profile2.reset(ProfileManager::CreateProfile(dest_path2)); | 138 profile2.reset(ProfileManager::CreateProfile(dest_path2)); |
| 136 ASSERT_TRUE(profile2.get()); | 139 ASSERT_TRUE(profile2.get()); |
| 137 | 140 |
| 138 // Force lazy-init of some profile services to simulate use. | 141 // Force lazy-init of some profile services to simulate use. |
| 139 EXPECT_TRUE(profile1->GetHistoryService(Profile::EXPLICIT_ACCESS)); | 142 EXPECT_TRUE(profile1->GetHistoryService(Profile::EXPLICIT_ACCESS)); |
| 140 EXPECT_TRUE(profile1->GetBookmarkModel()); | 143 EXPECT_TRUE(profile1->GetBookmarkModel()); |
| 141 EXPECT_TRUE(profile2->GetBookmarkModel()); | 144 EXPECT_TRUE(profile2->GetBookmarkModel()); |
| 142 EXPECT_TRUE(profile2->GetHistoryService(Profile::EXPLICIT_ACCESS)); | 145 EXPECT_TRUE(profile2->GetHistoryService(Profile::EXPLICIT_ACCESS)); |
| 146 |
| 147 // Make sure any pending tasks run before we destroy the profiles. |
| 148 message_loop_.RunAllPending(); |
| 149 |
| 143 profile1.reset(); | 150 profile1.reset(); |
| 144 profile2.reset(); | 151 profile2.reset(); |
| 152 |
| 145 // Make sure history cleans up correctly. | 153 // Make sure history cleans up correctly. |
| 146 message_loop_.RunAllPending(); | 154 message_loop_.RunAllPending(); |
| 147 } | 155 } |
| OLD | NEW |