| 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/path_service.h" | 10 #include "base/path_service.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 #include "chrome/browser/profiles/profiles_state.h" | 28 #include "chrome/browser/profiles/profiles_state.h" |
| 29 #include "chrome/browser/ui/browser.h" | 29 #include "chrome/browser/ui/browser.h" |
| 30 #include "chrome/common/chrome_constants.h" | 30 #include "chrome/common/chrome_constants.h" |
| 31 #include "chrome/common/chrome_paths.h" | 31 #include "chrome/common/chrome_paths.h" |
| 32 #include "chrome/common/chrome_switches.h" | 32 #include "chrome/common/chrome_switches.h" |
| 33 #include "chrome/common/pref_names.h" | 33 #include "chrome/common/pref_names.h" |
| 34 #include "chrome/test/base/scoped_testing_local_state.h" | 34 #include "chrome/test/base/scoped_testing_local_state.h" |
| 35 #include "chrome/test/base/test_browser_window.h" | 35 #include "chrome/test/base/test_browser_window.h" |
| 36 #include "chrome/test/base/testing_browser_process.h" | 36 #include "chrome/test/base/testing_browser_process.h" |
| 37 #include "chrome/test/base/testing_profile.h" | 37 #include "chrome/test/base/testing_profile.h" |
| 38 #include "components/signin/core/common/profile_management_switches.h" | |
| 39 #include "content/public/browser/notification_service.h" | 38 #include "content/public/browser/notification_service.h" |
| 40 #include "content/public/common/content_switches.h" | 39 #include "content/public/common/content_switches.h" |
| 41 #include "content/public/test/test_browser_thread_bundle.h" | 40 #include "content/public/test/test_browser_thread_bundle.h" |
| 42 #include "grit/generated_resources.h" | 41 #include "grit/generated_resources.h" |
| 43 #include "testing/gmock/include/gmock/gmock.h" | 42 #include "testing/gmock/include/gmock/gmock.h" |
| 44 #include "testing/gtest/include/gtest/gtest.h" | 43 #include "testing/gtest/include/gtest/gtest.h" |
| 45 #include "ui/base/l10n/l10n_util.h" | 44 #include "ui/base/l10n/l10n_util.h" |
| 46 | 45 |
| 47 #if defined(OS_CHROMEOS) | 46 #if defined(OS_CHROMEOS) |
| 48 #include "chrome/browser/chromeos/login/users/mock_user_manager.h" | 47 #include "chrome/browser/chromeos/login/users/mock_user_manager.h" |
| (...skipping 835 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 884 | 883 |
| 885 EXPECT_EQ(dest_path2, profile_manager->GetLastUsedProfile()->GetPath()); | 884 EXPECT_EQ(dest_path2, profile_manager->GetLastUsedProfile()->GetPath()); |
| 886 EXPECT_EQ(profile_name2, local_state->GetString(prefs::kProfileLastUsed)); | 885 EXPECT_EQ(profile_name2, local_state->GetString(prefs::kProfileLastUsed)); |
| 887 } | 886 } |
| 888 | 887 |
| 889 TEST_F(ProfileManagerTest, ProfileDisplayNameResetsDefaultName) { | 888 TEST_F(ProfileManagerTest, ProfileDisplayNameResetsDefaultName) { |
| 890 if (!profiles::IsMultipleProfilesEnabled()) | 889 if (!profiles::IsMultipleProfilesEnabled()) |
| 891 return; | 890 return; |
| 892 | 891 |
| 893 // The command line is reset at the end of every test by the test suite. | 892 // The command line is reset at the end of every test by the test suite. |
| 894 switches::EnableNewProfileManagementForTesting( | 893 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 895 CommandLine::ForCurrentProcess()); | 894 switches::kNewProfileManagement); |
| 896 | 895 |
| 897 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 896 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 898 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 897 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); |
| 899 EXPECT_EQ(0u, cache.GetNumberOfProfiles()); | 898 EXPECT_EQ(0u, cache.GetNumberOfProfiles()); |
| 900 | 899 |
| 901 // Only one local profile means we display IDS_SINGLE_PROFILE_DISPLAY_NAME. | 900 // Only one local profile means we display IDS_SINGLE_PROFILE_DISPLAY_NAME. |
| 902 const base::string16 default_profile_name = | 901 const base::string16 default_profile_name = |
| 903 l10n_util::GetStringUTF16(IDS_SINGLE_PROFILE_DISPLAY_NAME); | 902 l10n_util::GetStringUTF16(IDS_SINGLE_PROFILE_DISPLAY_NAME); |
| 904 const base::string16 profile_name1 = cache.ChooseNameForNewProfile(0); | 903 const base::string16 profile_name1 = cache.ChooseNameForNewProfile(0); |
| 905 Profile* profile1 = AddProfileToCache(profile_manager, | 904 Profile* profile1 = AddProfileToCache(profile_manager, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 919 // Spin the message loop so that all the callbacks can finish running. | 918 // Spin the message loop so that all the callbacks can finish running. |
| 920 base::RunLoop().RunUntilIdle(); | 919 base::RunLoop().RunUntilIdle(); |
| 921 EXPECT_EQ(default_profile_name, profiles::GetAvatarNameForProfile(profile1)); | 920 EXPECT_EQ(default_profile_name, profiles::GetAvatarNameForProfile(profile1)); |
| 922 } | 921 } |
| 923 | 922 |
| 924 TEST_F(ProfileManagerTest, ProfileDisplayNamePreservesCustomName) { | 923 TEST_F(ProfileManagerTest, ProfileDisplayNamePreservesCustomName) { |
| 925 if (!profiles::IsMultipleProfilesEnabled()) | 924 if (!profiles::IsMultipleProfilesEnabled()) |
| 926 return; | 925 return; |
| 927 | 926 |
| 928 // The command line is reset at the end of every test by the test suite. | 927 // The command line is reset at the end of every test by the test suite. |
| 929 switches::EnableNewProfileManagementForTesting( | 928 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 930 CommandLine::ForCurrentProcess()); | 929 switches::kNewProfileManagement); |
| 931 | 930 |
| 932 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 931 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 933 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 932 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); |
| 934 EXPECT_EQ(0u, cache.GetNumberOfProfiles()); | 933 EXPECT_EQ(0u, cache.GetNumberOfProfiles()); |
| 935 | 934 |
| 936 // Only one local profile means we display IDS_SINGLE_PROFILE_DISPLAY_NAME. | 935 // Only one local profile means we display IDS_SINGLE_PROFILE_DISPLAY_NAME. |
| 937 const base::string16 default_profile_name = | 936 const base::string16 default_profile_name = |
| 938 l10n_util::GetStringUTF16(IDS_SINGLE_PROFILE_DISPLAY_NAME); | 937 l10n_util::GetStringUTF16(IDS_SINGLE_PROFILE_DISPLAY_NAME); |
| 939 const base::string16 profile_name1 = cache.ChooseNameForNewProfile(0); | 938 const base::string16 profile_name1 = cache.ChooseNameForNewProfile(0); |
| 940 Profile* profile1 = AddProfileToCache(profile_manager, | 939 Profile* profile1 = AddProfileToCache(profile_manager, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 959 ProfileManager::CreateCallback()); | 958 ProfileManager::CreateCallback()); |
| 960 // Spin the message loop so that all the callbacks can finish running. | 959 // Spin the message loop so that all the callbacks can finish running. |
| 961 base::RunLoop().RunUntilIdle(); | 960 base::RunLoop().RunUntilIdle(); |
| 962 EXPECT_EQ(custom_profile_name, profiles::GetAvatarNameForProfile(profile1)); | 961 EXPECT_EQ(custom_profile_name, profiles::GetAvatarNameForProfile(profile1)); |
| 963 } | 962 } |
| 964 | 963 |
| 965 TEST_F(ProfileManagerTest, ProfileDisplayNamePreservesSignedInName) { | 964 TEST_F(ProfileManagerTest, ProfileDisplayNamePreservesSignedInName) { |
| 966 if (!profiles::IsMultipleProfilesEnabled()) | 965 if (!profiles::IsMultipleProfilesEnabled()) |
| 967 return; | 966 return; |
| 968 | 967 |
| 969 // The command line is reset at the end of every test by the test suite. | 968 // The command line is reset at the end of every test by the test suite. |
| 970 switches::EnableNewProfileManagementForTesting( | 969 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 971 CommandLine::ForCurrentProcess()); | 970 switches::kNewProfileManagement); |
| 972 | 971 |
| 973 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 972 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 974 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 973 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); |
| 975 EXPECT_EQ(0u, cache.GetNumberOfProfiles()); | 974 EXPECT_EQ(0u, cache.GetNumberOfProfiles()); |
| 976 | 975 |
| 977 // Only one local profile means we display IDS_SINGLE_PROFILE_DISPLAY_NAME. | 976 // Only one local profile means we display IDS_SINGLE_PROFILE_DISPLAY_NAME. |
| 978 const base::string16 default_profile_name = | 977 const base::string16 default_profile_name = |
| 979 l10n_util::GetStringUTF16(IDS_SINGLE_PROFILE_DISPLAY_NAME); | 978 l10n_util::GetStringUTF16(IDS_SINGLE_PROFILE_DISPLAY_NAME); |
| 980 const base::string16 profile_name1 = cache.ChooseNameForNewProfile(0); | 979 const base::string16 profile_name1 = cache.ChooseNameForNewProfile(0); |
| 981 Profile* profile1 = AddProfileToCache(profile_manager, | 980 Profile* profile1 = AddProfileToCache(profile_manager, |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1102 dest_path2.BaseName().MaybeAsASCII()); | 1101 dest_path2.BaseName().MaybeAsASCII()); |
| 1103 profile_manager->ScheduleProfileForDeletion(dest_path2, | 1102 profile_manager->ScheduleProfileForDeletion(dest_path2, |
| 1104 ProfileManager::CreateCallback()); | 1103 ProfileManager::CreateCallback()); |
| 1105 // Spin the message loop so that all the callbacks can finish running. | 1104 // Spin the message loop so that all the callbacks can finish running. |
| 1106 base::RunLoop().RunUntilIdle(); | 1105 base::RunLoop().RunUntilIdle(); |
| 1107 | 1106 |
| 1108 EXPECT_EQ(dest_path3, profile_manager->GetLastUsedProfile()->GetPath()); | 1107 EXPECT_EQ(dest_path3, profile_manager->GetLastUsedProfile()->GetPath()); |
| 1109 EXPECT_EQ(profile_name3, local_state->GetString(prefs::kProfileLastUsed)); | 1108 EXPECT_EQ(profile_name3, local_state->GetString(prefs::kProfileLastUsed)); |
| 1110 } | 1109 } |
| 1111 #endif // !defined(OS_MACOSX) | 1110 #endif // !defined(OS_MACOSX) |
| OLD | NEW |