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