OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/omnibox/browser/keyword_provider.h" | 5 #include "components/omnibox/browser/keyword_provider.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 | 125 |
126 template<class ResultType> | 126 template<class ResultType> |
127 void KeywordProviderTest::RunTest(TestData<ResultType>* keyword_cases, | 127 void KeywordProviderTest::RunTest(TestData<ResultType>* keyword_cases, |
128 int num_cases, | 128 int num_cases, |
129 ResultType AutocompleteMatch::* member) { | 129 ResultType AutocompleteMatch::* member) { |
130 ACMatches matches; | 130 ACMatches matches; |
131 for (int i = 0; i < num_cases; ++i) { | 131 for (int i = 0; i < num_cases; ++i) { |
132 SCOPED_TRACE(keyword_cases[i].input); | 132 SCOPED_TRACE(keyword_cases[i].input); |
133 AutocompleteInput input( | 133 AutocompleteInput input( |
134 keyword_cases[i].input, base::string16::npos, std::string(), GURL(), | 134 keyword_cases[i].input, base::string16::npos, std::string(), GURL(), |
135 metrics::OmniboxEventProto::INVALID_SPEC, true, false, true, true, | 135 base::string16(), metrics::OmniboxEventProto::INVALID_SPEC, true, false, |
136 false, TestingSchemeClassifier()); | 136 true, true, false, TestingSchemeClassifier()); |
137 kw_provider_->Start(input, false); | 137 kw_provider_->Start(input, false); |
138 EXPECT_TRUE(kw_provider_->done()); | 138 EXPECT_TRUE(kw_provider_->done()); |
139 matches = kw_provider_->matches(); | 139 matches = kw_provider_->matches(); |
140 ASSERT_EQ(keyword_cases[i].num_results, matches.size()); | 140 ASSERT_EQ(keyword_cases[i].num_results, matches.size()); |
141 for (size_t j = 0; j < matches.size(); ++j) { | 141 for (size_t j = 0; j < matches.size(); ++j) { |
142 EXPECT_EQ(keyword_cases[i].output[j].member, matches[j].*member); | 142 EXPECT_EQ(keyword_cases[i].output[j].member, matches[j].*member); |
143 EXPECT_EQ(keyword_cases[i].output[j].allowed_to_be_default_match, | 143 EXPECT_EQ(keyword_cases[i].output[j].allowed_to_be_default_match, |
144 matches[j].allowed_to_be_default_match); | 144 matches[j].allowed_to_be_default_match); |
145 } | 145 } |
146 } | 146 } |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 { "aa foo", 7u, true, "aa.com?foo={searchTerms}", "foo", 3u }, | 492 { "aa foo", 7u, true, "aa.com?foo={searchTerms}", "foo", 3u }, |
493 // Extra space after keyword, no trailing space, cursor in the middle. | 493 // Extra space after keyword, no trailing space, cursor in the middle. |
494 { "aa foo", 5u, true, "aa.com?foo={searchTerms}", "foo", 1u }, | 494 { "aa foo", 5u, true, "aa.com?foo={searchTerms}", "foo", 1u }, |
495 | 495 |
496 // Disallow exact keyword match. | 496 // Disallow exact keyword match. |
497 { "aa foo", base::string16::npos, false, "", "aa foo", | 497 { "aa foo", base::string16::npos, false, "", "aa foo", |
498 base::string16::npos }, | 498 base::string16::npos }, |
499 }; | 499 }; |
500 SetUpClientAndKeywordProvider(); | 500 SetUpClientAndKeywordProvider(); |
501 for (size_t i = 0; i < arraysize(cases); i++) { | 501 for (size_t i = 0; i < arraysize(cases); i++) { |
502 AutocompleteInput input(ASCIIToUTF16(cases[i].text), | 502 AutocompleteInput input( |
503 cases[i].cursor_position, std::string(), GURL(), | 503 ASCIIToUTF16(cases[i].text), cases[i].cursor_position, std::string(), |
504 metrics::OmniboxEventProto::INVALID_SPEC, false, | 504 GURL(), base::string16(), metrics::OmniboxEventProto::INVALID_SPEC, |
505 false, cases[i].allow_exact_keyword_match, true, | 505 false, false, cases[i].allow_exact_keyword_match, true, false, |
506 false, TestingSchemeClassifier()); | 506 TestingSchemeClassifier()); |
507 const TemplateURL* url = | 507 const TemplateURL* url = |
508 KeywordProvider::GetSubstitutingTemplateURLForInput( | 508 KeywordProvider::GetSubstitutingTemplateURLForInput( |
509 client_->GetTemplateURLService(), &input); | 509 client_->GetTemplateURLService(), &input); |
510 if (cases[i].expected_url.empty()) | 510 if (cases[i].expected_url.empty()) |
511 EXPECT_FALSE(url); | 511 EXPECT_FALSE(url); |
512 else | 512 else |
513 EXPECT_EQ(cases[i].expected_url, url->url()); | 513 EXPECT_EQ(cases[i].expected_url, url->url()); |
514 EXPECT_EQ(ASCIIToUTF16(cases[i].updated_text), input.text()); | 514 EXPECT_EQ(ASCIIToUTF16(cases[i].updated_text), input.text()); |
515 EXPECT_EQ(cases[i].updated_cursor_position, input.cursor_position()); | 515 EXPECT_EQ(cases[i].updated_cursor_position, input.cursor_position()); |
516 } | 516 } |
(...skipping 13 matching lines...) Expand all Loading... |
530 }; | 530 }; |
531 | 531 |
532 SetUpClientAndKeywordProvider(); | 532 SetUpClientAndKeywordProvider(); |
533 RunTest<GURL>(url_cases, arraysize(url_cases), | 533 RunTest<GURL>(url_cases, arraysize(url_cases), |
534 &AutocompleteMatch::destination_url); | 534 &AutocompleteMatch::destination_url); |
535 } | 535 } |
536 | 536 |
537 TEST_F(KeywordProviderTest, DoesNotProvideMatchesOnFocus) { | 537 TEST_F(KeywordProviderTest, DoesNotProvideMatchesOnFocus) { |
538 SetUpClientAndKeywordProvider(); | 538 SetUpClientAndKeywordProvider(); |
539 AutocompleteInput input(ASCIIToUTF16("aaa"), base::string16::npos, | 539 AutocompleteInput input(ASCIIToUTF16("aaa"), base::string16::npos, |
540 std::string(), GURL(), | 540 std::string(), GURL(), base::string16(), |
541 metrics::OmniboxEventProto::INVALID_SPEC, true, false, | 541 metrics::OmniboxEventProto::INVALID_SPEC, true, false, |
542 true, true, true, TestingSchemeClassifier()); | 542 true, true, true, TestingSchemeClassifier()); |
543 kw_provider_->Start(input, false); | 543 kw_provider_->Start(input, false); |
544 ASSERT_TRUE(kw_provider_->matches().empty()); | 544 ASSERT_TRUE(kw_provider_->matches().empty()); |
545 } | 545 } |
OLD | NEW |