| 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 // Disallow exact keyword match. |
| 251 { "aa foo", string16::npos, false, "", "aa foo", string16::npos }, |
| 252 }; |
| 253 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { |
| 254 AutocompleteInput input(ASCIIToUTF16(cases[i].text), |
| 255 cases[i].cursor_position, string16(), |
| 256 false, false, cases[i].allow_exact_keyword_match, |
| 257 AutocompleteInput::ALL_MATCHES); |
| 258 const TemplateURL* url = |
| 259 KeywordProvider::GetSubstitutingTemplateURLForInput(model_.get(), |
| 260 &input); |
| 261 if (cases[i].expected_url.empty()) |
| 262 EXPECT_FALSE(url); |
| 263 else |
| 264 EXPECT_EQ(cases[i].expected_url, url->url()); |
| 265 EXPECT_EQ(ASCIIToUTF16(cases[i].updated_text), input.text()); |
| 266 EXPECT_EQ(cases[i].updated_cursor_position, input.cursor_position()); |
| 267 } |
| 268 } |
| OLD | NEW |