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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 { "aa FoO", 4u, true, "aa.com?foo={searchTerms}", "FoO", 1u },
246 { "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.
247
248 // Disallow exact keyword match.
249 { "aa foo", string16::npos, false, "", "aa foo", string16::npos },
250 };
251 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) {
252 AutocompleteInput input(ASCIIToUTF16(cases[i].text),
253 cases[i].cursor_position, string16(),
254 false, false, cases[i].allow_exact_keyword_match,
255 AutocompleteInput::ALL_MATCHES);
256 const TemplateURL* url =
257 KeywordProvider::GetSubstitutingTemplateURLForInput(model_.get(),
258 &input);
259 if (cases[i].expected_url.empty())
260 EXPECT_FALSE(url);
261 else
262 EXPECT_EQ(cases[i].expected_url, url->url());
263 EXPECT_EQ(ASCIIToUTF16(cases[i].updated_text), input.text());
264 EXPECT_EQ(cases[i].updated_cursor_position, input.cursor_position());
265 }
266 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698