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" |
11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
15 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 15 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
17 #include "chrome/browser/chromeos/settings/cros_settings.h" | 17 #include "chrome/browser/chromeos/settings/cros_settings.h" |
18 #include "chrome/browser/extensions/event_router_forwarder.h" | 18 #include "chrome/browser/extensions/event_router_forwarder.h" |
19 #include "chrome/browser/history/history_service.h" | 19 #include "chrome/browser/history/history_service.h" |
20 #include "chrome/browser/history/history_service_factory.h" | 20 #include "chrome/browser/history/history_service_factory.h" |
21 #include "chrome/browser/io_thread.h" | 21 #include "chrome/browser/io_thread.h" |
22 #include "chrome/browser/prefs/browser_prefs.h" | 22 #include "chrome/browser/prefs/browser_prefs.h" |
| 23 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
23 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
24 #include "chrome/browser/profiles/profile_info_cache.h" | 25 #include "chrome/browser/profiles/profile_info_cache.h" |
25 #include "chrome/browser/profiles/profile_manager.h" | 26 #include "chrome/browser/profiles/profile_manager.h" |
26 #include "chrome/browser/ui/browser.h" | 27 #include "chrome/browser/ui/browser.h" |
27 #include "chrome/common/chrome_constants.h" | 28 #include "chrome/common/chrome_constants.h" |
28 #include "chrome/common/chrome_notification_types.h" | 29 #include "chrome/common/chrome_notification_types.h" |
29 #include "chrome/common/chrome_paths.h" | 30 #include "chrome/common/chrome_paths.h" |
30 #include "chrome/common/chrome_switches.h" | 31 #include "chrome/common/chrome_switches.h" |
31 #include "chrome/common/pref_names.h" | 32 #include "chrome/common/pref_names.h" |
32 #include "chrome/test/base/scoped_testing_local_state.h" | 33 #include "chrome/test/base/scoped_testing_local_state.h" |
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 | 422 |
422 size_t profile_index = cache.GetIndexOfProfileWithPath(dest_path); | 423 size_t profile_index = cache.GetIndexOfProfileWithPath(dest_path); |
423 | 424 |
424 // Check if the profile prefs are the same as the cache prefs | 425 // Check if the profile prefs are the same as the cache prefs |
425 EXPECT_EQ(profile_name, | 426 EXPECT_EQ(profile_name, |
426 UTF16ToUTF8(cache.GetNameOfProfileAtIndex(profile_index))); | 427 UTF16ToUTF8(cache.GetNameOfProfileAtIndex(profile_index))); |
427 EXPECT_EQ(avatar_index, | 428 EXPECT_EQ(avatar_index, |
428 cache.GetAvatarIconIndexOfProfileAtIndex(profile_index)); | 429 cache.GetAvatarIconIndexOfProfileAtIndex(profile_index)); |
429 } | 430 } |
430 | 431 |
| 432 TEST_F(ProfileManagerTest, GetLastUsedProfileAllowedByPolicy) { |
| 433 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 434 ASSERT_TRUE(profile_manager); |
| 435 |
| 436 Profile* profile = profile_manager->GetLastUsedProfileAllowedByPolicy(); |
| 437 ASSERT_TRUE(profile); |
| 438 EXPECT_FALSE(profile->IsOffTheRecord()); |
| 439 PrefService* prefs = profile->GetPrefs(); |
| 440 EXPECT_EQ(IncognitoModePrefs::ENABLED, |
| 441 IncognitoModePrefs::GetAvailability(prefs)); |
| 442 |
| 443 // Attach an incognito Profile to the TestingProfile. |
| 444 ASSERT_FALSE(profile->GetOffTheRecordProfile()); |
| 445 TestingProfile* incognito_profile = new TestingProfile(); |
| 446 incognito_profile->set_incognito(true); |
| 447 EXPECT_TRUE(incognito_profile->IsOffTheRecord()); |
| 448 TestingProfile* testing_profile = static_cast<TestingProfile*>(profile); |
| 449 testing_profile->SetOffTheRecordProfile(incognito_profile); |
| 450 ASSERT_TRUE(profile->GetOffTheRecordProfile()); |
| 451 |
| 452 IncognitoModePrefs::SetAvailability(prefs, IncognitoModePrefs::DISABLED); |
| 453 EXPECT_FALSE( |
| 454 profile_manager->GetLastUsedProfileAllowedByPolicy()->IsOffTheRecord()); |
| 455 |
| 456 // GetLastUsedProfileAllowedByPolicy() returns the incognito Profile when |
| 457 // incognito mode is forced. |
| 458 IncognitoModePrefs::SetAvailability(prefs, IncognitoModePrefs::FORCED); |
| 459 EXPECT_TRUE( |
| 460 profile_manager->GetLastUsedProfileAllowedByPolicy()->IsOffTheRecord()); |
| 461 } |
| 462 |
431 #if !defined(OS_ANDROID) | 463 #if !defined(OS_ANDROID) |
432 // There's no Browser object on Android. | 464 // There's no Browser object on Android. |
433 TEST_F(ProfileManagerTest, LastOpenedProfiles) { | 465 TEST_F(ProfileManagerTest, LastOpenedProfiles) { |
434 base::FilePath dest_path1 = temp_dir_.path(); | 466 base::FilePath dest_path1 = temp_dir_.path(); |
435 dest_path1 = dest_path1.Append(FILE_PATH_LITERAL("New Profile 1")); | 467 dest_path1 = dest_path1.Append(FILE_PATH_LITERAL("New Profile 1")); |
436 | 468 |
437 base::FilePath dest_path2 = temp_dir_.path(); | 469 base::FilePath dest_path2 = temp_dir_.path(); |
438 dest_path2 = dest_path2.Append(FILE_PATH_LITERAL("New Profile 2")); | 470 dest_path2 = dest_path2.Append(FILE_PATH_LITERAL("New Profile 2")); |
439 | 471 |
440 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 472 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
611 browser2b.reset(); | 643 browser2b.reset(); |
612 last_opened_profiles = profile_manager->GetLastOpenedProfiles(); | 644 last_opened_profiles = profile_manager->GetLastOpenedProfiles(); |
613 ASSERT_EQ(1U, last_opened_profiles.size()); | 645 ASSERT_EQ(1U, last_opened_profiles.size()); |
614 EXPECT_EQ(profile1, last_opened_profiles[0]); | 646 EXPECT_EQ(profile1, last_opened_profiles[0]); |
615 | 647 |
616 browser1.reset(); | 648 browser1.reset(); |
617 last_opened_profiles = profile_manager->GetLastOpenedProfiles(); | 649 last_opened_profiles = profile_manager->GetLastOpenedProfiles(); |
618 ASSERT_EQ(0U, last_opened_profiles.size()); | 650 ASSERT_EQ(0U, last_opened_profiles.size()); |
619 } | 651 } |
620 #endif // !defined(OS_ANDROID) | 652 #endif // !defined(OS_ANDROID) |
OLD | NEW |