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