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

Unified Diff: chrome/browser/profiles/profile_info_cache_unittest.cc

Issue 7155015: Store profile avatar to preferences (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 6 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 side-by-side diff with in-line comments
Download patch
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..a9bbfffb13d6a3c73934333d355901de7af9c211
--- /dev/null
+++ b/chrome/browser/profiles/profile_info_cache_unittest.cc
@@ -0,0 +1,90 @@
+// 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 "base/stringprintf.h"
+#include "base/utf_string_conversions.h"
+#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.
+#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/skia/include/core/SkBitmap.h"
+#include "ui/base/resource/resource_bundle.h"
+#include "ui/gfx/image/image.h"
+
+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.
+ protected:
+ ProfileInfoCacheUnittests() : cache_(GetUserDataDir()) {
+ }
+
+ FilePath GetUserDataDir() {
+ return StringToFilePath("/usr/profile/directory");
Miranda Callahan 2011/06/15 15:16:08 Will this really work on all platforms?
+ }
+
+ FilePath StringToFilePath(std::string string_path) {
+#if defined(OS_POSIX)
+ 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);
+}

Powered by Google App Engine
This is Rietveld 408576698