 Chromium Code Reviews
 Chromium Code Reviews Issue 7155015:
  Store profile avatar to preferences  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src
    
  
    Issue 7155015:
  Store profile avatar to preferences  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src| OLD | NEW | 
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/profiles/profile_info_cache.h" | |
| 6 | |
| 7 #include "base/stringprintf.h" | |
| 8 #include "base/utf_string_conversions.h" | |
| 9 #include "chrome/test/testing_browser_process_test.h" | |
| 10 #include "third_party/skia/include/core/SkBitmap.h" | |
| 11 #include "ui/base/resource/resource_bundle.h" | |
| 12 #include "ui/gfx/image/image.h" | |
| 13 | |
| 14 namespace { | |
| 15 | |
| 16 class ProfileInfoCacheUnittests : public TestingBrowserProcessTest { | |
| 17 protected: | |
| 18 ProfileInfoCacheUnittests() : cache_(GetUserDataDir()) { | |
| 19 } | |
| 20 | |
| 21 FilePath GetUserDataDir() { | |
| 22 return StringToFilePath("/usr/profile/directory"); | |
| 23 } | |
| 24 | |
| 25 FilePath StringToFilePath(std::string string_path) { | |
| 26 #if defined(OS_POSIX) | |
| 
willchan no longer on Chromium
2011/06/21 08:26:27
I think you need build/build_config.h for these pr
 
sail
2011/06/21 16:28:13
Testing on windows and linux now.
 | |
| 27 return FilePath(string_path); | |
| 28 #elif defined(OS_WIN) | |
| 29 return FilePath(ASCIIToWide(string_path); | |
| 30 #endif | |
| 31 } | |
| 32 | |
| 33 ProfileInfoCache cache_; | |
| 34 }; | |
| 35 | |
| 36 TEST_F(ProfileInfoCacheUnittests, AddProfiles) { | |
| 37 EXPECT_EQ(0u, cache_.GetNumberOfProfiles()); | |
| 38 | |
| 39 for (uint32 i = 0; i < 4; ++i) { | |
| 40 std::string base_name = StringPrintf("path_%ud", i); | |
| 41 FilePath profile_path = | |
| 42 GetUserDataDir().Append(StringToFilePath(base_name)); | |
| 43 string16 profile_name = ASCIIToUTF16(StringPrintf("name_%ud", i)); | |
| 44 const SkBitmap& icon = ResourceBundle::GetSharedInstance().GetImageNamed( | |
| 45 ProfileInfoCache::GetDefaultAvatarIconResourceIDAtIndex(i)); | |
| 46 | |
| 47 cache_.AddProfileToCache(profile_path, profile_name, 0); | |
| 48 | |
| 49 EXPECT_EQ(i + 1, cache_.GetNumberOfProfiles()); | |
| 50 EXPECT_EQ(profile_name, cache_.GetNameOfProfileAtIndex(i)); | |
| 51 EXPECT_EQ(profile_path, cache_.GetPathOfProfileAtIndex(i)); | |
| 52 const SkBitmap& actual_icon = cache_.GetAvatarIconOfProfileAtIndex(i); | |
| 53 EXPECT_EQ(icon.width(), actual_icon.width()); | |
| 54 EXPECT_EQ(icon.height(), actual_icon.height()); | |
| 55 } | |
| 56 } | |
| 57 | |
| 58 TEST_F(ProfileInfoCacheUnittests, DeleteProfile) { | |
| 59 EXPECT_EQ(0u, cache_.GetNumberOfProfiles()); | |
| 60 | |
| 61 FilePath path_1 = GetUserDataDir().Append("path_1"); | |
| 62 cache_.AddProfileToCache(path_1, ASCIIToUTF16("name_1"), 0); | |
| 63 EXPECT_EQ(1u, cache_.GetNumberOfProfiles()); | |
| 64 | |
| 65 FilePath path_2 = GetUserDataDir().Append("path_2"); | |
| 66 string16 name_2 = ASCIIToUTF16("name_2"); | |
| 67 cache_.AddProfileToCache(path_2, name_2, 0); | |
| 68 EXPECT_EQ(2u, cache_.GetNumberOfProfiles()); | |
| 69 | |
| 70 cache_.DeleteProfileFromCache(path_1); | |
| 71 EXPECT_EQ(1u, cache_.GetNumberOfProfiles()); | |
| 72 EXPECT_EQ(name_2, cache_.GetNameOfProfileAtIndex(0)); | |
| 73 | |
| 74 cache_.DeleteProfileFromCache(path_2); | |
| 75 EXPECT_EQ(0u, cache_.GetNumberOfProfiles()); | |
| 76 } | |
| 77 | |
| 78 TEST_F(ProfileInfoCacheUnittests, MutateProfile) { | |
| 79 cache_.AddProfileToCache(GetUserDataDir().Append("path_1"), | |
| 80 ASCIIToUTF16("name_1"), 0); | |
| 81 cache_.AddProfileToCache(GetUserDataDir().Append("path_2"), | |
| 82 ASCIIToUTF16("name_2"), 0); | |
| 83 | |
| 84 string16 new_name = ASCIIToUTF16("new_name"); | |
| 85 cache_.SetNameOfProfileAtIndex(1, new_name); | |
| 86 EXPECT_EQ(new_name, cache_.GetNameOfProfileAtIndex(1)); | |
| 87 EXPECT_NE(new_name, cache_.GetNameOfProfileAtIndex(0)); | |
| 88 | |
| 89 size_t new_icon_index = 3; | |
| 90 cache_.SetAvatarIconOfProfileAtIndex(1, new_icon_index); | |
| 91 // Not much to test. | |
| 92 cache_.GetAvatarIconOfProfileAtIndex(1); | |
| 93 } | |
| 94 | |
| 95 } // namespace | |
| OLD | NEW |