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

Side by Side Diff: chrome/browser/profiles/profile_info_cache_unittest.cc

Issue 222313005: [Profiles] Download high-res avatars using the --new-profile-management flag (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: typo Created 6 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 | Annotate | Revision Log
OLDNEW
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/browser/profiles/profile_info_cache_unittest.h" 5 #include "chrome/browser/profiles/profile_info_cache_unittest.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/prefs/testing_pref_service.h" 9 #include "base/prefs/testing_pref_service.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "base/time/time.h" 12 #include "base/time/time.h"
13 #include "chrome/browser/browser_process.h" 13 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/chrome_notification_types.h" 14 #include "chrome/browser/chrome_notification_types.h"
15 #include "chrome/browser/prefs/pref_service_syncable.h" 15 #include "chrome/browser/prefs/pref_service_syncable.h"
16 #include "chrome/browser/profiles/profile_avatar_downloader.h"
16 #include "chrome/browser/profiles/profile_avatar_icon_util.h" 17 #include "chrome/browser/profiles/profile_avatar_icon_util.h"
17 #include "chrome/browser/profiles/profile_info_cache.h" 18 #include "chrome/browser/profiles/profile_info_cache.h"
18 #include "chrome/browser/profiles/profile_manager.h" 19 #include "chrome/browser/profiles/profile_manager.h"
19 #include "chrome/test/base/testing_browser_process.h" 20 #include "chrome/test/base/testing_browser_process.h"
20 #include "content/public/browser/notification_observer.h" 21 #include "content/public/browser/notification_observer.h"
21 #include "content/public/browser/notification_registrar.h" 22 #include "content/public/browser/notification_registrar.h"
22 #include "content/public/browser/notification_service.h" 23 #include "content/public/browser/notification_service.h"
23 #include "content/public/test/test_browser_thread_bundle.h" 24 #include "content/public/test/test_browser_thread_bundle.h"
24 #include "content/public/test/test_utils.h" 25 #include "content/public/test/test_utils.h"
25 #include "third_party/skia/include/core/SkBitmap.h" 26 #include "third_party/skia/include/core/SkBitmap.h"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 base::FilePath ProfileInfoCacheTest::GetProfilePath( 111 base::FilePath ProfileInfoCacheTest::GetProfilePath(
111 const std::string& base_name) { 112 const std::string& base_name) {
112 return testing_profile_manager_.profile_manager()->user_data_dir(). 113 return testing_profile_manager_.profile_manager()->user_data_dir().
113 AppendASCII(base_name); 114 AppendASCII(base_name);
114 } 115 }
115 116
116 void ProfileInfoCacheTest::ResetCache() { 117 void ProfileInfoCacheTest::ResetCache() {
117 testing_profile_manager_.DeleteProfileInfoCache(); 118 testing_profile_manager_.DeleteProfileInfoCache();
118 } 119 }
119 120
120 namespace {
121
122 TEST_F(ProfileInfoCacheTest, AddProfiles) { 121 TEST_F(ProfileInfoCacheTest, AddProfiles) {
123 EXPECT_EQ(0u, GetCache()->GetNumberOfProfiles()); 122 EXPECT_EQ(0u, GetCache()->GetNumberOfProfiles());
124 123
125 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 124 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
126 for (uint32 i = 0; i < 4; ++i) { 125 for (uint32 i = 0; i < 4; ++i) {
127 base::FilePath profile_path = 126 base::FilePath profile_path =
128 GetProfilePath(base::StringPrintf("path_%ud", i)); 127 GetProfilePath(base::StringPrintf("path_%ud", i));
129 base::string16 profile_name = 128 base::string16 profile_name =
130 ASCIIToUTF16(base::StringPrintf("name_%ud", i)); 129 ASCIIToUTF16(base::StringPrintf("name_%ud", i));
131 const SkBitmap* icon = rb.GetImageNamed( 130 const SkBitmap* icon = rb.GetImageNamed(
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 } 494 }
496 495
497 ASSERT_EQ(4U, GetCache()->GetNumberOfProfiles()); 496 ASSERT_EQ(4U, GetCache()->GetNumberOfProfiles());
498 497
499 // Check that the profiles can be extracted from the local state. 498 // Check that the profiles can be extracted from the local state.
500 std::vector<base::string16> names = ProfileInfoCache::GetProfileNames(); 499 std::vector<base::string16> names = ProfileInfoCache::GetProfileNames();
501 for (size_t i = 0; i < 4; i++) 500 for (size_t i = 0; i < 4; i++)
502 ASSERT_FALSE(names[i].empty()); 501 ASSERT_FALSE(names[i].empty());
503 } 502 }
504 503
505 } // namespace 504 TEST_F(ProfileInfoCacheTest, DownloadHighResAvatarTest) {
505 EXPECT_EQ(0U, GetCache()->GetNumberOfProfiles());
506 base::FilePath path_1 = GetProfilePath("path_1");
507 GetCache()->AddProfileToCache(path_1, ASCIIToUTF16("name_1"),
508 base::string16(), 0, std::string());
509 EXPECT_EQ(1U, GetCache()->GetNumberOfProfiles());
510
511 // We haven't downloaded any high-res avatars yet.
512 EXPECT_EQ(0U, GetCache()->cached_avatar_images_.size());
513 EXPECT_EQ(0U, GetCache()->avatar_images_downloads_in_progress_.size());
514 EXPECT_FALSE(GetCache()->GetHighResAvatarOfProfileAtIndex(0));
515
516 // Simulate downloading a high-res avatar.
517 ProfileAvatarDownloader avatar_downloader(
518 TestingBrowserProcess::GetGlobal()->system_request_context(),
519 0,
520 GetCache());
521
522 // Put a real bitmap into "bitmap". 2x2 bitmap of green 32 bit pixels.
523 SkBitmap bitmap;
524 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 2, 2);
525 bitmap.allocPixels();
526 bitmap.eraseColor(SK_ColorGREEN);
527
528 avatar_downloader.OnFetchComplete(
529 GURL("http://www.google.com/avatar.png"), &bitmap);
530
531 std::string file_name =
532 profiles::GetDefaultAvatarIconFileNameAtIndex(0);
533
534 // The file should have been cached and saved.
535 EXPECT_EQ(0U, GetCache()->avatar_images_downloads_in_progress_.size());
536 EXPECT_EQ(1U, GetCache()->cached_avatar_images_.size());
537 EXPECT_TRUE(GetCache()->GetHighResAvatarOfProfileAtIndex(0));
538 EXPECT_EQ(GetCache()->cached_avatar_images_[file_name],
539 GetCache()->GetHighResAvatarOfProfileAtIndex(0));
540 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698