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

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

Issue 1855423003: Interpret '?' and Ctrl-K or Ctrl-E as putting omnibox in keyword search mode for Default Search Pro… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add includes for mac tests Created 4 years, 6 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
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 "components/omnibox/browser/search_provider.h" 5 #include "components/omnibox/browser/search_provider.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <string> 9 #include <string>
10 10
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 const base::string16& text, 213 const base::string16& text,
214 const bool prefer_keyword, 214 const bool prefer_keyword,
215 const std::string& default_fetcher_response, 215 const std::string& default_fetcher_response,
216 const std::string& keyword_fetcher_response); 216 const std::string& keyword_fetcher_response);
217 217
218 // Notifies the URLFetcher for the suggest query corresponding to the default 218 // Notifies the URLFetcher for the suggest query corresponding to the default
219 // search provider that it's done. 219 // search provider that it's done.
220 // Be sure and wrap calls to this in ASSERT_NO_FATAL_FAILURE. 220 // Be sure and wrap calls to this in ASSERT_NO_FATAL_FAILURE.
221 void FinishDefaultSuggestQuery(); 221 void FinishDefaultSuggestQuery();
222 222
223 // Runs SearchProvider on |input|, for which the suggest server replies
224 // with |json|, and expects that the resulting matches' contents equals
225 // that in |matches|. An empty entry in |matches| means no match should
226 // be returned in that position. Reports any errors with a message that
227 // includes |error_description|.
228 void ForcedQueryTestHelper(const std::string& input,
229 const std::string& json,
230 const std::string matches[3],
231 const std::string& error_description);
232
233 // Verifies that |matches| and |expected_matches| agree on the first 223 // Verifies that |matches| and |expected_matches| agree on the first
234 // |num_expected_matches|, displaying an error message that includes 224 // |num_expected_matches|, displaying an error message that includes
235 // |description| for any disagreement. 225 // |description| for any disagreement.
236 void CheckMatches(const std::string& description, 226 void CheckMatches(const std::string& description,
237 const size_t num_expected_matches, 227 const size_t num_expected_matches,
238 const ExpectedMatch expected_matches[], 228 const ExpectedMatch expected_matches[],
239 const ACMatches& matches); 229 const ACMatches& matches);
240 230
241 void ResetFieldTrialList(); 231 void ResetFieldTrialList();
242 232
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 net::TestURLFetcher* default_fetcher = 476 net::TestURLFetcher* default_fetcher =
487 test_factory_.GetFetcherByID( 477 test_factory_.GetFetcherByID(
488 SearchProvider::kDefaultProviderURLFetcherID); 478 SearchProvider::kDefaultProviderURLFetcherID);
489 ASSERT_TRUE(default_fetcher); 479 ASSERT_TRUE(default_fetcher);
490 480
491 // Tell the SearchProvider the default suggest query is done. 481 // Tell the SearchProvider the default suggest query is done.
492 default_fetcher->set_response_code(200); 482 default_fetcher->set_response_code(200);
493 default_fetcher->delegate()->OnURLFetchComplete(default_fetcher); 483 default_fetcher->delegate()->OnURLFetchComplete(default_fetcher);
494 } 484 }
495 485
496 void SearchProviderTest::ForcedQueryTestHelper(
497 const std::string& input,
498 const std::string& json,
499 const std::string expected_matches[3],
500 const std::string& error_description) {
501 // Send the query twice in order to have a synchronous pass after the first
502 // response is received. This is necessary because SearchProvider doesn't
503 // allow an asynchronous response to change the default match.
504 for (size_t i = 0; i < 2; ++i) {
505 QueryForInputAndWaitForFetcherResponses(
506 ASCIIToUTF16(input), false, json, std::string());
507 }
508
509 const ACMatches& matches = provider_->matches();
510 ASSERT_LE(matches.size(), 3u);
511 size_t i = 0;
512 // Ensure that the returned matches equal the expectations.
513 for (; i < matches.size(); ++i) {
514 EXPECT_EQ(ASCIIToUTF16(expected_matches[i]), matches[i].contents) <<
515 error_description;
516 }
517 // Ensure that no expected matches are missing.
518 for (; i < 3u; ++i) {
519 EXPECT_EQ(std::string(), expected_matches[i]) <<
520 "Case #" << i << ": " << error_description;
521 }
522 }
523
524 void SearchProviderTest::CheckMatches(const std::string& description, 486 void SearchProviderTest::CheckMatches(const std::string& description,
525 const size_t num_expected_matches, 487 const size_t num_expected_matches,
526 const ExpectedMatch expected_matches[], 488 const ExpectedMatch expected_matches[],
527 const ACMatches& matches) { 489 const ACMatches& matches) {
528 ASSERT_FALSE(matches.empty()); 490 ASSERT_FALSE(matches.empty());
529 ASSERT_LE(matches.size(), num_expected_matches); 491 ASSERT_LE(matches.size(), num_expected_matches);
530 size_t i = 0; 492 size_t i = 0;
531 SCOPED_TRACE(description); 493 SCOPED_TRACE(description);
532 // Ensure that the returned matches equal the expectations. 494 // Ensure that the returned matches equal the expectations.
533 for (; i < matches.size(); ++i) { 495 for (; i < matches.size(); ++i) {
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 // 'docs.google.com'. The search term should have a lower priority than the 763 // 'docs.google.com'. The search term should have a lower priority than the
802 // what you typed match. 764 // what you typed match.
803 ASSERT_EQ(2u, provider_->matches().size()); 765 ASSERT_EQ(2u, provider_->matches().size());
804 AutocompleteMatch term_match; 766 AutocompleteMatch term_match;
805 EXPECT_TRUE(FindMatchWithDestination(url, &term_match)); 767 EXPECT_TRUE(FindMatchWithDestination(url, &term_match));
806 EXPECT_GT(wyt_match.relevance, term_match.relevance); 768 EXPECT_GT(wyt_match.relevance, term_match.relevance);
807 EXPECT_TRUE(wyt_match.allowed_to_be_default_match); 769 EXPECT_TRUE(wyt_match.allowed_to_be_default_match);
808 EXPECT_TRUE(term_match.allowed_to_be_default_match); 770 EXPECT_TRUE(term_match.allowed_to_be_default_match);
809 } 771 }
810 772
811 TEST_F(SearchProviderTest, DontGiveNavsuggestionsInForcedQueryMode) {
812 const std::string kEmptyMatch;
813 struct {
814 const std::string json;
815 const std::string matches_in_default_mode[3];
816 const std::string matches_in_forced_query_mode[3];
817 } cases[] = {
818 // Without suggested relevance scores.
819 { "[\"a\",[\"http://a1.com\", \"a2\"],[],[],"
820 "{\"google:suggesttype\":[\"NAVIGATION\", \"QUERY\"]}]",
821 { "a", "a1.com", "a2" },
822 { "a", "a2", kEmptyMatch } },
823
824 // With suggested relevance scores in a situation where navsuggest would
825 // go second.
826 { "[\"a\",[\"http://a1.com\", \"a2\"],[],[],"
827 "{\"google:suggesttype\":[\"NAVIGATION\", \"QUERY\"],"
828 "\"google:suggestrelevance\":[1250, 1200]}]",
829 { "a", "a1.com", "a2" },
830 { "a", "a2", kEmptyMatch } },
831
832 // With suggested relevance scores in a situation where navsuggest
833 // would go first.
834 { "[\"a\",[\"http://a1.com\", \"a2\"],[],[],"
835 "{\"google:suggesttype\":[\"NAVIGATION\", \"QUERY\"],"
836 "\"google:suggestrelevance\":[1350, 1250]}]",
837 { "a1.com", "a", "a2" },
838 { "a", "a2", kEmptyMatch } },
839
840 // With suggested relevance scores in a situation where navsuggest
841 // would go first only because verbatim has been demoted.
842 { "[\"a\",[\"http://a1.com\", \"a2\"],[],[],"
843 "{\"google:suggesttype\":[\"NAVIGATION\", \"QUERY\"],"
844 "\"google:suggestrelevance\":[1450, 1400],"
845 "\"google:verbatimrelevance\":1350}]",
846 { "a1.com", "a2", "a" },
847 { "a2", "a", kEmptyMatch } },
848 };
849
850 for (size_t i = 0; i < arraysize(cases); ++i) {
851 ForcedQueryTestHelper("a", cases[i].json, cases[i].matches_in_default_mode,
852 "regular input with json=" + cases[i].json);
853 ForcedQueryTestHelper("?a", cases[i].json,
854 cases[i].matches_in_forced_query_mode,
855 "forced query input with json=" + cases[i].json);
856 }
857 }
858
859 // A multiword search with one visit should not autocomplete until multiple 773 // A multiword search with one visit should not autocomplete until multiple
860 // words are typed. 774 // words are typed.
861 TEST_F(SearchProviderTest, DontAutocompleteUntilMultipleWordsTyped) { 775 TEST_F(SearchProviderTest, DontAutocompleteUntilMultipleWordsTyped) {
862 GURL term_url(AddSearchToHistory(default_t_url_, ASCIIToUTF16("one search"), 776 GURL term_url(AddSearchToHistory(default_t_url_, ASCIIToUTF16("one search"),
863 1)); 777 1));
864 profile_.BlockUntilHistoryProcessesPendingRequests(); 778 profile_.BlockUntilHistoryProcessesPendingRequests();
865 779
866 AutocompleteMatch wyt_match; 780 AutocompleteMatch wyt_match;
867 ASSERT_NO_FATAL_FAILURE(QueryForInputAndSetWYTMatch(ASCIIToUTF16("on"), 781 ASSERT_NO_FATAL_FAILURE(QueryForInputAndSetWYTMatch(ASCIIToUTF16("on"),
868 &wyt_match)); 782 &wyt_match));
(...skipping 1857 matching lines...) Expand 10 before | Expand all | Expand 10 after
2726 { "www.ab", "https://www.abc.com/path/file.htm?q=x#foo", 2640 { "www.ab", "https://www.abc.com/path/file.htm?q=x#foo",
2727 "https://www.abc.com/path/file.htm?q=x#foo", 2641 "https://www.abc.com/path/file.htm?q=x#foo",
2728 "c.com/path/file.htm?q=x#foo", true, false }, 2642 "c.com/path/file.htm?q=x#foo", true, false },
2729 { "ab", "https://www.abc.com/path/file.htm?q=x#foo", 2643 { "ab", "https://www.abc.com/path/file.htm?q=x#foo",
2730 "https://www.abc.com/path/file.htm?q=x#foo", 2644 "https://www.abc.com/path/file.htm?q=x#foo",
2731 "c.com/path/file.htm?q=x#foo", true, false }, 2645 "c.com/path/file.htm?q=x#foo", true, false },
2732 { "ab", "https://abc.com/path/file.htm?q=x#foo", 2646 { "ab", "https://abc.com/path/file.htm?q=x#foo",
2733 "https://abc.com/path/file.htm?q=x#foo", 2647 "https://abc.com/path/file.htm?q=x#foo",
2734 "c.com/path/file.htm?q=x#foo", true, false }, 2648 "c.com/path/file.htm?q=x#foo", true, false },
2735 2649
2736 // Forced query input should inline and retain the "?" prefix.
2737 { "?http://www.ab", "http://www.abc.com",
2738 "?http://www.abc.com", "c.com", true, false },
2739 { "?www.ab", "http://www.abc.com",
2740 "?www.abc.com", "c.com", true, false },
2741 { "?ab", "http://www.abc.com",
2742 "?www.abc.com", "c.com", true, false },
2743 { "?abc.com", "http://www.abc.com",
2744 "?www.abc.com", std::string(), true, true },
2745 }; 2650 };
2746 2651
2747 for (size_t i = 0; i < arraysize(cases); ++i) { 2652 for (size_t i = 0; i < arraysize(cases); ++i) {
2748 // First test regular mode. 2653 // First test regular mode.
2749 QueryForInput(ASCIIToUTF16(cases[i].input), false, false); 2654 QueryForInput(ASCIIToUTF16(cases[i].input), false, false);
2750 SearchSuggestionParser::NavigationResult result( 2655 SearchSuggestionParser::NavigationResult result(
2751 ChromeAutocompleteSchemeClassifier(&profile_), GURL(cases[i].url), 2656 ChromeAutocompleteSchemeClassifier(&profile_), GURL(cases[i].url),
2752 AutocompleteMatchType::NAVSUGGEST, base::string16(), std::string(), 2657 AutocompleteMatchType::NAVSUGGEST, base::string16(), std::string(),
2753 false, 0, false, ASCIIToUTF16(cases[i].input)); 2658 false, 0, false, ASCIIToUTF16(cases[i].input));
2754 result.set_received_after_last_keystroke(false); 2659 result.set_received_after_last_keystroke(false);
(...skipping 843 matching lines...) Expand 10 before | Expand all | Expand 10 after
3598 } 3503 }
3599 3504
3600 TEST_F(SearchProviderTest, DoesNotProvideOnFocus) { 3505 TEST_F(SearchProviderTest, DoesNotProvideOnFocus) {
3601 AutocompleteInput input( 3506 AutocompleteInput input(
3602 base::ASCIIToUTF16("f"), base::string16::npos, std::string(), GURL(), 3507 base::ASCIIToUTF16("f"), base::string16::npos, std::string(), GURL(),
3603 metrics::OmniboxEventProto::INVALID_SPEC, false, true, true, true, true, 3508 metrics::OmniboxEventProto::INVALID_SPEC, false, true, true, true, true,
3604 ChromeAutocompleteSchemeClassifier(&profile_)); 3509 ChromeAutocompleteSchemeClassifier(&profile_));
3605 provider_->Start(input, false); 3510 provider_->Start(input, false);
3606 EXPECT_TRUE(provider_->matches().empty()); 3511 EXPECT_TRUE(provider_->matches().empty());
3607 } 3512 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/autocomplete_browsertest.cc ('k') | chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698