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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 'Y'<<8|'T', 'Z'<<8|'A', 'Z'<<8|'M', 'Z'<<8|'W', -1 }; | 71 'Y'<<8|'T', 'Z'<<8|'A', 'Z'<<8|'M', 'Z'<<8|'W', -1 }; |
72 | 72 |
73 // Verifies the set of prepopulate data doesn't contain entries with duplicate | 73 // Verifies the set of prepopulate data doesn't contain entries with duplicate |
74 // ids. | 74 // ids. |
75 TEST(TemplateURLPrepopulateDataTest, UniqueIDs) { | 75 TEST(TemplateURLPrepopulateDataTest, UniqueIDs) { |
76 TestingProfile profile; | 76 TestingProfile profile; |
77 for (size_t i = 0; i < arraysize(kCountryIds); ++i) { | 77 for (size_t i = 0; i < arraysize(kCountryIds); ++i) { |
78 profile.GetPrefs()->SetInteger(prefs::kCountryIDAtInstall, kCountryIds[i]); | 78 profile.GetPrefs()->SetInteger(prefs::kCountryIDAtInstall, kCountryIds[i]); |
79 ScopedVector<TemplateURL> urls; | 79 ScopedVector<TemplateURL> urls; |
80 size_t default_index; | 80 size_t default_index; |
81 TemplateURLPrepopulateData::GetPrepopulatedEngines(profile.GetPrefs(), | 81 TemplateURLPrepopulateData::GetPrepopulatedEngines(&profile, &urls.get(), |
82 &urls.get(), &default_index); | 82 &default_index); |
83 std::set<int> unique_ids; | 83 std::set<int> unique_ids; |
84 for (size_t turl_i = 0; turl_i < urls.size(); ++turl_i) { | 84 for (size_t turl_i = 0; turl_i < urls.size(); ++turl_i) { |
85 ASSERT_TRUE(unique_ids.find(urls[turl_i]->prepopulate_id()) == | 85 ASSERT_TRUE(unique_ids.find(urls[turl_i]->prepopulate_id()) == |
86 unique_ids.end()); | 86 unique_ids.end()); |
87 unique_ids.insert(urls[turl_i]->prepopulate_id()); | 87 unique_ids.insert(urls[turl_i]->prepopulate_id()); |
88 } | 88 } |
89 } | 89 } |
90 } | 90 } |
91 | 91 |
92 // Verifies that default search providers from the preferences file | 92 // Verifies that default search providers from the preferences file |
(...skipping 14 matching lines...) Expand all Loading... |
107 entry->SetString("encoding", "UTF-8"); | 107 entry->SetString("encoding", "UTF-8"); |
108 entry->SetInteger("id", 1001); | 108 entry->SetInteger("id", 1001); |
109 overrides->Append(entry); | 109 overrides->Append(entry); |
110 prefs->SetUserPref(prefs::kSearchProviderOverrides, overrides); | 110 prefs->SetUserPref(prefs::kSearchProviderOverrides, overrides); |
111 | 111 |
112 int version = TemplateURLPrepopulateData::GetDataVersion(prefs); | 112 int version = TemplateURLPrepopulateData::GetDataVersion(prefs); |
113 EXPECT_EQ(1, version); | 113 EXPECT_EQ(1, version); |
114 | 114 |
115 ScopedVector<TemplateURL> t_urls; | 115 ScopedVector<TemplateURL> t_urls; |
116 size_t default_index; | 116 size_t default_index; |
117 TemplateURLPrepopulateData::GetPrepopulatedEngines(prefs, &t_urls.get(), | 117 TemplateURLPrepopulateData::GetPrepopulatedEngines(&profile, &t_urls.get(), |
118 &default_index); | 118 &default_index); |
119 | 119 |
120 ASSERT_EQ(1u, t_urls.size()); | 120 ASSERT_EQ(1u, t_urls.size()); |
121 EXPECT_EQ(ASCIIToUTF16("foo"), t_urls[0]->short_name()); | 121 EXPECT_EQ(ASCIIToUTF16("foo"), t_urls[0]->short_name()); |
122 EXPECT_EQ(ASCIIToUTF16("fook"), t_urls[0]->keyword()); | 122 EXPECT_EQ(ASCIIToUTF16("fook"), t_urls[0]->keyword()); |
123 EXPECT_EQ("foo.com", t_urls[0]->url_ref().GetHost()); | 123 EXPECT_EQ("foo.com", t_urls[0]->url_ref().GetHost()); |
124 EXPECT_EQ("foi.com", t_urls[0]->favicon_url().host()); | 124 EXPECT_EQ("foi.com", t_urls[0]->favicon_url().host()); |
125 EXPECT_EQ(1u, t_urls[0]->input_encodings().size()); | 125 EXPECT_EQ(1u, t_urls[0]->input_encodings().size()); |
126 EXPECT_EQ(1001, t_urls[0]->prepopulate_id()); | 126 EXPECT_EQ(1001, t_urls[0]->prepopulate_id()); |
127 } | 127 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 EXPECT_EQ(SEARCH_ENGINE_YAHOO, | 181 EXPECT_EQ(SEARCH_ENGINE_YAHOO, |
182 TemplateURLPrepopulateData::GetEngineType(kYahooURLs[i])); | 182 TemplateURLPrepopulateData::GetEngineType(kYahooURLs[i])); |
183 } | 183 } |
184 // Search URL for which no prepopulated search provider exists. | 184 // Search URL for which no prepopulated search provider exists. |
185 std::string kExampleSearchURL = "http://example.net/search?q={searchTerms}"; | 185 std::string kExampleSearchURL = "http://example.net/search?q={searchTerms}"; |
186 EXPECT_EQ(SEARCH_ENGINE_OTHER, | 186 EXPECT_EQ(SEARCH_ENGINE_OTHER, |
187 TemplateURLPrepopulateData::GetEngineType(kExampleSearchURL)); | 187 TemplateURLPrepopulateData::GetEngineType(kExampleSearchURL)); |
188 EXPECT_EQ(SEARCH_ENGINE_OTHER, | 188 EXPECT_EQ(SEARCH_ENGINE_OTHER, |
189 TemplateURLPrepopulateData::GetEngineType("invalid:search:url")); | 189 TemplateURLPrepopulateData::GetEngineType("invalid:search:url")); |
190 } | 190 } |
OLD | NEW |