| 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/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/message_loop/message_loop.h" | 6 #include "base/message_loop/message_loop.h" |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/browser/autocomplete/autocomplete_match.h" | 8 #include "chrome/browser/autocomplete/autocomplete_match.h" |
| 9 #include "chrome/browser/autocomplete/keyword_provider.h" | 9 #include "chrome/browser/autocomplete/keyword_provider.h" |
| 10 #include "chrome/browser/search_engines/template_url.h" | 10 #include "chrome/browser/search_engines/template_url.h" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 template<class ResultType> | 74 template<class ResultType> |
| 75 void KeywordProviderTest::RunTest( | 75 void KeywordProviderTest::RunTest( |
| 76 TestData<ResultType>* keyword_cases, | 76 TestData<ResultType>* keyword_cases, |
| 77 int num_cases, | 77 int num_cases, |
| 78 ResultType AutocompleteMatch::* member) { | 78 ResultType AutocompleteMatch::* member) { |
| 79 ACMatches matches; | 79 ACMatches matches; |
| 80 for (int i = 0; i < num_cases; ++i) { | 80 for (int i = 0; i < num_cases; ++i) { |
| 81 SCOPED_TRACE(keyword_cases[i].input); | 81 SCOPED_TRACE(keyword_cases[i].input); |
| 82 AutocompleteInput input(keyword_cases[i].input, base::string16::npos, | 82 AutocompleteInput input(keyword_cases[i].input, base::string16::npos, |
| 83 base::string16(), GURL(), | 83 base::string16(), GURL(), |
| 84 AutocompleteInput::INVALID_SPEC, true, | 84 metrics::OmniboxEventProto::INVALID_SPEC, true, |
| 85 false, true, true); | 85 false, true, true); |
| 86 kw_provider_->Start(input, false); | 86 kw_provider_->Start(input, false); |
| 87 EXPECT_TRUE(kw_provider_->done()); | 87 EXPECT_TRUE(kw_provider_->done()); |
| 88 matches = kw_provider_->matches(); | 88 matches = kw_provider_->matches(); |
| 89 ASSERT_EQ(keyword_cases[i].num_results, matches.size()); | 89 ASSERT_EQ(keyword_cases[i].num_results, matches.size()); |
| 90 for (size_t j = 0; j < matches.size(); ++j) { | 90 for (size_t j = 0; j < matches.size(); ++j) { |
| 91 EXPECT_EQ(keyword_cases[i].output[j].member, matches[j].*member); | 91 EXPECT_EQ(keyword_cases[i].output[j].member, matches[j].*member); |
| 92 EXPECT_EQ(keyword_cases[i].output[j].allowed_to_be_default_match, | 92 EXPECT_EQ(keyword_cases[i].output[j].allowed_to_be_default_match, |
| 93 matches[j].allowed_to_be_default_match); | 93 matches[j].allowed_to_be_default_match); |
| 94 } | 94 } |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 // Extra space after keyword, no trailing space, cursor in the middle. | 316 // Extra space after keyword, no trailing space, cursor in the middle. |
| 317 { "aa foo", 5u, true, "aa.com?foo={searchTerms}", "foo", 1u }, | 317 { "aa foo", 5u, true, "aa.com?foo={searchTerms}", "foo", 1u }, |
| 318 | 318 |
| 319 // Disallow exact keyword match. | 319 // Disallow exact keyword match. |
| 320 { "aa foo", base::string16::npos, false, "", "aa foo", | 320 { "aa foo", base::string16::npos, false, "", "aa foo", |
| 321 base::string16::npos }, | 321 base::string16::npos }, |
| 322 }; | 322 }; |
| 323 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { | 323 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { |
| 324 AutocompleteInput input(ASCIIToUTF16(cases[i].text), | 324 AutocompleteInput input(ASCIIToUTF16(cases[i].text), |
| 325 cases[i].cursor_position, base::string16(), GURL(), | 325 cases[i].cursor_position, base::string16(), GURL(), |
| 326 AutocompleteInput::INVALID_SPEC, false, false, | 326 metrics::OmniboxEventProto::INVALID_SPEC, false, |
| 327 cases[i].allow_exact_keyword_match, true); | 327 false, cases[i].allow_exact_keyword_match, true); |
| 328 const TemplateURL* url = | 328 const TemplateURL* url = |
| 329 KeywordProvider::GetSubstitutingTemplateURLForInput(model_.get(), | 329 KeywordProvider::GetSubstitutingTemplateURLForInput(model_.get(), |
| 330 &input); | 330 &input); |
| 331 if (cases[i].expected_url.empty()) | 331 if (cases[i].expected_url.empty()) |
| 332 EXPECT_FALSE(url); | 332 EXPECT_FALSE(url); |
| 333 else | 333 else |
| 334 EXPECT_EQ(cases[i].expected_url, url->url()); | 334 EXPECT_EQ(cases[i].expected_url, url->url()); |
| 335 EXPECT_EQ(ASCIIToUTF16(cases[i].updated_text), input.text()); | 335 EXPECT_EQ(ASCIIToUTF16(cases[i].updated_text), input.text()); |
| 336 EXPECT_EQ(cases[i].updated_cursor_position, input.cursor_position()); | 336 EXPECT_EQ(cases[i].updated_cursor_position, input.cursor_position()); |
| 337 } | 337 } |
| 338 } | 338 } |
| 339 | 339 |
| 340 // If extra query params are specified on the command line, they should be | 340 // If extra query params are specified on the command line, they should be |
| 341 // reflected (only) in the default search provider's destination URL. | 341 // reflected (only) in the default search provider's destination URL. |
| 342 TEST_F(KeywordProviderTest, ExtraQueryParams) { | 342 TEST_F(KeywordProviderTest, ExtraQueryParams) { |
| 343 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 343 CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 344 switches::kExtraSearchQueryParams, "a=b"); | 344 switches::kExtraSearchQueryParams, "a=b"); |
| 345 | 345 |
| 346 TestData<GURL> url_cases[] = { | 346 TestData<GURL> url_cases[] = { |
| 347 { ASCIIToUTF16("a 1 2 3"), 3, | 347 { ASCIIToUTF16("a 1 2 3"), 3, |
| 348 { { GURL("aa.com?a=b&foo=1+2+3"), false }, | 348 { { GURL("aa.com?a=b&foo=1+2+3"), false }, |
| 349 { GURL("bogus URL 1+2+3"), false }, | 349 { GURL("bogus URL 1+2+3"), false }, |
| 350 { GURL("http://aaaa/?aaaa=1&b=1+2+3&c"), false } } }, | 350 { GURL("http://aaaa/?aaaa=1&b=1+2+3&c"), false } } }, |
| 351 }; | 351 }; |
| 352 | 352 |
| 353 RunTest<GURL>(url_cases, arraysize(url_cases), | 353 RunTest<GURL>(url_cases, arraysize(url_cases), |
| 354 &AutocompleteMatch::destination_url); | 354 &AutocompleteMatch::destination_url); |
| 355 } | 355 } |
| OLD | NEW |