OLD | NEW |
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/command_line.h" |
6 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
7 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
8 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
9 #include "chrome/browser/rlz/rlz.h" | 10 #include "chrome/browser/rlz/rlz.h" |
10 #include "chrome/browser/search_engines/search_terms_data.h" | 11 #include "chrome/browser/search_engines/search_terms_data.h" |
11 #include "chrome/browser/search_engines/template_url.h" | 12 #include "chrome/browser/search_engines/template_url.h" |
| 13 #include "chrome/common/chrome_switches.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
13 | 15 |
14 #if defined(ENABLE_RLZ) | 16 #if defined(ENABLE_RLZ) |
15 #include "chrome/browser/google/google_util.h" | 17 #include "chrome/browser/google/google_util.h" |
16 #endif | 18 #endif |
17 | 19 |
18 #if defined(OS_ANDROID) | 20 #if defined(OS_ANDROID) |
19 #include "chrome/browser/search_engines/search_terms_data_android.h" | 21 #include "chrome/browser/search_engines/search_terms_data_android.h" |
20 #endif | 22 #endif |
21 | 23 |
(...skipping 1003 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1025 EXPECT_FALSE(url.ReplaceSearchTermsInURL( | 1027 EXPECT_FALSE(url.ReplaceSearchTermsInURL( |
1026 GURL("http://google.com/alt/?q=#q="), search_terms, &result)); | 1028 GURL("http://google.com/alt/?q=#q="), search_terms, &result)); |
1027 | 1029 |
1028 EXPECT_FALSE(url.ReplaceSearchTermsInURL( | 1030 EXPECT_FALSE(url.ReplaceSearchTermsInURL( |
1029 GURL("http://google.com/alt/?q=123#q="), search_terms, &result)); | 1031 GURL("http://google.com/alt/?q=123#q="), search_terms, &result)); |
1030 | 1032 |
1031 EXPECT_TRUE(url.ReplaceSearchTermsInURL( | 1033 EXPECT_TRUE(url.ReplaceSearchTermsInURL( |
1032 GURL("http://google.com/alt/?q=#q=123"), search_terms, &result)); | 1034 GURL("http://google.com/alt/?q=#q=123"), search_terms, &result)); |
1033 EXPECT_EQ(GURL("http://google.com/alt/?q=#q=Bob Morane"), result); | 1035 EXPECT_EQ(GURL("http://google.com/alt/?q=#q=Bob Morane"), result); |
1034 } | 1036 } |
| 1037 |
| 1038 // Test the |append_extra_query_params| field of SearchTermsArgs. |
| 1039 TEST_F(TemplateURLTest, ExtraQueryParams) { |
| 1040 UIThreadSearchTermsData::SetGoogleBaseURL("http://www.google.com/"); |
| 1041 TemplateURLData data; |
| 1042 // Pick a URL with replacements before, during, and after the query, to ensure |
| 1043 // we don't goof up any of them. |
| 1044 data.SetURL("{google:baseURL}search?q={searchTerms}" |
| 1045 "#{google:originalQueryForSuggestion}x"); |
| 1046 TemplateURL url(NULL, data); |
| 1047 |
| 1048 // Baseline: no command-line args, no |append_extra_query_params| flag. |
| 1049 TemplateURLRef::SearchTermsArgs search_terms(ASCIIToUTF16("abc")); |
| 1050 search_terms.original_query = ASCIIToUTF16("def"); |
| 1051 search_terms.accepted_suggestion = 0; |
| 1052 EXPECT_EQ("http://www.google.com/search?q=abc#oq=def&x", |
| 1053 url.url_ref().ReplaceSearchTerms(search_terms)); |
| 1054 |
| 1055 // Set the flag. Since there are no command-line args, this should have no |
| 1056 // effect. |
| 1057 search_terms.append_extra_query_params = true; |
| 1058 EXPECT_EQ("http://www.google.com/search?q=abc#oq=def&x", |
| 1059 url.url_ref().ReplaceSearchTerms(search_terms)); |
| 1060 |
| 1061 // Now append the command-line arg. This should be inserted into the query. |
| 1062 CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 1063 switches::kExtraSearchQueryParams, "a=b"); |
| 1064 EXPECT_EQ("http://www.google.com/search?a=b&q=abc#oq=def&x", |
| 1065 url.url_ref().ReplaceSearchTerms(search_terms)); |
| 1066 |
| 1067 // Turn off the flag. Now the command-line arg should be ignored again. |
| 1068 search_terms.append_extra_query_params = false; |
| 1069 EXPECT_EQ("http://www.google.com/search?q=abc#oq=def&x", |
| 1070 url.url_ref().ReplaceSearchTerms(search_terms)); |
| 1071 } |
OLD | NEW |