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

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

Issue 1579433002: Make profile statistics tasks inspectable by tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Renamed ProfileAttributesStorage related functions in profile_statistics.* Created 4 years, 9 months 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 <map> 5 #include <map>
6 #include <set> 6 #include <set>
7 #include <utility>
7 #include <vector> 8 #include <vector>
8 9
9 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
10 #include "chrome/browser/profiles/profile_statistics.h" 11 #include "chrome/browser/profiles/profile_statistics.h"
12 #include "chrome/browser/profiles/profile_statistics_common.h"
11 #include "chrome/test/base/testing_browser_process.h" 13 #include "chrome/test/base/testing_browser_process.h"
12 #include "chrome/test/base/testing_profile.h" 14 #include "chrome/test/base/testing_profile.h"
13 #include "chrome/test/base/testing_profile_manager.h" 15 #include "chrome/test/base/testing_profile_manager.h"
14 #include "content/public/test/test_browser_thread_bundle.h" 16 #include "content/public/test/test_browser_thread_bundle.h"
15 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
16 18
17 namespace { 19 namespace {
18 void VerifyStatisticsCache(const base::FilePath& profile_path, 20 void VerifyStatisticsCache(const base::FilePath& profile_path,
19 const std::map<std::string, int>& expected, 21 const std::map<std::string, int>& expected,
20 const std::vector<std::string>& categories_to_check) { 22 const std::vector<std::string>& categories_to_check) {
21 const profiles::ProfileCategoryStats actual = 23 const profiles::ProfileCategoryStats actual =
22 profiles::GetProfileStatisticsFromCache(profile_path); 24 ProfileStatistics::GetProfileStatisticsFromAttributesStorage(
25 profile_path);
23 26
24 EXPECT_EQ(categories_to_check.size(), actual.size()); 27 EXPECT_EQ(categories_to_check.size(), actual.size());
25 28
26 std::set<std::string> checked; 29 std::set<std::string> checked;
27 for (const auto& stat : actual) { 30 for (const auto& stat : actual) {
28 bool has_category = expected.count(stat.category); 31 bool has_category = expected.count(stat.category);
29 EXPECT_EQ(has_category, stat.success); 32 EXPECT_EQ(has_category, stat.success);
30 EXPECT_EQ(has_category ? expected.at(stat.category) : 0, stat.count); 33 EXPECT_EQ(has_category ? expected.at(stat.category) : 0, stat.count);
31 EXPECT_TRUE(checked.insert(stat.category).second); 34 EXPECT_TRUE(checked.insert(stat.category).second);
32 } 35 }
(...skipping 13 matching lines...) Expand all
46 void TearDown() override { 49 void TearDown() override {
47 } 50 }
48 51
49 TestingProfileManager* manager() { return &manager_; } 52 TestingProfileManager* manager() { return &manager_; }
50 53
51 private: 54 private:
52 TestingProfileManager manager_; 55 TestingProfileManager manager_;
53 content::TestBrowserThreadBundle thread_bundle_; 56 content::TestBrowserThreadBundle thread_bundle_;
54 }; 57 };
55 58
56 TEST_F(ProfileStatisticsTest, ProfileInfoCacheStorage) { 59 TEST_F(ProfileStatisticsTest, ProfileAttributesStorage) {
57 TestingProfile* profile = manager()->CreateTestingProfile("Test 1"); 60 TestingProfile* profile = manager()->CreateTestingProfile("Test 1");
58 ASSERT_TRUE(profile); 61 ASSERT_TRUE(profile);
59 base::FilePath profile_path = profile->GetPath(); 62 base::FilePath profile_path = profile->GetPath();
60 63
61 std::vector<std::string> categories_to_check{ 64 std::vector<std::string> categories_to_check;
62 profiles::kProfileStatisticsBrowsingHistory, 65 categories_to_check.push_back(profiles::kProfileStatisticsBrowsingHistory);
63 profiles::kProfileStatisticsPasswords, 66 categories_to_check.push_back(profiles::kProfileStatisticsPasswords);
64 profiles::kProfileStatisticsBookmarks, 67 categories_to_check.push_back(profiles::kProfileStatisticsBookmarks);
65 profiles::kProfileStatisticsSettings 68 categories_to_check.push_back(profiles::kProfileStatisticsSettings);
66 };
67 69
68 std::vector<std::pair<std::string, int>> insertions; 70 std::vector<std::pair<std::string, int>> insertions;
69 int num = 3; 71 int num = 3;
70 // Insert for the first round, overwrite for the second round. 72 // Insert for the first round, overwrite for the second round.
71 for (int i = 0; i < 2; i++) { 73 for (int i = 0; i < 2; i++) {
72 for (const auto& category : categories_to_check) { 74 for (const auto& category : categories_to_check)
73 insertions.push_back(std::make_pair(category, num++)); 75 insertions.push_back(std::make_pair(category, num++));
74 }
75 } 76 }
76 77
77 std::map<std::string, int> expected; 78 std::map<std::string, int> expected;
78 // Now no keys are set. 79 // Now no keys are set.
79 VerifyStatisticsCache(profile_path, expected, categories_to_check); 80 VerifyStatisticsCache(profile_path, expected, categories_to_check);
80 // Insert items and test after each insert. 81 // Insert items and test after each insert.
81 for (const auto& item : insertions) { 82 for (const auto& item : insertions) {
82 profiles::SetProfileStatisticsInCache(profile_path, item.first, 83 ProfileStatistics::SetProfileStatisticsToAttributesStorage(
83 item.second); 84 profile_path, item.first, item.second);
84 expected[item.first] = item.second; 85 expected[item.first] = item.second;
85 VerifyStatisticsCache(profile_path, expected, categories_to_check); 86 VerifyStatisticsCache(profile_path, expected, categories_to_check);
86 } 87 }
87 } 88 }
OLDNEW
« no previous file with comments | « chrome/browser/profiles/profile_statistics_factory.cc ('k') | chrome/browser/ui/webui/signin/user_manager_screen_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698