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

Side by Side Diff: components/search_engines/template_url_service_sync_unittest.cc

Issue 513133002: Move TemplateURLService related tests to components/search_engines (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments Created 6 years, 3 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
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 "base/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "base/memory/scoped_vector.h" 6 #include "base/memory/scoped_vector.h"
7 #include "base/message_loop/message_loop.h"
7 #include "base/run_loop.h" 8 #include "base/run_loop.h"
8 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
9 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
10 #include "base/time/time.h" 11 #include "base/time/time.h"
11 #include "chrome/browser/search_engines/template_url_service_factory.h"
12 #include "chrome/browser/search_engines/template_url_service_test_util.h" 12 #include "chrome/browser/search_engines/template_url_service_test_util.h"
13 #include "chrome/test/base/testing_pref_service_syncable.h" 13 #include "chrome/test/base/testing_pref_service_syncable.h"
14 #include "chrome/test/base/testing_profile.h" 14 #include "chrome/test/base/testing_profile.h"
15 #include "components/search_engines/search_engines_pref_names.h" 15 #include "components/search_engines/search_engines_pref_names.h"
16 #include "components/search_engines/search_terms_data.h" 16 #include "components/search_engines/search_terms_data.h"
17 #include "components/search_engines/template_url.h" 17 #include "components/search_engines/template_url.h"
18 #include "components/search_engines/template_url_prepopulate_data.h" 18 #include "components/search_engines/template_url_prepopulate_data.h"
19 #include "components/search_engines/template_url_service.h" 19 #include "components/search_engines/template_url_service.h"
20 #include "components/search_engines/template_url_service_client.h" 20 #include "components/search_engines/template_url_service_client.h"
21 #include "net/base/net_util.h" 21 #include "net/base/net_util.h"
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 154
155 TemplateURLServiceSyncTest(); 155 TemplateURLServiceSyncTest();
156 156
157 virtual void SetUp() OVERRIDE; 157 virtual void SetUp() OVERRIDE;
158 virtual void TearDown() OVERRIDE; 158 virtual void TearDown() OVERRIDE;
159 159
160 TemplateURLService* model() { return test_util_a_->model(); } 160 TemplateURLService* model() { return test_util_a_->model(); }
161 // For readability, we redefine an accessor for Model A for use in tests that 161 // For readability, we redefine an accessor for Model A for use in tests that
162 // involve syncing two models. 162 // involve syncing two models.
163 TemplateURLService* model_a() { return test_util_a_->model(); } 163 TemplateURLService* model_a() { return test_util_a_->model(); }
164 TemplateURLService* model_b() { return model_b_.get(); } 164 TemplateURLService* model_b() { return test_util_b_->model(); }
165 TestingProfile* profile_a() { return test_util_a_->profile(); } 165 TestingProfile* profile_a() { return test_util_a_->profile(); }
166 TestChangeProcessor* processor() { return sync_processor_.get(); } 166 TestChangeProcessor* processor() { return sync_processor_.get(); }
167 scoped_ptr<syncer::SyncChangeProcessor> PassProcessor(); 167 scoped_ptr<syncer::SyncChangeProcessor> PassProcessor();
168 scoped_ptr<syncer::SyncErrorFactory> CreateAndPassSyncErrorFactory(); 168 scoped_ptr<syncer::SyncErrorFactory> CreateAndPassSyncErrorFactory();
169 169
170 // Creates a TemplateURL with some test values. The caller owns the returned 170 // Creates a TemplateURL with some test values. The caller owns the returned
171 // TemplateURL*. 171 // TemplateURL*.
172 TemplateURL* CreateTestTemplateURL(const base::string16& keyword, 172 TemplateURL* CreateTestTemplateURL(const base::string16& keyword,
173 const std::string& url, 173 const std::string& url,
174 const std::string& guid = std::string(), 174 const std::string& guid = std::string(),
(...skipping 27 matching lines...) Expand all
202 202
203 // Creates a new TemplateURL copying the fields of |turl| but replacing 203 // Creates a new TemplateURL copying the fields of |turl| but replacing
204 // the |url| and |guid| and initializing the date_created and last_modified 204 // the |url| and |guid| and initializing the date_created and last_modified
205 // timestamps to a default value of 100. The caller owns the returned 205 // timestamps to a default value of 100. The caller owns the returned
206 // TemplateURL*. 206 // TemplateURL*.
207 TemplateURL* CopyTemplateURL(const TemplateURLData* turl, 207 TemplateURL* CopyTemplateURL(const TemplateURLData* turl,
208 const std::string& url, 208 const std::string& url,
209 const std::string& guid); 209 const std::string& guid);
210 210
211 protected: 211 protected:
212 base::MessageLoop message_loop_;
212 // We keep two TemplateURLServices to test syncing between them. 213 // We keep two TemplateURLServices to test syncing between them.
213 scoped_ptr<TemplateURLServiceTestUtil> test_util_a_; 214 scoped_ptr<TemplateURLServiceTestUtil> test_util_a_;
214 scoped_ptr<TestingProfile> profile_b_; 215 scoped_ptr<TemplateURLServiceTestUtil> test_util_b_;
215 scoped_ptr<TemplateURLService> model_b_;
216 216
217 // Our dummy ChangeProcessor used to inspect changes pushed to Sync. 217 // Our dummy ChangeProcessor used to inspect changes pushed to Sync.
218 scoped_ptr<TestChangeProcessor> sync_processor_; 218 scoped_ptr<TestChangeProcessor> sync_processor_;
219 scoped_ptr<syncer::SyncChangeProcessorWrapperForTest> sync_processor_wrapper_; 219 scoped_ptr<syncer::SyncChangeProcessorWrapperForTest> sync_processor_wrapper_;
220 220
221 DISALLOW_COPY_AND_ASSIGN(TemplateURLServiceSyncTest); 221 DISALLOW_COPY_AND_ASSIGN(TemplateURLServiceSyncTest);
222 }; 222 };
223 223
224 TemplateURLServiceSyncTest::TemplateURLServiceSyncTest() 224 TemplateURLServiceSyncTest::TemplateURLServiceSyncTest()
225 : sync_processor_(new TestChangeProcessor), 225 : sync_processor_(new TestChangeProcessor),
226 sync_processor_wrapper_(new syncer::SyncChangeProcessorWrapperForTest( 226 sync_processor_wrapper_(new syncer::SyncChangeProcessorWrapperForTest(
227 sync_processor_.get())) {} 227 sync_processor_.get())) {}
228 228
229 void TemplateURLServiceSyncTest::SetUp() { 229 void TemplateURLServiceSyncTest::SetUp() {
230 DefaultSearchManager::SetFallbackSearchEnginesDisabledForTesting(true); 230 DefaultSearchManager::SetFallbackSearchEnginesDisabledForTesting(true);
231 test_util_a_.reset(new TemplateURLServiceTestUtil); 231 test_util_a_.reset(new TemplateURLServiceTestUtil);
232 // Use ChangeToLoadState() instead of VerifyLoad() so we don't actually pull 232 // Use ChangeToLoadState() instead of VerifyLoad() so we don't actually pull
233 // in the prepopulate data, which the sync tests don't care about (and would 233 // in the prepopulate data, which the sync tests don't care about (and would
234 // just foul them up). 234 // just foul them up).
235 test_util_a_->ChangeModelToLoadState(); 235 test_util_a_->ChangeModelToLoadState();
236 profile_b_.reset(new TestingProfile); 236
237 TemplateURLServiceFactory::GetInstance()-> 237 test_util_b_.reset(new TemplateURLServiceTestUtil);
238 RegisterUserPrefsOnBrowserContextForTest(profile_b_.get()); 238 test_util_b_->VerifyLoad();
239 model_b_.reset(new TemplateURLService(
240 profile_b_->GetPrefs(), make_scoped_ptr(new SearchTermsData), NULL,
241 scoped_ptr<TemplateURLServiceClient>(), NULL, NULL, base::Closure()));
242 model_b_->Load();
243 } 239 }
244 240
245 void TemplateURLServiceSyncTest::TearDown() { 241 void TemplateURLServiceSyncTest::TearDown() {
246 test_util_a_.reset(); 242 test_util_a_.reset();
247 DefaultSearchManager::SetFallbackSearchEnginesDisabledForTesting(false); 243 DefaultSearchManager::SetFallbackSearchEnginesDisabledForTesting(false);
248 } 244 }
249 245
250 scoped_ptr<syncer::SyncChangeProcessor> 246 scoped_ptr<syncer::SyncChangeProcessor>
251 TemplateURLServiceSyncTest::PassProcessor() { 247 TemplateURLServiceSyncTest::PassProcessor() {
252 return sync_processor_wrapper_.PassAs<syncer::SyncChangeProcessor>(); 248 return sync_processor_wrapper_.PassAs<syncer::SyncChangeProcessor>();
(...skipping 1981 matching lines...) Expand 10 before | Expand all | Expand 10 after
2234 const char kNewGUID[] = "newdefault"; 2230 const char kNewGUID[] = "newdefault";
2235 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("what"), 2231 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("what"),
2236 "http://thewhat.com/{searchTerms}", 2232 "http://thewhat.com/{searchTerms}",
2237 kNewGUID)); 2233 kNewGUID));
2238 model()->SetUserSelectedDefaultSearchProvider( 2234 model()->SetUserSelectedDefaultSearchProvider(
2239 model()->GetTemplateURLForGUID(kNewGUID)); 2235 model()->GetTemplateURLForGUID(kNewGUID));
2240 2236
2241 EXPECT_EQ(kNewGUID, profile_a()->GetTestingPrefService()->GetString( 2237 EXPECT_EQ(kNewGUID, profile_a()->GetTestingPrefService()->GetString(
2242 prefs::kSyncedDefaultSearchProviderGUID)); 2238 prefs::kSyncedDefaultSearchProviderGUID));
2243 } 2239 }
OLDNEW
« no previous file with comments | « components/search_engines/template_url_service.cc ('k') | components/search_engines/template_url_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698