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

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

Issue 939713003: Enabled the "search web for image" context menu item when "Yandex" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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 "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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 TemplateURLData data; 151 TemplateURLData data;
152 data.image_url = KImageSearchURL; 152 data.image_url = KImageSearchURL;
153 153
154 // Try to parse invalid post parameters. 154 // Try to parse invalid post parameters.
155 data.image_url_post_params = kInvalidPostParamsString; 155 data.image_url_post_params = kInvalidPostParamsString;
156 TemplateURL url_bad(data); 156 TemplateURL url_bad(data);
157 ASSERT_FALSE(url_bad.image_url_ref().IsValid(search_terms_data_)); 157 ASSERT_FALSE(url_bad.image_url_ref().IsValid(search_terms_data_));
158 const TemplateURLRef::PostParams& bad_post_params = 158 const TemplateURLRef::PostParams& bad_post_params =
159 url_bad.image_url_ref().post_params_; 159 url_bad.image_url_ref().post_params_;
160 ASSERT_EQ(2U, bad_post_params.size()); 160 ASSERT_EQ(2U, bad_post_params.size());
161 EXPECT_EQ("unknown_template", bad_post_params[0].first); 161 EXPECT_EQ("unknown_template", bad_post_params[0].value_name);
Peter Kasting 2015/02/18 21:55:52 Nit: Many of these place you're touching might get
Vitaly Baranov 2015/02/19 17:31:20 Done.
162 EXPECT_EQ("{UnknownTemplate}", bad_post_params[0].second); 162 EXPECT_EQ("{UnknownTemplate}", bad_post_params[0].value);
163 EXPECT_EQ("bad_value", bad_post_params[1].first); 163 EXPECT_TRUE(bad_post_params[0].content_type.empty());
164 EXPECT_EQ("bad{value}", bad_post_params[1].second); 164 EXPECT_EQ("bad_value", bad_post_params[1].value_name);
165 EXPECT_EQ("bad{value}", bad_post_params[1].value);
166 EXPECT_TRUE(bad_post_params[1].content_type.empty());
165 167
166 // Try to parse valid post parameters. 168 // Try to parse valid post parameters.
167 data.image_url_post_params = kValidPostParamsString; 169 data.image_url_post_params = kValidPostParamsString;
168 TemplateURL url(data); 170 TemplateURL url(data);
169 ASSERT_TRUE(url.image_url_ref().IsValid(search_terms_data_)); 171 ASSERT_TRUE(url.image_url_ref().IsValid(search_terms_data_));
170 ASSERT_FALSE(url.image_url_ref().SupportsReplacement(search_terms_data_)); 172 ASSERT_FALSE(url.image_url_ref().SupportsReplacement(search_terms_data_));
171 173
172 // Check term replacement. 174 // Check term replacement.
173 TemplateURLRef::SearchTermsArgs search_args(ASCIIToUTF16("X")); 175 TemplateURLRef::SearchTermsArgs search_args(ASCIIToUTF16("X"));
174 search_args.image_thumbnail_content = "dummy-image-thumbnail"; 176 search_args.image_thumbnail_content = "dummy-image-thumbnail";
177 search_args.image_thumbnail_format = "jpeg";
175 search_args.image_url = GURL("http://dummyimage.com/dummy.jpg"); 178 search_args.image_url = GURL("http://dummyimage.com/dummy.jpg");
176 search_args.image_original_size = gfx::Size(10, 10); 179 search_args.image_original_size = gfx::Size(10, 10);
177 // Replacement operation with no post_data buffer should still return 180 // Replacement operation with no post_data buffer should still return
178 // the parsed URL. 181 // the parsed URL.
179 TestingSearchTermsData search_terms_data("http://X"); 182 TestingSearchTermsData search_terms_data("http://X");
180 GURL result(url.image_url_ref().ReplaceSearchTerms( 183 GURL result(url.image_url_ref().ReplaceSearchTerms(
181 search_args, search_terms_data)); 184 search_args, search_terms_data));
182 ASSERT_TRUE(result.is_valid()); 185 ASSERT_TRUE(result.is_valid());
183 EXPECT_EQ(KImageSearchURL, result.spec()); 186 EXPECT_EQ(KImageSearchURL, result.spec());
184 TemplateURLRef::PostContent post_content; 187 TemplateURLRef::PostContent post_content;
(...skipping 11 matching lines...) Expand all
196 url.image_url_ref().post_params_; 199 url.image_url_ref().post_params_;
197 EXPECT_EQ(7U, post_params.size()); 200 EXPECT_EQ(7U, post_params.size());
198 for (TemplateURLRef::PostParams::const_iterator i = post_params.begin(); 201 for (TemplateURLRef::PostParams::const_iterator i = post_params.begin();
199 i != post_params.end(); ++i) { 202 i != post_params.end(); ++i) {
200 TemplateURLRef::Replacements::const_iterator j = replacements.begin(); 203 TemplateURLRef::Replacements::const_iterator j = replacements.begin();
201 for (; j != replacements.end(); ++j) { 204 for (; j != replacements.end(); ++j) {
202 if (j->is_post_param && j->index == 205 if (j->is_post_param && j->index ==
203 static_cast<size_t>(i - post_params.begin())) { 206 static_cast<size_t>(i - post_params.begin())) {
204 switch (j->type) { 207 switch (j->type) {
205 case TemplateURLRef::GOOGLE_IMAGE_ORIGINAL_WIDTH: 208 case TemplateURLRef::GOOGLE_IMAGE_ORIGINAL_WIDTH:
206 EXPECT_EQ("width", i->first); 209 EXPECT_EQ("width", i->value_name);
207 EXPECT_EQ( 210 EXPECT_EQ(
208 base::IntToString(search_args.image_original_size.width()), 211 base::IntToString(search_args.image_original_size.width()),
209 i->second); 212 i->value);
213 EXPECT_TRUE(i->content_type.empty());
210 break; 214 break;
211 case TemplateURLRef::GOOGLE_IMAGE_SEARCH_SOURCE: 215 case TemplateURLRef::GOOGLE_IMAGE_SEARCH_SOURCE:
212 EXPECT_EQ("sbisrc", i->first); 216 EXPECT_EQ("sbisrc", i->value_name);
213 EXPECT_EQ(search_terms_data.GoogleImageSearchSource(), i->second); 217 EXPECT_EQ(search_terms_data.GoogleImageSearchSource(), i->value);
218 EXPECT_TRUE(i->content_type.empty());
214 break; 219 break;
215 case TemplateURLRef::GOOGLE_IMAGE_THUMBNAIL: 220 case TemplateURLRef::GOOGLE_IMAGE_THUMBNAIL:
216 EXPECT_EQ("image_content", i->first); 221 EXPECT_EQ("image_content", i->value_name);
217 EXPECT_EQ(search_args.image_thumbnail_content, i->second); 222 EXPECT_EQ(search_args.image_thumbnail_content, i->value);
223 EXPECT_EQ("image/" + search_args.image_thumbnail_format,
224 i->content_type);
218 break; 225 break;
219 case TemplateURLRef::GOOGLE_IMAGE_URL: 226 case TemplateURLRef::GOOGLE_IMAGE_URL:
220 EXPECT_EQ("image_url", i->first); 227 EXPECT_EQ("image_url", i->value_name);
221 EXPECT_EQ(search_args.image_url.spec(), i->second); 228 EXPECT_EQ(search_args.image_url.spec(), i->value);
229 EXPECT_TRUE(i->content_type.empty());
222 break; 230 break;
223 case TemplateURLRef::LANGUAGE: 231 case TemplateURLRef::LANGUAGE:
224 EXPECT_EQ("language", i->first); 232 EXPECT_EQ("language", i->value_name);
225 EXPECT_EQ("en", i->second); 233 EXPECT_EQ("en", i->value);
234 EXPECT_TRUE(i->content_type.empty());
226 break; 235 break;
227 default: 236 default:
228 ADD_FAILURE(); // Should never go here. 237 ADD_FAILURE(); // Should never go here.
229 } 238 }
230 break; 239 break;
231 } 240 }
232 } 241 }
233 if (j != replacements.end()) 242 if (j != replacements.end())
234 continue; 243 continue;
235 if (i->first == "empty_param") { 244 if (i->value_name == "empty_param") {
236 EXPECT_TRUE(i->second.empty()); 245 EXPECT_TRUE(i->value.empty());
237 } else if (i->first == "sbisrc") { 246 EXPECT_TRUE(i->content_type.empty());
238 EXPECT_FALSE(i->second.empty()); 247 } else if (i->value_name == "sbisrc") {
248 EXPECT_FALSE(i->value.empty());
249 EXPECT_TRUE(i->content_type.empty());
239 } else { 250 } else {
240 EXPECT_EQ("constant_param", i->first); 251 EXPECT_EQ("constant_param", i->value_name);
241 EXPECT_EQ("constant", i->second); 252 EXPECT_EQ("constant", i->value);
253 EXPECT_TRUE(i->content_type.empty());
242 } 254 }
243 } 255 }
244 } 256 }
245 257
246 // Test that setting the prepopulate ID from TemplateURL causes the stored 258 // Test that setting the prepopulate ID from TemplateURL causes the stored
247 // TemplateURLRef to handle parsing the URL parameters differently. 259 // TemplateURLRef to handle parsing the URL parameters differently.
248 TEST_F(TemplateURLTest, SetPrepopulatedAndParse) { 260 TEST_F(TemplateURLTest, SetPrepopulatedAndParse) {
249 TemplateURLData data; 261 TemplateURLData data;
250 data.SetURL("http://foo{fhqwhgads}bar"); 262 data.SetURL("http://foo{fhqwhgads}bar");
251 TemplateURL url(data); 263 TemplateURL url(data);
(...skipping 1243 matching lines...) Expand 10 before | Expand all | Expand 10 after
1495 EXPECT_EQ("http://bar/search?q=foo&pfq=full%20query%20text&qha=2338&xssi=t", 1507 EXPECT_EQ("http://bar/search?q=foo&pfq=full%20query%20text&qha=2338&xssi=t",
1496 result); 1508 result);
1497 1509
1498 TemplateURL url2(data); 1510 TemplateURL url2(data);
1499 search_terms_args.prefetch_query.clear(); 1511 search_terms_args.prefetch_query.clear();
1500 search_terms_args.prefetch_query_type.clear(); 1512 search_terms_args.prefetch_query_type.clear();
1501 result = 1513 result =
1502 url2.url_ref().ReplaceSearchTerms(search_terms_args, search_terms_data_); 1514 url2.url_ref().ReplaceSearchTerms(search_terms_args, search_terms_data_);
1503 EXPECT_EQ("http://bar/search?q=foo&xssi=t", result); 1515 EXPECT_EQ("http://bar/search?q=foo&xssi=t", result);
1504 } 1516 }
OLDNEW
« components/search_engines/template_url.h ('K') | « components/search_engines/template_url.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698