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

Side by Side Diff: chrome/browser/search_engines/template_url_service_sync_unittest.cc

Issue 151963002: Remove duplicated code from sync related unit tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rename SyncChangeProcessorDelgate to SyncChangeProcessorDelgator. Created 6 years, 10 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/run_loop.h" 7 #include "base/run_loop.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
11 #include "chrome/browser/chrome_notification_types.h" 11 #include "chrome/browser/chrome_notification_types.h"
12 #include "chrome/browser/search_engines/search_terms_data.h" 12 #include "chrome/browser/search_engines/search_terms_data.h"
13 #include "chrome/browser/search_engines/template_url.h" 13 #include "chrome/browser/search_engines/template_url.h"
14 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" 14 #include "chrome/browser/search_engines/template_url_prepopulate_data.h"
15 #include "chrome/browser/search_engines/template_url_service.h" 15 #include "chrome/browser/search_engines/template_url_service.h"
16 #include "chrome/browser/search_engines/template_url_service_factory.h" 16 #include "chrome/browser/search_engines/template_url_service_factory.h"
17 #include "chrome/browser/search_engines/template_url_service_test_util.h" 17 #include "chrome/browser/search_engines/template_url_service_test_util.h"
18 #include "chrome/common/pref_names.h" 18 #include "chrome/common/pref_names.h"
19 #include "chrome/common/url_constants.h" 19 #include "chrome/common/url_constants.h"
20 #include "chrome/test/base/testing_pref_service_syncable.h" 20 #include "chrome/test/base/testing_pref_service_syncable.h"
21 #include "chrome/test/base/testing_profile.h" 21 #include "chrome/test/base/testing_profile.h"
22 #include "content/public/browser/notification_service.h" 22 #include "content/public/browser/notification_service.h"
23 #include "extensions/common/constants.h" 23 #include "extensions/common/constants.h"
24 #include "net/base/net_util.h" 24 #include "net/base/net_util.h"
25 #include "sync/api/sync_change_processor_delegator.h"
25 #include "sync/api/sync_error_factory.h" 26 #include "sync/api/sync_error_factory.h"
26 #include "sync/api/sync_error_factory_mock.h" 27 #include "sync/api/sync_error_factory_mock.h"
27 #include "sync/protocol/search_engine_specifics.pb.h" 28 #include "sync/protocol/search_engine_specifics.pb.h"
28 #include "sync/protocol/sync.pb.h" 29 #include "sync/protocol/sync.pb.h"
29 #include "testing/gtest/include/gtest/gtest.h" 30 #include "testing/gtest/include/gtest/gtest.h"
30 31
31 using base::ASCIIToUTF16; 32 using base::ASCIIToUTF16;
32 using base::UTF8ToUTF16; 33 using base::UTF8ToUTF16;
33 using base::Time; 34 using base::Time;
34 35
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 syncer::SEARCH_ENGINES); 139 syncer::SEARCH_ENGINES);
139 140
140 change_map_.erase(change_map_.begin(), change_map_.end()); 141 change_map_.erase(change_map_.begin(), change_map_.end());
141 for (syncer::SyncChangeList::const_iterator iter = change_list.begin(); 142 for (syncer::SyncChangeList::const_iterator iter = change_list.begin();
142 iter != change_list.end(); ++iter) 143 iter != change_list.end(); ++iter)
143 change_map_[GetGUID(iter->sync_data())] = *iter; 144 change_map_[GetGUID(iter->sync_data())] = *iter;
144 return syncer::SyncError(); 145 return syncer::SyncError();
145 } 146 }
146 147
147 148
148 // SyncChangeProcessorDelegate ------------------------------------------------
149
150 class SyncChangeProcessorDelegate : public syncer::SyncChangeProcessor {
151 public:
152 explicit SyncChangeProcessorDelegate(syncer::SyncChangeProcessor* recipient);
153 virtual ~SyncChangeProcessorDelegate();
154
155 // syncer::SyncChangeProcessor implementation.
156 virtual syncer::SyncError ProcessSyncChanges(
157 const tracked_objects::Location& from_here,
158 const syncer::SyncChangeList& change_list) OVERRIDE;
159
160 virtual syncer::SyncDataList GetAllSyncData(syncer::ModelType type) const
161 OVERRIDE {
162 return recipient_->GetAllSyncData(type);
163 }
164
165 private:
166 // The recipient of all sync changes.
167 syncer::SyncChangeProcessor* recipient_;
168
169 DISALLOW_COPY_AND_ASSIGN(SyncChangeProcessorDelegate);
170 };
171
172 SyncChangeProcessorDelegate::SyncChangeProcessorDelegate(
173 syncer::SyncChangeProcessor* recipient)
174 : recipient_(recipient) {
175 DCHECK(recipient_);
176 }
177
178 SyncChangeProcessorDelegate::~SyncChangeProcessorDelegate() {
179 }
180
181 syncer::SyncError SyncChangeProcessorDelegate::ProcessSyncChanges(
182 const tracked_objects::Location& from_here,
183 const syncer::SyncChangeList& change_list) {
184 return recipient_->ProcessSyncChanges(from_here, change_list);
185 }
186
187 } // namespace 149 } // namespace
188 150
189 151
190 // TemplateURLServiceSyncTest ------------------------------------------------- 152 // TemplateURLServiceSyncTest -------------------------------------------------
191 153
192 class TemplateURLServiceSyncTest : public testing::Test { 154 class TemplateURLServiceSyncTest : public testing::Test {
193 public: 155 public:
194 typedef TemplateURLService::SyncDataMap SyncDataMap; 156 typedef TemplateURLService::SyncDataMap SyncDataMap;
195 157
196 TemplateURLServiceSyncTest(); 158 TemplateURLServiceSyncTest();
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 const std::string& guid); 212 const std::string& guid);
251 213
252 protected: 214 protected:
253 // We keep two TemplateURLServices to test syncing between them. 215 // We keep two TemplateURLServices to test syncing between them.
254 TemplateURLServiceTestUtil test_util_a_; 216 TemplateURLServiceTestUtil test_util_a_;
255 scoped_ptr<TestingProfile> profile_b_; 217 scoped_ptr<TestingProfile> profile_b_;
256 scoped_ptr<TemplateURLService> model_b_; 218 scoped_ptr<TemplateURLService> model_b_;
257 219
258 // Our dummy ChangeProcessor used to inspect changes pushed to Sync. 220 // Our dummy ChangeProcessor used to inspect changes pushed to Sync.
259 scoped_ptr<TestChangeProcessor> sync_processor_; 221 scoped_ptr<TestChangeProcessor> sync_processor_;
260 scoped_ptr<SyncChangeProcessorDelegate> sync_processor_delegate_; 222 scoped_ptr<syncer::SyncChangeProcessorDelegator> sync_processor_delegate_;
261 223
262 DISALLOW_COPY_AND_ASSIGN(TemplateURLServiceSyncTest); 224 DISALLOW_COPY_AND_ASSIGN(TemplateURLServiceSyncTest);
263 }; 225 };
264 226
265 TemplateURLServiceSyncTest::TemplateURLServiceSyncTest() 227 TemplateURLServiceSyncTest::TemplateURLServiceSyncTest()
266 : sync_processor_(new TestChangeProcessor), 228 : sync_processor_(new TestChangeProcessor),
267 sync_processor_delegate_(new SyncChangeProcessorDelegate( 229 sync_processor_delegate_(
268 sync_processor_.get())) { 230 new syncer::SyncChangeProcessorDelegator(sync_processor_.get())) {}
269 }
270 231
271 void TemplateURLServiceSyncTest::SetUp() { 232 void TemplateURLServiceSyncTest::SetUp() {
272 test_util_a_.SetUp(); 233 test_util_a_.SetUp();
273 // Use ChangeToLoadState() instead of VerifyLoad() so we don't actually pull 234 // Use ChangeToLoadState() instead of VerifyLoad() so we don't actually pull
274 // in the prepopulate data, which the sync tests don't care about (and would 235 // in the prepopulate data, which the sync tests don't care about (and would
275 // just foul them up). 236 // just foul them up).
276 test_util_a_.ChangeModelToLoadState(); 237 test_util_a_.ChangeModelToLoadState();
277 profile_b_.reset(new TestingProfile); 238 profile_b_.reset(new TestingProfile);
278 TemplateURLServiceFactory::GetInstance()-> 239 TemplateURLServiceFactory::GetInstance()->
279 RegisterUserPrefsOnBrowserContextForTest(profile_b_.get()); 240 RegisterUserPrefsOnBrowserContextForTest(profile_b_.get());
(...skipping 1034 matching lines...) Expand 10 before | Expand all | Expand 10 after
1314 } 1275 }
1315 1276
1316 TEST_F(TemplateURLServiceSyncTest, MergeTwoClientsBasic) { 1277 TEST_F(TemplateURLServiceSyncTest, MergeTwoClientsBasic) {
1317 // Start off B with some empty data. 1278 // Start off B with some empty data.
1318 model_b()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, 1279 model_b()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES,
1319 CreateInitialSyncData(), PassProcessor(), 1280 CreateInitialSyncData(), PassProcessor(),
1320 CreateAndPassSyncErrorFactory()); 1281 CreateAndPassSyncErrorFactory());
1321 1282
1322 // Merge A and B. All of B's data should transfer over to A, which initially 1283 // Merge A and B. All of B's data should transfer over to A, which initially
1323 // has no data. 1284 // has no data.
1324 scoped_ptr<SyncChangeProcessorDelegate> delegate_b( 1285 scoped_ptr<syncer::SyncChangeProcessorDelegator> delegate_b(
1325 new SyncChangeProcessorDelegate(model_b())); 1286 new syncer::SyncChangeProcessorDelegator(model_b()));
maniscalco 2014/02/03 23:05:50 Unfortunately, model_b() returns a TemplateURLServ
maniscalco 2014/02/06 20:05:27 Done.
1326 model_a()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, 1287 model_a()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES,
1327 model_b()->GetAllSyncData(syncer::SEARCH_ENGINES), 1288 model_b()->GetAllSyncData(syncer::SEARCH_ENGINES),
1328 delegate_b.PassAs<syncer::SyncChangeProcessor>(), 1289 delegate_b.PassAs<syncer::SyncChangeProcessor>(),
1329 CreateAndPassSyncErrorFactory()); 1290 CreateAndPassSyncErrorFactory());
1330 1291
1331 // They should be consistent. 1292 // They should be consistent.
1332 AssertEquals(model_a()->GetAllSyncData(syncer::SEARCH_ENGINES), 1293 AssertEquals(model_a()->GetAllSyncData(syncer::SEARCH_ENGINES),
1333 model_b()->GetAllSyncData(syncer::SEARCH_ENGINES)); 1294 model_b()->GetAllSyncData(syncer::SEARCH_ENGINES));
1334 } 1295 }
1335 1296
1336 TEST_F(TemplateURLServiceSyncTest, MergeTwoClientsDupesAndConflicts) { 1297 TEST_F(TemplateURLServiceSyncTest, MergeTwoClientsDupesAndConflicts) {
1337 // Start off B with some empty data. 1298 // Start off B with some empty data.
1338 model_b()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, 1299 model_b()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES,
1339 CreateInitialSyncData(), PassProcessor(), 1300 CreateInitialSyncData(), PassProcessor(),
1340 CreateAndPassSyncErrorFactory()); 1301 CreateAndPassSyncErrorFactory());
1341 1302
1342 // Set up A so we have some interesting duplicates and conflicts. 1303 // Set up A so we have some interesting duplicates and conflicts.
1343 model_a()->Add(CreateTestTemplateURL(ASCIIToUTF16("key4"), "http://key4.com", 1304 model_a()->Add(CreateTestTemplateURL(ASCIIToUTF16("key4"), "http://key4.com",
1344 "key4")); // Added 1305 "key4")); // Added
1345 model_a()->Add(CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://key2.com", 1306 model_a()->Add(CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://key2.com",
1346 "key2")); // Merge - Copy of key2. 1307 "key2")); // Merge - Copy of key2.
1347 model_a()->Add(CreateTestTemplateURL(ASCIIToUTF16("key3"), "http://key3.com", 1308 model_a()->Add(CreateTestTemplateURL(ASCIIToUTF16("key3"), "http://key3.com",
1348 "key5", 10)); // Merge - Dupe of key3. 1309 "key5", 10)); // Merge - Dupe of key3.
1349 model_a()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key6.com", 1310 model_a()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key6.com",
1350 "key6", 10)); // Conflict with key1 1311 "key6", 10)); // Conflict with key1
1351 1312
1352 // Merge A and B. 1313 // Merge A and B.
1353 scoped_ptr<SyncChangeProcessorDelegate> delegate_b( 1314 scoped_ptr<syncer::SyncChangeProcessorDelegator> delegate_b(
1354 new SyncChangeProcessorDelegate(model_b())); 1315 new syncer::SyncChangeProcessorDelegator(model_b()));
1355 model_a()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, 1316 model_a()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES,
1356 model_b()->GetAllSyncData(syncer::SEARCH_ENGINES), 1317 model_b()->GetAllSyncData(syncer::SEARCH_ENGINES),
1357 delegate_b.PassAs<syncer::SyncChangeProcessor>(), 1318 delegate_b.PassAs<syncer::SyncChangeProcessor>(),
1358 CreateAndPassSyncErrorFactory()); 1319 CreateAndPassSyncErrorFactory());
1359 1320
1360 // They should be consistent. 1321 // They should be consistent.
1361 AssertEquals(model_a()->GetAllSyncData(syncer::SEARCH_ENGINES), 1322 AssertEquals(model_a()->GetAllSyncData(syncer::SEARCH_ENGINES),
1362 model_b()->GetAllSyncData(syncer::SEARCH_ENGINES)); 1323 model_b()->GetAllSyncData(syncer::SEARCH_ENGINES));
1363 } 1324 }
1364 1325
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
1461 TemplateURLData data(temp_turl->data()); 1422 TemplateURLData data(temp_turl->data());
1462 data.short_name = ASCIIToUTF16("SomethingDifferent"); 1423 data.short_name = ASCIIToUTF16("SomethingDifferent");
1463 temp_turl.reset(new TemplateURL(temp_turl->profile(), data)); 1424 temp_turl.reset(new TemplateURL(temp_turl->profile(), data));
1464 initial_data.clear(); 1425 initial_data.clear();
1465 initial_data.push_back( 1426 initial_data.push_back(
1466 TemplateURLService::CreateSyncDataFromTemplateURL(*temp_turl)); 1427 TemplateURLService::CreateSyncDataFromTemplateURL(*temp_turl));
1467 1428
1468 // Remerge the data again. This simulates shutting down and syncing again 1429 // Remerge the data again. This simulates shutting down and syncing again
1469 // at a different time, but the cloud data has not changed. 1430 // at a different time, but the cloud data has not changed.
1470 model()->StopSyncing(syncer::SEARCH_ENGINES); 1431 model()->StopSyncing(syncer::SEARCH_ENGINES);
1471 sync_processor_delegate_.reset(new SyncChangeProcessorDelegate( 1432 sync_processor_delegate_.reset(
1472 sync_processor_.get())); 1433 new syncer::SyncChangeProcessorDelegator(sync_processor_.get()));
1473 error = model()->MergeDataAndStartSyncing( 1434 error = model()->MergeDataAndStartSyncing(
1474 syncer::SEARCH_ENGINES, 1435 syncer::SEARCH_ENGINES,
1475 initial_data, 1436 initial_data,
1476 PassProcessor(), 1437 PassProcessor(),
1477 CreateAndPassSyncErrorFactory()).error(); 1438 CreateAndPassSyncErrorFactory()).error();
1478 ASSERT_FALSE(error.IsSet()); 1439 ASSERT_FALSE(error.IsSet());
1479 1440
1480 // Check that the TemplateURL was not modified. 1441 // Check that the TemplateURL was not modified.
1481 const TemplateURL* reupdated_turl = model()->GetTemplateURLForGUID("key1"); 1442 const TemplateURL* reupdated_turl = model()->GetTemplateURLForGUID("key1");
1482 ASSERT_TRUE(reupdated_turl); 1443 ASSERT_TRUE(reupdated_turl);
(...skipping 794 matching lines...) Expand 10 before | Expand all | Expand 10 after
2277 syncer::SyncMergeResult merge_result = model()->MergeDataAndStartSyncing( 2238 syncer::SyncMergeResult merge_result = model()->MergeDataAndStartSyncing(
2278 syncer::SEARCH_ENGINES, list, PassProcessor(), 2239 syncer::SEARCH_ENGINES, list, PassProcessor(),
2279 CreateAndPassSyncErrorFactory()); 2240 CreateAndPassSyncErrorFactory());
2280 2241
2281 const TemplateURL* result_turl = model()->GetTemplateURLForGUID("default"); 2242 const TemplateURL* result_turl = model()->GetTemplateURLForGUID("default");
2282 EXPECT_TRUE(result_turl); 2243 EXPECT_TRUE(result_turl);
2283 EXPECT_EQ(default_turl->keyword(), result_turl->keyword()); 2244 EXPECT_EQ(default_turl->keyword(), result_turl->keyword());
2284 EXPECT_EQ(default_turl->short_name(), result_turl->short_name()); 2245 EXPECT_EQ(default_turl->short_name(), result_turl->short_name());
2285 EXPECT_EQ(default_turl->url(), result_turl->url()); 2246 EXPECT_EQ(default_turl->url(), result_turl->url());
2286 } 2247 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698