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

Unified Diff: chrome/browser/autocomplete/keyword_provider_unittest.cc

Issue 12039053: Fix cursor position for default provider searches in keyword mode. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Addressed Mark's comments. Created 7 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/autocomplete/keyword_provider_unittest.cc
diff --git a/chrome/browser/autocomplete/keyword_provider_unittest.cc b/chrome/browser/autocomplete/keyword_provider_unittest.cc
index ef192d7fbe800d5dcb250b873b27c5446569c623..8f1600d625ad1ac3b629ccfcd7657afacbd5af7f 100644
--- a/chrome/browser/autocomplete/keyword_provider_unittest.cc
+++ b/chrome/browser/autocomplete/keyword_provider_unittest.cc
@@ -224,3 +224,43 @@ TEST_F(KeywordProviderTest, GetKeywordForInput) {
EXPECT_EQ(string16(),
kw_provider_->GetKeywordForText(ASCIIToUTF16("aa foo")));
}
+
+TEST_F(KeywordProviderTest, GetSubstitutingTemplateURLForInput) {
+ struct {
+ const std::string text;
+ const size_t cursor_position;
+ const bool allow_exact_keyword_match;
+ const std::string expected_url;
+ const std::string updated_text;
+ const size_t updated_cursor_position;
+ } cases[] = {
+ { "foo", string16::npos, true, "", "foo", string16::npos },
+ { "aa foo", string16::npos, true, "aa.com?foo={searchTerms}", "foo",
+ string16::npos },
+
+ // Cursor adjustment.
+ { "aa foo", string16::npos, true, "aa.com?foo={searchTerms}", "foo",
+ string16::npos },
+ { "aa foo", 4u, true, "aa.com?foo={searchTerms}", "foo", 1u },
+ { "aa FoO", 4u, true, "aa.com?foo={searchTerms}", "FoO", 1u },
+ { "aa foo", 1u, true, "aa.com?foo={searchTerms}", "foo", 0u },
Mark P 2013/01/25 21:19:15 Please comment this line about cursor in keyword.
Mark P 2013/01/25 21:19:15 For completeness, please add a test with the curso
Bart N. 2013/01/29 21:28:17 Done.
Bart N. 2013/01/29 21:28:17 I had to remove this test because of DCHECKs.
+
+ // Disallow exact keyword match.
+ { "aa foo", string16::npos, false, "", "aa foo", string16::npos },
+ };
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) {
+ AutocompleteInput input(ASCIIToUTF16(cases[i].text),
+ cases[i].cursor_position, string16(),
+ false, false, cases[i].allow_exact_keyword_match,
+ AutocompleteInput::ALL_MATCHES);
+ const TemplateURL* url =
+ KeywordProvider::GetSubstitutingTemplateURLForInput(model_.get(),
+ &input);
+ if (cases[i].expected_url.empty())
+ EXPECT_FALSE(url);
+ else
+ EXPECT_EQ(cases[i].expected_url, url->url());
+ EXPECT_EQ(ASCIIToUTF16(cases[i].updated_text), input.text());
+ EXPECT_EQ(cases[i].updated_cursor_position, input.cursor_position());
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698