| 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/history_url_provider.h" | 5 #include "components/omnibox/browser/history_url_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 | 11 |
| 12 #include "base/files/scoped_temp_dir.h" | 12 #include "base/files/scoped_temp_dir.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
| 16 #include "base/run_loop.h" |
| 16 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
| 17 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
| 18 #include "base/time/time.h" | 19 #include "base/time/time.h" |
| 19 #include "components/history/core/browser/history_service.h" | 20 #include "components/history/core/browser/history_service.h" |
| 20 #include "components/history/core/browser/url_database.h" | 21 #include "components/history/core/browser/url_database.h" |
| 21 #include "components/history/core/test/history_service_test_util.h" | 22 #include "components/history/core/test/history_service_test_util.h" |
| 22 #include "components/metrics/proto/omnibox_event.pb.h" | 23 #include "components/metrics/proto/omnibox_event.pb.h" |
| 23 #include "components/metrics/proto/omnibox_input_type.pb.h" | 24 #include "components/metrics/proto/omnibox_input_type.pb.h" |
| 24 #include "components/omnibox/browser/autocomplete_match.h" | 25 #include "components/omnibox/browser/autocomplete_match.h" |
| 25 #include "components/omnibox/browser/autocomplete_provider.h" | 26 #include "components/omnibox/browser/autocomplete_provider.h" |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 const UrlAndLegalDefault* expected_urls, | 322 const UrlAndLegalDefault* expected_urls, |
| 322 size_t num_results, | 323 size_t num_results, |
| 323 metrics::OmniboxInputType::Type* identified_input_type) { | 324 metrics::OmniboxInputType::Type* identified_input_type) { |
| 324 AutocompleteInput input(text, base::string16::npos, desired_tld, GURL(), | 325 AutocompleteInput input(text, base::string16::npos, desired_tld, GURL(), |
| 325 metrics::OmniboxEventProto::INVALID_SPEC, | 326 metrics::OmniboxEventProto::INVALID_SPEC, |
| 326 prevent_inline_autocomplete, false, true, true, false, | 327 prevent_inline_autocomplete, false, true, true, false, |
| 327 TestSchemeClassifier()); | 328 TestSchemeClassifier()); |
| 328 *identified_input_type = input.type(); | 329 *identified_input_type = input.type(); |
| 329 autocomplete_->Start(input, false); | 330 autocomplete_->Start(input, false); |
| 330 if (!autocomplete_->done()) | 331 if (!autocomplete_->done()) |
| 331 base::MessageLoop::current()->Run(); | 332 base::RunLoop().Run(); |
| 332 | 333 |
| 333 matches_ = autocomplete_->matches(); | 334 matches_ = autocomplete_->matches(); |
| 334 if (sort_matches_) { | 335 if (sort_matches_) { |
| 335 TemplateURLService* service = client_->GetTemplateURLService(); | 336 TemplateURLService* service = client_->GetTemplateURLService(); |
| 336 for (ACMatches::iterator i = matches_.begin(); i != matches_.end(); ++i) { | 337 for (ACMatches::iterator i = matches_.begin(); i != matches_.end(); ++i) { |
| 337 i->ComputeStrippedDestinationURL(input, service); | 338 i->ComputeStrippedDestinationURL(input, service); |
| 338 } | 339 } |
| 339 AutocompleteResult::SortAndDedupMatches(input.current_page_classification(), | 340 AutocompleteResult::SortAndDedupMatches(input.current_page_classification(), |
| 340 &matches_); | 341 &matches_); |
| 341 std::sort(matches_.begin(), matches_.end(), | 342 std::sort(matches_.begin(), matches_.end(), |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 658 // HistoryURLProvider shouldn't be done (waiting on async results). | 659 // HistoryURLProvider shouldn't be done (waiting on async results). |
| 659 EXPECT_FALSE(autocomplete_->done()); | 660 EXPECT_FALSE(autocomplete_->done()); |
| 660 | 661 |
| 661 // We should get back an entry for pandora. | 662 // We should get back an entry for pandora. |
| 662 matches_ = autocomplete_->matches(); | 663 matches_ = autocomplete_->matches(); |
| 663 ASSERT_GT(matches_.size(), 0u); | 664 ASSERT_GT(matches_.size(), 0u); |
| 664 EXPECT_EQ(GURL("http://pandora.com/"), matches_[0].destination_url); | 665 EXPECT_EQ(GURL("http://pandora.com/"), matches_[0].destination_url); |
| 665 int pandora_relevance = matches_[0].relevance; | 666 int pandora_relevance = matches_[0].relevance; |
| 666 | 667 |
| 667 // Run the message loop. When |autocomplete_| finishes the loop is quit. | 668 // Run the message loop. When |autocomplete_| finishes the loop is quit. |
| 668 base::MessageLoop::current()->Run(); | 669 base::RunLoop().Run(); |
| 669 EXPECT_TRUE(autocomplete_->done()); | 670 EXPECT_TRUE(autocomplete_->done()); |
| 670 matches_ = autocomplete_->matches(); | 671 matches_ = autocomplete_->matches(); |
| 671 ASSERT_GT(matches_.size(), 0u); | 672 ASSERT_GT(matches_.size(), 0u); |
| 672 EXPECT_EQ(GURL("http://pandora.com/"), matches_[0].destination_url); | 673 EXPECT_EQ(GURL("http://pandora.com/"), matches_[0].destination_url); |
| 673 EXPECT_EQ(pandora_relevance, matches_[0].relevance); | 674 EXPECT_EQ(pandora_relevance, matches_[0].relevance); |
| 674 } | 675 } |
| 675 | 676 |
| 676 TEST_F(HistoryURLProviderTestNoDB, NavigateWithoutDB) { | 677 TEST_F(HistoryURLProviderTestNoDB, NavigateWithoutDB) { |
| 677 // Ensure that we will still produce matches for navigation when there is no | 678 // Ensure that we will still produce matches for navigation when there is no |
| 678 // database. | 679 // database. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 691 RunTest(ASCIIToUTF16("this is a query"), std::string(), false, NULL, 0); | 692 RunTest(ASCIIToUTF16("this is a query"), std::string(), false, NULL, 0); |
| 692 } | 693 } |
| 693 | 694 |
| 694 TEST_F(HistoryURLProviderTest, DontAutocompleteOnTrailingWhitespace) { | 695 TEST_F(HistoryURLProviderTest, DontAutocompleteOnTrailingWhitespace) { |
| 695 AutocompleteInput input( | 696 AutocompleteInput input( |
| 696 ASCIIToUTF16("slash "), base::string16::npos, std::string(), GURL(), | 697 ASCIIToUTF16("slash "), base::string16::npos, std::string(), GURL(), |
| 697 metrics::OmniboxEventProto::INVALID_SPEC, false, false, true, true, false, | 698 metrics::OmniboxEventProto::INVALID_SPEC, false, false, true, true, false, |
| 698 TestSchemeClassifier()); | 699 TestSchemeClassifier()); |
| 699 autocomplete_->Start(input, false); | 700 autocomplete_->Start(input, false); |
| 700 if (!autocomplete_->done()) | 701 if (!autocomplete_->done()) |
| 701 base::MessageLoop::current()->Run(); | 702 base::RunLoop().Run(); |
| 702 | 703 |
| 703 // None of the matches should attempt to autocomplete. | 704 // None of the matches should attempt to autocomplete. |
| 704 matches_ = autocomplete_->matches(); | 705 matches_ = autocomplete_->matches(); |
| 705 for (size_t i = 0; i < matches_.size(); ++i) { | 706 for (size_t i = 0; i < matches_.size(); ++i) { |
| 706 EXPECT_TRUE(matches_[i].inline_autocompletion.empty()); | 707 EXPECT_TRUE(matches_[i].inline_autocompletion.empty()); |
| 707 EXPECT_FALSE(matches_[i].allowed_to_be_default_match); | 708 EXPECT_FALSE(matches_[i].allowed_to_be_default_match); |
| 708 } | 709 } |
| 709 } | 710 } |
| 710 | 711 |
| 711 TEST_F(HistoryURLProviderTest, TreatEmailsAsSearches) { | 712 TEST_F(HistoryURLProviderTest, TreatEmailsAsSearches) { |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 830 "\\@st", | 831 "\\@st", |
| 831 "view-source:x", | 832 "view-source:x", |
| 832 }; | 833 }; |
| 833 for (size_t i = 0; i < arraysize(test_cases); ++i) { | 834 for (size_t i = 0; i < arraysize(test_cases); ++i) { |
| 834 AutocompleteInput input( | 835 AutocompleteInput input( |
| 835 ASCIIToUTF16(test_cases[i]), base::string16::npos, std::string(), | 836 ASCIIToUTF16(test_cases[i]), base::string16::npos, std::string(), |
| 836 GURL(), metrics::OmniboxEventProto::INVALID_SPEC, false, false, true, | 837 GURL(), metrics::OmniboxEventProto::INVALID_SPEC, false, false, true, |
| 837 true, false, TestSchemeClassifier()); | 838 true, false, TestSchemeClassifier()); |
| 838 autocomplete_->Start(input, false); | 839 autocomplete_->Start(input, false); |
| 839 if (!autocomplete_->done()) | 840 if (!autocomplete_->done()) |
| 840 base::MessageLoop::current()->Run(); | 841 base::RunLoop().Run(); |
| 841 } | 842 } |
| 842 } | 843 } |
| 843 | 844 |
| 844 TEST_F(HistoryURLProviderTest, DoesNotProvideMatchesOnFocus) { | 845 TEST_F(HistoryURLProviderTest, DoesNotProvideMatchesOnFocus) { |
| 845 AutocompleteInput input( | 846 AutocompleteInput input( |
| 846 ASCIIToUTF16("foo"), base::string16::npos, std::string(), GURL(), | 847 ASCIIToUTF16("foo"), base::string16::npos, std::string(), GURL(), |
| 847 metrics::OmniboxEventProto::INVALID_SPEC, false, false, true, true, true, | 848 metrics::OmniboxEventProto::INVALID_SPEC, false, false, true, true, true, |
| 848 TestSchemeClassifier()); | 849 TestSchemeClassifier()); |
| 849 autocomplete_->Start(input, false); | 850 autocomplete_->Start(input, false); |
| 850 EXPECT_TRUE(autocomplete_->matches().empty()); | 851 EXPECT_TRUE(autocomplete_->matches().empty()); |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1118 // the default experimental scoring. | 1119 // the default experimental scoring. |
| 1119 autocomplete_->scoring_params_.experimental_scoring_enabled = true; | 1120 autocomplete_->scoring_params_.experimental_scoring_enabled = true; |
| 1120 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16(test_cases[i].input), | 1121 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16(test_cases[i].input), |
| 1121 std::string(), false, output, max_matches)); | 1122 std::string(), false, output, max_matches)); |
| 1122 for (int j = 0; j < max_matches; ++j) { | 1123 for (int j = 0; j < max_matches; ++j) { |
| 1123 EXPECT_EQ(test_cases[i].matches[j].experiment_relevance, | 1124 EXPECT_EQ(test_cases[i].matches[j].experiment_relevance, |
| 1124 matches_[j].relevance); | 1125 matches_[j].relevance); |
| 1125 } | 1126 } |
| 1126 } | 1127 } |
| 1127 } | 1128 } |
| OLD | NEW |