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

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

Issue 1428973003: Utilize ProfileInfoCache to support data type counts in profile deletion flow (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: user_pod_row.js done, statistics now saved when the last window of a profile is closed. 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 "base/values.h"
7 #include "chrome/browser/profiles/profile_info_cache.h" 8 #include "chrome/browser/profiles/profile_info_cache.h"
8 #include "chrome/browser/profiles/profile_manager.h" 9 #include "chrome/browser/profiles/profile_manager.h"
9 #include "chrome/browser/supervised_user/supervised_user_constants.h" 10 #include "chrome/browser/supervised_user/supervised_user_constants.h"
10 #include "chrome/test/base/testing_browser_process.h" 11 #include "chrome/test/base/testing_browser_process.h"
11 #include "chrome/test/base/testing_profile_manager.h" 12 #include "chrome/test/base/testing_profile_manager.h"
12 #include "content/public/test/test_browser_thread_bundle.h" 13 #include "content/public/test/test_browser_thread_bundle.h"
13 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
14 15
15 namespace { 16 namespace {
16 // The ProfileMetadataEntry accessors aren't just plain old accessors to local 17 // The ProfileMetadataEntry accessors aren't just plain old accessors to local
(...skipping 27 matching lines...) Expand all
44 void TestAccessors(ProfileAttributesEntry** entry, 45 void TestAccessors(ProfileAttributesEntry** entry,
45 TGetter getter_func, 46 TGetter getter_func,
46 TSetter setter_func, 47 TSetter setter_func,
47 TValue first_value, 48 TValue first_value,
48 TValue second_value) { 49 TValue second_value) {
49 (*entry->*setter_func)(first_value); 50 (*entry->*setter_func)(first_value);
50 EXPECT_EQ(first_value, (*entry->*getter_func)()); 51 EXPECT_EQ(first_value, (*entry->*getter_func)());
51 (*entry->*setter_func)(second_value); 52 (*entry->*setter_func)(second_value);
52 EXPECT_EQ(second_value, (*entry->*getter_func)()); 53 EXPECT_EQ(second_value, (*entry->*getter_func)());
53 } 54 }
55
56 void VerifyStatistics(const ProfileAttributesEntry * const entry,
57 const std::map<std::string, int>& expect_map,
58 const std::vector<std::string>& categories_to_check) {
59 // Check GetStatistic().
60 for (const auto& category : categories_to_check)
61 EXPECT_EQ(expect_map.count(category) ? expect_map.at(category) : 0,
62 entry->GetStatistic(category));
63
64 // Check GetAllStatistics() and GetAllStatisticsAsDictionaryValue().
65 const std::map<std::string, int> actual_map = entry->GetAllStatistics();
66 const scoped_ptr<base::DictionaryValue> actual_dict =
67 entry->GetAllStatisticsAsDictionaryValue();
68
69 EXPECT_EQ(expect_map.size(), actual_map.size());
70 EXPECT_EQ(expect_map.size(), actual_dict->size());
71
72 for (const auto& item : expect_map) {
73 ASSERT_TRUE(actual_map.count(item.first));
74 ASSERT_EQ(item.second, actual_map.at(item.first));
75
76 int actual_value;
77 ASSERT_TRUE(actual_dict->GetInteger(item.first, &actual_value));
78 ASSERT_EQ(item.second, actual_value);
79 }
80 }
54 } // namespace 81 } // namespace
55 82
56 class ProfileAttributesStorageTest : public testing::Test { 83 class ProfileAttributesStorageTest : public testing::Test {
57 public: 84 public:
58 ProfileAttributesStorageTest() 85 ProfileAttributesStorageTest()
59 : testing_profile_manager_(TestingBrowserProcess::GetGlobal()) {} 86 : testing_profile_manager_(TestingBrowserProcess::GetGlobal()) {}
60 ~ProfileAttributesStorageTest() override {} 87 ~ProfileAttributesStorageTest() override {}
61 88
62 protected: 89 protected:
63 void SetUp() override { 90 void SetUp() override {
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 ASSERT_TRUE(entry->IsSupervised()); 290 ASSERT_TRUE(entry->IsSupervised());
264 ASSERT_FALSE(entry->IsChild()); 291 ASSERT_FALSE(entry->IsChild());
265 ASSERT_TRUE(entry->IsLegacySupervised()); 292 ASSERT_TRUE(entry->IsLegacySupervised());
266 293
267 entry->SetSupervisedUserId(supervised_users::kChildAccountSUID); 294 entry->SetSupervisedUserId(supervised_users::kChildAccountSUID);
268 ASSERT_TRUE(entry->IsSupervised()); 295 ASSERT_TRUE(entry->IsSupervised());
269 ASSERT_TRUE(entry->IsChild()); 296 ASSERT_TRUE(entry->IsChild());
270 ASSERT_FALSE(entry->IsLegacySupervised()); 297 ASSERT_FALSE(entry->IsLegacySupervised());
271 } 298 }
272 299
300 TEST_F(ProfileAttributesStorageTest, StatisticsAccessors) {
301 AddTestingProfile();
302
303 ProfileAttributesEntry* entry;
304 ASSERT_TRUE(storage()->GetProfileAttributesWithPath(
305 GetProfilePath("testing_profile_path0"), &entry));
306
307 EXPECT_EQ(GetProfilePath("testing_profile_path0"), entry->GetPath());
308
309 std::vector<std::string> categories_to_check{"One", "Two", "Three"};
310 std::map<std::string, int> expect_map;
311 std::vector<std::pair<std::string, int>> insertions{
312 std::make_pair("One", 3), // Insert data
313 std::make_pair("Two", 4), // Insert data
314 std::make_pair("One", 5) // Overwrite data
315 };
316
317 // Now no keys are set.
318 VerifyStatistics(entry, expect_map, categories_to_check);
319 // Insert items and test after each insert.
320 for (const auto& item : insertions) {
321 entry->SetStatistic(item.first, item.second);
322 expect_map[item.first] = item.second;
323 VerifyStatistics(entry, expect_map, categories_to_check);
324 }
325 }
326
273 TEST_F(ProfileAttributesStorageTest, ReSortTriggered) { 327 TEST_F(ProfileAttributesStorageTest, ReSortTriggered) {
274 storage()->AddProfile(GetProfilePath("alpha_path"), 328 storage()->AddProfile(GetProfilePath("alpha_path"),
275 base::ASCIIToUTF16("alpha"), 329 base::ASCIIToUTF16("alpha"),
276 std::string("alpha_gaia"), 330 std::string("alpha_gaia"),
277 base::ASCIIToUTF16("alpha_username"), 331 base::ASCIIToUTF16("alpha_username"),
278 1, 332 1,
279 std::string("")); 333 std::string(""));
280 334
281 storage()->AddProfile(GetProfilePath("lima_path"), 335 storage()->AddProfile(GetProfilePath("lima_path"),
282 base::ASCIIToUTF16("lima"), 336 base::ASCIIToUTF16("lima"),
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 // should be reflected by the ProfileAttributesStorage. 401 // should be reflected by the ProfileAttributesStorage.
348 size_t index = profile_info_cache()->GetIndexOfProfileWithPath( 402 size_t index = profile_info_cache()->GetIndexOfProfileWithPath(
349 GetProfilePath("testing_profile_path0")); 403 GetProfilePath("testing_profile_path0"));
350 EXPECT_EQ(base::ASCIIToUTF16("NewName"), 404 EXPECT_EQ(base::ASCIIToUTF16("NewName"),
351 profile_info_cache()->GetNameOfProfileAtIndex(index)); 405 profile_info_cache()->GetNameOfProfileAtIndex(index));
352 406
353 profile_info_cache()->SetNameOfProfileAtIndex( 407 profile_info_cache()->SetNameOfProfileAtIndex(
354 index, base::ASCIIToUTF16("OtherNewName")); 408 index, base::ASCIIToUTF16("OtherNewName"));
355 EXPECT_EQ(base::ASCIIToUTF16("OtherNewName"), first_entry->GetName()); 409 EXPECT_EQ(base::ASCIIToUTF16("OtherNewName"), first_entry->GetName());
356 } 410 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698