Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 returns results (including keyword |
|
Bart N.
2013/01/29 18:50:42
Nit: returns -> return (unless you meant one Autoc
Mark P
2013/01/30 19:46:21
Done.
Mark P
2013/01/30 19:46:21
Done.
| |
| 791 TEST_F(SearchProviderTest, UpdateKeywordDescriptions) { | 791 // results) in the right order and sets descriptions for them correctly. |
|
Bart N.
2013/01/29 18:50:42
sets -> set.
Bart N.
2013/01/29 18:50:42
sets -> set
Mark P
2013/01/30 19:46:21
Done.
Mark P
2013/01/30 19:46:21
Duplicate of another comment.
| |
| 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. They'll all have keywords. (The | |
| 807 // default provider's result will be listed under the default provider's | |
| 808 // keyword.) Also, the top result will always have a description. The | |
| 809 // third result, coming from a different provider than the first two, | |
| 810 // should also. Whether the second result has one doesn't matter much. | |
| 811 // (If it was missing, people would infer that it's the same search | |
| 812 // provider as the one above it.) | |
| 813 ASSERT_EQ(3u, result.size()); | |
| 814 | |
| 815 EXPECT_GT(result.match_at(0).relevance, result.match_at(1).relevance); | |
|
Bart N.
2013/01/29 18:50:42
Technically speaking, why GT and not GE?
Mark P
2013/01/30 19:46:21
There shouldn't be ties in this test. If there ar
| |
| 816 EXPECT_GT(result.match_at(1).relevance, result.match_at(2).relevance); | |
| 805 | 817 |
| 806 EXPECT_FALSE(result.match_at(0).keyword.empty()); | 818 EXPECT_FALSE(result.match_at(0).keyword.empty()); |
|
Bart N.
2013/01/29 18:50:42
Honestly, I'd prefer exact assertion here, i.e. sa
Mark P
2013/01/30 19:46:21
Mostly done. Did the exact equal asserts for the
| |
| 807 EXPECT_FALSE(result.match_at(1).keyword.empty()); | 819 EXPECT_FALSE(result.match_at(1).keyword.empty()); |
| 808 EXPECT_NE(result.match_at(0).keyword, result.match_at(1).keyword); | 820 EXPECT_FALSE(result.match_at(2).keyword.empty()); |
| 821 EXPECT_EQ(result.match_at(0).keyword, result.match_at(1).keyword); | |
| 822 EXPECT_NE(result.match_at(0).keyword, result.match_at(2).keyword); | |
| 809 | 823 |
| 810 EXPECT_FALSE(result.match_at(0).description.empty()); | 824 EXPECT_FALSE(result.match_at(0).description.empty()); |
| 811 EXPECT_FALSE(result.match_at(1).description.empty()); | 825 EXPECT_FALSE(result.match_at(2).description.empty()); |
| 812 EXPECT_NE(result.match_at(0).description, result.match_at(1).description); | 826 EXPECT_NE(result.match_at(0).description, result.match_at(2).description); |
| 813 } | 827 } |
|
Bart N.
2013/01/29 18:50:42
I think it would be worth to add a unit test that
Mark P
2013/01/30 19:46:21
Added to this test (and analogous ones).
| |
| 814 | 828 |
| 815 // Verifies Navsuggest results don't set a TemplateURL, which instant relies on. | 829 // 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 | 830 // Also verifies that just the *first* navigational result is listed as a match |
| 817 // if suggested relevance scores were not sent. | 831 // if suggested relevance scores were not sent. |
| 818 TEST_F(SearchProviderTest, NavSuggestNoSuggestedRelevanceScores) { | 832 TEST_F(SearchProviderTest, NavSuggestNoSuggestedRelevanceScores) { |
| 819 QueryForInput(ASCIIToUTF16("a.c"), string16(), false); | 833 QueryForInput(ASCIIToUTF16("a.c"), string16(), false); |
| 820 | 834 |
| 821 // Make sure the default providers suggest service was queried. | 835 // Make sure the default providers suggest service was queried. |
| 822 net::TestURLFetcher* fetcher = test_factory_.GetFetcherByID( | 836 net::TestURLFetcher* fetcher = test_factory_.GetFetcherByID( |
| 823 SearchProvider::kDefaultProviderURLFetcherID); | 837 SearchProvider::kDefaultProviderURLFetcherID); |
| (...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1417 EXPECT_EQ(AutocompleteMatch::ACMatchClassification::URL, | 1431 EXPECT_EQ(AutocompleteMatch::ACMatchClassification::URL, |
| 1418 match.contents_class[0].style); | 1432 match.contents_class[0].style); |
| 1419 EXPECT_EQ(4U, match.contents_class[1].offset); | 1433 EXPECT_EQ(4U, match.contents_class[1].offset); |
| 1420 EXPECT_EQ(AutocompleteMatch::ACMatchClassification::URL | | 1434 EXPECT_EQ(AutocompleteMatch::ACMatchClassification::URL | |
| 1421 AutocompleteMatch::ACMatchClassification::MATCH, | 1435 AutocompleteMatch::ACMatchClassification::MATCH, |
| 1422 match.contents_class[1].style); | 1436 match.contents_class[1].style); |
| 1423 EXPECT_EQ(5U, match.contents_class[2].offset); | 1437 EXPECT_EQ(5U, match.contents_class[2].offset); |
| 1424 EXPECT_EQ(AutocompleteMatch::ACMatchClassification::URL, | 1438 EXPECT_EQ(AutocompleteMatch::ACMatchClassification::URL, |
| 1425 match.contents_class[2].style); | 1439 match.contents_class[2].style); |
| 1426 } | 1440 } |
| OLD | NEW |