Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(394)

Side by Side Diff: chrome/browser/autocomplete/search_provider_unittest.cc

Issue 12090006: Omnibox: Create Keyword Verbatim Result in Search Provider (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Bart's final comments. Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 "chrome/browser/autocomplete/search_provider.h" 5 #include "chrome/browser/autocomplete/search_provider.h"
6 6
7 #include "base/metrics/field_trial.h" 7 #include "base/metrics/field_trial.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/time.h" 10 #include "base/time.h"
(...skipping 769 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 ASSERT_NO_FATAL_FAILURE(QueryForInputAndSetWYTMatch(ASCIIToUTF16("f"), 780 ASSERT_NO_FATAL_FAILURE(QueryForInputAndSetWYTMatch(ASCIIToUTF16("f"),
781 &wyt_match)); 781 &wyt_match));
782 ASSERT_EQ(2u, provider_->matches().size()); 782 ASSERT_EQ(2u, provider_->matches().size());
783 AutocompleteMatch term_match; 783 AutocompleteMatch term_match;
784 EXPECT_TRUE(FindMatchWithDestination(term_url, &term_match)); 784 EXPECT_TRUE(FindMatchWithDestination(term_url, &term_match));
785 EXPECT_GT(term_match.relevance, wyt_match.relevance); 785 EXPECT_GT(term_match.relevance, wyt_match.relevance);
786 EXPECT_EQ(1u, term_match.inline_autocomplete_offset); 786 EXPECT_EQ(1u, term_match.inline_autocomplete_offset);
787 EXPECT_EQ(ASCIIToUTF16("FOO"), term_match.fill_into_edit); 787 EXPECT_EQ(ASCIIToUTF16("FOO"), term_match.fill_into_edit);
788 } 788 }
789 789
790 // Verifies AutocompleteControllers sets descriptions for results correctly. 790 // Verifies AutocompleteControllers return results (including keyword
msw 2013/01/31 00:38:16 I would really like to see some additional tests h
Mark P 2013/01/31 23:09:27 I'll do this soon. Right now I'll hit reply to se
791 TEST_F(SearchProviderTest, UpdateKeywordDescriptions) { 791 // results) in the right order and set descriptions for them correctly.
792 TEST_F(SearchProviderTest, KeywordOrderingAndDescriptions) {
792 // Add an entry that corresponds to a keyword search with 'term2'. 793 // Add an entry that corresponds to a keyword search with 'term2'.
793 AddSearchToHistory(keyword_t_url_, ASCIIToUTF16("term2"), 1); 794 AddSearchToHistory(keyword_t_url_, ASCIIToUTF16("term2"), 1);
794 profile_.BlockUntilHistoryProcessesPendingRequests(); 795 profile_.BlockUntilHistoryProcessesPendingRequests();
795 796
796 AutocompleteController controller(&profile_, NULL, 797 AutocompleteController controller(&profile_, NULL,
797 AutocompleteProvider::TYPE_SEARCH); 798 AutocompleteProvider::TYPE_SEARCH);
798 controller.Start(AutocompleteInput( 799 controller.Start(AutocompleteInput(
799 ASCIIToUTF16("k t"), string16::npos, string16(), false, false, true, 800 ASCIIToUTF16("k t"), string16::npos, string16(), false, false, true,
800 AutocompleteInput::ALL_MATCHES)); 801 AutocompleteInput::ALL_MATCHES));
801 const AutocompleteResult& result = controller.result(); 802 const AutocompleteResult& result = controller.result();
802 803
803 // There should be two matches, one for the keyword one for what you typed. 804 // There should be three matches, one for the keyword history, one for
804 ASSERT_EQ(2u, result.size()); 805 // keyword provider's what-you-typed, and one for the default provider's
806 // what you typed, in that order.
807 ASSERT_EQ(3u, result.size());
808 EXPECT_EQ(AutocompleteMatch::SEARCH_HISTORY, result.match_at(0).type);
809 EXPECT_EQ(AutocompleteMatch::SEARCH_OTHER_ENGINE, result.match_at(1).type);
810 EXPECT_EQ(AutocompleteMatch::SEARCH_WHAT_YOU_TYPED, result.match_at(2).type);
811 EXPECT_GT(result.match_at(0).relevance, result.match_at(1).relevance);
msw 2013/01/31 00:38:16 nit: isn't this scoring guaranteed by the match or
Mark P 2013/01/31 23:09:27 Not as far as I know. The controller resorts matc
msw 2013/02/01 20:52:37 Okay, then this is good, thanks.
812 EXPECT_GT(result.match_at(1).relevance, result.match_at(2).relevance);
805 813
806 EXPECT_FALSE(result.match_at(0).keyword.empty()); 814 // The two keyword results should come with the keyword we expect.
807 EXPECT_FALSE(result.match_at(1).keyword.empty()); 815 EXPECT_EQ(ASCIIToUTF16("k"), result.match_at(0).keyword);
808 EXPECT_NE(result.match_at(0).keyword, result.match_at(1).keyword); 816 EXPECT_EQ(ASCIIToUTF16("k"), result.match_at(1).keyword);
817 // The default provider has a different keyword. (We don't explicitly
818 // set it during this test, so all we do is assert that it's different.)
819 EXPECT_NE(result.match_at(0).keyword, result.match_at(2).keyword);
809 820
821 // The top result will always have a description. The third result,
822 // coming from a different provider than the first two, should also.
823 // Whether the second result has one doesn't matter much. (If it was
824 // missing, people would infer that it's the same search provider as
825 // the one above it.)
810 EXPECT_FALSE(result.match_at(0).description.empty()); 826 EXPECT_FALSE(result.match_at(0).description.empty());
811 EXPECT_FALSE(result.match_at(1).description.empty()); 827 EXPECT_FALSE(result.match_at(2).description.empty());
812 EXPECT_NE(result.match_at(0).description, result.match_at(1).description); 828 EXPECT_NE(result.match_at(0).description, result.match_at(2).description);
829
msw 2013/01/31 00:38:16 nit: remove extra line.
Mark P 2013/01/31 23:09:27 Done.
813 } 830 }
814 831
815 // Verifies Navsuggest results don't set a TemplateURL, which instant relies on. 832 // Verifies Navsuggest results don't set a TemplateURL, which instant relies on.
816 // Also verifies that just the *first* navigational result is listed as a match 833 // Also verifies that just the *first* navigational result is listed as a match
817 // if suggested relevance scores were not sent. 834 // if suggested relevance scores were not sent.
818 TEST_F(SearchProviderTest, NavSuggestNoSuggestedRelevanceScores) { 835 TEST_F(SearchProviderTest, NavSuggestNoSuggestedRelevanceScores) {
819 QueryForInput(ASCIIToUTF16("a.c"), string16(), false); 836 QueryForInput(ASCIIToUTF16("a.c"), string16(), false);
820 837
821 // Make sure the default providers suggest service was queried. 838 // Make sure the default providers suggest service was queried.
822 net::TestURLFetcher* fetcher = test_factory_.GetFetcherByID( 839 net::TestURLFetcher* fetcher = test_factory_.GetFetcherByID(
(...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after
1417 EXPECT_EQ(AutocompleteMatch::ACMatchClassification::URL, 1434 EXPECT_EQ(AutocompleteMatch::ACMatchClassification::URL,
1418 match.contents_class[0].style); 1435 match.contents_class[0].style);
1419 EXPECT_EQ(4U, match.contents_class[1].offset); 1436 EXPECT_EQ(4U, match.contents_class[1].offset);
1420 EXPECT_EQ(AutocompleteMatch::ACMatchClassification::URL | 1437 EXPECT_EQ(AutocompleteMatch::ACMatchClassification::URL |
1421 AutocompleteMatch::ACMatchClassification::MATCH, 1438 AutocompleteMatch::ACMatchClassification::MATCH,
1422 match.contents_class[1].style); 1439 match.contents_class[1].style);
1423 EXPECT_EQ(5U, match.contents_class[2].offset); 1440 EXPECT_EQ(5U, match.contents_class[2].offset);
1424 EXPECT_EQ(AutocompleteMatch::ACMatchClassification::URL, 1441 EXPECT_EQ(AutocompleteMatch::ACMatchClassification::URL,
1425 match.contents_class[2].style); 1442 match.contents_class[2].style);
1426 } 1443 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698