OLD | NEW |
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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <utility> |
6 | 7 |
7 #include "base/macros.h" | 8 #include "base/macros.h" |
8 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
9 #include "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
10 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
11 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
12 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
13 #include "base/time/time.h" | 14 #include "base/time/time.h" |
14 #include "chrome/browser/search_engines/template_url_service_test_util.h" | 15 #include "chrome/browser/search_engines/template_url_service_test_util.h" |
15 #include "chrome/test/base/testing_profile.h" | 16 #include "chrome/test/base/testing_profile.h" |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 test_util_b_->VerifyLoad(); | 271 test_util_b_->VerifyLoad(); |
271 } | 272 } |
272 | 273 |
273 void TemplateURLServiceSyncTest::TearDown() { | 274 void TemplateURLServiceSyncTest::TearDown() { |
274 test_util_a_.reset(); | 275 test_util_a_.reset(); |
275 DefaultSearchManager::SetFallbackSearchEnginesDisabledForTesting(false); | 276 DefaultSearchManager::SetFallbackSearchEnginesDisabledForTesting(false); |
276 } | 277 } |
277 | 278 |
278 scoped_ptr<syncer::SyncChangeProcessor> | 279 scoped_ptr<syncer::SyncChangeProcessor> |
279 TemplateURLServiceSyncTest::PassProcessor() { | 280 TemplateURLServiceSyncTest::PassProcessor() { |
280 return sync_processor_wrapper_.Pass(); | 281 return std::move(sync_processor_wrapper_); |
281 } | 282 } |
282 | 283 |
283 scoped_ptr<syncer::SyncErrorFactory> TemplateURLServiceSyncTest:: | 284 scoped_ptr<syncer::SyncErrorFactory> TemplateURLServiceSyncTest:: |
284 CreateAndPassSyncErrorFactory() { | 285 CreateAndPassSyncErrorFactory() { |
285 return scoped_ptr<syncer::SyncErrorFactory>( | 286 return scoped_ptr<syncer::SyncErrorFactory>( |
286 new syncer::SyncErrorFactoryMock()); | 287 new syncer::SyncErrorFactoryMock()); |
287 } | 288 } |
288 | 289 |
289 TemplateURL* TemplateURLServiceSyncTest::CreateTestTemplateURL( | 290 TemplateURL* TemplateURLServiceSyncTest::CreateTestTemplateURL( |
290 const base::string16& keyword, | 291 const base::string16& keyword, |
(...skipping 1021 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1312 // Start off B with some empty data. | 1313 // Start off B with some empty data. |
1313 model_b()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, | 1314 model_b()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, |
1314 CreateInitialSyncData(), PassProcessor(), | 1315 CreateInitialSyncData(), PassProcessor(), |
1315 CreateAndPassSyncErrorFactory()); | 1316 CreateAndPassSyncErrorFactory()); |
1316 | 1317 |
1317 // Merge A and B. All of B's data should transfer over to A, which initially | 1318 // Merge A and B. All of B's data should transfer over to A, which initially |
1318 // has no data. | 1319 // has no data. |
1319 scoped_ptr<syncer::SyncChangeProcessorWrapperForTest> delegate_b( | 1320 scoped_ptr<syncer::SyncChangeProcessorWrapperForTest> delegate_b( |
1320 new syncer::SyncChangeProcessorWrapperForTest(model_b())); | 1321 new syncer::SyncChangeProcessorWrapperForTest(model_b())); |
1321 model_a()->MergeDataAndStartSyncing( | 1322 model_a()->MergeDataAndStartSyncing( |
1322 syncer::SEARCH_ENGINES, | 1323 syncer::SEARCH_ENGINES, model_b()->GetAllSyncData(syncer::SEARCH_ENGINES), |
1323 model_b()->GetAllSyncData(syncer::SEARCH_ENGINES), | 1324 std::move(delegate_b), CreateAndPassSyncErrorFactory()); |
1324 delegate_b.Pass(), | |
1325 CreateAndPassSyncErrorFactory()); | |
1326 | 1325 |
1327 // They should be consistent. | 1326 // They should be consistent. |
1328 AssertEquals(model_a()->GetAllSyncData(syncer::SEARCH_ENGINES), | 1327 AssertEquals(model_a()->GetAllSyncData(syncer::SEARCH_ENGINES), |
1329 model_b()->GetAllSyncData(syncer::SEARCH_ENGINES)); | 1328 model_b()->GetAllSyncData(syncer::SEARCH_ENGINES)); |
1330 } | 1329 } |
1331 | 1330 |
1332 TEST_F(TemplateURLServiceSyncTest, MergeTwoClientsDupesAndConflicts) { | 1331 TEST_F(TemplateURLServiceSyncTest, MergeTwoClientsDupesAndConflicts) { |
1333 // Start off B with some empty data. | 1332 // Start off B with some empty data. |
1334 model_b()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, | 1333 model_b()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, |
1335 CreateInitialSyncData(), PassProcessor(), | 1334 CreateInitialSyncData(), PassProcessor(), |
1336 CreateAndPassSyncErrorFactory()); | 1335 CreateAndPassSyncErrorFactory()); |
1337 | 1336 |
1338 // Set up A so we have some interesting duplicates and conflicts. | 1337 // Set up A so we have some interesting duplicates and conflicts. |
1339 model_a()->Add(CreateTestTemplateURL(ASCIIToUTF16("key4"), "http://key4.com", | 1338 model_a()->Add(CreateTestTemplateURL(ASCIIToUTF16("key4"), "http://key4.com", |
1340 "key4")); // Added | 1339 "key4")); // Added |
1341 model_a()->Add(CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://key2.com", | 1340 model_a()->Add(CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://key2.com", |
1342 "key2")); // Merge - Copy of key2. | 1341 "key2")); // Merge - Copy of key2. |
1343 model_a()->Add(CreateTestTemplateURL(ASCIIToUTF16("key3"), "http://key3.com", | 1342 model_a()->Add(CreateTestTemplateURL(ASCIIToUTF16("key3"), "http://key3.com", |
1344 "key5", 10)); // Merge - Dupe of key3. | 1343 "key5", 10)); // Merge - Dupe of key3. |
1345 model_a()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key6.com", | 1344 model_a()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key6.com", |
1346 "key6", 10)); // Conflict with key1 | 1345 "key6", 10)); // Conflict with key1 |
1347 | 1346 |
1348 // Merge A and B. | 1347 // Merge A and B. |
1349 scoped_ptr<syncer::SyncChangeProcessorWrapperForTest> delegate_b( | 1348 scoped_ptr<syncer::SyncChangeProcessorWrapperForTest> delegate_b( |
1350 new syncer::SyncChangeProcessorWrapperForTest(model_b())); | 1349 new syncer::SyncChangeProcessorWrapperForTest(model_b())); |
1351 model_a()->MergeDataAndStartSyncing( | 1350 model_a()->MergeDataAndStartSyncing( |
1352 syncer::SEARCH_ENGINES, | 1351 syncer::SEARCH_ENGINES, model_b()->GetAllSyncData(syncer::SEARCH_ENGINES), |
1353 model_b()->GetAllSyncData(syncer::SEARCH_ENGINES), | 1352 std::move(delegate_b), CreateAndPassSyncErrorFactory()); |
1354 delegate_b.Pass(), | |
1355 CreateAndPassSyncErrorFactory()); | |
1356 | 1353 |
1357 // They should be consistent. | 1354 // They should be consistent. |
1358 AssertEquals(model_a()->GetAllSyncData(syncer::SEARCH_ENGINES), | 1355 AssertEquals(model_a()->GetAllSyncData(syncer::SEARCH_ENGINES), |
1359 model_b()->GetAllSyncData(syncer::SEARCH_ENGINES)); | 1356 model_b()->GetAllSyncData(syncer::SEARCH_ENGINES)); |
1360 } | 1357 } |
1361 | 1358 |
1362 TEST_F(TemplateURLServiceSyncTest, StopSyncing) { | 1359 TEST_F(TemplateURLServiceSyncTest, StopSyncing) { |
1363 syncer::SyncError error = | 1360 syncer::SyncError error = |
1364 model()->MergeDataAndStartSyncing( | 1361 model()->MergeDataAndStartSyncing( |
1365 syncer::SEARCH_ENGINES, | 1362 syncer::SEARCH_ENGINES, |
(...skipping 898 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2264 const char kNewGUID[] = "newdefault"; | 2261 const char kNewGUID[] = "newdefault"; |
2265 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("what"), | 2262 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("what"), |
2266 "http://thewhat.com/{searchTerms}", | 2263 "http://thewhat.com/{searchTerms}", |
2267 kNewGUID)); | 2264 kNewGUID)); |
2268 model()->SetUserSelectedDefaultSearchProvider( | 2265 model()->SetUserSelectedDefaultSearchProvider( |
2269 model()->GetTemplateURLForGUID(kNewGUID)); | 2266 model()->GetTemplateURLForGUID(kNewGUID)); |
2270 | 2267 |
2271 EXPECT_EQ(kNewGUID, profile_a()->GetTestingPrefService()->GetString( | 2268 EXPECT_EQ(kNewGUID, profile_a()->GetTestingPrefService()->GetString( |
2272 prefs::kSyncedDefaultSearchProviderGUID)); | 2269 prefs::kSyncedDefaultSearchProviderGUID)); |
2273 } | 2270 } |
OLD | NEW |