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

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

Issue 1415223002: Add counts of User data to ProfileInfoCache (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added methods in profile_statistics.cc to access ProfileInfoCache, fixed a few style errors Created 5 years, 1 month 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/strings/stringprintf.h" 5 #include "base/strings/stringprintf.h"
6 #include "base/strings/utf_string_conversions.h" 6 #include "base/strings/utf_string_conversions.h"
7 #include "chrome/browser/profiles/profile_info_cache.h" 7 #include "chrome/browser/profiles/profile_info_cache.h"
8 #include "chrome/browser/profiles/profile_manager.h" 8 #include "chrome/browser/profiles/profile_manager.h"
9 #include "chrome/browser/supervised_user/supervised_user_constants.h" 9 #include "chrome/browser/supervised_user/supervised_user_constants.h"
10 #include "chrome/test/base/testing_browser_process.h" 10 #include "chrome/test/base/testing_browser_process.h"
(...skipping 16 matching lines...) Expand all
27 TEST_ACCESSORS(entry_type, entry, member, \ 27 TEST_ACCESSORS(entry_type, entry, member, \
28 base::ASCIIToUTF16("first_" #member "_value"), \ 28 base::ASCIIToUTF16("first_" #member "_value"), \
29 base::ASCIIToUTF16("second_" #member "_value")); 29 base::ASCIIToUTF16("second_" #member "_value"));
30 30
31 #define TEST_STRING_ACCESSORS(entry_type, entry, member) \ 31 #define TEST_STRING_ACCESSORS(entry_type, entry, member) \
32 TEST_ACCESSORS(entry_type, entry, member, \ 32 TEST_ACCESSORS(entry_type, entry, member, \
33 std::string("first_" #member "_value"), \ 33 std::string("first_" #member "_value"), \
34 std::string("second_" #member "_value")); 34 std::string("second_" #member "_value"));
35 35
36 #define TEST_BOOL_ACCESSORS(entry_type, entry, member) \ 36 #define TEST_BOOL_ACCESSORS(entry_type, entry, member) \
37 TestAccessors(&entry, \ 37 TestAccessors(&entry, \
38 &entry_type::member, \ 38 &entry_type::member, \
39 &entry_type::Set ## member, \ 39 &entry_type::Set ## member, \
40 false, \ 40 false, \
41 true); 41 true);
42
43 #define TEST_STAT_ACCESSORS(entry_type, entry, member) \
44 TestStatAccessors(&entry, \
45 &entry_type::Has ## member, \
46 &entry_type::Get ## member, \
47 &entry_type::Set ## member, \
48 10, \
49 20);
42 50
43 template<typename TValue, typename TGetter, typename TSetter> 51 template<typename TValue, typename TGetter, typename TSetter>
44 void TestAccessors(ProfileAttributesEntry** entry, 52 void TestAccessors(ProfileAttributesEntry** entry,
45 TGetter getter_func, 53 TGetter getter_func,
46 TSetter setter_func, 54 TSetter setter_func,
47 TValue first_value, 55 TValue first_value,
48 TValue second_value) { 56 TValue second_value) {
49 (*entry->*setter_func)(first_value); 57 (*entry->*setter_func)(first_value);
50 EXPECT_EQ(first_value, (*entry->*getter_func)()); 58 EXPECT_EQ(first_value, (*entry->*getter_func)());
51 (*entry->*setter_func)(second_value); 59 (*entry->*setter_func)(second_value);
52 EXPECT_EQ(second_value, (*entry->*getter_func)()); 60 EXPECT_EQ(second_value, (*entry->*getter_func)());
53 } 61 }
62
63 template<typename TValue, typename TExist, typename TGetter, typename TSetter>
64 void TestStatAccessors(ProfileAttributesEntry** entry,
65 TExist exist_func,
66 TGetter getter_func,
67 TSetter setter_func,
68 TValue first_value,
69 TValue second_value) {
70 EXPECT_FALSE((*entry->*exist_func)());
71 (*entry->*setter_func)(first_value);
72 EXPECT_TRUE((*entry->*exist_func)());
73 EXPECT_EQ(first_value, (*entry->*getter_func)());
74 (*entry->*setter_func)(second_value);
75 EXPECT_TRUE((*entry->*exist_func)());
76 EXPECT_EQ(second_value, (*entry->*getter_func)());
77 }
54 } // namespace 78 } // namespace
55 79
56 class ProfileAttributesStorageTest : public testing::Test { 80 class ProfileAttributesStorageTest : public testing::Test {
57 public: 81 public:
58 ProfileAttributesStorageTest() 82 ProfileAttributesStorageTest()
59 : testing_profile_manager_(TestingBrowserProcess::GetGlobal()) {} 83 : testing_profile_manager_(TestingBrowserProcess::GetGlobal()) {}
60 ~ProfileAttributesStorageTest() override {} 84 ~ProfileAttributesStorageTest() override {}
61 85
62 protected: 86 protected:
63 void SetUp() override { 87 void SetUp() override {
(...skipping 11 matching lines...) Expand all
75 ProfileAttributesStorage* storage() { 99 ProfileAttributesStorage* storage() {
76 return profile_info_cache(); 100 return profile_info_cache();
77 } 101 }
78 102
79 ProfileInfoCache* profile_info_cache() { 103 ProfileInfoCache* profile_info_cache() {
80 return testing_profile_manager_.profile_info_cache(); 104 return testing_profile_manager_.profile_info_cache();
81 } 105 }
82 106
83 void AddTestingProfile() { 107 void AddTestingProfile() {
84 unsigned long number_of_profiles = 108 unsigned long number_of_profiles =
85 static_cast<unsigned long>(storage()->GetNumberOfProfiles()); 109 static_cast<unsigned long>(storage()->GetNumberOfProfiles());
lwchkg 2015/11/15 19:40:06 Should this be simply "size_t" without casting? If
Mike Lerman 2015/11/17 16:29:51 Yes, just use size_t where that's the defined type
lwchkg 2015/11/18 17:34:53 Done.
86 110
87 storage()->AddProfile( 111 storage()->AddProfile(
88 GetProfilePath( 112 GetProfilePath(
89 base::StringPrintf("testing_profile_path%lu", number_of_profiles)), 113 base::StringPrintf("testing_profile_path%lu", number_of_profiles)),
90 base::ASCIIToUTF16( 114 base::ASCIIToUTF16(
91 base::StringPrintf("testing_profile_name%lu", number_of_profiles)), 115 base::StringPrintf("testing_profile_name%lu", number_of_profiles)),
92 std::string( 116 std::string(
93 base::StringPrintf("testing_profile_gaia%lu", number_of_profiles)), 117 base::StringPrintf("testing_profile_gaia%lu", number_of_profiles)),
94 base::ASCIIToUTF16( 118 base::ASCIIToUTF16(
95 base::StringPrintf("testing_profile_user%lu", number_of_profiles)), 119 base::StringPrintf("testing_profile_user%lu", number_of_profiles)),
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 GetProfilePath("testing_profile_path0"), &entry)); 200 GetProfilePath("testing_profile_path0"), &entry));
177 EXPECT_EQ(base::ASCIIToUTF16("testing_profile_name0"), entry->GetName()); 201 EXPECT_EQ(base::ASCIIToUTF16("testing_profile_name0"), entry->GetName());
178 202
179 storage()->RemoveProfile(GetProfilePath("testing_profile_path0")); 203 storage()->RemoveProfile(GetProfilePath("testing_profile_path0"));
180 ASSERT_FALSE(storage()->GetProfileAttributesWithPath( 204 ASSERT_FALSE(storage()->GetProfileAttributesWithPath(
181 GetProfilePath("testing_profile_path0"), &entry)); 205 GetProfilePath("testing_profile_path0"), &entry));
182 EXPECT_EQ(4U, storage()->GetNumberOfProfiles()); 206 EXPECT_EQ(4U, storage()->GetNumberOfProfiles());
183 207
184 std::vector<ProfileAttributesEntry*> entries = 208 std::vector<ProfileAttributesEntry*> entries =
185 storage()->GetAllProfilesAttributes(); 209 storage()->GetAllProfilesAttributes();
186 for (auto& entry: entries) { 210 for (auto& entry : entries) {
187 EXPECT_NE(GetProfilePath("testing_profile_path0"), entry->GetPath()); 211 EXPECT_NE(GetProfilePath("testing_profile_path0"), entry->GetPath());
188 } 212 }
189 } 213 }
190 214
191 TEST_F(ProfileAttributesStorageTest, InitialValues) { 215 TEST_F(ProfileAttributesStorageTest, InitialValues) {
192 AddTestingProfile(); 216 AddTestingProfile();
193 217
194 ProfileAttributesEntry* entry; 218 ProfileAttributesEntry* entry;
195 ASSERT_TRUE(storage()->GetProfileAttributesWithPath( 219 ASSERT_TRUE(storage()->GetProfileAttributesWithPath(
196 GetProfilePath("testing_profile_path0"), &entry)); 220 GetProfilePath("testing_profile_path0"), &entry));
(...skipping 23 matching lines...) Expand all
220 TEST_STRING16_ACCESSORS(ProfileAttributesEntry, entry, GAIAName); 244 TEST_STRING16_ACCESSORS(ProfileAttributesEntry, entry, GAIAName);
221 TEST_STRING16_ACCESSORS(ProfileAttributesEntry, entry, GAIAGivenName); 245 TEST_STRING16_ACCESSORS(ProfileAttributesEntry, entry, GAIAGivenName);
222 TEST_BOOL_ACCESSORS(ProfileAttributesEntry, entry, IsUsingGAIAPicture); 246 TEST_BOOL_ACCESSORS(ProfileAttributesEntry, entry, IsUsingGAIAPicture);
223 TEST_BOOL_ACCESSORS(ProfileAttributesEntry, entry, IsOmitted); 247 TEST_BOOL_ACCESSORS(ProfileAttributesEntry, entry, IsOmitted);
224 TEST_BOOL_ACCESSORS(ProfileAttributesEntry, entry, IsSigninRequired); 248 TEST_BOOL_ACCESSORS(ProfileAttributesEntry, entry, IsSigninRequired);
225 TEST_STRING_ACCESSORS(ProfileAttributesEntry, entry, SupervisedUserId); 249 TEST_STRING_ACCESSORS(ProfileAttributesEntry, entry, SupervisedUserId);
226 TEST_BOOL_ACCESSORS(ProfileAttributesEntry, entry, IsEphemeral); 250 TEST_BOOL_ACCESSORS(ProfileAttributesEntry, entry, IsEphemeral);
227 TEST_BOOL_ACCESSORS(ProfileAttributesEntry, entry, IsUsingDefaultName); 251 TEST_BOOL_ACCESSORS(ProfileAttributesEntry, entry, IsUsingDefaultName);
228 TEST_BOOL_ACCESSORS(ProfileAttributesEntry, entry, IsUsingDefaultAvatar); 252 TEST_BOOL_ACCESSORS(ProfileAttributesEntry, entry, IsUsingDefaultAvatar);
229 TEST_BOOL_ACCESSORS(ProfileAttributesEntry, entry, IsAuthError); 253 TEST_BOOL_ACCESSORS(ProfileAttributesEntry, entry, IsAuthError);
254
255 TEST_STAT_ACCESSORS(ProfileAttributesEntry, entry, StatsBrowsingHistory);
256 TEST_STAT_ACCESSORS(ProfileAttributesEntry, entry, StatsBookmarks);
257 TEST_STAT_ACCESSORS(ProfileAttributesEntry, entry, StatsPasswords);
258 TEST_STAT_ACCESSORS(ProfileAttributesEntry, entry, StatsSettings);
230 } 259 }
231 260
232 TEST_F(ProfileAttributesStorageTest, AuthInfo) { 261 TEST_F(ProfileAttributesStorageTest, AuthInfo) {
233 AddTestingProfile(); 262 AddTestingProfile();
234 263
235 ProfileAttributesEntry* entry; 264 ProfileAttributesEntry* entry;
236 ASSERT_TRUE(storage()->GetProfileAttributesWithPath( 265 ASSERT_TRUE(storage()->GetProfileAttributesWithPath(
237 GetProfilePath("testing_profile_path0"), &entry)); 266 GetProfilePath("testing_profile_path0"), &entry));
238 267
239 entry->SetAuthInfo("", base::string16()); 268 entry->SetAuthInfo("", base::string16());
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 332
304 ProfileAttributesEntry* first_entry; 333 ProfileAttributesEntry* first_entry;
305 ASSERT_TRUE(storage()->GetProfileAttributesWithPath( 334 ASSERT_TRUE(storage()->GetProfileAttributesWithPath(
306 GetProfilePath("testing_profile_path0"), &first_entry)); 335 GetProfilePath("testing_profile_path0"), &first_entry));
307 336
308 ProfileAttributesEntry* second_entry; 337 ProfileAttributesEntry* second_entry;
309 ASSERT_TRUE(storage()->GetProfileAttributesWithPath( 338 ASSERT_TRUE(storage()->GetProfileAttributesWithPath(
310 GetProfilePath("testing_profile_path1"), &second_entry)); 339 GetProfilePath("testing_profile_path1"), &second_entry));
311 340
312 EXPECT_EQ( 341 EXPECT_EQ(
313 base::ASCIIToUTF16("testing_profile_name0"),first_entry->GetName()); 342 base::ASCIIToUTF16("testing_profile_name0"), first_entry->GetName());
314 343
315 storage()->RemoveProfile(GetProfilePath("testing_profile_path1")); 344 storage()->RemoveProfile(GetProfilePath("testing_profile_path1"));
316 ASSERT_FALSE(storage()->GetProfileAttributesWithPath( 345 ASSERT_FALSE(storage()->GetProfileAttributesWithPath(
317 GetProfilePath("testing_profile_path1"), &second_entry)); 346 GetProfilePath("testing_profile_path1"), &second_entry));
318 347
319 EXPECT_EQ(GetProfilePath("testing_profile_path0"), first_entry->GetPath()); 348 EXPECT_EQ(GetProfilePath("testing_profile_path0"), first_entry->GetPath());
320 EXPECT_EQ( 349 EXPECT_EQ(
321 base::ASCIIToUTF16("testing_profile_name0"), first_entry->GetName()); 350 base::ASCIIToUTF16("testing_profile_name0"), first_entry->GetName());
322 351
323 // Deleting through the ProfileInfoCache should be reflected in the 352 // Deleting through the ProfileInfoCache should be reflected in the
(...skipping 23 matching lines...) Expand all
347 // should be reflected by the ProfileAttributesStorage. 376 // should be reflected by the ProfileAttributesStorage.
348 size_t index = profile_info_cache()->GetIndexOfProfileWithPath( 377 size_t index = profile_info_cache()->GetIndexOfProfileWithPath(
349 GetProfilePath("testing_profile_path0")); 378 GetProfilePath("testing_profile_path0"));
350 EXPECT_EQ(base::ASCIIToUTF16("NewName"), 379 EXPECT_EQ(base::ASCIIToUTF16("NewName"),
351 profile_info_cache()->GetNameOfProfileAtIndex(index)); 380 profile_info_cache()->GetNameOfProfileAtIndex(index));
352 381
353 profile_info_cache()->SetNameOfProfileAtIndex( 382 profile_info_cache()->SetNameOfProfileAtIndex(
354 index, base::ASCIIToUTF16("OtherNewName")); 383 index, base::ASCIIToUTF16("OtherNewName"));
355 EXPECT_EQ(base::ASCIIToUTF16("OtherNewName"), first_entry->GetName()); 384 EXPECT_EQ(base::ASCIIToUTF16("OtherNewName"), first_entry->GetName());
356 } 385 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698