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

Side by Side Diff: components/suggestions/blacklist_store_unittest.cc

Issue 379283002: Rework UMAHistogramHelper and StatisticsDeltaReader into [Chrome]HistogramTester. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « chrome/test/nacl/nacl_browsertest_uma.cc ('k') | content/public/test/browser_test_utils.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "components/suggestions/blacklist_store.h" 5 #include "components/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" 11
12 #include "base/metrics/statistics_recorder.h" 12 #include "base/test/histogram_tester.h"
13 #include "base/test/statistics_delta_reader.h"
14 #include "components/pref_registry/testing_pref_service_syncable.h" 13 #include "components/pref_registry/testing_pref_service_syncable.h"
15 #include "components/suggestions/proto/suggestions.pb.h" 14 #include "components/suggestions/proto/suggestions.pb.h"
16 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
17 16
18 using user_prefs::TestingPrefServiceSyncable; 17 using user_prefs::TestingPrefServiceSyncable;
19 18
20 namespace suggestions { 19 namespace suggestions {
21 20
22 namespace { 21 namespace {
23 22
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 EXPECT_TRUE(blacklist_store.BlacklistUrl(GURL(kTestUrlB))); 125 EXPECT_TRUE(blacklist_store.BlacklistUrl(GURL(kTestUrlB)));
127 126
128 // Expect to retrieve A or B. 127 // Expect to retrieve A or B.
129 EXPECT_TRUE(blacklist_store.GetFirstUrlFromBlacklist(&retrieved)); 128 EXPECT_TRUE(blacklist_store.GetFirstUrlFromBlacklist(&retrieved));
130 std::string retrieved_string = retrieved.spec(); 129 std::string retrieved_string = retrieved.spec();
131 EXPECT_TRUE(retrieved_string == std::string(kTestUrlA) || 130 EXPECT_TRUE(retrieved_string == std::string(kTestUrlA) ||
132 retrieved_string == std::string(kTestUrlB)); 131 retrieved_string == std::string(kTestUrlB));
133 } 132 }
134 133
135 TEST_F(BlacklistStoreTest, LogsBlacklistSize) { 134 TEST_F(BlacklistStoreTest, LogsBlacklistSize) {
136 base::StatisticsDeltaReader statistics_delta_reader; 135 base::HistogramTester histogram_tester;
137 136
138 // Create a first store - blacklist is empty at this point. 137 // Create a first store - blacklist is empty at this point.
139 scoped_ptr<BlacklistStore> blacklist_store( 138 scoped_ptr<BlacklistStore> blacklist_store(
140 new BlacklistStore(pref_service())); 139 new BlacklistStore(pref_service()));
141 scoped_ptr<base::HistogramSamples> samples( 140
142 statistics_delta_reader.GetHistogramSamplesSinceCreation( 141 histogram_tester.ExpectTotalCount("Suggestions.LocalBlacklistSize", 1);
143 "Suggestions.LocalBlacklistSize")); 142 histogram_tester.ExpectUniqueSample("Suggestions.LocalBlacklistSize", 0, 1);
144 EXPECT_EQ(1, samples->TotalCount());
145 EXPECT_EQ(1, samples->GetCount(0));
146 143
147 // Add some content to the blacklist. 144 // Add some content to the blacklist.
148 EXPECT_TRUE(blacklist_store->BlacklistUrl(GURL(kTestUrlA))); 145 EXPECT_TRUE(blacklist_store->BlacklistUrl(GURL(kTestUrlA)));
149 EXPECT_TRUE(blacklist_store->BlacklistUrl(GURL(kTestUrlB))); 146 EXPECT_TRUE(blacklist_store->BlacklistUrl(GURL(kTestUrlB)));
150 147
151 // Create a new BlacklistStore and verify the counts. 148 // Create a new BlacklistStore and verify the counts.
152 blacklist_store.reset(new BlacklistStore(pref_service())); 149 blacklist_store.reset(new BlacklistStore(pref_service()));
153 samples = statistics_delta_reader.GetHistogramSamplesSinceCreation( 150
154 "Suggestions.LocalBlacklistSize"); 151 histogram_tester.ExpectTotalCount("Suggestions.LocalBlacklistSize", 2);
155 EXPECT_EQ(2, samples->TotalCount()); 152 histogram_tester.ExpectBucketCount("Suggestions.LocalBlacklistSize", 0, 1);
156 EXPECT_EQ(1, samples->GetCount(0)); 153 histogram_tester.ExpectBucketCount("Suggestions.LocalBlacklistSize", 2, 1);
157 EXPECT_EQ(1, samples->GetCount(2));
158 } 154 }
159 155
160 } // namespace suggestions 156 } // namespace suggestions
OLDNEW
« no previous file with comments | « chrome/test/nacl/nacl_browsertest_uma.cc ('k') | content/public/test/browser_test_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698