Chromium Code Reviews| 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 <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 1174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1185 result); | 1185 result); |
| 1186 | 1186 |
| 1187 EXPECT_TRUE(url.ExtractSearchTermsFromURL( | 1187 EXPECT_TRUE(url.ExtractSearchTermsFromURL( |
| 1188 GURL("http://windows-1251.ru/path/%E1%F3%EA%E2%FB%20%C0%20%E8%20A"), | 1188 GURL("http://windows-1251.ru/path/%E1%F3%EA%E2%FB%20%C0%20%E8%20A"), |
| 1189 search_terms_data_, &result)); | 1189 search_terms_data_, &result)); |
| 1190 EXPECT_EQ( | 1190 EXPECT_EQ( |
| 1191 base::WideToUTF16(L"\x0431\x0443\x043A\x0432\x044B \x0410 \x0438 A"), | 1191 base::WideToUTF16(L"\x0431\x0443\x043A\x0432\x044B \x0410 \x0438 A"), |
| 1192 result); | 1192 result); |
| 1193 } | 1193 } |
| 1194 | 1194 |
| 1195 // Checks that the ExtractSearchTermsFromURL function strips constant | |
| 1196 // prefix/suffix strings from the search terms param. | |
| 1197 TEST_F(TemplateURLTest, ExtractSearchTermsWithPrefixAndSuffix) { | |
| 1198 TemplateURLData data; | |
| 1199 data.alternate_urls.push_back("http://www.example.com/?q=chromium-{searchTerms }@chromium.org"); | |
| 1200 data.alternate_urls.push_back("http://www.example.com/chromium-{searchTerms}@c hromium.org/info"); | |
| 1201 TemplateURL url(data); | |
| 1202 base::string16 result; | |
| 1203 | |
| 1204 EXPECT_TRUE(url.ExtractSearchTermsFromURL( | |
| 1205 GURL("http://www.example.com/?q=chromium-dev@chromium.org"), | |
| 1206 search_terms_data_, &result)); | |
| 1207 EXPECT_EQ(ASCIIToUTF16("dev"), result); | |
| 1208 | |
| 1209 EXPECT_TRUE(url.ExtractSearchTermsFromURL( | |
| 1210 GURL("http://www.example.com/chromium-dev@chromium.org/info"), | |
| 1211 search_terms_data_, &result)); | |
| 1212 EXPECT_EQ(ASCIIToUTF16("dev"), result); | |
| 1213 | |
| 1214 // To be safe, still succeed if they're missing. This is no worse than the | |
| 1215 // previous behavior. | |
| 1216 EXPECT_TRUE(url.ExtractSearchTermsFromURL( | |
| 1217 GURL("http://www.example.com/?q=invalid"), search_terms_data_, &result)); | |
| 1218 EXPECT_EQ(ASCIIToUTF16("invalid"), result); | |
|
Peter Kasting
2016/04/21 19:48:57
Hmm. I don't think we should allow "foo.com/?q=xy
jbroman
2016/04/21 21:01:42
My reasoning was that they were accepted before th
| |
| 1219 } | |
| 1220 | |
| 1195 TEST_F(TemplateURLTest, HasSearchTermsReplacementKey) { | 1221 TEST_F(TemplateURLTest, HasSearchTermsReplacementKey) { |
| 1196 TemplateURLData data; | 1222 TemplateURLData data; |
| 1197 data.SetURL("http://google.com/?q={searchTerms}"); | 1223 data.SetURL("http://google.com/?q={searchTerms}"); |
| 1198 data.instant_url = "http://google.com/instant#q={searchTerms}"; | 1224 data.instant_url = "http://google.com/instant#q={searchTerms}"; |
| 1199 data.alternate_urls.push_back("http://google.com/alt/#q={searchTerms}"); | 1225 data.alternate_urls.push_back("http://google.com/alt/#q={searchTerms}"); |
| 1200 data.alternate_urls.push_back( | 1226 data.alternate_urls.push_back( |
| 1201 "http://google.com/alt/?ext=foo&q={searchTerms}#ref=bar"); | 1227 "http://google.com/alt/?ext=foo&q={searchTerms}#ref=bar"); |
| 1202 data.search_terms_replacement_key = "espv"; | 1228 data.search_terms_replacement_key = "espv"; |
| 1203 TemplateURL url(data); | 1229 TemplateURL url(data); |
| 1204 | 1230 |
| (...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1778 GURL("https://www.foo.org/search?q=Y+Z"), | 1804 GURL("https://www.foo.org/search?q=Y+Z"), |
| 1779 search_terms_data_, &search_terms)); | 1805 search_terms_data_, &search_terms)); |
| 1780 EXPECT_EQ(base::ASCIIToUTF16("Y Z"), search_terms); | 1806 EXPECT_EQ(base::ASCIIToUTF16("Y Z"), search_terms); |
| 1781 EXPECT_TRUE(url.ExtractSearchTermsFromURL( | 1807 EXPECT_TRUE(url.ExtractSearchTermsFromURL( |
| 1782 GURL("https://www.foo.org/s#q=123"), | 1808 GURL("https://www.foo.org/s#q=123"), |
| 1783 search_terms_data_, &search_terms)); | 1809 search_terms_data_, &search_terms)); |
| 1784 EXPECT_EQ(base::ASCIIToUTF16("123"), search_terms); | 1810 EXPECT_EQ(base::ASCIIToUTF16("123"), search_terms); |
| 1785 | 1811 |
| 1786 search_terms_data_.set_google_base_url("http://www.google.com/"); | 1812 search_terms_data_.set_google_base_url("http://www.google.com/"); |
| 1787 } | 1813 } |
| OLD | NEW |