OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/scoped_temp_dir.h" | 6 #include "base/scoped_temp_dir.h" |
7 #include "base/scoped_vector.h" | 7 #include "base/scoped_vector.h" |
8 #include "chrome/browser/prefs/pref_service.h" | |
9 #include "chrome/browser/search_engines/search_engine_type.h" | 8 #include "chrome/browser/search_engines/search_engine_type.h" |
10 #include "chrome/browser/search_engines/search_terms_data.h" | 9 #include "chrome/browser/search_engines/search_terms_data.h" |
11 #include "chrome/browser/search_engines/template_url.h" | 10 #include "chrome/browser/search_engines/template_url.h" |
12 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" | 11 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" |
13 #include "chrome/browser/search_engines/template_url_model.h" | 12 #include "chrome/browser/search_engines/template_url_model.h" |
14 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
| 14 #include "chrome/test/testing_pref_service.h" |
15 #include "chrome/test/testing_profile.h" | 15 #include "chrome/test/testing_profile.h" |
16 #include "grit/theme_resources.h" | 16 #include "grit/theme_resources.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
18 | 18 |
19 typedef testing::Test TemplateURLPrepopulateDataTest; | 19 typedef testing::Test TemplateURLPrepopulateDataTest; |
20 | 20 |
21 const int kCountryIds[] = { | 21 const int kCountryIds[] = { |
22 'A'<<8|'D', 'A'<<8|'E', 'A'<<8|'F', 'A'<<8|'G', 'A'<<8|'I', | 22 'A'<<8|'D', 'A'<<8|'E', 'A'<<8|'F', 'A'<<8|'G', 'A'<<8|'I', |
23 'A'<<8|'L', 'A'<<8|'M', 'A'<<8|'N', 'A'<<8|'O', 'A'<<8|'Q', | 23 'A'<<8|'L', 'A'<<8|'M', 'A'<<8|'N', 'A'<<8|'O', 'A'<<8|'Q', |
24 'A'<<8|'R', 'A'<<8|'S', 'A'<<8|'T', 'A'<<8|'U', 'A'<<8|'W', | 24 'A'<<8|'R', 'A'<<8|'S', 'A'<<8|'T', 'A'<<8|'U', 'A'<<8|'W', |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 ASSERT_TRUE(unique_ids.find(urls[turl_i]->prepopulate_id()) == | 84 ASSERT_TRUE(unique_ids.find(urls[turl_i]->prepopulate_id()) == |
85 unique_ids.end()); | 85 unique_ids.end()); |
86 unique_ids.insert(urls[turl_i]->prepopulate_id()); | 86 unique_ids.insert(urls[turl_i]->prepopulate_id()); |
87 } | 87 } |
88 } | 88 } |
89 } | 89 } |
90 | 90 |
91 // Verifies that default search providers from the preferences file | 91 // Verifies that default search providers from the preferences file |
92 // override the built-in ones. | 92 // override the built-in ones. |
93 TEST_F(TemplateURLPrepopulateDataTest, ProvidersFromPrefs) { | 93 TEST_F(TemplateURLPrepopulateDataTest, ProvidersFromPrefs) { |
94 const char pref_data[] = | 94 TestingPrefService prefs; |
95 "{ " | 95 TemplateURLPrepopulateData::RegisterUserPrefs(&prefs); |
96 " \"search_provider_overrides_version\":1," | 96 prefs.SetUserPref(prefs::kSearchProviderOverridesVersion, |
97 " \"search_provider_overrides\": [" | 97 Value::CreateIntegerValue(1)); |
98 " { \"name\":\"foo\"," | 98 ListValue* overrides = new ListValue; |
99 " \"keyword\":\"fook\"," | 99 DictionaryValue* entry = new DictionaryValue; |
100 " \"search_url\":\"http://foo.com/s?q={searchTerms}\"," | 100 entry->SetString("name", "foo"); |
101 " \"favicon_url\":\"http://foi.com/favicon.ico\"," | 101 entry->SetString("keyword", "fook"); |
102 " \"suggest_url\":\"\"," | 102 entry->SetString("search_url", "http://foo.com/s?q={searchTerms}"); |
103 " \"instant_url\":\"\"," | 103 entry->SetString("favicon_url", "http://foi.com/favicon.ico"); |
104 " \"encoding\":\"UTF-8\"," | 104 entry->SetString("suggest_url", ""); |
105 " \"search_engine_type\":1," | 105 entry->SetString("instant_url", ""); |
106 " \"logo_id\":0," | 106 entry->SetString("encoding", "UTF-8"); |
107 " \"id\":1001" | 107 entry->SetInteger("search_engine_type", 1); |
108 " }" | 108 entry->SetInteger("logo_id", 0); |
109 " ]" | 109 entry->SetInteger("id", 1001); |
110 "}"; | 110 overrides->Append(entry); |
| 111 prefs.SetUserPref(prefs::kSearchProviderOverrides, overrides); |
111 | 112 |
112 ScopedTempDir temp_dir; | 113 int version = TemplateURLPrepopulateData::GetDataVersion(&prefs); |
113 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | |
114 FilePath preferences_file = temp_dir.path().AppendASCII("Preferences"); | |
115 file_util::WriteFile(preferences_file, pref_data, sizeof(pref_data)); | |
116 | |
117 scoped_ptr<PrefService> prefs( | |
118 PrefService::CreateUserPrefService(preferences_file)); | |
119 TemplateURLPrepopulateData::RegisterUserPrefs(prefs.get()); | |
120 | |
121 int version = TemplateURLPrepopulateData::GetDataVersion(prefs.get()); | |
122 EXPECT_EQ(1, version); | 114 EXPECT_EQ(1, version); |
123 | 115 |
124 ScopedVector<TemplateURL> t_urls; | 116 ScopedVector<TemplateURL> t_urls; |
125 size_t default_index; | 117 size_t default_index; |
126 TemplateURLPrepopulateData::GetPrepopulatedEngines( | 118 TemplateURLPrepopulateData::GetPrepopulatedEngines( |
127 prefs.get(), &(t_urls.get()), &default_index); | 119 &prefs, &(t_urls.get()), &default_index); |
128 | 120 |
129 ASSERT_EQ(1u, t_urls.size()); | 121 ASSERT_EQ(1u, t_urls.size()); |
130 EXPECT_EQ(L"foo", t_urls[0]->short_name()); | 122 EXPECT_EQ(L"foo", t_urls[0]->short_name()); |
131 EXPECT_EQ(L"fook", t_urls[0]->keyword()); | 123 EXPECT_EQ(L"fook", t_urls[0]->keyword()); |
132 EXPECT_EQ("foo.com", t_urls[0]->url()->GetHost()); | 124 EXPECT_EQ("foo.com", t_urls[0]->url()->GetHost()); |
133 EXPECT_EQ("foi.com", t_urls[0]->GetFavIconURL().host()); | 125 EXPECT_EQ("foi.com", t_urls[0]->GetFavIconURL().host()); |
134 EXPECT_EQ(1u, t_urls[0]->input_encodings().size()); | 126 EXPECT_EQ(1u, t_urls[0]->input_encodings().size()); |
135 EXPECT_EQ(1001, t_urls[0]->prepopulate_id()); | 127 EXPECT_EQ(1001, t_urls[0]->prepopulate_id()); |
136 EXPECT_EQ(SEARCH_ENGINE_GOOGLE, t_urls[0]->search_engine_type()); | 128 EXPECT_EQ(SEARCH_ENGINE_GOOGLE, t_urls[0]->search_engine_type()); |
137 EXPECT_EQ(0, t_urls[0]->logo_id()); | 129 EXPECT_EQ(0, t_urls[0]->logo_id()); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 EXPECT_EQ(kNoSearchEngineLogo, | 177 EXPECT_EQ(kNoSearchEngineLogo, |
186 TemplateURLPrepopulateData::GetSearchEngineLogo(bad_engine)); | 178 TemplateURLPrepopulateData::GetSearchEngineLogo(bad_engine)); |
187 GURL engine_with_logo("http://www.ask.com/"); | 179 GURL engine_with_logo("http://www.ask.com/"); |
188 EXPECT_EQ(IDR_SEARCH_ENGINE_LOGO_ASK, | 180 EXPECT_EQ(IDR_SEARCH_ENGINE_LOGO_ASK, |
189 TemplateURLPrepopulateData::GetSearchEngineLogo(engine_with_logo)); | 181 TemplateURLPrepopulateData::GetSearchEngineLogo(engine_with_logo)); |
190 GURL engine_no_logo("http://araby.com/"); | 182 GURL engine_no_logo("http://araby.com/"); |
191 EXPECT_EQ(kNoSearchEngineLogo, | 183 EXPECT_EQ(kNoSearchEngineLogo, |
192 TemplateURLPrepopulateData::GetSearchEngineLogo(engine_no_logo)); | 184 TemplateURLPrepopulateData::GetSearchEngineLogo(engine_no_logo)); |
193 | 185 |
194 } | 186 } |
OLD | NEW |