| OLD | NEW |
| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 } | 76 } |
| 75 } | 77 } |
| 76 | 78 |
| 77 std::map<std::string, int> expected; | 79 std::map<std::string, int> expected; |
| 78 // Now no keys are set. | 80 // Now no keys are set. |
| 79 VerifyStatisticsCache(profile_path, expected, categories_to_check); | 81 VerifyStatisticsCache(profile_path, expected, categories_to_check); |
| 80 // Insert items and test after each insert. | 82 // Insert items and test after each insert. |
| 81 for (const auto& item : insertions) { | 83 for (const auto& item : insertions) { |
| 82 profiles::SetProfileStatisticsInCache(profile_path, item.first, | 84 ProfileStatistics::SetProfileStatisticsInCache(profile_path, item.first, |
| 83 item.second); | 85 item.second); |
| 84 expected[item.first] = item.second; | 86 expected[item.first] = item.second; |
| 85 VerifyStatisticsCache(profile_path, expected, categories_to_check); | 87 VerifyStatisticsCache(profile_path, expected, categories_to_check); |
| 86 } | 88 } |
| 87 } | 89 } |
| OLD | NEW |