| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/search/suggestions/suggestions_store.h" | |
| 6 | |
| 7 #include "chrome/browser/search/suggestions/proto/suggestions.pb.h" | |
| 8 #include "chrome/test/base/testing_pref_service_syncable.h" | |
| 9 #include "testing/gtest/include/gtest/gtest.h" | |
| 10 | |
| 11 namespace suggestions { | |
| 12 | |
| 13 namespace { | |
| 14 | |
| 15 const char kTestTitle[] = "Foo site"; | |
| 16 const char kTestUrl[] = "http://foo.com/"; | |
| 17 | |
| 18 SuggestionsProfile CreateTestSuggestions() { | |
| 19 SuggestionsProfile suggestions; | |
| 20 ChromeSuggestion* suggestion = suggestions.add_suggestions(); | |
| 21 suggestion->set_url(kTestUrl); | |
| 22 suggestion->set_title(kTestTitle); | |
| 23 return suggestions; | |
| 24 } | |
| 25 | |
| 26 void ValidateSuggestions(const SuggestionsProfile& expected, | |
| 27 const SuggestionsProfile& actual) { | |
| 28 EXPECT_EQ(expected.suggestions_size(), actual.suggestions_size()); | |
| 29 for (int i = 0; i < expected.suggestions_size(); ++i) { | |
| 30 EXPECT_EQ(expected.suggestions(i).url(), actual.suggestions(i).url()); | |
| 31 EXPECT_EQ(expected.suggestions(i).title(), actual.suggestions(i).title()); | |
| 32 EXPECT_EQ(expected.suggestions(i).favicon_url(), | |
| 33 actual.suggestions(i).favicon_url()); | |
| 34 EXPECT_EQ(expected.suggestions(i).thumbnail(), | |
| 35 actual.suggestions(i).thumbnail()); | |
| 36 } | |
| 37 } | |
| 38 | |
| 39 } // namespace | |
| 40 | |
| 41 TEST(SuggestionsStoreTest, LoadStoreClear) { | |
| 42 TestingPrefServiceSyncable prefs; | |
| 43 SuggestionsStore::RegisterProfilePrefs(prefs.registry()); | |
| 44 SuggestionsStore suggestions_store(&prefs); | |
| 45 | |
| 46 const SuggestionsProfile suggestions = CreateTestSuggestions(); | |
| 47 const SuggestionsProfile empty_suggestions; | |
| 48 SuggestionsProfile recovered_suggestions; | |
| 49 | |
| 50 // Attempt to load when prefs are empty. | |
| 51 EXPECT_FALSE(suggestions_store.LoadSuggestions(&recovered_suggestions)); | |
| 52 ValidateSuggestions(empty_suggestions, recovered_suggestions); | |
| 53 | |
| 54 // Store then reload. | |
| 55 EXPECT_TRUE(suggestions_store.StoreSuggestions(suggestions)); | |
| 56 EXPECT_TRUE(suggestions_store.LoadSuggestions(&recovered_suggestions)); | |
| 57 ValidateSuggestions(suggestions, recovered_suggestions); | |
| 58 | |
| 59 // Clear. | |
| 60 suggestions_store.ClearSuggestions(); | |
| 61 EXPECT_FALSE(suggestions_store.LoadSuggestions(&recovered_suggestions)); | |
| 62 ValidateSuggestions(empty_suggestions, recovered_suggestions); | |
| 63 } | |
| 64 | |
| 65 } // namespace suggestions | |
| OLD | NEW |