[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 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" |
[email protected] | 8ad3636e | 2011-08-01 22:31:40 | [diff] [blame^] | 9 | #include "chrome/test/base/testing_pref_service.h" |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 10 | #include "chrome/test/testing_browser_process_test.h" |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 11 | #include "third_party/skia/include/core/SkBitmap.h" |
| 12 | #include "ui/base/resource/resource_bundle.h" |
| 13 | #include "ui/gfx/image/image.h" |
| 14 | |
| 15 | namespace { |
| 16 | |
| 17 | class ProfileInfoCacheUnittests : public TestingBrowserProcessTest { |
| 18 | protected: |
| 19 | ProfileInfoCacheUnittests() : local_state_(testing_browser_process_.get()) { |
| 20 | cache_.reset(new ProfileInfoCache(local_state_.Get(), GetUserDataDir())); |
| 21 | } |
| 22 | |
| 23 | FilePath GetUserDataDir() { |
| 24 | return StringToFilePath("usr").Append(StringToFilePath("profile")); |
| 25 | } |
| 26 | |
| 27 | FilePath StringToFilePath(std::string string_path) { |
| 28 | #if defined(OS_POSIX) |
| 29 | return FilePath(string_path); |
| 30 | #elif defined(OS_WIN) |
| 31 | return FilePath(ASCIIToWide(string_path)); |
| 32 | #endif |
| 33 | } |
| 34 | |
| 35 | scoped_ptr<ProfileInfoCache> cache_; |
| 36 | ScopedTestingLocalState local_state_; |
| 37 | }; |
| 38 | |
[email protected] | 66fa0ac | 2011-07-06 17:31:32 | [diff] [blame] | 39 | // TODO(sail): This fails on windows for some reason. |
[email protected] | 54a25179 | 2011-07-06 18:22:45 | [diff] [blame] | 40 | TEST_F(ProfileInfoCacheUnittests, DISABLED_AddProfiles) { |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 41 | EXPECT_EQ(0u, cache_->GetNumberOfProfiles()); |
| 42 | |
| 43 | for (uint32 i = 0; i < 4; ++i) { |
| 44 | std::string base_name = StringPrintf("path_%ud", i); |
| 45 | FilePath profile_path = |
| 46 | GetUserDataDir().Append(StringToFilePath(base_name)); |
| 47 | string16 profile_name = ASCIIToUTF16(StringPrintf("name_%ud", i)); |
| 48 | const SkBitmap& icon = ResourceBundle::GetSharedInstance().GetImageNamed( |
| 49 | ProfileInfoCache::GetDefaultAvatarIconResourceIDAtIndex(i)); |
| 50 | |
| 51 | cache_->AddProfileToCache(profile_path, profile_name, 0); |
| 52 | |
| 53 | EXPECT_EQ(i + 1, cache_->GetNumberOfProfiles()); |
| 54 | EXPECT_EQ(profile_name, cache_->GetNameOfProfileAtIndex(i)); |
| 55 | EXPECT_EQ(profile_path, cache_->GetPathOfProfileAtIndex(i)); |
| 56 | const SkBitmap& actual_icon = cache_->GetAvatarIconOfProfileAtIndex(i); |
| 57 | EXPECT_EQ(icon.width(), actual_icon.width()); |
| 58 | EXPECT_EQ(icon.height(), actual_icon.height()); |
| 59 | } |
| 60 | } |
| 61 | |
[email protected] | ae64106 | 2011-07-06 19:25:31 | [diff] [blame] | 62 | TEST_F(ProfileInfoCacheUnittests, DISABLED_DeleteProfile) { |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 63 | EXPECT_EQ(0u, cache_->GetNumberOfProfiles()); |
| 64 | |
| 65 | FilePath path_1 = GetUserDataDir().Append(StringToFilePath("path_1")); |
| 66 | cache_->AddProfileToCache(path_1, ASCIIToUTF16("name_1"), |
| 67 | 0); |
| 68 | EXPECT_EQ(1u, cache_->GetNumberOfProfiles()); |
| 69 | |
| 70 | FilePath path_2 = GetUserDataDir().Append(StringToFilePath("path_2")); |
| 71 | string16 name_2 = ASCIIToUTF16("name_2"); |
| 72 | cache_->AddProfileToCache(path_2, name_2, 0); |
| 73 | EXPECT_EQ(2u, cache_->GetNumberOfProfiles()); |
| 74 | |
| 75 | cache_->DeleteProfileFromCache(path_1); |
| 76 | EXPECT_EQ(1u, cache_->GetNumberOfProfiles()); |
| 77 | EXPECT_EQ(name_2, cache_->GetNameOfProfileAtIndex(0)); |
| 78 | |
| 79 | cache_->DeleteProfileFromCache(path_2); |
| 80 | EXPECT_EQ(0u, cache_->GetNumberOfProfiles()); |
| 81 | } |
| 82 | |
[email protected] | ae64106 | 2011-07-06 19:25:31 | [diff] [blame] | 83 | TEST_F(ProfileInfoCacheUnittests, DISABLED_MutateProfile) { |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 84 | cache_->AddProfileToCache(GetUserDataDir().Append(StringToFilePath("path_1")), |
| 85 | ASCIIToUTF16("name_1"), 0); |
| 86 | cache_->AddProfileToCache(GetUserDataDir().Append(StringToFilePath("path_2")), |
| 87 | ASCIIToUTF16("name_2"), 0); |
| 88 | |
| 89 | string16 new_name = ASCIIToUTF16("new_name"); |
| 90 | cache_->SetNameOfProfileAtIndex(1, new_name); |
| 91 | EXPECT_EQ(new_name, cache_->GetNameOfProfileAtIndex(1)); |
| 92 | EXPECT_NE(new_name, cache_->GetNameOfProfileAtIndex(0)); |
| 93 | |
| 94 | size_t new_icon_index = 3; |
| 95 | cache_->SetAvatarIconOfProfileAtIndex(1, new_icon_index); |
| 96 | // Not much to test. |
| 97 | cache_->GetAvatarIconOfProfileAtIndex(1); |
| 98 | } |
| 99 | |
| 100 | } // namespace |