Chromium Code Reviews| Index: chrome/browser/profiles/profile_info_cache_unittest.cc |
| diff --git a/chrome/browser/profiles/profile_info_cache_unittest.cc b/chrome/browser/profiles/profile_info_cache_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..9e5b8e4d7efead706e5b0f66a1fccca908925ce4 |
| --- /dev/null |
| +++ b/chrome/browser/profiles/profile_info_cache_unittest.cc |
| @@ -0,0 +1,95 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/profiles/profile_info_cache.h" |
| + |
| +#include "base/stringprintf.h" |
| +#include "base/utf_string_conversions.h" |
| +#include "chrome/test/testing_browser_process_test.h" |
| +#include "third_party/skia/include/core/SkBitmap.h" |
| +#include "ui/base/resource/resource_bundle.h" |
| +#include "ui/gfx/image/image.h" |
| + |
| +namespace { |
| + |
| +class ProfileInfoCacheUnittests : public TestingBrowserProcessTest { |
| + protected: |
| + ProfileInfoCacheUnittests() : cache_(GetUserDataDir()) { |
| + } |
| + |
| + FilePath GetUserDataDir() { |
| + return StringToFilePath("/usr/profile/directory"); |
| + } |
| + |
| + FilePath StringToFilePath(std::string string_path) { |
| +#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.
|
| + return FilePath(string_path); |
| +#elif defined(OS_WIN) |
| + return FilePath(ASCIIToWide(string_path); |
| +#endif |
| + } |
| + |
| + ProfileInfoCache cache_; |
| +}; |
| + |
| +TEST_F(ProfileInfoCacheUnittests, AddProfiles) { |
| + EXPECT_EQ(0u, cache_.GetNumberOfProfiles()); |
| + |
| + for (uint32 i = 0; i < 4; ++i) { |
| + std::string base_name = StringPrintf("path_%ud", i); |
| + FilePath profile_path = |
| + GetUserDataDir().Append(StringToFilePath(base_name)); |
| + string16 profile_name = ASCIIToUTF16(StringPrintf("name_%ud", i)); |
| + const SkBitmap& icon = ResourceBundle::GetSharedInstance().GetImageNamed( |
| + ProfileInfoCache::GetDefaultAvatarIconResourceIDAtIndex(i)); |
| + |
| + cache_.AddProfileToCache(profile_path, profile_name, 0); |
| + |
| + EXPECT_EQ(i + 1, cache_.GetNumberOfProfiles()); |
| + EXPECT_EQ(profile_name, cache_.GetNameOfProfileAtIndex(i)); |
| + EXPECT_EQ(profile_path, cache_.GetPathOfProfileAtIndex(i)); |
| + const SkBitmap& actual_icon = cache_.GetAvatarIconOfProfileAtIndex(i); |
| + EXPECT_EQ(icon.width(), actual_icon.width()); |
| + EXPECT_EQ(icon.height(), actual_icon.height()); |
| + } |
| +} |
| + |
| +TEST_F(ProfileInfoCacheUnittests, DeleteProfile) { |
| + EXPECT_EQ(0u, cache_.GetNumberOfProfiles()); |
| + |
| + FilePath path_1 = GetUserDataDir().Append("path_1"); |
| + cache_.AddProfileToCache(path_1, ASCIIToUTF16("name_1"), 0); |
| + EXPECT_EQ(1u, cache_.GetNumberOfProfiles()); |
| + |
| + FilePath path_2 = GetUserDataDir().Append("path_2"); |
| + string16 name_2 = ASCIIToUTF16("name_2"); |
| + cache_.AddProfileToCache(path_2, name_2, 0); |
| + EXPECT_EQ(2u, cache_.GetNumberOfProfiles()); |
| + |
| + cache_.DeleteProfileFromCache(path_1); |
| + EXPECT_EQ(1u, cache_.GetNumberOfProfiles()); |
| + EXPECT_EQ(name_2, cache_.GetNameOfProfileAtIndex(0)); |
| + |
| + cache_.DeleteProfileFromCache(path_2); |
| + EXPECT_EQ(0u, cache_.GetNumberOfProfiles()); |
| +} |
| + |
| +TEST_F(ProfileInfoCacheUnittests, MutateProfile) { |
| + cache_.AddProfileToCache(GetUserDataDir().Append("path_1"), |
| + ASCIIToUTF16("name_1"), 0); |
| + cache_.AddProfileToCache(GetUserDataDir().Append("path_2"), |
| + ASCIIToUTF16("name_2"), 0); |
| + |
| + string16 new_name = ASCIIToUTF16("new_name"); |
| + cache_.SetNameOfProfileAtIndex(1, new_name); |
| + EXPECT_EQ(new_name, cache_.GetNameOfProfileAtIndex(1)); |
| + EXPECT_NE(new_name, cache_.GetNameOfProfileAtIndex(0)); |
| + |
| + size_t new_icon_index = 3; |
| + cache_.SetAvatarIconOfProfileAtIndex(1, new_icon_index); |
| + // Not much to test. |
| + cache_.GetAvatarIconOfProfileAtIndex(1); |
| +} |
| + |
| +} // namespace |