| 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 "base/base_paths.h" | 5 #include "base/base_paths.h" |
| 6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
| 7 #include "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "components/metrics/proto/omnibox_event.pb.h" | 10 #include "components/metrics/proto/omnibox_event.pb.h" |
| (...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 635 ASSERT_TRUE(url.url_ref().SupportsReplacement(search_terms_data_)); | 635 ASSERT_TRUE(url.url_ref().SupportsReplacement(search_terms_data_)); |
| 636 TemplateURLRef::SearchTermsArgs search_terms_args(test_data[i].search_term); | 636 TemplateURLRef::SearchTermsArgs search_terms_args(test_data[i].search_term); |
| 637 search_terms_args.current_page_url = test_data[i].current_page_url; | 637 search_terms_args.current_page_url = test_data[i].current_page_url; |
| 638 GURL result(url.url_ref().ReplaceSearchTerms(search_terms_args, | 638 GURL result(url.url_ref().ReplaceSearchTerms(search_terms_args, |
| 639 search_terms_data_)); | 639 search_terms_data_)); |
| 640 ASSERT_TRUE(result.is_valid()); | 640 ASSERT_TRUE(result.is_valid()); |
| 641 EXPECT_EQ(test_data[i].expected_result, result.spec()); | 641 EXPECT_EQ(test_data[i].expected_result, result.spec()); |
| 642 } | 642 } |
| 643 } | 643 } |
| 644 | 644 |
| 645 TEST_F(TemplateURLTest, OmniboxStartmargin) { | |
| 646 struct TestData { | |
| 647 const bool enable_omnibox_start_margin; | |
| 648 const int omnibox_start_margin; | |
| 649 const std::string expected_result; | |
| 650 } test_data[] = { | |
| 651 { false, | |
| 652 0, | |
| 653 "http://bar/foo?q=foobar" }, | |
| 654 { true, | |
| 655 0, | |
| 656 "http://bar/foo?es_sm=0&q=foobar" }, | |
| 657 { true, | |
| 658 42, | |
| 659 "http://bar/foo?es_sm=42&q=foobar" }, | |
| 660 }; | |
| 661 TemplateURLData data; | |
| 662 data.SetURL("http://bar/foo?{google:omniboxStartMarginParameter}" | |
| 663 "q={searchTerms}"); | |
| 664 data.input_encodings.push_back("UTF-8"); | |
| 665 TemplateURL url(data); | |
| 666 EXPECT_TRUE(url.url_ref().IsValid(search_terms_data_)); | |
| 667 ASSERT_TRUE(url.url_ref().SupportsReplacement(search_terms_data_)); | |
| 668 for (size_t i = 0; i < arraysize(test_data); ++i) { | |
| 669 TemplateURLRef::SearchTermsArgs search_terms_args(ASCIIToUTF16("foobar")); | |
| 670 search_terms_args.enable_omnibox_start_margin = | |
| 671 test_data[i].enable_omnibox_start_margin; | |
| 672 search_terms_data_.set_omnibox_start_margin( | |
| 673 test_data[i].omnibox_start_margin); | |
| 674 GURL result(url.url_ref().ReplaceSearchTerms(search_terms_args, | |
| 675 search_terms_data_)); | |
| 676 ASSERT_TRUE(result.is_valid()); | |
| 677 EXPECT_EQ(test_data[i].expected_result, result.spec()); | |
| 678 } | |
| 679 } | |
| 680 | |
| 681 TEST_F(TemplateURLTest, Suggestions) { | 645 TEST_F(TemplateURLTest, Suggestions) { |
| 682 struct TestData { | 646 struct TestData { |
| 683 const int accepted_suggestion; | 647 const int accepted_suggestion; |
| 684 const base::string16 original_query_for_suggestion; | 648 const base::string16 original_query_for_suggestion; |
| 685 const std::string expected_result; | 649 const std::string expected_result; |
| 686 } test_data[] = { | 650 } test_data[] = { |
| 687 { TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, base::string16(), | 651 { TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, base::string16(), |
| 688 "http://bar/foo?q=foobar" }, | 652 "http://bar/foo?q=foobar" }, |
| 689 { TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, ASCIIToUTF16("foo"), | 653 { TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, ASCIIToUTF16("foo"), |
| 690 "http://bar/foo?q=foobar" }, | 654 "http://bar/foo?q=foobar" }, |
| (...skipping 904 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1595 { "http://bar/newtab", false, }, | 1559 { "http://bar/newtab", false, }, |
| 1596 }; | 1560 }; |
| 1597 | 1561 |
| 1598 for (size_t i = 0; i < arraysize(url_data); ++i) { | 1562 for (size_t i = 0; i < arraysize(url_data); ++i) { |
| 1599 EXPECT_EQ(url_data[i].result, | 1563 EXPECT_EQ(url_data[i].result, |
| 1600 search_provider.IsSearchURL(GURL(url_data[i].url), | 1564 search_provider.IsSearchURL(GURL(url_data[i].url), |
| 1601 search_terms_data_)); | 1565 search_terms_data_)); |
| 1602 } | 1566 } |
| 1603 } | 1567 } |
| 1604 | 1568 |
| 1605 TEST_F(TemplateURLTest, ReflectsBookmarkBarPinned) { | |
| 1606 TemplateURLData data; | |
| 1607 data.input_encodings.push_back("UTF-8"); | |
| 1608 data.SetURL("{google:baseURL}?{google:bookmarkBarPinned}q={searchTerms}"); | |
| 1609 TemplateURL url(data); | |
| 1610 EXPECT_TRUE(url.url_ref().IsValid(search_terms_data_)); | |
| 1611 ASSERT_TRUE(url.url_ref().SupportsReplacement(search_terms_data_)); | |
| 1612 TemplateURLRef::SearchTermsArgs search_terms_args(ASCIIToUTF16("foo")); | |
| 1613 | |
| 1614 // Do not add the param when InstantExtended is suppressed on SRPs. | |
| 1615 search_terms_data_.set_is_showing_search_terms_on_search_results_pages(false); | |
| 1616 std::string result = url.url_ref().ReplaceSearchTerms(search_terms_args, | |
| 1617 search_terms_data_); | |
| 1618 EXPECT_EQ("http://www.google.com/?q=foo", result); | |
| 1619 | |
| 1620 // Add the param when InstantExtended is not suppressed on SRPs. | |
| 1621 search_terms_data_.set_is_showing_search_terms_on_search_results_pages(true); | |
| 1622 search_terms_args.bookmark_bar_pinned = false; | |
| 1623 result = url.url_ref().ReplaceSearchTerms(search_terms_args, | |
| 1624 search_terms_data_); | |
| 1625 EXPECT_EQ("http://www.google.com/?bmbp=0&q=foo", result); | |
| 1626 | |
| 1627 search_terms_data_.set_is_showing_search_terms_on_search_results_pages(true); | |
| 1628 search_terms_args.bookmark_bar_pinned = true; | |
| 1629 result = url.url_ref().ReplaceSearchTerms(search_terms_args, | |
| 1630 search_terms_data_); | |
| 1631 EXPECT_EQ("http://www.google.com/?bmbp=1&q=foo", result); | |
| 1632 } | |
| 1633 | |
| 1634 TEST_F(TemplateURLTest, SearchboxVersionIncludedForAnswers) { | 1569 TEST_F(TemplateURLTest, SearchboxVersionIncludedForAnswers) { |
| 1635 TemplateURLData data; | 1570 TemplateURLData data; |
| 1636 search_terms_data_.set_google_base_url("http://bar/"); | 1571 search_terms_data_.set_google_base_url("http://bar/"); |
| 1637 data.SetURL("http://bar/search?q={searchTerms}&{google:searchVersion}xssi=t"); | 1572 data.SetURL("http://bar/search?q={searchTerms}&{google:searchVersion}xssi=t"); |
| 1638 | 1573 |
| 1639 TemplateURL url(data); | 1574 TemplateURL url(data); |
| 1640 TemplateURLRef::SearchTermsArgs search_terms_args(ASCIIToUTF16("foo")); | 1575 TemplateURLRef::SearchTermsArgs search_terms_args(ASCIIToUTF16("foo")); |
| 1641 std::string result = url.url_ref().ReplaceSearchTerms(search_terms_args, | 1576 std::string result = url.url_ref().ReplaceSearchTerms(search_terms_args, |
| 1642 search_terms_data_); | 1577 search_terms_data_); |
| 1643 EXPECT_EQ("http://bar/search?q=foo&gs_rn=42&xssi=t", result); | 1578 EXPECT_EQ("http://bar/search?q=foo&gs_rn=42&xssi=t", result); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1747 EXPECT_EQ("http://bar/search?q=foo&pfq=full%20query%20text&qha=2338&xssi=t", | 1682 EXPECT_EQ("http://bar/search?q=foo&pfq=full%20query%20text&qha=2338&xssi=t", |
| 1748 result); | 1683 result); |
| 1749 | 1684 |
| 1750 TemplateURL url2(data); | 1685 TemplateURL url2(data); |
| 1751 search_terms_args.prefetch_query.clear(); | 1686 search_terms_args.prefetch_query.clear(); |
| 1752 search_terms_args.prefetch_query_type.clear(); | 1687 search_terms_args.prefetch_query_type.clear(); |
| 1753 result = | 1688 result = |
| 1754 url2.url_ref().ReplaceSearchTerms(search_terms_args, search_terms_data_); | 1689 url2.url_ref().ReplaceSearchTerms(search_terms_args, search_terms_data_); |
| 1755 EXPECT_EQ("http://bar/search?q=foo&xssi=t", result); | 1690 EXPECT_EQ("http://bar/search?q=foo&xssi=t", result); |
| 1756 } | 1691 } |
| OLD | NEW |