| 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/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/files/scoped_temp_dir.h" | 6 #include "base/files/scoped_temp_dir.h" |
| 7 #include "base/memory/scoped_vector.h" | 7 #include "base/memory/scoped_vector.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/search_engines/template_url.h" | 9 #include "chrome/browser/search_engines/template_url.h" |
| 10 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" | 10 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" |
| 11 #include "chrome/browser/search_engines/template_url_service.h" | 11 #include "chrome/browser/search_engines/template_url_service.h" |
| 12 #include "chrome/common/chrome_switches.h" | 12 #include "chrome/common/chrome_switches.h" |
| 13 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
| 14 #include "chrome/test/base/testing_pref_service_syncable.h" | |
| 15 #include "chrome/test/base/testing_profile.h" | |
| 16 #include "components/google/core/browser/google_switches.h" | 14 #include "components/google/core/browser/google_switches.h" |
| 15 #include "components/pref_registry/testing_pref_service_syncable.h" |
| 17 #include "components/search_engines/prepopulated_engines.h" | 16 #include "components/search_engines/prepopulated_engines.h" |
| 18 #include "components/search_engines/search_terms_data.h" | 17 #include "components/search_engines/search_terms_data.h" |
| 19 #include "grit/generated_resources.h" | 18 #include "grit/generated_resources.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 21 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
| 22 | 21 |
| 23 using base::ASCIIToUTF16; | 22 using base::ASCIIToUTF16; |
| 24 | 23 |
| 25 namespace { | 24 namespace { |
| 26 | 25 |
| 27 SearchEngineType GetEngineType(const std::string& url) { | 26 SearchEngineType GetEngineType(const std::string& url) { |
| 28 TemplateURLData data; | 27 TemplateURLData data; |
| 29 data.SetURL(url); | 28 data.SetURL(url); |
| 30 return TemplateURLPrepopulateData::GetEngineType(TemplateURL(data), | 29 return TemplateURLPrepopulateData::GetEngineType(TemplateURL(data), |
| 31 SearchTermsData()); | 30 SearchTermsData()); |
| 32 } | 31 } |
| 33 | 32 |
| 34 std::string GetHostFromTemplateURLData(const TemplateURLData& data) { | 33 std::string GetHostFromTemplateURLData(const TemplateURLData& data) { |
| 35 return TemplateURL(data).url_ref().GetHost(SearchTermsData()); | 34 return TemplateURL(data).url_ref().GetHost(SearchTermsData()); |
| 36 } | 35 } |
| 37 | 36 |
| 38 } // namespace | 37 } // namespace |
| 39 | 38 |
| 40 typedef testing::Test TemplateURLPrepopulateDataTest; | 39 class TemplateURLPrepopulateDataTest : public testing::Test { |
| 40 public: |
| 41 virtual void SetUp() OVERRIDE { |
| 42 TemplateURLPrepopulateData::RegisterProfilePrefs(prefs_.registry()); |
| 43 } |
| 44 |
| 45 protected: |
| 46 user_prefs::TestingPrefServiceSyncable prefs_; |
| 47 }; |
| 41 | 48 |
| 42 // Verifies the set of prepopulate data doesn't contain entries with duplicate | 49 // Verifies the set of prepopulate data doesn't contain entries with duplicate |
| 43 // ids. | 50 // ids. |
| 44 TEST(TemplateURLPrepopulateDataTest, UniqueIDs) { | 51 TEST_F(TemplateURLPrepopulateDataTest, UniqueIDs) { |
| 45 const int kCountryIds[] = { | 52 const int kCountryIds[] = { |
| 46 'A'<<8|'D', 'A'<<8|'E', 'A'<<8|'F', 'A'<<8|'G', 'A'<<8|'I', | 53 'A'<<8|'D', 'A'<<8|'E', 'A'<<8|'F', 'A'<<8|'G', 'A'<<8|'I', |
| 47 'A'<<8|'L', 'A'<<8|'M', 'A'<<8|'N', 'A'<<8|'O', 'A'<<8|'Q', | 54 'A'<<8|'L', 'A'<<8|'M', 'A'<<8|'N', 'A'<<8|'O', 'A'<<8|'Q', |
| 48 'A'<<8|'R', 'A'<<8|'S', 'A'<<8|'T', 'A'<<8|'U', 'A'<<8|'W', | 55 'A'<<8|'R', 'A'<<8|'S', 'A'<<8|'T', 'A'<<8|'U', 'A'<<8|'W', |
| 49 'A'<<8|'X', 'A'<<8|'Z', 'B'<<8|'A', 'B'<<8|'B', 'B'<<8|'D', | 56 'A'<<8|'X', 'A'<<8|'Z', 'B'<<8|'A', 'B'<<8|'B', 'B'<<8|'D', |
| 50 'B'<<8|'E', 'B'<<8|'F', 'B'<<8|'G', 'B'<<8|'H', 'B'<<8|'I', | 57 'B'<<8|'E', 'B'<<8|'F', 'B'<<8|'G', 'B'<<8|'H', 'B'<<8|'I', |
| 51 'B'<<8|'J', 'B'<<8|'M', 'B'<<8|'N', 'B'<<8|'O', 'B'<<8|'R', | 58 'B'<<8|'J', 'B'<<8|'M', 'B'<<8|'N', 'B'<<8|'O', 'B'<<8|'R', |
| 52 'B'<<8|'S', 'B'<<8|'T', 'B'<<8|'V', 'B'<<8|'W', 'B'<<8|'Y', | 59 'B'<<8|'S', 'B'<<8|'T', 'B'<<8|'V', 'B'<<8|'W', 'B'<<8|'Y', |
| 53 'B'<<8|'Z', 'C'<<8|'A', 'C'<<8|'C', 'C'<<8|'D', 'C'<<8|'F', | 60 'B'<<8|'Z', 'C'<<8|'A', 'C'<<8|'C', 'C'<<8|'D', 'C'<<8|'F', |
| 54 'C'<<8|'G', 'C'<<8|'H', 'C'<<8|'I', 'C'<<8|'K', 'C'<<8|'L', | 61 'C'<<8|'G', 'C'<<8|'H', 'C'<<8|'I', 'C'<<8|'K', 'C'<<8|'L', |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 'S'<<8|'M', 'S'<<8|'N', 'S'<<8|'O', 'S'<<8|'R', 'S'<<8|'T', | 93 'S'<<8|'M', 'S'<<8|'N', 'S'<<8|'O', 'S'<<8|'R', 'S'<<8|'T', |
| 87 'S'<<8|'V', 'S'<<8|'Y', 'S'<<8|'Z', 'T'<<8|'C', 'T'<<8|'D', | 94 'S'<<8|'V', 'S'<<8|'Y', 'S'<<8|'Z', 'T'<<8|'C', 'T'<<8|'D', |
| 88 'T'<<8|'F', 'T'<<8|'G', 'T'<<8|'H', 'T'<<8|'J', 'T'<<8|'K', | 95 'T'<<8|'F', 'T'<<8|'G', 'T'<<8|'H', 'T'<<8|'J', 'T'<<8|'K', |
| 89 'T'<<8|'L', 'T'<<8|'M', 'T'<<8|'N', 'T'<<8|'O', 'T'<<8|'R', | 96 'T'<<8|'L', 'T'<<8|'M', 'T'<<8|'N', 'T'<<8|'O', 'T'<<8|'R', |
| 90 'T'<<8|'T', 'T'<<8|'V', 'T'<<8|'W', 'T'<<8|'Z', 'U'<<8|'A', | 97 'T'<<8|'T', 'T'<<8|'V', 'T'<<8|'W', 'T'<<8|'Z', 'U'<<8|'A', |
| 91 'U'<<8|'G', 'U'<<8|'M', 'U'<<8|'S', 'U'<<8|'Y', 'U'<<8|'Z', | 98 'U'<<8|'G', 'U'<<8|'M', 'U'<<8|'S', 'U'<<8|'Y', 'U'<<8|'Z', |
| 92 'V'<<8|'A', 'V'<<8|'C', 'V'<<8|'E', 'V'<<8|'G', 'V'<<8|'I', | 99 'V'<<8|'A', 'V'<<8|'C', 'V'<<8|'E', 'V'<<8|'G', 'V'<<8|'I', |
| 93 'V'<<8|'N', 'V'<<8|'U', 'W'<<8|'F', 'W'<<8|'S', 'Y'<<8|'E', | 100 'V'<<8|'N', 'V'<<8|'U', 'W'<<8|'F', 'W'<<8|'S', 'Y'<<8|'E', |
| 94 'Y'<<8|'T', 'Z'<<8|'A', 'Z'<<8|'M', 'Z'<<8|'W', -1 }; | 101 'Y'<<8|'T', 'Z'<<8|'A', 'Z'<<8|'M', 'Z'<<8|'W', -1 }; |
| 95 | 102 |
| 96 TestingProfile profile; | |
| 97 for (size_t i = 0; i < arraysize(kCountryIds); ++i) { | 103 for (size_t i = 0; i < arraysize(kCountryIds); ++i) { |
| 98 profile.GetPrefs()->SetInteger(prefs::kCountryIDAtInstall, kCountryIds[i]); | 104 prefs_.SetInteger(prefs::kCountryIDAtInstall, kCountryIds[i]); |
| 99 size_t default_index; | 105 size_t default_index; |
| 100 ScopedVector<TemplateURLData> urls = | 106 ScopedVector<TemplateURLData> urls = |
| 101 TemplateURLPrepopulateData::GetPrepopulatedEngines(profile.GetPrefs(), | 107 TemplateURLPrepopulateData::GetPrepopulatedEngines(&prefs_, |
| 102 &default_index); | 108 &default_index); |
| 103 std::set<int> unique_ids; | 109 std::set<int> unique_ids; |
| 104 for (size_t turl_i = 0; turl_i < urls.size(); ++turl_i) { | 110 for (size_t turl_i = 0; turl_i < urls.size(); ++turl_i) { |
| 105 ASSERT_TRUE(unique_ids.find(urls[turl_i]->prepopulate_id) == | 111 ASSERT_TRUE(unique_ids.find(urls[turl_i]->prepopulate_id) == |
| 106 unique_ids.end()); | 112 unique_ids.end()); |
| 107 unique_ids.insert(urls[turl_i]->prepopulate_id); | 113 unique_ids.insert(urls[turl_i]->prepopulate_id); |
| 108 } | 114 } |
| 109 } | 115 } |
| 110 } | 116 } |
| 111 | 117 |
| 112 // Verifies that default search providers from the preferences file | 118 // Verifies that default search providers from the preferences file |
| 113 // override the built-in ones. | 119 // override the built-in ones. |
| 114 TEST(TemplateURLPrepopulateDataTest, ProvidersFromPrefs) { | 120 TEST_F(TemplateURLPrepopulateDataTest, ProvidersFromPrefs) { |
| 115 TestingProfile profile; | 121 prefs_.SetUserPref(prefs::kSearchProviderOverridesVersion, |
| 116 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); | |
| 117 prefs->SetUserPref(prefs::kSearchProviderOverridesVersion, | |
| 118 base::Value::CreateIntegerValue(1)); | 122 base::Value::CreateIntegerValue(1)); |
| 119 base::ListValue* overrides = new base::ListValue; | 123 base::ListValue* overrides = new base::ListValue; |
| 120 scoped_ptr<base::DictionaryValue> entry(new base::DictionaryValue); | 124 scoped_ptr<base::DictionaryValue> entry(new base::DictionaryValue); |
| 121 // Set only the minimal required settings for a search provider configuration. | 125 // Set only the minimal required settings for a search provider configuration. |
| 122 entry->SetString("name", "foo"); | 126 entry->SetString("name", "foo"); |
| 123 entry->SetString("keyword", "fook"); | 127 entry->SetString("keyword", "fook"); |
| 124 entry->SetString("search_url", "http://foo.com/s?q={searchTerms}"); | 128 entry->SetString("search_url", "http://foo.com/s?q={searchTerms}"); |
| 125 entry->SetString("favicon_url", "http://foi.com/favicon.ico"); | 129 entry->SetString("favicon_url", "http://foi.com/favicon.ico"); |
| 126 entry->SetString("encoding", "UTF-8"); | 130 entry->SetString("encoding", "UTF-8"); |
| 127 entry->SetInteger("id", 1001); | 131 entry->SetInteger("id", 1001); |
| 128 overrides->Append(entry->DeepCopy()); | 132 overrides->Append(entry->DeepCopy()); |
| 129 prefs->SetUserPref(prefs::kSearchProviderOverrides, overrides); | 133 prefs_.SetUserPref(prefs::kSearchProviderOverrides, overrides); |
| 130 | 134 |
| 131 int version = TemplateURLPrepopulateData::GetDataVersion(prefs); | 135 int version = TemplateURLPrepopulateData::GetDataVersion(&prefs_); |
| 132 EXPECT_EQ(1, version); | 136 EXPECT_EQ(1, version); |
| 133 | 137 |
| 134 size_t default_index; | 138 size_t default_index; |
| 135 ScopedVector<TemplateURLData> t_urls = | 139 ScopedVector<TemplateURLData> t_urls = |
| 136 TemplateURLPrepopulateData::GetPrepopulatedEngines(prefs, &default_index); | 140 TemplateURLPrepopulateData::GetPrepopulatedEngines(&prefs_, |
| 141 &default_index); |
| 137 | 142 |
| 138 ASSERT_EQ(1u, t_urls.size()); | 143 ASSERT_EQ(1u, t_urls.size()); |
| 139 EXPECT_EQ(ASCIIToUTF16("foo"), t_urls[0]->short_name); | 144 EXPECT_EQ(ASCIIToUTF16("foo"), t_urls[0]->short_name); |
| 140 EXPECT_EQ(ASCIIToUTF16("fook"), t_urls[0]->keyword()); | 145 EXPECT_EQ(ASCIIToUTF16("fook"), t_urls[0]->keyword()); |
| 141 EXPECT_EQ("foo.com", GetHostFromTemplateURLData(*t_urls[0])); | 146 EXPECT_EQ("foo.com", GetHostFromTemplateURLData(*t_urls[0])); |
| 142 EXPECT_EQ("foi.com", t_urls[0]->favicon_url.host()); | 147 EXPECT_EQ("foi.com", t_urls[0]->favicon_url.host()); |
| 143 EXPECT_EQ(1u, t_urls[0]->input_encodings.size()); | 148 EXPECT_EQ(1u, t_urls[0]->input_encodings.size()); |
| 144 EXPECT_EQ(1001, t_urls[0]->prepopulate_id); | 149 EXPECT_EQ(1001, t_urls[0]->prepopulate_id); |
| 145 EXPECT_TRUE(t_urls[0]->suggestions_url.empty()); | 150 EXPECT_TRUE(t_urls[0]->suggestions_url.empty()); |
| 146 EXPECT_TRUE(t_urls[0]->instant_url.empty()); | 151 EXPECT_TRUE(t_urls[0]->instant_url.empty()); |
| 147 EXPECT_EQ(0u, t_urls[0]->alternate_urls.size()); | 152 EXPECT_EQ(0u, t_urls[0]->alternate_urls.size()); |
| 148 EXPECT_TRUE(t_urls[0]->search_terms_replacement_key.empty()); | 153 EXPECT_TRUE(t_urls[0]->search_terms_replacement_key.empty()); |
| 149 | 154 |
| 150 // Test the optional settings too. | 155 // Test the optional settings too. |
| 151 entry->SetString("suggest_url", "http://foo.com/suggest?q={searchTerms}"); | 156 entry->SetString("suggest_url", "http://foo.com/suggest?q={searchTerms}"); |
| 152 entry->SetString("instant_url", "http://foo.com/instant?q={searchTerms}"); | 157 entry->SetString("instant_url", "http://foo.com/instant?q={searchTerms}"); |
| 153 base::ListValue* alternate_urls = new base::ListValue; | 158 base::ListValue* alternate_urls = new base::ListValue; |
| 154 alternate_urls->AppendString("http://foo.com/alternate?q={searchTerms}"); | 159 alternate_urls->AppendString("http://foo.com/alternate?q={searchTerms}"); |
| 155 entry->Set("alternate_urls", alternate_urls); | 160 entry->Set("alternate_urls", alternate_urls); |
| 156 entry->SetString("search_terms_replacement_key", "espv"); | 161 entry->SetString("search_terms_replacement_key", "espv"); |
| 157 overrides = new base::ListValue; | 162 overrides = new base::ListValue; |
| 158 overrides->Append(entry->DeepCopy()); | 163 overrides->Append(entry->DeepCopy()); |
| 159 prefs->SetUserPref(prefs::kSearchProviderOverrides, overrides); | 164 prefs_.SetUserPref(prefs::kSearchProviderOverrides, overrides); |
| 160 | 165 |
| 161 t_urls = TemplateURLPrepopulateData::GetPrepopulatedEngines( | 166 t_urls = TemplateURLPrepopulateData::GetPrepopulatedEngines( |
| 162 profile.GetPrefs(), &default_index); | 167 &prefs_, &default_index); |
| 163 ASSERT_EQ(1u, t_urls.size()); | 168 ASSERT_EQ(1u, t_urls.size()); |
| 164 EXPECT_EQ(ASCIIToUTF16("foo"), t_urls[0]->short_name); | 169 EXPECT_EQ(ASCIIToUTF16("foo"), t_urls[0]->short_name); |
| 165 EXPECT_EQ(ASCIIToUTF16("fook"), t_urls[0]->keyword()); | 170 EXPECT_EQ(ASCIIToUTF16("fook"), t_urls[0]->keyword()); |
| 166 EXPECT_EQ("foo.com", GetHostFromTemplateURLData(*t_urls[0])); | 171 EXPECT_EQ("foo.com", GetHostFromTemplateURLData(*t_urls[0])); |
| 167 EXPECT_EQ("foi.com", t_urls[0]->favicon_url.host()); | 172 EXPECT_EQ("foi.com", t_urls[0]->favicon_url.host()); |
| 168 EXPECT_EQ(1u, t_urls[0]->input_encodings.size()); | 173 EXPECT_EQ(1u, t_urls[0]->input_encodings.size()); |
| 169 EXPECT_EQ(1001, t_urls[0]->prepopulate_id); | 174 EXPECT_EQ(1001, t_urls[0]->prepopulate_id); |
| 170 EXPECT_EQ("http://foo.com/suggest?q={searchTerms}", | 175 EXPECT_EQ("http://foo.com/suggest?q={searchTerms}", |
| 171 t_urls[0]->suggestions_url); | 176 t_urls[0]->suggestions_url); |
| 172 EXPECT_EQ("http://foo.com/instant?q={searchTerms}", | 177 EXPECT_EQ("http://foo.com/instant?q={searchTerms}", |
| (...skipping 10 matching lines...) Expand all Loading... |
| 183 entry->SetInteger("id", 1002); | 188 entry->SetInteger("id", 1002); |
| 184 entry->SetString("name", "bar"); | 189 entry->SetString("name", "bar"); |
| 185 entry->SetString("keyword", "bark"); | 190 entry->SetString("keyword", "bark"); |
| 186 entry->SetString("encoding", std::string()); | 191 entry->SetString("encoding", std::string()); |
| 187 overrides->Append(entry->DeepCopy()); | 192 overrides->Append(entry->DeepCopy()); |
| 188 entry->SetInteger("id", 1003); | 193 entry->SetInteger("id", 1003); |
| 189 entry->SetString("name", "baz"); | 194 entry->SetString("name", "baz"); |
| 190 entry->SetString("keyword", "bazk"); | 195 entry->SetString("keyword", "bazk"); |
| 191 entry->SetString("encoding", "UTF-8"); | 196 entry->SetString("encoding", "UTF-8"); |
| 192 overrides->Append(entry->DeepCopy()); | 197 overrides->Append(entry->DeepCopy()); |
| 193 prefs->SetUserPref(prefs::kSearchProviderOverrides, overrides); | 198 prefs_.SetUserPref(prefs::kSearchProviderOverrides, overrides); |
| 194 | 199 |
| 195 t_urls = | 200 t_urls = |
| 196 TemplateURLPrepopulateData::GetPrepopulatedEngines(prefs, &default_index); | 201 TemplateURLPrepopulateData::GetPrepopulatedEngines(&prefs_, |
| 202 &default_index); |
| 197 EXPECT_EQ(2u, t_urls.size()); | 203 EXPECT_EQ(2u, t_urls.size()); |
| 198 } | 204 } |
| 199 | 205 |
| 200 TEST(TemplateURLPrepopulateDataTest, ClearProvidersFromPrefs) { | 206 TEST_F(TemplateURLPrepopulateDataTest, ClearProvidersFromPrefs) { |
| 201 TestingProfile profile; | 207 prefs_.SetUserPref(prefs::kSearchProviderOverridesVersion, |
| 202 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); | |
| 203 prefs->SetUserPref(prefs::kSearchProviderOverridesVersion, | |
| 204 base::Value::CreateIntegerValue(1)); | 208 base::Value::CreateIntegerValue(1)); |
| 205 base::ListValue* overrides = new base::ListValue; | 209 base::ListValue* overrides = new base::ListValue; |
| 206 base::DictionaryValue* entry(new base::DictionaryValue); | 210 base::DictionaryValue* entry(new base::DictionaryValue); |
| 207 // Set only the minimal required settings for a search provider configuration. | 211 // Set only the minimal required settings for a search provider configuration. |
| 208 entry->SetString("name", "foo"); | 212 entry->SetString("name", "foo"); |
| 209 entry->SetString("keyword", "fook"); | 213 entry->SetString("keyword", "fook"); |
| 210 entry->SetString("search_url", "http://foo.com/s?q={searchTerms}"); | 214 entry->SetString("search_url", "http://foo.com/s?q={searchTerms}"); |
| 211 entry->SetString("favicon_url", "http://foi.com/favicon.ico"); | 215 entry->SetString("favicon_url", "http://foi.com/favicon.ico"); |
| 212 entry->SetString("encoding", "UTF-8"); | 216 entry->SetString("encoding", "UTF-8"); |
| 213 entry->SetInteger("id", 1001); | 217 entry->SetInteger("id", 1001); |
| 214 overrides->Append(entry); | 218 overrides->Append(entry); |
| 215 prefs->SetUserPref(prefs::kSearchProviderOverrides, overrides); | 219 prefs_.SetUserPref(prefs::kSearchProviderOverrides, overrides); |
| 216 | 220 |
| 217 int version = TemplateURLPrepopulateData::GetDataVersion(prefs); | 221 int version = TemplateURLPrepopulateData::GetDataVersion(&prefs_); |
| 218 EXPECT_EQ(1, version); | 222 EXPECT_EQ(1, version); |
| 219 | 223 |
| 220 // This call removes the above search engine. | 224 // This call removes the above search engine. |
| 221 TemplateURLPrepopulateData::ClearPrepopulatedEnginesInPrefs(prefs); | 225 TemplateURLPrepopulateData::ClearPrepopulatedEnginesInPrefs(&prefs_); |
| 222 | 226 |
| 223 version = TemplateURLPrepopulateData::GetDataVersion(prefs); | 227 version = TemplateURLPrepopulateData::GetDataVersion(&prefs_); |
| 224 EXPECT_EQ(TemplateURLPrepopulateData::kCurrentDataVersion, version); | 228 EXPECT_EQ(TemplateURLPrepopulateData::kCurrentDataVersion, version); |
| 225 | 229 |
| 226 size_t default_index; | 230 size_t default_index; |
| 227 ScopedVector<TemplateURLData> t_urls = | 231 ScopedVector<TemplateURLData> t_urls = |
| 228 TemplateURLPrepopulateData::GetPrepopulatedEngines(prefs, &default_index); | 232 TemplateURLPrepopulateData::GetPrepopulatedEngines(&prefs_, |
| 233 &default_index); |
| 229 ASSERT_FALSE(t_urls.empty()); | 234 ASSERT_FALSE(t_urls.empty()); |
| 230 for (size_t i = 0; i < t_urls.size(); ++i) { | 235 for (size_t i = 0; i < t_urls.size(); ++i) { |
| 231 EXPECT_NE(ASCIIToUTF16("foo"), t_urls[i]->short_name); | 236 EXPECT_NE(ASCIIToUTF16("foo"), t_urls[i]->short_name); |
| 232 EXPECT_NE(ASCIIToUTF16("fook"), t_urls[i]->keyword()); | 237 EXPECT_NE(ASCIIToUTF16("fook"), t_urls[i]->keyword()); |
| 233 EXPECT_NE("foi.com", t_urls[i]->favicon_url.host()); | 238 EXPECT_NE("foi.com", t_urls[i]->favicon_url.host()); |
| 234 EXPECT_NE("foo.com", GetHostFromTemplateURLData(*t_urls[i])); | 239 EXPECT_NE("foo.com", GetHostFromTemplateURLData(*t_urls[i])); |
| 235 EXPECT_NE(1001, t_urls[i]->prepopulate_id); | 240 EXPECT_NE(1001, t_urls[i]->prepopulate_id); |
| 236 } | 241 } |
| 237 // Ensures the default URL is Google and has the optional fields filled. | 242 // Ensures the default URL is Google and has the optional fields filled. |
| 238 EXPECT_EQ(ASCIIToUTF16("Google"), t_urls[default_index]->short_name); | 243 EXPECT_EQ(ASCIIToUTF16("Google"), t_urls[default_index]->short_name); |
| 239 EXPECT_FALSE(t_urls[default_index]->suggestions_url.empty()); | 244 EXPECT_FALSE(t_urls[default_index]->suggestions_url.empty()); |
| 240 EXPECT_FALSE(t_urls[default_index]->instant_url.empty()); | 245 EXPECT_FALSE(t_urls[default_index]->instant_url.empty()); |
| 241 EXPECT_FALSE(t_urls[default_index]->image_url.empty()); | 246 EXPECT_FALSE(t_urls[default_index]->image_url.empty()); |
| 242 EXPECT_FALSE(t_urls[default_index]->new_tab_url.empty()); | 247 EXPECT_FALSE(t_urls[default_index]->new_tab_url.empty()); |
| 243 EXPECT_FALSE(t_urls[default_index]->contextual_search_url.empty()); | 248 EXPECT_FALSE(t_urls[default_index]->contextual_search_url.empty()); |
| 244 EXPECT_FALSE(t_urls[default_index]->image_url_post_params.empty()); | 249 EXPECT_FALSE(t_urls[default_index]->image_url_post_params.empty()); |
| 245 EXPECT_EQ(SEARCH_ENGINE_GOOGLE, | 250 EXPECT_EQ(SEARCH_ENGINE_GOOGLE, |
| 246 TemplateURLPrepopulateData::GetEngineType( | 251 TemplateURLPrepopulateData::GetEngineType( |
| 247 TemplateURL(*t_urls[default_index]), | 252 TemplateURL(*t_urls[default_index]), |
| 248 SearchTermsData())); | 253 SearchTermsData())); |
| 249 } | 254 } |
| 250 | 255 |
| 251 // Verifies that built-in search providers are processed correctly. | 256 // Verifies that built-in search providers are processed correctly. |
| 252 TEST(TemplateURLPrepopulateDataTest, ProvidersFromPrepopulated) { | 257 TEST_F(TemplateURLPrepopulateDataTest, ProvidersFromPrepopulated) { |
| 253 TestingProfile profile; | |
| 254 // Use United States. | 258 // Use United States. |
| 255 profile.GetPrefs()->SetInteger(prefs::kCountryIDAtInstall, 'U'<<8|'S'); | 259 prefs_.SetInteger(prefs::kCountryIDAtInstall, 'U'<<8|'S'); |
| 256 size_t default_index; | 260 size_t default_index; |
| 257 ScopedVector<TemplateURLData> t_urls = | 261 ScopedVector<TemplateURLData> t_urls = |
| 258 TemplateURLPrepopulateData::GetPrepopulatedEngines(profile.GetPrefs(), | 262 TemplateURLPrepopulateData::GetPrepopulatedEngines(&prefs_, |
| 259 &default_index); | 263 &default_index); |
| 260 | 264 |
| 261 // Ensure all the URLs have the required fields populated. | 265 // Ensure all the URLs have the required fields populated. |
| 262 ASSERT_FALSE(t_urls.empty()); | 266 ASSERT_FALSE(t_urls.empty()); |
| 263 for (size_t i = 0; i < t_urls.size(); ++i) { | 267 for (size_t i = 0; i < t_urls.size(); ++i) { |
| 264 ASSERT_FALSE(t_urls[i]->short_name.empty()); | 268 ASSERT_FALSE(t_urls[i]->short_name.empty()); |
| 265 ASSERT_FALSE(t_urls[i]->keyword().empty()); | 269 ASSERT_FALSE(t_urls[i]->keyword().empty()); |
| 266 ASSERT_FALSE(t_urls[i]->favicon_url.host().empty()); | 270 ASSERT_FALSE(t_urls[i]->favicon_url.host().empty()); |
| 267 ASSERT_FALSE(GetHostFromTemplateURLData(*t_urls[i]).empty()); | 271 ASSERT_FALSE(GetHostFromTemplateURLData(*t_urls[i]).empty()); |
| 268 ASSERT_FALSE(t_urls[i]->input_encodings.empty()); | 272 ASSERT_FALSE(t_urls[i]->input_encodings.empty()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 282 EXPECT_GT(t_urls[default_index]->alternate_urls.size(), 1u); | 286 EXPECT_GT(t_urls[default_index]->alternate_urls.size(), 1u); |
| 283 for (size_t i = 0; i < t_urls[default_index]->alternate_urls.size(); ++i) | 287 for (size_t i = 0; i < t_urls[default_index]->alternate_urls.size(); ++i) |
| 284 EXPECT_FALSE(t_urls[default_index]->alternate_urls[i].empty()); | 288 EXPECT_FALSE(t_urls[default_index]->alternate_urls[i].empty()); |
| 285 EXPECT_EQ(SEARCH_ENGINE_GOOGLE, | 289 EXPECT_EQ(SEARCH_ENGINE_GOOGLE, |
| 286 TemplateURLPrepopulateData::GetEngineType( | 290 TemplateURLPrepopulateData::GetEngineType( |
| 287 TemplateURL(*t_urls[default_index]), | 291 TemplateURL(*t_urls[default_index]), |
| 288 SearchTermsData())); | 292 SearchTermsData())); |
| 289 EXPECT_FALSE(t_urls[default_index]->search_terms_replacement_key.empty()); | 293 EXPECT_FALSE(t_urls[default_index]->search_terms_replacement_key.empty()); |
| 290 } | 294 } |
| 291 | 295 |
| 292 TEST(TemplateURLPrepopulateDataTest, GetEngineTypeBasic) { | 296 TEST_F(TemplateURLPrepopulateDataTest, GetEngineTypeBasic) { |
| 293 EXPECT_EQ(SEARCH_ENGINE_OTHER, GetEngineType("http://example.com/")); | 297 EXPECT_EQ(SEARCH_ENGINE_OTHER, GetEngineType("http://example.com/")); |
| 294 EXPECT_EQ(SEARCH_ENGINE_ASK, GetEngineType("http://www.ask.com/")); | 298 EXPECT_EQ(SEARCH_ENGINE_ASK, GetEngineType("http://www.ask.com/")); |
| 295 EXPECT_EQ(SEARCH_ENGINE_OTHER, GetEngineType("http://search.atlas.cz/")); | 299 EXPECT_EQ(SEARCH_ENGINE_OTHER, GetEngineType("http://search.atlas.cz/")); |
| 296 EXPECT_EQ(SEARCH_ENGINE_GOOGLE, GetEngineType("http://www.google.com/")); | 300 EXPECT_EQ(SEARCH_ENGINE_GOOGLE, GetEngineType("http://www.google.com/")); |
| 297 } | 301 } |
| 298 | 302 |
| 299 TEST(TemplateURLPrepopulateDataTest, GetEngineTypeAdvanced) { | 303 TEST_F(TemplateURLPrepopulateDataTest, GetEngineTypeAdvanced) { |
| 300 // Google URLs in different forms. | 304 // Google URLs in different forms. |
| 301 const char* kGoogleURLs[] = { | 305 const char* kGoogleURLs[] = { |
| 302 // Original with google:baseURL: | 306 // Original with google:baseURL: |
| 303 "{google:baseURL}search?q={searchTerms}&{google:RLZ}" | 307 "{google:baseURL}search?q={searchTerms}&{google:RLZ}" |
| 304 "{google:originalQueryForSuggestion}{google:searchFieldtrialParameter}" | 308 "{google:originalQueryForSuggestion}{google:searchFieldtrialParameter}" |
| 305 "sourceid=chrome&ie={inputEncoding}", | 309 "sourceid=chrome&ie={inputEncoding}", |
| 306 // Custom with google.com and reordered query params: | 310 // Custom with google.com and reordered query params: |
| 307 "http://google.com/search?{google:RLZ}{google:originalQueryForSuggestion}" | 311 "http://google.com/search?{google:RLZ}{google:originalQueryForSuggestion}" |
| 308 "{google:searchFieldtrialParameter}" | 312 "{google:searchFieldtrialParameter}" |
| 309 "sourceid=chrome&ie={inputEncoding}&q={searchTerms}", | 313 "sourceid=chrome&ie={inputEncoding}&q={searchTerms}", |
| (...skipping 29 matching lines...) Expand all Loading... |
| 339 EXPECT_EQ(SEARCH_ENGINE_OTHER, GetEngineType("invalid:search:url")); | 343 EXPECT_EQ(SEARCH_ENGINE_OTHER, GetEngineType("invalid:search:url")); |
| 340 | 344 |
| 341 // URL that doesn't look Google-related, but matches a Google base URL | 345 // URL that doesn't look Google-related, but matches a Google base URL |
| 342 // specified on the command line. | 346 // specified on the command line. |
| 343 const std::string foo_url("http://www.foo.com/search?q={searchTerms}"); | 347 const std::string foo_url("http://www.foo.com/search?q={searchTerms}"); |
| 344 EXPECT_EQ(SEARCH_ENGINE_OTHER, GetEngineType(foo_url)); | 348 EXPECT_EQ(SEARCH_ENGINE_OTHER, GetEngineType(foo_url)); |
| 345 CommandLine::ForCurrentProcess()->AppendSwitchASCII(switches::kGoogleBaseURL, | 349 CommandLine::ForCurrentProcess()->AppendSwitchASCII(switches::kGoogleBaseURL, |
| 346 "http://www.foo.com/"); | 350 "http://www.foo.com/"); |
| 347 EXPECT_EQ(SEARCH_ENGINE_GOOGLE, GetEngineType(foo_url)); | 351 EXPECT_EQ(SEARCH_ENGINE_GOOGLE, GetEngineType(foo_url)); |
| 348 } | 352 } |
| OLD | NEW |