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