OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/search/suggestions/blacklist_store.h" | 5 #include "chrome/browser/search/suggestions/blacklist_store.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/metrics/histogram_samples.h" | |
12 #include "base/metrics/statistics_recorder.h" | |
13 #include "base/test/statistics_delta_reader.h" | |
14 #include "chrome/browser/search/suggestions/proto/suggestions.pb.h" | 11 #include "chrome/browser/search/suggestions/proto/suggestions.pb.h" |
12 #include "chrome/test/base/chrome_histogram_tester.h" | |
Ilya Sherman
2014/07/15 03:56:35
nit: Please include the //base class rather than t
Mike Lerman
2014/07/16 17:29:03
Done.
| |
15 #include "components/pref_registry/testing_pref_service_syncable.h" | 13 #include "components/pref_registry/testing_pref_service_syncable.h" |
16 #include "content/public/test/test_browser_thread_bundle.h" | 14 #include "content/public/test/test_browser_thread_bundle.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
18 | 16 |
19 using user_prefs::TestingPrefServiceSyncable; | 17 using user_prefs::TestingPrefServiceSyncable; |
20 | 18 |
21 namespace suggestions { | 19 namespace suggestions { |
22 | 20 |
23 namespace { | 21 namespace { |
24 | 22 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
116 EXPECT_TRUE(blacklist_store.BlacklistUrl(GURL(kTestUrlB))); | 114 EXPECT_TRUE(blacklist_store.BlacklistUrl(GURL(kTestUrlB))); |
117 | 115 |
118 // Expect to retrieve A or B. | 116 // Expect to retrieve A or B. |
119 EXPECT_TRUE(blacklist_store.GetFirstUrlFromBlacklist(&retrieved)); | 117 EXPECT_TRUE(blacklist_store.GetFirstUrlFromBlacklist(&retrieved)); |
120 std::string retrieved_string = retrieved.spec(); | 118 std::string retrieved_string = retrieved.spec(); |
121 EXPECT_TRUE(retrieved_string == std::string(kTestUrlA) || | 119 EXPECT_TRUE(retrieved_string == std::string(kTestUrlA) || |
122 retrieved_string == std::string(kTestUrlB)); | 120 retrieved_string == std::string(kTestUrlB)); |
123 } | 121 } |
124 | 122 |
125 TEST(BlacklistStoreLogTest, LogsBlacklistSize) { | 123 TEST(BlacklistStoreLogTest, LogsBlacklistSize) { |
124 base::HistogramTester histogram_tester; | |
126 content::TestBrowserThreadBundle bundle; | 125 content::TestBrowserThreadBundle bundle; |
127 base::StatisticsDeltaReader statistics_delta_reader; | |
128 | 126 |
129 // Create a first store - blacklist is empty at this point. | 127 // Create a first store - blacklist is empty at this point. |
130 TestingPrefServiceSyncable prefs; | 128 TestingPrefServiceSyncable prefs; |
131 BlacklistStore::RegisterProfilePrefs(prefs.registry()); | 129 BlacklistStore::RegisterProfilePrefs(prefs.registry()); |
132 scoped_ptr<BlacklistStore> blacklist_store(new BlacklistStore(&prefs)); | 130 scoped_ptr<BlacklistStore> blacklist_store(new BlacklistStore(&prefs)); |
133 scoped_ptr<base::HistogramSamples> samples( | 131 |
134 statistics_delta_reader.GetHistogramSamplesSinceCreation( | 132 histogram_tester.ExpectTotalCount("Suggestions.LocalBlacklistSize", 1); |
135 "Suggestions.LocalBlacklistSize")); | 133 histogram_tester.ExpectUniqueSample("Suggestions.LocalBlacklistSize", 0, 1); |
136 EXPECT_EQ(1, samples->TotalCount()); | |
137 EXPECT_EQ(1, samples->GetCount(0)); | |
138 | 134 |
139 // Add some content to the blacklist. | 135 // Add some content to the blacklist. |
140 EXPECT_TRUE(blacklist_store->BlacklistUrl(GURL(kTestUrlA))); | 136 EXPECT_TRUE(blacklist_store->BlacklistUrl(GURL(kTestUrlA))); |
141 EXPECT_TRUE(blacklist_store->BlacklistUrl(GURL(kTestUrlB))); | 137 EXPECT_TRUE(blacklist_store->BlacklistUrl(GURL(kTestUrlB))); |
142 | 138 |
143 // Create a new BlacklistStore and verify the counts. | 139 // Create a new BlacklistStore and verify the counts. |
144 blacklist_store.reset(new BlacklistStore(&prefs)); | 140 blacklist_store.reset(new BlacklistStore(&prefs)); |
145 samples = statistics_delta_reader.GetHistogramSamplesSinceCreation( | 141 |
146 "Suggestions.LocalBlacklistSize"); | 142 histogram_tester.ExpectTotalCount("Suggestions.LocalBlacklistSize", 2); |
147 EXPECT_EQ(2, samples->TotalCount()); | 143 histogram_tester.ExpectBucketCount("Suggestions.LocalBlacklistSize", 0, 1); |
148 EXPECT_EQ(1, samples->GetCount(0)); | 144 histogram_tester.ExpectBucketCount("Suggestions.LocalBlacklistSize", 2, 1); |
Ilya Sherman
2014/07/15 03:56:35
Hmm, it's a bit unfortunate that both the second a
Mike Lerman
2014/07/16 17:29:03
Use Objective-C? I agree, this is ugly. Can't thin
Ilya Sherman
2014/07/16 18:44:46
Hmm, that's definitely an interesting thought, wor
Mike Lerman
2014/07/16 19:36:35
Acknowledged.
| |
149 EXPECT_EQ(1, samples->GetCount(2)); | |
150 } | 145 } |
151 | 146 |
152 } // namespace suggestions | 147 } // namespace suggestions |
OLD | NEW |