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

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

Issue 2877983002: Use search_term_value_prefix_ & search_term_value_suffix_ to specify the location of {searchTerms} … (Closed)
Patch Set: Fix unit-test Created 3 years, 7 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
« no previous file with comments | « components/search_engines/template_url.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/i18n/case_conversion.h" 9 #include "base/i18n/case_conversion.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 760 matching lines...) Expand 10 before | Expand all | Expand 10 after
771 result.spec()); 771 result.spec());
772 } 772 }
773 773
774 TEST_F(TemplateURLTest, HostAndSearchTermKey) { 774 TEST_F(TemplateURLTest, HostAndSearchTermKey) {
775 struct TestData { 775 struct TestData {
776 const std::string url; 776 const std::string url;
777 const std::string host; 777 const std::string host;
778 const std::string path; 778 const std::string path;
779 const std::string search_term_key; 779 const std::string search_term_key;
780 } test_data[] = { 780 } test_data[] = {
781 { "http://blah/?foo=bar&q={searchTerms}&b=x", "blah", "/", "q"}, 781 {"http://blah/?foo=bar&q={searchTerms}&b=x", "blah", "/", "q"},
782 { "http://blah/{searchTerms}", "blah", "/", ""}, 782 {"http://blah/{searchTerms}", "blah", "", ""},
783 783
784 // No term should result in empty values. 784 // No term should result in empty values.
785 { "http://blah/", "", "", ""}, 785 {"http://blah/", "", "", ""},
786 786
787 // Multiple terms should result in empty values. 787 // Multiple terms should result in empty values.
788 { "http://blah/?q={searchTerms}&x={searchTerms}", "", "", ""}, 788 {"http://blah/?q={searchTerms}&x={searchTerms}", "", "", ""},
789 789
790 // Term in the host shouldn't match. 790 // Term in the host shouldn't match.
791 { "http://{searchTerms}", "", "", ""}, 791 {"http://{searchTerms}", "", "", ""},
792 792
793 { "http://blah/?q={searchTerms}", "blah", "/", "q"}, 793 {"http://blah/?q={searchTerms}", "blah", "/", "q"},
794 { "https://blah/?q={searchTerms}", "blah", "/", "q"}, 794 {"https://blah/?q={searchTerms}", "blah", "/", "q"},
795 795
796 // Single term with extra chars in value should match. 796 // Single term with extra chars in value should match.
797 { "http://blah/?q=stock:{searchTerms}", "blah", "/", "q"}, 797 {"http://blah/?q=stock:{searchTerms}", "blah", "/", "q"},
798 }; 798 };
799 799
800 for (size_t i = 0; i < arraysize(test_data); ++i) { 800 for (size_t i = 0; i < arraysize(test_data); ++i) {
801 TemplateURLData data; 801 TemplateURLData data;
802 data.SetURL(test_data[i].url); 802 data.SetURL(test_data[i].url);
803 TemplateURL url(data); 803 TemplateURL url(data);
804 EXPECT_EQ(test_data[i].host, url.url_ref().GetHost(search_terms_data_)); 804 EXPECT_EQ(test_data[i].host, url.url_ref().GetHost(search_terms_data_));
805 EXPECT_EQ(test_data[i].path, url.url_ref().GetPath(search_terms_data_)); 805 EXPECT_EQ(test_data[i].path, url.url_ref().GetPath(search_terms_data_));
806 EXPECT_EQ(test_data[i].search_term_key, 806 EXPECT_EQ(test_data[i].search_term_key,
807 url.url_ref().GetSearchTermKey(search_terms_data_)); 807 url.url_ref().GetSearchTermKey(search_terms_data_));
808 } 808 }
809 } 809 }
810 810
811 TEST_F(TemplateURLTest, SearchTermKeyLocation) { 811 TEST_F(TemplateURLTest, SearchTermKeyLocation) {
812 struct TestData { 812 struct TestData {
813 const std::string url; 813 const std::string url;
814 const url::Parsed::ComponentType location; 814 const url::Parsed::ComponentType location;
815 const std::string path; 815 const std::string path;
816 size_t position_in_path; 816 const std::string key;
817 const std::string value_prefix;
818 const std::string value_suffix;
817 } test_data[] = { 819 } test_data[] = {
818 { "http://blah/{searchTerms}/", url::Parsed::PATH, "//", 1 }, 820 {"http://blah/{searchTerms}/", url::Parsed::PATH, "", "", "/", "/"},
819 { "http://blah/{searchTerms}", url::Parsed::PATH, "/", 1 }, 821 {"http://blah/{searchTerms}", url::Parsed::PATH, "", "", "/", ""},
820 { "http://blah/begin/{searchTerms}/end", url::Parsed::PATH, "/begin//end", 7 }, 822 {"http://blah/begin/{searchTerms}/end", url::Parsed::PATH, "", "",
823 "/begin/", "/end"},
824 {"http://blah/?foo=bar&q={searchTerms}&b=x", url::Parsed::QUERY, "/", "q",
825 "", ""},
826 {"http://blah/?foo=bar#x={searchTerms}&b=x", url::Parsed::REF, "/", "x",
827 "", ""},
828 {"http://www.example.com/?q=chromium-{searchTerms}@chromium.org/info",
829 url::Parsed::QUERY, "/", "q", "chromium-", "@chromium.org/info"},
821 830
822 { "http://blah/?foo=bar&q={searchTerms}&b=x", url::Parsed::QUERY, 831 // searchTerms is a key, not a value, so this should result in an empty
823 "/", std::string::npos }, 832 // value.
824 { "http://blah/?foo=bar#x={searchTerms}&b=x", url::Parsed::REF, 833 {"http://blah/?foo=bar#x=012345678901234&a=b&{searchTerms}=x",
825 "/", std::string::npos }, 834 url::Parsed::QUERY, "", "", "", ""},
826 // searchTerms is a key, not a value, so this should result in an empty
827 // value.
828 { "http://blah/?foo=bar#x=012345678901234&a=b&{searchTerms}=x",
829 url::Parsed::QUERY, std::string(), std::string::npos },
830 835
831 // Multiple search terms should result in empty values. 836 // Multiple search terms should result in empty values.
832 { "http://blah/{searchTerms}?q={searchTerms}", url::Parsed::QUERY, 837 {"http://blah/{searchTerms}?q={searchTerms}", url::Parsed::QUERY, "", "",
833 "", std::string::npos }, 838 "", ""},
834 { "http://blah/{searchTerms}#x={searchTerms}", url::Parsed::QUERY, 839 {"http://blah/{searchTerms}#x={searchTerms}", url::Parsed::QUERY, "", "",
835 "", std::string::npos }, 840 "", ""},
836 { "http://blah/?q={searchTerms}#x={searchTerms}", url::Parsed::QUERY, 841 {"http://blah/?q={searchTerms}#x={searchTerms}", url::Parsed::QUERY, "",
837 "", std::string::npos }, 842 "", "", ""},
838 }; 843 };
839 844
840 for (size_t i = 0; i < arraysize(test_data); ++i) { 845 for (size_t i = 0; i < arraysize(test_data); ++i) {
841 TemplateURLData data; 846 TemplateURLData data;
842 data.SetURL(test_data[i].url); 847 data.SetURL(test_data[i].url);
843 TemplateURL url(data); 848 TemplateURL url(data);
844 EXPECT_EQ(test_data[i].location, 849 EXPECT_EQ(test_data[i].location,
845 url.url_ref().GetSearchTermKeyLocation(search_terms_data_)); 850 url.url_ref().GetSearchTermKeyLocation(search_terms_data_));
846 EXPECT_EQ(test_data[i].path, 851 EXPECT_EQ(test_data[i].path,
847 url.url_ref().GetPath(search_terms_data_)); 852 url.url_ref().GetPath(search_terms_data_));
848 EXPECT_EQ(test_data[i].position_in_path, 853 EXPECT_EQ(test_data[i].key,
849 url.url_ref().GetSearchTermPositionInPath(search_terms_data_)); 854 url.url_ref().GetSearchTermKey(search_terms_data_));
855 EXPECT_EQ(test_data[i].value_prefix,
856 url.url_ref().GetSearchTermValuePrefix(search_terms_data_));
857 EXPECT_EQ(test_data[i].value_suffix,
858 url.url_ref().GetSearchTermValueSuffix(search_terms_data_));
850 } 859 }
851 } 860 }
852 861
853 TEST_F(TemplateURLTest, GoogleBaseSuggestURL) { 862 TEST_F(TemplateURLTest, GoogleBaseSuggestURL) {
854 static const struct { 863 static const struct {
855 const char* const base_url; 864 const char* const base_url;
856 const char* const base_suggest_url; 865 const char* const base_suggest_url;
857 } data[] = { 866 } data[] = {
858 { "http://google.com/", "http://google.com/complete/", }, 867 { "http://google.com/", "http://google.com/complete/", },
859 { "http://www.google.com/", "http://www.google.com/complete/", }, 868 { "http://www.google.com/", "http://www.google.com/complete/", },
(...skipping 1065 matching lines...) Expand 10 before | Expand all | Expand 10 after
1925 EXPECT_EQ(google_util::kInstantExtendedAPIParam, 1934 EXPECT_EQ(google_util::kInstantExtendedAPIParam,
1926 turl.search_terms_replacement_key()); 1935 turl.search_terms_replacement_key());
1927 // Expect that replacement of {google:instantExtendedEnabledKey} in search url 1936 // Expect that replacement of {google:instantExtendedEnabledKey} in search url
1928 // is correct. 1937 // is correct.
1929 GURL search_generated = turl.GenerateSearchURL(search_terms_data_); 1938 GURL search_generated = turl.GenerateSearchURL(search_terms_data_);
1930 EXPECT_TRUE(turl.HasSearchTermsReplacementKey(search_generated)); 1939 EXPECT_TRUE(turl.HasSearchTermsReplacementKey(search_generated));
1931 net::QueryIterator it(search_generated); 1940 net::QueryIterator it(search_generated);
1932 ASSERT_FALSE(it.IsAtEnd()); 1941 ASSERT_FALSE(it.IsAtEnd());
1933 EXPECT_EQ(google_util::kInstantExtendedAPIParam, it.GetKey()); 1942 EXPECT_EQ(google_util::kInstantExtendedAPIParam, it.GetKey());
1934 } 1943 }
OLDNEW
« no previous file with comments | « components/search_engines/template_url.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698