| 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 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 }; | 369 }; |
| 370 | 370 |
| 371 SetUpClientAndKeywordProvider(); | 371 SetUpClientAndKeywordProvider(); |
| 372 RunTest<GURL>(url_cases, arraysize(url_cases), | 372 RunTest<GURL>(url_cases, arraysize(url_cases), |
| 373 &AutocompleteMatch::destination_url); | 373 &AutocompleteMatch::destination_url); |
| 374 } | 374 } |
| 375 | 375 |
| 376 TEST_F(KeywordProviderTest, Contents) { | 376 TEST_F(KeywordProviderTest, Contents) { |
| 377 const MatchType<base::string16> kEmptyMatch = { base::string16(), false }; | 377 const MatchType<base::string16> kEmptyMatch = { base::string16(), false }; |
| 378 TestData<base::string16> contents_cases[] = { | 378 TestData<base::string16> contents_cases[] = { |
| 379 // No query input -> substitute "<enter query>" into contents. | 379 // No query input -> substitute "<Type search term>" into contents. |
| 380 { ASCIIToUTF16("z"), 1, | 380 { ASCIIToUTF16("z"), 1, |
| 381 { { ASCIIToUTF16("Search z for <enter query>"), true }, | 381 { { ASCIIToUTF16("<Type search term>"), true }, |
| 382 kEmptyMatch, kEmptyMatch } }, | 382 kEmptyMatch, kEmptyMatch } }, |
| 383 { ASCIIToUTF16("z \t"), 1, | 383 { ASCIIToUTF16("z \t"), 1, |
| 384 { { ASCIIToUTF16("Search z for <enter query>"), true }, | 384 { { ASCIIToUTF16("<Type search term>"), true }, |
| 385 kEmptyMatch, kEmptyMatch } }, | 385 kEmptyMatch, kEmptyMatch } }, |
| 386 | 386 |
| 387 // Exact keyword matches with remaining text should return nothing. | 387 // Exact keyword matches with remaining text should return nothing. |
| 388 { ASCIIToUTF16("www.www www"), 0, | 388 { ASCIIToUTF16("www.www www"), 0, |
| 389 { kEmptyMatch, kEmptyMatch, kEmptyMatch } }, | 389 { kEmptyMatch, kEmptyMatch, kEmptyMatch } }, |
| 390 { ASCIIToUTF16("z a b c++"), 0, | 390 { ASCIIToUTF16("z a b c++"), 0, |
| 391 { kEmptyMatch, kEmptyMatch, kEmptyMatch } }, | 391 { kEmptyMatch, kEmptyMatch, kEmptyMatch } }, |
| 392 | 392 |
| 393 // Exact keyword matches with remaining text when the keyword is an | 393 // Exact keyword matches with remaining text when the keyword is an |
| 394 // extension keyword should return something. This is tested in | 394 // extension keyword should return something. This is tested in |
| 395 // chrome/browser/extensions/api/omnibox/omnibox_apitest.cc's | 395 // chrome/browser/extensions/api/omnibox/omnibox_apitest.cc's |
| 396 // in OmniboxApiTest's Basic test. | 396 // in OmniboxApiTest's Basic test. |
| 397 | 397 |
| 398 // Substitution should work with various locations of the "%s". | 398 // There are two keywords that start with "aaa". Suggestions will be |
| 399 // disambiguated by the description. We do not test the description value |
| 400 // here because KeywordProvider doesn't set descriptions; these are |
| 401 // populated later by AutocompleteController. |
| 399 { ASCIIToUTF16("aaa"), 2, | 402 { ASCIIToUTF16("aaa"), 2, |
| 400 { { ASCIIToUTF16("Search aaaa for <enter query>"), false }, | 403 { { ASCIIToUTF16("<Type search term>"), false }, |
| 401 { ASCIIToUTF16("Search aaaaa for <enter query>"), false }, | 404 { ASCIIToUTF16("<Type search term>"), false }, |
| 402 kEmptyMatch} }, | 405 kEmptyMatch} }, |
| 406 // When there is a search string, simply display it. |
| 403 { ASCIIToUTF16("www.w w"), 2, | 407 { ASCIIToUTF16("www.w w"), 2, |
| 404 { { ASCIIToUTF16("Search www for w"), false }, | 408 { { ASCIIToUTF16("w"), false }, |
| 405 { ASCIIToUTF16("Search weasel for w"), false }, | 409 { ASCIIToUTF16("w"), false }, |
| 406 kEmptyMatch } }, | 410 kEmptyMatch } }, |
| 407 // Also, check that tokenization only collapses whitespace between first | 411 // Also, check that tokenization only collapses whitespace between first |
| 408 // tokens and contents are not escaped or unescaped. | 412 // tokens and contents are not escaped or unescaped. |
| 409 { ASCIIToUTF16("a 1 2+ 3"), 3, | 413 { ASCIIToUTF16("a 1 2+ 3"), 3, |
| 410 { { ASCIIToUTF16("Search aa for 1 2+ 3"), false }, | 414 { { ASCIIToUTF16("1 2+ 3"), false }, |
| 411 { ASCIIToUTF16("Search ab for 1 2+ 3"), false }, | 415 { ASCIIToUTF16("1 2+ 3"), false }, |
| 412 { ASCIIToUTF16("Search aaaa for 1 2+ 3"), false } } }, | 416 { ASCIIToUTF16("1 2+ 3"), false } } }, |
| 413 }; | 417 }; |
| 414 | 418 |
| 415 SetUpClientAndKeywordProvider(); | 419 SetUpClientAndKeywordProvider(); |
| 416 RunTest<base::string16>(contents_cases, arraysize(contents_cases), | 420 RunTest<base::string16>(contents_cases, arraysize(contents_cases), |
| 417 &AutocompleteMatch::contents); | 421 &AutocompleteMatch::contents); |
| 418 } | 422 } |
| 419 | 423 |
| 420 TEST_F(KeywordProviderTest, AddKeyword) { | 424 TEST_F(KeywordProviderTest, AddKeyword) { |
| 421 SetUpClientAndKeywordProvider(); | 425 SetUpClientAndKeywordProvider(); |
| 422 TemplateURLData data; | 426 TemplateURLData data; |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 | 535 |
| 532 TEST_F(KeywordProviderTest, DoesNotProvideMatchesOnFocus) { | 536 TEST_F(KeywordProviderTest, DoesNotProvideMatchesOnFocus) { |
| 533 SetUpClientAndKeywordProvider(); | 537 SetUpClientAndKeywordProvider(); |
| 534 AutocompleteInput input(ASCIIToUTF16("aaa"), base::string16::npos, | 538 AutocompleteInput input(ASCIIToUTF16("aaa"), base::string16::npos, |
| 535 std::string(), GURL(), | 539 std::string(), GURL(), |
| 536 metrics::OmniboxEventProto::INVALID_SPEC, true, false, | 540 metrics::OmniboxEventProto::INVALID_SPEC, true, false, |
| 537 true, true, true, TestingSchemeClassifier()); | 541 true, true, true, TestingSchemeClassifier()); |
| 538 kw_provider_->Start(input, false); | 542 kw_provider_->Start(input, false); |
| 539 ASSERT_TRUE(kw_provider_->matches().empty()); | 543 ASSERT_TRUE(kw_provider_->matches().empty()); |
| 540 } | 544 } |
| OLD | NEW |