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