Chromium Code Reviews| 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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 130 for (GUIDToTURLMap::iterator it = a_turls.begin(); | 130 for (GUIDToTURLMap::iterator it = a_turls.begin(); |
| 131 it != a_turls.end(); ++it) { | 131 it != a_turls.end(); ++it) { |
| 132 if (b_turls.find(it->first) == b_turls.end()) { | 132 if (b_turls.find(it->first) == b_turls.end()) { |
| 133 LOG(ERROR) << "TURL GUID from a not found in b's TURLs: " << it->first; | 133 LOG(ERROR) << "TURL GUID from a not found in b's TURLs: " << it->first; |
| 134 return false; | 134 return false; |
| 135 } | 135 } |
| 136 if (!TURLsMatch(b_turls[it->first], it->second)) | 136 if (!TURLsMatch(b_turls[it->first], it->second)) |
| 137 return false; | 137 return false; |
| 138 } | 138 } |
| 139 | 139 |
| 140 const TemplateURL* default_a = service_a->GetDefaultSearchProvider(); | |
| 141 const TemplateURL* default_b = service_b->GetDefaultSearchProvider(); | |
| 142 CHECK(default_a); | |
| 143 CHECK(default_b); | |
| 144 if (!TURLsMatch(default_a, default_b)) { | |
| 145 LOG(ERROR) << "Default search providers do not match: A's default: " | |
| 146 << default_a->keyword() << " B's default: " | |
| 147 << default_b->keyword(); | |
| 148 return false; | |
| 149 } else { | |
| 150 LOG(INFO) << "A had default with URL: " << default_a->url()->url() | |
|
Raghu Simha
2011/11/07 22:18:12
Is url()->url() a typo or do you need to go that d
SteveT
2011/11/08 00:17:27
Yeah, I want to print the URL itself. This output
| |
| 151 << " and keyword: " << default_a->keyword(); | |
| 152 } | |
| 153 | |
| 140 return true; | 154 return true; |
| 141 } | 155 } |
| 142 | 156 |
| 143 bool AllServicesMatch() { | 157 bool AllServicesMatch() { |
| 144 // Use 0 as the baseline. | 158 // Use 0 as the baseline. |
| 145 if (!ServiceMatchesVerifier(0)) | 159 if (!ServiceMatchesVerifier(0)) |
| 146 return false; | 160 return false; |
| 147 | 161 |
| 148 for (int it = 0; it < test()->num_clients(); ++it) { | 162 for (int it = 0; it < test()->num_clients(); ++it) { |
| 149 if (!ServicesMatch(0, it)) { | 163 if (!ServicesMatch(0, it)) { |
| 150 LOG(ERROR) << "TemplateURLService " << it << " does not match with " | 164 LOG(ERROR) << "TemplateURLService " << it << " does not match with " |
| 151 << "service 0."; | 165 << "service 0."; |
| 152 return false; | 166 return false; |
| 153 } | 167 } |
| 154 } | 168 } |
| 155 return true; | 169 return true; |
| 156 } | 170 } |
| 157 | 171 |
| 172 // Convenience helper for consistently generating the same keyword for a given | |
| 173 // seed. | |
| 174 string16 CreateKeyword(int seed) { | |
| 175 return ASCIIToUTF16(base::StringPrintf("test%d", seed)); | |
| 176 } | |
| 177 | |
| 158 TemplateURL* CreateTestTemplateURL(int seed) { | 178 TemplateURL* CreateTestTemplateURL(int seed) { |
| 159 TemplateURL* turl = new TemplateURL(); | 179 TemplateURL* turl = new TemplateURL(); |
| 160 turl->SetURL(base::StringPrintf("http://www.test%d.com/", seed), 0, 0); | 180 turl->SetURL(base::StringPrintf("http://www.test%d.com/", seed), 0, 0); |
| 161 turl->set_keyword(ASCIIToUTF16(base::StringPrintf("test%d", seed))); | 181 turl->set_keyword(CreateKeyword(seed)); |
| 162 turl->set_short_name(ASCIIToUTF16(base::StringPrintf("test%d", seed))); | 182 turl->set_short_name(ASCIIToUTF16(base::StringPrintf("test%d", seed))); |
| 163 turl->set_safe_for_autoreplace(true); | 183 turl->set_safe_for_autoreplace(true); |
| 164 GURL favicon_url("http://favicon.url"); | 184 GURL favicon_url("http://favicon.url"); |
| 165 turl->SetFaviconURL(favicon_url); | 185 turl->SetFaviconURL(favicon_url); |
| 166 turl->set_date_created(base::Time::FromTimeT(100)); | 186 turl->set_date_created(base::Time::FromTimeT(100)); |
| 167 turl->set_last_modified(base::Time::FromTimeT(100)); | 187 turl->set_last_modified(base::Time::FromTimeT(100)); |
| 168 turl->SetPrepopulateId(999999); | 188 turl->SetPrepopulateId(999999); |
| 169 turl->set_sync_guid(base::StringPrintf("0000-0000-0000-%04d", seed)); | 189 turl->set_sync_guid(base::StringPrintf("0000-0000-0000-%04d", seed)); |
| 170 return turl; | 190 return turl; |
| 171 } | 191 } |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 193 const TemplateURL* verifier_turl = | 213 const TemplateURL* verifier_turl = |
| 194 GetVerifierService()->GetTemplateURLForKeyword(ASCIIToUTF16(keyword)); | 214 GetVerifierService()->GetTemplateURLForKeyword(ASCIIToUTF16(keyword)); |
| 195 EXPECT_TRUE(verifier_turl); | 215 EXPECT_TRUE(verifier_turl); |
| 196 GetVerifierService()->ResetTemplateURL(verifier_turl, | 216 GetVerifierService()->ResetTemplateURL(verifier_turl, |
| 197 ASCIIToUTF16(short_name), | 217 ASCIIToUTF16(short_name), |
| 198 ASCIIToUTF16(new_keyword), | 218 ASCIIToUTF16(new_keyword), |
| 199 url); | 219 url); |
| 200 } | 220 } |
| 201 } | 221 } |
| 202 | 222 |
| 203 void DeleteSearchEngine(int profile, const std::string& keyword) { | 223 void DeleteSearchEngine(int profile, const string16 keyword) { |
| 204 const TemplateURL* turl = GetServiceForProfile(profile)-> | 224 const TemplateURL* turl = GetServiceForProfile(profile)-> |
| 205 GetTemplateURLForKeyword(ASCIIToUTF16(keyword)); | 225 GetTemplateURLForKeyword(keyword); |
| 206 EXPECT_TRUE(turl); | 226 EXPECT_TRUE(turl); |
| 207 GetServiceForProfile(profile)->Remove(turl); | 227 GetServiceForProfile(profile)->Remove(turl); |
| 208 // Make sure we do the same on the verifier. | 228 // Make sure we do the same on the verifier. |
| 209 if (test()->use_verifier()) { | 229 if (test()->use_verifier()) { |
| 210 const TemplateURL* verifier_turl = | 230 const TemplateURL* verifier_turl = |
| 211 GetVerifierService()->GetTemplateURLForKeyword(ASCIIToUTF16(keyword)); | 231 GetVerifierService()->GetTemplateURLForKeyword(keyword); |
| 212 EXPECT_TRUE(verifier_turl); | 232 EXPECT_TRUE(verifier_turl); |
| 213 GetVerifierService()->Remove(verifier_turl); | 233 GetVerifierService()->Remove(verifier_turl); |
| 214 } | 234 } |
| 215 } | 235 } |
| 216 | 236 |
| 237 void DeleteSearchEngineBySeed(int profile, int seed) { | |
| 238 DeleteSearchEngine(profile, CreateKeyword(seed)); | |
| 239 } | |
| 240 | |
| 241 void ChangeDefaultSearchProvider(int profile, int seed) { | |
| 242 TemplateURLService* service = GetServiceForProfile(profile); | |
| 243 ASSERT_TRUE(service); | |
| 244 const TemplateURL* new_default = service->GetTemplateURLForKeyword( | |
| 245 CreateKeyword(seed)); | |
| 246 ASSERT_TRUE(new_default); | |
| 247 service->SetDefaultSearchProvider(new_default); | |
| 248 if (test()->use_verifier()) { | |
| 249 new_default = GetVerifierService()->GetTemplateURLForKeyword( | |
| 250 CreateKeyword(seed)); | |
| 251 ASSERT_TRUE(new_default); | |
| 252 GetVerifierService()->SetDefaultSearchProvider(new_default); | |
| 253 } | |
| 254 } | |
| 255 | |
| 217 } // namespace search_engines_helper | 256 } // namespace search_engines_helper |
| OLD | NEW |