[email protected] | ca59107 | 2012-03-27 01:54:44 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 5 | #include "chrome/browser/profiles/profile_info_cache_unittest.h" |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 6 | |
[email protected] | 04748180 | 2013-09-16 22:26:38 | [diff] [blame] | 7 | #include <vector> |
| 8 | |
[email protected] | e5ba874f | 2013-02-14 17:20:19 | [diff] [blame] | 9 | #include "base/prefs/testing_pref_service.h" |
[email protected] | 76fb05c | 2013-06-11 04:38:05 | [diff] [blame] | 10 | #include "base/strings/stringprintf.h" |
[email protected] | e309f31 | 2013-06-07 21:50:08 | [diff] [blame] | 11 | #include "base/strings/utf_string_conversions.h" |
[email protected] | 583844c | 2011-08-27 00:38:35 | [diff] [blame] | 12 | #include "chrome/browser/browser_process.h" |
[email protected] | 25ff086 | 2013-07-12 00:59:03 | [diff] [blame] | 13 | #include "chrome/browser/chrome_notification_types.h" |
[email protected] | 0aa018a | 2013-07-31 15:08:54 | [diff] [blame] | 14 | #include "chrome/browser/prefs/pref_service_syncable.h" |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 15 | #include "chrome/browser/profiles/profile_info_cache.h" |
[email protected] | 6730b1e | 2011-09-29 05:23:52 | [diff] [blame] | 16 | #include "chrome/browser/profiles/profile_manager.h" |
[email protected] | 583844c | 2011-08-27 00:38:35 | [diff] [blame] | 17 | #include "chrome/test/base/testing_browser_process.h" |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 18 | #include "content/public/browser/notification_observer.h" |
| 19 | #include "content/public/browser/notification_registrar.h" |
[email protected] | c0b03090 | 2011-12-19 16:21:05 | [diff] [blame] | 20 | #include "content/public/browser/notification_service.h" |
[email protected] | 371662e37 | 2013-10-17 22:05:22 | [diff] [blame] | 21 | #include "content/public/test/test_browser_thread_bundle.h" |
[email protected] | a7fe911 | 2012-07-20 02:34:45 | [diff] [blame] | 22 | #include "content/public/test/test_utils.h" |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 23 | #include "third_party/skia/include/core/SkBitmap.h" |
| 24 | #include "ui/base/resource/resource_bundle.h" |
| 25 | #include "ui/gfx/image/image.h" |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 26 | #include "ui/gfx/image/image_unittest_util.h" |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 27 | |
[email protected] | 6778fed | 2013-12-24 20:09:37 | [diff] [blame^] | 28 | using base::ASCIIToUTF16; |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 29 | using content::BrowserThread; |
| 30 | |
[email protected] | 6a46066 | 2011-12-22 22:05:16 | [diff] [blame] | 31 | ProfileNameVerifierObserver::ProfileNameVerifierObserver( |
| 32 | TestingProfileManager* testing_profile_manager) |
| 33 | : testing_profile_manager_(testing_profile_manager) { |
| 34 | DCHECK(testing_profile_manager_); |
[email protected] | 590e189b | 2011-12-13 22:07:03 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | ProfileNameVerifierObserver::~ProfileNameVerifierObserver() { |
| 38 | } |
| 39 | |
| 40 | void ProfileNameVerifierObserver::OnProfileAdded( |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 41 | const base::FilePath& profile_path) { |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 42 | base::string16 profile_name = GetCache()->GetNameOfProfileAtIndex( |
[email protected] | 6a46066 | 2011-12-22 22:05:16 | [diff] [blame] | 43 | GetCache()->GetIndexOfProfileWithPath(profile_path)); |
[email protected] | 590e189b | 2011-12-13 22:07:03 | [diff] [blame] | 44 | EXPECT_TRUE(profile_names_.find(profile_name) == profile_names_.end()); |
| 45 | profile_names_.insert(profile_name); |
| 46 | } |
| 47 | |
[email protected] | 7b0af15 | 2011-12-16 17:02:06 | [diff] [blame] | 48 | void ProfileNameVerifierObserver::OnProfileWillBeRemoved( |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 49 | const base::FilePath& profile_path) { |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 50 | base::string16 profile_name = GetCache()->GetNameOfProfileAtIndex( |
[email protected] | 6a46066 | 2011-12-22 22:05:16 | [diff] [blame] | 51 | GetCache()->GetIndexOfProfileWithPath(profile_path)); |
[email protected] | 590e189b | 2011-12-13 22:07:03 | [diff] [blame] | 52 | EXPECT_TRUE(profile_names_.find(profile_name) != profile_names_.end()); |
| 53 | profile_names_.erase(profile_name); |
| 54 | } |
| 55 | |
[email protected] | 7b0af15 | 2011-12-16 17:02:06 | [diff] [blame] | 56 | void ProfileNameVerifierObserver::OnProfileWasRemoved( |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 57 | const base::FilePath& profile_path, |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 58 | const base::string16& profile_name) { |
[email protected] | 7b0af15 | 2011-12-16 17:02:06 | [diff] [blame] | 59 | EXPECT_TRUE(profile_names_.find(profile_name) == profile_names_.end()); |
| 60 | } |
| 61 | |
[email protected] | 590e189b | 2011-12-13 22:07:03 | [diff] [blame] | 62 | void ProfileNameVerifierObserver::OnProfileNameChanged( |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 63 | const base::FilePath& profile_path, |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 64 | const base::string16& old_profile_name) { |
| 65 | base::string16 new_profile_name = GetCache()->GetNameOfProfileAtIndex( |
[email protected] | 6a46066 | 2011-12-22 22:05:16 | [diff] [blame] | 66 | GetCache()->GetIndexOfProfileWithPath(profile_path)); |
[email protected] | 590e189b | 2011-12-13 22:07:03 | [diff] [blame] | 67 | EXPECT_TRUE(profile_names_.find(old_profile_name) != profile_names_.end()); |
| 68 | EXPECT_TRUE(profile_names_.find(new_profile_name) == profile_names_.end()); |
| 69 | profile_names_.erase(old_profile_name); |
| 70 | profile_names_.insert(new_profile_name); |
| 71 | } |
| 72 | |
| 73 | void ProfileNameVerifierObserver::OnProfileAvatarChanged( |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 74 | const base::FilePath& profile_path) { |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 75 | base::string16 profile_name = GetCache()->GetNameOfProfileAtIndex( |
[email protected] | 6a46066 | 2011-12-22 22:05:16 | [diff] [blame] | 76 | GetCache()->GetIndexOfProfileWithPath(profile_path)); |
[email protected] | 590e189b | 2011-12-13 22:07:03 | [diff] [blame] | 77 | EXPECT_TRUE(profile_names_.find(profile_name) != profile_names_.end()); |
| 78 | } |
| 79 | |
[email protected] | 6a46066 | 2011-12-22 22:05:16 | [diff] [blame] | 80 | ProfileInfoCache* ProfileNameVerifierObserver::GetCache() { |
| 81 | return testing_profile_manager_->profile_info_cache(); |
| 82 | } |
| 83 | |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 84 | ProfileInfoCacheTest::ProfileInfoCacheTest() |
[email protected] | 0aa018a | 2013-07-31 15:08:54 | [diff] [blame] | 85 | : testing_profile_manager_(TestingBrowserProcess::GetGlobal()), |
[email protected] | 6a46066 | 2011-12-22 22:05:16 | [diff] [blame] | 86 | name_observer_(&testing_profile_manager_) { |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | ProfileInfoCacheTest::~ProfileInfoCacheTest() { |
| 90 | } |
| 91 | |
| 92 | void ProfileInfoCacheTest::SetUp() { |
| 93 | ASSERT_TRUE(testing_profile_manager_.SetUp()); |
[email protected] | 590e189b | 2011-12-13 22:07:03 | [diff] [blame] | 94 | testing_profile_manager_.profile_info_cache()->AddObserver(&name_observer_); |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 95 | } |
| 96 | |
[email protected] | 1302dcf | 2011-11-30 21:47:05 | [diff] [blame] | 97 | void ProfileInfoCacheTest::TearDown() { |
| 98 | // Drain the UI thread to make sure all tasks are completed. This prevents |
| 99 | // memory leaks. |
[email protected] | 0aa018a | 2013-07-31 15:08:54 | [diff] [blame] | 100 | base::RunLoop().RunUntilIdle(); |
[email protected] | 1302dcf | 2011-11-30 21:47:05 | [diff] [blame] | 101 | } |
| 102 | |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 103 | ProfileInfoCache* ProfileInfoCacheTest::GetCache() { |
| 104 | return testing_profile_manager_.profile_info_cache(); |
| 105 | } |
| 106 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 107 | base::FilePath ProfileInfoCacheTest::GetProfilePath( |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 108 | const std::string& base_name) { |
| 109 | return testing_profile_manager_.profile_manager()->user_data_dir(). |
| 110 | AppendASCII(base_name); |
| 111 | } |
| 112 | |
| 113 | void ProfileInfoCacheTest::ResetCache() { |
| 114 | testing_profile_manager_.DeleteProfileInfoCache(); |
| 115 | } |
| 116 | |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 117 | namespace { |
| 118 | |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 119 | TEST_F(ProfileInfoCacheTest, AddProfiles) { |
[email protected] | 6730b1e | 2011-09-29 05:23:52 | [diff] [blame] | 120 | EXPECT_EQ(0u, GetCache()->GetNumberOfProfiles()); |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 121 | |
[email protected] | ca59107 | 2012-03-27 01:54:44 | [diff] [blame] | 122 | ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 123 | for (uint32 i = 0; i < 4; ++i) { |
[email protected] | 7d3cbc9 | 2013-03-18 22:33:04 | [diff] [blame] | 124 | base::FilePath profile_path = |
| 125 | GetProfilePath(base::StringPrintf("path_%ud", i)); |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 126 | base::string16 profile_name = |
| 127 | ASCIIToUTF16(base::StringPrintf("name_%ud", i)); |
[email protected] | ca59107 | 2012-03-27 01:54:44 | [diff] [blame] | 128 | const SkBitmap* icon = rb.GetImageNamed( |
| 129 | ProfileInfoCache::GetDefaultAvatarIconResourceIDAtIndex( |
| 130 | i)).ToSkBitmap(); |
[email protected] | a6e01b4 | 2013-08-05 14:13:13 | [diff] [blame] | 131 | std::string managed_user_id = i == 3 ? "TEST_ID" : ""; |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 132 | |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 133 | GetCache()->AddProfileToCache(profile_path, profile_name, base::string16(), |
| 134 | i, managed_user_id); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 135 | GetCache()->SetBackgroundStatusOfProfileAtIndex(i, true); |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 136 | base::string16 gaia_name = ASCIIToUTF16(base::StringPrintf("gaia_%ud", i)); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 137 | GetCache()->SetGAIANameOfProfileAtIndex(i, gaia_name); |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 138 | |
[email protected] | 6730b1e | 2011-09-29 05:23:52 | [diff] [blame] | 139 | EXPECT_EQ(i + 1, GetCache()->GetNumberOfProfiles()); |
| 140 | EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(i)); |
| 141 | EXPECT_EQ(profile_path, GetCache()->GetPathOfProfileAtIndex(i)); |
[email protected] | 0aa018a | 2013-07-31 15:08:54 | [diff] [blame] | 142 | const SkBitmap* actual_icon = |
| 143 | GetCache()->GetAvatarIconOfProfileAtIndex(i).ToSkBitmap(); |
[email protected] | ca59107 | 2012-03-27 01:54:44 | [diff] [blame] | 144 | EXPECT_EQ(icon->width(), actual_icon->width()); |
| 145 | EXPECT_EQ(icon->height(), actual_icon->height()); |
[email protected] | a6e01b4 | 2013-08-05 14:13:13 | [diff] [blame] | 146 | EXPECT_EQ(i == 3, GetCache()->ProfileIsManagedAtIndex(i)); |
| 147 | EXPECT_EQ(managed_user_id, GetCache()->GetManagedUserIdOfProfileAtIndex(i)); |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 148 | } |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 149 | |
| 150 | // Reset the cache and test the it reloads correctly. |
| 151 | ResetCache(); |
| 152 | |
| 153 | EXPECT_EQ(4u, GetCache()->GetNumberOfProfiles()); |
| 154 | for (uint32 i = 0; i < 4; ++i) { |
[email protected] | 7d3cbc9 | 2013-03-18 22:33:04 | [diff] [blame] | 155 | base::FilePath profile_path = |
| 156 | GetProfilePath(base::StringPrintf("path_%ud", i)); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 157 | EXPECT_EQ(i, GetCache()->GetIndexOfProfileWithPath(profile_path)); |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 158 | base::string16 profile_name = |
| 159 | ASCIIToUTF16(base::StringPrintf("name_%ud", i)); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 160 | EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(i)); |
| 161 | EXPECT_EQ(i, GetCache()->GetAvatarIconIndexOfProfileAtIndex(i)); |
| 162 | EXPECT_EQ(true, GetCache()->GetBackgroundStatusOfProfileAtIndex(i)); |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 163 | base::string16 gaia_name = ASCIIToUTF16(base::StringPrintf("gaia_%ud", i)); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 164 | EXPECT_EQ(gaia_name, GetCache()->GetGAIANameOfProfileAtIndex(i)); |
| 165 | } |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 166 | } |
| 167 | |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 168 | TEST_F(ProfileInfoCacheTest, DeleteProfile) { |
[email protected] | 6730b1e | 2011-09-29 05:23:52 | [diff] [blame] | 169 | EXPECT_EQ(0u, GetCache()->GetNumberOfProfiles()); |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 170 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 171 | base::FilePath path_1 = GetProfilePath("path_1"); |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 172 | GetCache()->AddProfileToCache(path_1, ASCIIToUTF16("name_1"), |
| 173 | base::string16(), 0, std::string()); |
[email protected] | 6730b1e | 2011-09-29 05:23:52 | [diff] [blame] | 174 | EXPECT_EQ(1u, GetCache()->GetNumberOfProfiles()); |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 175 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 176 | base::FilePath path_2 = GetProfilePath("path_2"); |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 177 | base::string16 name_2 = ASCIIToUTF16("name_2"); |
| 178 | GetCache()->AddProfileToCache(path_2, name_2, base::string16(), 0, |
| 179 | std::string()); |
[email protected] | 6730b1e | 2011-09-29 05:23:52 | [diff] [blame] | 180 | EXPECT_EQ(2u, GetCache()->GetNumberOfProfiles()); |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 181 | |
[email protected] | 6730b1e | 2011-09-29 05:23:52 | [diff] [blame] | 182 | GetCache()->DeleteProfileFromCache(path_1); |
| 183 | EXPECT_EQ(1u, GetCache()->GetNumberOfProfiles()); |
| 184 | EXPECT_EQ(name_2, GetCache()->GetNameOfProfileAtIndex(0)); |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 185 | |
[email protected] | 6730b1e | 2011-09-29 05:23:52 | [diff] [blame] | 186 | GetCache()->DeleteProfileFromCache(path_2); |
| 187 | EXPECT_EQ(0u, GetCache()->GetNumberOfProfiles()); |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 188 | } |
| 189 | |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 190 | TEST_F(ProfileInfoCacheTest, MutateProfile) { |
| 191 | GetCache()->AddProfileToCache( |
[email protected] | a6e01b4 | 2013-08-05 14:13:13 | [diff] [blame] | 192 | GetProfilePath("path_1"), ASCIIToUTF16("name_1"), |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 193 | base::string16(), 0, std::string()); |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 194 | GetCache()->AddProfileToCache( |
[email protected] | a6e01b4 | 2013-08-05 14:13:13 | [diff] [blame] | 195 | GetProfilePath("path_2"), ASCIIToUTF16("name_2"), |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 196 | base::string16(), 0, std::string()); |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 197 | |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 198 | base::string16 new_name = ASCIIToUTF16("new_name"); |
[email protected] | 6730b1e | 2011-09-29 05:23:52 | [diff] [blame] | 199 | GetCache()->SetNameOfProfileAtIndex(1, new_name); |
| 200 | EXPECT_EQ(new_name, GetCache()->GetNameOfProfileAtIndex(1)); |
| 201 | EXPECT_NE(new_name, GetCache()->GetNameOfProfileAtIndex(0)); |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 202 | |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 203 | base::string16 new_user_name = ASCIIToUTF16("user_name"); |
[email protected] | e8e7809 | 2011-09-29 18:15:38 | [diff] [blame] | 204 | GetCache()->SetUserNameOfProfileAtIndex(1, new_user_name); |
| 205 | EXPECT_EQ(new_user_name, GetCache()->GetUserNameOfProfileAtIndex(1)); |
| 206 | EXPECT_NE(new_user_name, GetCache()->GetUserNameOfProfileAtIndex(0)); |
| 207 | |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 208 | size_t new_icon_index = 3; |
[email protected] | 6730b1e | 2011-09-29 05:23:52 | [diff] [blame] | 209 | GetCache()->SetAvatarIconOfProfileAtIndex(1, new_icon_index); |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 210 | // Not much to test. |
[email protected] | 6730b1e | 2011-09-29 05:23:52 | [diff] [blame] | 211 | GetCache()->GetAvatarIconOfProfileAtIndex(1); |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 212 | } |
| 213 | |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 214 | TEST_F(ProfileInfoCacheTest, Sort) { |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 215 | base::string16 name_a = ASCIIToUTF16("apple"); |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 216 | GetCache()->AddProfileToCache( |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 217 | GetProfilePath("path_a"), name_a, base::string16(), 0, std::string()); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 218 | |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 219 | base::string16 name_c = ASCIIToUTF16("cat"); |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 220 | GetCache()->AddProfileToCache( |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 221 | GetProfilePath("path_c"), name_c, base::string16(), 0, std::string()); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 222 | |
| 223 | // Sanity check the initial order. |
| 224 | EXPECT_EQ(name_a, GetCache()->GetNameOfProfileAtIndex(0)); |
| 225 | EXPECT_EQ(name_c, GetCache()->GetNameOfProfileAtIndex(1)); |
| 226 | |
| 227 | // Add a new profile (start with a capital to test case insensitive sorting. |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 228 | base::string16 name_b = ASCIIToUTF16("Banana"); |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 229 | GetCache()->AddProfileToCache( |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 230 | GetProfilePath("path_b"), name_b, base::string16(), 0, std::string()); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 231 | |
| 232 | // Verify the new order. |
| 233 | EXPECT_EQ(name_a, GetCache()->GetNameOfProfileAtIndex(0)); |
| 234 | EXPECT_EQ(name_b, GetCache()->GetNameOfProfileAtIndex(1)); |
| 235 | EXPECT_EQ(name_c, GetCache()->GetNameOfProfileAtIndex(2)); |
| 236 | |
| 237 | // Change the name of an existing profile. |
| 238 | name_a = UTF8ToUTF16("dog"); |
| 239 | GetCache()->SetNameOfProfileAtIndex(0, name_a); |
| 240 | |
| 241 | // Verify the new order. |
| 242 | EXPECT_EQ(name_b, GetCache()->GetNameOfProfileAtIndex(0)); |
| 243 | EXPECT_EQ(name_c, GetCache()->GetNameOfProfileAtIndex(1)); |
| 244 | EXPECT_EQ(name_a, GetCache()->GetNameOfProfileAtIndex(2)); |
| 245 | |
| 246 | // Delete a profile. |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 247 | GetCache()->DeleteProfileFromCache(GetProfilePath("path_c")); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 248 | |
| 249 | // Verify the new order. |
| 250 | EXPECT_EQ(name_b, GetCache()->GetNameOfProfileAtIndex(0)); |
| 251 | EXPECT_EQ(name_a, GetCache()->GetNameOfProfileAtIndex(1)); |
| 252 | } |
| 253 | |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 254 | TEST_F(ProfileInfoCacheTest, BackgroundModeStatus) { |
[email protected] | 27917083 | 2011-10-12 23:38:03 | [diff] [blame] | 255 | GetCache()->AddProfileToCache( |
[email protected] | a6e01b4 | 2013-08-05 14:13:13 | [diff] [blame] | 256 | GetProfilePath("path_1"), ASCIIToUTF16("name_1"), |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 257 | base::string16(), 0, std::string()); |
[email protected] | 27917083 | 2011-10-12 23:38:03 | [diff] [blame] | 258 | GetCache()->AddProfileToCache( |
[email protected] | a6e01b4 | 2013-08-05 14:13:13 | [diff] [blame] | 259 | GetProfilePath("path_2"), ASCIIToUTF16("name_2"), |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 260 | base::string16(), 0, std::string()); |
[email protected] | 27917083 | 2011-10-12 23:38:03 | [diff] [blame] | 261 | |
| 262 | EXPECT_FALSE(GetCache()->GetBackgroundStatusOfProfileAtIndex(0)); |
| 263 | EXPECT_FALSE(GetCache()->GetBackgroundStatusOfProfileAtIndex(1)); |
| 264 | |
| 265 | GetCache()->SetBackgroundStatusOfProfileAtIndex(1, true); |
| 266 | |
| 267 | EXPECT_FALSE(GetCache()->GetBackgroundStatusOfProfileAtIndex(0)); |
| 268 | EXPECT_TRUE(GetCache()->GetBackgroundStatusOfProfileAtIndex(1)); |
| 269 | |
| 270 | GetCache()->SetBackgroundStatusOfProfileAtIndex(0, true); |
| 271 | |
| 272 | EXPECT_TRUE(GetCache()->GetBackgroundStatusOfProfileAtIndex(0)); |
| 273 | EXPECT_TRUE(GetCache()->GetBackgroundStatusOfProfileAtIndex(1)); |
| 274 | |
| 275 | GetCache()->SetBackgroundStatusOfProfileAtIndex(1, false); |
| 276 | |
| 277 | EXPECT_TRUE(GetCache()->GetBackgroundStatusOfProfileAtIndex(0)); |
| 278 | EXPECT_FALSE(GetCache()->GetBackgroundStatusOfProfileAtIndex(1)); |
| 279 | } |
| 280 | |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 281 | TEST_F(ProfileInfoCacheTest, HasMigrated) { |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 282 | GetCache()->AddProfileToCache( |
[email protected] | a6e01b4 | 2013-08-05 14:13:13 | [diff] [blame] | 283 | GetProfilePath("path_1"), ASCIIToUTF16("name_1"), |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 284 | base::string16(), 0, std::string()); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 285 | GetCache()->AddProfileToCache( |
[email protected] | a6e01b4 | 2013-08-05 14:13:13 | [diff] [blame] | 286 | GetProfilePath("path_2"), ASCIIToUTF16("name_2"), |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 287 | base::string16(), 0, std::string()); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 288 | |
| 289 | // Sanity check. |
| 290 | EXPECT_FALSE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(0)); |
| 291 | EXPECT_FALSE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(1)); |
| 292 | |
| 293 | // Set migrated state for 2nd profile. |
| 294 | GetCache()->SetHasMigratedToGAIAInfoOfProfileAtIndex(1, true); |
| 295 | EXPECT_FALSE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(0)); |
| 296 | EXPECT_TRUE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(1)); |
| 297 | |
| 298 | // Set migrated state for 1st profile. |
| 299 | GetCache()->SetHasMigratedToGAIAInfoOfProfileAtIndex(0, true); |
| 300 | EXPECT_TRUE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(0)); |
| 301 | EXPECT_TRUE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(1)); |
| 302 | |
| 303 | // Unset migrated state for 2nd profile. |
| 304 | GetCache()->SetHasMigratedToGAIAInfoOfProfileAtIndex(1, false); |
| 305 | EXPECT_TRUE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(0)); |
| 306 | EXPECT_FALSE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(1)); |
| 307 | } |
| 308 | |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 309 | TEST_F(ProfileInfoCacheTest, GAIAName) { |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 310 | GetCache()->AddProfileToCache( |
[email protected] | a6e01b4 | 2013-08-05 14:13:13 | [diff] [blame] | 311 | GetProfilePath("path_1"), ASCIIToUTF16("name_1"), |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 312 | base::string16(), 0, std::string()); |
| 313 | base::string16 profile_name(ASCIIToUTF16("profile name 2")); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 314 | GetCache()->AddProfileToCache( |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 315 | GetProfilePath("path_2"), profile_name, base::string16(), 0, |
| 316 | std::string()); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 317 | |
| 318 | // Sanity check. |
| 319 | EXPECT_TRUE(GetCache()->GetGAIANameOfProfileAtIndex(0).empty()); |
| 320 | EXPECT_TRUE(GetCache()->GetGAIANameOfProfileAtIndex(1).empty()); |
| 321 | EXPECT_FALSE(GetCache()->IsUsingGAIANameOfProfileAtIndex(0)); |
| 322 | EXPECT_FALSE(GetCache()->IsUsingGAIANameOfProfileAtIndex(1)); |
| 323 | |
| 324 | // Set GAIA name. |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 325 | base::string16 gaia_name(ASCIIToUTF16("Pat Smith")); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 326 | GetCache()->SetGAIANameOfProfileAtIndex(1, gaia_name); |
| 327 | EXPECT_TRUE(GetCache()->GetGAIANameOfProfileAtIndex(0).empty()); |
| 328 | EXPECT_EQ(gaia_name, GetCache()->GetGAIANameOfProfileAtIndex(1)); |
| 329 | EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(1)); |
| 330 | |
| 331 | // Use GAIA name as profile name. |
| 332 | GetCache()->SetIsUsingGAIANameOfProfileAtIndex(1, true); |
| 333 | |
| 334 | EXPECT_EQ(gaia_name, GetCache()->GetNameOfProfileAtIndex(1)); |
| 335 | EXPECT_EQ(gaia_name, GetCache()->GetGAIANameOfProfileAtIndex(1)); |
| 336 | |
| 337 | // Don't use GAIA name as profile name. |
| 338 | GetCache()->SetIsUsingGAIANameOfProfileAtIndex(1, false); |
| 339 | EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(1)); |
| 340 | EXPECT_EQ(gaia_name, GetCache()->GetGAIANameOfProfileAtIndex(1)); |
| 341 | } |
| 342 | |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 343 | TEST_F(ProfileInfoCacheTest, GAIAPicture) { |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 344 | GetCache()->AddProfileToCache( |
[email protected] | a6e01b4 | 2013-08-05 14:13:13 | [diff] [blame] | 345 | GetProfilePath("path_1"), ASCIIToUTF16("name_1"), |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 346 | base::string16(), 0, std::string()); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 347 | GetCache()->AddProfileToCache( |
[email protected] | a6e01b4 | 2013-08-05 14:13:13 | [diff] [blame] | 348 | GetProfilePath("path_2"), ASCIIToUTF16("name_2"), |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 349 | base::string16(), 0, std::string()); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 350 | |
| 351 | // Sanity check. |
[email protected] | 2f3c00f | 2011-11-30 04:36:22 | [diff] [blame] | 352 | EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(0)); |
| 353 | EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(1)); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 354 | EXPECT_FALSE(GetCache()->IsUsingGAIAPictureOfProfileAtIndex(0)); |
| 355 | EXPECT_FALSE(GetCache()->IsUsingGAIAPictureOfProfileAtIndex(1)); |
| 356 | |
| 357 | // The profile icon should be the default one. |
| 358 | int id = ProfileInfoCache::GetDefaultAvatarIconResourceIDAtIndex(0); |
| 359 | const gfx::Image& profile_image( |
| 360 | ResourceBundle::GetSharedInstance().GetImageNamed(id)); |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 361 | EXPECT_TRUE(gfx::test::IsEqual( |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 362 | profile_image, GetCache()->GetAvatarIconOfProfileAtIndex(1))); |
| 363 | |
| 364 | // Set GAIA picture. |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 365 | gfx::Image gaia_image(gfx::test::CreateImage()); |
[email protected] | 2f3c00f | 2011-11-30 04:36:22 | [diff] [blame] | 366 | GetCache()->SetGAIAPictureOfProfileAtIndex(1, &gaia_image); |
| 367 | EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(0)); |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 368 | EXPECT_TRUE(gfx::test::IsEqual( |
[email protected] | 2f3c00f | 2011-11-30 04:36:22 | [diff] [blame] | 369 | gaia_image, *GetCache()->GetGAIAPictureOfProfileAtIndex(1))); |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 370 | EXPECT_TRUE(gfx::test::IsEqual( |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 371 | profile_image, GetCache()->GetAvatarIconOfProfileAtIndex(1))); |
| 372 | |
| 373 | // Use GAIA picture as profile picture. |
| 374 | GetCache()->SetIsUsingGAIAPictureOfProfileAtIndex(1, true); |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 375 | EXPECT_TRUE(gfx::test::IsEqual( |
[email protected] | 2f3c00f | 2011-11-30 04:36:22 | [diff] [blame] | 376 | gaia_image, *GetCache()->GetGAIAPictureOfProfileAtIndex(1))); |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 377 | EXPECT_TRUE(gfx::test::IsEqual( |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 378 | gaia_image, GetCache()->GetAvatarIconOfProfileAtIndex(1))); |
| 379 | |
| 380 | // Don't use GAIA picture as profile picture. |
| 381 | GetCache()->SetIsUsingGAIAPictureOfProfileAtIndex(1, false); |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 382 | EXPECT_TRUE(gfx::test::IsEqual( |
[email protected] | 2f3c00f | 2011-11-30 04:36:22 | [diff] [blame] | 383 | gaia_image, *GetCache()->GetGAIAPictureOfProfileAtIndex(1))); |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 384 | EXPECT_TRUE(gfx::test::IsEqual( |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 385 | profile_image, GetCache()->GetAvatarIconOfProfileAtIndex(1))); |
| 386 | } |
| 387 | |
[email protected] | 754bebc | 2011-12-01 16:42:16 | [diff] [blame] | 388 | TEST_F(ProfileInfoCacheTest, PersistGAIAPicture) { |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 389 | GetCache()->AddProfileToCache( |
[email protected] | a6e01b4 | 2013-08-05 14:13:13 | [diff] [blame] | 390 | GetProfilePath("path_1"), ASCIIToUTF16("name_1"), |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 391 | base::string16(), 0, std::string()); |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 392 | gfx::Image gaia_image(gfx::test::CreateImage()); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 393 | |
[email protected] | a7fe911 | 2012-07-20 02:34:45 | [diff] [blame] | 394 | content::WindowedNotificationObserver save_observer( |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 395 | chrome::NOTIFICATION_PROFILE_CACHE_PICTURE_SAVED, |
| 396 | content::NotificationService::AllSources()); |
[email protected] | 2f3c00f | 2011-11-30 04:36:22 | [diff] [blame] | 397 | GetCache()->SetGAIAPictureOfProfileAtIndex(0, &gaia_image); |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 398 | EXPECT_TRUE(gfx::test::IsEqual( |
[email protected] | 2f3c00f | 2011-11-30 04:36:22 | [diff] [blame] | 399 | gaia_image, *GetCache()->GetGAIAPictureOfProfileAtIndex(0))); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 400 | |
| 401 | // Wait for the file to be written to disk then reset the cache. |
| 402 | save_observer.Wait(); |
| 403 | ResetCache(); |
| 404 | |
| 405 | // Try to get the GAIA picture. This should return NULL until the read from |
| 406 | // disk is done. |
[email protected] | a7fe911 | 2012-07-20 02:34:45 | [diff] [blame] | 407 | content::WindowedNotificationObserver read_observer( |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 408 | chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, |
| 409 | content::NotificationService::AllSources()); |
[email protected] | 2f3c00f | 2011-11-30 04:36:22 | [diff] [blame] | 410 | EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(0)); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 411 | read_observer.Wait(); |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 412 | EXPECT_TRUE(gfx::test::IsEqual( |
[email protected] | 2f3c00f | 2011-11-30 04:36:22 | [diff] [blame] | 413 | gaia_image, *GetCache()->GetGAIAPictureOfProfileAtIndex(0))); |
| 414 | } |
| 415 | |
[email protected] | a6e01b4 | 2013-08-05 14:13:13 | [diff] [blame] | 416 | TEST_F(ProfileInfoCacheTest, SetManagedUserId) { |
[email protected] | 0aa018a | 2013-07-31 15:08:54 | [diff] [blame] | 417 | GetCache()->AddProfileToCache( |
[email protected] | a6e01b4 | 2013-08-05 14:13:13 | [diff] [blame] | 418 | GetProfilePath("test"), ASCIIToUTF16("Test"), |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 419 | base::string16(), 0, std::string()); |
[email protected] | 0aa018a | 2013-07-31 15:08:54 | [diff] [blame] | 420 | EXPECT_FALSE(GetCache()->ProfileIsManagedAtIndex(0)); |
| 421 | |
[email protected] | a6e01b4 | 2013-08-05 14:13:13 | [diff] [blame] | 422 | GetCache()->SetManagedUserIdOfProfileAtIndex(0, "TEST_ID"); |
[email protected] | 0aa018a | 2013-07-31 15:08:54 | [diff] [blame] | 423 | EXPECT_TRUE(GetCache()->ProfileIsManagedAtIndex(0)); |
[email protected] | a6e01b4 | 2013-08-05 14:13:13 | [diff] [blame] | 424 | EXPECT_EQ("TEST_ID", GetCache()->GetManagedUserIdOfProfileAtIndex(0)); |
[email protected] | 0aa018a | 2013-07-31 15:08:54 | [diff] [blame] | 425 | |
| 426 | ResetCache(); |
| 427 | EXPECT_TRUE(GetCache()->ProfileIsManagedAtIndex(0)); |
| 428 | |
[email protected] | a6e01b4 | 2013-08-05 14:13:13 | [diff] [blame] | 429 | GetCache()->SetManagedUserIdOfProfileAtIndex(0, std::string()); |
[email protected] | 0aa018a | 2013-07-31 15:08:54 | [diff] [blame] | 430 | EXPECT_FALSE(GetCache()->ProfileIsManagedAtIndex(0)); |
[email protected] | a6e01b4 | 2013-08-05 14:13:13 | [diff] [blame] | 431 | EXPECT_EQ("", GetCache()->GetManagedUserIdOfProfileAtIndex(0)); |
[email protected] | 0aa018a | 2013-07-31 15:08:54 | [diff] [blame] | 432 | } |
| 433 | |
[email protected] | 2f3c00f | 2011-11-30 04:36:22 | [diff] [blame] | 434 | TEST_F(ProfileInfoCacheTest, EmptyGAIAInfo) { |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 435 | base::string16 profile_name = ASCIIToUTF16("name_1"); |
[email protected] | 2f3c00f | 2011-11-30 04:36:22 | [diff] [blame] | 436 | int id = ProfileInfoCache::GetDefaultAvatarIconResourceIDAtIndex(0); |
| 437 | const gfx::Image& profile_image( |
| 438 | ResourceBundle::GetSharedInstance().GetImageNamed(id)); |
| 439 | |
| 440 | GetCache()->AddProfileToCache( |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 441 | GetProfilePath("path_1"), profile_name, base::string16(), 0, |
| 442 | std::string()); |
[email protected] | 2f3c00f | 2011-11-30 04:36:22 | [diff] [blame] | 443 | |
| 444 | // Set empty GAIA info. |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 445 | GetCache()->SetGAIANameOfProfileAtIndex(0, base::string16()); |
[email protected] | 2f3c00f | 2011-11-30 04:36:22 | [diff] [blame] | 446 | GetCache()->SetGAIAPictureOfProfileAtIndex(0, NULL); |
| 447 | GetCache()->SetIsUsingGAIANameOfProfileAtIndex(0, true); |
| 448 | GetCache()->SetIsUsingGAIAPictureOfProfileAtIndex(0, true); |
| 449 | |
| 450 | // Verify that the profile name and picture are not empty. |
| 451 | EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(0)); |
| 452 | EXPECT_TRUE(gfx::test::IsEqual( |
| 453 | profile_image, GetCache()->GetAvatarIconOfProfileAtIndex(0))); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 454 | } |
| 455 | |
[email protected] | 0aa018a | 2013-07-31 15:08:54 | [diff] [blame] | 456 | TEST_F(ProfileInfoCacheTest, CreateManagedTestingProfile) { |
| 457 | testing_profile_manager_.CreateTestingProfile("default"); |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 458 | base::string16 managed_user_name = ASCIIToUTF16("Supervised User"); |
[email protected] | 0aa018a | 2013-07-31 15:08:54 | [diff] [blame] | 459 | testing_profile_manager_.CreateTestingProfile( |
[email protected] | a6e01b4 | 2013-08-05 14:13:13 | [diff] [blame] | 460 | "test1", scoped_ptr<PrefServiceSyncable>(), |
[email protected] | cb0323d | 2013-11-22 23:21:26 | [diff] [blame] | 461 | managed_user_name, 0, "TEST_ID", TestingProfile::TestingFactories()); |
[email protected] | 0aa018a | 2013-07-31 15:08:54 | [diff] [blame] | 462 | for (size_t i = 0; i < GetCache()->GetNumberOfProfiles(); i++) { |
| 463 | bool is_managed = |
| 464 | GetCache()->GetNameOfProfileAtIndex(i) == managed_user_name; |
| 465 | EXPECT_EQ(is_managed, GetCache()->ProfileIsManagedAtIndex(i)); |
[email protected] | a6e01b4 | 2013-08-05 14:13:13 | [diff] [blame] | 466 | std::string managed_user_id = is_managed ? "TEST_ID" : ""; |
| 467 | EXPECT_EQ(managed_user_id, GetCache()->GetManagedUserIdOfProfileAtIndex(i)); |
[email protected] | 0aa018a | 2013-07-31 15:08:54 | [diff] [blame] | 468 | } |
[email protected] | 371662e37 | 2013-10-17 22:05:22 | [diff] [blame] | 469 | |
| 470 | // Managed profiles have a custom theme, which needs to be deleted on the FILE |
| 471 | // thread. Reset the profile manager now so everything is deleted while we |
| 472 | // still have a FILE thread. |
| 473 | TestingBrowserProcess::GetGlobal()->SetProfileManager(NULL); |
[email protected] | 0aa018a | 2013-07-31 15:08:54 | [diff] [blame] | 474 | } |
| 475 | |
[email protected] | 04748180 | 2013-09-16 22:26:38 | [diff] [blame] | 476 | TEST_F(ProfileInfoCacheTest, AddStubProfile) { |
| 477 | EXPECT_EQ(0u, GetCache()->GetNumberOfProfiles()); |
| 478 | |
| 479 | // Add some profiles with and without a '.' in their paths. |
| 480 | const struct { |
| 481 | const char* profile_path; |
| 482 | const char* profile_name; |
| 483 | } kTestCases[] = { |
| 484 | { "path.test0", "name_0" }, |
| 485 | { "path_test1", "name_1" }, |
| 486 | { "path.test2", "name_2" }, |
| 487 | { "path_test3", "name_3" }, |
| 488 | }; |
| 489 | |
| 490 | for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { |
| 491 | base::FilePath profile_path = GetProfilePath(kTestCases[i].profile_path); |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 492 | base::string16 profile_name = ASCIIToUTF16(kTestCases[i].profile_name); |
[email protected] | 04748180 | 2013-09-16 22:26:38 | [diff] [blame] | 493 | |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 494 | GetCache()->AddProfileToCache(profile_path, profile_name, base::string16(), |
| 495 | i, ""); |
[email protected] | 04748180 | 2013-09-16 22:26:38 | [diff] [blame] | 496 | |
| 497 | EXPECT_EQ(profile_path, GetCache()->GetPathOfProfileAtIndex(i)); |
| 498 | EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(i)); |
| 499 | } |
| 500 | |
| 501 | ASSERT_EQ(4U, GetCache()->GetNumberOfProfiles()); |
| 502 | |
| 503 | // Check that the profiles can be extracted from the local state. |
[email protected] | d2065e06 | 2013-12-12 23:49:52 | [diff] [blame] | 504 | std::vector<base::string16> names = ProfileInfoCache::GetProfileNames(); |
[email protected] | 04748180 | 2013-09-16 22:26:38 | [diff] [blame] | 505 | for (size_t i = 0; i < 4; i++) |
| 506 | ASSERT_FALSE(names[i].empty()); |
| 507 | } |
| 508 | |
[email protected] | 6730b1e | 2011-09-29 05:23:52 | [diff] [blame] | 509 | } // namespace |