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 <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/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
113 CommandLine* cl = CommandLine::ForCurrentProcess(); | 113 CommandLine* cl = CommandLine::ForCurrentProcess(); |
114 cl->AppendSwitch(switches::kTestType); | 114 cl->AppendSwitch(switches::kTestType); |
115 #endif | 115 #endif |
116 } | 116 } |
117 | 117 |
118 virtual void TearDown() { | 118 virtual void TearDown() { |
119 TestingBrowserProcess::GetGlobal()->SetProfileManager(NULL); | 119 TestingBrowserProcess::GetGlobal()->SetProfileManager(NULL); |
120 message_loop_.RunUntilIdle(); | 120 message_loop_.RunUntilIdle(); |
121 } | 121 } |
122 | 122 |
123 virtual void CreateProfileAsync(ProfileManager* manager, | |
124 const base::FilePath& path, | |
125 MockObserver* mock_observer) { | |
126 manager->CreateProfileAsync( | |
127 path, base::Bind(&MockObserver::OnProfileCreated, | |
128 base::Unretained(mock_observer)), | |
129 string16(), | |
130 string16(), | |
131 false); | |
132 } | |
133 | |
123 #if defined(OS_CHROMEOS) | 134 #if defined(OS_CHROMEOS) |
124 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; | 135 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; |
125 chromeos::ScopedTestCrosSettings test_cros_settings_; | 136 chromeos::ScopedTestCrosSettings test_cros_settings_; |
126 #endif | 137 #endif |
127 | 138 |
128 // The path to temporary directory used to contain the test operations. | 139 // The path to temporary directory used to contain the test operations. |
129 base::ScopedTempDir temp_dir_; | 140 base::ScopedTempDir temp_dir_; |
130 ScopedTestingLocalState local_state_; | 141 ScopedTestingLocalState local_state_; |
131 scoped_refptr<extensions::EventRouterForwarder> | 142 scoped_refptr<extensions::EventRouterForwarder> |
132 extension_event_router_forwarder_; | 143 extension_event_router_forwarder_; |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
240 // Tests asynchronous profile creation mechanism. | 251 // Tests asynchronous profile creation mechanism. |
241 // Crashes: http://crbug.com/89421 | 252 // Crashes: http://crbug.com/89421 |
242 TEST_F(ProfileManagerTest, DISABLED_CreateProfileAsync) { | 253 TEST_F(ProfileManagerTest, DISABLED_CreateProfileAsync) { |
243 base::FilePath dest_path = | 254 base::FilePath dest_path = |
244 temp_dir_.path().Append(FILE_PATH_LITERAL("New Profile")); | 255 temp_dir_.path().Append(FILE_PATH_LITERAL("New Profile")); |
245 | 256 |
246 MockObserver mock_observer; | 257 MockObserver mock_observer; |
247 EXPECT_CALL(mock_observer, OnProfileCreated( | 258 EXPECT_CALL(mock_observer, OnProfileCreated( |
248 testing::NotNull(), NotFail())).Times(testing::AtLeast(1)); | 259 testing::NotNull(), NotFail())).Times(testing::AtLeast(1)); |
249 | 260 |
250 g_browser_process->profile_manager()->CreateProfileAsync(dest_path, | 261 CreateProfileAsync(g_browser_process->profile_manager(), |
251 base::Bind(&MockObserver::OnProfileCreated, | 262 dest_path, |
252 base::Unretained(&mock_observer)), | 263 &mock_observer); |
253 string16(), string16(), false); | |
254 | 264 |
255 message_loop_.RunUntilIdle(); | 265 message_loop_.RunUntilIdle(); |
256 } | 266 } |
257 | 267 |
258 MATCHER(SameNotNull, "The same non-NULL value for all calls.") { | 268 MATCHER(SameNotNull, "The same non-NULL value for all calls.") { |
259 if (!g_created_profile) | 269 if (!g_created_profile) |
260 g_created_profile = arg; | 270 g_created_profile = arg; |
261 return arg != NULL && arg == g_created_profile; | 271 return arg != NULL && arg == g_created_profile; |
262 } | 272 } |
263 | 273 |
264 TEST_F(ProfileManagerTest, CreateProfileAsyncMultipleRequests) { | 274 TEST_F(ProfileManagerTest, CreateProfileAsyncMultipleRequests) { |
265 base::FilePath dest_path = | 275 base::FilePath dest_path = |
266 temp_dir_.path().Append(FILE_PATH_LITERAL("New Profile")); | 276 temp_dir_.path().Append(FILE_PATH_LITERAL("New Profile")); |
267 | 277 |
268 g_created_profile = NULL; | 278 g_created_profile = NULL; |
269 | 279 |
270 MockObserver mock_observer1; | 280 MockObserver mock_observer1; |
271 EXPECT_CALL(mock_observer1, OnProfileCreated( | 281 EXPECT_CALL(mock_observer1, OnProfileCreated( |
272 SameNotNull(), NotFail())).Times(testing::AtLeast(1)); | 282 SameNotNull(), NotFail())).Times(testing::AtLeast(1)); |
273 MockObserver mock_observer2; | 283 MockObserver mock_observer2; |
274 EXPECT_CALL(mock_observer2, OnProfileCreated( | 284 EXPECT_CALL(mock_observer2, OnProfileCreated( |
275 SameNotNull(), NotFail())).Times(testing::AtLeast(1)); | 285 SameNotNull(), NotFail())).Times(testing::AtLeast(1)); |
276 MockObserver mock_observer3; | 286 MockObserver mock_observer3; |
277 EXPECT_CALL(mock_observer3, OnProfileCreated( | 287 EXPECT_CALL(mock_observer3, OnProfileCreated( |
278 SameNotNull(), NotFail())).Times(testing::AtLeast(1)); | 288 SameNotNull(), NotFail())).Times(testing::AtLeast(1)); |
279 | 289 |
280 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 290 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
281 | 291 |
282 profile_manager->CreateProfileAsync(dest_path, | 292 CreateProfileAsync(profile_manager, dest_path, &mock_observer1); |
283 base::Bind(&MockObserver::OnProfileCreated, | 293 CreateProfileAsync(profile_manager, dest_path, &mock_observer2); |
284 base::Unretained(&mock_observer1)), | 294 CreateProfileAsync(profile_manager, dest_path, &mock_observer3); |
285 string16(), string16(), false); | |
286 profile_manager->CreateProfileAsync(dest_path, | |
287 base::Bind(&MockObserver::OnProfileCreated, | |
288 base::Unretained(&mock_observer2)), | |
289 string16(), string16(), false); | |
290 profile_manager->CreateProfileAsync(dest_path, | |
291 base::Bind(&MockObserver::OnProfileCreated, | |
292 base::Unretained(&mock_observer3)), | |
293 string16(), string16(), false); | |
294 | 295 |
295 message_loop_.RunUntilIdle(); | 296 message_loop_.RunUntilIdle(); |
296 } | 297 } |
297 | 298 |
298 TEST_F(ProfileManagerTest, CreateProfilesAsync) { | 299 TEST_F(ProfileManagerTest, CreateProfilesAsync) { |
299 base::FilePath dest_path1 = | 300 base::FilePath dest_path1 = |
300 temp_dir_.path().Append(FILE_PATH_LITERAL("New Profile 1")); | 301 temp_dir_.path().Append(FILE_PATH_LITERAL("New Profile 1")); |
301 base::FilePath dest_path2 = | 302 base::FilePath dest_path2 = |
302 temp_dir_.path().Append(FILE_PATH_LITERAL("New Profile 2")); | 303 temp_dir_.path().Append(FILE_PATH_LITERAL("New Profile 2")); |
303 | 304 |
304 MockObserver mock_observer; | 305 MockObserver mock_observer; |
305 EXPECT_CALL(mock_observer, OnProfileCreated( | 306 EXPECT_CALL(mock_observer, OnProfileCreated( |
306 testing::NotNull(), NotFail())).Times(testing::AtLeast(3)); | 307 testing::NotNull(), NotFail())).Times(testing::AtLeast(3)); |
307 | 308 |
308 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 309 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
309 | 310 |
310 profile_manager->CreateProfileAsync(dest_path1, | 311 CreateProfileAsync(profile_manager, dest_path1, &mock_observer); |
311 base::Bind(&MockObserver::OnProfileCreated, | 312 CreateProfileAsync(profile_manager, dest_path2, &mock_observer); |
312 base::Unretained(&mock_observer)), | |
313 string16(), string16(), false); | |
314 profile_manager->CreateProfileAsync(dest_path2, | |
315 base::Bind(&MockObserver::OnProfileCreated, | |
316 base::Unretained(&mock_observer)), | |
317 string16(), string16(), false); | |
318 | 313 |
319 message_loop_.RunUntilIdle(); | 314 message_loop_.RunUntilIdle(); |
320 } | 315 } |
321 | 316 |
322 TEST_F(ProfileManagerTest, AutoloadProfilesWithBackgroundApps) { | 317 TEST_F(ProfileManagerTest, AutoloadProfilesWithBackgroundApps) { |
323 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 318 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
324 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 319 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); |
325 local_state_.Get()->SetUserPref(prefs::kBackgroundModeEnabled, | 320 local_state_.Get()->SetUserPref(prefs::kBackgroundModeEnabled, |
326 Value::CreateBooleanValue(true)); | 321 Value::CreateBooleanValue(true)); |
327 | 322 |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
443 EXPECT_FALSE( | 438 EXPECT_FALSE( |
444 profile_manager->GetLastUsedProfileAllowedByPolicy()->IsOffTheRecord()); | 439 profile_manager->GetLastUsedProfileAllowedByPolicy()->IsOffTheRecord()); |
445 | 440 |
446 // GetLastUsedProfileAllowedByPolicy() returns the incognito Profile when | 441 // GetLastUsedProfileAllowedByPolicy() returns the incognito Profile when |
447 // incognito mode is forced. | 442 // incognito mode is forced. |
448 IncognitoModePrefs::SetAvailability(prefs, IncognitoModePrefs::FORCED); | 443 IncognitoModePrefs::SetAvailability(prefs, IncognitoModePrefs::FORCED); |
449 EXPECT_TRUE( | 444 EXPECT_TRUE( |
450 profile_manager->GetLastUsedProfileAllowedByPolicy()->IsOffTheRecord()); | 445 profile_manager->GetLastUsedProfileAllowedByPolicy()->IsOffTheRecord()); |
451 } | 446 } |
452 | 447 |
448 TEST_F(ProfileManagerTest, ActiveProfileDeleted) { | |
449 ProfileManager* profile_manager = g_browser_process->profile_manager(); | |
450 ASSERT_TRUE(profile_manager); | |
451 | |
452 // Create and load two profiles. | |
453 base::FilePath dest_path1 = | |
454 temp_dir_.path().Append(FILE_PATH_LITERAL("New Profile 1")); | |
455 base::FilePath dest_path2 = | |
456 temp_dir_.path().Append(FILE_PATH_LITERAL("New Profile 2")); | |
457 | |
458 MockObserver mock_observer; | |
459 EXPECT_CALL(mock_observer, OnProfileCreated( | |
460 testing::NotNull(), NotFail())).Times(testing::AtLeast(3)); | |
461 | |
462 CreateProfileAsync(profile_manager, dest_path1, &mock_observer); | |
463 CreateProfileAsync(profile_manager, dest_path2, &mock_observer); | |
464 message_loop_.RunUntilIdle(); | |
465 | |
466 EXPECT_EQ(2u, profile_manager->GetLoadedProfiles().size()); | |
467 EXPECT_EQ(2u, profile_manager->GetProfileInfoCache().GetNumberOfProfiles()); | |
468 | |
469 // Set the active profile. | |
470 PrefService* local_state = g_browser_process->local_state(); | |
471 local_state->SetString(prefs::kProfileLastUsed, | |
472 dest_path1.BaseName().MaybeAsASCII()); | |
473 | |
474 // Delete the active profile. | |
475 profile_manager->ScheduleProfileForDeletion(dest_path1, | |
476 ProfileManager::CreateCallback()); | |
477 // Spin the message loop so that all the callbacks can finish running. | |
478 message_loop_.RunUntilIdle(); | |
479 | |
480 EXPECT_EQ( | |
481 g_browser_process->profile_manager()->GetLastUsedProfile()->GetPath(), | |
482 dest_path2); | |
483 EXPECT_EQ( | |
484 g_browser_process->local_state()->GetString(prefs::kProfileLastUsed), | |
485 "New Profile 2"); | |
Alexei Svitkine (slow)
2013/06/14 22:04:58
Same comments here as for the test below.
| |
486 } | |
487 | |
488 TEST_F(ProfileManagerTest, ActiveProfileDeletedNeedsToLoadNextProfile) { | |
489 ProfileManager* profile_manager = g_browser_process->profile_manager(); | |
490 ASSERT_TRUE(profile_manager); | |
491 | |
492 // Create and load one profile, and just create a second profile. | |
493 base::FilePath dest_path1 = | |
494 temp_dir_.path().Append(FILE_PATH_LITERAL("New Profile 1")); | |
495 base::FilePath dest_path2 = | |
496 temp_dir_.path().Append(FILE_PATH_LITERAL("New Profile 2")); | |
497 | |
498 MockObserver mock_observer; | |
499 EXPECT_CALL(mock_observer, OnProfileCreated( | |
500 testing::NotNull(), NotFail())).Times(testing::AtLeast(2)); | |
501 CreateProfileAsync(profile_manager, dest_path1, &mock_observer); | |
502 message_loop_.RunUntilIdle(); | |
503 | |
504 // Track the profile, but don't load it. | |
505 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | |
506 cache.AddProfileToCache(dest_path2, ASCIIToUTF16("New Profile 2"), | |
507 string16(), 0, false); | |
508 | |
509 message_loop_.RunUntilIdle(); | |
510 | |
511 EXPECT_EQ(1u, profile_manager->GetLoadedProfiles().size()); | |
512 EXPECT_EQ(2u, cache.GetNumberOfProfiles()); | |
513 | |
514 // Set the active profile. | |
515 PrefService* local_state = g_browser_process->local_state(); | |
516 local_state->SetString(prefs::kProfileLastUsed, | |
517 dest_path1.BaseName().MaybeAsASCII()); | |
518 | |
519 // Delete the active profile. This should switch and load the unloaded | |
520 // profile. | |
521 profile_manager->ScheduleProfileForDeletion(dest_path1, | |
522 ProfileManager::CreateCallback()); | |
523 | |
524 // Spin the message loop so that all the callbacks can finish running. | |
525 message_loop_.RunUntilIdle(); | |
526 | |
527 EXPECT_EQ( | |
528 g_browser_process->profile_manager()->GetLastUsedProfile()->GetPath(), | |
Alexei Svitkine (slow)
2013/06/14 22:04:58
Nit: you already have a local pointer to profile_m
noms (inactive)
2013/06/18 21:38:11
Done.
| |
529 dest_path2); | |
530 EXPECT_EQ( | |
531 g_browser_process->local_state()->GetString(prefs::kProfileLastUsed), | |
Alexei Svitkine (slow)
2013/06/14 22:04:58
Ditto for local_state
noms (inactive)
2013/06/18 21:38:11
Done.
| |
532 "New Profile 2"); | |
Alexei Svitkine (slow)
2013/06/14 22:04:58
Usually, we put the expected value as the first pa
noms (inactive)
2013/06/18 21:38:11
Done.
| |
533 } | |
534 | |
453 #if !defined(OS_ANDROID) | 535 #if !defined(OS_ANDROID) |
454 // There's no Browser object on Android. | 536 // There's no Browser object on Android. |
455 TEST_F(ProfileManagerTest, LastOpenedProfiles) { | 537 TEST_F(ProfileManagerTest, LastOpenedProfiles) { |
456 base::FilePath dest_path1 = temp_dir_.path(); | 538 base::FilePath dest_path1 = temp_dir_.path(); |
457 dest_path1 = dest_path1.Append(FILE_PATH_LITERAL("New Profile 1")); | 539 dest_path1 = dest_path1.Append(FILE_PATH_LITERAL("New Profile 1")); |
458 | 540 |
459 base::FilePath dest_path2 = temp_dir_.path(); | 541 base::FilePath dest_path2 = temp_dir_.path(); |
460 dest_path2 = dest_path2.Append(FILE_PATH_LITERAL("New Profile 2")); | 542 dest_path2 = dest_path2.Append(FILE_PATH_LITERAL("New Profile 2")); |
461 | 543 |
462 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 544 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
633 browser2b.reset(); | 715 browser2b.reset(); |
634 last_opened_profiles = profile_manager->GetLastOpenedProfiles(); | 716 last_opened_profiles = profile_manager->GetLastOpenedProfiles(); |
635 ASSERT_EQ(1U, last_opened_profiles.size()); | 717 ASSERT_EQ(1U, last_opened_profiles.size()); |
636 EXPECT_EQ(profile1, last_opened_profiles[0]); | 718 EXPECT_EQ(profile1, last_opened_profiles[0]); |
637 | 719 |
638 browser1.reset(); | 720 browser1.reset(); |
639 last_opened_profiles = profile_manager->GetLastOpenedProfiles(); | 721 last_opened_profiles = profile_manager->GetLastOpenedProfiles(); |
640 ASSERT_EQ(0U, last_opened_profiles.size()); | 722 ASSERT_EQ(0U, last_opened_profiles.size()); |
641 } | 723 } |
642 #endif // !defined(OS_ANDROID) | 724 #endif // !defined(OS_ANDROID) |
OLD | NEW |