Chromium Code Reviews| 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 "base/stringprintf.h" | |
| 6 #include "base/utf_string_conversions.h" | |
| 7 #include "chrome/browser/profiles/profile_info_cache.h" | |
|
willchan no longer on Chromium
2011/06/15 11:22:12
Put this include first. See http://google-stylegui
sail
2011/06/21 03:26:53
Done.
| |
| 8 #include "testing/gtest/include/gtest/gtest.h" | |
| 9 #include "third_party/skia/include/core/SkBitmap.h" | |
| 10 #include "ui/base/resource/resource_bundle.h" | |
| 11 #include "ui/gfx/image/image.h" | |
| 12 | |
| 13 class ProfileInfoCacheUnittests : public ::testing::Test { | |
|
willchan no longer on Chromium
2011/06/15 11:22:12
If test code doesn't need to be externally referen
sail
2011/06/21 03:26:53
Done.
| |
| 14 protected: | |
| 15 ProfileInfoCacheUnittests() : cache_(GetUserDataDir()) { | |
| 16 } | |
| 17 | |
| 18 FilePath GetUserDataDir() { | |
| 19 return StringToFilePath("/usr/profile/directory"); | |
|
Miranda Callahan
2011/06/15 15:16:08
Will this really work on all platforms?
| |
| 20 } | |
| 21 | |
| 22 FilePath StringToFilePath(std::string string_path) { | |
| 23 #if defined(OS_POSIX) | |
| 24 return FilePath(string_path); | |
| 25 #elif defined(OS_WIN) | |
| 26 return FilePath(ASCIIToWide(string_path); | |
| 27 #endif | |
| 28 } | |
| 29 | |
| 30 ProfileInfoCache cache_; | |
| 31 }; | |
| 32 | |
| 33 TEST_F(ProfileInfoCacheUnittests, AddProfiles) { | |
| 34 EXPECT_EQ(0u, cache_.GetNumberOfProfiles()); | |
| 35 | |
| 36 for (uint32 i = 0; i < 4; ++i) { | |
| 37 std::string base_name = StringPrintf("path_%ud", i); | |
| 38 FilePath profile_path = | |
| 39 GetUserDataDir().Append(StringToFilePath(base_name)); | |
| 40 string16 profile_name = ASCIIToUTF16(StringPrintf("name_%ud", i)); | |
| 41 const SkBitmap& icon = ResourceBundle::GetSharedInstance().GetImageNamed( | |
| 42 ProfileInfoCache::GetDefaultAvatarIconResourceIDAtIndex(i)); | |
| 43 | |
| 44 cache_.AddProfileToCache(profile_path, profile_name, 0); | |
| 45 | |
| 46 EXPECT_EQ(i + 1, cache_.GetNumberOfProfiles()); | |
| 47 EXPECT_EQ(profile_name, cache_.GetNameOfProfileAtIndex(i)); | |
| 48 EXPECT_EQ(profile_path, cache_.GetPathOfProfileAtIndex(i)); | |
| 49 const SkBitmap& actual_icon = cache_.GetAvatarIconOfProfileAtIndex(i); | |
| 50 EXPECT_EQ(icon.width(), actual_icon.width()); | |
| 51 EXPECT_EQ(icon.height(), actual_icon.height()); | |
| 52 } | |
| 53 } | |
| 54 | |
| 55 TEST_F(ProfileInfoCacheUnittests, DeleteProfile) { | |
| 56 EXPECT_EQ(0u, cache_.GetNumberOfProfiles()); | |
| 57 | |
| 58 FilePath path_1 = GetUserDataDir().Append("path_1"); | |
| 59 cache_.AddProfileToCache(path_1, ASCIIToUTF16("name_1"), 0); | |
| 60 EXPECT_EQ(1u, cache_.GetNumberOfProfiles()); | |
| 61 | |
| 62 FilePath path_2 = GetUserDataDir().Append("path_2"); | |
| 63 string16 name_2 = ASCIIToUTF16("name_2"); | |
| 64 cache_.AddProfileToCache(path_2, name_2, 0); | |
| 65 EXPECT_EQ(2u, cache_.GetNumberOfProfiles()); | |
| 66 | |
| 67 cache_.DeleteProfileFromCache(path_1); | |
| 68 EXPECT_EQ(1u, cache_.GetNumberOfProfiles()); | |
| 69 EXPECT_EQ(name_2, cache_.GetNameOfProfileAtIndex(0)); | |
| 70 | |
| 71 cache_.DeleteProfileFromCache(path_2); | |
| 72 EXPECT_EQ(0u, cache_.GetNumberOfProfiles()); | |
| 73 } | |
| 74 | |
| 75 TEST_F(ProfileInfoCacheUnittests, MutateProfile) { | |
| 76 cache_.AddProfileToCache(GetUserDataDir().Append("path_1"), | |
| 77 ASCIIToUTF16("name_1"), 0); | |
| 78 cache_.AddProfileToCache(GetUserDataDir().Append("path_2"), | |
| 79 ASCIIToUTF16("name_2"), 0); | |
| 80 | |
| 81 string16 new_name = ASCIIToUTF16("new_name"); | |
| 82 cache_.SetNameOfProfileAtIndex(1, new_name); | |
| 83 EXPECT_EQ(new_name, cache_.GetNameOfProfileAtIndex(1)); | |
| 84 EXPECT_NE(new_name, cache_.GetNameOfProfileAtIndex(0)); | |
| 85 | |
| 86 size_t new_icon_index = 3; | |
| 87 cache_.SetAvatarIconOfProfileAtIndex(1, new_icon_index); | |
| 88 // Not much to test. | |
| 89 cache_.GetAvatarIconOfProfileAtIndex(1); | |
| 90 } | |
| OLD | NEW |