| OLD | NEW | 
|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "base/message_loop.h" | 5 #include "base/message_loop.h" | 
| 6 #include "base/utf_string_conversions.h" | 6 #include "base/utf_string_conversions.h" | 
| 7 #include "chrome/browser/autocomplete/autocomplete_match.h" | 7 #include "chrome/browser/autocomplete/autocomplete_match.h" | 
| 8 #include "chrome/browser/autocomplete/keyword_provider.h" | 8 #include "chrome/browser/autocomplete/keyword_provider.h" | 
| 9 #include "chrome/browser/search_engines/template_url.h" | 9 #include "chrome/browser/search_engines/template_url.h" | 
| 10 #include "chrome/browser/search_engines/template_url_service.h" | 10 #include "chrome/browser/search_engines/template_url_service.h" | 
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 217 } | 217 } | 
| 218 | 218 | 
| 219 TEST_F(KeywordProviderTest, GetKeywordForInput) { | 219 TEST_F(KeywordProviderTest, GetKeywordForInput) { | 
| 220   EXPECT_EQ(ASCIIToUTF16("aa"), | 220   EXPECT_EQ(ASCIIToUTF16("aa"), | 
| 221       kw_provider_->GetKeywordForText(ASCIIToUTF16("aa"))); | 221       kw_provider_->GetKeywordForText(ASCIIToUTF16("aa"))); | 
| 222   EXPECT_EQ(string16(), | 222   EXPECT_EQ(string16(), | 
| 223       kw_provider_->GetKeywordForText(ASCIIToUTF16("aafoo"))); | 223       kw_provider_->GetKeywordForText(ASCIIToUTF16("aafoo"))); | 
| 224   EXPECT_EQ(string16(), | 224   EXPECT_EQ(string16(), | 
| 225       kw_provider_->GetKeywordForText(ASCIIToUTF16("aa foo"))); | 225       kw_provider_->GetKeywordForText(ASCIIToUTF16("aa foo"))); | 
| 226 } | 226 } | 
|  | 227 | 
|  | 228 TEST_F(KeywordProviderTest, GetSubstitutingTemplateURLForInput) { | 
|  | 229   struct { | 
|  | 230     const std::string text; | 
|  | 231     const size_t cursor_position; | 
|  | 232     const bool allow_exact_keyword_match; | 
|  | 233     const std::string expected_url; | 
|  | 234     const std::string updated_text; | 
|  | 235     const size_t updated_cursor_position; | 
|  | 236   } cases[] = { | 
|  | 237     { "foo", string16::npos, true, "", "foo", string16::npos }, | 
|  | 238     { "aa foo", string16::npos, true, "aa.com?foo={searchTerms}", "foo", | 
|  | 239       string16::npos }, | 
|  | 240 | 
|  | 241     // Cursor adjustment. | 
|  | 242     { "aa foo", string16::npos, true, "aa.com?foo={searchTerms}", "foo", | 
|  | 243       string16::npos }, | 
|  | 244     { "aa foo", 4u, true, "aa.com?foo={searchTerms}", "foo", 1u }, | 
|  | 245     // Cursor at the end. | 
|  | 246     { "aa foo", 6u, true, "aa.com?foo={searchTerms}", "foo", 3u }, | 
|  | 247     // Cursor before the first character of the remaining text. | 
|  | 248     { "aa foo", 3u, true, "aa.com?foo={searchTerms}", "foo", 0u }, | 
|  | 249 | 
|  | 250     // Trailing space. | 
|  | 251     { "aa foo ", 7u, true, "aa.com?foo={searchTerms}", "foo", string16::npos }, | 
|  | 252     // Trailing space without remaining text, cursor in the middle. | 
|  | 253     { "aa  ", 3u, true, "aa.com?foo={searchTerms}", "", string16::npos }, | 
|  | 254     // Trailing space without remaining text, cursor at the end. | 
|  | 255     { "aa  ", 4u, true, "aa.com?foo={searchTerms}", "", string16::npos }, | 
|  | 256     // Extra space after keyword, cursor at the end. | 
|  | 257     { "aa  foo ", 8u, true, "aa.com?foo={searchTerms}", "foo", string16::npos }, | 
|  | 258     // Extra space after keyword, cursor in the middle. | 
|  | 259     { "aa  foo ", 3u, true, "aa.com?foo={searchTerms}", "foo", string16::npos }, | 
|  | 260     // Extra space after keyword, no trailing space, cursor at the end. | 
|  | 261     { "aa  foo", 7u, true, "aa.com?foo={searchTerms}", "foo", 3u }, | 
|  | 262     // Extra space after keyword, no trailing space, cursor in the middle. | 
|  | 263     { "aa  foo", 5u, true, "aa.com?foo={searchTerms}", "foo", 1u }, | 
|  | 264 | 
|  | 265     // Disallow exact keyword match. | 
|  | 266     { "aa foo", string16::npos, false, "", "aa foo", string16::npos }, | 
|  | 267   }; | 
|  | 268   for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { | 
|  | 269     AutocompleteInput input(ASCIIToUTF16(cases[i].text), | 
|  | 270                             cases[i].cursor_position, string16(), | 
|  | 271                             false, false, cases[i].allow_exact_keyword_match, | 
|  | 272                             AutocompleteInput::ALL_MATCHES); | 
|  | 273     const TemplateURL* url = | 
|  | 274         KeywordProvider::GetSubstitutingTemplateURLForInput(model_.get(), | 
|  | 275                                                             &input); | 
|  | 276     if (cases[i].expected_url.empty()) | 
|  | 277       EXPECT_FALSE(url); | 
|  | 278     else | 
|  | 279       EXPECT_EQ(cases[i].expected_url, url->url()); | 
|  | 280     EXPECT_EQ(ASCIIToUTF16(cases[i].updated_text), input.text()); | 
|  | 281     EXPECT_EQ(cases[i].updated_cursor_position, input.cursor_position()); | 
|  | 282   } | 
|  | 283 } | 
| OLD | NEW | 
|---|