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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 } | 59 } |
60 | 60 |
61 template<class ResultType> | 61 template<class ResultType> |
62 void KeywordProviderTest::RunTest( | 62 void KeywordProviderTest::RunTest( |
63 test_data<ResultType>* keyword_cases, | 63 test_data<ResultType>* keyword_cases, |
64 int num_cases, | 64 int num_cases, |
65 ResultType AutocompleteMatch::* member) { | 65 ResultType AutocompleteMatch::* member) { |
66 ACMatches matches; | 66 ACMatches matches; |
67 for (int i = 0; i < num_cases; ++i) { | 67 for (int i = 0; i < num_cases; ++i) { |
68 AutocompleteInput input(keyword_cases[i].input, string16::npos, string16(), | 68 AutocompleteInput input(keyword_cases[i].input, string16::npos, string16(), |
69 true, false, true, AutocompleteInput::ALL_MATCHES); | 69 GURL(), true, false, true, |
| 70 AutocompleteInput::ALL_MATCHES); |
70 kw_provider_->Start(input, false); | 71 kw_provider_->Start(input, false); |
71 EXPECT_TRUE(kw_provider_->done()); | 72 EXPECT_TRUE(kw_provider_->done()); |
72 matches = kw_provider_->matches(); | 73 matches = kw_provider_->matches(); |
73 EXPECT_EQ(keyword_cases[i].num_results, matches.size()) << | 74 EXPECT_EQ(keyword_cases[i].num_results, matches.size()) << |
74 ASCIIToUTF16("Input was: ") + keyword_cases[i].input; | 75 ASCIIToUTF16("Input was: ") + keyword_cases[i].input; |
75 if (matches.size() == keyword_cases[i].num_results) { | 76 if (matches.size() == keyword_cases[i].num_results) { |
76 for (size_t j = 0; j < keyword_cases[i].num_results; ++j) { | 77 for (size_t j = 0; j < keyword_cases[i].num_results; ++j) { |
77 EXPECT_EQ(keyword_cases[i].output[j], matches[j].*member); | 78 EXPECT_EQ(keyword_cases[i].output[j], matches[j].*member); |
78 } | 79 } |
79 } | 80 } |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 // Extra space after keyword, no trailing space, cursor at the end. | 273 // Extra space after keyword, no trailing space, cursor at the end. |
273 { "aa foo", 7u, true, "aa.com?foo={searchTerms}", "foo", 3u }, | 274 { "aa foo", 7u, true, "aa.com?foo={searchTerms}", "foo", 3u }, |
274 // Extra space after keyword, no trailing space, cursor in the middle. | 275 // Extra space after keyword, no trailing space, cursor in the middle. |
275 { "aa foo", 5u, true, "aa.com?foo={searchTerms}", "foo", 1u }, | 276 { "aa foo", 5u, true, "aa.com?foo={searchTerms}", "foo", 1u }, |
276 | 277 |
277 // Disallow exact keyword match. | 278 // Disallow exact keyword match. |
278 { "aa foo", string16::npos, false, "", "aa foo", string16::npos }, | 279 { "aa foo", string16::npos, false, "", "aa foo", string16::npos }, |
279 }; | 280 }; |
280 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { | 281 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { |
281 AutocompleteInput input(ASCIIToUTF16(cases[i].text), | 282 AutocompleteInput input(ASCIIToUTF16(cases[i].text), |
282 cases[i].cursor_position, string16(), | 283 cases[i].cursor_position, string16(), GURL(), |
283 false, false, cases[i].allow_exact_keyword_match, | 284 false, false, cases[i].allow_exact_keyword_match, |
284 AutocompleteInput::ALL_MATCHES); | 285 AutocompleteInput::ALL_MATCHES); |
285 const TemplateURL* url = | 286 const TemplateURL* url = |
286 KeywordProvider::GetSubstitutingTemplateURLForInput(model_.get(), | 287 KeywordProvider::GetSubstitutingTemplateURLForInput(model_.get(), |
287 &input); | 288 &input); |
288 if (cases[i].expected_url.empty()) | 289 if (cases[i].expected_url.empty()) |
289 EXPECT_FALSE(url); | 290 EXPECT_FALSE(url); |
290 else | 291 else |
291 EXPECT_EQ(cases[i].expected_url, url->url()); | 292 EXPECT_EQ(cases[i].expected_url, url->url()); |
292 EXPECT_EQ(ASCIIToUTF16(cases[i].updated_text), input.text()); | 293 EXPECT_EQ(ASCIIToUTF16(cases[i].updated_text), input.text()); |
293 EXPECT_EQ(cases[i].updated_cursor_position, input.cursor_position()); | 294 EXPECT_EQ(cases[i].updated_cursor_position, input.cursor_position()); |
294 } | 295 } |
295 } | 296 } |
OLD | NEW |