| Index: chrome/browser/profiles/profile_attributes_storage_unittest.cc
|
| diff --git a/chrome/browser/profiles/profile_attributes_storage_unittest.cc b/chrome/browser/profiles/profile_attributes_storage_unittest.cc
|
| index b3668121d249b0c1db37cf2f84bbbca2681054f2..4e8d5483801530cb47b0fcad1502d2025a8325e4 100644
|
| --- a/chrome/browser/profiles/profile_attributes_storage_unittest.cc
|
| +++ b/chrome/browser/profiles/profile_attributes_storage_unittest.cc
|
| @@ -4,6 +4,7 @@
|
|
|
| #include "base/strings/stringprintf.h"
|
| #include "base/strings/utf_string_conversions.h"
|
| +#include "base/values.h"
|
| #include "chrome/browser/profiles/profile_info_cache.h"
|
| #include "chrome/browser/profiles/profile_manager.h"
|
| #include "chrome/browser/supervised_user/supervised_user_constants.h"
|
| @@ -51,6 +52,32 @@ void TestAccessors(ProfileAttributesEntry** entry,
|
| (*entry->*setter_func)(second_value);
|
| EXPECT_EQ(second_value, (*entry->*getter_func)());
|
| }
|
| +
|
| +void VerifyStatistics(const ProfileAttributesEntry * const entry,
|
| + const std::map<std::string, int>& expect_map,
|
| + const std::vector<std::string>& categories_to_check) {
|
| + // Check GetStatistic().
|
| + for (const auto& category : categories_to_check)
|
| + EXPECT_EQ(expect_map.count(category) ? expect_map.at(category) : 0,
|
| + entry->GetStatistic(category));
|
| +
|
| + // Check GetAllStatistics() and GetAllStatisticsAsDictionaryValue().
|
| + const std::map<std::string, int> actual_map = entry->GetAllStatistics();
|
| + const scoped_ptr<base::DictionaryValue> actual_dict =
|
| + entry->GetAllStatisticsAsDictionaryValue();
|
| +
|
| + EXPECT_EQ(expect_map.size(), actual_map.size());
|
| + EXPECT_EQ(expect_map.size(), actual_dict->size());
|
| +
|
| + for (const auto& item : expect_map) {
|
| + ASSERT_TRUE(actual_map.count(item.first));
|
| + ASSERT_EQ(item.second, actual_map.at(item.first));
|
| +
|
| + int actual_value;
|
| + ASSERT_TRUE(actual_dict->GetInteger(item.first, &actual_value));
|
| + ASSERT_EQ(item.second, actual_value);
|
| + }
|
| +}
|
| } // namespace
|
|
|
| class ProfileAttributesStorageTest : public testing::Test {
|
| @@ -270,6 +297,33 @@ TEST_F(ProfileAttributesStorageTest, SupervisedUsersAccessors) {
|
| ASSERT_FALSE(entry->IsLegacySupervised());
|
| }
|
|
|
| +TEST_F(ProfileAttributesStorageTest, StatisticsAccessors) {
|
| + AddTestingProfile();
|
| +
|
| + ProfileAttributesEntry* entry;
|
| + ASSERT_TRUE(storage()->GetProfileAttributesWithPath(
|
| + GetProfilePath("testing_profile_path0"), &entry));
|
| +
|
| + EXPECT_EQ(GetProfilePath("testing_profile_path0"), entry->GetPath());
|
| +
|
| + std::vector<std::string> categories_to_check{"One", "Two", "Three"};
|
| + std::map<std::string, int> expect_map;
|
| + std::vector<std::pair<std::string, int>> insertions{
|
| + std::make_pair("One", 3), // Insert data
|
| + std::make_pair("Two", 4), // Insert data
|
| + std::make_pair("One", 5) // Overwrite data
|
| + };
|
| +
|
| + // Now no keys are set.
|
| + VerifyStatistics(entry, expect_map, categories_to_check);
|
| + // Insert items and test after each insert.
|
| + for (const auto& item : insertions) {
|
| + entry->SetStatistic(item.first, item.second);
|
| + expect_map[item.first] = item.second;
|
| + VerifyStatistics(entry, expect_map, categories_to_check);
|
| + }
|
| +}
|
| +
|
| TEST_F(ProfileAttributesStorageTest, ReSortTriggered) {
|
| storage()->AddProfile(GetProfilePath("alpha_path"),
|
| base::ASCIIToUTF16("alpha"),
|
|
|