OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/test/base/testing_profile_manager.h" | 5 #include "chrome/test/base/testing_profile_manager.h" |
6 | 6 |
7 #include "base/files/file_util.h" | |
8 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
9 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/browser/prefs/pref_service_syncable.h" | 9 #include "chrome/browser/prefs/pref_service_syncable.h" |
11 #include "chrome/browser/profiles/profile_avatar_downloader.h" | |
12 #include "chrome/browser/profiles/profile_avatar_icon_util.h" | |
13 #include "chrome/browser/profiles/profile_info_cache.h" | 10 #include "chrome/browser/profiles/profile_info_cache.h" |
14 #include "chrome/browser/profiles/profile_manager.h" | 11 #include "chrome/browser/profiles/profile_manager.h" |
15 #include "chrome/common/chrome_constants.h" | 12 #include "chrome/common/chrome_constants.h" |
16 #include "chrome/test/base/testing_browser_process.h" | 13 #include "chrome/test/base/testing_browser_process.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
18 | 15 |
19 #if defined(OS_CHROMEOS) | 16 #if defined(OS_CHROMEOS) |
20 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 17 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
21 #endif | 18 #endif |
22 | 19 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 | 90 |
94 TestingProfile* profile = builder.Build().release(); | 91 TestingProfile* profile = builder.Build().release(); |
95 profile->set_profile_name(profile_name); | 92 profile->set_profile_name(profile_name); |
96 profile_manager_->AddProfile(profile); // Takes ownership. | 93 profile_manager_->AddProfile(profile); // Takes ownership. |
97 | 94 |
98 // Update the user metadata. | 95 // Update the user metadata. |
99 ProfileInfoCache& cache = profile_manager_->GetProfileInfoCache(); | 96 ProfileInfoCache& cache = profile_manager_->GetProfileInfoCache(); |
100 size_t index = cache.GetIndexOfProfileWithPath(profile_path); | 97 size_t index = cache.GetIndexOfProfileWithPath(profile_path); |
101 cache.SetAvatarIconOfProfileAtIndex(index, avatar_id); | 98 cache.SetAvatarIconOfProfileAtIndex(index, avatar_id); |
102 cache.SetSupervisedUserIdOfProfileAtIndex(index, supervised_user_id); | 99 cache.SetSupervisedUserIdOfProfileAtIndex(index, supervised_user_id); |
103 | |
104 // Cache a "high res" icon if none exists to avoid a network fetch. | |
105 size_t icon_index = cache.GetAvatarIconIndexOfProfileAtIndex(index); | |
106 if (!base::PathExists(profiles::GetPathOfHighResAvatarAtIndex(icon_index))) { | |
107 ProfileAvatarDownloader avatar_downloader( | |
108 cache.GetAvatarIconIndexOfProfileAtIndex(index), profile_path, &cache); | |
109 | |
110 // Put a real bitmap into "bitmap". 2x2 bitmap of green 32 bit pixels. | |
111 SkBitmap bitmap; | |
112 bitmap.allocN32Pixels(2, 2); | |
113 bitmap.eraseColor(SK_ColorGREEN); | |
114 avatar_downloader.OnFetchComplete( | |
115 GURL("http://www.google.com/avatar.png"), &bitmap); | |
116 } | |
117 | |
118 // SetNameOfProfileAtIndex may reshuffle the list of profiles, so we do it | 100 // SetNameOfProfileAtIndex may reshuffle the list of profiles, so we do it |
119 // last. | 101 // last. |
120 cache.SetNameOfProfileAtIndex(index, user_name); | 102 cache.SetNameOfProfileAtIndex(index, user_name); |
121 | 103 |
122 testing_profiles_.insert(std::make_pair(profile_name, profile)); | 104 testing_profiles_.insert(std::make_pair(profile_name, profile)); |
123 | 105 |
124 return profile; | 106 return profile; |
125 } | 107 } |
126 | 108 |
127 TestingProfile* TestingProfileManager::CreateTestingProfile( | 109 TestingProfile* TestingProfileManager::CreateTestingProfile( |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 << "ProfileManager already exists"; | 235 << "ProfileManager already exists"; |
254 | 236 |
255 // Set up the directory for profiles. | 237 // Set up the directory for profiles. |
256 ASSERT_TRUE(profiles_dir_.CreateUniqueTempDir()); | 238 ASSERT_TRUE(profiles_dir_.CreateUniqueTempDir()); |
257 | 239 |
258 profile_manager_ = new testing::ProfileManager(profiles_dir_.path()); | 240 profile_manager_ = new testing::ProfileManager(profiles_dir_.path()); |
259 browser_process_->SetProfileManager(profile_manager_); // Takes ownership. | 241 browser_process_->SetProfileManager(profile_manager_); // Takes ownership. |
260 | 242 |
261 called_set_up_ = true; | 243 called_set_up_ = true; |
262 } | 244 } |
OLD | NEW |