[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 | |
avi | b896c71 | 2015-12-26 02:10:43 | [diff] [blame] | 7 | #include <stddef.h> |
| 8 | #include <stdint.h> |
| 9 | |
[email protected] | 04748180 | 2013-09-16 22:26:38 | [diff] [blame] | 10 | #include <vector> |
| 11 | |
lwchkg | 3f449120 | 2016-03-30 16:49:52 | [diff] [blame] | 12 | #include "base/bind.h" |
[email protected] | 5cf8bcd9 | 2014-07-17 20:27:40 | [diff] [blame] | 13 | #include "base/command_line.h" |
thestig | 18dfb7a5 | 2014-08-26 10:44:04 | [diff] [blame] | 14 | #include "base/files/file_util.h" |
avi | b896c71 | 2015-12-26 02:10:43 | [diff] [blame] | 15 | #include "base/macros.h" |
[email protected] | 76fb05c | 2013-06-11 04:38:05 | [diff] [blame] | 16 | #include "base/strings/stringprintf.h" |
[email protected] | e309f31 | 2013-06-07 21:50:08 | [diff] [blame] | 17 | #include "base/strings/utf_string_conversions.h" |
[email protected] | 85503a0 | 2014-01-16 17:27:22 | [diff] [blame] | 18 | #include "base/time/time.h" |
avi | b896c71 | 2015-12-26 02:10:43 | [diff] [blame] | 19 | #include "build/build_config.h" |
[email protected] | 583844c | 2011-08-27 00:38:35 | [diff] [blame] | 20 | #include "chrome/browser/browser_process.h" |
Xi Cheng | 1b76138 | 2017-08-15 20:37:34 | [diff] [blame] | 21 | #include "chrome/browser/profiles/avatar_menu.h" |
[email protected] | c3e55977 | 2014-04-09 04:02:54 | [diff] [blame] | 22 | #include "chrome/browser/profiles/profile_avatar_icon_util.h" |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 23 | #include "chrome/browser/profiles/profile_info_cache.h" |
[email protected] | 6730b1e | 2011-09-29 05:23:52 | [diff] [blame] | 24 | #include "chrome/browser/profiles/profile_manager.h" |
[email protected] | 5cf8bcd9 | 2014-07-17 20:27:40 | [diff] [blame] | 25 | #include "chrome/common/chrome_switches.h" |
noms | 693f35aa | 2015-02-05 16:03:16 | [diff] [blame] | 26 | #include "chrome/common/pref_names.h" |
[email protected] | 583844c | 2011-08-27 00:38:35 | [diff] [blame] | 27 | #include "chrome/test/base/testing_browser_process.h" |
Alexander Alekseev | 3f09a8f | 2018-05-03 02:52:10 | [diff] [blame] | 28 | #include "components/account_id/account_id.h" |
brettw | b1fc1b8 | 2016-02-02 00:19:08 | [diff] [blame] | 29 | #include "components/prefs/testing_pref_service.h" |
Colin Blundell | ac55c997 | 2018-11-07 15:30:33 | [diff] [blame^] | 30 | #include "components/signin/core/browser/account_consistency_method.h" |
maxbogue | ea16ff41 | 2016-10-28 16:35:29 | [diff] [blame] | 31 | #include "components/sync_preferences/pref_service_syncable.h" |
[email protected] | 371662e37 | 2013-10-17 22:05:22 | [diff] [blame] | 32 | #include "content/public/test/test_browser_thread_bundle.h" |
[email protected] | a7fe911 | 2012-07-20 02:34:45 | [diff] [blame] | 33 | #include "content/public/test/test_utils.h" |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 34 | #include "third_party/skia/include/core/SkBitmap.h" |
| 35 | #include "ui/base/resource/resource_bundle.h" |
| 36 | #include "ui/gfx/image/image.h" |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 37 | #include "ui/gfx/image/image_unittest_util.h" |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 38 | |
Jochen Eisinger | d84bb42a | 2018-07-23 22:39:03 | [diff] [blame] | 39 | #if BUILDFLAG(ENABLE_SUPERVISED_USERS) |
| 40 | #include "chrome/browser/supervised_user/supervised_user_constants.h" |
| 41 | #endif |
| 42 | |
[email protected] | 6778fed | 2013-12-24 20:09:37 | [diff] [blame] | 43 | using base::ASCIIToUTF16; |
[email protected] | f729d7a | 2013-12-26 07:07:56 | [diff] [blame] | 44 | using base::UTF8ToUTF16; |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 45 | using content::BrowserThread; |
| 46 | |
[email protected] | 6a46066 | 2011-12-22 22:05:16 | [diff] [blame] | 47 | ProfileNameVerifierObserver::ProfileNameVerifierObserver( |
| 48 | TestingProfileManager* testing_profile_manager) |
| 49 | : testing_profile_manager_(testing_profile_manager) { |
| 50 | DCHECK(testing_profile_manager_); |
[email protected] | 590e189b | 2011-12-13 22:07:03 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | ProfileNameVerifierObserver::~ProfileNameVerifierObserver() { |
| 54 | } |
| 55 | |
| 56 | void ProfileNameVerifierObserver::OnProfileAdded( |
[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 | base::string16 profile_name = GetCache()->GetNameOfProfileAtIndex( |
[email protected] | 6a46066 | 2011-12-22 22:05:16 | [diff] [blame] | 59 | GetCache()->GetIndexOfProfileWithPath(profile_path)); |
[email protected] | 590e189b | 2011-12-13 22:07:03 | [diff] [blame] | 60 | EXPECT_TRUE(profile_names_.find(profile_name) == profile_names_.end()); |
| 61 | profile_names_.insert(profile_name); |
| 62 | } |
| 63 | |
[email protected] | 7b0af15 | 2011-12-16 17:02:06 | [diff] [blame] | 64 | void ProfileNameVerifierObserver::OnProfileWillBeRemoved( |
[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 | base::string16 profile_name = GetCache()->GetNameOfProfileAtIndex( |
[email protected] | 6a46066 | 2011-12-22 22:05:16 | [diff] [blame] | 67 | GetCache()->GetIndexOfProfileWithPath(profile_path)); |
[email protected] | 590e189b | 2011-12-13 22:07:03 | [diff] [blame] | 68 | EXPECT_TRUE(profile_names_.find(profile_name) != profile_names_.end()); |
| 69 | profile_names_.erase(profile_name); |
| 70 | } |
| 71 | |
[email protected] | 7b0af15 | 2011-12-16 17:02:06 | [diff] [blame] | 72 | void ProfileNameVerifierObserver::OnProfileWasRemoved( |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 73 | const base::FilePath& profile_path, |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 74 | const base::string16& profile_name) { |
[email protected] | 7b0af15 | 2011-12-16 17:02:06 | [diff] [blame] | 75 | EXPECT_TRUE(profile_names_.find(profile_name) == profile_names_.end()); |
| 76 | } |
| 77 | |
[email protected] | 590e189b | 2011-12-13 22:07:03 | [diff] [blame] | 78 | void ProfileNameVerifierObserver::OnProfileNameChanged( |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 79 | const base::FilePath& profile_path, |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 80 | const base::string16& old_profile_name) { |
| 81 | base::string16 new_profile_name = GetCache()->GetNameOfProfileAtIndex( |
[email protected] | 6a46066 | 2011-12-22 22:05:16 | [diff] [blame] | 82 | GetCache()->GetIndexOfProfileWithPath(profile_path)); |
[email protected] | 590e189b | 2011-12-13 22:07:03 | [diff] [blame] | 83 | EXPECT_TRUE(profile_names_.find(old_profile_name) != profile_names_.end()); |
| 84 | EXPECT_TRUE(profile_names_.find(new_profile_name) == profile_names_.end()); |
| 85 | profile_names_.erase(old_profile_name); |
| 86 | profile_names_.insert(new_profile_name); |
| 87 | } |
| 88 | |
| 89 | void ProfileNameVerifierObserver::OnProfileAvatarChanged( |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 90 | const base::FilePath& profile_path) { |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 91 | base::string16 profile_name = GetCache()->GetNameOfProfileAtIndex( |
[email protected] | 6a46066 | 2011-12-22 22:05:16 | [diff] [blame] | 92 | GetCache()->GetIndexOfProfileWithPath(profile_path)); |
[email protected] | 590e189b | 2011-12-13 22:07:03 | [diff] [blame] | 93 | EXPECT_TRUE(profile_names_.find(profile_name) != profile_names_.end()); |
| 94 | } |
| 95 | |
[email protected] | 6a46066 | 2011-12-22 22:05:16 | [diff] [blame] | 96 | ProfileInfoCache* ProfileNameVerifierObserver::GetCache() { |
| 97 | return testing_profile_manager_->profile_info_cache(); |
| 98 | } |
| 99 | |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 100 | ProfileInfoCacheTest::ProfileInfoCacheTest() |
[email protected] | 0aa018a | 2013-07-31 15:08:54 | [diff] [blame] | 101 | : testing_profile_manager_(TestingBrowserProcess::GetGlobal()), |
WC Leung | 6c602d4 | 2018-01-23 22:32:18 | [diff] [blame] | 102 | name_observer_(&testing_profile_manager_) {} |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 103 | |
| 104 | ProfileInfoCacheTest::~ProfileInfoCacheTest() { |
| 105 | } |
| 106 | |
| 107 | void ProfileInfoCacheTest::SetUp() { |
| 108 | ASSERT_TRUE(testing_profile_manager_.SetUp()); |
[email protected] | 590e189b | 2011-12-13 22:07:03 | [diff] [blame] | 109 | testing_profile_manager_.profile_info_cache()->AddObserver(&name_observer_); |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 110 | } |
| 111 | |
[email protected] | 1302dcf | 2011-11-30 21:47:05 | [diff] [blame] | 112 | void ProfileInfoCacheTest::TearDown() { |
Gabriel Charette | 426214f | 2017-08-14 18:21:58 | [diff] [blame] | 113 | // Drain remaining tasks to make sure all tasks are completed. This prevents |
[email protected] | 1302dcf | 2011-11-30 21:47:05 | [diff] [blame] | 114 | // memory leaks. |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 115 | content::RunAllTasksUntilIdle(); |
[email protected] | 1302dcf | 2011-11-30 21:47:05 | [diff] [blame] | 116 | } |
| 117 | |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 118 | ProfileInfoCache* ProfileInfoCacheTest::GetCache() { |
| 119 | return testing_profile_manager_.profile_info_cache(); |
| 120 | } |
| 121 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 122 | base::FilePath ProfileInfoCacheTest::GetProfilePath( |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 123 | const std::string& base_name) { |
| 124 | return testing_profile_manager_.profile_manager()->user_data_dir(). |
| 125 | AppendASCII(base_name); |
| 126 | } |
| 127 | |
| 128 | void ProfileInfoCacheTest::ResetCache() { |
| 129 | testing_profile_manager_.DeleteProfileInfoCache(); |
| 130 | } |
| 131 | |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 132 | TEST_F(ProfileInfoCacheTest, AddProfiles) { |
[email protected] | 6730b1e | 2011-09-29 05:23:52 | [diff] [blame] | 133 | EXPECT_EQ(0u, GetCache()->GetNumberOfProfiles()); |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 134 | |
[email protected] | ca59107 | 2012-03-27 01:54:44 | [diff] [blame] | 135 | ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
avi | b896c71 | 2015-12-26 02:10:43 | [diff] [blame] | 136 | for (uint32_t i = 0; i < 4; ++i) { |
[email protected] | 7d3cbc9 | 2013-03-18 22:33:04 | [diff] [blame] | 137 | base::FilePath profile_path = |
| 138 | GetProfilePath(base::StringPrintf("path_%ud", i)); |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 139 | base::string16 profile_name = |
| 140 | ASCIIToUTF16(base::StringPrintf("name_%ud", i)); |
[email protected] | ca59107 | 2012-03-27 01:54:44 | [diff] [blame] | 141 | const SkBitmap* icon = rb.GetImageNamed( |
[email protected] | c3e55977 | 2014-04-09 04:02:54 | [diff] [blame] | 142 | profiles::GetDefaultAvatarIconResourceIDAtIndex( |
[email protected] | ca59107 | 2012-03-27 01:54:44 | [diff] [blame] | 143 | i)).ToSkBitmap(); |
Jochen Eisinger | d84bb42a | 2018-07-23 22:39:03 | [diff] [blame] | 144 | std::string supervised_user_id = ""; |
| 145 | #if BUILDFLAG(ENABLE_SUPERVISED_USERS) |
| 146 | if (i == 3) |
| 147 | supervised_user_id = supervised_users::kChildAccountSUID; |
| 148 | #endif |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 149 | |
rogerta | e2265960 | 2015-05-11 21:58:21 | [diff] [blame] | 150 | GetCache()->AddProfileToCache(profile_path, profile_name, std::string(), |
Roman Sorokin | 8ead4d7 | 2018-04-16 15:58:58 | [diff] [blame] | 151 | base::string16(), i, supervised_user_id, |
| 152 | EmptyAccountId()); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 153 | GetCache()->SetBackgroundStatusOfProfileAtIndex(i, true); |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 154 | base::string16 gaia_name = ASCIIToUTF16(base::StringPrintf("gaia_%ud", i)); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 155 | GetCache()->SetGAIANameOfProfileAtIndex(i, gaia_name); |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 156 | |
[email protected] | 6730b1e | 2011-09-29 05:23:52 | [diff] [blame] | 157 | EXPECT_EQ(i + 1, GetCache()->GetNumberOfProfiles()); |
| 158 | EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(i)); |
| 159 | EXPECT_EQ(profile_path, GetCache()->GetPathOfProfileAtIndex(i)); |
[email protected] | 0aa018a | 2013-07-31 15:08:54 | [diff] [blame] | 160 | const SkBitmap* actual_icon = |
| 161 | GetCache()->GetAvatarIconOfProfileAtIndex(i).ToSkBitmap(); |
[email protected] | ca59107 | 2012-03-27 01:54:44 | [diff] [blame] | 162 | EXPECT_EQ(icon->width(), actual_icon->width()); |
| 163 | EXPECT_EQ(icon->height(), actual_icon->height()); |
[email protected] | d20d043 | 2014-06-12 17:14:05 | [diff] [blame] | 164 | EXPECT_EQ(i == 3, GetCache()->ProfileIsSupervisedAtIndex(i)); |
[email protected] | 5ddfade | 2014-02-03 10:24:53 | [diff] [blame] | 165 | EXPECT_EQ(i == 3, GetCache()->IsOmittedProfileAtIndex(i)); |
[email protected] | d20d043 | 2014-06-12 17:14:05 | [diff] [blame] | 166 | EXPECT_EQ(supervised_user_id, |
| 167 | GetCache()->GetSupervisedUserIdOfProfileAtIndex(i)); |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 168 | } |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 169 | |
| 170 | // Reset the cache and test the it reloads correctly. |
| 171 | ResetCache(); |
| 172 | |
| 173 | EXPECT_EQ(4u, GetCache()->GetNumberOfProfiles()); |
avi | b896c71 | 2015-12-26 02:10:43 | [diff] [blame] | 174 | for (uint32_t i = 0; i < 4; ++i) { |
[email protected] | 7d3cbc9 | 2013-03-18 22:33:04 | [diff] [blame] | 175 | base::FilePath profile_path = |
| 176 | GetProfilePath(base::StringPrintf("path_%ud", i)); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 177 | EXPECT_EQ(i, GetCache()->GetIndexOfProfileWithPath(profile_path)); |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 178 | base::string16 profile_name = |
| 179 | ASCIIToUTF16(base::StringPrintf("name_%ud", i)); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 180 | EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(i)); |
| 181 | EXPECT_EQ(i, GetCache()->GetAvatarIconIndexOfProfileAtIndex(i)); |
| 182 | EXPECT_EQ(true, GetCache()->GetBackgroundStatusOfProfileAtIndex(i)); |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 183 | base::string16 gaia_name = ASCIIToUTF16(base::StringPrintf("gaia_%ud", i)); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 184 | EXPECT_EQ(gaia_name, GetCache()->GetGAIANameOfProfileAtIndex(i)); |
| 185 | } |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 186 | } |
| 187 | |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 188 | TEST_F(ProfileInfoCacheTest, DeleteProfile) { |
[email protected] | 6730b1e | 2011-09-29 05:23:52 | [diff] [blame] | 189 | EXPECT_EQ(0u, GetCache()->GetNumberOfProfiles()); |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 190 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 191 | base::FilePath path_1 = GetProfilePath("path_1"); |
Roman Sorokin | 8ead4d7 | 2018-04-16 15:58:58 | [diff] [blame] | 192 | GetCache()->AddProfileToCache(path_1, ASCIIToUTF16("name_1"), std::string(), |
| 193 | base::string16(), 0, std::string(), |
| 194 | EmptyAccountId()); |
[email protected] | 6730b1e | 2011-09-29 05:23:52 | [diff] [blame] | 195 | EXPECT_EQ(1u, GetCache()->GetNumberOfProfiles()); |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 196 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 197 | base::FilePath path_2 = GetProfilePath("path_2"); |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 198 | base::string16 name_2 = ASCIIToUTF16("name_2"); |
rogerta | e2265960 | 2015-05-11 21:58:21 | [diff] [blame] | 199 | GetCache()->AddProfileToCache(path_2, name_2, std::string(), base::string16(), |
Roman Sorokin | 8ead4d7 | 2018-04-16 15:58:58 | [diff] [blame] | 200 | 0, std::string(), EmptyAccountId()); |
[email protected] | 6730b1e | 2011-09-29 05:23:52 | [diff] [blame] | 201 | EXPECT_EQ(2u, GetCache()->GetNumberOfProfiles()); |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 202 | |
[email protected] | 6730b1e | 2011-09-29 05:23:52 | [diff] [blame] | 203 | GetCache()->DeleteProfileFromCache(path_1); |
| 204 | EXPECT_EQ(1u, GetCache()->GetNumberOfProfiles()); |
| 205 | EXPECT_EQ(name_2, GetCache()->GetNameOfProfileAtIndex(0)); |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 206 | |
[email protected] | 6730b1e | 2011-09-29 05:23:52 | [diff] [blame] | 207 | GetCache()->DeleteProfileFromCache(path_2); |
| 208 | EXPECT_EQ(0u, GetCache()->GetNumberOfProfiles()); |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 209 | } |
| 210 | |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 211 | TEST_F(ProfileInfoCacheTest, MutateProfile) { |
| 212 | GetCache()->AddProfileToCache( |
rogerta | e2265960 | 2015-05-11 21:58:21 | [diff] [blame] | 213 | GetProfilePath("path_1"), ASCIIToUTF16("name_1"), std::string(), |
Roman Sorokin | 8ead4d7 | 2018-04-16 15:58:58 | [diff] [blame] | 214 | base::string16(), 0, std::string(), EmptyAccountId()); |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 215 | GetCache()->AddProfileToCache( |
rogerta | e2265960 | 2015-05-11 21:58:21 | [diff] [blame] | 216 | GetProfilePath("path_2"), ASCIIToUTF16("name_2"), std::string(), |
Roman Sorokin | 8ead4d7 | 2018-04-16 15:58:58 | [diff] [blame] | 217 | base::string16(), 0, std::string(), EmptyAccountId()); |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 218 | |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 219 | base::string16 new_name = ASCIIToUTF16("new_name"); |
[email protected] | 6730b1e | 2011-09-29 05:23:52 | [diff] [blame] | 220 | GetCache()->SetNameOfProfileAtIndex(1, new_name); |
| 221 | EXPECT_EQ(new_name, GetCache()->GetNameOfProfileAtIndex(1)); |
| 222 | EXPECT_NE(new_name, GetCache()->GetNameOfProfileAtIndex(0)); |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 223 | |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 224 | base::string16 new_user_name = ASCIIToUTF16("user_name"); |
rogerta | e2265960 | 2015-05-11 21:58:21 | [diff] [blame] | 225 | std::string new_gaia_id = "12345"; |
| 226 | GetCache()->SetAuthInfoOfProfileAtIndex(1, new_gaia_id, new_user_name); |
[email protected] | e8e7809 | 2011-09-29 18:15:38 | [diff] [blame] | 227 | EXPECT_EQ(new_user_name, GetCache()->GetUserNameOfProfileAtIndex(1)); |
rogerta | e2265960 | 2015-05-11 21:58:21 | [diff] [blame] | 228 | EXPECT_EQ(new_gaia_id, GetCache()->GetGAIAIdOfProfileAtIndex(1)); |
[email protected] | e8e7809 | 2011-09-29 18:15:38 | [diff] [blame] | 229 | EXPECT_NE(new_user_name, GetCache()->GetUserNameOfProfileAtIndex(0)); |
| 230 | |
lixan | 20fabcc | 2017-01-31 16:03:02 | [diff] [blame] | 231 | const size_t new_icon_index = 3; |
[email protected] | 6730b1e | 2011-09-29 05:23:52 | [diff] [blame] | 232 | GetCache()->SetAvatarIconOfProfileAtIndex(1, new_icon_index); |
lixan | 20fabcc | 2017-01-31 16:03:02 | [diff] [blame] | 233 | EXPECT_EQ(new_icon_index, GetCache()->GetAvatarIconIndexOfProfileAtIndex(1)); |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 234 | // Not much to test. |
[email protected] | 6730b1e | 2011-09-29 05:23:52 | [diff] [blame] | 235 | GetCache()->GetAvatarIconOfProfileAtIndex(1); |
lixan | 20fabcc | 2017-01-31 16:03:02 | [diff] [blame] | 236 | |
| 237 | const size_t wrong_icon_index = profiles::GetDefaultAvatarIconCount() + 1; |
| 238 | const size_t generic_icon_index = 0; |
| 239 | GetCache()->SetAvatarIconOfProfileAtIndex(1, wrong_icon_index); |
| 240 | EXPECT_EQ(generic_icon_index, |
| 241 | GetCache()->GetAvatarIconIndexOfProfileAtIndex(1)); |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 242 | } |
| 243 | |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 244 | TEST_F(ProfileInfoCacheTest, Sort) { |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 245 | base::string16 name_a = ASCIIToUTF16("apple"); |
Roman Sorokin | 8ead4d7 | 2018-04-16 15:58:58 | [diff] [blame] | 246 | GetCache()->AddProfileToCache(GetProfilePath("path_a"), name_a, std::string(), |
| 247 | base::string16(), 0, std::string(), |
| 248 | EmptyAccountId()); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 249 | |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 250 | base::string16 name_c = ASCIIToUTF16("cat"); |
Roman Sorokin | 8ead4d7 | 2018-04-16 15:58:58 | [diff] [blame] | 251 | GetCache()->AddProfileToCache(GetProfilePath("path_c"), name_c, std::string(), |
| 252 | base::string16(), 0, std::string(), |
| 253 | EmptyAccountId()); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 254 | |
| 255 | // Sanity check the initial order. |
| 256 | EXPECT_EQ(name_a, GetCache()->GetNameOfProfileAtIndex(0)); |
| 257 | EXPECT_EQ(name_c, GetCache()->GetNameOfProfileAtIndex(1)); |
| 258 | |
| 259 | // Add a new profile (start with a capital to test case insensitive sorting. |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 260 | base::string16 name_b = ASCIIToUTF16("Banana"); |
Roman Sorokin | 8ead4d7 | 2018-04-16 15:58:58 | [diff] [blame] | 261 | GetCache()->AddProfileToCache(GetProfilePath("path_b"), name_b, std::string(), |
| 262 | base::string16(), 0, std::string(), |
| 263 | EmptyAccountId()); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 264 | |
| 265 | // Verify the new order. |
| 266 | EXPECT_EQ(name_a, GetCache()->GetNameOfProfileAtIndex(0)); |
| 267 | EXPECT_EQ(name_b, GetCache()->GetNameOfProfileAtIndex(1)); |
| 268 | EXPECT_EQ(name_c, GetCache()->GetNameOfProfileAtIndex(2)); |
| 269 | |
| 270 | // Change the name of an existing profile. |
| 271 | name_a = UTF8ToUTF16("dog"); |
| 272 | GetCache()->SetNameOfProfileAtIndex(0, name_a); |
| 273 | |
| 274 | // Verify the new order. |
| 275 | EXPECT_EQ(name_b, GetCache()->GetNameOfProfileAtIndex(0)); |
| 276 | EXPECT_EQ(name_c, GetCache()->GetNameOfProfileAtIndex(1)); |
| 277 | EXPECT_EQ(name_a, GetCache()->GetNameOfProfileAtIndex(2)); |
| 278 | |
| 279 | // Delete a profile. |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 280 | GetCache()->DeleteProfileFromCache(GetProfilePath("path_c")); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 281 | |
| 282 | // Verify the new order. |
| 283 | EXPECT_EQ(name_b, GetCache()->GetNameOfProfileAtIndex(0)); |
| 284 | EXPECT_EQ(name_a, GetCache()->GetNameOfProfileAtIndex(1)); |
| 285 | } |
| 286 | |
WC Leung | 1775638 | 2017-08-25 04:57:36 | [diff] [blame] | 287 | // Will be removed SOON with ProfileInfoCache tests. |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 288 | TEST_F(ProfileInfoCacheTest, BackgroundModeStatus) { |
[email protected] | 27917083 | 2011-10-12 23:38:03 | [diff] [blame] | 289 | GetCache()->AddProfileToCache( |
Roman Sorokin | 8ead4d7 | 2018-04-16 15:58:58 | [diff] [blame] | 290 | GetProfilePath("path_1"), ASCIIToUTF16("name_1"), std::string(), |
| 291 | base::string16(), 0, std::string(), EmptyAccountId()); |
[email protected] | 27917083 | 2011-10-12 23:38:03 | [diff] [blame] | 292 | GetCache()->AddProfileToCache( |
Roman Sorokin | 8ead4d7 | 2018-04-16 15:58:58 | [diff] [blame] | 293 | GetProfilePath("path_2"), ASCIIToUTF16("name_2"), std::string(), |
| 294 | base::string16(), 0, std::string(), EmptyAccountId()); |
[email protected] | 27917083 | 2011-10-12 23:38:03 | [diff] [blame] | 295 | |
| 296 | EXPECT_FALSE(GetCache()->GetBackgroundStatusOfProfileAtIndex(0)); |
| 297 | EXPECT_FALSE(GetCache()->GetBackgroundStatusOfProfileAtIndex(1)); |
| 298 | |
| 299 | GetCache()->SetBackgroundStatusOfProfileAtIndex(1, true); |
| 300 | |
| 301 | EXPECT_FALSE(GetCache()->GetBackgroundStatusOfProfileAtIndex(0)); |
| 302 | EXPECT_TRUE(GetCache()->GetBackgroundStatusOfProfileAtIndex(1)); |
| 303 | |
| 304 | GetCache()->SetBackgroundStatusOfProfileAtIndex(0, true); |
| 305 | |
| 306 | EXPECT_TRUE(GetCache()->GetBackgroundStatusOfProfileAtIndex(0)); |
| 307 | EXPECT_TRUE(GetCache()->GetBackgroundStatusOfProfileAtIndex(1)); |
| 308 | |
| 309 | GetCache()->SetBackgroundStatusOfProfileAtIndex(1, false); |
| 310 | |
| 311 | EXPECT_TRUE(GetCache()->GetBackgroundStatusOfProfileAtIndex(0)); |
| 312 | EXPECT_FALSE(GetCache()->GetBackgroundStatusOfProfileAtIndex(1)); |
| 313 | } |
| 314 | |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 315 | TEST_F(ProfileInfoCacheTest, GAIAName) { |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 316 | GetCache()->AddProfileToCache( |
Roman Sorokin | 8ead4d7 | 2018-04-16 15:58:58 | [diff] [blame] | 317 | GetProfilePath("path_1"), ASCIIToUTF16("Person 1"), std::string(), |
| 318 | base::string16(), 0, std::string(), EmptyAccountId()); |
[email protected] | a4352d0 | 2014-03-06 06:00:27 | [diff] [blame] | 319 | base::string16 profile_name(ASCIIToUTF16("Person 2")); |
Roman Sorokin | 8ead4d7 | 2018-04-16 15:58:58 | [diff] [blame] | 320 | GetCache()->AddProfileToCache(GetProfilePath("path_2"), profile_name, |
| 321 | std::string(), base::string16(), 0, |
| 322 | std::string(), EmptyAccountId()); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 323 | |
[email protected] | a4352d0 | 2014-03-06 06:00:27 | [diff] [blame] | 324 | int index1 = GetCache()->GetIndexOfProfileWithPath(GetProfilePath("path_1")); |
| 325 | int index2 = GetCache()->GetIndexOfProfileWithPath(GetProfilePath("path_2")); |
| 326 | |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 327 | // Sanity check. |
[email protected] | a4352d0 | 2014-03-06 06:00:27 | [diff] [blame] | 328 | EXPECT_TRUE(GetCache()->GetGAIANameOfProfileAtIndex(index1).empty()); |
| 329 | EXPECT_TRUE(GetCache()->GetGAIANameOfProfileAtIndex(index2).empty()); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 330 | |
[email protected] | 425d6ab | 2014-03-25 05:59:39 | [diff] [blame] | 331 | // Set GAIA name. This re-sorts the cache. |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 332 | base::string16 gaia_name(ASCIIToUTF16("Pat Smith")); |
[email protected] | a4352d0 | 2014-03-06 06:00:27 | [diff] [blame] | 333 | GetCache()->SetGAIANameOfProfileAtIndex(index2, gaia_name); |
[email protected] | 425d6ab | 2014-03-25 05:59:39 | [diff] [blame] | 334 | index1 = GetCache()->GetIndexOfProfileWithPath(GetProfilePath("path_1")); |
| 335 | index2 = GetCache()->GetIndexOfProfileWithPath(GetProfilePath("path_2")); |
| 336 | |
| 337 | // Since there is a GAIA name, we use that as a display name. |
[email protected] | a4352d0 | 2014-03-06 06:00:27 | [diff] [blame] | 338 | EXPECT_TRUE(GetCache()->GetGAIANameOfProfileAtIndex(index1).empty()); |
| 339 | EXPECT_EQ(gaia_name, GetCache()->GetGAIANameOfProfileAtIndex(index2)); |
[email protected] | a4352d0 | 2014-03-06 06:00:27 | [diff] [blame] | 340 | EXPECT_EQ(gaia_name, GetCache()->GetNameOfProfileAtIndex(index2)); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 341 | |
[email protected] | a4352d0 | 2014-03-06 06:00:27 | [diff] [blame] | 342 | // Don't use GAIA name as profile name. This re-sorts the cache. |
[email protected] | 425d6ab | 2014-03-25 05:59:39 | [diff] [blame] | 343 | base::string16 custom_name(ASCIIToUTF16("Custom name")); |
| 344 | GetCache()->SetNameOfProfileAtIndex(index2, custom_name); |
[email protected] | 1cdf093 | 2014-08-16 06:00:49 | [diff] [blame] | 345 | GetCache()->SetProfileIsUsingDefaultNameAtIndex(index2, false); |
| 346 | |
[email protected] | a4352d0 | 2014-03-06 06:00:27 | [diff] [blame] | 347 | index1 = GetCache()->GetIndexOfProfileWithPath(GetProfilePath("path_1")); |
| 348 | index2 = GetCache()->GetIndexOfProfileWithPath(GetProfilePath("path_2")); |
| 349 | |
[email protected] | 425d6ab | 2014-03-25 05:59:39 | [diff] [blame] | 350 | EXPECT_EQ(custom_name, GetCache()->GetNameOfProfileAtIndex(index2)); |
[email protected] | a4352d0 | 2014-03-06 06:00:27 | [diff] [blame] | 351 | EXPECT_EQ(gaia_name, GetCache()->GetGAIANameOfProfileAtIndex(index2)); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 352 | } |
| 353 | |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 354 | TEST_F(ProfileInfoCacheTest, GAIAPicture) { |
[email protected] | 2290090 | 2014-07-30 11:50:41 | [diff] [blame] | 355 | const int kDefaultAvatarIndex = 0; |
| 356 | const int kOtherAvatarIndex = 1; |
[email protected] | 979dc4f | 2014-08-12 22:52:11 | [diff] [blame] | 357 | const int kGaiaPictureSize = 256; // Standard size of a Gaia account picture. |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 358 | GetCache()->AddProfileToCache( |
Roman Sorokin | 8ead4d7 | 2018-04-16 15:58:58 | [diff] [blame] | 359 | GetProfilePath("path_1"), ASCIIToUTF16("name_1"), std::string(), |
| 360 | base::string16(), kDefaultAvatarIndex, std::string(), EmptyAccountId()); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 361 | GetCache()->AddProfileToCache( |
Roman Sorokin | 8ead4d7 | 2018-04-16 15:58:58 | [diff] [blame] | 362 | GetProfilePath("path_2"), ASCIIToUTF16("name_2"), std::string(), |
| 363 | base::string16(), kDefaultAvatarIndex, std::string(), EmptyAccountId()); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 364 | |
| 365 | // Sanity check. |
[email protected] | 2f3c00f | 2011-11-30 04:36:22 | [diff] [blame] | 366 | EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(0)); |
| 367 | EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(1)); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 368 | EXPECT_FALSE(GetCache()->IsUsingGAIAPictureOfProfileAtIndex(0)); |
| 369 | EXPECT_FALSE(GetCache()->IsUsingGAIAPictureOfProfileAtIndex(1)); |
| 370 | |
| 371 | // The profile icon should be the default one. |
[email protected] | 2290090 | 2014-07-30 11:50:41 | [diff] [blame] | 372 | EXPECT_TRUE(GetCache()->ProfileIsUsingDefaultAvatarAtIndex(0)); |
| 373 | EXPECT_TRUE(GetCache()->ProfileIsUsingDefaultAvatarAtIndex(1)); |
| 374 | int default_avatar_id = |
| 375 | profiles::GetDefaultAvatarIconResourceIDAtIndex(kDefaultAvatarIndex); |
| 376 | const gfx::Image& default_avatar_image( |
Lei Zhang | 7640d54 | 2017-10-03 16:26:49 | [diff] [blame] | 377 | ui::ResourceBundle::GetSharedInstance().GetImageNamed(default_avatar_id)); |
pkotwicz | b312b51 | 2015-09-29 23:44:43 | [diff] [blame] | 378 | EXPECT_TRUE(gfx::test::AreImagesEqual( |
[email protected] | 2290090 | 2014-07-30 11:50:41 | [diff] [blame] | 379 | default_avatar_image, GetCache()->GetAvatarIconOfProfileAtIndex(1))); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 380 | |
| 381 | // Set GAIA picture. |
[email protected] | 979dc4f | 2014-08-12 22:52:11 | [diff] [blame] | 382 | gfx::Image gaia_image(gfx::test::CreateImage( |
| 383 | kGaiaPictureSize, kGaiaPictureSize)); |
[email protected] | 2f3c00f | 2011-11-30 04:36:22 | [diff] [blame] | 384 | GetCache()->SetGAIAPictureOfProfileAtIndex(1, &gaia_image); |
| 385 | EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(0)); |
pkotwicz | b312b51 | 2015-09-29 23:44:43 | [diff] [blame] | 386 | EXPECT_TRUE(gfx::test::AreImagesEqual( |
[email protected] | 2f3c00f | 2011-11-30 04:36:22 | [diff] [blame] | 387 | gaia_image, *GetCache()->GetGAIAPictureOfProfileAtIndex(1))); |
[email protected] | 2290090 | 2014-07-30 11:50:41 | [diff] [blame] | 388 | // Since we're still using the default avatar, the GAIA image should be |
| 389 | // preferred over the generic avatar image. |
| 390 | EXPECT_TRUE(GetCache()->ProfileIsUsingDefaultAvatarAtIndex(1)); |
| 391 | EXPECT_TRUE(GetCache()->IsUsingGAIAPictureOfProfileAtIndex(1)); |
pkotwicz | b312b51 | 2015-09-29 23:44:43 | [diff] [blame] | 392 | EXPECT_TRUE(gfx::test::AreImagesEqual( |
[email protected] | 2290090 | 2014-07-30 11:50:41 | [diff] [blame] | 393 | gaia_image, GetCache()->GetAvatarIconOfProfileAtIndex(1))); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 394 | |
[email protected] | 1cdf093 | 2014-08-16 06:00:49 | [diff] [blame] | 395 | // Set a non-default avatar. This should be preferred over the GAIA image. |
[email protected] | 2290090 | 2014-07-30 11:50:41 | [diff] [blame] | 396 | GetCache()->SetAvatarIconOfProfileAtIndex(1, kOtherAvatarIndex); |
[email protected] | 1cdf093 | 2014-08-16 06:00:49 | [diff] [blame] | 397 | GetCache()->SetProfileIsUsingDefaultAvatarAtIndex(1, false); |
[email protected] | 2290090 | 2014-07-30 11:50:41 | [diff] [blame] | 398 | EXPECT_FALSE(GetCache()->ProfileIsUsingDefaultAvatarAtIndex(1)); |
| 399 | EXPECT_FALSE(GetCache()->IsUsingGAIAPictureOfProfileAtIndex(1)); |
| 400 | int other_avatar_id = |
| 401 | profiles::GetDefaultAvatarIconResourceIDAtIndex(kOtherAvatarIndex); |
| 402 | const gfx::Image& other_avatar_image( |
Lei Zhang | 7640d54 | 2017-10-03 16:26:49 | [diff] [blame] | 403 | ui::ResourceBundle::GetSharedInstance().GetImageNamed(other_avatar_id)); |
pkotwicz | b312b51 | 2015-09-29 23:44:43 | [diff] [blame] | 404 | EXPECT_TRUE(gfx::test::AreImagesEqual( |
[email protected] | 2290090 | 2014-07-30 11:50:41 | [diff] [blame] | 405 | other_avatar_image, GetCache()->GetAvatarIconOfProfileAtIndex(1))); |
| 406 | |
| 407 | // Explicitly setting the GAIA picture should make it preferred again. |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 408 | GetCache()->SetIsUsingGAIAPictureOfProfileAtIndex(1, true); |
[email protected] | 2290090 | 2014-07-30 11:50:41 | [diff] [blame] | 409 | EXPECT_TRUE(GetCache()->IsUsingGAIAPictureOfProfileAtIndex(1)); |
pkotwicz | b312b51 | 2015-09-29 23:44:43 | [diff] [blame] | 410 | EXPECT_TRUE(gfx::test::AreImagesEqual( |
[email protected] | 2f3c00f | 2011-11-30 04:36:22 | [diff] [blame] | 411 | gaia_image, *GetCache()->GetGAIAPictureOfProfileAtIndex(1))); |
pkotwicz | b312b51 | 2015-09-29 23:44:43 | [diff] [blame] | 412 | EXPECT_TRUE(gfx::test::AreImagesEqual( |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 413 | gaia_image, GetCache()->GetAvatarIconOfProfileAtIndex(1))); |
| 414 | |
[email protected] | 2290090 | 2014-07-30 11:50:41 | [diff] [blame] | 415 | // Clearing the IsUsingGAIAPicture flag should result in the generic image |
| 416 | // being used again. |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 417 | GetCache()->SetIsUsingGAIAPictureOfProfileAtIndex(1, false); |
[email protected] | 2290090 | 2014-07-30 11:50:41 | [diff] [blame] | 418 | EXPECT_FALSE(GetCache()->IsUsingGAIAPictureOfProfileAtIndex(1)); |
pkotwicz | b312b51 | 2015-09-29 23:44:43 | [diff] [blame] | 419 | EXPECT_TRUE(gfx::test::AreImagesEqual( |
[email protected] | 2f3c00f | 2011-11-30 04:36:22 | [diff] [blame] | 420 | gaia_image, *GetCache()->GetGAIAPictureOfProfileAtIndex(1))); |
pkotwicz | b312b51 | 2015-09-29 23:44:43 | [diff] [blame] | 421 | EXPECT_TRUE(gfx::test::AreImagesEqual( |
[email protected] | 2290090 | 2014-07-30 11:50:41 | [diff] [blame] | 422 | other_avatar_image, GetCache()->GetAvatarIconOfProfileAtIndex(1))); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 423 | } |
| 424 | |
[email protected] | 754bebc | 2011-12-01 16:42:16 | [diff] [blame] | 425 | TEST_F(ProfileInfoCacheTest, PersistGAIAPicture) { |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 426 | GetCache()->AddProfileToCache( |
Roman Sorokin | 8ead4d7 | 2018-04-16 15:58:58 | [diff] [blame] | 427 | GetProfilePath("path_1"), ASCIIToUTF16("name_1"), std::string(), |
| 428 | base::string16(), 0, std::string(), EmptyAccountId()); |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 429 | gfx::Image gaia_image(gfx::test::CreateImage()); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 430 | |
[email protected] | 2f3c00f | 2011-11-30 04:36:22 | [diff] [blame] | 431 | GetCache()->SetGAIAPictureOfProfileAtIndex(0, &gaia_image); |
noms | 75ca019 | 2015-02-26 03:14:30 | [diff] [blame] | 432 | |
| 433 | // Make sure everything has completed, and the file has been written to disk. |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 434 | content::RunAllTasksUntilIdle(); |
noms | 75ca019 | 2015-02-26 03:14:30 | [diff] [blame] | 435 | |
pkotwicz | b312b51 | 2015-09-29 23:44:43 | [diff] [blame] | 436 | EXPECT_TRUE(gfx::test::AreImagesEqual( |
[email protected] | 2f3c00f | 2011-11-30 04:36:22 | [diff] [blame] | 437 | gaia_image, *GetCache()->GetGAIAPictureOfProfileAtIndex(0))); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 438 | |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 439 | ResetCache(); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 440 | // Try to get the GAIA picture. This should return NULL until the read from |
| 441 | // disk is done. |
[email protected] | 2f3c00f | 2011-11-30 04:36:22 | [diff] [blame] | 442 | EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(0)); |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 443 | content::RunAllTasksUntilIdle(); |
noms | 75ca019 | 2015-02-26 03:14:30 | [diff] [blame] | 444 | |
pkotwicz | b312b51 | 2015-09-29 23:44:43 | [diff] [blame] | 445 | EXPECT_TRUE(gfx::test::AreImagesEqual( |
[email protected] | 2f3c00f | 2011-11-30 04:36:22 | [diff] [blame] | 446 | gaia_image, *GetCache()->GetGAIAPictureOfProfileAtIndex(0))); |
| 447 | } |
| 448 | |
Jochen Eisinger | d84bb42a | 2018-07-23 22:39:03 | [diff] [blame] | 449 | #if BUILDFLAG(ENABLE_SUPERVISED_USERS) |
[email protected] | d20d043 | 2014-06-12 17:14:05 | [diff] [blame] | 450 | TEST_F(ProfileInfoCacheTest, SetSupervisedUserId) { |
Roman Sorokin | 8ead4d7 | 2018-04-16 15:58:58 | [diff] [blame] | 451 | GetCache()->AddProfileToCache(GetProfilePath("test"), ASCIIToUTF16("Test"), |
| 452 | std::string(), base::string16(), 0, |
| 453 | std::string(), EmptyAccountId()); |
[email protected] | d20d043 | 2014-06-12 17:14:05 | [diff] [blame] | 454 | EXPECT_FALSE(GetCache()->ProfileIsSupervisedAtIndex(0)); |
[email protected] | 0aa018a | 2013-07-31 15:08:54 | [diff] [blame] | 455 | |
Jochen Eisinger | d84bb42a | 2018-07-23 22:39:03 | [diff] [blame] | 456 | GetCache()->SetSupervisedUserIdOfProfileAtIndex( |
| 457 | 0, supervised_users::kChildAccountSUID); |
[email protected] | d20d043 | 2014-06-12 17:14:05 | [diff] [blame] | 458 | EXPECT_TRUE(GetCache()->ProfileIsSupervisedAtIndex(0)); |
Jochen Eisinger | d84bb42a | 2018-07-23 22:39:03 | [diff] [blame] | 459 | EXPECT_EQ(supervised_users::kChildAccountSUID, |
| 460 | GetCache()->GetSupervisedUserIdOfProfileAtIndex(0)); |
[email protected] | 0aa018a | 2013-07-31 15:08:54 | [diff] [blame] | 461 | |
| 462 | ResetCache(); |
[email protected] | d20d043 | 2014-06-12 17:14:05 | [diff] [blame] | 463 | EXPECT_TRUE(GetCache()->ProfileIsSupervisedAtIndex(0)); |
[email protected] | 0aa018a | 2013-07-31 15:08:54 | [diff] [blame] | 464 | |
[email protected] | d20d043 | 2014-06-12 17:14:05 | [diff] [blame] | 465 | GetCache()->SetSupervisedUserIdOfProfileAtIndex(0, std::string()); |
| 466 | EXPECT_FALSE(GetCache()->ProfileIsSupervisedAtIndex(0)); |
| 467 | EXPECT_EQ("", GetCache()->GetSupervisedUserIdOfProfileAtIndex(0)); |
[email protected] | 0aa018a | 2013-07-31 15:08:54 | [diff] [blame] | 468 | } |
Jochen Eisinger | d84bb42a | 2018-07-23 22:39:03 | [diff] [blame] | 469 | #endif // BUILDFLAG(ENABLE_SUPERVISED_USERS) |
[email protected] | 0aa018a | 2013-07-31 15:08:54 | [diff] [blame] | 470 | |
[email protected] | 2f3c00f | 2011-11-30 04:36:22 | [diff] [blame] | 471 | TEST_F(ProfileInfoCacheTest, EmptyGAIAInfo) { |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 472 | base::string16 profile_name = ASCIIToUTF16("name_1"); |
[email protected] | c3e55977 | 2014-04-09 04:02:54 | [diff] [blame] | 473 | int id = profiles::GetDefaultAvatarIconResourceIDAtIndex(0); |
[email protected] | 2f3c00f | 2011-11-30 04:36:22 | [diff] [blame] | 474 | const gfx::Image& profile_image( |
Lei Zhang | 7640d54 | 2017-10-03 16:26:49 | [diff] [blame] | 475 | ui::ResourceBundle::GetSharedInstance().GetImageNamed(id)); |
[email protected] | 2f3c00f | 2011-11-30 04:36:22 | [diff] [blame] | 476 | |
Roman Sorokin | 8ead4d7 | 2018-04-16 15:58:58 | [diff] [blame] | 477 | GetCache()->AddProfileToCache(GetProfilePath("path_1"), profile_name, |
| 478 | std::string(), base::string16(), 0, |
| 479 | std::string(), EmptyAccountId()); |
[email protected] | 2f3c00f | 2011-11-30 04:36:22 | [diff] [blame] | 480 | |
| 481 | // Set empty GAIA info. |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 482 | GetCache()->SetGAIANameOfProfileAtIndex(0, base::string16()); |
[email protected] | 2f3c00f | 2011-11-30 04:36:22 | [diff] [blame] | 483 | GetCache()->SetGAIAPictureOfProfileAtIndex(0, NULL); |
[email protected] | 2f3c00f | 2011-11-30 04:36:22 | [diff] [blame] | 484 | GetCache()->SetIsUsingGAIAPictureOfProfileAtIndex(0, true); |
| 485 | |
| 486 | // Verify that the profile name and picture are not empty. |
| 487 | EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(0)); |
pkotwicz | b312b51 | 2015-09-29 23:44:43 | [diff] [blame] | 488 | EXPECT_TRUE(gfx::test::AreImagesEqual( |
[email protected] | 2f3c00f | 2011-11-30 04:36:22 | [diff] [blame] | 489 | profile_image, GetCache()->GetAvatarIconOfProfileAtIndex(0))); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 490 | } |
| 491 | |
Jochen Eisinger | d84bb42a | 2018-07-23 22:39:03 | [diff] [blame] | 492 | #if BUILDFLAG(ENABLE_SUPERVISED_USERS) |
[email protected] | d20d043 | 2014-06-12 17:14:05 | [diff] [blame] | 493 | TEST_F(ProfileInfoCacheTest, CreateSupervisedTestingProfile) { |
[email protected] | 0aa018a | 2013-07-31 15:08:54 | [diff] [blame] | 494 | testing_profile_manager_.CreateTestingProfile("default"); |
[email protected] | d20d043 | 2014-06-12 17:14:05 | [diff] [blame] | 495 | base::string16 supervised_user_name = ASCIIToUTF16("Supervised User"); |
[email protected] | 0aa018a | 2013-07-31 15:08:54 | [diff] [blame] | 496 | testing_profile_manager_.CreateTestingProfile( |
maxbogue | ea16ff41 | 2016-10-28 16:35:29 | [diff] [blame] | 497 | "test1", std::unique_ptr<sync_preferences::PrefServiceSyncable>(), |
Jochen Eisinger | d84bb42a | 2018-07-23 22:39:03 | [diff] [blame] | 498 | supervised_user_name, 0, supervised_users::kChildAccountSUID, |
| 499 | TestingProfile::TestingFactories()); |
[email protected] | 0aa018a | 2013-07-31 15:08:54 | [diff] [blame] | 500 | for (size_t i = 0; i < GetCache()->GetNumberOfProfiles(); i++) { |
[email protected] | d20d043 | 2014-06-12 17:14:05 | [diff] [blame] | 501 | bool is_supervised = |
| 502 | GetCache()->GetNameOfProfileAtIndex(i) == supervised_user_name; |
| 503 | EXPECT_EQ(is_supervised, GetCache()->ProfileIsSupervisedAtIndex(i)); |
Jochen Eisinger | d84bb42a | 2018-07-23 22:39:03 | [diff] [blame] | 504 | std::string supervised_user_id = |
| 505 | is_supervised ? supervised_users::kChildAccountSUID : ""; |
[email protected] | d20d043 | 2014-06-12 17:14:05 | [diff] [blame] | 506 | EXPECT_EQ(supervised_user_id, |
| 507 | GetCache()->GetSupervisedUserIdOfProfileAtIndex(i)); |
[email protected] | 0aa018a | 2013-07-31 15:08:54 | [diff] [blame] | 508 | } |
[email protected] | 371662e37 | 2013-10-17 22:05:22 | [diff] [blame] | 509 | |
[email protected] | d20d043 | 2014-06-12 17:14:05 | [diff] [blame] | 510 | // Supervised profiles have a custom theme, which needs to be deleted on the |
| 511 | // FILE thread. Reset the profile manager now so everything is deleted while |
| 512 | // we still have a FILE thread. |
[email protected] | 371662e37 | 2013-10-17 22:05:22 | [diff] [blame] | 513 | TestingBrowserProcess::GetGlobal()->SetProfileManager(NULL); |
[email protected] | 0aa018a | 2013-07-31 15:08:54 | [diff] [blame] | 514 | } |
Jochen Eisinger | d84bb42a | 2018-07-23 22:39:03 | [diff] [blame] | 515 | #endif |
[email protected] | 0aa018a | 2013-07-31 15:08:54 | [diff] [blame] | 516 | |
[email protected] | 04748180 | 2013-09-16 22:26:38 | [diff] [blame] | 517 | TEST_F(ProfileInfoCacheTest, AddStubProfile) { |
| 518 | EXPECT_EQ(0u, GetCache()->GetNumberOfProfiles()); |
| 519 | |
| 520 | // Add some profiles with and without a '.' in their paths. |
| 521 | const struct { |
| 522 | const char* profile_path; |
| 523 | const char* profile_name; |
| 524 | } kTestCases[] = { |
| 525 | { "path.test0", "name_0" }, |
| 526 | { "path_test1", "name_1" }, |
| 527 | { "path.test2", "name_2" }, |
| 528 | { "path_test3", "name_3" }, |
| 529 | }; |
| 530 | |
viettrungluu | 9e65ad1 | 2014-10-16 04:22:26 | [diff] [blame] | 531 | for (size_t i = 0; i < arraysize(kTestCases); ++i) { |
[email protected] | 04748180 | 2013-09-16 22:26:38 | [diff] [blame] | 532 | base::FilePath profile_path = GetProfilePath(kTestCases[i].profile_path); |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 533 | base::string16 profile_name = ASCIIToUTF16(kTestCases[i].profile_name); |
[email protected] | 04748180 | 2013-09-16 22:26:38 | [diff] [blame] | 534 | |
rogerta | e2265960 | 2015-05-11 21:58:21 | [diff] [blame] | 535 | GetCache()->AddProfileToCache(profile_path, profile_name, std::string(), |
Roman Sorokin | 8ead4d7 | 2018-04-16 15:58:58 | [diff] [blame] | 536 | base::string16(), i, "", EmptyAccountId()); |
[email protected] | 04748180 | 2013-09-16 22:26:38 | [diff] [blame] | 537 | |
| 538 | EXPECT_EQ(profile_path, GetCache()->GetPathOfProfileAtIndex(i)); |
| 539 | EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(i)); |
| 540 | } |
| 541 | |
| 542 | ASSERT_EQ(4U, GetCache()->GetNumberOfProfiles()); |
| 543 | |
| 544 | // Check that the profiles can be extracted from the local state. |
noms | 693f35aa | 2015-02-05 16:03:16 | [diff] [blame] | 545 | std::vector<base::string16> names; |
| 546 | PrefService* local_state = g_browser_process->local_state(); |
| 547 | const base::DictionaryValue* cache = local_state->GetDictionary( |
| 548 | prefs::kProfileInfoCache); |
| 549 | base::string16 name; |
| 550 | for (base::DictionaryValue::Iterator it(*cache); !it.IsAtEnd(); |
| 551 | it.Advance()) { |
| 552 | const base::DictionaryValue* info = NULL; |
| 553 | it.value().GetAsDictionary(&info); |
| 554 | info->GetString("name", &name); |
| 555 | names.push_back(name); |
| 556 | } |
| 557 | |
[email protected] | 04748180 | 2013-09-16 22:26:38 | [diff] [blame] | 558 | for (size_t i = 0; i < 4; i++) |
| 559 | ASSERT_FALSE(names[i].empty()); |
| 560 | } |
| 561 | |
lwchkg | 778965f | 2016-05-12 13:14:22 | [diff] [blame] | 562 | TEST_F(ProfileInfoCacheTest, EntriesInAttributesStorage) { |
| 563 | EXPECT_EQ(0u, GetCache()->GetNumberOfProfiles()); |
| 564 | |
| 565 | // Add some profiles with and without a '.' in their paths. |
| 566 | const struct { |
| 567 | const char* profile_path; |
| 568 | const char* profile_name; |
| 569 | } kTestCases[] = { |
| 570 | { "path.test0", "name_0" }, |
| 571 | { "path_test1", "name_1" }, |
| 572 | { "path.test2", "name_2" }, |
| 573 | { "path_test3", "name_3" }, |
| 574 | }; |
| 575 | |
| 576 | // Profiles are added and removed using all combinations of the old and the |
| 577 | // new interfaces. The content of |profile_attributes_entries_| in |
| 578 | // ProfileAttributesStorage is checked after each insert and delete operation. |
| 579 | |
| 580 | // Add profiles. |
| 581 | for (size_t i = 0; i < arraysize(kTestCases); ++i) { |
| 582 | base::FilePath profile_path = GetProfilePath(kTestCases[i].profile_path); |
| 583 | base::string16 profile_name = ASCIIToUTF16(kTestCases[i].profile_name); |
| 584 | |
| 585 | ASSERT_EQ(0u, GetCache()->profile_attributes_entries_.count( |
| 586 | profile_path.value())); |
| 587 | |
| 588 | // Use ProfileInfoCache in profiles 0 and 2, and ProfileAttributesStorage in |
| 589 | // profiles 1 and 3. |
| 590 | if (i | 1u) { |
| 591 | GetCache()->AddProfileToCache(profile_path, profile_name, std::string(), |
Roman Sorokin | 8ead4d7 | 2018-04-16 15:58:58 | [diff] [blame] | 592 | base::string16(), i, "", EmptyAccountId()); |
lwchkg | 778965f | 2016-05-12 13:14:22 | [diff] [blame] | 593 | } else { |
| 594 | GetCache()->AddProfile(profile_path, profile_name, std::string(), |
Roman Sorokin | 8ead4d7 | 2018-04-16 15:58:58 | [diff] [blame] | 595 | base::string16(), i, "", EmptyAccountId()); |
lwchkg | 778965f | 2016-05-12 13:14:22 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | ASSERT_EQ(i + 1, GetCache()->GetNumberOfProfiles()); |
| 599 | ASSERT_EQ(i + 1, GetCache()->profile_attributes_entries_.size()); |
| 600 | |
| 601 | ASSERT_EQ(1u, GetCache()->profile_attributes_entries_.count( |
| 602 | profile_path.value())); |
| 603 | // TODO(anthonyvd) : check that the entry in |profile_attributes_entries_| |
| 604 | // is null before GetProfileAttributesWithPath is run. Currently this is |
| 605 | // impossible to check because GetProfileAttributesWithPath is called during |
| 606 | // profile creation. |
| 607 | |
| 608 | ProfileAttributesEntry* entry = nullptr; |
| 609 | GetCache()->GetProfileAttributesWithPath(profile_path, &entry); |
| 610 | EXPECT_EQ( |
| 611 | entry, |
| 612 | GetCache()->profile_attributes_entries_[profile_path.value()].get()); |
| 613 | } |
| 614 | |
| 615 | // Remove profiles. |
| 616 | for (size_t i = 0; i < arraysize(kTestCases); ++i) { |
| 617 | base::FilePath profile_path = GetProfilePath(kTestCases[i].profile_path); |
| 618 | ASSERT_EQ(1u, GetCache()->profile_attributes_entries_.count( |
| 619 | profile_path.value())); |
| 620 | |
| 621 | // Use ProfileInfoCache in profiles 0 and 1, and ProfileAttributesStorage in |
| 622 | // profiles 2 and 3. |
| 623 | if (i | 2u) |
| 624 | GetCache()->DeleteProfileFromCache(profile_path); |
| 625 | else |
| 626 | GetCache()->RemoveProfile(profile_path); |
| 627 | |
| 628 | ASSERT_EQ(0u, GetCache()->profile_attributes_entries_.count( |
| 629 | profile_path.value())); |
| 630 | |
| 631 | ProfileAttributesEntry* entry = nullptr; |
| 632 | EXPECT_FALSE(GetCache()->GetProfileAttributesWithPath(profile_path, |
| 633 | &entry)); |
| 634 | ASSERT_EQ(0u, GetCache()->profile_attributes_entries_.count( |
| 635 | profile_path.value())); |
| 636 | } |
| 637 | } |
| 638 | |
jam | 1c5a9149 | 2016-02-24 20:47:53 | [diff] [blame] | 639 | #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) |
noms | be073e5 | 2014-08-23 22:01:04 | [diff] [blame] | 640 | TEST_F(ProfileInfoCacheTest, MigrateLegacyProfileNamesWithNewAvatarMenu) { |
noms | be073e5 | 2014-08-23 22:01:04 | [diff] [blame] | 641 | EXPECT_EQ(0U, GetCache()->GetNumberOfProfiles()); |
| 642 | |
| 643 | base::FilePath path_1 = GetProfilePath("path_1"); |
| 644 | GetCache()->AddProfileToCache(path_1, ASCIIToUTF16("Default Profile"), |
rogerta | e2265960 | 2015-05-11 21:58:21 | [diff] [blame] | 645 | std::string(), base::string16(), 0, |
Roman Sorokin | 8ead4d7 | 2018-04-16 15:58:58 | [diff] [blame] | 646 | std::string(), EmptyAccountId()); |
noms | be073e5 | 2014-08-23 22:01:04 | [diff] [blame] | 647 | base::FilePath path_2 = GetProfilePath("path_2"); |
| 648 | GetCache()->AddProfileToCache(path_2, ASCIIToUTF16("First user"), |
rogerta | e2265960 | 2015-05-11 21:58:21 | [diff] [blame] | 649 | std::string(), base::string16(), 1, |
Roman Sorokin | 8ead4d7 | 2018-04-16 15:58:58 | [diff] [blame] | 650 | std::string(), EmptyAccountId()); |
noms | be073e5 | 2014-08-23 22:01:04 | [diff] [blame] | 651 | base::string16 name_3 = ASCIIToUTF16("Lemonade"); |
| 652 | base::FilePath path_3 = GetProfilePath("path_3"); |
Roman Sorokin | 8ead4d7 | 2018-04-16 15:58:58 | [diff] [blame] | 653 | GetCache()->AddProfileToCache(path_3, name_3, std::string(), base::string16(), |
| 654 | 2, std::string(), EmptyAccountId()); |
noms | be073e5 | 2014-08-23 22:01:04 | [diff] [blame] | 655 | base::string16 name_4 = ASCIIToUTF16("Batman"); |
| 656 | base::FilePath path_4 = GetProfilePath("path_4"); |
Roman Sorokin | 8ead4d7 | 2018-04-16 15:58:58 | [diff] [blame] | 657 | GetCache()->AddProfileToCache(path_4, name_4, std::string(), base::string16(), |
| 658 | 3, std::string(), EmptyAccountId()); |
noms | be073e5 | 2014-08-23 22:01:04 | [diff] [blame] | 659 | base::string16 name_5 = ASCIIToUTF16("Person 2"); |
| 660 | base::FilePath path_5 = GetProfilePath("path_5"); |
Roman Sorokin | 8ead4d7 | 2018-04-16 15:58:58 | [diff] [blame] | 661 | GetCache()->AddProfileToCache(path_5, name_5, std::string(), base::string16(), |
| 662 | 2, std::string(), EmptyAccountId()); |
noms | be073e5 | 2014-08-23 22:01:04 | [diff] [blame] | 663 | |
| 664 | EXPECT_EQ(5U, GetCache()->GetNumberOfProfiles()); |
| 665 | |
| 666 | |
| 667 | ResetCache(); |
| 668 | |
| 669 | // Legacy profile names like "Default Profile" and "First user" should be |
WC Leung | 0ea09a64 | 2017-09-02 01:46:15 | [diff] [blame] | 670 | // migrated to "Person %n" type names, i.e. any permutation of "Person 1" and |
| 671 | // "Person 3". |
| 672 | if (ASCIIToUTF16("Person 1") == |
| 673 | GetCache()->GetNameOfProfileAtIndex( |
| 674 | GetCache()->GetIndexOfProfileWithPath(path_1))) { |
| 675 | EXPECT_EQ(ASCIIToUTF16("Person 3"), |
| 676 | GetCache()->GetNameOfProfileAtIndex( |
| 677 | GetCache()->GetIndexOfProfileWithPath(path_2))); |
| 678 | } else { |
| 679 | EXPECT_EQ(ASCIIToUTF16("Person 3"), |
| 680 | GetCache()->GetNameOfProfileAtIndex( |
| 681 | GetCache()->GetIndexOfProfileWithPath(path_1))); |
| 682 | EXPECT_EQ(ASCIIToUTF16("Person 1"), |
| 683 | GetCache()->GetNameOfProfileAtIndex( |
| 684 | GetCache()->GetIndexOfProfileWithPath(path_2))); |
| 685 | } |
noms | be073e5 | 2014-08-23 22:01:04 | [diff] [blame] | 686 | |
| 687 | // Other profile names should not be migrated even if they're the old |
| 688 | // default cartoon profile names. |
| 689 | EXPECT_EQ(name_3, GetCache()->GetNameOfProfileAtIndex( |
| 690 | GetCache()->GetIndexOfProfileWithPath(path_3))); |
| 691 | EXPECT_EQ(name_4, GetCache()->GetNameOfProfileAtIndex( |
| 692 | GetCache()->GetIndexOfProfileWithPath(path_4))); |
| 693 | EXPECT_EQ(name_5, GetCache()->GetNameOfProfileAtIndex( |
| 694 | GetCache()->GetIndexOfProfileWithPath(path_5))); |
| 695 | } |
Xi Cheng | 1b76138 | 2017-08-15 20:37:34 | [diff] [blame] | 696 | |
| 697 | TEST_F(ProfileInfoCacheTest, GetGaiaImageForAvatarMenu) { |
| 698 | // The TestingProfileManager's ProfileInfoCache doesn't download avatars. |
| 699 | ProfileInfoCache profile_info_cache( |
| 700 | g_browser_process->local_state(), |
| 701 | testing_profile_manager_.profile_manager()->user_data_dir()); |
| 702 | |
| 703 | base::FilePath profile_path = GetProfilePath("path_1"); |
| 704 | |
| 705 | GetCache()->AddProfileToCache(profile_path, ASCIIToUTF16("name_1"), |
| 706 | std::string(), base::string16(), 0, |
Roman Sorokin | 8ead4d7 | 2018-04-16 15:58:58 | [diff] [blame] | 707 | std::string(), EmptyAccountId()); |
Xi Cheng | 1b76138 | 2017-08-15 20:37:34 | [diff] [blame] | 708 | |
| 709 | gfx::Image gaia_image(gfx::test::CreateImage()); |
| 710 | GetCache()->SetGAIAPictureOfProfileAtIndex(0, &gaia_image); |
| 711 | |
| 712 | // Make sure everything has completed, and the file has been written to disk. |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 713 | content::RunAllTasksUntilIdle(); |
Xi Cheng | 1b76138 | 2017-08-15 20:37:34 | [diff] [blame] | 714 | |
| 715 | // Make sure this profile is using GAIA picture. |
| 716 | EXPECT_TRUE(GetCache()->IsUsingGAIAPictureOfProfileAtIndex(0)); |
| 717 | |
| 718 | ResetCache(); |
| 719 | |
| 720 | // We need to explicitly set the GAIA usage flag after resetting the cache. |
| 721 | GetCache()->SetIsUsingGAIAPictureOfProfileAtIndex(0, true); |
| 722 | EXPECT_TRUE(GetCache()->IsUsingGAIAPictureOfProfileAtIndex(0)); |
| 723 | |
| 724 | gfx::Image image_loaded; |
| 725 | |
| 726 | // Try to get the GAIA image. For the first time, it triggers an async image |
| 727 | // load from disk. The load status indicates the image is still being loaded. |
| 728 | EXPECT_EQ(AvatarMenu::ImageLoadStatus::LOADING, |
| 729 | AvatarMenu::GetImageForMenuButton(profile_path, &image_loaded)); |
| 730 | EXPECT_FALSE(gfx::test::AreImagesEqual(gaia_image, image_loaded)); |
| 731 | |
| 732 | // Wait until the async image load finishes. |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 733 | content::RunAllTasksUntilIdle(); |
Xi Cheng | 1b76138 | 2017-08-15 20:37:34 | [diff] [blame] | 734 | |
| 735 | // Since the GAIA image is loaded now, we can get it this time. |
| 736 | EXPECT_EQ(AvatarMenu::ImageLoadStatus::LOADED, |
| 737 | AvatarMenu::GetImageForMenuButton(profile_path, &image_loaded)); |
| 738 | EXPECT_TRUE(gfx::test::AreImagesEqual(gaia_image, image_loaded)); |
| 739 | } |
[email protected] | b09bfa1 | 2014-08-15 19:05:25 | [diff] [blame] | 740 | #endif |
noms | be073e5 | 2014-08-23 22:01:04 | [diff] [blame] | 741 | |
jam | 1c5a9149 | 2016-02-24 20:47:53 | [diff] [blame] | 742 | #if defined(OS_CHROMEOS) || defined(OS_ANDROID) |
noms | be073e5 | 2014-08-23 22:01:04 | [diff] [blame] | 743 | TEST_F(ProfileInfoCacheTest, |
| 744 | DontMigrateLegacyProfileNamesWithoutNewAvatarMenu) { |
| 745 | EXPECT_EQ(0U, GetCache()->GetNumberOfProfiles()); |
| 746 | |
| 747 | base::string16 name_1 = ASCIIToUTF16("Default Profile"); |
| 748 | base::FilePath path_1 = GetProfilePath("path_1"); |
Roman Sorokin | 8ead4d7 | 2018-04-16 15:58:58 | [diff] [blame] | 749 | GetCache()->AddProfileToCache(path_1, name_1, std::string(), base::string16(), |
| 750 | 0, std::string(), EmptyAccountId()); |
noms | be073e5 | 2014-08-23 22:01:04 | [diff] [blame] | 751 | base::string16 name_2 = ASCIIToUTF16("First user"); |
| 752 | base::FilePath path_2 = GetProfilePath("path_2"); |
Roman Sorokin | 8ead4d7 | 2018-04-16 15:58:58 | [diff] [blame] | 753 | GetCache()->AddProfileToCache(path_2, name_2, std::string(), base::string16(), |
| 754 | 1, std::string(), EmptyAccountId()); |
noms | be073e5 | 2014-08-23 22:01:04 | [diff] [blame] | 755 | base::string16 name_3 = ASCIIToUTF16("Lemonade"); |
| 756 | base::FilePath path_3 = GetProfilePath("path_3"); |
Roman Sorokin | 8ead4d7 | 2018-04-16 15:58:58 | [diff] [blame] | 757 | GetCache()->AddProfileToCache(path_3, name_3, std::string(), base::string16(), |
| 758 | 2, std::string(), EmptyAccountId()); |
noms | be073e5 | 2014-08-23 22:01:04 | [diff] [blame] | 759 | base::string16 name_4 = ASCIIToUTF16("Batman"); |
| 760 | base::FilePath path_4 = GetProfilePath("path_4"); |
Roman Sorokin | 8ead4d7 | 2018-04-16 15:58:58 | [diff] [blame] | 761 | GetCache()->AddProfileToCache(path_4, name_4, std::string(), base::string16(), |
| 762 | 3, std::string(), EmptyAccountId()); |
noms | be073e5 | 2014-08-23 22:01:04 | [diff] [blame] | 763 | EXPECT_EQ(4U, GetCache()->GetNumberOfProfiles()); |
| 764 | |
| 765 | ResetCache(); |
| 766 | |
| 767 | // Profile names should have been preserved. |
| 768 | EXPECT_EQ(name_1, GetCache()->GetNameOfProfileAtIndex( |
| 769 | GetCache()->GetIndexOfProfileWithPath(path_1))); |
| 770 | EXPECT_EQ(name_2, GetCache()->GetNameOfProfileAtIndex( |
| 771 | GetCache()->GetIndexOfProfileWithPath(path_2))); |
| 772 | EXPECT_EQ(name_3, GetCache()->GetNameOfProfileAtIndex( |
| 773 | GetCache()->GetIndexOfProfileWithPath(path_3))); |
| 774 | EXPECT_EQ(name_4, GetCache()->GetNameOfProfileAtIndex( |
| 775 | GetCache()->GetIndexOfProfileWithPath(path_4))); |
| 776 | } |
anthonyvd | 66aa95d | 2015-10-02 15:40:26 | [diff] [blame] | 777 | #endif |
Alexander Alekseev | 4084f50 | 2018-02-20 22:16:46 | [diff] [blame] | 778 | |
| 779 | TEST_F(ProfileInfoCacheTest, RemoveProfileByAccountId) { |
| 780 | EXPECT_EQ(0u, GetCache()->GetNumberOfProfiles()); |
| 781 | |
| 782 | base::FilePath path_1 = GetProfilePath("path_1"); |
| 783 | const AccountId account_id_1( |
| 784 | AccountId::FromUserEmailGaiaId("email1", "111111")); |
| 785 | base::string16 name_1 = ASCIIToUTF16("name_1"); |
| 786 | GetCache()->AddProfileToCache(path_1, name_1, account_id_1.GetGaiaId(), |
| 787 | UTF8ToUTF16(account_id_1.GetUserEmail()), 0, |
Roman Sorokin | 8ead4d7 | 2018-04-16 15:58:58 | [diff] [blame] | 788 | std::string(), EmptyAccountId()); |
Alexander Alekseev | 4084f50 | 2018-02-20 22:16:46 | [diff] [blame] | 789 | EXPECT_EQ(1u, GetCache()->GetNumberOfProfiles()); |
| 790 | |
| 791 | base::FilePath path_2 = GetProfilePath("path_2"); |
| 792 | base::string16 name_2 = ASCIIToUTF16("name_2"); |
| 793 | const AccountId account_id_2( |
| 794 | AccountId::FromUserEmailGaiaId("email2", "222222")); |
| 795 | GetCache()->AddProfileToCache(path_2, name_2, account_id_2.GetGaiaId(), |
| 796 | UTF8ToUTF16(account_id_2.GetUserEmail()), 0, |
Roman Sorokin | 8ead4d7 | 2018-04-16 15:58:58 | [diff] [blame] | 797 | std::string(), EmptyAccountId()); |
Alexander Alekseev | 4084f50 | 2018-02-20 22:16:46 | [diff] [blame] | 798 | EXPECT_EQ(2u, GetCache()->GetNumberOfProfiles()); |
| 799 | |
| 800 | base::FilePath path_3 = GetProfilePath("path_3"); |
| 801 | base::string16 name_3 = ASCIIToUTF16("name_3"); |
| 802 | const AccountId account_id_3( |
| 803 | AccountId::FromUserEmailGaiaId("email3", "333333")); |
| 804 | GetCache()->AddProfileToCache(path_3, name_3, account_id_3.GetGaiaId(), |
| 805 | UTF8ToUTF16(account_id_3.GetUserEmail()), 0, |
Roman Sorokin | 8ead4d7 | 2018-04-16 15:58:58 | [diff] [blame] | 806 | std::string(), EmptyAccountId()); |
Alexander Alekseev | 4084f50 | 2018-02-20 22:16:46 | [diff] [blame] | 807 | EXPECT_EQ(3u, GetCache()->GetNumberOfProfiles()); |
| 808 | |
| 809 | base::FilePath path_4 = GetProfilePath("path_4"); |
| 810 | base::string16 name_4 = ASCIIToUTF16("name_4"); |
| 811 | const AccountId account_id_4( |
| 812 | AccountId::FromUserEmailGaiaId("email4", "444444")); |
| 813 | GetCache()->AddProfileToCache(path_4, name_4, account_id_4.GetGaiaId(), |
| 814 | UTF8ToUTF16(account_id_4.GetUserEmail()), 0, |
Roman Sorokin | 8ead4d7 | 2018-04-16 15:58:58 | [diff] [blame] | 815 | std::string(), EmptyAccountId()); |
Alexander Alekseev | 4084f50 | 2018-02-20 22:16:46 | [diff] [blame] | 816 | EXPECT_EQ(4u, GetCache()->GetNumberOfProfiles()); |
| 817 | |
| 818 | GetCache()->RemoveProfileByAccountId(account_id_3); |
| 819 | EXPECT_EQ(3u, GetCache()->GetNumberOfProfiles()); |
| 820 | EXPECT_EQ(name_1, GetCache()->GetNameOfProfileAtIndex(0)); |
| 821 | |
| 822 | GetCache()->RemoveProfileByAccountId(account_id_1); |
| 823 | EXPECT_EQ(2u, GetCache()->GetNumberOfProfiles()); |
| 824 | EXPECT_EQ(name_2, GetCache()->GetNameOfProfileAtIndex(0)); |
| 825 | |
| 826 | // this profile is already deleted. |
| 827 | GetCache()->RemoveProfileByAccountId(account_id_3); |
| 828 | EXPECT_EQ(2u, GetCache()->GetNumberOfProfiles()); |
| 829 | EXPECT_EQ(name_2, GetCache()->GetNameOfProfileAtIndex(0)); |
| 830 | |
| 831 | // Remove profile by partial match |
| 832 | GetCache()->RemoveProfileByAccountId( |
| 833 | AccountId::FromUserEmail(account_id_2.GetUserEmail())); |
| 834 | EXPECT_EQ(1u, GetCache()->GetNumberOfProfiles()); |
| 835 | EXPECT_EQ(name_4, GetCache()->GetNameOfProfileAtIndex(0)); |
| 836 | |
| 837 | // Remove last profile |
| 838 | GetCache()->RemoveProfileByAccountId(account_id_4); |
| 839 | EXPECT_EQ(0u, GetCache()->GetNumberOfProfiles()); |
| 840 | } |