Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(157)

Side by Side Diff: chrome/browser/sync/test/integration/search_engines_helper.cc

Issue 15517005: Remove references to Profile from browser_context_keyed_service. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase & style Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 if (!result) { 54 if (!result) {
55 LOG(ERROR) << "TemplateURLs did not match: " << GetTURLInfoString(turl1) 55 LOG(ERROR) << "TemplateURLs did not match: " << GetTURLInfoString(turl1)
56 << " vs " << GetTURLInfoString(turl2); 56 << " vs " << GetTURLInfoString(turl2);
57 } 57 }
58 58
59 return result; 59 return result;
60 } 60 }
61 61
62 bool ServicesMatch(int profile_a, int profile_b) { 62 bool ServicesMatch(int profile_a, int profile_b) {
63 TemplateURLService* service_a = 63 TemplateURLService* service_a =
64 search_engines_helper::GetServiceForProfile(profile_a); 64 search_engines_helper::GetServiceForBrowserContext(profile_a);
65 TemplateURLService* service_b = 65 TemplateURLService* service_b =
66 search_engines_helper::GetServiceForProfile(profile_b); 66 search_engines_helper::GetServiceForBrowserContext(profile_b);
67 CHECK(service_a); 67 CHECK(service_a);
68 CHECK(service_b); 68 CHECK(service_b);
69 69
70 // Services that have synced should have identical TURLs, including the GUIDs. 70 // Services that have synced should have identical TURLs, including the GUIDs.
71 // Make sure we compare those fields in addition to the user-visible fields. 71 // Make sure we compare those fields in addition to the user-visible fields.
72 GUIDToTURLMap a_turls = CreateGUIDToTURLMap(service_a); 72 GUIDToTURLMap a_turls = CreateGUIDToTURLMap(service_a);
73 GUIDToTURLMap b_turls = CreateGUIDToTURLMap(service_b); 73 GUIDToTURLMap b_turls = CreateGUIDToTURLMap(service_b);
74 74
75 if (a_turls.size() != b_turls.size()) { 75 if (a_turls.size() != b_turls.size()) {
76 LOG(ERROR) << "Service a and b do not match in size: " << a_turls.size() 76 LOG(ERROR) << "Service a and b do not match in size: " << a_turls.size()
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 // Convenience helper for consistently generating the same keyword for a given 108 // Convenience helper for consistently generating the same keyword for a given
109 // seed. 109 // seed.
110 string16 CreateKeyword(int seed) { 110 string16 CreateKeyword(int seed) {
111 return ASCIIToUTF16(base::StringPrintf("test%d", seed)); 111 return ASCIIToUTF16(base::StringPrintf("test%d", seed));
112 } 112 }
113 113
114 } // namespace 114 } // namespace
115 115
116 namespace search_engines_helper { 116 namespace search_engines_helper {
117 117
118 TemplateURLService* GetServiceForProfile(int profile_index) { 118 TemplateURLService* GetServiceForBrowserContext(int profile_index) {
119 return TemplateURLServiceFactory::GetForProfile( 119 return TemplateURLServiceFactory::GetForProfile(
120 test()->GetProfile(profile_index)); 120 test()->GetProfile(profile_index));
121 } 121 }
122 122
123 TemplateURLService* GetVerifierService() { 123 TemplateURLService* GetVerifierService() {
124 return TemplateURLServiceFactory::GetForProfile(test()->verifier()); 124 return TemplateURLServiceFactory::GetForProfile(test()->verifier());
125 } 125 }
126 126
127 bool ServiceMatchesVerifier(int profile_index) { 127 bool ServiceMatchesVerifier(int profile_index) {
128 TemplateURLService* verifier = GetVerifierService(); 128 TemplateURLService* verifier = GetVerifierService();
129 TemplateURLService* other = GetServiceForProfile(profile_index); 129 TemplateURLService* other = GetServiceForBrowserContext(profile_index);
130 130
131 CHECK(verifier); 131 CHECK(verifier);
132 CHECK(other); 132 CHECK(other);
133 133
134 TemplateURLService::TemplateURLVector verifier_turls = 134 TemplateURLService::TemplateURLVector verifier_turls =
135 verifier->GetTemplateURLs(); 135 verifier->GetTemplateURLs();
136 if (verifier_turls.size() != other->GetTemplateURLs().size()) { 136 if (verifier_turls.size() != other->GetTemplateURLs().size()) {
137 LOG(ERROR) << "Verifier and other service have a different count of TURLs: " 137 LOG(ERROR) << "Verifier and other service have a different count of TURLs: "
138 << verifier_turls.size() << " vs " 138 << verifier_turls.size() << " vs "
139 << other->GetTemplateURLs().size() << " respectively."; 139 << other->GetTemplateURLs().size() << " respectively.";
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 if (test()->use_verifier()) 213 if (test()->use_verifier())
214 GetVerifierService()->Add(CreateTestTemplateURL(profile, seed)); 214 GetVerifierService()->Add(CreateTestTemplateURL(profile, seed));
215 } 215 }
216 216
217 void EditSearchEngine(int profile_index, 217 void EditSearchEngine(int profile_index,
218 const string16& keyword, 218 const string16& keyword,
219 const string16& short_name, 219 const string16& short_name,
220 const string16& new_keyword, 220 const string16& new_keyword,
221 const std::string& url) { 221 const std::string& url) {
222 DCHECK(!url.empty()); 222 DCHECK(!url.empty());
223 TemplateURLService* service = GetServiceForProfile(profile_index); 223 TemplateURLService* service = GetServiceForBrowserContext(profile_index);
224 TemplateURL* turl = service->GetTemplateURLForKeyword(keyword); 224 TemplateURL* turl = service->GetTemplateURLForKeyword(keyword);
225 EXPECT_TRUE(turl); 225 EXPECT_TRUE(turl);
226 ASSERT_FALSE(new_keyword.empty()); 226 ASSERT_FALSE(new_keyword.empty());
227 service->ResetTemplateURL(turl, short_name, new_keyword, url); 227 service->ResetTemplateURL(turl, short_name, new_keyword, url);
228 // Make sure we do the same on the verifier. 228 // Make sure we do the same on the verifier.
229 if (test()->use_verifier()) { 229 if (test()->use_verifier()) {
230 TemplateURL* verifier_turl = 230 TemplateURL* verifier_turl =
231 GetVerifierService()->GetTemplateURLForKeyword(keyword); 231 GetVerifierService()->GetTemplateURLForKeyword(keyword);
232 EXPECT_TRUE(verifier_turl); 232 EXPECT_TRUE(verifier_turl);
233 GetVerifierService()->ResetTemplateURL(verifier_turl, short_name, 233 GetVerifierService()->ResetTemplateURL(verifier_turl, short_name,
234 new_keyword, url); 234 new_keyword, url);
235 } 235 }
236 } 236 }
237 237
238 void DeleteSearchEngineBySeed(int profile_index, int seed) { 238 void DeleteSearchEngineBySeed(int profile_index, int seed) {
239 TemplateURLService* service = GetServiceForProfile(profile_index); 239 TemplateURLService* service = GetServiceForBrowserContext(profile_index);
240 string16 keyword(CreateKeyword(seed)); 240 string16 keyword(CreateKeyword(seed));
241 TemplateURL* turl = service->GetTemplateURLForKeyword(keyword); 241 TemplateURL* turl = service->GetTemplateURLForKeyword(keyword);
242 EXPECT_TRUE(turl); 242 EXPECT_TRUE(turl);
243 service->Remove(turl); 243 service->Remove(turl);
244 // Make sure we do the same on the verifier. 244 // Make sure we do the same on the verifier.
245 if (test()->use_verifier()) { 245 if (test()->use_verifier()) {
246 TemplateURL* verifier_turl = 246 TemplateURL* verifier_turl =
247 GetVerifierService()->GetTemplateURLForKeyword(keyword); 247 GetVerifierService()->GetTemplateURLForKeyword(keyword);
248 EXPECT_TRUE(verifier_turl); 248 EXPECT_TRUE(verifier_turl);
249 GetVerifierService()->Remove(verifier_turl); 249 GetVerifierService()->Remove(verifier_turl);
250 } 250 }
251 } 251 }
252 252
253 void ChangeDefaultSearchProvider(int profile_index, int seed) { 253 void ChangeDefaultSearchProvider(int profile_index, int seed) {
254 TemplateURLService* service = GetServiceForProfile(profile_index); 254 TemplateURLService* service = GetServiceForBrowserContext(profile_index);
255 ASSERT_TRUE(service); 255 ASSERT_TRUE(service);
256 TemplateURL* turl = service->GetTemplateURLForKeyword(CreateKeyword(seed)); 256 TemplateURL* turl = service->GetTemplateURLForKeyword(CreateKeyword(seed));
257 ASSERT_TRUE(turl); 257 ASSERT_TRUE(turl);
258 service->SetDefaultSearchProvider(turl); 258 service->SetDefaultSearchProvider(turl);
259 if (test()->use_verifier()) { 259 if (test()->use_verifier()) {
260 TemplateURL* verifier_turl = 260 TemplateURL* verifier_turl =
261 GetVerifierService()->GetTemplateURLForKeyword(CreateKeyword(seed)); 261 GetVerifierService()->GetTemplateURLForKeyword(CreateKeyword(seed));
262 ASSERT_TRUE(verifier_turl); 262 ASSERT_TRUE(verifier_turl);
263 GetVerifierService()->SetDefaultSearchProvider(verifier_turl); 263 GetVerifierService()->SetDefaultSearchProvider(verifier_turl);
264 } 264 }
265 } 265 }
266 266
267 } // namespace search_engines_helper 267 } // namespace search_engines_helper
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698