OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/memory/scoped_temp_dir.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/prefs/browser_prefs.h" | 11 #include "chrome/browser/prefs/browser_prefs.h" |
12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/browser/profiles/profile_manager.h" | 13 #include "chrome/browser/profiles/profile_manager.h" |
14 #include "chrome/common/chrome_constants.h" | 14 #include "chrome/common/chrome_constants.h" |
15 #include "chrome/common/chrome_paths.h" | 15 #include "chrome/common/chrome_paths.h" |
16 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
17 #include "chrome/test/testing_browser_process.h" | 17 #include "chrome/test/testing_browser_process.h" |
18 #include "chrome/test/testing_pref_service.h" | 18 #include "chrome/test/testing_pref_service.h" |
19 #include "content/browser/browser_thread.h" | 19 #include "content/browser/browser_thread.h" |
20 #include "content/common/notification_service.h" | 20 #include "content/common/notification_service.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
22 #include "ui/base/system_monitor/system_monitor.h" | 22 #include "ui/base/system_monitor/system_monitor.h" |
23 | 23 |
24 class ProfileManagerTest : public testing::Test { | 24 class ProfileManagerTest : public testing::Test { |
25 protected: | 25 protected: |
26 ProfileManagerTest() | 26 ProfileManagerTest() |
27 : ui_thread_(BrowserThread::UI, &message_loop_), | 27 : ui_thread_(BrowserThread::UI, &message_loop_), |
28 file_thread_(BrowserThread::FILE, &message_loop_) { | 28 file_thread_(BrowserThread::FILE, &message_loop_) { |
29 } | 29 } |
30 | 30 |
31 virtual void SetUp() { | 31 virtual void SetUp() { |
32 // Name a subdirectory of the temp directory. | 32 // Create a new temporary directory, and store the path |
33 ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &test_dir_)); | 33 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
34 test_dir_ = test_dir_.Append(FILE_PATH_LITERAL("ProfileManagerTest")); | |
35 | |
36 // Create a fresh, empty copy of this directory. | |
37 file_util::Delete(test_dir_, true); | |
38 file_util::CreateDirectory(test_dir_); | |
39 | 34 |
40 // Create a local_state PrefService. | 35 // Create a local_state PrefService. |
41 browser::RegisterLocalState(&test_local_state_); | 36 browser::RegisterLocalState(&test_local_state_); |
42 TestingBrowserProcess* testing_browser_process = | 37 TestingBrowserProcess* testing_browser_process = |
43 static_cast<TestingBrowserProcess*>(g_browser_process); | 38 static_cast<TestingBrowserProcess*>(g_browser_process); |
44 testing_browser_process->SetPrefService(&test_local_state_); | 39 testing_browser_process->SetPrefService(&test_local_state_); |
45 } | 40 } |
46 | 41 |
47 virtual void TearDown() { | 42 virtual void TearDown() { |
48 // Clean up test directory | 43 // Clean up test directory |
49 ASSERT_TRUE(file_util::Delete(test_dir_, true)); | 44 ASSERT_TRUE(temp_dir_.Delete()); |
Paweł Hajdan Jr.
2011/04/08 15:58:17
Shouldn't be needed.
Mike West
2011/04/11 14:47:04
Done.
| |
50 ASSERT_FALSE(file_util::PathExists(test_dir_)); | |
51 | 45 |
52 TestingBrowserProcess* testing_browser_process = | 46 TestingBrowserProcess* testing_browser_process = |
53 static_cast<TestingBrowserProcess*>(g_browser_process); | 47 static_cast<TestingBrowserProcess*>(g_browser_process); |
54 testing_browser_process->SetPrefService(NULL); | 48 testing_browser_process->SetPrefService(NULL); |
55 } | 49 } |
56 | 50 |
51 // the path to temporary directory used to contain the test operations | |
Paweł Hajdan Jr.
2011/04/08 15:58:17
nit: Start with a capital letter, end with a dot.
Mike West
2011/04/11 14:47:04
Done.
| |
52 ScopedTempDir temp_dir_; | |
53 | |
57 MessageLoopForUI message_loop_; | 54 MessageLoopForUI message_loop_; |
58 BrowserThread ui_thread_; | 55 BrowserThread ui_thread_; |
59 BrowserThread file_thread_; | 56 BrowserThread file_thread_; |
60 | 57 |
61 // the path to temporary directory used to contain the test operations | |
62 FilePath test_dir_; | |
63 | |
64 TestingPrefService test_local_state_; | 58 TestingPrefService test_local_state_; |
65 }; | 59 }; |
66 | 60 |
67 TEST_F(ProfileManagerTest, CreateProfile) { | 61 TEST_F(ProfileManagerTest, CreateProfile) { |
68 FilePath source_path; | 62 FilePath source_path; |
69 PathService::Get(chrome::DIR_TEST_DATA, &source_path); | 63 PathService::Get(chrome::DIR_TEST_DATA, &source_path); |
70 source_path = source_path.Append(FILE_PATH_LITERAL("profiles")); | 64 source_path = source_path.Append(FILE_PATH_LITERAL("profiles")); |
71 source_path = source_path.Append(FILE_PATH_LITERAL("sample")); | 65 source_path = source_path.Append(FILE_PATH_LITERAL("sample")); |
72 | 66 |
73 FilePath dest_path = test_dir_; | 67 FilePath dest_path = temp_dir_.path(); |
74 dest_path = dest_path.Append(FILE_PATH_LITERAL("New Profile")); | 68 dest_path = dest_path.Append(FILE_PATH_LITERAL("New Profile")); |
75 | 69 |
76 scoped_ptr<Profile> profile; | 70 scoped_ptr<Profile> profile; |
77 | 71 |
78 // Successfully create a profile. | 72 // Successfully create a profile. |
79 profile.reset(ProfileManager::CreateProfile(dest_path)); | 73 profile.reset(ProfileManager::CreateProfile(dest_path)); |
80 ASSERT_TRUE(profile.get()); | 74 ASSERT_TRUE(profile.get()); |
81 | 75 |
82 profile.reset(); | 76 profile.reset(); |
83 | 77 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
120 FilePath().AppendASCII(chrome::kNotSignedInProfile); | 114 FilePath().AppendASCII(chrome::kNotSignedInProfile); |
121 EXPECT_EQ(expected_default.value(), | 115 EXPECT_EQ(expected_default.value(), |
122 profile_manager.GetCurrentProfileDir().value()); | 116 profile_manager.GetCurrentProfileDir().value()); |
123 | 117 |
124 profile_manager.Observe(NotificationType::LOGIN_USER_CHANGED, | 118 profile_manager.Observe(NotificationType::LOGIN_USER_CHANGED, |
125 NotificationService::AllSources(), | 119 NotificationService::AllSources(), |
126 NotificationService::NoDetails()); | 120 NotificationService::NoDetails()); |
127 FilePath expected_logged_in(profile_dir); | 121 FilePath expected_logged_in(profile_dir); |
128 EXPECT_EQ(expected_logged_in.value(), | 122 EXPECT_EQ(expected_logged_in.value(), |
129 profile_manager.GetCurrentProfileDir().value()); | 123 profile_manager.GetCurrentProfileDir().value()); |
130 VLOG(1) << test_dir_.Append(profile_manager.GetCurrentProfileDir()).value(); | 124 VLOG(1) << temp_dir_.path().Append( |
125 profile_manager.GetCurrentProfileDir()).value(); | |
131 } | 126 } |
132 | 127 |
133 #endif | 128 #endif |
134 | 129 |
135 TEST_F(ProfileManagerTest, CreateAndUseTwoProfiles) { | 130 TEST_F(ProfileManagerTest, CreateAndUseTwoProfiles) { |
136 FilePath source_path; | 131 FilePath source_path; |
137 PathService::Get(chrome::DIR_TEST_DATA, &source_path); | 132 PathService::Get(chrome::DIR_TEST_DATA, &source_path); |
138 source_path = source_path.Append(FILE_PATH_LITERAL("profiles")); | 133 source_path = source_path.Append(FILE_PATH_LITERAL("profiles")); |
139 source_path = source_path.Append(FILE_PATH_LITERAL("sample")); | 134 source_path = source_path.Append(FILE_PATH_LITERAL("sample")); |
140 | 135 |
141 FilePath dest_path1 = test_dir_; | 136 FilePath dest_path1 = temp_dir_.path(); |
142 dest_path1 = dest_path1.Append(FILE_PATH_LITERAL("New Profile 1")); | 137 dest_path1 = dest_path1.Append(FILE_PATH_LITERAL("New Profile 1")); |
143 | 138 |
144 FilePath dest_path2 = test_dir_; | 139 FilePath dest_path2 = temp_dir_.path(); |
145 dest_path2 = dest_path2.Append(FILE_PATH_LITERAL("New Profile 2")); | 140 dest_path2 = dest_path2.Append(FILE_PATH_LITERAL("New Profile 2")); |
146 | 141 |
147 scoped_ptr<Profile> profile1; | 142 scoped_ptr<Profile> profile1; |
148 scoped_ptr<Profile> profile2; | 143 scoped_ptr<Profile> profile2; |
149 | 144 |
150 // Successfully create the profiles. | 145 // Successfully create the profiles. |
151 profile1.reset(ProfileManager::CreateProfile(dest_path1)); | 146 profile1.reset(ProfileManager::CreateProfile(dest_path1)); |
152 ASSERT_TRUE(profile1.get()); | 147 ASSERT_TRUE(profile1.get()); |
153 | 148 |
154 profile2.reset(ProfileManager::CreateProfile(dest_path2)); | 149 profile2.reset(ProfileManager::CreateProfile(dest_path2)); |
155 ASSERT_TRUE(profile2.get()); | 150 ASSERT_TRUE(profile2.get()); |
156 | 151 |
157 // Force lazy-init of some profile services to simulate use. | 152 // Force lazy-init of some profile services to simulate use. |
158 EXPECT_TRUE(profile1->GetHistoryService(Profile::EXPLICIT_ACCESS)); | 153 EXPECT_TRUE(profile1->GetHistoryService(Profile::EXPLICIT_ACCESS)); |
159 EXPECT_TRUE(profile1->GetBookmarkModel()); | 154 EXPECT_TRUE(profile1->GetBookmarkModel()); |
160 EXPECT_TRUE(profile2->GetBookmarkModel()); | 155 EXPECT_TRUE(profile2->GetBookmarkModel()); |
161 EXPECT_TRUE(profile2->GetHistoryService(Profile::EXPLICIT_ACCESS)); | 156 EXPECT_TRUE(profile2->GetHistoryService(Profile::EXPLICIT_ACCESS)); |
162 | 157 |
163 // Make sure any pending tasks run before we destroy the profiles. | 158 // Make sure any pending tasks run before we destroy the profiles. |
164 message_loop_.RunAllPending(); | 159 message_loop_.RunAllPending(); |
165 | 160 |
166 profile1.reset(); | 161 profile1.reset(); |
167 profile2.reset(); | 162 profile2.reset(); |
168 | 163 |
169 // Make sure history cleans up correctly. | 164 // Make sure history cleans up correctly. |
170 message_loop_.RunAllPending(); | 165 message_loop_.RunAllPending(); |
171 } | 166 } |
OLD | NEW |