Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Side by Side Diff: chrome/browser/chromeos/login/users/avatar/user_image_manager_browsertest.cc

Issue 1091363002: Change ProfileDownloader to use AccountTrackerService. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nits. Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/profiles/profile_downloader.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <map> 5 #include <map>
6 #include <string> 6 #include <string>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 21 matching lines...) Expand all
32 #include "chrome/browser/chromeos/login/users/avatar/user_image_manager_test_uti l.h" 32 #include "chrome/browser/chromeos/login/users/avatar/user_image_manager_test_uti l.h"
33 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h" 33 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h"
34 #include "chrome/browser/chromeos/login/users/mock_user_manager.h" 34 #include "chrome/browser/chromeos/login/users/mock_user_manager.h"
35 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" 35 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h"
36 #include "chrome/browser/chromeos/policy/cloud_external_data_manager_base_test_u til.h" 36 #include "chrome/browser/chromeos/policy/cloud_external_data_manager_base_test_u til.h"
37 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h" 37 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h"
38 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chrom eos.h" 38 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chrom eos.h"
39 #include "chrome/browser/chromeos/profiles/profile_helper.h" 39 #include "chrome/browser/chromeos/profiles/profile_helper.h"
40 #include "chrome/browser/profiles/profile.h" 40 #include "chrome/browser/profiles/profile.h"
41 #include "chrome/browser/profiles/profile_downloader.h" 41 #include "chrome/browser/profiles/profile_downloader.h"
42 #include "chrome/browser/signin/account_tracker_service_factory.h"
42 #include "chrome/common/chrome_paths.h" 43 #include "chrome/common/chrome_paths.h"
43 #include "chrome/test/base/in_process_browser_test.h" 44 #include "chrome/test/base/in_process_browser_test.h"
44 #include "chrome/test/base/testing_browser_process.h" 45 #include "chrome/test/base/testing_browser_process.h"
45 #include "chromeos/chromeos_paths.h" 46 #include "chromeos/chromeos_paths.h"
46 #include "chromeos/dbus/cryptohome_client.h" 47 #include "chromeos/dbus/cryptohome_client.h"
47 #include "chromeos/dbus/dbus_thread_manager.h" 48 #include "chromeos/dbus/dbus_thread_manager.h"
48 #include "chromeos/dbus/fake_session_manager_client.h" 49 #include "chromeos/dbus/fake_session_manager_client.h"
49 #include "chromeos/dbus/session_manager_client.h" 50 #include "chromeos/dbus/session_manager_client.h"
50 #include "components/policy/core/common/cloud/cloud_policy_core.h" 51 #include "components/policy/core/common/cloud/cloud_policy_core.h"
51 #include "components/policy/core/common/cloud/cloud_policy_store.h" 52 #include "components/policy/core/common/cloud/cloud_policy_store.h"
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 SetOldUserImageInfo( 210 SetOldUserImageInfo(
210 username, user_manager::User::USER_IMAGE_EXTERNAL, image_path); 211 username, user_manager::User::USER_IMAGE_EXTERNAL, image_path);
211 } 212 }
212 213
213 // Returns the image path for user |username| with specified |extension|. 214 // Returns the image path for user |username| with specified |extension|.
214 base::FilePath GetUserImagePath(const std::string& username, 215 base::FilePath GetUserImagePath(const std::string& username,
215 const std::string& extension) { 216 const std::string& extension) {
216 return user_data_dir_.Append(username).AddExtension(extension); 217 return user_data_dir_.Append(username).AddExtension(extension);
217 } 218 }
218 219
220 // Seeds the AccountTrackerService with test data so the ProfileDownloader can
221 // retrieve the picture URL and fetch the image.
222 void SeedAccountTrackerService(const std::string& username,
223 Profile* profile) {
224 AccountTrackerService::AccountInfo info;
225 info.account_id = std::string();
226 info.gaia = username;
227 info.email = username;
228 info.full_name = username;
229 info.given_name = username;
230 info.hosted_domain = std::string();
231 info.locale = username;
232 info.picture_url = "http://localhost/avatar.jpg";
233
234 AccountTrackerServiceFactory::GetForProfile(profile)->SeedAccountInfo(info);
235 }
236
219 // Completes the download of all non-image profile data for the user 237 // Completes the download of all non-image profile data for the user
220 // |username|. This method must only be called after a profile data 238 // |username|. This method must only be called after a profile data
221 // download has been started. |url_fetcher_factory| will capture 239 // download has been started. |url_fetcher_factory| will capture
222 // the net::TestURLFetcher created by the ProfileDownloader to 240 // the net::TestURLFetcher created by the ProfileDownloader to
223 // download the profile image. 241 // download the profile image.
224 void CompleteProfileMetadataDownload( 242 void CompleteProfileMetadataDownload(
225 const std::string& username, 243 const std::string& username,
226 net::TestURLFetcherFactory* url_fetcher_factory) { 244 net::TestURLFetcherFactory* url_fetcher_factory) {
227 ProfileDownloader* profile_downloader = 245 ProfileDownloader* profile_downloader =
228 reinterpret_cast<UserImageManagerImpl*>( 246 reinterpret_cast<UserImageManagerImpl*>(
229 ChromeUserManager::Get()->GetUserImageManager(username)) 247 ChromeUserManager::Get()->GetUserImageManager(username))
230 ->profile_downloader_.get(); 248 ->profile_downloader_.get();
231 ASSERT_TRUE(profile_downloader); 249 ASSERT_TRUE(profile_downloader);
232 250
233 static_cast<OAuth2TokenService::Consumer*>(profile_downloader)-> 251 static_cast<OAuth2TokenService::Consumer*>(profile_downloader)->
234 OnGetTokenSuccess(NULL, 252 OnGetTokenSuccess(NULL,
235 std::string(), 253 std::string(),
236 base::Time::Now() + base::TimeDelta::FromDays(1)); 254 base::Time::Now() + base::TimeDelta::FromDays(1));
237
238 net::TestURLFetcher* fetcher = url_fetcher_factory->GetFetcherByID(
239 gaia::GaiaOAuthClient::kUrlFetcherId);
240 ASSERT_TRUE(fetcher);
241 fetcher->SetResponseString(
242 "{ \"picture\": \"http://localhost/avatar.jpg\" }");
243 fetcher->set_status(net::URLRequestStatus(net::URLRequestStatus::SUCCESS,
244 net::OK));
245 fetcher->set_response_code(200);
246 fetcher->delegate()->OnURLFetchComplete(fetcher);
247 base::RunLoop().RunUntilIdle();
248 } 255 }
249 256
250 // Completes the download of the currently logged-in user's profile image. 257 // Completes the download of the currently logged-in user's profile image.
251 // This method must only be called after a profile data download including 258 // This method must only be called after a profile data download including
252 // the profile image has been started, the download of all non-image data has 259 // the profile image has been started, the download of all non-image data has
253 // been completed by calling CompleteProfileMetadataDownload() and the 260 // been completed by calling CompleteProfileMetadataDownload() and the
254 // net::TestURLFetcher created by the ProfileDownloader to download the 261 // net::TestURLFetcher created by the ProfileDownloader to download the
255 // profile image has been captured by |url_fetcher_factory|. 262 // profile image has been captured by |url_fetcher_factory|.
256 void CompleteProfileImageDownload( 263 void CompleteProfileImageDownload(
257 net::TestURLFetcherFactory* url_fetcher_factory) { 264 net::TestURLFetcherFactory* url_fetcher_factory) {
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 523
517 // Verifies that SaveUserImageFromProfileImage() correctly downloads, sets and 524 // Verifies that SaveUserImageFromProfileImage() correctly downloads, sets and
518 // persists the chosen user image. 525 // persists the chosen user image.
519 IN_PROC_BROWSER_TEST_F(UserImageManagerTest, SaveUserImageFromProfileImage) { 526 IN_PROC_BROWSER_TEST_F(UserImageManagerTest, SaveUserImageFromProfileImage) {
520 const user_manager::User* user = 527 const user_manager::User* user =
521 user_manager::UserManager::Get()->FindUser(kTestUser1); 528 user_manager::UserManager::Get()->FindUser(kTestUser1);
522 ASSERT_TRUE(user); 529 ASSERT_TRUE(user);
523 530
524 UserImageManagerImpl::IgnoreProfileDataDownloadDelayForTesting(); 531 UserImageManagerImpl::IgnoreProfileDataDownloadDelayForTesting();
525 LoginUser(kTestUser1); 532 LoginUser(kTestUser1);
533 Profile* profile = ProfileHelper::Get()->GetProfileByUserUnsafe(user);
534 SeedAccountTrackerService(kTestUser1, profile);
526 535
527 run_loop_.reset(new base::RunLoop); 536 run_loop_.reset(new base::RunLoop);
528 UserImageManager* user_image_manager = 537 UserImageManager* user_image_manager =
529 ChromeUserManager::Get()->GetUserImageManager(kTestUser1); 538 ChromeUserManager::Get()->GetUserImageManager(kTestUser1);
530 user_image_manager->SaveUserImageFromProfileImage(); 539 user_image_manager->SaveUserImageFromProfileImage();
531 run_loop_->Run(); 540 run_loop_->Run();
532 541
533 net::TestURLFetcherFactory url_fetcher_factory; 542 net::TestURLFetcherFactory url_fetcher_factory;
534 CompleteProfileMetadataDownload(kTestUser1, &url_fetcher_factory); 543 CompleteProfileMetadataDownload(kTestUser1, &url_fetcher_factory);
535 CompleteProfileImageDownload(&url_fetcher_factory); 544 CompleteProfileImageDownload(&url_fetcher_factory);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 ProfileImageDownloadDoesNotClobber) { 576 ProfileImageDownloadDoesNotClobber) {
568 const user_manager::User* user = 577 const user_manager::User* user =
569 user_manager::UserManager::Get()->FindUser(kTestUser1); 578 user_manager::UserManager::Get()->FindUser(kTestUser1);
570 ASSERT_TRUE(user); 579 ASSERT_TRUE(user);
571 580
572 const gfx::ImageSkia& default_image = 581 const gfx::ImageSkia& default_image =
573 user_manager::GetDefaultImage(user_manager::kFirstDefaultImageIndex); 582 user_manager::GetDefaultImage(user_manager::kFirstDefaultImageIndex);
574 583
575 UserImageManagerImpl::IgnoreProfileDataDownloadDelayForTesting(); 584 UserImageManagerImpl::IgnoreProfileDataDownloadDelayForTesting();
576 LoginUser(kTestUser1); 585 LoginUser(kTestUser1);
586 Profile* profile = ProfileHelper::Get()->GetProfileByUserUnsafe(user);
587 SeedAccountTrackerService(kTestUser1, profile);
577 588
578 run_loop_.reset(new base::RunLoop); 589 run_loop_.reset(new base::RunLoop);
579 UserImageManager* user_image_manager = 590 UserImageManager* user_image_manager =
580 ChromeUserManager::Get()->GetUserImageManager(kTestUser1); 591 ChromeUserManager::Get()->GetUserImageManager(kTestUser1);
581 user_image_manager->SaveUserImageFromProfileImage(); 592 user_image_manager->SaveUserImageFromProfileImage();
582 run_loop_->Run(); 593 run_loop_->Run();
583 594
584 net::TestURLFetcherFactory url_fetcher_factory; 595 net::TestURLFetcherFactory url_fetcher_factory;
585 CompleteProfileMetadataDownload(kTestUser1, &url_fetcher_factory); 596 CompleteProfileMetadataDownload(kTestUser1, &url_fetcher_factory);
586 597
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
885 896
886 saved_image = test::ImageLoader(GetUserImagePath(kTestUser1, "jpg")).Load(); 897 saved_image = test::ImageLoader(GetUserImagePath(kTestUser1, "jpg")).Load();
887 ASSERT_TRUE(saved_image); 898 ASSERT_TRUE(saved_image);
888 899
889 // Check image dimensions. Images can't be compared since JPEG is lossy. 900 // Check image dimensions. Images can't be compared since JPEG is lossy.
890 EXPECT_EQ(policy_image_->width(), saved_image->width()); 901 EXPECT_EQ(policy_image_->width(), saved_image->width());
891 EXPECT_EQ(policy_image_->height(), saved_image->height()); 902 EXPECT_EQ(policy_image_->height(), saved_image->height());
892 } 903 }
893 904
894 } // namespace chromeos 905 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/profiles/profile_downloader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698