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

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

Issue 1415223002: Add counts of User data to ProfileInfoCache (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Bug fix. Removed a non-trivial style fix (will upload in another CL). 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
« no previous file with comments | « chrome/browser/profiles/profile_statistics.cc ('k') | chrome/chrome_tests_unit.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include <map>
6 #include <set>
7 #include <vector>
8
9 #include "base/files/file_path.h"
10 #include "chrome/browser/profiles/profile_statistics.h"
11 #include "chrome/test/base/testing_browser_process.h"
12 #include "chrome/test/base/testing_profile.h"
13 #include "chrome/test/base/testing_profile_manager.h"
14 #include "content/public/test/test_browser_thread_bundle.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16
17 namespace {
18 void VerifyStatisticsCache(const base::FilePath& profile_path,
19 const std::map<std::string, int>& expected,
20 const std::vector<std::string>& categories_to_check) {
21 const profiles::ProfileCategoryStats actual =
22 profiles::GetProfileStatisticsFromCache(profile_path);
23
24 EXPECT_EQ(categories_to_check.size(), actual.size());
25
26 std::set<std::string> checked;
27 for (const auto& stat : actual) {
28 bool has_category = expected.count(stat.category);
29 EXPECT_EQ(has_category, stat.success);
30 EXPECT_EQ(has_category ? expected.at(stat.category) : 0, stat.count);
31 EXPECT_TRUE(checked.insert(stat.category).second);
32 }
33 }
34 } // namespace
35
36 class ProfileStatisticsTest : public testing::Test {
37 public:
38 ProfileStatisticsTest() : manager_(TestingBrowserProcess::GetGlobal()) {}
39 ~ProfileStatisticsTest() override {}
40
41 protected:
42 void SetUp() override {
43 ASSERT_TRUE(manager_.SetUp());
44 }
45
46 void TearDown() override {
47 }
48
49 TestingProfileManager* manager() { return &manager_; }
50
51 private:
52 TestingProfileManager manager_;
53 content::TestBrowserThreadBundle thread_bundle_;
54 };
55
56 TEST_F(ProfileStatisticsTest, ProfileInfoCacheStorage) {
57 TestingProfile* profile = manager()->CreateTestingProfile("Test 1");
58 ASSERT_TRUE(profile);
59 base::FilePath profile_path = profile->GetPath();
60
61 std::vector<std::string> categories_to_check{
62 profiles::kProfileStatisticsBrowsingHistory,
63 profiles::kProfileStatisticsPasswords,
64 profiles::kProfileStatisticsBookmarks,
65 profiles::kProfileStatisticsSettings
66 };
67
68 std::vector<std::pair<std::string, int>> insertions;
69 int num = 3;
70 // Insert for the first round, overwrite for the second round.
71 for (int i = 0; i < 2; i++) {
72 for (const auto& category : categories_to_check) {
73 insertions.push_back(std::make_pair(category, num++));
74 }
75 }
76
77 std::map<std::string, int> expected;
78 // Now no keys are set.
79 VerifyStatisticsCache(profile_path, expected, categories_to_check);
80 // Insert items and test after each insert.
81 for (const auto& item : insertions) {
82 profiles::SetProfileStatisticsInCache(profile_path, item.first,
83 item.second);
84 expected[item.first] = item.second;
85 VerifyStatisticsCache(profile_path, expected, categories_to_check);
86 }
87 }
OLDNEW
« no previous file with comments | « chrome/browser/profiles/profile_statistics.cc ('k') | chrome/chrome_tests_unit.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698