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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 std::vector<const TemplateURL*> verifier_turls = verifier->GetTemplateURLs(); |
88 if (verifier_turls.size() != other->GetTemplateURLs().size()) { | 88 if (verifier_turls.size() != other->GetTemplateURLs().size()) { |
89 LOG(ERROR) << "verifier and other service have a different count of TURLs: " | 89 LOG(ERROR) << "Verifier and other service have a different count of TURLs: " |
90 << verifier_turls.size() << " vs " | 90 << verifier_turls.size() << " vs " |
91 << other->GetTemplateURLs().size() << " respectively."; | 91 << other->GetTemplateURLs().size() << " respectively."; |
92 return false; | 92 return false; |
93 } | 93 } |
94 | 94 |
95 for (size_t i = 0; i < verifier_turls.size(); ++i) { | 95 for (size_t i = 0; i < verifier_turls.size(); ++i) { |
96 const TemplateURL* verifier_turl = verifier_turls.at(i); | 96 const TemplateURL* verifier_turl = verifier_turls.at(i); |
97 CHECK(verifier_turl); | 97 CHECK(verifier_turl); |
98 const TemplateURL* other_turl = other->GetTemplateURLForKeyword( | 98 const TemplateURL* other_turl = other->GetTemplateURLForKeyword( |
99 verifier_turl->keyword()); | 99 verifier_turl->keyword()); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 } else { | 149 } else { |
150 LOG(INFO) << "A had default with URL: " << default_a->url()->url() | 150 LOG(INFO) << "A had default with URL: " << default_a->url()->url() |
151 << " and keyword: " << default_a->keyword(); | 151 << " and keyword: " << default_a->keyword(); |
152 } | 152 } |
153 | 153 |
154 return true; | 154 return true; |
155 } | 155 } |
156 | 156 |
157 bool AllServicesMatch() { | 157 bool AllServicesMatch() { |
158 // Use 0 as the baseline. | 158 // Use 0 as the baseline. |
159 if (!ServiceMatchesVerifier(0)) | 159 if (!ServiceMatchesVerifier(0)) { |
| 160 LOG(ERROR) << "TemplateURLService 0 does not match verifier."; |
160 return false; | 161 return false; |
| 162 } |
161 | 163 |
162 for (int it = 0; it < test()->num_clients(); ++it) { | 164 for (int it = 0; it < test()->num_clients(); ++it) { |
163 if (!ServicesMatch(0, it)) { | 165 if (!ServicesMatch(0, it)) { |
164 LOG(ERROR) << "TemplateURLService " << it << " does not match with " | 166 LOG(ERROR) << "TemplateURLService " << it << " does not match with " |
165 << "service 0."; | 167 << "service 0."; |
166 return false; | 168 return false; |
167 } | 169 } |
168 } | 170 } |
169 return true; | 171 return true; |
170 } | 172 } |
(...skipping 13 matching lines...) Expand all Loading... |
184 GURL favicon_url("http://favicon.url"); | 186 GURL favicon_url("http://favicon.url"); |
185 turl->SetFaviconURL(favicon_url); | 187 turl->SetFaviconURL(favicon_url); |
186 turl->set_date_created(base::Time::FromTimeT(100)); | 188 turl->set_date_created(base::Time::FromTimeT(100)); |
187 turl->set_last_modified(base::Time::FromTimeT(100)); | 189 turl->set_last_modified(base::Time::FromTimeT(100)); |
188 turl->SetPrepopulateId(999999); | 190 turl->SetPrepopulateId(999999); |
189 turl->set_sync_guid(base::StringPrintf("0000-0000-0000-%04d", seed)); | 191 turl->set_sync_guid(base::StringPrintf("0000-0000-0000-%04d", seed)); |
190 return turl; | 192 return turl; |
191 } | 193 } |
192 | 194 |
193 void AddSearchEngine(int profile, int seed) { | 195 void AddSearchEngine(int profile, int seed) { |
194 GetServiceForProfile(profile)->Add(CreateTestTemplateURL(seed)); | 196 if (profile != -1) |
| 197 GetServiceForProfile(profile)->Add(CreateTestTemplateURL(seed)); |
195 if (test()->use_verifier()) | 198 if (test()->use_verifier()) |
196 GetVerifierService()->Add(CreateTestTemplateURL(seed)); | 199 GetVerifierService()->Add(CreateTestTemplateURL(seed)); |
197 } | 200 } |
198 | 201 |
199 void EditSearchEngine(int profile, | 202 void EditSearchEngine(int profile, |
200 const std::string& keyword, | 203 const std::string& keyword, |
201 const std::string& short_name, | 204 const std::string& short_name, |
202 const std::string& new_keyword, | 205 const std::string& new_keyword, |
203 const std::string& url) { | 206 const std::string& url) { |
204 const TemplateURL* turl = GetServiceForProfile(profile)-> | 207 if (profile != -1) { |
| 208 const TemplateURL* turl = GetServiceForProfile(profile)-> |
205 GetTemplateURLForKeyword(ASCIIToUTF16(keyword)); | 209 GetTemplateURLForKeyword(ASCIIToUTF16(keyword)); |
206 EXPECT_TRUE(turl); | 210 EXPECT_TRUE(turl); |
207 GetServiceForProfile(profile)->ResetTemplateURL(turl, | 211 GetServiceForProfile(profile)->ResetTemplateURL(turl, |
208 ASCIIToUTF16(short_name), | 212 ASCIIToUTF16(short_name), |
209 ASCIIToUTF16(new_keyword), | 213 ASCIIToUTF16(new_keyword), |
210 url); | 214 url); |
| 215 } |
211 // Make sure we do the same on the verifier. | 216 // Make sure we do the same on the verifier. |
212 if (test()->use_verifier()) { | 217 if (test()->use_verifier()) { |
213 const TemplateURL* verifier_turl = | 218 const TemplateURL* verifier_turl = |
214 GetVerifierService()->GetTemplateURLForKeyword(ASCIIToUTF16(keyword)); | 219 GetVerifierService()->GetTemplateURLForKeyword(ASCIIToUTF16(keyword)); |
215 EXPECT_TRUE(verifier_turl); | 220 EXPECT_TRUE(verifier_turl); |
216 GetVerifierService()->ResetTemplateURL(verifier_turl, | 221 GetVerifierService()->ResetTemplateURL(verifier_turl, |
217 ASCIIToUTF16(short_name), | 222 ASCIIToUTF16(short_name), |
218 ASCIIToUTF16(new_keyword), | 223 ASCIIToUTF16(new_keyword), |
219 url); | 224 url); |
220 } | 225 } |
221 } | 226 } |
222 | 227 |
223 void DeleteSearchEngineByKeyword(int profile, const string16 keyword) { | 228 void DeleteSearchEngineByKeyword(int profile, const string16 keyword) { |
224 const TemplateURL* turl = GetServiceForProfile(profile)-> | 229 if (profile != -1) { |
225 GetTemplateURLForKeyword(keyword); | 230 const TemplateURL* turl = GetServiceForProfile(profile)-> |
226 EXPECT_TRUE(turl); | 231 GetTemplateURLForKeyword(keyword); |
227 GetServiceForProfile(profile)->Remove(turl); | 232 EXPECT_TRUE(turl); |
| 233 GetServiceForProfile(profile)->Remove(turl); |
| 234 } |
228 // Make sure we do the same on the verifier. | 235 // Make sure we do the same on the verifier. |
229 if (test()->use_verifier()) { | 236 if (test()->use_verifier()) { |
230 const TemplateURL* verifier_turl = | 237 const TemplateURL* verifier_turl = |
231 GetVerifierService()->GetTemplateURLForKeyword(keyword); | 238 GetVerifierService()->GetTemplateURLForKeyword(keyword); |
232 EXPECT_TRUE(verifier_turl); | 239 EXPECT_TRUE(verifier_turl); |
233 GetVerifierService()->Remove(verifier_turl); | 240 GetVerifierService()->Remove(verifier_turl); |
234 } | 241 } |
235 } | 242 } |
236 | 243 |
237 void DeleteSearchEngineBySeed(int profile, int seed) { | 244 void DeleteSearchEngineBySeed(int profile, int seed) { |
238 DeleteSearchEngineByKeyword(profile, CreateKeyword(seed)); | 245 DeleteSearchEngineByKeyword(profile, CreateKeyword(seed)); |
239 } | 246 } |
240 | 247 |
241 void ChangeDefaultSearchProvider(int profile, int seed) { | 248 void ChangeDefaultSearchProvider(int profile, int seed) { |
242 TemplateURLService* service = GetServiceForProfile(profile); | 249 if (profile != -1) { |
243 ASSERT_TRUE(service); | 250 TemplateURLService* service = GetServiceForProfile(profile); |
244 const TemplateURL* new_default = service->GetTemplateURLForKeyword( | 251 ASSERT_TRUE(service); |
245 CreateKeyword(seed)); | 252 const TemplateURL* turl = service->GetTemplateURLForKeyword( |
246 ASSERT_TRUE(new_default); | 253 CreateKeyword(seed)); |
247 service->SetDefaultSearchProvider(new_default); | 254 ASSERT_TRUE(turl); |
| 255 service->SetDefaultSearchProvider(turl); |
| 256 } |
248 if (test()->use_verifier()) { | 257 if (test()->use_verifier()) { |
249 new_default = GetVerifierService()->GetTemplateURLForKeyword( | 258 const TemplateURL* verifier_turl = |
250 CreateKeyword(seed)); | 259 GetVerifierService()->GetTemplateURLForKeyword(CreateKeyword(seed)); |
251 ASSERT_TRUE(new_default); | 260 ASSERT_TRUE(verifier_turl); |
252 GetVerifierService()->SetDefaultSearchProvider(new_default); | 261 GetVerifierService()->SetDefaultSearchProvider(verifier_turl); |
253 } | 262 } |
254 } | 263 } |
255 | 264 |
256 } // namespace search_engines_helper | 265 } // namespace search_engines_helper |
OLD | NEW |