Chromium Code Reviews| 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/command_line.h" |
| 7 #include "base/metrics/field_trial.h" | |
| 7 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 8 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
| 11 #include "chrome/browser/rlz/rlz.h" | 12 #include "chrome/browser/rlz/rlz.h" |
| 12 #include "chrome/browser/search_engines/search_terms_data.h" | 13 #include "chrome/browser/search_engines/search_terms_data.h" |
| 13 #include "chrome/browser/search_engines/template_url.h" | 14 #include "chrome/browser/search_engines/template_url.h" |
| 15 #include "chrome/browser/search/search.h" | |
| 14 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
| 15 #include "chrome/common/chrome_version_info.h" | 17 #include "chrome/common/chrome_version_info.h" |
| 18 #include "components/variations/entropy_provider.h" | |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 20 |
| 18 #if defined(ENABLE_RLZ) | 21 #if defined(ENABLE_RLZ) |
| 19 #include "chrome/browser/google/google_util.h" | 22 #include "chrome/browser/google/google_util.h" |
| 20 #endif | 23 #endif |
| 21 | 24 |
| 22 #if defined(OS_ANDROID) | 25 #if defined(OS_ANDROID) |
| 23 #include "chrome/browser/search_engines/search_terms_data_android.h" | 26 #include "chrome/browser/search_engines/search_terms_data_android.h" |
| 24 #endif | 27 #endif |
| 25 | 28 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 43 } | 46 } |
| 44 | 47 |
| 45 std::string TestSearchTermsData::GoogleBaseURLValue() const { | 48 std::string TestSearchTermsData::GoogleBaseURLValue() const { |
| 46 return google_base_url_; | 49 return google_base_url_; |
| 47 } | 50 } |
| 48 | 51 |
| 49 // TemplateURLTest ------------------------------------------------------------ | 52 // TemplateURLTest ------------------------------------------------------------ |
| 50 | 53 |
| 51 class TemplateURLTest : public testing::Test { | 54 class TemplateURLTest : public testing::Test { |
| 52 public: | 55 public: |
| 56 virtual void SetUp() OVERRIDE { | |
| 57 field_trial_list_.reset(new base::FieldTrialList( | |
|
Peter Kasting
2013/10/01 01:03:31
I'm not thrilled about going through the field tri
Jered
2013/10/01 18:46:15
This state is field trial state, so going through
| |
| 58 new metrics::SHA1EntropyProvider("42"))); | |
| 59 } | |
| 60 | |
| 53 void CheckSuggestBaseURL(const std::string& base_url, | 61 void CheckSuggestBaseURL(const std::string& base_url, |
| 54 const std::string& base_suggest_url) const; | 62 const std::string& base_suggest_url) const; |
| 63 | |
| 64 private: | |
| 65 scoped_ptr<base::FieldTrialList> field_trial_list_; | |
| 55 }; | 66 }; |
| 56 | 67 |
| 57 void TemplateURLTest::CheckSuggestBaseURL( | 68 void TemplateURLTest::CheckSuggestBaseURL( |
| 58 const std::string& base_url, | 69 const std::string& base_url, |
| 59 const std::string& base_suggest_url) const { | 70 const std::string& base_suggest_url) const { |
| 60 TestSearchTermsData search_terms_data(base_url); | 71 TestSearchTermsData search_terms_data(base_url); |
| 61 EXPECT_EQ(base_suggest_url, search_terms_data.GoogleBaseSuggestURLValue()); | 72 EXPECT_EQ(base_suggest_url, search_terms_data.GoogleBaseSuggestURLValue()); |
| 62 } | 73 } |
| 63 | 74 |
| 64 | 75 |
| (...skipping 1161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1226 { "http://bar/", false, }, | 1237 { "http://bar/", false, }, |
| 1227 { "http://foo/", false, }, | 1238 { "http://foo/", false, }, |
| 1228 { "http://bar/newtab", false, }, | 1239 { "http://bar/newtab", false, }, |
| 1229 }; | 1240 }; |
| 1230 | 1241 |
| 1231 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(url_data); ++i) { | 1242 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(url_data); ++i) { |
| 1232 EXPECT_EQ(url_data[i].result, | 1243 EXPECT_EQ(url_data[i].result, |
| 1233 search_provider.IsSearchURL(GURL(url_data[i].url))); | 1244 search_provider.IsSearchURL(GURL(url_data[i].url))); |
| 1234 } | 1245 } |
| 1235 } | 1246 } |
| 1247 | |
| 1248 TEST_F(TemplateURLTest, BookmarkBarPinnedArgNotReplaced) { | |
| 1249 chrome::EnableInstantExtendedAPIForTesting(); | |
| 1250 TemplateURLData data; | |
| 1251 data.input_encodings.push_back("UTF-8"); | |
| 1252 data.SetURL("{google:baseURL}?{google:bookmarkBarPinned}q={searchTerms}"); | |
| 1253 TemplateURL url(NULL, data); | |
| 1254 EXPECT_TRUE(url.url_ref().IsValid()); | |
| 1255 ASSERT_TRUE(url.url_ref().SupportsReplacement()); | |
| 1256 TemplateURLRef::SearchTermsArgs search_terms_args(ASCIIToUTF16("foo")); | |
| 1257 | |
| 1258 // Do not add the param when InstantExtended is suppressed on SRPs. | |
| 1259 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | |
| 1260 "InstantExtended", "Group1 espv:2 suppress_on_srp:1")); | |
| 1261 ASSERT_TRUE(chrome::ShouldSuppressInstantExtendedOnSRP()); | |
| 1262 std::string result = url.url_ref().ReplaceSearchTerms(search_terms_args); | |
| 1263 EXPECT_EQ("http://www.google.com/?q=foo", result); | |
| 1264 } | |
| 1265 | |
| 1266 TEST_F(TemplateURLTest, BookmarkBarPinnedArgReplaced) { | |
|
Peter Kasting
2013/10/01 01:03:31
Nit: Again, I'd make this all one test, since it's
Jered
2013/10/01 18:46:15
Done.
| |
| 1267 chrome::EnableInstantExtendedAPIForTesting(); | |
| 1268 TemplateURLData data; | |
| 1269 data.input_encodings.push_back("UTF-8"); | |
| 1270 data.SetURL("{google:baseURL}?{google:bookmarkBarPinned}q={searchTerms}"); | |
| 1271 TemplateURL url(NULL, data); | |
| 1272 EXPECT_TRUE(url.url_ref().IsValid()); | |
| 1273 ASSERT_TRUE(url.url_ref().SupportsReplacement()); | |
| 1274 TemplateURLRef::SearchTermsArgs search_terms_args(ASCIIToUTF16("foo")); | |
| 1275 | |
| 1276 // Add the param when InstantExtended is suppressed on SRPs. | |
| 1277 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | |
| 1278 "InstantExtended", "Group1 espv:2 suppress_on_srp:0")); | |
| 1279 ASSERT_FALSE(chrome::ShouldSuppressInstantExtendedOnSRP()); | |
| 1280 | |
| 1281 search_terms_args.bookmark_bar_pinned = false; | |
| 1282 std::string result = url.url_ref().ReplaceSearchTerms(search_terms_args); | |
| 1283 EXPECT_EQ("http://www.google.com/?bmbp=0&q=foo", result); | |
| 1284 | |
| 1285 search_terms_args.bookmark_bar_pinned = true; | |
| 1286 result = url.url_ref().ReplaceSearchTerms(search_terms_args); | |
| 1287 EXPECT_EQ("http://www.google.com/?bmbp=1&q=foo", result); | |
| 1288 } | |
| OLD | NEW |