| 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/suggestions_store.h" | 5 #include "components/suggestions/suggestions_store.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/test/simple_test_clock.h" | 13 #include "base/test/simple_test_clock.h" |
| 14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 15 #include "components/pref_registry/testing_pref_service_syncable.h" | |
| 16 #include "components/suggestions/proto/suggestions.pb.h" | 15 #include "components/suggestions/proto/suggestions.pb.h" |
| 16 #include "components/sync_preferences/testing_pref_service_syncable.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 18 |
| 19 using user_prefs::TestingPrefServiceSyncable; | 19 using sync_preferences::TestingPrefServiceSyncable; |
| 20 | 20 |
| 21 namespace suggestions { | 21 namespace suggestions { |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 const char kTestTitle[] = "Foo site"; | 25 const char kTestTitle[] = "Foo site"; |
| 26 const char kTestUrl[] = "http://foo.com/"; | 26 const char kTestUrl[] = "http://foo.com/"; |
| 27 | 27 |
| 28 void AddSuggestion(SuggestionsProfile* suggestions, | 28 void AddSuggestion(SuggestionsProfile* suggestions, |
| 29 const char* title, | 29 const char* title, |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 EXPECT_EQ(expected.suggestions(i).thumbnail(), | 75 EXPECT_EQ(expected.suggestions(i).thumbnail(), |
| 76 actual.suggestions(i).thumbnail()); | 76 actual.suggestions(i).thumbnail()); |
| 77 } | 77 } |
| 78 } | 78 } |
| 79 | 79 |
| 80 } // namespace | 80 } // namespace |
| 81 | 81 |
| 82 class SuggestionsStoreTest : public testing::Test { | 82 class SuggestionsStoreTest : public testing::Test { |
| 83 public: | 83 public: |
| 84 SuggestionsStoreTest() | 84 SuggestionsStoreTest() |
| 85 : pref_service_(new user_prefs::TestingPrefServiceSyncable) {} | 85 : pref_service_(new sync_preferences::TestingPrefServiceSyncable) {} |
| 86 | 86 |
| 87 void SetUp() override { | 87 void SetUp() override { |
| 88 SuggestionsStore::RegisterProfilePrefs(pref_service_->registry()); | 88 SuggestionsStore::RegisterProfilePrefs(pref_service_->registry()); |
| 89 suggestions_store_.reset(new SuggestionsStore(pref_service_.get())); | 89 suggestions_store_.reset(new SuggestionsStore(pref_service_.get())); |
| 90 | 90 |
| 91 base::SimpleTestClock* test_clock(new base::SimpleTestClock()); | 91 base::SimpleTestClock* test_clock(new base::SimpleTestClock()); |
| 92 current_time = base::Time::FromInternalValue(13063394337546738); | 92 current_time = base::Time::FromInternalValue(13063394337546738); |
| 93 test_clock->SetNow(current_time); | 93 test_clock->SetNow(current_time); |
| 94 suggestions_store_->SetClockForTesting(base::WrapUnique(test_clock)); | 94 suggestions_store_->SetClockForTesting(base::WrapUnique(test_clock)); |
| 95 } | 95 } |
| 96 | 96 |
| 97 protected: | 97 protected: |
| 98 std::unique_ptr<user_prefs::TestingPrefServiceSyncable> pref_service_; | 98 std::unique_ptr<sync_preferences::TestingPrefServiceSyncable> pref_service_; |
| 99 std::unique_ptr<SuggestionsStore> suggestions_store_; | 99 std::unique_ptr<SuggestionsStore> suggestions_store_; |
| 100 base::Time current_time; | 100 base::Time current_time; |
| 101 | 101 |
| 102 DISALLOW_COPY_AND_ASSIGN(SuggestionsStoreTest); | 102 DISALLOW_COPY_AND_ASSIGN(SuggestionsStoreTest); |
| 103 }; | 103 }; |
| 104 | 104 |
| 105 // Tests LoadSuggestions function to filter expired suggestions. | 105 // Tests LoadSuggestions function to filter expired suggestions. |
| 106 TEST_F(SuggestionsStoreTest, LoadAllExpired) { | 106 TEST_F(SuggestionsStoreTest, LoadAllExpired) { |
| 107 SuggestionsProfile suggestions = | 107 SuggestionsProfile suggestions = |
| 108 CreateTestSuggestionsProfileWithExpiry(current_time, 5, 0); | 108 CreateTestSuggestionsProfileWithExpiry(current_time, 5, 0); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 EXPECT_TRUE(suggestions_store_->LoadSuggestions(&recovered_suggestions)); | 156 EXPECT_TRUE(suggestions_store_->LoadSuggestions(&recovered_suggestions)); |
| 157 ValidateSuggestions(suggestions, recovered_suggestions); | 157 ValidateSuggestions(suggestions, recovered_suggestions); |
| 158 | 158 |
| 159 // Clear. | 159 // Clear. |
| 160 suggestions_store_->ClearSuggestions(); | 160 suggestions_store_->ClearSuggestions(); |
| 161 EXPECT_FALSE(suggestions_store_->LoadSuggestions(&recovered_suggestions)); | 161 EXPECT_FALSE(suggestions_store_->LoadSuggestions(&recovered_suggestions)); |
| 162 ValidateSuggestions(empty_suggestions, recovered_suggestions); | 162 ValidateSuggestions(empty_suggestions, recovered_suggestions); |
| 163 } | 163 } |
| 164 | 164 |
| 165 } // namespace suggestions | 165 } // namespace suggestions |
| OLD | NEW |