OLD | NEW |
---|---|
(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 "chrome/browser/profiles/profile_statistics.h" | |
10 #include "chrome/test/base/testing_browser_process.h" | |
11 #include "chrome/test/base/testing_profile.h" | |
12 #include "chrome/test/base/testing_profile_manager.h" | |
13 #include "content/public/test/test_browser_thread_bundle.h" | |
14 #include "testing/gtest/include/gtest/gtest.h" | |
15 | |
16 namespace { | |
17 void VerifyStatisticsCache(Profile* profile, | |
18 const std::map<std::string, int>& expected, | |
lwchkg
2015/11/18 17:34:53
Wrong indent here. Done.
| |
19 const std::vector<std::string>& categories_to_check) { | |
20 ASSERT_TRUE(profile); | |
21 | |
22 const profiles::ProfileCategoryStats actual = | |
23 profiles::GetProfileStatisticsFromCache(profile); | |
24 | |
25 EXPECT_EQ(categories_to_check.size(), actual.size()); | |
26 | |
27 std::set<std::string> checked; | |
28 for (const auto& stat : actual) { | |
29 bool has_category = expected.count(stat.category); | |
30 EXPECT_EQ(has_category, stat.success); | |
31 EXPECT_EQ(has_category ? expected.at(stat.category) : 0, stat.count); | |
32 EXPECT_TRUE(checked.insert(stat.category).second); | |
33 } | |
34 } | |
35 } // namespace | |
36 | |
37 class ProfileStatisticsTest : public testing::Test { | |
38 public: | |
39 ProfileStatisticsTest() : manager_(TestingBrowserProcess::GetGlobal()) {} | |
40 ~ProfileStatisticsTest() override {} | |
41 | |
42 protected: | |
43 void SetUp() override { | |
44 ASSERT_TRUE(manager_.SetUp()); | |
45 } | |
46 | |
47 void TearDown() override { | |
48 } | |
49 | |
50 TestingProfileManager* manager() { return &manager_; } | |
51 | |
52 private: | |
53 TestingProfileManager manager_; | |
54 content::TestBrowserThreadBundle thread_bundle_; | |
55 }; | |
56 | |
57 TEST_F(ProfileStatisticsTest, ProfileInfoCacheStorage) { | |
58 TestingProfile* profile = manager()->CreateTestingProfile("Test 1"); | |
59 ASSERT_TRUE(profile); | |
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, expected, categories_to_check); | |
80 // Insert items and test after each insert. | |
81 for (const auto& item : insertions) { | |
82 profiles::StoreProfileStatisticsToCache(profile, item.first, item.second); | |
83 expected[item.first] = item.second; | |
84 VerifyStatisticsCache(profile, expected, categories_to_check); | |
85 } | |
86 } | |
OLD | NEW |