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/file_util.h" | 6 #include "base/file_util.h" |
6 #include "base/memory/scoped_vector.h" | 7 #include "base/memory/scoped_vector.h" |
7 #include "base/scoped_temp_dir.h" | 8 #include "base/scoped_temp_dir.h" |
8 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
9 #include "chrome/browser/search_engines/search_terms_data.h" | 10 #include "chrome/browser/search_engines/search_terms_data.h" |
10 #include "chrome/browser/search_engines/template_url.h" | 11 #include "chrome/browser/search_engines/template_url.h" |
11 #include "chrome/browser/search_engines/template_url_service.h" | 12 #include "chrome/browser/search_engines/template_url_service.h" |
12 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" | 13 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" |
| 14 #include "chrome/common/chrome_switches.h" |
13 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
14 #include "chrome/test/base/testing_pref_service.h" | 16 #include "chrome/test/base/testing_pref_service.h" |
15 #include "chrome/test/base/testing_profile.h" | 17 #include "chrome/test/base/testing_profile.h" |
16 #include "grit/generated_resources.h" | 18 #include "grit/generated_resources.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
18 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
19 | 21 |
20 typedef testing::Test TemplateURLPrepopulateDataTest; | 22 typedef testing::Test TemplateURLPrepopulateDataTest; |
21 | 23 |
22 const int kCountryIds[] = { | 24 const int kCountryIds[] = { |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 entry->SetString("encoding", "UTF-8"); | 172 entry->SetString("encoding", "UTF-8"); |
171 overrides->Append(entry->DeepCopy()); | 173 overrides->Append(entry->DeepCopy()); |
172 prefs->SetUserPref(prefs::kSearchProviderOverrides, overrides); | 174 prefs->SetUserPref(prefs::kSearchProviderOverrides, overrides); |
173 | 175 |
174 t_urls.clear(); | 176 t_urls.clear(); |
175 TemplateURLPrepopulateData::GetPrepopulatedEngines(&profile, &t_urls.get(), | 177 TemplateURLPrepopulateData::GetPrepopulatedEngines(&profile, &t_urls.get(), |
176 &default_index); | 178 &default_index); |
177 EXPECT_EQ(2u, t_urls.size()); | 179 EXPECT_EQ(2u, t_urls.size()); |
178 } | 180 } |
179 | 181 |
| 182 // Verifies that built-in search providers are processed correctly. |
| 183 TEST(TemplateURLPrepopulateDataTest, ProvidersFromPrepopulated) { |
| 184 // Use Norway to test some unicode characters. |
| 185 CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 186 switches::kCountry, "NO"); |
| 187 TestingProfile profile; |
| 188 ScopedVector<TemplateURL> t_urls; |
| 189 size_t default_index; |
| 190 TemplateURLPrepopulateData::GetPrepopulatedEngines(&profile, &t_urls.get(), |
| 191 &default_index); |
| 192 ASSERT_EQ(0u, default_index); |
| 193 ASSERT_EQ(5u, t_urls.size()); |
| 194 EXPECT_EQ(ASCIIToUTF16("Google"), t_urls[0]->short_name()); |
| 195 EXPECT_EQ(ASCIIToUTF16("google.com"), t_urls[0]->keyword()); |
| 196 EXPECT_EQ("www.google.com", t_urls[0]->url_ref().GetHost()); |
| 197 EXPECT_EQ("http://www.google.com/favicon.ico", |
| 198 t_urls[0]->favicon_url().spec()); |
| 199 EXPECT_EQ(1u, t_urls[0]->input_encodings().size()); |
| 200 EXPECT_EQ("UTF-8", t_urls[0]->input_encodings()[0]); |
| 201 EXPECT_EQ(1, t_urls[0]->prepopulate_id()); |
| 202 EXPECT_EQ("{google:baseSuggestURL}search?{google:searchFieldtrialParameter}" |
| 203 "client=chrome&q={searchTerms}&" |
| 204 "sugkey={google:suggestAPIKeyParameter}", |
| 205 t_urls[0]->suggestions_url()); |
| 206 EXPECT_EQ("{google:baseURL}webhp?sourceid=chrome-instant&{google:RLZ}" |
| 207 "{google:instantEnabledParameter}ie={inputEncoding}", |
| 208 t_urls[0]->instant_url()); |
| 209 EXPECT_EQ("{google:baseURL}#q={searchTerms}", |
| 210 t_urls[0]->alternate_urls()[0]); |
| 211 EXPECT_EQ("{google:baseURL}search#q={searchTerms}", |
| 212 t_urls[0]->alternate_urls()[1]); |
| 213 EXPECT_EQ("{google:baseURL}webhp#q={searchTerms}", |
| 214 t_urls[0]->alternate_urls()[2]); |
| 215 |
| 216 // Testing unicode characters work correctly. |
| 217 EXPECT_EQ(WideToUTF16(L"ABC S\x00f8k"), t_urls[2]->short_name()); |
| 218 } |
| 219 |
180 TEST(TemplateURLPrepopulateDataTest, GetEngineTypeBasic) { | 220 TEST(TemplateURLPrepopulateDataTest, GetEngineTypeBasic) { |
181 EXPECT_EQ(SEARCH_ENGINE_OTHER, | 221 EXPECT_EQ(SEARCH_ENGINE_OTHER, |
182 TemplateURLPrepopulateData::GetEngineType("http://example.com/")); | 222 TemplateURLPrepopulateData::GetEngineType("http://example.com/")); |
183 EXPECT_EQ(SEARCH_ENGINE_ASK, | 223 EXPECT_EQ(SEARCH_ENGINE_ASK, |
184 TemplateURLPrepopulateData::GetEngineType("http://www.ask.com/")); | 224 TemplateURLPrepopulateData::GetEngineType("http://www.ask.com/")); |
185 EXPECT_EQ(SEARCH_ENGINE_OTHER, | 225 EXPECT_EQ(SEARCH_ENGINE_OTHER, |
186 TemplateURLPrepopulateData::GetEngineType("http://search.atlas.cz/")); | 226 TemplateURLPrepopulateData::GetEngineType("http://search.atlas.cz/")); |
187 EXPECT_EQ(SEARCH_ENGINE_GOOGLE, | 227 EXPECT_EQ(SEARCH_ENGINE_GOOGLE, |
188 TemplateURLPrepopulateData::GetEngineType("http://www.google.com/")); | 228 TemplateURLPrepopulateData::GetEngineType("http://www.google.com/")); |
189 } | 229 } |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 | 294 |
255 TEST(TemplateURLPrepopulateDataTest, GetLogoURLInvalid) { | 295 TEST(TemplateURLPrepopulateDataTest, GetLogoURLInvalid) { |
256 TemplateURLData data; | 296 TemplateURLData data; |
257 data.SetURL("http://invalid:search:url/"); | 297 data.SetURL("http://invalid:search:url/"); |
258 TemplateURL turl(NULL, data); | 298 TemplateURL turl(NULL, data); |
259 GURL logo_url = TemplateURLPrepopulateData::GetLogoURL( | 299 GURL logo_url = TemplateURLPrepopulateData::GetLogoURL( |
260 turl, TemplateURLPrepopulateData::LOGO_100_PERCENT); | 300 turl, TemplateURLPrepopulateData::LOGO_100_PERCENT); |
261 | 301 |
262 EXPECT_TRUE(logo_url.is_empty()); | 302 EXPECT_TRUE(logo_url.is_empty()); |
263 } | 303 } |
OLD | NEW |