| 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/omnibox/base_search_provider.h" | 5 #include "components/omnibox/base_search_provider.h" |
| 6 | 6 |
| 7 #include "base/strings/string16.h" | 7 #include "base/strings/string16.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "components/omnibox/autocomplete_match.h" | 9 #include "components/omnibox/autocomplete_match.h" |
| 10 #include "components/omnibox/autocomplete_match_type.h" | 10 #include "components/omnibox/autocomplete_match_type.h" |
| 11 #include "components/omnibox/autocomplete_provider_client.h" | |
| 12 #include "components/omnibox/autocomplete_scheme_classifier.h" | 11 #include "components/omnibox/autocomplete_scheme_classifier.h" |
| 12 #include "components/omnibox/mock_autocomplete_provider_client.h" |
| 13 #include "components/omnibox/search_suggestion_parser.h" | 13 #include "components/omnibox/search_suggestion_parser.h" |
| 14 #include "components/omnibox/suggestion_answer.h" | 14 #include "components/omnibox/suggestion_answer.h" |
| 15 #include "components/search_engines/search_terms_data.h" | 15 #include "components/search_engines/search_terms_data.h" |
| 16 #include "components/search_engines/template_url_service.h" | 16 #include "components/search_engines/template_url_service.h" |
| 17 #include "components/search_engines/template_url_service_client.h" | 17 #include "components/search_engines/template_url_service_client.h" |
| 18 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 20 | 20 |
| 21 using testing::NiceMock; | 21 using testing::NiceMock; |
| 22 using testing::Return; | 22 using testing::Return; |
| 23 using testing::_; | 23 using testing::_; |
| 24 | 24 |
| 25 class MockAutocompleteProviderClient : public AutocompleteProviderClient { | |
| 26 public: | |
| 27 MockAutocompleteProviderClient() { | |
| 28 template_url_service_.reset(new TemplateURLService( | |
| 29 nullptr, scoped_ptr<SearchTermsData>(new SearchTermsData), nullptr, | |
| 30 scoped_ptr<TemplateURLServiceClient>(), nullptr, nullptr, | |
| 31 base::Closure())); | |
| 32 } | |
| 33 MOCK_METHOD0(GetRequestContext, net::URLRequestContextGetter*()); | |
| 34 MOCK_METHOD0(GetPrefs, PrefService*()); | |
| 35 MOCK_CONST_METHOD0(GetSchemeClassifier, | |
| 36 const AutocompleteSchemeClassifier&()); | |
| 37 MOCK_METHOD0(GetAutocompleteClassifier, AutocompleteClassifier*()); | |
| 38 MOCK_METHOD0(GetHistoryService, history::HistoryService*()); | |
| 39 | |
| 40 // Can't mock scoped_refptr :\. | |
| 41 scoped_refptr<history::TopSites> GetTopSites() override { return nullptr; } | |
| 42 | |
| 43 MOCK_METHOD0(GetBookmarkModel, bookmarks::BookmarkModel*()); | |
| 44 MOCK_METHOD0(GetInMemoryDatabase, history::URLDatabase*()); | |
| 45 | |
| 46 TemplateURLService* GetTemplateURLService() override { | |
| 47 return template_url_service_.get(); | |
| 48 } | |
| 49 const TemplateURLService* GetTemplateURLService() const override { | |
| 50 return template_url_service_.get(); | |
| 51 } | |
| 52 | |
| 53 MOCK_CONST_METHOD0(GetSearchTermsData, const SearchTermsData&()); | |
| 54 | |
| 55 // Can't mock scoped_refptr :\. | |
| 56 scoped_refptr<ShortcutsBackend> GetShortcutsBackend() override { | |
| 57 return nullptr; | |
| 58 } | |
| 59 scoped_refptr<ShortcutsBackend> GetShortcutsBackendIfExists() override { | |
| 60 return nullptr; | |
| 61 } | |
| 62 | |
| 63 MOCK_CONST_METHOD0(GetAcceptLanguages, std::string()); | |
| 64 MOCK_CONST_METHOD0(IsOffTheRecord, bool()); | |
| 65 MOCK_CONST_METHOD0(SearchSuggestEnabled, bool()); | |
| 66 MOCK_CONST_METHOD0(BookmarkBarIsVisible, bool()); | |
| 67 MOCK_CONST_METHOD0(TabSyncEnabledAndUnencrypted, bool()); | |
| 68 MOCK_METHOD6( | |
| 69 Classify, | |
| 70 void(const base::string16& text, | |
| 71 bool prefer_keyword, | |
| 72 bool allow_exact_keyword_match, | |
| 73 metrics::OmniboxEventProto::PageClassification page_classification, | |
| 74 AutocompleteMatch* match, | |
| 75 GURL* alternate_nav_url)); | |
| 76 MOCK_METHOD2(DeleteMatchingURLsForKeywordFromHistory, | |
| 77 void(history::KeywordID keyword_id, const base::string16& term)); | |
| 78 MOCK_METHOD1(PrefetchImage, void(const GURL& url)); | |
| 79 | |
| 80 private: | |
| 81 scoped_ptr<TemplateURLService> template_url_service_; | |
| 82 | |
| 83 DISALLOW_COPY_AND_ASSIGN(MockAutocompleteProviderClient); | |
| 84 }; | |
| 85 | |
| 86 class TestBaseSearchProvider : public BaseSearchProvider { | 25 class TestBaseSearchProvider : public BaseSearchProvider { |
| 87 public: | 26 public: |
| 88 typedef BaseSearchProvider::MatchMap MatchMap; | 27 typedef BaseSearchProvider::MatchMap MatchMap; |
| 89 | 28 |
| 90 TestBaseSearchProvider(AutocompleteProvider::Type type, | 29 TestBaseSearchProvider(AutocompleteProvider::Type type, |
| 91 AutocompleteProviderClient* client) | 30 AutocompleteProviderClient* client) |
| 92 : BaseSearchProvider(type, client) {} | 31 : BaseSearchProvider(type, client) {} |
| 93 MOCK_METHOD1(DeleteMatch, void(const AutocompleteMatch& match)); | 32 MOCK_METHOD1(DeleteMatch, void(const AutocompleteMatch& match)); |
| 94 MOCK_CONST_METHOD1(AddProviderInfo, void(ProvidersInfo* provider_info)); | 33 MOCK_CONST_METHOD1(AddProviderInfo, void(ProvidersInfo* provider_info)); |
| 95 MOCK_CONST_METHOD1(GetTemplateURL, const TemplateURL*(bool is_keyword)); | 34 MOCK_CONST_METHOD1(GetTemplateURL, const TemplateURL*(bool is_keyword)); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 120 private: | 59 private: |
| 121 DISALLOW_COPY_AND_ASSIGN(TestBaseSearchProvider); | 60 DISALLOW_COPY_AND_ASSIGN(TestBaseSearchProvider); |
| 122 }; | 61 }; |
| 123 | 62 |
| 124 class BaseSearchProviderTest : public testing::Test { | 63 class BaseSearchProviderTest : public testing::Test { |
| 125 public: | 64 public: |
| 126 ~BaseSearchProviderTest() override {} | 65 ~BaseSearchProviderTest() override {} |
| 127 | 66 |
| 128 protected: | 67 protected: |
| 129 void SetUp() override { | 68 void SetUp() override { |
| 69 scoped_ptr<TemplateURLService> template_url_service(new TemplateURLService( |
| 70 nullptr, scoped_ptr<SearchTermsData>(new SearchTermsData), nullptr, |
| 71 scoped_ptr<TemplateURLServiceClient>(), nullptr, nullptr, |
| 72 base::Closure())); |
| 130 client_.reset(new NiceMock<MockAutocompleteProviderClient>()); | 73 client_.reset(new NiceMock<MockAutocompleteProviderClient>()); |
| 74 client_->set_template_url_service(template_url_service.Pass()); |
| 131 provider_ = new NiceMock<TestBaseSearchProvider>( | 75 provider_ = new NiceMock<TestBaseSearchProvider>( |
| 132 AutocompleteProvider::TYPE_SEARCH, client_.get()); | 76 AutocompleteProvider::TYPE_SEARCH, client_.get()); |
| 133 } | 77 } |
| 134 | 78 |
| 135 scoped_refptr<NiceMock<TestBaseSearchProvider> > provider_; | 79 scoped_refptr<NiceMock<TestBaseSearchProvider> > provider_; |
| 136 scoped_ptr<NiceMock<MockAutocompleteProviderClient>> client_; | 80 scoped_ptr<NiceMock<MockAutocompleteProviderClient>> client_; |
| 137 }; | 81 }; |
| 138 | 82 |
| 139 TEST_F(BaseSearchProviderTest, PreserveAnswersWhenDeduplicating) { | 83 TEST_F(BaseSearchProviderTest, PreserveAnswersWhenDeduplicating) { |
| 140 TemplateURLData data; | 84 TemplateURLData data; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 EXPECT_TRUE(answer2->Equals(*match.answer)); | 158 EXPECT_TRUE(answer2->Equals(*match.answer)); |
| 215 EXPECT_EQ(AutocompleteMatchType::SEARCH_HISTORY, match.type); | 159 EXPECT_EQ(AutocompleteMatchType::SEARCH_HISTORY, match.type); |
| 216 EXPECT_EQ(1300, match.relevance); | 160 EXPECT_EQ(1300, match.relevance); |
| 217 | 161 |
| 218 EXPECT_EQ(answer_contents, duplicate.answer_contents); | 162 EXPECT_EQ(answer_contents, duplicate.answer_contents); |
| 219 EXPECT_EQ(answer_type, duplicate.answer_type); | 163 EXPECT_EQ(answer_type, duplicate.answer_type); |
| 220 EXPECT_TRUE(answer->Equals(*duplicate.answer)); | 164 EXPECT_TRUE(answer->Equals(*duplicate.answer)); |
| 221 EXPECT_EQ(AutocompleteMatchType::SEARCH_SUGGEST, duplicate.type); | 165 EXPECT_EQ(AutocompleteMatchType::SEARCH_SUGGEST, duplicate.type); |
| 222 EXPECT_EQ(850, duplicate.relevance); | 166 EXPECT_EQ(850, duplicate.relevance); |
| 223 } | 167 } |
| OLD | NEW |