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

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: Changed gyp/gn files, also a few small changes 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 <vector> 7 #include <vector>
8 8
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "chrome/browser/profiles/profile_statistics.h" 10 #include "chrome/browser/profiles/profile_statistics.h"
11 #include "chrome/browser/profiles/profile_statistics_constants.h"
12 #include "chrome/browser/profiles/profile_statistics_types.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::GetProfileStatisticsFromCache(profile_path);
23 25
24 EXPECT_EQ(categories_to_check.size(), actual.size()); 26 EXPECT_EQ(categories_to_check.size(), actual.size());
25 27
26 std::set<std::string> checked; 28 std::set<std::string> checked;
27 for (const auto& stat : actual) { 29 for (const auto& stat : actual) {
28 bool has_category = expected.count(stat.category); 30 bool has_category = expected.count(stat.category);
29 EXPECT_EQ(has_category, stat.success); 31 EXPECT_EQ(has_category, stat.success);
30 EXPECT_EQ(has_category ? expected.at(stat.category) : 0, stat.count); 32 EXPECT_EQ(has_category ? expected.at(stat.category) : 0, stat.count);
31 EXPECT_TRUE(checked.insert(stat.category).second); 33 EXPECT_TRUE(checked.insert(stat.category).second);
32 } 34 }
(...skipping 18 matching lines...) Expand all
51 private: 53 private:
52 TestingProfileManager manager_; 54 TestingProfileManager manager_;
53 content::TestBrowserThreadBundle thread_bundle_; 55 content::TestBrowserThreadBundle thread_bundle_;
54 }; 56 };
55 57
56 TEST_F(ProfileStatisticsTest, ProfileInfoCacheStorage) { 58 TEST_F(ProfileStatisticsTest, ProfileInfoCacheStorage) {
57 TestingProfile* profile = manager()->CreateTestingProfile("Test 1"); 59 TestingProfile* profile = manager()->CreateTestingProfile("Test 1");
58 ASSERT_TRUE(profile); 60 ASSERT_TRUE(profile);
59 base::FilePath profile_path = profile->GetPath(); 61 base::FilePath profile_path = profile->GetPath();
60 62
61 std::vector<std::string> categories_to_check{ 63 std::vector<std::string> categories_to_check;
62 profiles::kProfileStatisticsBrowsingHistory, 64 categories_to_check.push_back(profiles::kProfileStatisticsBrowsingHistory);
63 profiles::kProfileStatisticsPasswords, 65 categories_to_check.push_back(profiles::kProfileStatisticsPasswords);
64 profiles::kProfileStatisticsBookmarks, 66 categories_to_check.push_back(profiles::kProfileStatisticsBookmarks);
65 profiles::kProfileStatisticsSettings 67 categories_to_check.push_back(profiles::kProfileStatisticsSettings);
66 };
67 68
68 std::vector<std::pair<std::string, int>> insertions; 69 std::vector<std::pair<std::string, int>> insertions;
69 int num = 3; 70 int num = 3;
70 // Insert for the first round, overwrite for the second round. 71 // Insert for the first round, overwrite for the second round.
71 for (int i = 0; i < 2; i++) { 72 for (int i = 0; i < 2; i++) {
72 for (const auto& category : categories_to_check) { 73 for (const auto& category : categories_to_check)
73 insertions.push_back(std::make_pair(category, num++)); 74 insertions.push_back(std::make_pair(category, num++));
74 }
75 } 75 }
76 76
77 std::map<std::string, int> expected; 77 std::map<std::string, int> expected;
78 // Now no keys are set. 78 // Now no keys are set.
79 VerifyStatisticsCache(profile_path, expected, categories_to_check); 79 VerifyStatisticsCache(profile_path, expected, categories_to_check);
80 // Insert items and test after each insert. 80 // Insert items and test after each insert.
81 for (const auto& item : insertions) { 81 for (const auto& item : insertions) {
82 profiles::SetProfileStatisticsInCache(profile_path, item.first, 82 ProfileStatistics::SetProfileStatisticsInCache(profile_path, item.first,
83 item.second); 83 item.second);
84 expected[item.first] = item.second; 84 expected[item.first] = item.second;
85 VerifyStatisticsCache(profile_path, expected, categories_to_check); 85 VerifyStatisticsCache(profile_path, expected, categories_to_check);
86 } 86 }
87 } 87 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698