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 "components/suggestions/blacklist_store.h" | 5 #include "components/suggestions/blacklist_store.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/test/histogram_tester.h" | 12 #include "base/test/histogram_tester.h" |
13 #include "components/pref_registry/testing_pref_service_syncable.h" | |
14 #include "components/suggestions/proto/suggestions.pb.h" | 13 #include "components/suggestions/proto/suggestions.pb.h" |
| 14 #include "components/sync_preferences/testing_pref_service_syncable.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 | 16 |
17 using user_prefs::TestingPrefServiceSyncable; | 17 using sync_preferences::TestingPrefServiceSyncable; |
18 | 18 |
19 namespace suggestions { | 19 namespace suggestions { |
20 | 20 |
21 namespace { | 21 namespace { |
22 | 22 |
23 const char kTestUrlA[] = "http://aaa.com/"; | 23 const char kTestUrlA[] = "http://aaa.com/"; |
24 const char kTestUrlB[] = "http://bbb.com/"; | 24 const char kTestUrlB[] = "http://bbb.com/"; |
25 const char kTestUrlC[] = "http://ccc.com/"; | 25 const char kTestUrlC[] = "http://ccc.com/"; |
26 const char kTestUrlD[] = "http://ddd.com/"; | 26 const char kTestUrlD[] = "http://ddd.com/"; |
27 | 27 |
(...skipping 18 matching lines...) Expand all Loading... |
46 EXPECT_EQ(expected.suggestions(i).thumbnail(), | 46 EXPECT_EQ(expected.suggestions(i).thumbnail(), |
47 actual.suggestions(i).thumbnail()); | 47 actual.suggestions(i).thumbnail()); |
48 } | 48 } |
49 } | 49 } |
50 | 50 |
51 } // namespace | 51 } // namespace |
52 | 52 |
53 class BlacklistStoreTest : public testing::Test { | 53 class BlacklistStoreTest : public testing::Test { |
54 public: | 54 public: |
55 BlacklistStoreTest() | 55 BlacklistStoreTest() |
56 : pref_service_(new user_prefs::TestingPrefServiceSyncable) {} | 56 : pref_service_(new sync_preferences::TestingPrefServiceSyncable) {} |
57 | 57 |
58 void SetUp() override { | 58 void SetUp() override { |
59 BlacklistStore::RegisterProfilePrefs(pref_service()->registry()); | 59 BlacklistStore::RegisterProfilePrefs(pref_service()->registry()); |
60 } | 60 } |
61 | 61 |
62 user_prefs::TestingPrefServiceSyncable* pref_service() { | 62 sync_preferences::TestingPrefServiceSyncable* pref_service() { |
63 return pref_service_.get(); | 63 return pref_service_.get(); |
64 } | 64 } |
65 | 65 |
66 private: | 66 private: |
67 std::unique_ptr<user_prefs::TestingPrefServiceSyncable> pref_service_; | 67 std::unique_ptr<sync_preferences::TestingPrefServiceSyncable> pref_service_; |
68 | 68 |
69 DISALLOW_COPY_AND_ASSIGN(BlacklistStoreTest); | 69 DISALLOW_COPY_AND_ASSIGN(BlacklistStoreTest); |
70 }; | 70 }; |
71 | 71 |
72 // Tests adding, removing to the blacklist and filtering. | 72 // Tests adding, removing to the blacklist and filtering. |
73 TEST_F(BlacklistStoreTest, BasicInteractions) { | 73 TEST_F(BlacklistStoreTest, BasicInteractions) { |
74 BlacklistStore blacklist_store(pref_service()); | 74 BlacklistStore blacklist_store(pref_service()); |
75 | 75 |
76 // Create suggestions with A, B and C. C and D will be added to the blacklist. | 76 // Create suggestions with A, B and C. C and D will be added to the blacklist. |
77 std::set<std::string> suggested_urls; | 77 std::set<std::string> suggested_urls; |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 EXPECT_TRUE(blacklist_store->BlacklistUrl(GURL(kTestUrlB))); | 187 EXPECT_TRUE(blacklist_store->BlacklistUrl(GURL(kTestUrlB))); |
188 | 188 |
189 // Create a new BlacklistStore and verify the counts. | 189 // Create a new BlacklistStore and verify the counts. |
190 blacklist_store.reset(new BlacklistStore(pref_service())); | 190 blacklist_store.reset(new BlacklistStore(pref_service())); |
191 histogram_tester.ExpectTotalCount("Suggestions.LocalBlacklistSize", 2); | 191 histogram_tester.ExpectTotalCount("Suggestions.LocalBlacklistSize", 2); |
192 histogram_tester.ExpectBucketCount("Suggestions.LocalBlacklistSize", 0, 1); | 192 histogram_tester.ExpectBucketCount("Suggestions.LocalBlacklistSize", 0, 1); |
193 histogram_tester.ExpectBucketCount("Suggestions.LocalBlacklistSize", 2, 1); | 193 histogram_tester.ExpectBucketCount("Suggestions.LocalBlacklistSize", 2, 1); |
194 } | 194 } |
195 | 195 |
196 } // namespace suggestions | 196 } // namespace suggestions |
OLD | NEW |