| 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 "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 1229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1240 EXPECT_EQ("http://www.google.com/search?q=abc#oq=def&x", | 1240 EXPECT_EQ("http://www.google.com/search?q=abc#oq=def&x", |
| 1241 url.url_ref().ReplaceSearchTerms(search_terms, search_terms_data_)); | 1241 url.url_ref().ReplaceSearchTerms(search_terms, search_terms_data_)); |
| 1242 | 1242 |
| 1243 // Set the suggest_query_params. | 1243 // Set the suggest_query_params. |
| 1244 search_terms.suggest_query_params = "pq=xyz"; | 1244 search_terms.suggest_query_params = "pq=xyz"; |
| 1245 EXPECT_EQ("http://www.google.com/search?pq=xyz&q=abc#oq=def&x", | 1245 EXPECT_EQ("http://www.google.com/search?pq=xyz&q=abc#oq=def&x", |
| 1246 url.url_ref().ReplaceSearchTerms(search_terms, search_terms_data_)); | 1246 url.url_ref().ReplaceSearchTerms(search_terms, search_terms_data_)); |
| 1247 | 1247 |
| 1248 // Add extra_query_params in the mix, and ensure it works. | 1248 // Add extra_query_params in the mix, and ensure it works. |
| 1249 search_terms.append_extra_query_params = true; | 1249 search_terms.append_extra_query_params = true; |
| 1250 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 1250 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 1251 switches::kExtraSearchQueryParams, "a=b"); | 1251 switches::kExtraSearchQueryParams, "a=b"); |
| 1252 EXPECT_EQ("http://www.google.com/search?a=b&pq=xyz&q=abc#oq=def&x", | 1252 EXPECT_EQ("http://www.google.com/search?a=b&pq=xyz&q=abc#oq=def&x", |
| 1253 url.url_ref().ReplaceSearchTerms(search_terms, search_terms_data_)); | 1253 url.url_ref().ReplaceSearchTerms(search_terms, search_terms_data_)); |
| 1254 } | 1254 } |
| 1255 | 1255 |
| 1256 // Test the |append_extra_query_params| field of SearchTermsArgs. | 1256 // Test the |append_extra_query_params| field of SearchTermsArgs. |
| 1257 TEST_F(TemplateURLTest, ExtraQueryParams) { | 1257 TEST_F(TemplateURLTest, ExtraQueryParams) { |
| 1258 TemplateURLData data; | 1258 TemplateURLData data; |
| 1259 // Pick a URL with replacements before, during, and after the query, to ensure | 1259 // Pick a URL with replacements before, during, and after the query, to ensure |
| 1260 // we don't goof up any of them. | 1260 // we don't goof up any of them. |
| 1261 data.SetURL("{google:baseURL}search?q={searchTerms}" | 1261 data.SetURL("{google:baseURL}search?q={searchTerms}" |
| 1262 "#{google:originalQueryForSuggestion}x"); | 1262 "#{google:originalQueryForSuggestion}x"); |
| 1263 TemplateURL url(data); | 1263 TemplateURL url(data); |
| 1264 | 1264 |
| 1265 // Baseline: no command-line args, no |append_extra_query_params| flag. | 1265 // Baseline: no command-line args, no |append_extra_query_params| flag. |
| 1266 TemplateURLRef::SearchTermsArgs search_terms(ASCIIToUTF16("abc")); | 1266 TemplateURLRef::SearchTermsArgs search_terms(ASCIIToUTF16("abc")); |
| 1267 search_terms.original_query = ASCIIToUTF16("def"); | 1267 search_terms.original_query = ASCIIToUTF16("def"); |
| 1268 search_terms.accepted_suggestion = 0; | 1268 search_terms.accepted_suggestion = 0; |
| 1269 EXPECT_EQ("http://www.google.com/search?q=abc#oq=def&x", | 1269 EXPECT_EQ("http://www.google.com/search?q=abc#oq=def&x", |
| 1270 url.url_ref().ReplaceSearchTerms(search_terms, search_terms_data_)); | 1270 url.url_ref().ReplaceSearchTerms(search_terms, search_terms_data_)); |
| 1271 | 1271 |
| 1272 // Set the flag. Since there are no command-line args, this should have no | 1272 // Set the flag. Since there are no command-line args, this should have no |
| 1273 // effect. | 1273 // effect. |
| 1274 search_terms.append_extra_query_params = true; | 1274 search_terms.append_extra_query_params = true; |
| 1275 EXPECT_EQ("http://www.google.com/search?q=abc#oq=def&x", | 1275 EXPECT_EQ("http://www.google.com/search?q=abc#oq=def&x", |
| 1276 url.url_ref().ReplaceSearchTerms(search_terms, search_terms_data_)); | 1276 url.url_ref().ReplaceSearchTerms(search_terms, search_terms_data_)); |
| 1277 | 1277 |
| 1278 // Now append the command-line arg. This should be inserted into the query. | 1278 // Now append the command-line arg. This should be inserted into the query. |
| 1279 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 1279 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 1280 switches::kExtraSearchQueryParams, "a=b"); | 1280 switches::kExtraSearchQueryParams, "a=b"); |
| 1281 EXPECT_EQ("http://www.google.com/search?a=b&q=abc#oq=def&x", | 1281 EXPECT_EQ("http://www.google.com/search?a=b&q=abc#oq=def&x", |
| 1282 url.url_ref().ReplaceSearchTerms(search_terms, search_terms_data_)); | 1282 url.url_ref().ReplaceSearchTerms(search_terms, search_terms_data_)); |
| 1283 | 1283 |
| 1284 // Turn off the flag. Now the command-line arg should be ignored again. | 1284 // Turn off the flag. Now the command-line arg should be ignored again. |
| 1285 search_terms.append_extra_query_params = false; | 1285 search_terms.append_extra_query_params = false; |
| 1286 EXPECT_EQ("http://www.google.com/search?q=abc#oq=def&x", | 1286 EXPECT_EQ("http://www.google.com/search?q=abc#oq=def&x", |
| 1287 url.url_ref().ReplaceSearchTerms(search_terms, search_terms_data_)); | 1287 url.url_ref().ReplaceSearchTerms(search_terms, search_terms_data_)); |
| 1288 } | 1288 } |
| 1289 | 1289 |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1495 EXPECT_EQ("http://bar/search?q=foo&pfq=full%20query%20text&qha=2338&xssi=t", | 1495 EXPECT_EQ("http://bar/search?q=foo&pfq=full%20query%20text&qha=2338&xssi=t", |
| 1496 result); | 1496 result); |
| 1497 | 1497 |
| 1498 TemplateURL url2(data); | 1498 TemplateURL url2(data); |
| 1499 search_terms_args.prefetch_query.clear(); | 1499 search_terms_args.prefetch_query.clear(); |
| 1500 search_terms_args.prefetch_query_type.clear(); | 1500 search_terms_args.prefetch_query_type.clear(); |
| 1501 result = | 1501 result = |
| 1502 url2.url_ref().ReplaceSearchTerms(search_terms_args, search_terms_data_); | 1502 url2.url_ref().ReplaceSearchTerms(search_terms_args, search_terms_data_); |
| 1503 EXPECT_EQ("http://bar/search?q=foo&xssi=t", result); | 1503 EXPECT_EQ("http://bar/search?q=foo&xssi=t", result); |
| 1504 } | 1504 } |
| OLD | NEW |