Chromium Code Reviews| 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..1c062d6496270b349614604cd6d16cbb3abc9ed0 100644 |
| --- a/chrome/browser/autocomplete/keyword_provider_unittest.cc |
| +++ b/chrome/browser/autocomplete/keyword_provider_unittest.cc |
| @@ -224,3 +224,56 @@ 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 }, |
| + // Cursor at the end. |
| + { "aa foo", 6u, true, "aa.com?foo={searchTerms}", "foo", 3u }, |
| + // Cursor before the first character of the remaining text. |
| + { "aa foo", 3u, true, "aa.com?foo={searchTerms}", "foo", 0u }, |
| + |
| + // Trailing space. |
| + { "aa foo ", 7u, true, "aa.com?foo={searchTerms}", "foo", string16::npos }, |
| + // Trailing space without remaining text, cursor in the middle. |
| + { "aa ", 3u, true, "aa.com?foo={searchTerms}", "", string16::npos }, |
| + // Trailing space without remaining text, cursor at the end. |
| + { "aa ", 4u, true, "aa.com?foo={searchTerms}", "", string16::npos }, |
| + // Extra space after keyword, cursor at the end. |
| + { "aa foo ", 8u, true, "aa.com?foo={searchTerms}", "foo", string16::npos }, |
| + // Extra space after keyword, cursor in the middle. |
| + { "aa foo ", 3u, true, "aa.com?foo={searchTerms}", "foo", string16::npos }, |
| + |
|
Mark P
2013/01/30 19:43:53
Can you test extra space after keyword but no trai
Bart N.
2013/01/30 21:22:58
Done.
Mark P
2013/01/31 19:46:12
Can you please upload the new changelist? I don't
|
| + // 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()); |
| + } |
| +} |