OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/sync/test/integration/search_engines_helper.h" | 5 #include "chrome/browser/sync/test/integration/search_engines_helper.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 } | 27 } |
28 | 28 |
29 TemplateURLService* GetVerifierService() { | 29 TemplateURLService* GetVerifierService() { |
30 return TemplateURLServiceFactory::GetForProfile(test()->verifier()); | 30 return TemplateURLServiceFactory::GetForProfile(test()->verifier()); |
31 } | 31 } |
32 | 32 |
33 GUIDToTURLMap CreateGUIDToTURLMap(TemplateURLService* service) { | 33 GUIDToTURLMap CreateGUIDToTURLMap(TemplateURLService* service) { |
34 CHECK(service); | 34 CHECK(service); |
35 | 35 |
36 GUIDToTURLMap map; | 36 GUIDToTURLMap map; |
37 std::vector<const TemplateURL*> turls = service->GetTemplateURLs(); | 37 TemplateURLService::TemplateURLVector turls = service->GetTemplateURLs(); |
38 for (std::vector<const TemplateURL*>::iterator it = turls.begin(); | 38 for (TemplateURLService::TemplateURLVector::iterator it = turls.begin(); |
39 it != turls.end(); ++it) { | 39 it != turls.end(); ++it) { |
40 CHECK(*it); | 40 CHECK(*it); |
41 CHECK(map.find((*it)->sync_guid()) == map.end()); | 41 CHECK(map.find((*it)->sync_guid()) == map.end()); |
42 map[(*it)->sync_guid()] = *it; | 42 map[(*it)->sync_guid()] = *it; |
43 } | 43 } |
44 | 44 |
45 return map; | 45 return map; |
46 } | 46 } |
47 | 47 |
48 std::string GetTURLInfoString(const TemplateURL* turl) { | 48 std::string GetTURLInfoString(const TemplateURL* turl) { |
(...skipping 28 matching lines...) Expand all Loading... |
77 return result; | 77 return result; |
78 } | 78 } |
79 | 79 |
80 bool ServiceMatchesVerifier(int profile) { | 80 bool ServiceMatchesVerifier(int profile) { |
81 TemplateURLService* verifier = GetVerifierService(); | 81 TemplateURLService* verifier = GetVerifierService(); |
82 TemplateURLService* other = GetServiceForProfile(profile); | 82 TemplateURLService* other = GetServiceForProfile(profile); |
83 | 83 |
84 CHECK(verifier); | 84 CHECK(verifier); |
85 CHECK(other); | 85 CHECK(other); |
86 | 86 |
87 std::vector<const TemplateURL*> verifier_turls = verifier->GetTemplateURLs(); | 87 TemplateURLService::TemplateURLVector verifier_turls = |
| 88 verifier->GetTemplateURLs(); |
88 if (verifier_turls.size() != other->GetTemplateURLs().size()) { | 89 if (verifier_turls.size() != other->GetTemplateURLs().size()) { |
89 LOG(ERROR) << "Verifier and other service have a different count of TURLs: " | 90 LOG(ERROR) << "Verifier and other service have a different count of TURLs: " |
90 << verifier_turls.size() << " vs " | 91 << verifier_turls.size() << " vs " |
91 << other->GetTemplateURLs().size() << " respectively."; | 92 << other->GetTemplateURLs().size() << " respectively."; |
92 return false; | 93 return false; |
93 } | 94 } |
94 | 95 |
95 for (size_t i = 0; i < verifier_turls.size(); ++i) { | 96 for (size_t i = 0; i < verifier_turls.size(); ++i) { |
96 const TemplateURL* verifier_turl = verifier_turls.at(i); | 97 const TemplateURL* verifier_turl = verifier_turls.at(i); |
97 CHECK(verifier_turl); | 98 CHECK(verifier_turl); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 return true; | 172 return true; |
172 } | 173 } |
173 | 174 |
174 // Convenience helper for consistently generating the same keyword for a given | 175 // Convenience helper for consistently generating the same keyword for a given |
175 // seed. | 176 // seed. |
176 string16 CreateKeyword(int seed) { | 177 string16 CreateKeyword(int seed) { |
177 return ASCIIToUTF16(base::StringPrintf("test%d", seed)); | 178 return ASCIIToUTF16(base::StringPrintf("test%d", seed)); |
178 } | 179 } |
179 | 180 |
180 TemplateURL* CreateTestTemplateURL(int seed) { | 181 TemplateURL* CreateTestTemplateURL(int seed) { |
| 182 return CreateTestTemplateURL(seed, CreateKeyword(seed), |
| 183 base::StringPrintf("0000-0000-0000-%04d", seed)); |
| 184 } |
| 185 |
| 186 TemplateURL* CreateTestTemplateURL(int seed, |
| 187 const string16& keyword, |
| 188 const std::string& sync_guid) { |
| 189 return CreateTestTemplateURL(seed, |
| 190 base::StringPrintf("http://www.test%d.com/", seed), keyword, sync_guid); |
| 191 } |
| 192 |
| 193 TemplateURL* CreateTestTemplateURL(int seed, |
| 194 const std::string& url, |
| 195 const string16& keyword, |
| 196 const std::string& sync_guid) { |
181 TemplateURL* turl = new TemplateURL(); | 197 TemplateURL* turl = new TemplateURL(); |
182 turl->SetURL(base::StringPrintf("http://www.test%d.com/", seed), 0, 0); | 198 turl->set_short_name(CreateKeyword(seed)); |
183 turl->set_keyword(CreateKeyword(seed)); | 199 turl->set_keyword(keyword); |
184 turl->set_short_name(ASCIIToUTF16(base::StringPrintf("test%d", seed))); | |
185 turl->set_safe_for_autoreplace(true); | 200 turl->set_safe_for_autoreplace(true); |
186 GURL favicon_url("http://favicon.url"); | |
187 turl->SetFaviconURL(favicon_url); | |
188 turl->set_date_created(base::Time::FromTimeT(100)); | 201 turl->set_date_created(base::Time::FromTimeT(100)); |
189 turl->set_last_modified(base::Time::FromTimeT(100)); | 202 turl->set_last_modified(base::Time::FromTimeT(100)); |
190 turl->SetPrepopulateId(999999); | 203 turl->SetPrepopulateId(999999); |
191 turl->set_sync_guid(base::StringPrintf("0000-0000-0000-%04d", seed)); | 204 turl->set_sync_guid(sync_guid); |
| 205 turl->SetURL(url, 0, 0); |
| 206 turl->SetFaviconURL(GURL("http://favicon.url")); |
192 return turl; | 207 return turl; |
193 } | 208 } |
194 | 209 |
195 void AddSearchEngine(int profile, int seed) { | 210 void AddSearchEngine(int profile, int seed) { |
196 GetServiceForProfile(profile)->Add(CreateTestTemplateURL(seed)); | 211 GetServiceForProfile(profile)->Add(CreateTestTemplateURL(seed)); |
197 if (test()->use_verifier()) | 212 if (test()->use_verifier()) |
198 GetVerifierService()->Add(CreateTestTemplateURL(seed)); | 213 GetVerifierService()->Add(CreateTestTemplateURL(seed)); |
199 } | 214 } |
200 | 215 |
201 void EditSearchEngine(int profile, | 216 void EditSearchEngine(int profile, |
202 const std::string& keyword, | 217 const string16& keyword, |
203 const std::string& short_name, | 218 const string16& short_name, |
204 const std::string& new_keyword, | 219 const string16& new_keyword, |
205 const std::string& url) { | 220 const std::string& url) { |
206 const TemplateURL* turl = GetServiceForProfile(profile)-> | 221 DCHECK(!url.empty()); |
207 GetTemplateURLForKeyword(ASCIIToUTF16(keyword)); | 222 const TemplateURL* turl = |
| 223 GetServiceForProfile(profile)->GetTemplateURLForKeyword(keyword); |
208 EXPECT_TRUE(turl); | 224 EXPECT_TRUE(turl); |
209 GetServiceForProfile(profile)->ResetTemplateURL(turl, | 225 ASSERT_FALSE(new_keyword.empty()); |
210 ASCIIToUTF16(short_name), | 226 GetServiceForProfile(profile)->ResetTemplateURL(turl, short_name, new_keyword, |
211 ASCIIToUTF16(new_keyword), | |
212 url); | 227 url); |
213 // Make sure we do the same on the verifier. | 228 // Make sure we do the same on the verifier. |
214 if (test()->use_verifier()) { | 229 if (test()->use_verifier()) { |
215 const TemplateURL* verifier_turl = | 230 const TemplateURL* verifier_turl = |
216 GetVerifierService()->GetTemplateURLForKeyword(ASCIIToUTF16(keyword)); | 231 GetVerifierService()->GetTemplateURLForKeyword(keyword); |
217 EXPECT_TRUE(verifier_turl); | 232 EXPECT_TRUE(verifier_turl); |
218 GetVerifierService()->ResetTemplateURL(verifier_turl, | 233 GetVerifierService()->ResetTemplateURL(verifier_turl, short_name, |
219 ASCIIToUTF16(short_name), | 234 new_keyword, url); |
220 ASCIIToUTF16(new_keyword), | |
221 url); | |
222 } | 235 } |
223 } | 236 } |
224 | 237 |
225 void DeleteSearchEngineByKeyword(int profile, const string16 keyword) { | 238 void DeleteSearchEngineByKeyword(int profile, const string16& keyword) { |
226 const TemplateURL* turl = GetServiceForProfile(profile)-> | 239 const TemplateURL* turl = |
227 GetTemplateURLForKeyword(keyword); | 240 GetServiceForProfile(profile)->GetTemplateURLForKeyword(keyword); |
228 EXPECT_TRUE(turl); | 241 EXPECT_TRUE(turl); |
229 GetServiceForProfile(profile)->Remove(turl); | 242 GetServiceForProfile(profile)->Remove(turl); |
230 // Make sure we do the same on the verifier. | 243 // Make sure we do the same on the verifier. |
231 if (test()->use_verifier()) { | 244 if (test()->use_verifier()) { |
232 const TemplateURL* verifier_turl = | 245 const TemplateURL* verifier_turl = |
233 GetVerifierService()->GetTemplateURLForKeyword(keyword); | 246 GetVerifierService()->GetTemplateURLForKeyword(keyword); |
234 EXPECT_TRUE(verifier_turl); | 247 EXPECT_TRUE(verifier_turl); |
235 GetVerifierService()->Remove(verifier_turl); | 248 GetVerifierService()->Remove(verifier_turl); |
236 } | 249 } |
237 } | 250 } |
238 | 251 |
239 void DeleteSearchEngineBySeed(int profile, int seed) { | 252 void DeleteSearchEngineBySeed(int profile, int seed) { |
240 DeleteSearchEngineByKeyword(profile, CreateKeyword(seed)); | 253 DeleteSearchEngineByKeyword(profile, CreateKeyword(seed)); |
241 } | 254 } |
242 | 255 |
243 void ChangeDefaultSearchProvider(int profile, int seed) { | 256 void ChangeDefaultSearchProvider(int profile, int seed) { |
244 TemplateURLService* service = GetServiceForProfile(profile); | 257 TemplateURLService* service = GetServiceForProfile(profile); |
245 ASSERT_TRUE(service); | 258 ASSERT_TRUE(service); |
246 const TemplateURL* turl = service->GetTemplateURLForKeyword( | 259 const TemplateURL* turl = |
247 CreateKeyword(seed)); | 260 service->GetTemplateURLForKeyword(CreateKeyword(seed)); |
248 ASSERT_TRUE(turl); | 261 ASSERT_TRUE(turl); |
249 service->SetDefaultSearchProvider(turl); | 262 service->SetDefaultSearchProvider(turl); |
250 if (test()->use_verifier()) { | 263 if (test()->use_verifier()) { |
251 const TemplateURL* verifier_turl = | 264 const TemplateURL* verifier_turl = |
252 GetVerifierService()->GetTemplateURLForKeyword(CreateKeyword(seed)); | 265 GetVerifierService()->GetTemplateURLForKeyword(CreateKeyword(seed)); |
253 ASSERT_TRUE(verifier_turl); | 266 ASSERT_TRUE(verifier_turl); |
254 GetVerifierService()->SetDefaultSearchProvider(verifier_turl); | 267 GetVerifierService()->SetDefaultSearchProvider(verifier_turl); |
255 } | 268 } |
256 } | 269 } |
257 | 270 |
258 } // namespace search_engines_helper | 271 } // namespace search_engines_helper |
OLD | NEW |