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

Side by Side Diff: chrome/browser/profiles/profile_info_cache_unittest.cc

Issue 7256002: Multi-Profiles: New Profile Setup UI (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: show product logo at bottom 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 "chrome/test/testing_pref_service.h"
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/profile/directory");
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
39 TEST_F(ProfileInfoCacheUnittests, AddProfiles) {
40 EXPECT_EQ(0u, cache_->GetNumberOfProfiles());
41
42 for (uint32 i = 0; i < 4; ++i) {
43 std::string base_name = StringPrintf("path_%ud", i);
44 FilePath profile_path =
45 GetUserDataDir().Append(StringToFilePath(base_name));
46 string16 profile_name = ASCIIToUTF16(StringPrintf("name_%ud", i));
47 const SkBitmap& icon = ResourceBundle::GetSharedInstance().GetImageNamed(
48 ProfileInfoCache::GetDefaultAvatarIconResourceIDAtIndex(i));
49
50 cache_->AddProfileToCache(profile_path, profile_name, 0);
51
52 EXPECT_EQ(i + 1, cache_->GetNumberOfProfiles());
53 EXPECT_EQ(profile_name, cache_->GetNameOfProfileAtIndex(i));
54 EXPECT_EQ(profile_path, cache_->GetPathOfProfileAtIndex(i));
55 const SkBitmap& actual_icon = cache_->GetAvatarIconOfProfileAtIndex(i);
56 EXPECT_EQ(icon.width(), actual_icon.width());
57 EXPECT_EQ(icon.height(), actual_icon.height());
58 }
59 }
60
61 TEST_F(ProfileInfoCacheUnittests, DeleteProfile) {
62 EXPECT_EQ(0u, cache_->GetNumberOfProfiles());
63
64 FilePath path_1 = GetUserDataDir().Append("path_1");
65 cache_->AddProfileToCache(path_1, ASCIIToUTF16("name_1"), 0);
66 EXPECT_EQ(1u, cache_->GetNumberOfProfiles());
67
68 FilePath path_2 = GetUserDataDir().Append("path_2");
69 string16 name_2 = ASCIIToUTF16("name_2");
70 cache_->AddProfileToCache(path_2, name_2, 0);
71 EXPECT_EQ(2u, cache_->GetNumberOfProfiles());
72
73 cache_->DeleteProfileFromCache(path_1);
74 EXPECT_EQ(1u, cache_->GetNumberOfProfiles());
75 EXPECT_EQ(name_2, cache_->GetNameOfProfileAtIndex(0));
76
77 cache_->DeleteProfileFromCache(path_2);
78 EXPECT_EQ(0u, cache_->GetNumberOfProfiles());
79 }
80
81 TEST_F(ProfileInfoCacheUnittests, MutateProfile) {
82 cache_->AddProfileToCache(GetUserDataDir().Append("path_1"),
83 ASCIIToUTF16("name_1"), 0);
84 cache_->AddProfileToCache(GetUserDataDir().Append("path_2"),
85 ASCIIToUTF16("name_2"), 0);
86
87 string16 new_name = ASCIIToUTF16("new_name");
88 cache_->SetNameOfProfileAtIndex(1, new_name);
89 EXPECT_EQ(new_name, cache_->GetNameOfProfileAtIndex(1));
90 EXPECT_NE(new_name, cache_->GetNameOfProfileAtIndex(0));
91
92 size_t new_icon_index = 3;
93 cache_->SetAvatarIconOfProfileAtIndex(1, new_icon_index);
94 // Not much to test.
95 cache_->GetAvatarIconOfProfileAtIndex(1);
96 }
97
98 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698