Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(90)

Side by Side Diff: components/search_engines/template_url_unittest.cc

Issue 1543203002: Remove a variety of no-longer-used query params. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review comments Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include "base/base_paths.h" 7 #include "base/base_paths.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 ASSERT_TRUE(url.url_ref().SupportsReplacement(search_terms_data_)); 638 ASSERT_TRUE(url.url_ref().SupportsReplacement(search_terms_data_));
639 TemplateURLRef::SearchTermsArgs search_terms_args(test_data[i].search_term); 639 TemplateURLRef::SearchTermsArgs search_terms_args(test_data[i].search_term);
640 search_terms_args.current_page_url = test_data[i].current_page_url; 640 search_terms_args.current_page_url = test_data[i].current_page_url;
641 GURL result(url.url_ref().ReplaceSearchTerms(search_terms_args, 641 GURL result(url.url_ref().ReplaceSearchTerms(search_terms_args,
642 search_terms_data_)); 642 search_terms_data_));
643 ASSERT_TRUE(result.is_valid()); 643 ASSERT_TRUE(result.is_valid());
644 EXPECT_EQ(test_data[i].expected_result, result.spec()); 644 EXPECT_EQ(test_data[i].expected_result, result.spec());
645 } 645 }
646 } 646 }
647 647
648 TEST_F(TemplateURLTest, OmniboxStartmargin) {
649 struct TestData {
650 const bool enable_omnibox_start_margin;
651 const int omnibox_start_margin;
652 const std::string expected_result;
653 } test_data[] = {
654 { false,
655 0,
656 "http://bar/foo?q=foobar" },
657 { true,
658 0,
659 "http://bar/foo?es_sm=0&q=foobar" },
660 { true,
661 42,
662 "http://bar/foo?es_sm=42&q=foobar" },
663 };
664 TemplateURLData data;
665 data.SetURL("http://bar/foo?{google:omniboxStartMarginParameter}"
666 "q={searchTerms}");
667 data.input_encodings.push_back("UTF-8");
668 TemplateURL url(data);
669 EXPECT_TRUE(url.url_ref().IsValid(search_terms_data_));
670 ASSERT_TRUE(url.url_ref().SupportsReplacement(search_terms_data_));
671 for (size_t i = 0; i < arraysize(test_data); ++i) {
672 TemplateURLRef::SearchTermsArgs search_terms_args(ASCIIToUTF16("foobar"));
673 search_terms_args.enable_omnibox_start_margin =
674 test_data[i].enable_omnibox_start_margin;
675 search_terms_data_.set_omnibox_start_margin(
676 test_data[i].omnibox_start_margin);
677 GURL result(url.url_ref().ReplaceSearchTerms(search_terms_args,
678 search_terms_data_));
679 ASSERT_TRUE(result.is_valid());
680 EXPECT_EQ(test_data[i].expected_result, result.spec());
681 }
682 }
683
684 TEST_F(TemplateURLTest, Suggestions) { 648 TEST_F(TemplateURLTest, Suggestions) {
685 struct TestData { 649 struct TestData {
686 const int accepted_suggestion; 650 const int accepted_suggestion;
687 const base::string16 original_query_for_suggestion; 651 const base::string16 original_query_for_suggestion;
688 const std::string expected_result; 652 const std::string expected_result;
689 } test_data[] = { 653 } test_data[] = {
690 { TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, base::string16(), 654 { TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, base::string16(),
691 "http://bar/foo?q=foobar" }, 655 "http://bar/foo?q=foobar" },
692 { TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, ASCIIToUTF16("foo"), 656 { TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, ASCIIToUTF16("foo"),
693 "http://bar/foo?q=foobar" }, 657 "http://bar/foo?q=foobar" },
(...skipping 904 matching lines...) Expand 10 before | Expand all | Expand 10 after
1598 { "http://bar/newtab", false, }, 1562 { "http://bar/newtab", false, },
1599 }; 1563 };
1600 1564
1601 for (size_t i = 0; i < arraysize(url_data); ++i) { 1565 for (size_t i = 0; i < arraysize(url_data); ++i) {
1602 EXPECT_EQ(url_data[i].result, 1566 EXPECT_EQ(url_data[i].result,
1603 search_provider.IsSearchURL(GURL(url_data[i].url), 1567 search_provider.IsSearchURL(GURL(url_data[i].url),
1604 search_terms_data_)); 1568 search_terms_data_));
1605 } 1569 }
1606 } 1570 }
1607 1571
1608 TEST_F(TemplateURLTest, ReflectsBookmarkBarPinned) {
1609 TemplateURLData data;
1610 data.input_encodings.push_back("UTF-8");
1611 data.SetURL("{google:baseURL}?{google:bookmarkBarPinned}q={searchTerms}");
1612 TemplateURL url(data);
1613 EXPECT_TRUE(url.url_ref().IsValid(search_terms_data_));
1614 ASSERT_TRUE(url.url_ref().SupportsReplacement(search_terms_data_));
1615 TemplateURLRef::SearchTermsArgs search_terms_args(ASCIIToUTF16("foo"));
1616
1617 // Do not add the param when InstantExtended is suppressed on SRPs.
1618 search_terms_data_.set_is_showing_search_terms_on_search_results_pages(false);
1619 std::string result = url.url_ref().ReplaceSearchTerms(search_terms_args,
1620 search_terms_data_);
1621 EXPECT_EQ("http://www.google.com/?q=foo", result);
1622
1623 // Add the param when InstantExtended is not suppressed on SRPs.
1624 search_terms_data_.set_is_showing_search_terms_on_search_results_pages(true);
1625 search_terms_args.bookmark_bar_pinned = false;
1626 result = url.url_ref().ReplaceSearchTerms(search_terms_args,
1627 search_terms_data_);
1628 EXPECT_EQ("http://www.google.com/?bmbp=0&q=foo", result);
1629
1630 search_terms_data_.set_is_showing_search_terms_on_search_results_pages(true);
1631 search_terms_args.bookmark_bar_pinned = true;
1632 result = url.url_ref().ReplaceSearchTerms(search_terms_args,
1633 search_terms_data_);
1634 EXPECT_EQ("http://www.google.com/?bmbp=1&q=foo", result);
1635 }
1636
1637 TEST_F(TemplateURLTest, SearchboxVersionIncludedForAnswers) { 1572 TEST_F(TemplateURLTest, SearchboxVersionIncludedForAnswers) {
1638 TemplateURLData data; 1573 TemplateURLData data;
1639 search_terms_data_.set_google_base_url("http://bar/"); 1574 search_terms_data_.set_google_base_url("http://bar/");
1640 data.SetURL("http://bar/search?q={searchTerms}&{google:searchVersion}xssi=t"); 1575 data.SetURL("http://bar/search?q={searchTerms}&{google:searchVersion}xssi=t");
1641 1576
1642 TemplateURL url(data); 1577 TemplateURL url(data);
1643 TemplateURLRef::SearchTermsArgs search_terms_args(ASCIIToUTF16("foo")); 1578 TemplateURLRef::SearchTermsArgs search_terms_args(ASCIIToUTF16("foo"));
1644 std::string result = url.url_ref().ReplaceSearchTerms(search_terms_args, 1579 std::string result = url.url_ref().ReplaceSearchTerms(search_terms_args,
1645 search_terms_data_); 1580 search_terms_data_);
1646 EXPECT_EQ("http://bar/search?q=foo&gs_rn=42&xssi=t", result); 1581 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
1750 EXPECT_EQ("http://bar/search?q=foo&pfq=full%20query%20text&qha=2338&xssi=t", 1685 EXPECT_EQ("http://bar/search?q=foo&pfq=full%20query%20text&qha=2338&xssi=t",
1751 result); 1686 result);
1752 1687
1753 TemplateURL url2(data); 1688 TemplateURL url2(data);
1754 search_terms_args.prefetch_query.clear(); 1689 search_terms_args.prefetch_query.clear();
1755 search_terms_args.prefetch_query_type.clear(); 1690 search_terms_args.prefetch_query_type.clear();
1756 result = 1691 result =
1757 url2.url_ref().ReplaceSearchTerms(search_terms_args, search_terms_data_); 1692 url2.url_ref().ReplaceSearchTerms(search_terms_args, search_terms_data_);
1758 EXPECT_EQ("http://bar/search?q=foo&xssi=t", result); 1693 EXPECT_EQ("http://bar/search?q=foo&xssi=t", result);
1759 } 1694 }
OLDNEW
« no previous file with comments | « components/search_engines/template_url.cc ('k') | components/search_engines/testing_search_terms_data.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698