OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/browser/bookmark_provider.h" | 5 #include "components/omnibox/browser/bookmark_provider.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
16 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
17 #include "base/strings/string16.h" | 17 #include "base/strings/string16.h" |
18 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
19 #include "base/strings/string_split.h" | 19 #include "base/strings/string_split.h" |
20 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
21 #include "components/bookmarks/browser/bookmark_model.h" | 21 #include "components/bookmarks/browser/bookmark_model.h" |
22 #include "components/bookmarks/browser/titled_url_match.h" | 22 #include "components/bookmarks/browser/titled_url_match.h" |
23 #include "components/bookmarks/test/test_bookmark_client.h" | 23 #include "components/bookmarks/test/test_bookmark_client.h" |
24 #include "components/metrics/proto/omnibox_event.pb.h" | 24 #include "components/metrics/proto/omnibox_event.pb.h" |
25 #include "components/omnibox/browser/autocomplete_provider.h" | 25 #include "components/omnibox/browser/autocomplete_provider.h" |
26 #include "components/omnibox/browser/mock_autocomplete_provider_client.h" | 26 #include "components/omnibox/browser/mock_autocomplete_provider_client.h" |
27 #include "components/omnibox/browser/test_scheme_classifier.h" | 27 #include "components/omnibox/browser/test_scheme_classifier.h" |
| 28 #include "components/omnibox/browser/titled_url_match_utils.h" |
28 #include "testing/gmock/include/gmock/gmock.h" | 29 #include "testing/gmock/include/gmock/gmock.h" |
29 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
30 | 31 |
31 using bookmarks::BookmarkModel; | 32 using bookmarks::BookmarkModel; |
32 using bookmarks::BookmarkNode; | 33 using bookmarks::BookmarkNode; |
33 using bookmarks::TitledUrlMatch; | 34 using bookmarks::TitledUrlMatch; |
34 | 35 |
35 namespace { | 36 namespace { |
36 | 37 |
37 // The bookmark corpus against which we will simulate searches. | 38 // The bookmark corpus against which we will simulate searches. |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 AutocompleteInput input(base::ASCIIToUTF16(query_data[i].query), | 416 AutocompleteInput input(base::ASCIIToUTF16(query_data[i].query), |
416 base::string16::npos, std::string(), GURL(), | 417 base::string16::npos, std::string(), GURL(), |
417 metrics::OmniboxEventProto::INVALID_SPEC, false, | 418 metrics::OmniboxEventProto::INVALID_SPEC, false, |
418 false, false, true, false, TestSchemeClassifier()); | 419 false, false, true, false, TestSchemeClassifier()); |
419 const base::string16 fixed_up_input( | 420 const base::string16 fixed_up_input( |
420 provider_->FixupUserInput(input).second); | 421 provider_->FixupUserInput(input).second); |
421 BookmarkNode node(GURL(query_data[i].url)); | 422 BookmarkNode node(GURL(query_data[i].url)); |
422 node.SetTitle(base::ASCIIToUTF16(query_data[i].url)); | 423 node.SetTitle(base::ASCIIToUTF16(query_data[i].url)); |
423 TitledUrlMatch bookmark_match; | 424 TitledUrlMatch bookmark_match; |
424 bookmark_match.node = &node; | 425 bookmark_match.node = &node; |
425 const AutocompleteMatch& ac_match = provider_->TitledUrlMatchToACMatch( | 426 int relevance = provider_->CalculateBookmarkMatchRelevance(bookmark_match); |
426 input, fixed_up_input, bookmark_match); | 427 const AutocompleteMatch& ac_match = TitledUrlMatchToAutocompleteMatch( |
| 428 bookmark_match, AutocompleteMatchType::BOOKMARK_TITLE, relevance, |
| 429 provider_.get(), classifier_, input, fixed_up_input); |
427 EXPECT_EQ(query_data[i].allowed_to_be_default_match, | 430 EXPECT_EQ(query_data[i].allowed_to_be_default_match, |
428 ac_match.allowed_to_be_default_match) << description; | 431 ac_match.allowed_to_be_default_match) << description; |
429 EXPECT_EQ(base::ASCIIToUTF16(query_data[i].inline_autocompletion), | 432 EXPECT_EQ(base::ASCIIToUTF16(query_data[i].inline_autocompletion), |
430 ac_match.inline_autocompletion) << description; | 433 ac_match.inline_autocompletion) << description; |
431 } | 434 } |
432 } | 435 } |
433 | 436 |
434 TEST_F(BookmarkProviderTest, StripHttpAndAdjustOffsets) { | 437 TEST_F(BookmarkProviderTest, StripHttpAndAdjustOffsets) { |
435 // Simulate searches. | 438 // Simulate searches. |
436 struct QueryData { | 439 struct QueryData { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 } | 487 } |
485 | 488 |
486 TEST_F(BookmarkProviderTest, DoesNotProvideMatchesOnFocus) { | 489 TEST_F(BookmarkProviderTest, DoesNotProvideMatchesOnFocus) { |
487 AutocompleteInput input(base::ASCIIToUTF16("foo"), base::string16::npos, | 490 AutocompleteInput input(base::ASCIIToUTF16("foo"), base::string16::npos, |
488 std::string(), GURL(), | 491 std::string(), GURL(), |
489 metrics::OmniboxEventProto::INVALID_SPEC, false, | 492 metrics::OmniboxEventProto::INVALID_SPEC, false, |
490 false, false, true, true, TestSchemeClassifier()); | 493 false, false, true, true, TestSchemeClassifier()); |
491 provider_->Start(input, false); | 494 provider_->Start(input, false); |
492 EXPECT_TRUE(provider_->matches().empty()); | 495 EXPECT_TRUE(provider_->matches().empty()); |
493 } | 496 } |
OLD | NEW |