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

Side by Side Diff: chrome/browser/search_engines/template_url_unittest.cc

Issue 12623029: Upstreaming mechanism to add query refinement to omnibox searches. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed ChromeOS. Created 7 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/string_util.h" 6 #include "base/string_util.h"
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/browser_process.h" 8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/rlz/rlz.h" 9 #include "chrome/browser/rlz/rlz.h"
10 #include "chrome/browser/search_engines/search_terms_data.h" 10 #include "chrome/browser/search_engines/search_terms_data.h"
(...skipping 907 matching lines...) Expand 10 before | Expand all | Expand 10 after
918 EXPECT_TRUE(url.HasSearchTermsReplacementKey( 918 EXPECT_TRUE(url.HasSearchTermsReplacementKey(
919 GURL("http://google.com/?q=something#espv=1"))); 919 GURL("http://google.com/?q=something#espv=1")));
920 920
921 // This does not ensure the domain matches. 921 // This does not ensure the domain matches.
922 EXPECT_TRUE(url.HasSearchTermsReplacementKey( 922 EXPECT_TRUE(url.HasSearchTermsReplacementKey(
923 GURL("http://bing.com/?espv"))); 923 GURL("http://bing.com/?espv")));
924 924
925 EXPECT_TRUE(url.HasSearchTermsReplacementKey( 925 EXPECT_TRUE(url.HasSearchTermsReplacementKey(
926 GURL("http://bing.com/#espv"))); 926 GURL("http://bing.com/#espv")));
927 } 927 }
928
929 TEST_F(TemplateURLTest, ReplaceSearchTermsInURL) {
930 TemplateURLData data;
931 data.SetURL("http://google.com/?q={searchTerms}");
932 data.instant_url = "http://google.com/instant#q={searchTerms}";
933 data.alternate_urls.push_back("http://google.com/alt/#q={searchTerms}");
934 data.alternate_urls.push_back(
935 "http://google.com/alt/?ext=foo&q={searchTerms}#ref=bar");
936 TemplateURL url(NULL, data);
937 TemplateURLRef::SearchTermsArgs search_terms(ASCIIToUTF16("Bob Morane"));
938 GURL result;
939
940 EXPECT_TRUE(url.ReplaceSearchTermsInURL(
941 GURL("http://google.com/?q=something"), search_terms, &result));
942 EXPECT_EQ(GURL("http://google.com/?q=Bob%20Morane"), result);
943
944 result = GURL("http://should.not.change.com");
945 EXPECT_FALSE(url.ReplaceSearchTermsInURL(
946 GURL("http://google.ca/?q=something"), search_terms, &result));
947 EXPECT_EQ(GURL("http://should.not.change.com"), result);
948
949 EXPECT_FALSE(url.ReplaceSearchTermsInURL(
950 GURL("http://google.com/foo/?q=foo"), search_terms, &result));
951
952 EXPECT_TRUE(url.ReplaceSearchTermsInURL(
953 GURL("https://google.com/?q=foo"), search_terms, &result));
954 EXPECT_EQ(GURL("https://google.com/?q=Bob%20Morane"), result);
955
956 EXPECT_FALSE(url.ReplaceSearchTermsInURL(
957 GURL("http://google.com:8080/?q=foo"), search_terms, &result));
958
959 EXPECT_TRUE(url.ReplaceSearchTermsInURL(
960 GURL("http://google.com/?q=1+2+3&b=456"), search_terms, &result));
961 EXPECT_EQ(GURL("http://google.com/?q=Bob%20Morane&b=456"), result);
962
963 // Note: Spaces in REF parameters are not escaped. See TryEncoding() in
964 // template_url.cc for details.
965 EXPECT_TRUE(url.ReplaceSearchTermsInURL(
966 GURL("http://google.com/alt/?q=123#q=456"), search_terms, &result));
967 EXPECT_EQ(GURL("http://google.com/alt/?q=123#q=Bob Morane"), result);
968
969 EXPECT_TRUE(url.ReplaceSearchTermsInURL(
970 GURL("http://google.com/alt/?a=012&q=123&b=456#f=789"), search_terms,
971 &result));
972 EXPECT_EQ(GURL("http://google.com/alt/?a=012&q=Bob%20Morane&b=456#f=789"),
973 result);
974
975 EXPECT_TRUE(url.ReplaceSearchTermsInURL(
976 GURL("http://google.com/alt/?a=012&q=123&b=456#j=abc&q=789&h=def9"),
977 search_terms, &result));
978 EXPECT_EQ(GURL("http://google.com/alt/?a=012&q=123&b=456"
979 "#j=abc&q=Bob Morane&h=def9"), result);
980
981 EXPECT_FALSE(url.ReplaceSearchTermsInURL(
982 GURL("http://google.com/alt/?q="), search_terms, &result));
983
984 EXPECT_FALSE(url.ReplaceSearchTermsInURL(
985 GURL("http://google.com/alt/?#q="), search_terms, &result));
986
987 EXPECT_FALSE(url.ReplaceSearchTermsInURL(
988 GURL("http://google.com/alt/?q=#q="), search_terms, &result));
989
990 EXPECT_FALSE(url.ReplaceSearchTermsInURL(
991 GURL("http://google.com/alt/?q=123#q="), search_terms, &result));
992
993 EXPECT_TRUE(url.ReplaceSearchTermsInURL(
994 GURL("http://google.com/alt/?q=#q=123"), search_terms, &result));
995 EXPECT_EQ(GURL("http://google.com/alt/?q=#q=Bob Morane"), result);
996 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698