OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/profiles/profile.h" | 5 #include "chrome/browser/profiles/profile.h" |
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/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
10 #include "base/json/json_reader.h" | |
10 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
12 #include "base/sequenced_task_runner.h" | |
11 #include "base/synchronization/waitable_event.h" | 13 #include "base/synchronization/waitable_event.h" |
14 #include "base/values.h" | |
12 #include "base/version.h" | 15 #include "base/version.h" |
16 #include "chrome/browser/browser_process.h" | |
13 #include "chrome/browser/chrome_notification_types.h" | 17 #include "chrome/browser/chrome_notification_types.h" |
14 #include "chrome/browser/profiles/chrome_version_service.h" | 18 #include "chrome/browser/profiles/chrome_version_service.h" |
15 #include "chrome/browser/profiles/profile_impl.h" | 19 #include "chrome/browser/profiles/profile_impl.h" |
20 #include "chrome/browser/profiles/profile_manager.h" | |
16 #include "chrome/browser/profiles/startup_task_runner_service.h" | 21 #include "chrome/browser/profiles/startup_task_runner_service.h" |
17 #include "chrome/browser/profiles/startup_task_runner_service_factory.h" | 22 #include "chrome/browser/profiles/startup_task_runner_service_factory.h" |
18 #include "chrome/common/chrome_constants.h" | 23 #include "chrome/common/chrome_constants.h" |
19 #include "chrome/common/chrome_version_info.h" | 24 #include "chrome/common/chrome_version_info.h" |
20 #include "chrome/common/pref_names.h" | 25 #include "chrome/common/pref_names.h" |
21 #include "chrome/test/base/in_process_browser_test.h" | 26 #include "chrome/test/base/in_process_browser_test.h" |
22 #include "chrome/test/base/ui_test_utils.h" | 27 #include "chrome/test/base/ui_test_utils.h" |
23 #include "testing/gmock/include/gmock/gmock.h" | 28 #include "testing/gmock/include/gmock/gmock.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
25 | 30 |
26 #if defined(OS_CHROMEOS) | 31 #if defined(OS_CHROMEOS) |
27 #include "chromeos/chromeos_switches.h" | 32 #include "chromeos/chromeos_switches.h" |
28 #endif | 33 #endif |
29 | 34 |
30 namespace { | 35 namespace { |
31 | 36 |
32 class MockProfileDelegate : public Profile::Delegate { | 37 class MockProfileDelegate : public Profile::Delegate { |
33 public: | 38 public: |
34 MOCK_METHOD1(OnPrefsLoaded, void(Profile*)); | 39 MOCK_METHOD1(OnPrefsLoaded, void(Profile*)); |
35 MOCK_METHOD3(OnProfileCreated, void(Profile*, bool, bool)); | 40 MOCK_METHOD3(OnProfileCreated, void(Profile*, bool, bool)); |
36 }; | 41 }; |
37 | 42 |
38 // Creates a prefs file in the given directory. | 43 // Creates a prefs file in the given directory. |
39 void CreatePrefsFileInDirectory(const base::FilePath& directory_path) { | 44 void CreatePrefsFileInDirectory(const base::FilePath& directory_path) { |
40 base::FilePath pref_path(directory_path.Append(chrome::kPreferencesFilename)); | 45 base::FilePath pref_path(directory_path.Append(chrome::kPreferencesFilename)); |
41 std::string data("{}"); | 46 std::string data("{}"); |
42 ASSERT_TRUE(base::WriteFile(pref_path, data.c_str(), data.size())); | 47 ASSERT_TRUE(base::WriteFile(pref_path, data.c_str(), data.size())); |
43 } | 48 } |
44 | 49 |
45 scoped_ptr<Profile> CreateProfile( | |
46 const base::FilePath& path, | |
47 Profile::Delegate* delegate, | |
48 Profile::CreateMode create_mode) { | |
49 scoped_ptr<Profile> profile(Profile::CreateProfile( | |
50 path, delegate, create_mode)); | |
51 EXPECT_TRUE(profile.get()); | |
52 // This is necessary to avoid a memleak from BookmarkModel::Load. | |
53 // Unfortunately, this also results in warnings during debug runs. | |
54 StartupTaskRunnerServiceFactory::GetForProfile(profile.get())-> | |
55 StartDeferredTaskRunners(); | |
56 return profile.Pass(); | |
57 } | |
58 | |
59 void CheckChromeVersion(Profile *profile, bool is_new) { | 50 void CheckChromeVersion(Profile *profile, bool is_new) { |
60 std::string created_by_version; | 51 std::string created_by_version; |
61 if (is_new) { | 52 if (is_new) { |
62 chrome::VersionInfo version_info; | 53 chrome::VersionInfo version_info; |
63 created_by_version = version_info.Version(); | 54 created_by_version = version_info.Version(); |
64 } else { | 55 } else { |
65 created_by_version = "1.0.0.0"; | 56 created_by_version = "1.0.0.0"; |
66 } | 57 } |
67 std::string pref_version = | 58 std::string pref_version = |
68 ChromeVersionService::GetVersion(profile->GetPrefs()); | 59 ChromeVersionService::GetVersion(profile->GetPrefs()); |
69 // Assert that created_by_version pref gets set to current version. | 60 // Assert that created_by_version pref gets set to current version. |
70 EXPECT_EQ(created_by_version, pref_version); | 61 EXPECT_EQ(created_by_version, pref_version); |
71 } | 62 } |
72 | 63 |
73 void BlockThread( | 64 void BlockThread( |
74 base::WaitableEvent* is_blocked, | 65 base::WaitableEvent* is_blocked, |
75 base::WaitableEvent* unblock) { | 66 base::WaitableEvent* unblock) { |
76 is_blocked->Signal(); | 67 is_blocked->Signal(); |
77 unblock->Wait(); | 68 unblock->Wait(); |
78 } | 69 } |
79 | 70 |
71 void FlushTaskRunner(base::SequencedTaskRunner* runner) { | |
72 ASSERT_TRUE(runner); | |
73 base::WaitableEvent unblock(false, false); | |
74 | |
75 runner->PostTask(FROM_HERE, | |
76 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&unblock))); | |
77 | |
78 unblock.Wait(); | |
79 } | |
80 | |
81 std::string GetExitTypePreferenceFromDisk(Profile* profile) { | |
82 base::FilePath prefs_path = | |
83 profile->GetPath().Append(chrome::kPreferencesFilename); | |
84 std::string prefs; | |
85 if (!base::ReadFileToString(prefs_path, &prefs)) | |
86 return ""; | |
gab
2014/07/04 15:22:18
s/""/std::string()/
I forget when I was told this
gab
2014/07/04 23:39:27
Ping
Sigurður Ásgeirsson
2014/07/05 20:03:01
Done.
| |
87 | |
88 scoped_ptr<base::Value> value(base::JSONReader::Read(prefs)); | |
89 if (!value) | |
90 return ""; | |
91 | |
92 base::DictionaryValue* dict; | |
gab
2014/07/04 15:22:17
Initialize to NULL (otherwise |!dict| can be readi
gab
2014/07/04 23:39:27
Ping
Sigurður Ásgeirsson
2014/07/05 20:03:01
Done.
| |
93 if (!value->GetAsDictionary(&dict) || !dict) | |
94 return ""; | |
95 | |
96 std::string exit_type; | |
97 if (!dict->GetString("profile.exit_type", &exit_type)) | |
98 return ""; | |
99 | |
100 return exit_type; | |
101 } | |
102 | |
80 void SpinThreads() { | 103 void SpinThreads() { |
81 // Give threads a chance to do their stuff before shutting down (i.e. | 104 // Give threads a chance to do their stuff before shutting down (i.e. |
82 // deleting scoped temp dir etc). | 105 // deleting scoped temp dir etc). |
83 // Should not be necessary anymore once Profile deletion is fixed | 106 // Should not be necessary anymore once Profile deletion is fixed |
84 // (see crbug.com/88586). | 107 // (see crbug.com/88586). |
85 content::RunAllPendingInMessageLoop(); | 108 content::RunAllPendingInMessageLoop(); |
86 content::RunAllPendingInMessageLoop(content::BrowserThread::DB); | 109 content::RunAllPendingInMessageLoop(content::BrowserThread::DB); |
87 content::RunAllPendingInMessageLoop(content::BrowserThread::FILE); | 110 content::RunAllPendingInMessageLoop(content::BrowserThread::FILE); |
88 } | 111 } |
89 | 112 |
90 } // namespace | 113 } // namespace |
91 | 114 |
92 class ProfileBrowserTest : public InProcessBrowserTest { | 115 class ProfileBrowserTest : public InProcessBrowserTest { |
93 protected: | 116 protected: |
94 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 117 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
95 #if defined(OS_CHROMEOS) | 118 #if defined(OS_CHROMEOS) |
96 command_line->AppendSwitch( | 119 command_line->AppendSwitch( |
97 chromeos::switches::kIgnoreUserProfileMappingForTests); | 120 chromeos::switches::kIgnoreUserProfileMappingForTests); |
98 #endif | 121 #endif |
99 } | 122 } |
123 | |
124 scoped_ptr<Profile> CreateProfile( | |
125 const base::FilePath& path, | |
126 Profile::Delegate* delegate, | |
127 Profile::CreateMode create_mode) { | |
128 scoped_ptr<Profile> profile(Profile::CreateProfile( | |
129 path, delegate, create_mode)); | |
130 EXPECT_TRUE(profile.get()); | |
131 | |
132 // Store the Profile's IO task runner so we can wind it down. | |
133 profile_io_task_runner_ = profile->GetIOTaskRunner(); | |
134 | |
135 return profile.Pass(); | |
136 } | |
137 | |
138 void FlushIoTaskRunnerAndSpinThreads() { | |
139 FlushTaskRunner(profile_io_task_runner_); | |
140 SpinThreads(); | |
141 } | |
142 | |
143 scoped_refptr<base::SequencedTaskRunner> profile_io_task_runner_; | |
100 }; | 144 }; |
101 | 145 |
102 // Test OnProfileCreate is called with is_new_profile set to true when | 146 // Test OnProfileCreate is called with is_new_profile set to true when |
103 // creating a new profile synchronously. | 147 // creating a new profile synchronously. |
104 // | 148 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, CreateNewProfileSynchronous) { |
105 // Flaky (sometimes timeout): http://crbug.com/141141 | |
106 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, | |
107 DISABLED_CreateNewProfileSynchronous) { | |
108 base::ScopedTempDir temp_dir; | 149 base::ScopedTempDir temp_dir; |
109 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 150 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
110 | 151 |
111 MockProfileDelegate delegate; | 152 MockProfileDelegate delegate; |
112 EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, true)); | 153 EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, true)); |
113 | 154 |
114 { | 155 { |
115 scoped_ptr<Profile> profile(CreateProfile( | 156 scoped_ptr<Profile> profile(CreateProfile( |
116 temp_dir.path(), &delegate, Profile::CREATE_MODE_SYNCHRONOUS)); | 157 temp_dir.path(), &delegate, Profile::CREATE_MODE_SYNCHRONOUS)); |
117 CheckChromeVersion(profile.get(), true); | 158 CheckChromeVersion(profile.get(), true); |
118 } | 159 } |
119 | 160 |
120 SpinThreads(); | 161 FlushIoTaskRunnerAndSpinThreads(); |
121 } | 162 } |
122 | 163 |
123 // Test OnProfileCreate is called with is_new_profile set to false when | 164 // Test OnProfileCreate is called with is_new_profile set to false when |
124 // creating a profile synchronously with an existing prefs file. | 165 // creating a profile synchronously with an existing prefs file. |
125 // Flaky: http://crbug.com/141517 | 166 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, CreateOldProfileSynchronous) { |
126 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, | |
127 DISABLED_CreateOldProfileSynchronous) { | |
128 base::ScopedTempDir temp_dir; | 167 base::ScopedTempDir temp_dir; |
129 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 168 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
130 CreatePrefsFileInDirectory(temp_dir.path()); | 169 CreatePrefsFileInDirectory(temp_dir.path()); |
131 | 170 |
132 MockProfileDelegate delegate; | 171 MockProfileDelegate delegate; |
133 EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, false)); | 172 EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, false)); |
134 | 173 |
135 { | 174 { |
136 scoped_ptr<Profile> profile(CreateProfile( | 175 scoped_ptr<Profile> profile(CreateProfile( |
137 temp_dir.path(), &delegate, Profile::CREATE_MODE_SYNCHRONOUS)); | 176 temp_dir.path(), &delegate, Profile::CREATE_MODE_SYNCHRONOUS)); |
138 CheckChromeVersion(profile.get(), false); | 177 CheckChromeVersion(profile.get(), false); |
139 } | 178 } |
140 | 179 |
141 SpinThreads(); | 180 FlushIoTaskRunnerAndSpinThreads(); |
142 } | 181 } |
143 | 182 |
144 // Test OnProfileCreate is called with is_new_profile set to true when | 183 // Test OnProfileCreate is called with is_new_profile set to true when |
145 // creating a new profile asynchronously. | 184 // creating a new profile asynchronously. |
146 // This test is flaky on Linux, Win and Mac. See crbug.com/142787 | 185 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, CreateNewProfileAsynchronous) { |
147 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, | |
148 DISABLED_CreateNewProfileAsynchronous) { | |
149 base::ScopedTempDir temp_dir; | 186 base::ScopedTempDir temp_dir; |
150 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 187 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
151 | 188 |
152 MockProfileDelegate delegate; | 189 MockProfileDelegate delegate; |
153 EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, true)); | 190 EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, true)); |
154 | 191 |
155 { | 192 { |
156 content::WindowedNotificationObserver observer( | 193 content::WindowedNotificationObserver observer( |
157 chrome::NOTIFICATION_PROFILE_CREATED, | 194 chrome::NOTIFICATION_PROFILE_CREATED, |
158 content::NotificationService::AllSources()); | 195 content::NotificationService::AllSources()); |
159 | 196 |
160 scoped_ptr<Profile> profile(CreateProfile( | 197 scoped_ptr<Profile> profile(CreateProfile( |
161 temp_dir.path(), &delegate, Profile::CREATE_MODE_ASYNCHRONOUS)); | 198 temp_dir.path(), &delegate, Profile::CREATE_MODE_ASYNCHRONOUS)); |
162 | 199 |
163 // Wait for the profile to be created. | 200 // Wait for the profile to be created. |
164 observer.Wait(); | 201 observer.Wait(); |
165 CheckChromeVersion(profile.get(), true); | 202 CheckChromeVersion(profile.get(), true); |
166 } | 203 } |
167 | 204 |
168 SpinThreads(); | 205 FlushIoTaskRunnerAndSpinThreads(); |
169 } | 206 } |
170 | 207 |
171 // Test OnProfileCreate is called with is_new_profile set to false when | 208 // Test OnProfileCreate is called with is_new_profile set to false when |
172 // creating a profile asynchronously with an existing prefs file. | 209 // creating a profile asynchronously with an existing prefs file. |
173 // Flaky: http://crbug.com/141517 | 210 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, CreateOldProfileAsynchronous) { |
174 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, | |
175 DISABLED_CreateOldProfileAsynchronous) { | |
176 base::ScopedTempDir temp_dir; | 211 base::ScopedTempDir temp_dir; |
177 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 212 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
178 CreatePrefsFileInDirectory(temp_dir.path()); | 213 CreatePrefsFileInDirectory(temp_dir.path()); |
179 | 214 |
180 MockProfileDelegate delegate; | 215 MockProfileDelegate delegate; |
181 EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, false)); | 216 EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, false)); |
182 | 217 |
183 { | 218 { |
184 content::WindowedNotificationObserver observer( | 219 content::WindowedNotificationObserver observer( |
185 chrome::NOTIFICATION_PROFILE_CREATED, | 220 chrome::NOTIFICATION_PROFILE_CREATED, |
186 content::NotificationService::AllSources()); | 221 content::NotificationService::AllSources()); |
187 | 222 |
188 scoped_ptr<Profile> profile(CreateProfile( | 223 scoped_ptr<Profile> profile(CreateProfile( |
189 temp_dir.path(), &delegate, Profile::CREATE_MODE_ASYNCHRONOUS)); | 224 temp_dir.path(), &delegate, Profile::CREATE_MODE_ASYNCHRONOUS)); |
190 | 225 |
191 // Wait for the profile to be created. | 226 // Wait for the profile to be created. |
192 observer.Wait(); | 227 observer.Wait(); |
193 CheckChromeVersion(profile.get(), false); | 228 CheckChromeVersion(profile.get(), false); |
194 } | 229 } |
195 | 230 |
196 SpinThreads(); | 231 FlushIoTaskRunnerAndSpinThreads(); |
197 } | 232 } |
198 | 233 |
199 // Test that a README file is created for profiles that didn't have it. | 234 // Test that a README file is created for profiles that didn't have it. |
200 // Flaky: http://crbug.com/140882 | 235 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, ProfileReadmeCreated) { |
201 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, DISABLED_ProfileReadmeCreated) { | |
202 base::ScopedTempDir temp_dir; | 236 base::ScopedTempDir temp_dir; |
203 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 237 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
204 | 238 |
205 MockProfileDelegate delegate; | 239 MockProfileDelegate delegate; |
206 EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, true)); | 240 EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, true)); |
207 | 241 |
208 // No delay before README creation. | 242 // No delay before README creation. |
209 ProfileImpl::create_readme_delay_ms = 0; | 243 ProfileImpl::create_readme_delay_ms = 0; |
210 | 244 |
211 { | 245 { |
212 content::WindowedNotificationObserver observer( | 246 content::WindowedNotificationObserver observer( |
213 chrome::NOTIFICATION_PROFILE_CREATED, | 247 chrome::NOTIFICATION_PROFILE_CREATED, |
214 content::NotificationService::AllSources()); | 248 content::NotificationService::AllSources()); |
215 | 249 |
216 scoped_ptr<Profile> profile(CreateProfile( | 250 scoped_ptr<Profile> profile(CreateProfile( |
217 temp_dir.path(), &delegate, Profile::CREATE_MODE_ASYNCHRONOUS)); | 251 temp_dir.path(), &delegate, Profile::CREATE_MODE_ASYNCHRONOUS)); |
218 | 252 |
219 // Wait for the profile to be created. | 253 // Wait for the profile to be created. |
220 observer.Wait(); | 254 observer.Wait(); |
221 | 255 |
222 // Wait for file thread to create the README. | 256 // Wait for file thread to create the README. |
223 content::RunAllPendingInMessageLoop(content::BrowserThread::FILE); | 257 content::RunAllPendingInMessageLoop(content::BrowserThread::FILE); |
224 | 258 |
225 // Verify that README exists. | 259 // Verify that README exists. |
226 EXPECT_TRUE(base::PathExists( | 260 EXPECT_TRUE(base::PathExists( |
227 temp_dir.path().Append(chrome::kReadmeFilename))); | 261 temp_dir.path().Append(chrome::kReadmeFilename))); |
228 } | 262 } |
229 | 263 |
230 SpinThreads(); | 264 FlushIoTaskRunnerAndSpinThreads(); |
231 } | 265 } |
232 | 266 |
233 // Test that Profile can be deleted before README file is created. | 267 // Test that Profile can be deleted before README file is created. |
234 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, ProfileDeletedBeforeReadmeCreated) { | 268 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, ProfileDeletedBeforeReadmeCreated) { |
235 base::ScopedTempDir temp_dir; | 269 base::ScopedTempDir temp_dir; |
236 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 270 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
237 | 271 |
238 MockProfileDelegate delegate; | 272 MockProfileDelegate delegate; |
239 EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, true)); | 273 EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, true)); |
240 | 274 |
(...skipping 14 matching lines...) Expand all Loading... | |
255 temp_dir.path(), &delegate, Profile::CREATE_MODE_SYNCHRONOUS)); | 289 temp_dir.path(), &delegate, Profile::CREATE_MODE_SYNCHRONOUS)); |
256 | 290 |
257 // Delete the Profile instance before we give the file thread a chance to | 291 // Delete the Profile instance before we give the file thread a chance to |
258 // create the README. | 292 // create the README. |
259 profile.reset(); | 293 profile.reset(); |
260 | 294 |
261 // Now unblock the file thread again and run pending tasks (this includes the | 295 // Now unblock the file thread again and run pending tasks (this includes the |
262 // task for README creation). | 296 // task for README creation). |
263 unblock->Signal(); | 297 unblock->Signal(); |
264 | 298 |
265 SpinThreads(); | 299 FlushIoTaskRunnerAndSpinThreads(); |
266 } | 300 } |
267 | 301 |
268 // Test that repeated setting of exit type is handled correctly. | 302 // Test that repeated setting of exit type is handled correctly. |
269 #if defined(OS_WIN) | 303 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, ExitType) { |
270 // Flaky on Windows: http://crbug.com/163713 | |
271 #define MAYBE_ExitType DISABLED_ExitType | |
272 #else | |
273 #define MAYBE_ExitType ExitType | |
274 #endif | |
275 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, MAYBE_ExitType) { | |
276 base::ScopedTempDir temp_dir; | 304 base::ScopedTempDir temp_dir; |
277 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 305 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
278 | 306 |
279 MockProfileDelegate delegate; | 307 MockProfileDelegate delegate; |
280 EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, true)); | 308 EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, true)); |
281 { | 309 { |
282 scoped_ptr<Profile> profile(CreateProfile( | 310 scoped_ptr<Profile> profile(CreateProfile( |
283 temp_dir.path(), &delegate, Profile::CREATE_MODE_SYNCHRONOUS)); | 311 temp_dir.path(), &delegate, Profile::CREATE_MODE_SYNCHRONOUS)); |
284 | 312 |
285 PrefService* prefs = profile->GetPrefs(); | 313 PrefService* prefs = profile->GetPrefs(); |
286 // The initial state is crashed; store for later reference. | 314 // The initial state is crashed; store for later reference. |
287 std::string crash_value(prefs->GetString(prefs::kSessionExitType)); | 315 std::string crash_value(prefs->GetString(prefs::kSessionExitType)); |
288 | 316 |
289 // The first call to a type other than crashed should change the value. | 317 // The first call to a type other than crashed should change the value. |
290 profile->SetExitType(Profile::EXIT_SESSION_ENDED); | 318 profile->SetExitType(Profile::EXIT_SESSION_ENDED); |
291 std::string first_call_value(prefs->GetString(prefs::kSessionExitType)); | 319 std::string first_call_value(prefs->GetString(prefs::kSessionExitType)); |
292 EXPECT_NE(crash_value, first_call_value); | 320 EXPECT_NE(crash_value, first_call_value); |
293 | 321 |
294 // Subsequent calls to a non-crash value should be ignored. | 322 // Subsequent calls to a non-crash value should be ignored. |
295 profile->SetExitType(Profile::EXIT_NORMAL); | 323 profile->SetExitType(Profile::EXIT_NORMAL); |
296 std::string second_call_value(prefs->GetString(prefs::kSessionExitType)); | 324 std::string second_call_value(prefs->GetString(prefs::kSessionExitType)); |
297 EXPECT_EQ(first_call_value, second_call_value); | 325 EXPECT_EQ(first_call_value, second_call_value); |
298 | 326 |
299 // Setting back to a crashed value should work. | 327 // Setting back to a crashed value should work. |
300 profile->SetExitType(Profile::EXIT_CRASHED); | 328 profile->SetExitType(Profile::EXIT_CRASHED); |
301 std::string final_value(prefs->GetString(prefs::kSessionExitType)); | 329 std::string final_value(prefs->GetString(prefs::kSessionExitType)); |
302 EXPECT_EQ(crash_value, final_value); | 330 EXPECT_EQ(crash_value, final_value); |
303 } | 331 } |
304 | 332 |
305 SpinThreads(); | 333 FlushIoTaskRunnerAndSpinThreads(); |
306 } | 334 } |
335 | |
336 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, | |
337 WritesProfilesSynchronouslyOnEndSession) { | |
338 base::ScopedTempDir temp_dir; | |
339 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | |
340 | |
341 ProfileManager* profile_manager = g_browser_process->profile_manager(); | |
342 ASSERT_TRUE(profile_manager); | |
343 std::vector<Profile*> loaded_profiles = profile_manager->GetLoadedProfiles(); | |
344 | |
345 for (size_t i = 0; i < loaded_profiles.size(); ++i) { | |
noms (inactive)
2014/07/04 15:41:18
Can you add an assert or check that there's at lea
Sigurður Ásgeirsson
2014/07/05 20:03:01
Done.
| |
346 Profile* profile = loaded_profiles[i]; | |
347 | |
348 // Flush the profile data to disk for all loaded profiles. | |
349 profile->SetExitType(Profile::EXIT_CRASHED); | |
350 FlushTaskRunner(profile->GetIOTaskRunner()); | |
351 | |
352 // Make sure that the prefs file was written with the expected key/value. | |
353 ASSERT_EQ(GetExitTypePreferenceFromDisk(profile), "Crashed"); | |
354 } | |
355 | |
356 // This must not return until the profile data has been written to disk. | |
357 // If this test flakes, then logoff on Windows has broken again. | |
358 g_browser_process->EndSession(); | |
359 | |
360 // Verify that the setting was indeed written. | |
361 for (size_t i = 0; i < loaded_profiles.size(); ++i) { | |
362 Profile* profile = loaded_profiles[i]; | |
363 // Make sure that the prefs file was written with the expected key/value. | |
364 ASSERT_EQ(GetExitTypePreferenceFromDisk(profile), "SessionEnded"); | |
365 } | |
366 } | |
OLD | NEW |