| 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/file_util.h" | 5 #include "base/file_util.h" |
| 6 #include "base/memory/scoped_vector.h" | 6 #include "base/memory/scoped_vector.h" |
| 7 #include "base/scoped_temp_dir.h" | 7 #include "base/scoped_temp_dir.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/browser/search_engines/search_terms_data.h" | 9 #include "chrome/browser/search_engines/search_terms_data.h" |
| 10 #include "chrome/browser/search_engines/template_url.h" | 10 #include "chrome/browser/search_engines/template_url.h" |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 TEST(TemplateURLPrepopulateDataTest, ProvidersFromPrefs) { | 94 TEST(TemplateURLPrepopulateDataTest, ProvidersFromPrefs) { |
| 95 TestingProfile profile; | 95 TestingProfile profile; |
| 96 TestingPrefService* prefs = profile.GetTestingPrefService(); | 96 TestingPrefService* prefs = profile.GetTestingPrefService(); |
| 97 prefs->SetUserPref(prefs::kSearchProviderOverridesVersion, | 97 prefs->SetUserPref(prefs::kSearchProviderOverridesVersion, |
| 98 Value::CreateIntegerValue(1)); | 98 Value::CreateIntegerValue(1)); |
| 99 ListValue* overrides = new ListValue; | 99 ListValue* overrides = new ListValue; |
| 100 DictionaryValue* entry = new DictionaryValue; | 100 DictionaryValue* entry = new DictionaryValue; |
| 101 entry->SetString("name", "foo"); | 101 entry->SetString("name", "foo"); |
| 102 entry->SetString("keyword", "fook"); | 102 entry->SetString("keyword", "fook"); |
| 103 entry->SetString("search_url", "http://foo.com/s?q={searchTerms}"); | 103 entry->SetString("search_url", "http://foo.com/s?q={searchTerms}"); |
| 104 entry->SetString("logo_100_percent_url", "http://fol.com/logo.png"); |
| 105 entry->SetString("logo_200_percent_url", "http://fol.com/logo2x.png"); |
| 104 entry->SetString("favicon_url", "http://foi.com/favicon.ico"); | 106 entry->SetString("favicon_url", "http://foi.com/favicon.ico"); |
| 105 entry->SetString("suggest_url", ""); | 107 entry->SetString("suggest_url", ""); |
| 106 entry->SetString("instant_url", ""); | 108 entry->SetString("instant_url", ""); |
| 107 entry->SetString("encoding", "UTF-8"); | 109 entry->SetString("encoding", "UTF-8"); |
| 108 entry->SetInteger("id", 1001); | 110 entry->SetInteger("id", 1001); |
| 109 overrides->Append(entry); | 111 overrides->Append(entry); |
| 110 prefs->SetUserPref(prefs::kSearchProviderOverrides, overrides); | 112 prefs->SetUserPref(prefs::kSearchProviderOverrides, overrides); |
| 111 | 113 |
| 112 int version = TemplateURLPrepopulateData::GetDataVersion(prefs); | 114 int version = TemplateURLPrepopulateData::GetDataVersion(prefs); |
| 113 EXPECT_EQ(1, version); | 115 EXPECT_EQ(1, version); |
| 114 | 116 |
| 115 ScopedVector<TemplateURL> t_urls; | 117 ScopedVector<TemplateURL> t_urls; |
| 116 size_t default_index; | 118 size_t default_index; |
| 117 TemplateURLPrepopulateData::GetPrepopulatedEngines(&profile, &t_urls.get(), | 119 TemplateURLPrepopulateData::GetPrepopulatedEngines(&profile, &t_urls.get(), |
| 118 &default_index); | 120 &default_index); |
| 119 | 121 |
| 120 ASSERT_EQ(1u, t_urls.size()); | 122 ASSERT_EQ(1u, t_urls.size()); |
| 121 EXPECT_EQ(ASCIIToUTF16("foo"), t_urls[0]->short_name()); | 123 EXPECT_EQ(ASCIIToUTF16("foo"), t_urls[0]->short_name()); |
| 122 EXPECT_EQ(ASCIIToUTF16("fook"), t_urls[0]->keyword()); | 124 EXPECT_EQ(ASCIIToUTF16("fook"), t_urls[0]->keyword()); |
| 123 EXPECT_EQ("foo.com", t_urls[0]->url_ref().GetHost()); | 125 EXPECT_EQ("foo.com", t_urls[0]->url_ref().GetHost()); |
| 126 EXPECT_EQ("fol.com", t_urls[0]->logo_100_percent_url().host()); |
| 127 EXPECT_EQ("fol.com", t_urls[0]->logo_200_percent_url().host()); |
| 124 EXPECT_EQ("foi.com", t_urls[0]->favicon_url().host()); | 128 EXPECT_EQ("foi.com", t_urls[0]->favicon_url().host()); |
| 125 EXPECT_EQ(1u, t_urls[0]->input_encodings().size()); | 129 EXPECT_EQ(1u, t_urls[0]->input_encodings().size()); |
| 126 EXPECT_EQ(1001, t_urls[0]->prepopulate_id()); | 130 EXPECT_EQ(1001, t_urls[0]->prepopulate_id()); |
| 127 } | 131 } |
| 128 | 132 |
| 129 TEST(TemplateURLPrepopulateDataTest, GetEngineTypeBasic) { | 133 TEST(TemplateURLPrepopulateDataTest, GetEngineTypeBasic) { |
| 130 EXPECT_EQ(SEARCH_ENGINE_OTHER, | 134 EXPECT_EQ(SEARCH_ENGINE_OTHER, |
| 131 TemplateURLPrepopulateData::GetEngineType("http://example.com/")); | 135 TemplateURLPrepopulateData::GetEngineType("http://example.com/")); |
| 132 EXPECT_EQ(SEARCH_ENGINE_ASK, | 136 EXPECT_EQ(SEARCH_ENGINE_ASK, |
| 133 TemplateURLPrepopulateData::GetEngineType("http://www.ask.com/")); | 137 TemplateURLPrepopulateData::GetEngineType("http://www.ask.com/")); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 std::string kNigmaURL = "http://www.nigma.ru/?s={searchTerms}&arg1=value1"; | 173 std::string kNigmaURL = "http://www.nigma.ru/?s={searchTerms}&arg1=value1"; |
| 170 EXPECT_EQ(SEARCH_ENGINE_NIGMA, | 174 EXPECT_EQ(SEARCH_ENGINE_NIGMA, |
| 171 TemplateURLPrepopulateData::GetEngineType(kNigmaURL)); | 175 TemplateURLPrepopulateData::GetEngineType(kNigmaURL)); |
| 172 // Search URL for which no prepopulated search provider exists. | 176 // Search URL for which no prepopulated search provider exists. |
| 173 std::string kExampleSearchURL = "http://example.net/search?q={searchTerms}"; | 177 std::string kExampleSearchURL = "http://example.net/search?q={searchTerms}"; |
| 174 EXPECT_EQ(SEARCH_ENGINE_OTHER, | 178 EXPECT_EQ(SEARCH_ENGINE_OTHER, |
| 175 TemplateURLPrepopulateData::GetEngineType(kExampleSearchURL)); | 179 TemplateURLPrepopulateData::GetEngineType(kExampleSearchURL)); |
| 176 EXPECT_EQ(SEARCH_ENGINE_OTHER, | 180 EXPECT_EQ(SEARCH_ENGINE_OTHER, |
| 177 TemplateURLPrepopulateData::GetEngineType("invalid:search:url")); | 181 TemplateURLPrepopulateData::GetEngineType("invalid:search:url")); |
| 178 } | 182 } |
| OLD | NEW |