diff options
author | suzhe@google.com <suzhe@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-26 01:45:32 +0000 |
---|---|---|
committer | suzhe@google.com <suzhe@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-26 01:45:32 +0000 |
commit | 8f8ff994a1f9085ec49c40756db85d5da37ae807 (patch) | |
tree | bd2a8838269076a5d28cad055a5dde19d6f17c16 /chrome/browser/autocomplete | |
parent | fc8893b93c962a89b1d3ce9a8450b68b0e6e95f3 (diff) | |
download | chromium_src-8f8ff994a1f9085ec49c40756db85d5da37ae807.zip chromium_src-8f8ff994a1f9085ec49c40756db85d5da37ae807.tar.gz chromium_src-8f8ff994a1f9085ec49c40756db85d5da37ae807.tar.bz2 |
Always allow exact match non-substituting keywords.
BUG=70807
TEST=See bug report.
Review URL: http://codereview.chromium.org/6334017
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@72586 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autocomplete')
-rw-r--r-- | chrome/browser/autocomplete/autocomplete.h | 3 | ||||
-rw-r--r-- | chrome/browser/autocomplete/autocomplete_edit_view_browsertest.cc | 59 | ||||
-rw-r--r-- | chrome/browser/autocomplete/keyword_provider.cc | 14 | ||||
-rw-r--r-- | chrome/browser/autocomplete/keyword_provider.h | 10 |
4 files changed, 73 insertions, 13 deletions
diff --git a/chrome/browser/autocomplete/autocomplete.h b/chrome/browser/autocomplete/autocomplete.h index 7853f5aa..a69390b 100644 --- a/chrome/browser/autocomplete/autocomplete.h +++ b/chrome/browser/autocomplete/autocomplete.h @@ -573,7 +573,8 @@ class AutocompleteController : public ACProviderListener { // // |allow_exact_keyword_match| should be false when triggering keyword mode on // the input string would be surprising or wrong, e.g. when highlighting text - // in a page and telling the browser to search for it or navigate to it. + // in a page and telling the browser to search for it or navigate to it. This + // parameter only applies to substituting keywords. // If |synchronous_only| is true, the controller asks the providers to only // return matches which are synchronously available, which should mean that diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_browsertest.cc b/chrome/browser/autocomplete/autocomplete_edit_view_browsertest.cc index 4cc3019..116f900 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view_browsertest.cc +++ b/chrome/browser/autocomplete/autocomplete_edit_view_browsertest.cc @@ -791,6 +791,56 @@ class AutocompleteEditViewTest : public InProcessBrowserTest, ASSERT_TRUE(edit_view->GetText().empty()); } + void NonSubstitutingKeywordTest() { + AutocompleteEditView* edit_view = NULL; + ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); + AutocompletePopupModel* popup_model = edit_view->model()->popup_model(); + ASSERT_TRUE(popup_model); + + TemplateURLModel* template_url_model = + browser()->profile()->GetTemplateURLModel(); + + // Add a non-default substituting keyword. + TemplateURL* template_url = new TemplateURL(); + template_url->SetURL("http://abc.com/{searchTerms}", 0, 0); + template_url->set_keyword(UTF8ToUTF16(kSearchText)); + template_url->set_short_name(UTF8ToUTF16("Search abc")); + template_url_model->Add(template_url); + + edit_view->SetUserText(string16()); + + // Non-default substituting keyword shouldn't be matched by default. + ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys)); + ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); + ASSERT_TRUE(popup_model->IsOpen()); + + // Check if the default match result is Search Primary Provider. + ASSERT_EQ(AutocompleteMatch::SEARCH_WHAT_YOU_TYPED, + popup_model->result().default_match()->type); + ASSERT_EQ(kSearchTextURL, + popup_model->result().default_match()->destination_url.spec()); + + edit_view->SetUserText(string16()); + ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); + ASSERT_FALSE(popup_model->IsOpen()); + + // Try a non-substituting keyword. + template_url_model->Remove(template_url); + template_url = new TemplateURL(); + template_url->SetURL("http://abc.com/", 0, 0); + template_url->set_keyword(UTF8ToUTF16(kSearchText)); + template_url->set_short_name(UTF8ToUTF16("abc")); + template_url_model->Add(template_url); + + // We always allow exact matches for non-substituting keywords. + ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys)); + ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); + ASSERT_TRUE(popup_model->IsOpen()); + ASSERT_EQ(AutocompleteMatch::HISTORY_KEYWORD, + popup_model->result().default_match()->type); + ASSERT_EQ("http://abc.com/", + popup_model->result().default_match()->destination_url.spec()); + } }; // Test if ctrl-* accelerators are workable in omnibox. @@ -844,6 +894,10 @@ IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, AcceptKeywordBySpace) { AcceptKeywordBySpaceTest(); } +IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, NonSubstitutingKeywordTest) { + NonSubstitutingKeywordTest(); +} + #if defined(OS_LINUX) // TODO(oshima): enable these tests for views-implmentation when // these featuers are supported. @@ -1020,4 +1074,9 @@ IN_PROC_BROWSER_TEST_F(AutocompleteEditViewViewsTest, AcceptKeywordBySpace) { AcceptKeywordBySpaceTest(); } +IN_PROC_BROWSER_TEST_F(AutocompleteEditViewViewsTest, + NonSubstitutingKeywordTest) { + NonSubstitutingKeywordTest(); +} + #endif diff --git a/chrome/browser/autocomplete/keyword_provider.cc b/chrome/browser/autocomplete/keyword_provider.cc index 10cf328..97ccc5c 100644 --- a/chrome/browser/autocomplete/keyword_provider.cc +++ b/chrome/browser/autocomplete/keyword_provider.cc @@ -365,15 +365,15 @@ void KeywordProvider::FillInURLAndContents( // static int KeywordProvider::CalculateRelevance(AutocompleteInput::Type type, bool complete, - bool no_query_text_needed, + bool supports_replacement, + bool prefer_keyword, bool allow_exact_keyword_match) { if (!complete) return (type == AutocompleteInput::URL) ? 700 : 450; - if (!allow_exact_keyword_match) - return 1100; - if (no_query_text_needed) + if (!supports_replacement || (allow_exact_keyword_match && prefer_keyword)) return 1500; - return (type == AutocompleteInput::QUERY) ? 1450 : 1100; + return (allow_exact_keyword_match && (type == AutocompleteInput::QUERY)) ? + 1450 : 1100; } AutocompleteMatch KeywordProvider::CreateAutocompleteMatch( @@ -400,7 +400,7 @@ AutocompleteMatch KeywordProvider::CreateAutocompleteMatch( // When the user wants keyword matches to take // preference, score them highly regardless of // whether the input provides query text. - input.prefer_keyword() || !supports_replacement, + supports_replacement, input.prefer_keyword(), input.allow_exact_keyword_match()); } AutocompleteMatch result(this, relevance, false, @@ -494,7 +494,7 @@ void KeywordProvider::Observe(NotificationType type, // and subtract 1 for each subsequent suggestion from the extension. // We know that |complete| is true, because we wouldn't get results from // the extension unless the full keyword had been typed. - int first_relevance = CalculateRelevance(input.type(), true, + int first_relevance = CalculateRelevance(input.type(), true, true, input.prefer_keyword(), input.allow_exact_keyword_match()); extension_suggest_matches_.push_back(CreateAutocompleteMatch( model, keyword, input, keyword.length(), diff --git a/chrome/browser/autocomplete/keyword_provider.h b/chrome/browser/autocomplete/keyword_provider.h index bd5cb9e..6406fb9 100644 --- a/chrome/browser/autocomplete/keyword_provider.h +++ b/chrome/browser/autocomplete/keyword_provider.h @@ -109,14 +109,14 @@ class KeywordProvider : public AutocompleteProvider, AutocompleteMatch* match); // Determines the relevance for some input, given its type, whether the user - // typed the complete keyword, and whether the keyword needs query text (true - // if the keyword supports replacement and the user isn't in "prefer keyword - // matches" mode). + // typed the complete keyword, and whether the user is in "prefer keyword + // matches" mode, and whether the keyword supports replacement. // If |allow_exact_keyword_match| is false, the relevance for complete - // keywords is degraded. + // keywords that support replacements is degraded. static int CalculateRelevance(AutocompleteInput::Type type, bool complete, - bool no_query_text_needed, + bool support_replacement, + bool prefer_keyword, bool allow_exact_keyword_match); // Creates a fully marked-up AutocompleteMatch from the user's input. |