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

Unified 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: Change GetStatistic from int(...) back to bool(..., int*) 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 side-by-side diff with in-line comments
Download patch
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..7f2f6350fe0defb4a9a5e91925f9794ed910946c 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,27 @@ 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) {
+ bool has_category = expect_map.count(category);
+ int actual_value;
+ ASSERT_EQ(has_category, entry->GetStatistic(category, &actual_value));
+ if (has_category)
+ EXPECT_EQ(expect_map.at(category), actual_value);
+ }
+
+ // Check GetAllStatistics()
+ const std::map<std::string, int> actual_map = entry->GetAllStatistics();
+ EXPECT_EQ(expect_map.size(), actual_map.size());
+ for (const auto& item : expect_map) {
+ ASSERT_TRUE(actual_map.count(item.first));
+ ASSERT_EQ(item.second, actual_map.at(item.first));
+ }
+}
} // namespace
class ProfileAttributesStorageTest : public testing::Test {
@@ -270,6 +292,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"),

Powered by Google App Engine
This is Rietveld 408576698