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

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

Issue 10381016: Remove the "autogenerate keyword" bit on TemplateURL. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 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 "base/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "base/string_util.h" 6 #include "base/string_util.h"
7 #include "base/time.h" 7 #include "base/time.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/search_engines/search_terms_data.h"
9 #include "chrome/browser/search_engines/template_url.h" 10 #include "chrome/browser/search_engines/template_url.h"
10 #include "chrome/browser/search_engines/template_url_service.h" 11 #include "chrome/browser/search_engines/template_url_service.h"
11 #include "chrome/browser/search_engines/template_url_service_factory.h" 12 #include "chrome/browser/search_engines/template_url_service_factory.h"
12 #include "chrome/browser/search_engines/template_url_service_test_util.h" 13 #include "chrome/browser/search_engines/template_url_service_test_util.h"
13 #include "chrome/browser/sync/api/sync_error_factory.h" 14 #include "chrome/browser/sync/api/sync_error_factory.h"
14 #include "chrome/browser/sync/api/sync_error_factory_mock.h" 15 #include "chrome/browser/sync/api/sync_error_factory_mock.h"
15 #include "chrome/common/chrome_notification_types.h" 16 #include "chrome/common/chrome_notification_types.h"
16 #include "chrome/common/pref_names.h" 17 #include "chrome/common/pref_names.h"
18 #include "chrome/common/url_constants.h"
17 #include "chrome/test/base/testing_pref_service.h" 19 #include "chrome/test/base/testing_pref_service.h"
18 #include "chrome/test/base/testing_profile.h" 20 #include "chrome/test/base/testing_profile.h"
19 #include "content/public/browser/notification_service.h" 21 #include "content/public/browser/notification_service.h"
22 #include "net/base/net_util.h"
20 #include "sync/protocol/search_engine_specifics.pb.h" 23 #include "sync/protocol/search_engine_specifics.pb.h"
21 #include "sync/protocol/sync.pb.h" 24 #include "sync/protocol/sync.pb.h"
22 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
23 26
24 using base::Time; 27 using base::Time;
25 28
26 namespace { 29 namespace {
27 30
28 // Extract the GUID from a search engine SyncData. 31 // Extract the GUID from a search engine SyncData.
29 std::string GetGUID(const SyncData& sync_data) { 32 std::string GetGUID(const SyncData& sync_data) {
30 return sync_data.GetSpecifics().search_engine().sync_guid(); 33 return sync_data.GetSpecifics().search_engine().sync_guid();
31 } 34 }
32 35
33 // Extract the URL from a search engine SyncData. 36 // Extract the URL from a search engine SyncData.
34 std::string GetURL(const SyncData& sync_data) { 37 std::string GetURL(const SyncData& sync_data) {
35 return sync_data.GetSpecifics().search_engine().url(); 38 return sync_data.GetSpecifics().search_engine().url();
36 } 39 }
37 40
38 // Extract the keyword from a search engine SyncData. 41 // Extract the keyword from a search engine SyncData.
39 std::string GetKeyword(const SyncData& sync_data) { 42 std::string GetKeyword(const SyncData& sync_data) {
40 return sync_data.GetSpecifics().search_engine().keyword(); 43 return sync_data.GetSpecifics().search_engine().keyword();
41 } 44 }
42 45
43 // Much like TemplateURLService::CreateSyncDataFromTemplateURL(), but allows the 46 // Much like TemplateURLService::CreateSyncDataFromTemplateURL(), but allows the
44 // caller to override the URL or GUID fields with empty strings, in order to 47 // caller to override the keyword, URL, or GUID fields with empty strings, in
45 // create illegal data that should be DELETEd when we try to sync it to a 48 // order to create custom data that should be handled specially when synced to a
46 // client. 49 // client.
47 SyncData CreateBogusSyncData(const TemplateURL& turl, 50 SyncData CreateCustomSyncData(const TemplateURL& turl,
48 const std::string& url, 51 bool autogenerate_keyword,
49 const std::string& sync_guid) { 52 const std::string& url,
53 const std::string& sync_guid) {
50 sync_pb::EntitySpecifics specifics; 54 sync_pb::EntitySpecifics specifics;
51 sync_pb::SearchEngineSpecifics* se_specifics = 55 sync_pb::SearchEngineSpecifics* se_specifics =
52 specifics.mutable_search_engine(); 56 specifics.mutable_search_engine();
53 se_specifics->set_short_name(UTF16ToUTF8(turl.short_name())); 57 se_specifics->set_short_name(UTF16ToUTF8(turl.short_name()));
54 se_specifics->set_keyword(UTF16ToUTF8(turl.keyword())); 58 se_specifics->set_keyword(
59 autogenerate_keyword ? std::string() : UTF16ToUTF8(turl.keyword()));
55 se_specifics->set_favicon_url(turl.favicon_url().spec()); 60 se_specifics->set_favicon_url(turl.favicon_url().spec());
56 se_specifics->set_url(url); 61 se_specifics->set_url(url);
57 se_specifics->set_safe_for_autoreplace(turl.safe_for_autoreplace()); 62 se_specifics->set_safe_for_autoreplace(turl.safe_for_autoreplace());
58 se_specifics->set_originating_url(turl.originating_url().spec()); 63 se_specifics->set_originating_url(turl.originating_url().spec());
59 se_specifics->set_date_created(turl.date_created().ToInternalValue()); 64 se_specifics->set_date_created(turl.date_created().ToInternalValue());
60 se_specifics->set_input_encodings(JoinString(turl.input_encodings(), ';')); 65 se_specifics->set_input_encodings(JoinString(turl.input_encodings(), ';'));
61 se_specifics->set_show_in_default_list(turl.show_in_default_list()); 66 se_specifics->set_show_in_default_list(turl.show_in_default_list());
62 se_specifics->set_suggestions_url(turl.suggestions_url()); 67 se_specifics->set_suggestions_url(turl.suggestions_url());
63 se_specifics->set_prepopulate_id(turl.prepopulate_id()); 68 se_specifics->set_prepopulate_id(turl.prepopulate_id());
64 se_specifics->set_autogenerate_keyword(turl.autogenerate_keyword()); 69 se_specifics->set_autogenerate_keyword(autogenerate_keyword);
65 se_specifics->set_instant_url(turl.instant_url()); 70 se_specifics->set_instant_url(turl.instant_url());
66 se_specifics->set_last_modified(turl.last_modified().ToInternalValue()); 71 se_specifics->set_last_modified(turl.last_modified().ToInternalValue());
67 se_specifics->set_sync_guid(sync_guid); 72 se_specifics->set_sync_guid(sync_guid);
68 return SyncData::CreateLocalData(turl.sync_guid(), // Must be valid! 73 return SyncData::CreateLocalData(turl.sync_guid(), // Must be valid!
69 se_specifics->keyword(), specifics); 74 se_specifics->keyword(), specifics);
70 } 75 }
71 76
72 77
73 // TestChangeProcessor -------------------------------------------------------- 78 // TestChangeProcessor --------------------------------------------------------
74 79
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 TestChangeProcessor* processor() { return sync_processor_.get(); } 187 TestChangeProcessor* processor() { return sync_processor_.get(); }
183 scoped_ptr<SyncChangeProcessor> PassProcessor(); 188 scoped_ptr<SyncChangeProcessor> PassProcessor();
184 scoped_ptr<SyncErrorFactory> CreateAndPassSyncErrorFactory(); 189 scoped_ptr<SyncErrorFactory> CreateAndPassSyncErrorFactory();
185 190
186 // Create a TemplateURL with some test values. The caller owns the returned 191 // Create a TemplateURL with some test values. The caller owns the returned
187 // TemplateURL*. 192 // TemplateURL*.
188 TemplateURL* CreateTestTemplateURL(const string16& keyword, 193 TemplateURL* CreateTestTemplateURL(const string16& keyword,
189 const std::string& url, 194 const std::string& url,
190 const std::string& guid = std::string(), 195 const std::string& guid = std::string(),
191 time_t last_mod = 100, 196 time_t last_mod = 100,
192 bool created_by_policy = false) const; 197 bool created_by_policy = false,
198 bool safe_for_autoreplace = true) const;
193 199
194 // Verifies the two TemplateURLs are equal. 200 // Verifies the two TemplateURLs are equal.
195 // TODO(stevet): Share this with TemplateURLServiceTest. 201 // TODO(stevet): Share this with TemplateURLServiceTest.
196 void AssertEquals(const TemplateURL& expected, 202 void AssertEquals(const TemplateURL& expected,
197 const TemplateURL& actual) const; 203 const TemplateURL& actual) const;
198 204
199 // Expect that two SyncDataLists have equal contents, in terms of the 205 // Expect that two SyncDataLists have equal contents, in terms of the
200 // sync_guid, keyword, and url fields. 206 // sync_guid, keyword, and url fields.
201 void AssertEquals(const SyncDataList& data1, 207 void AssertEquals(const SyncDataList& data1,
202 const SyncDataList& data2) const; 208 const SyncDataList& data2) const;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 scoped_ptr<SyncErrorFactory> TemplateURLServiceSyncTest:: 263 scoped_ptr<SyncErrorFactory> TemplateURLServiceSyncTest::
258 CreateAndPassSyncErrorFactory() { 264 CreateAndPassSyncErrorFactory() {
259 return scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock()); 265 return scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock());
260 } 266 }
261 267
262 TemplateURL* TemplateURLServiceSyncTest::CreateTestTemplateURL( 268 TemplateURL* TemplateURLServiceSyncTest::CreateTestTemplateURL(
263 const string16& keyword, 269 const string16& keyword,
264 const std::string& url, 270 const std::string& url,
265 const std::string& guid, 271 const std::string& guid,
266 time_t last_mod, 272 time_t last_mod,
267 bool created_by_policy) const { 273 bool created_by_policy,
274 bool safe_for_autoreplace) const {
268 TemplateURLData data; 275 TemplateURLData data;
269 data.short_name = ASCIIToUTF16("unittest"); 276 data.short_name = ASCIIToUTF16("unittest");
270 data.SetKeyword(keyword); 277 data.SetKeyword(keyword);
271 data.SetURL(url); 278 data.SetURL(url);
272 data.favicon_url = GURL("http://favicon.url"); 279 data.favicon_url = GURL("http://favicon.url");
273 data.safe_for_autoreplace = true; 280 data.safe_for_autoreplace = safe_for_autoreplace;
274 data.date_created = Time::FromTimeT(100); 281 data.date_created = Time::FromTimeT(100);
275 data.last_modified = Time::FromTimeT(last_mod); 282 data.last_modified = Time::FromTimeT(last_mod);
276 data.created_by_policy = created_by_policy; 283 data.created_by_policy = created_by_policy;
277 data.prepopulate_id = 999999; 284 data.prepopulate_id = 999999;
278 if (!guid.empty()) 285 if (!guid.empty())
279 data.sync_guid = guid; 286 data.sync_guid = guid;
280 return new TemplateURL(NULL, data); 287 return new TemplateURL(NULL, data);
281 } 288 }
282 289
283 void TemplateURLServiceSyncTest::AssertEquals(const TemplateURL& expected, 290 void TemplateURLServiceSyncTest::AssertEquals(const TemplateURL& expected,
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 const TemplateURL* service_turl = model()->GetTemplateURLForGUID(guid); 381 const TemplateURL* service_turl = model()->GetTemplateURLForGUID(guid);
375 scoped_ptr<TemplateURL> deserialized(Deserialize(*iter)); 382 scoped_ptr<TemplateURL> deserialized(Deserialize(*iter));
376 AssertEquals(*service_turl, *deserialized); 383 AssertEquals(*service_turl, *deserialized);
377 } 384 }
378 } 385 }
379 386
380 TEST_F(TemplateURLServiceSyncTest, GetAllSyncDataNoExtensions) { 387 TEST_F(TemplateURLServiceSyncTest, GetAllSyncDataNoExtensions) {
381 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com")); 388 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com"));
382 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://key2.com")); 389 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://key2.com"));
383 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key3"), 390 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key3"),
384 "chrome-extension://blahblahblah")); 391 std::string(chrome::kExtensionScheme) + "://blahblahblah"));
385 SyncDataList all_sync_data = 392 SyncDataList all_sync_data =
386 model()->GetAllSyncData(syncable::SEARCH_ENGINES); 393 model()->GetAllSyncData(syncable::SEARCH_ENGINES);
387 394
388 EXPECT_EQ(2U, all_sync_data.size()); 395 EXPECT_EQ(2U, all_sync_data.size());
389 396
390 for (SyncDataList::const_iterator iter = all_sync_data.begin(); 397 for (SyncDataList::const_iterator iter = all_sync_data.begin();
391 iter != all_sync_data.end(); ++iter) { 398 iter != all_sync_data.end(); ++iter) {
392 std::string guid = GetGUID(*iter); 399 std::string guid = GetGUID(*iter);
393 const TemplateURL* service_turl = model()->GetTemplateURLForGUID(guid); 400 const TemplateURL* service_turl = model()->GetTemplateURLForGUID(guid);
394 scoped_ptr<TemplateURL> deserialized(Deserialize(*iter)); 401 scoped_ptr<TemplateURL> deserialized(Deserialize(*iter));
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 446
440 // Test a third collision. This should collide on both the autogenerated 447 // Test a third collision. This should collide on both the autogenerated
441 // keyword and the first uniquification attempt. 448 // keyword and the first uniquification attempt.
442 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://new.com")); 449 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://new.com"));
443 new_keyword = model()->UniquifyKeyword(*turl); 450 new_keyword = model()->UniquifyKeyword(*turl);
444 EXPECT_EQ(ASCIIToUTF16("key1__"), new_keyword); 451 EXPECT_EQ(ASCIIToUTF16("key1__"), new_keyword);
445 EXPECT_EQ(NULL, model()->GetTemplateURLForKeyword(new_keyword)); 452 EXPECT_EQ(NULL, model()->GetTemplateURLForKeyword(new_keyword));
446 } 453 }
447 454
448 TEST_F(TemplateURLServiceSyncTest, ResolveSyncKeywordConflict) { 455 TEST_F(TemplateURLServiceSyncTest, ResolveSyncKeywordConflict) {
456 // Create a keyword that conflicts, and make it older.
457 // Conflict, sync keyword is uniquified, and a SyncChange is added.
449 string16 original_turl_keyword = ASCIIToUTF16("key1"); 458 string16 original_turl_keyword = ASCIIToUTF16("key1");
450 TemplateURL* original_turl = CreateTestTemplateURL(original_turl_keyword, 459 TemplateURL* original_turl = CreateTestTemplateURL(original_turl_keyword,
451 "http://key1.com", std::string(), 9000); 460 "http://key1.com", std::string(), 9000);
452 model()->Add(original_turl); 461 model()->Add(original_turl);
453 462 scoped_ptr<TemplateURL> sync_turl(CreateTestTemplateURL(original_turl_keyword,
454 // Create a key that does not conflict with something in the model. 463 "http://new.com", "remote", 8999));
455 scoped_ptr<TemplateURL> sync_turl(
456 CreateTestTemplateURL(ASCIIToUTF16("unique"), "http://new.com"));
457 string16 sync_keyword = sync_turl->keyword();
458 SyncChangeList changes; 464 SyncChangeList changes;
459 465 model()->ResolveSyncKeywordConflict(sync_turl.get(), original_turl, &changes);
460 // No conflict, no TURLs changed, no changes.
461 EXPECT_FALSE(model()->ResolveSyncKeywordConflict(sync_turl.get(), &changes));
462 EXPECT_EQ(original_turl_keyword, original_turl->keyword());
463 EXPECT_EQ(sync_keyword, sync_turl->keyword());
464 EXPECT_EQ(0U, changes.size());
465
466 // Change sync keyword to something that conflicts, and make it older.
467 // Conflict, sync keyword is uniquified, and a SyncChange is added.
468 sync_turl.reset(CreateTestTemplateURL(original_turl_keyword, "http://new.com",
469 std::string(), 8999));
470 EXPECT_TRUE(model()->ResolveSyncKeywordConflict(sync_turl.get(), &changes));
471 EXPECT_NE(original_turl_keyword, sync_turl->keyword()); 466 EXPECT_NE(original_turl_keyword, sync_turl->keyword());
472 EXPECT_EQ(original_turl_keyword, original_turl->keyword()); 467 EXPECT_EQ(original_turl_keyword, original_turl->keyword());
473 EXPECT_EQ(1U, changes.size()); 468 ASSERT_EQ(1U, changes.size());
469 EXPECT_EQ("remote", GetGUID(changes[0].sync_data()));
474 changes.clear(); 470 changes.clear();
475 471
476 // Sync is newer. Original TemplateURL keyword is uniquified, no SyncChange 472 // Sync is newer. Original TemplateURL keyword is uniquified. A SyncChange is
477 // is added. Also ensure that this does not change the safe_for_autoreplace 473 // added (which in a normal run would be deleted by
478 // flag or the TemplateURLID in the original. 474 // PreventDuplicateGUIDUpdates() after we subsequently add an ACTION_ADD
475 // change for the local URL). Also ensure that this does not change the
476 // safe_for_autoreplace flag or the TemplateURLID in the original.
479 model()->Remove(original_turl); 477 model()->Remove(original_turl);
480 original_turl = CreateTestTemplateURL(original_turl_keyword, 478 original_turl = CreateTestTemplateURL(original_turl_keyword,
481 "http://key1.com", std::string(), 9000); 479 "http://key1.com", "local", 9000);
482 model()->Add(original_turl); 480 model()->Add(original_turl);
483 TemplateURLID original_id = original_turl->id(); 481 TemplateURLID original_id = original_turl->id();
484 sync_turl.reset(CreateTestTemplateURL(original_turl_keyword, "http://new.com", 482 sync_turl.reset(CreateTestTemplateURL(original_turl_keyword, "http://new.com",
485 std::string(), 9001)); 483 std::string(), 9001));
486 EXPECT_TRUE(model()->ResolveSyncKeywordConflict(sync_turl.get(), &changes)); 484 model()->ResolveSyncKeywordConflict(sync_turl.get(), original_turl, &changes);
487 EXPECT_EQ(original_turl_keyword, sync_turl->keyword()); 485 EXPECT_EQ(original_turl_keyword, sync_turl->keyword());
488 EXPECT_NE(original_turl_keyword, original_turl->keyword()); 486 EXPECT_NE(original_turl_keyword, original_turl->keyword());
489 EXPECT_TRUE(original_turl->safe_for_autoreplace()); 487 EXPECT_TRUE(original_turl->safe_for_autoreplace());
490 EXPECT_EQ(original_id, original_turl->id()); 488 EXPECT_EQ(original_id, original_turl->id());
491 EXPECT_EQ(NULL, model()->GetTemplateURLForKeyword(original_turl_keyword)); 489 EXPECT_EQ(NULL, model()->GetTemplateURLForKeyword(original_turl_keyword));
492 EXPECT_EQ(0U, changes.size()); 490 ASSERT_EQ(1U, changes.size());
491 EXPECT_EQ("local", GetGUID(changes[0].sync_data()));
493 changes.clear(); 492 changes.clear();
494 493
495 // Equal times. Same result as above. Sync left alone, original uniquified so 494 // Equal times. Same result as above. Sync left alone, original uniquified so
496 // sync_turl can fit. 495 // sync_turl can fit.
497 model()->Remove(original_turl); 496 model()->Remove(original_turl);
498 original_turl = CreateTestTemplateURL(original_turl_keyword, 497 original_turl = CreateTestTemplateURL(original_turl_keyword,
499 "http://key1.com", std::string(), 9000); 498 "http://key1.com", "local2", 9000);
500 model()->Add(original_turl); 499 model()->Add(original_turl);
501 sync_turl.reset(CreateTestTemplateURL(original_turl_keyword, "http://new.com", 500 sync_turl.reset(CreateTestTemplateURL(original_turl_keyword, "http://new.com",
502 std::string(), 9000)); 501 std::string(), 9000));
503 EXPECT_TRUE(model()->ResolveSyncKeywordConflict(sync_turl.get(), &changes)); 502 model()->ResolveSyncKeywordConflict(sync_turl.get(), original_turl, &changes);
504 EXPECT_EQ(original_turl_keyword, sync_turl->keyword()); 503 EXPECT_EQ(original_turl_keyword, sync_turl->keyword());
505 EXPECT_NE(original_turl_keyword, original_turl->keyword()); 504 EXPECT_NE(original_turl_keyword, original_turl->keyword());
506 EXPECT_EQ(NULL, model()->GetTemplateURLForKeyword(original_turl_keyword)); 505 EXPECT_EQ(NULL, model()->GetTemplateURLForKeyword(original_turl_keyword));
507 EXPECT_EQ(0U, changes.size()); 506 ASSERT_EQ(1U, changes.size());
507 EXPECT_EQ("local2", GetGUID(changes[0].sync_data()));
508 changes.clear(); 508 changes.clear();
509 509
510 // Sync is newer, but original TemplateURL is created by policy, so it wins. 510 // Sync is newer, but original TemplateURL is created by policy, so it wins.
511 // Sync keyword is uniquified, and a SyncChange is added. 511 // Sync keyword is uniquified, and a SyncChange is added.
512 model()->Remove(original_turl); 512 model()->Remove(original_turl);
513 original_turl = CreateTestTemplateURL(original_turl_keyword, 513 original_turl = CreateTestTemplateURL(original_turl_keyword,
514 "http://key1.com", std::string(), 9000, true); 514 "http://key1.com", std::string(), 9000, true);
515 model()->Add(original_turl); 515 model()->Add(original_turl);
516 sync_turl.reset(CreateTestTemplateURL(original_turl_keyword, "http://new.com", 516 sync_turl.reset(CreateTestTemplateURL(original_turl_keyword, "http://new.com",
517 std::string(), 9999)); 517 "remote2", 9999));
518 EXPECT_TRUE(model()->ResolveSyncKeywordConflict(sync_turl.get(), &changes)); 518 model()->ResolveSyncKeywordConflict(sync_turl.get(), original_turl, &changes);
519 EXPECT_NE(original_turl_keyword, sync_turl->keyword()); 519 EXPECT_NE(original_turl_keyword, sync_turl->keyword());
520 EXPECT_EQ(original_turl_keyword, original_turl->keyword()); 520 EXPECT_EQ(original_turl_keyword, original_turl->keyword());
521 EXPECT_EQ(NULL, model()->GetTemplateURLForKeyword(sync_turl->keyword())); 521 EXPECT_EQ(NULL, model()->GetTemplateURLForKeyword(sync_turl->keyword()));
522 EXPECT_EQ(1U, changes.size()); 522 ASSERT_EQ(1U, changes.size());
523 EXPECT_EQ("remote2", GetGUID(changes[0].sync_data()));
523 changes.clear(); 524 changes.clear();
524 } 525 }
525 526
526 TEST_F(TemplateURLServiceSyncTest, FindDuplicateOfSyncTemplateURL) { 527 TEST_F(TemplateURLServiceSyncTest, FindDuplicateOfSyncTemplateURL) {
527 TemplateURL* original_turl = 528 TemplateURL* original_turl =
528 CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com"); 529 CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com");
529 model()->Add(original_turl); 530 model()->Add(original_turl);
530 531
531 // No matches at all. 532 // No matches at all.
532 scoped_ptr<TemplateURL> sync_turl(CreateTestTemplateURL(ASCIIToUTF16("key2"), 533 scoped_ptr<TemplateURL> sync_turl(CreateTestTemplateURL(ASCIIToUTF16("key2"),
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 TemplateURL* sync_turl2 = CreateTestTemplateURL(ASCIIToUTF16("key1"), 575 TemplateURL* sync_turl2 = CreateTestTemplateURL(ASCIIToUTF16("key1"),
575 "http://key1.com", std::string(), 8999); 576 "http://key1.com", std::string(), 8999);
576 model()->MergeSyncAndLocalURLDuplicates(sync_turl2, sync_turl, &changes); 577 model()->MergeSyncAndLocalURLDuplicates(sync_turl2, sync_turl, &changes);
577 result = model()->GetTemplateURLForKeyword(ASCIIToUTF16("key1")); 578 result = model()->GetTemplateURLForKeyword(ASCIIToUTF16("key1"));
578 ASSERT_TRUE(result); 579 ASSERT_TRUE(result);
579 EXPECT_EQ(9001, result->last_modified().ToTimeT()); 580 EXPECT_EQ(9001, result->last_modified().ToTimeT());
580 EXPECT_EQ(1U, changes.size()); 581 EXPECT_EQ(1U, changes.size());
581 } 582 }
582 583
583 TEST_F(TemplateURLServiceSyncTest, StartSyncEmpty) { 584 TEST_F(TemplateURLServiceSyncTest, StartSyncEmpty) {
584 model()->MergeDataAndStartSyncing( 585 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, SyncDataList(),
585 syncable::SEARCH_ENGINES, SyncDataList(), 586 PassProcessor(), CreateAndPassSyncErrorFactory());
586 PassProcessor(),
587 CreateAndPassSyncErrorFactory());
588 587
589 EXPECT_EQ(0U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); 588 EXPECT_EQ(0U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size());
590 EXPECT_EQ(0U, processor()->change_list_size()); 589 EXPECT_EQ(0U, processor()->change_list_size());
591 } 590 }
592 591
593 TEST_F(TemplateURLServiceSyncTest, MergeIntoEmpty) { 592 TEST_F(TemplateURLServiceSyncTest, MergeIntoEmpty) {
594 SyncDataList initial_data = CreateInitialSyncData(); 593 SyncDataList initial_data = CreateInitialSyncData();
595 594
596 model()->MergeDataAndStartSyncing( 595 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data,
597 syncable::SEARCH_ENGINES, initial_data, 596 PassProcessor(), CreateAndPassSyncErrorFactory());
598 PassProcessor(),
599 CreateAndPassSyncErrorFactory());
600 597
601 EXPECT_EQ(3U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); 598 EXPECT_EQ(3U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size());
602 // We expect the model to have accepted all of the initial sync data. Search 599 // We expect the model to have accepted all of the initial sync data. Search
603 // through the model using the GUIDs to ensure that they're present. 600 // through the model using the GUIDs to ensure that they're present.
604 for (SyncDataList::const_iterator iter = initial_data.begin(); 601 for (SyncDataList::const_iterator iter = initial_data.begin();
605 iter != initial_data.end(); ++iter) { 602 iter != initial_data.end(); ++iter) {
606 std::string guid = GetGUID(*iter); 603 std::string guid = GetGUID(*iter);
607 EXPECT_TRUE(model()->GetTemplateURLForGUID(guid)); 604 EXPECT_TRUE(model()->GetTemplateURLForGUID(guid));
608 } 605 }
609 606
610 EXPECT_EQ(0U, processor()->change_list_size()); 607 EXPECT_EQ(0U, processor()->change_list_size());
611 } 608 }
612 609
613 TEST_F(TemplateURLServiceSyncTest, MergeInAllNewData) { 610 TEST_F(TemplateURLServiceSyncTest, MergeInAllNewData) {
614 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("google.com"), 611 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("abc.com"), "http://abc.com",
615 "http://google.com", "abc")); 612 "abc"));
616 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("yahoo.com"), 613 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("def.com"), "http://def.com",
617 "http://yahoo.com", "def")); 614 "def"));
618 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("bing.com"), 615 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("xyz.com"), "http://xyz.com",
619 "http://bing.com", "xyz")); 616 "xyz"));
620 SyncDataList initial_data = CreateInitialSyncData(); 617 SyncDataList initial_data = CreateInitialSyncData();
621 618
622 model()->MergeDataAndStartSyncing( 619 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data,
623 syncable::SEARCH_ENGINES, initial_data, 620 PassProcessor(), CreateAndPassSyncErrorFactory());
624 PassProcessor(),
625 CreateAndPassSyncErrorFactory());
626 621
627 EXPECT_EQ(6U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); 622 EXPECT_EQ(6U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size());
628 // We expect the model to have accepted all of the initial sync data. Search 623 // We expect the model to have accepted all of the initial sync data. Search
629 // through the model using the GUIDs to ensure that they're present. 624 // through the model using the GUIDs to ensure that they're present.
630 for (SyncDataList::const_iterator iter = initial_data.begin(); 625 for (SyncDataList::const_iterator iter = initial_data.begin();
631 iter != initial_data.end(); ++iter) { 626 iter != initial_data.end(); ++iter) {
632 std::string guid = GetGUID(*iter); 627 std::string guid = GetGUID(*iter);
633 EXPECT_TRUE(model()->GetTemplateURLForGUID(guid)); 628 EXPECT_TRUE(model()->GetTemplateURLForGUID(guid));
634 } 629 }
635 // All the original TemplateURLs should also remain in the model. 630 // All the original TemplateURLs should also remain in the model.
636 EXPECT_TRUE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("google.com"))); 631 EXPECT_TRUE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("abc.com")));
637 EXPECT_TRUE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("yahoo.com"))); 632 EXPECT_TRUE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("def.com")));
638 EXPECT_TRUE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("bing.com"))); 633 EXPECT_TRUE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("xyz.com")));
639 // Ensure that Sync received the expected changes. 634 // Ensure that Sync received the expected changes.
640 EXPECT_EQ(3U, processor()->change_list_size()); 635 EXPECT_EQ(3U, processor()->change_list_size());
641 EXPECT_TRUE(processor()->contains_guid("abc")); 636 EXPECT_TRUE(processor()->contains_guid("abc"));
642 EXPECT_TRUE(processor()->contains_guid("def")); 637 EXPECT_TRUE(processor()->contains_guid("def"));
643 EXPECT_TRUE(processor()->contains_guid("xyz")); 638 EXPECT_TRUE(processor()->contains_guid("xyz"));
644 } 639 }
645 640
646 TEST_F(TemplateURLServiceSyncTest, MergeSyncIsTheSame) { 641 TEST_F(TemplateURLServiceSyncTest, MergeSyncIsTheSame) {
647 // The local data is the same as the sync data merged in. i.e. - There have 642 // The local data is the same as the sync data merged in. i.e. - There have
648 // been no changes since the last time we synced. Even the last_modified 643 // been no changes since the last time we synced. Even the last_modified
649 // timestamps are the same. 644 // timestamps are the same.
650 SyncDataList initial_data = CreateInitialSyncData(); 645 SyncDataList initial_data = CreateInitialSyncData();
651 for (SyncDataList::const_iterator iter = initial_data.begin(); 646 for (SyncDataList::const_iterator iter = initial_data.begin();
652 iter != initial_data.end(); ++iter) { 647 iter != initial_data.end(); ++iter) {
653 TemplateURL* converted = Deserialize(*iter); 648 TemplateURL* converted = Deserialize(*iter);
654 model()->Add(converted); 649 model()->Add(converted);
655 } 650 }
656 651
657 model()->MergeDataAndStartSyncing( 652 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data,
658 syncable::SEARCH_ENGINES, initial_data, 653 PassProcessor(), CreateAndPassSyncErrorFactory());
659 PassProcessor(),
660 CreateAndPassSyncErrorFactory());
661 654
662 EXPECT_EQ(3U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); 655 EXPECT_EQ(3U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size());
663 for (SyncDataList::const_iterator iter = initial_data.begin(); 656 for (SyncDataList::const_iterator iter = initial_data.begin();
664 iter != initial_data.end(); ++iter) { 657 iter != initial_data.end(); ++iter) {
665 std::string guid = GetGUID(*iter); 658 std::string guid = GetGUID(*iter);
666 EXPECT_TRUE(model()->GetTemplateURLForGUID(guid)); 659 EXPECT_TRUE(model()->GetTemplateURLForGUID(guid));
667 } 660 }
668 EXPECT_EQ(0U, processor()->change_list_size()); 661 EXPECT_EQ(0U, processor()->change_list_size());
669 } 662 }
670 663
671 TEST_F(TemplateURLServiceSyncTest, MergeUpdateFromSync) { 664 TEST_F(TemplateURLServiceSyncTest, MergeUpdateFromSync) {
672 // The local data is the same as the sync data merged in, but timestamps have 665 // The local data is the same as the sync data merged in, but timestamps have
673 // changed. Ensure the right fields are merged in. 666 // changed. Ensure the right fields are merged in.
674 SyncDataList initial_data; 667 SyncDataList initial_data;
675 TemplateURL* turl1 = CreateTestTemplateURL(ASCIIToUTF16("google.com"), 668 TemplateURL* turl1 = CreateTestTemplateURL(ASCIIToUTF16("abc.com"),
676 "http://google.com", "abc", 9000); 669 "http://abc.com", "abc", 9000);
677 model()->Add(turl1); 670 model()->Add(turl1);
678 TemplateURL* turl2 = CreateTestTemplateURL(ASCIIToUTF16("bing.com"), 671 TemplateURL* turl2 = CreateTestTemplateURL(ASCIIToUTF16("xyz.com"),
679 "http://bing.com", "xyz", 9000); 672 "http://xyz.com", "xyz", 9000);
680 model()->Add(turl2); 673 model()->Add(turl2);
681 674
682 scoped_ptr<TemplateURL> turl1_newer(CreateTestTemplateURL( 675 scoped_ptr<TemplateURL> turl1_newer(CreateTestTemplateURL(
683 ASCIIToUTF16("google.com"), "http://google.ca", "abc", 9999)); 676 ASCIIToUTF16("abc.com"), "http://abc.ca", "abc", 9999));
684 initial_data.push_back( 677 initial_data.push_back(
685 TemplateURLService::CreateSyncDataFromTemplateURL(*turl1_newer)); 678 TemplateURLService::CreateSyncDataFromTemplateURL(*turl1_newer));
686 679
687 scoped_ptr<TemplateURL> turl2_older(CreateTestTemplateURL( 680 scoped_ptr<TemplateURL> turl2_older(CreateTestTemplateURL(
688 ASCIIToUTF16("bing.com"), "http://bing.ca", "xyz", 8888)); 681 ASCIIToUTF16("xyz.com"), "http://xyz.ca", "xyz", 8888));
689 initial_data.push_back( 682 initial_data.push_back(
690 TemplateURLService::CreateSyncDataFromTemplateURL(*turl2_older)); 683 TemplateURLService::CreateSyncDataFromTemplateURL(*turl2_older));
691 684
692 model()->MergeDataAndStartSyncing( 685 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data,
693 syncable::SEARCH_ENGINES, initial_data, 686 PassProcessor(), CreateAndPassSyncErrorFactory());
694 PassProcessor(),
695 CreateAndPassSyncErrorFactory());
696 687
697 // Both were local updates, so we expect the same count. 688 // Both were local updates, so we expect the same count.
698 EXPECT_EQ(2U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); 689 EXPECT_EQ(2U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size());
699 690
700 // Check that the first replaced the initial Google TemplateURL. 691 // Check that the first replaced the initial abc TemplateURL.
701 EXPECT_EQ(turl1, model()->GetTemplateURLForGUID("abc")); 692 EXPECT_EQ(turl1, model()->GetTemplateURLForGUID("abc"));
702 EXPECT_EQ("http://google.ca", turl1->url()); 693 EXPECT_EQ("http://abc.ca", turl1->url());
703 694
704 // Check that the second produced an upstream update to the Bing TemplateURL. 695 // Check that the second produced an upstream update to the xyz TemplateURL.
705 EXPECT_EQ(1U, processor()->change_list_size()); 696 EXPECT_EQ(1U, processor()->change_list_size());
706 ASSERT_TRUE(processor()->contains_guid("xyz")); 697 ASSERT_TRUE(processor()->contains_guid("xyz"));
707 SyncChange change = processor()->change_for_guid("xyz"); 698 SyncChange change = processor()->change_for_guid("xyz");
708 EXPECT_TRUE(change.change_type() == SyncChange::ACTION_UPDATE); 699 EXPECT_TRUE(change.change_type() == SyncChange::ACTION_UPDATE);
709 EXPECT_EQ("http://bing.com", GetURL(change.sync_data())); 700 EXPECT_EQ("http://xyz.com", GetURL(change.sync_data()));
710 } 701 }
711 702
712 TEST_F(TemplateURLServiceSyncTest, MergeAddFromOlderSyncData) { 703 TEST_F(TemplateURLServiceSyncTest, MergeAddFromOlderSyncData) {
713 // GUIDs all differ, so this is data to be added from Sync, but the timestamps 704 // GUIDs all differ, so this is data to be added from Sync, but the timestamps
714 // from Sync are older. Set up the local data so that one is a dupe, one has a 705 // from Sync are older. Set up the local data so that one is a dupe, one has a
715 // conflicting keyword, and the last has no conflicts (a clean ADD). 706 // conflicting keyword, and the last has no conflicts (a clean ADD).
716 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com", 707 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com",
717 "aaa", 100)); // dupe 708 "aaa", 100)); // dupe
718 709
719 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key2"), 710 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key2"),
720 "http://expected.com", "bbb", 100)); // keyword conflict 711 "http://expected.com", "bbb", 100)); // keyword conflict
721 712
722 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("unique"), 713 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("unique"),
723 "http://unique.com", "ccc")); // add 714 "http://unique.com", "ccc")); // add
724 715
725 model()->MergeDataAndStartSyncing( 716 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES,
726 syncable::SEARCH_ENGINES, CreateInitialSyncData(), 717 CreateInitialSyncData(), PassProcessor(),
727 PassProcessor(), 718 CreateAndPassSyncErrorFactory());
728 CreateAndPassSyncErrorFactory());
729 719
730 // The dupe results in a merge. The other two should be added to the model. 720 // The dupe results in a merge. The other two should be added to the model.
731 EXPECT_EQ(5U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); 721 EXPECT_EQ(5U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size());
732 722
733 // The key1 duplicate results in the local copy winning. Ensure that Sync's 723 // The key1 duplicate results in the local copy winning. Ensure that Sync's
734 // copy was not added, and the local copy is pushed upstream to Sync as an 724 // copy was not added, and the local copy is pushed upstream to Sync as an
735 // update. The local copy should have received the sync data's GUID. 725 // update. The local copy should have received the sync data's GUID.
736 EXPECT_TRUE(model()->GetTemplateURLForGUID("key1")); 726 EXPECT_TRUE(model()->GetTemplateURLForGUID("key1"));
737 // Check changes for the UPDATE. 727 // Check changes for the UPDATE.
738 ASSERT_TRUE(processor()->contains_guid("key1")); 728 ASSERT_TRUE(processor()->contains_guid("key1"));
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
775 // conflicting keyword, and the last has no conflicts (a clean ADD). 765 // conflicting keyword, and the last has no conflicts (a clean ADD).
776 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com", 766 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com",
777 "aaa", 10)); // dupe 767 "aaa", 10)); // dupe
778 768
779 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key2"), 769 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key2"),
780 "http://expected.com", "bbb", 10)); // keyword conflict 770 "http://expected.com", "bbb", 10)); // keyword conflict
781 771
782 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("unique"), 772 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("unique"),
783 "http://unique.com", "ccc", 10)); // add 773 "http://unique.com", "ccc", 10)); // add
784 774
785 model()->MergeDataAndStartSyncing( 775 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES,
786 syncable::SEARCH_ENGINES, 776 CreateInitialSyncData(), PassProcessor(),
787 CreateInitialSyncData(), 777 CreateAndPassSyncErrorFactory());
788 PassProcessor(),
789 CreateAndPassSyncErrorFactory());
790 778
791 // The dupe results in a merge. The other two should be added to the model. 779 // The dupe results in a merge. The other two should be added to the model.
792 EXPECT_EQ(5U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); 780 EXPECT_EQ(5U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size());
793 781
794 // The key1 duplicate results in Sync's copy winning. Ensure that Sync's 782 // The key1 duplicate results in Sync's copy winning. Ensure that Sync's
795 // copy replaced the local copy. 783 // copy replaced the local copy.
796 EXPECT_TRUE(model()->GetTemplateURLForGUID("key1")); 784 EXPECT_TRUE(model()->GetTemplateURLForGUID("key1"));
797 EXPECT_FALSE(model()->GetTemplateURLForGUID("aaa")); 785 EXPECT_FALSE(model()->GetTemplateURLForGUID("aaa"));
798 786
799 // The key2 keyword conflict results in Sync's copy winning, so ensure it 787 // The key2 keyword conflict results in Sync's copy winning, so ensure it
(...skipping 17 matching lines...) Expand all
817 ASSERT_TRUE(processor()->contains_guid("bbb")); 805 ASSERT_TRUE(processor()->contains_guid("bbb"));
818 EXPECT_EQ(SyncChange::ACTION_ADD, 806 EXPECT_EQ(SyncChange::ACTION_ADD,
819 processor()->change_for_guid("bbb").change_type()); 807 processor()->change_for_guid("bbb").change_type());
820 ASSERT_TRUE(processor()->contains_guid("ccc")); 808 ASSERT_TRUE(processor()->contains_guid("ccc"));
821 EXPECT_EQ(SyncChange::ACTION_ADD, 809 EXPECT_EQ(SyncChange::ACTION_ADD,
822 processor()->change_for_guid("ccc").change_type()); 810 processor()->change_for_guid("ccc").change_type());
823 } 811 }
824 812
825 TEST_F(TemplateURLServiceSyncTest, ProcessChangesEmptyModel) { 813 TEST_F(TemplateURLServiceSyncTest, ProcessChangesEmptyModel) {
826 // We initially have no data. 814 // We initially have no data.
827 model()->MergeDataAndStartSyncing( 815 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, SyncDataList(),
828 syncable::SEARCH_ENGINES, SyncDataList(), 816 PassProcessor(), CreateAndPassSyncErrorFactory());
829 PassProcessor(),
830 CreateAndPassSyncErrorFactory());
831 817
832 // Set up a bunch of ADDs. 818 // Set up a bunch of ADDs.
833 SyncChangeList changes; 819 SyncChangeList changes;
834 changes.push_back(CreateTestSyncChange(SyncChange::ACTION_ADD, 820 changes.push_back(CreateTestSyncChange(SyncChange::ACTION_ADD,
835 CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com", "key1"))); 821 CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com", "key1")));
836 changes.push_back(CreateTestSyncChange(SyncChange::ACTION_ADD, 822 changes.push_back(CreateTestSyncChange(SyncChange::ACTION_ADD,
837 CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://key2.com", "key2"))); 823 CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://key2.com", "key2")));
838 changes.push_back(CreateTestSyncChange(SyncChange::ACTION_ADD, 824 changes.push_back(CreateTestSyncChange(SyncChange::ACTION_ADD,
839 CreateTestTemplateURL(ASCIIToUTF16("key3"), "http://key3.com", "key3"))); 825 CreateTestTemplateURL(ASCIIToUTF16("key3"), "http://key3.com", "key3")));
840 826
841 model()->ProcessSyncChanges(FROM_HERE, changes); 827 model()->ProcessSyncChanges(FROM_HERE, changes);
842 828
843 EXPECT_EQ(3U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); 829 EXPECT_EQ(3U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size());
844 EXPECT_EQ(0U, processor()->change_list_size()); 830 EXPECT_EQ(0U, processor()->change_list_size());
845 EXPECT_TRUE(model()->GetTemplateURLForGUID("key1")); 831 EXPECT_TRUE(model()->GetTemplateURLForGUID("key1"));
846 EXPECT_TRUE(model()->GetTemplateURLForGUID("key2")); 832 EXPECT_TRUE(model()->GetTemplateURLForGUID("key2"));
847 EXPECT_TRUE(model()->GetTemplateURLForGUID("key3")); 833 EXPECT_TRUE(model()->GetTemplateURLForGUID("key3"));
848 } 834 }
849 835
850 TEST_F(TemplateURLServiceSyncTest, ProcessChangesNoConflicts) { 836 TEST_F(TemplateURLServiceSyncTest, ProcessChangesNoConflicts) {
851 model()->MergeDataAndStartSyncing( 837 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES,
852 syncable::SEARCH_ENGINES, 838 CreateInitialSyncData(), PassProcessor(),
853 CreateInitialSyncData(), PassProcessor(), 839 CreateAndPassSyncErrorFactory());
854 CreateAndPassSyncErrorFactory());
855 840
856 // Process different types of changes, without conflicts. 841 // Process different types of changes, without conflicts.
857 SyncChangeList changes; 842 SyncChangeList changes;
858 changes.push_back(CreateTestSyncChange(SyncChange::ACTION_ADD, 843 changes.push_back(CreateTestSyncChange(SyncChange::ACTION_ADD,
859 CreateTestTemplateURL(ASCIIToUTF16("key4"), "http://key4.com", "key4"))); 844 CreateTestTemplateURL(ASCIIToUTF16("key4"), "http://key4.com", "key4")));
860 changes.push_back(CreateTestSyncChange(SyncChange::ACTION_UPDATE, 845 changes.push_back(CreateTestSyncChange(SyncChange::ACTION_UPDATE,
861 CreateTestTemplateURL(ASCIIToUTF16("newkeyword"), "http://new.com", 846 CreateTestTemplateURL(ASCIIToUTF16("newkeyword"), "http://new.com",
862 "key2"))); 847 "key2")));
863 changes.push_back(CreateTestSyncChange(SyncChange::ACTION_DELETE, 848 changes.push_back(CreateTestSyncChange(SyncChange::ACTION_DELETE,
864 CreateTestTemplateURL(ASCIIToUTF16("key3"), "http://key3.com", "key3"))); 849 CreateTestTemplateURL(ASCIIToUTF16("key3"), "http://key3.com", "key3")));
865 850
866 model()->ProcessSyncChanges(FROM_HERE, changes); 851 model()->ProcessSyncChanges(FROM_HERE, changes);
867 852
868 // Add one, remove one, update one, so the number shouldn't change. 853 // Add one, remove one, update one, so the number shouldn't change.
869 EXPECT_EQ(3U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); 854 EXPECT_EQ(3U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size());
870 EXPECT_EQ(0U, processor()->change_list_size()); 855 EXPECT_EQ(0U, processor()->change_list_size());
871 EXPECT_TRUE(model()->GetTemplateURLForGUID("key1")); 856 EXPECT_TRUE(model()->GetTemplateURLForGUID("key1"));
872 EXPECT_TRUE(model()->GetTemplateURLForGUID("key2")); 857 EXPECT_TRUE(model()->GetTemplateURLForGUID("key2"));
873 const TemplateURL* turl = model()->GetTemplateURLForGUID("key2"); 858 const TemplateURL* turl = model()->GetTemplateURLForGUID("key2");
874 EXPECT_TRUE(turl); 859 EXPECT_TRUE(turl);
875 EXPECT_EQ(ASCIIToUTF16("newkeyword"), turl->keyword()); 860 EXPECT_EQ(ASCIIToUTF16("newkeyword"), turl->keyword());
876 EXPECT_EQ("http://new.com", turl->url()); 861 EXPECT_EQ("http://new.com", turl->url());
877 EXPECT_FALSE(model()->GetTemplateURLForGUID("key3")); 862 EXPECT_FALSE(model()->GetTemplateURLForGUID("key3"));
878 EXPECT_TRUE(model()->GetTemplateURLForGUID("key4")); 863 EXPECT_TRUE(model()->GetTemplateURLForGUID("key4"));
879 } 864 }
880 865
881 TEST_F(TemplateURLServiceSyncTest, ProcessChangesWithConflictsSyncWins) { 866 TEST_F(TemplateURLServiceSyncTest, ProcessChangesWithConflictsSyncWins) {
882 model()->MergeDataAndStartSyncing( 867 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES,
883 syncable::SEARCH_ENGINES, 868 CreateInitialSyncData(), PassProcessor(),
884 CreateInitialSyncData(), PassProcessor(), 869 CreateAndPassSyncErrorFactory());
885 CreateAndPassSyncErrorFactory());
886 870
887 // Process different types of changes, with conflicts. Note that all this data 871 // Process different types of changes, with conflicts. Note that all this data
888 // has a newer timestamp, so Sync will win in these scenarios. 872 // has a newer timestamp, so Sync will win in these scenarios.
889 SyncChangeList changes; 873 SyncChangeList changes;
890 changes.push_back(CreateTestSyncChange(SyncChange::ACTION_ADD, 874 changes.push_back(CreateTestSyncChange(SyncChange::ACTION_ADD,
891 CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://new.com", "aaa"))); 875 CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://new.com", "aaa")));
892 changes.push_back(CreateTestSyncChange(SyncChange::ACTION_UPDATE, 876 changes.push_back(CreateTestSyncChange(SyncChange::ACTION_UPDATE,
893 CreateTestTemplateURL(ASCIIToUTF16("key3"), "http://key3.com", "key1"))); 877 CreateTestTemplateURL(ASCIIToUTF16("key3"), "http://key3.com", "key1")));
894 878
895 model()->ProcessSyncChanges(FROM_HERE, changes); 879 model()->ProcessSyncChanges(FROM_HERE, changes);
(...skipping 14 matching lines...) Expand all
910 // key1 update conflicts with key3 and wins, forcing key3's keyword to update. 894 // key1 update conflicts with key3 and wins, forcing key3's keyword to update.
911 EXPECT_TRUE(model()->GetTemplateURLForGUID("key1")); 895 EXPECT_TRUE(model()->GetTemplateURLForGUID("key1"));
912 EXPECT_EQ(model()->GetTemplateURLForGUID("key1"), 896 EXPECT_EQ(model()->GetTemplateURLForGUID("key1"),
913 model()->GetTemplateURLForKeyword(ASCIIToUTF16("key3"))); 897 model()->GetTemplateURLForKeyword(ASCIIToUTF16("key3")));
914 EXPECT_TRUE(model()->GetTemplateURLForGUID("key3")); 898 EXPECT_TRUE(model()->GetTemplateURLForGUID("key3"));
915 EXPECT_EQ(model()->GetTemplateURLForGUID("key3"), 899 EXPECT_EQ(model()->GetTemplateURLForGUID("key3"),
916 model()->GetTemplateURLForKeyword(ASCIIToUTF16("key3.com"))); 900 model()->GetTemplateURLForKeyword(ASCIIToUTF16("key3.com")));
917 } 901 }
918 902
919 TEST_F(TemplateURLServiceSyncTest, ProcessChangesWithConflictsLocalWins) { 903 TEST_F(TemplateURLServiceSyncTest, ProcessChangesWithConflictsLocalWins) {
920 model()->MergeDataAndStartSyncing( 904 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES,
921 syncable::SEARCH_ENGINES, 905 CreateInitialSyncData(), PassProcessor(),
922 CreateInitialSyncData(), PassProcessor(), 906 CreateAndPassSyncErrorFactory());
923 CreateAndPassSyncErrorFactory());
924 907
925 // Process different types of changes, with conflicts. Note that all this data 908 // Process different types of changes, with conflicts. Note that all this data
926 // has an older timestamp, so the local data will win in these scenarios. 909 // has an older timestamp, so the local data will win in these scenarios.
927 SyncChangeList changes; 910 SyncChangeList changes;
928 changes.push_back(CreateTestSyncChange(SyncChange::ACTION_ADD, 911 changes.push_back(CreateTestSyncChange(SyncChange::ACTION_ADD,
929 CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://new.com", "aaa", 912 CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://new.com", "aaa",
930 10))); 913 10)));
931 changes.push_back(CreateTestSyncChange(SyncChange::ACTION_UPDATE, 914 changes.push_back(CreateTestSyncChange(SyncChange::ACTION_UPDATE,
932 CreateTestTemplateURL(ASCIIToUTF16("key3"), "http://key3.com", "key1", 915 CreateTestTemplateURL(ASCIIToUTF16("key3"), "http://key3.com", "key1",
933 10))); 916 10)));
(...skipping 25 matching lines...) Expand all
959 EXPECT_EQ(SyncChange::ACTION_UPDATE, 942 EXPECT_EQ(SyncChange::ACTION_UPDATE,
960 processor()->change_for_guid("aaa").change_type()); 943 processor()->change_for_guid("aaa").change_type());
961 ASSERT_TRUE(processor()->contains_guid("key1")); 944 ASSERT_TRUE(processor()->contains_guid("key1"));
962 EXPECT_EQ(SyncChange::ACTION_UPDATE, 945 EXPECT_EQ(SyncChange::ACTION_UPDATE,
963 processor()->change_for_guid("key1").change_type()); 946 processor()->change_for_guid("key1").change_type());
964 } 947 }
965 948
966 TEST_F(TemplateURLServiceSyncTest, ProcessTemplateURLChange) { 949 TEST_F(TemplateURLServiceSyncTest, ProcessTemplateURLChange) {
967 // Ensure that ProcessTemplateURLChange is called and pushes the correct 950 // Ensure that ProcessTemplateURLChange is called and pushes the correct
968 // changes to Sync whenever local changes are made to TemplateURLs. 951 // changes to Sync whenever local changes are made to TemplateURLs.
969 model()->MergeDataAndStartSyncing( 952 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES,
970 syncable::SEARCH_ENGINES, 953 CreateInitialSyncData(), PassProcessor(),
971 CreateInitialSyncData(), PassProcessor(), 954 CreateAndPassSyncErrorFactory());
972 CreateAndPassSyncErrorFactory());
973 955
974 // Add a new search engine. 956 // Add a new search engine.
975 TemplateURL* new_turl = 957 TemplateURL* new_turl =
976 CreateTestTemplateURL(ASCIIToUTF16("baidu"), "http://baidu.cn", "new"); 958 CreateTestTemplateURL(ASCIIToUTF16("baidu"), "http://baidu.cn", "new");
977 model()->Add(new_turl); 959 model()->Add(new_turl);
978 EXPECT_EQ(1U, processor()->change_list_size()); 960 EXPECT_EQ(1U, processor()->change_list_size());
979 ASSERT_TRUE(processor()->contains_guid("new")); 961 ASSERT_TRUE(processor()->contains_guid("new"));
980 SyncChange change = processor()->change_for_guid("new"); 962 SyncChange change = processor()->change_for_guid("new");
981 EXPECT_EQ(SyncChange::ACTION_ADD, change.change_type()); 963 EXPECT_EQ(SyncChange::ACTION_ADD, change.change_type());
982 EXPECT_EQ("baidu", GetKeyword(change.sync_data())); 964 EXPECT_EQ("baidu", GetKeyword(change.sync_data()));
(...skipping 11 matching lines...) Expand all
994 976
995 // Remove an existing search engine. 977 // Remove an existing search engine.
996 existing_turl = model()->GetTemplateURLForGUID("key2"); 978 existing_turl = model()->GetTemplateURLForGUID("key2");
997 model()->Remove(existing_turl); 979 model()->Remove(existing_turl);
998 EXPECT_EQ(1U, processor()->change_list_size()); 980 EXPECT_EQ(1U, processor()->change_list_size());
999 ASSERT_TRUE(processor()->contains_guid("key2")); 981 ASSERT_TRUE(processor()->contains_guid("key2"));
1000 change = processor()->change_for_guid("key2"); 982 change = processor()->change_for_guid("key2");
1001 EXPECT_EQ(SyncChange::ACTION_DELETE, change.change_type()); 983 EXPECT_EQ(SyncChange::ACTION_DELETE, change.change_type());
1002 } 984 }
1003 985
986 TEST_F(TemplateURLServiceSyncTest, ProcessChangesWithLocalExtensions) {
987 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES,
988 CreateInitialSyncData(), PassProcessor(),
989 CreateAndPassSyncErrorFactory());
990
991 // Add some extension keywords locally. These shouldn't be synced.
992 TemplateURL* extension1 = CreateTestTemplateURL(ASCIIToUTF16("keyword1"),
993 std::string(chrome::kExtensionScheme) + "://extension1");
994 model()->Add(extension1);
995 TemplateURL* extension2 = CreateTestTemplateURL(ASCIIToUTF16("keyword2"),
996 std::string(chrome::kExtensionScheme) + "://extension2");
997 model()->Add(extension2);
998 EXPECT_EQ(0U, processor()->change_list_size());
999
1000 // Create some sync changes that will conflict with the extension keywords.
1001 SyncChangeList changes;
1002 changes.push_back(CreateTestSyncChange(SyncChange::ACTION_ADD,
1003 CreateTestTemplateURL(ASCIIToUTF16("keyword1"), "http://aaa.com")));
1004 changes.push_back(CreateTestSyncChange(SyncChange::ACTION_ADD,
1005 CreateTestTemplateURL(ASCIIToUTF16("keyword2"), "http://bbb.com",
1006 std::string(), 100, false, false)));
1007 model()->ProcessSyncChanges(FROM_HERE, changes);
1008
1009 // The synced keywords should be added unchanged, and the result of
1010 // GetTemplateURLForKeyword() for each keyword should depend on whether the
1011 // synced keyword is replaceable or not.
1012 EXPECT_EQ(extension1,
1013 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword1")));
1014 EXPECT_FALSE(model()->GetTemplateURLForHost("aaa.com") == NULL);
1015 TemplateURL* url_for_keyword2 =
1016 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword2"));
1017 EXPECT_NE(extension2, url_for_keyword2);
1018 EXPECT_EQ("http://bbb.com", url_for_keyword2->url());
1019 // Note that extensions don't use host-based keywords, so we can't check that
1020 // |extension2| is still in the model using GetTemplateURLForHost(); and we
1021 // have to create a full-fledged Extension to use
1022 // GetTemplateURLForExtension(), which is annoying, so just grab all the URLs
1023 // from the model and search for |extension2| within them.
1024 TemplateURLService::TemplateURLVector template_urls(
1025 model()->GetTemplateURLs());
1026 EXPECT_FALSE(std::find(template_urls.begin(), template_urls.end(),
1027 extension2) == template_urls.end());
1028 }
1029
1030 TEST_F(TemplateURLServiceSyncTest, AutogeneratedKeywordMigrated) {
1031 // Create a couple of sync entries with autogenerated keywords.
1032 SyncDataList initial_data;
1033 scoped_ptr<TemplateURL> turl(
1034 CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com", "key1"));
1035 initial_data.push_back(
1036 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid()));
1037 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("key2"),
1038 "{google:baseURL}search?q={searchTerms}", "key2"));
1039 initial_data.push_back(
1040 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid()));
1041
1042 // Now try to sync the data locally.
1043 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data,
1044 PassProcessor(), CreateAndPassSyncErrorFactory());
1045
1046 // Both entries should have been added, with explicit keywords.
1047 TemplateURL* key1 = model()->GetTemplateURLForHost("key1.com");
1048 ASSERT_FALSE(key1 == NULL);
1049 EXPECT_EQ(ASCIIToUTF16("key1.com"), key1->keyword());
1050 std::string google_hostname(
1051 GURL(UIThreadSearchTermsData().GoogleBaseURLValue()).host());
1052 TemplateURL* key2 = model()->GetTemplateURLForHost(google_hostname);
1053 ASSERT_FALSE(key2 == NULL);
1054 string16 google_keyword(net::StripWWW(ASCIIToUTF16(google_hostname)));
1055 EXPECT_EQ(google_keyword, key2->keyword());
1056
1057 // We should also have gotten some corresponding UPDATEs pushed upstream.
1058 EXPECT_GE(processor()->change_list_size(), 2U);
1059 ASSERT_TRUE(processor()->contains_guid("key1"));
1060 SyncChange key1_change = processor()->change_for_guid("key1");
1061 EXPECT_EQ(SyncChange::ACTION_UPDATE, key1_change.change_type());
1062 EXPECT_EQ("key1.com", GetKeyword(key1_change.sync_data()));
1063 ASSERT_TRUE(processor()->contains_guid("key2"));
1064 SyncChange key2_change = processor()->change_for_guid("key2");
1065 EXPECT_EQ(SyncChange::ACTION_UPDATE, key2_change.change_type());
1066 EXPECT_EQ(google_keyword, UTF8ToUTF16(GetKeyword(key2_change.sync_data())));
1067 }
1068
1069 TEST_F(TemplateURLServiceSyncTest, AutogeneratedKeywordConflicts) {
1070 // Sync brings in some autogenerated keywords, but the generated keywords we
1071 // try to create conflict with ones in the model.
1072 string16 google_keyword(net::StripWWW(ASCIIToUTF16(GURL(
1073 UIThreadSearchTermsData().GoogleBaseURLValue()).host())));
1074 TemplateURL* google = CreateTestTemplateURL(google_keyword,
1075 "{google:baseURL}1/search?q={searchTerms}");
1076 model()->Add(google);
1077 TemplateURL* other =
1078 CreateTestTemplateURL(ASCIIToUTF16("other.com"), "http://other.com/foo");
1079 model()->Add(other);
1080 SyncDataList initial_data;
1081 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("sync1"),
1082 "{google:baseURL}2/search?q={searchTerms}", "sync1", 50));
1083 initial_data.push_back(
1084 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid()));
1085 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("sync2"),
1086 "http://other.com/search?q={searchTerms}", "sync2", 150));
1087 initial_data.push_back(
1088 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid()));
1089 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data,
1090 PassProcessor(), CreateAndPassSyncErrorFactory());
1091
1092 // In this case, the conflicts should be handled just like any other keyword
1093 // conflicts -- the later-modified TemplateURL is assumed to be authoritative.
1094 EXPECT_EQ(google_keyword, google->keyword());
1095 EXPECT_EQ(google_keyword + ASCIIToUTF16("_"),
1096 model()->GetTemplateURLForGUID("sync1")->keyword());
1097 EXPECT_EQ(ASCIIToUTF16("other.com_"), other->keyword());
1098 EXPECT_EQ(ASCIIToUTF16("other.com"),
1099 model()->GetTemplateURLForGUID("sync2")->keyword());
1100
1101 // Both synced URLs should have associated UPDATEs, since both needed their
1102 // keywords to be generated (and sync1 needed conflict resolution as well).
1103 EXPECT_GE(processor()->change_list_size(), 2U);
1104 ASSERT_TRUE(processor()->contains_guid("sync1"));
1105 SyncChange sync1_change = processor()->change_for_guid("sync1");
1106 EXPECT_EQ(SyncChange::ACTION_UPDATE, sync1_change.change_type());
1107 EXPECT_EQ(google_keyword + ASCIIToUTF16("_"),
1108 UTF8ToUTF16(GetKeyword(sync1_change.sync_data())));
1109 ASSERT_TRUE(processor()->contains_guid("sync2"));
1110 SyncChange sync2_change = processor()->change_for_guid("sync2");
1111 EXPECT_EQ(SyncChange::ACTION_UPDATE, sync2_change.change_type());
1112 EXPECT_EQ("other.com", GetKeyword(sync2_change.sync_data()));
1113 }
1114
1115 TEST_F(TemplateURLServiceSyncTest, TwoAutogeneratedKeywordsUsingGoogleBaseURL) {
1116 // Sync brings in two autogenerated keywords and both use Google base URLs.
1117 // We make the first older so that it will get renamed once before the second
1118 // and then again once after (when we resolve conflicts for the second).
1119 SyncDataList initial_data;
1120 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("key1"),
1121 "{google:baseURL}1/search?q={searchTerms}", "key1", 50));
1122 initial_data.push_back(
1123 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid()));
1124 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("key2"),
1125 "{google:baseURL}2/search?q={searchTerms}", "key2"));
1126 initial_data.push_back(
1127 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid()));
1128 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data,
1129 PassProcessor(), CreateAndPassSyncErrorFactory());
1130
1131 // We should still have coalesced the updates to one each.
1132 string16 google_keyword(net::StripWWW(ASCIIToUTF16(GURL(
1133 UIThreadSearchTermsData().GoogleBaseURLValue()).host())));
1134 TemplateURL* keyword1 =
1135 model()->GetTemplateURLForKeyword(google_keyword + ASCIIToUTF16("_"));
1136 ASSERT_FALSE(keyword1 == NULL);
1137 EXPECT_EQ("key1", keyword1->sync_guid());
1138 TemplateURL* keyword2 = model()->GetTemplateURLForKeyword(google_keyword);
1139 ASSERT_FALSE(keyword2 == NULL);
1140 EXPECT_EQ("key2", keyword2->sync_guid());
1141 EXPECT_GE(processor()->change_list_size(), 2U);
1142 ASSERT_TRUE(processor()->contains_guid("key1"));
1143 SyncChange key1_change = processor()->change_for_guid("key1");
1144 EXPECT_EQ(SyncChange::ACTION_UPDATE, key1_change.change_type());
1145 EXPECT_EQ(keyword1->keyword(),
1146 UTF8ToUTF16(GetKeyword(key1_change.sync_data())));
1147 ASSERT_TRUE(processor()->contains_guid("key2"));
1148 SyncChange key2_change = processor()->change_for_guid("key2");
1149 EXPECT_EQ(SyncChange::ACTION_UPDATE, key2_change.change_type());
1150 EXPECT_EQ(keyword2->keyword(),
1151 UTF8ToUTF16(GetKeyword(key2_change.sync_data())));
1152 }
1153
1004 TEST_F(TemplateURLServiceSyncTest, MergeTwoClientsBasic) { 1154 TEST_F(TemplateURLServiceSyncTest, MergeTwoClientsBasic) {
1005 // Start off B with some empty data. 1155 // Start off B with some empty data.
1006 model_b()->MergeDataAndStartSyncing( 1156 model_b()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES,
1007 syncable::SEARCH_ENGINES, 1157 CreateInitialSyncData(), PassProcessor(),
1008 CreateInitialSyncData(), PassProcessor(), 1158 CreateAndPassSyncErrorFactory());
1009 CreateAndPassSyncErrorFactory());
1010 1159
1011 // Merge A and B. All of B's data should transfer over to A, which initially 1160 // Merge A and B. All of B's data should transfer over to A, which initially
1012 // has no data. 1161 // has no data.
1013 scoped_ptr<SyncChangeProcessorDelegate> delegate_b( 1162 scoped_ptr<SyncChangeProcessorDelegate> delegate_b(
1014 new SyncChangeProcessorDelegate(model_b())); 1163 new SyncChangeProcessorDelegate(model_b()));
1015 model_a()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, 1164 model_a()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES,
1016 model_b()->GetAllSyncData(syncable::SEARCH_ENGINES), 1165 model_b()->GetAllSyncData(syncable::SEARCH_ENGINES),
1017 delegate_b.PassAs<SyncChangeProcessor>(), 1166 delegate_b.PassAs<SyncChangeProcessor>(),
1018 CreateAndPassSyncErrorFactory()); 1167 CreateAndPassSyncErrorFactory());
1019 1168
1020 // They should be consistent. 1169 // They should be consistent.
1021 AssertEquals(model_a()->GetAllSyncData(syncable::SEARCH_ENGINES), 1170 AssertEquals(model_a()->GetAllSyncData(syncable::SEARCH_ENGINES),
1022 model_b()->GetAllSyncData(syncable::SEARCH_ENGINES)); 1171 model_b()->GetAllSyncData(syncable::SEARCH_ENGINES));
1023 } 1172 }
1024 1173
1025 TEST_F(TemplateURLServiceSyncTest, MergeTwoClientsDupesAndConflicts) { 1174 TEST_F(TemplateURLServiceSyncTest, MergeTwoClientsDupesAndConflicts) {
1026 // Start off B with some empty data. 1175 // Start off B with some empty data.
1027 model_b()->MergeDataAndStartSyncing( 1176 model_b()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES,
1028 syncable::SEARCH_ENGINES, 1177 CreateInitialSyncData(), PassProcessor(),
1029 CreateInitialSyncData(), PassProcessor(), 1178 CreateAndPassSyncErrorFactory());
1030 CreateAndPassSyncErrorFactory());
1031 1179
1032 // Set up A so we have some interesting duplicates and conflicts. 1180 // Set up A so we have some interesting duplicates and conflicts.
1033 model_a()->Add(CreateTestTemplateURL(ASCIIToUTF16("key4"), "http://key4.com", 1181 model_a()->Add(CreateTestTemplateURL(ASCIIToUTF16("key4"), "http://key4.com",
1034 "key4")); // Added 1182 "key4")); // Added
1035 model_a()->Add(CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://key2.com", 1183 model_a()->Add(CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://key2.com",
1036 "key2")); // Merge - Copy of key2. 1184 "key2")); // Merge - Copy of key2.
1037 model_a()->Add(CreateTestTemplateURL(ASCIIToUTF16("key3"), "http://key3.com", 1185 model_a()->Add(CreateTestTemplateURL(ASCIIToUTF16("key3"), "http://key3.com",
1038 "key5", 10)); // Merge - Dupe of key3. 1186 "key5", 10)); // Merge - Dupe of key3.
1039 model_a()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key6.com", 1187 model_a()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key6.com",
1040 "key6", 10)); // Conflict with key1 1188 "key6", 10)); // Conflict with key1
1041 1189
1042 // Merge A and B. 1190 // Merge A and B.
1043 scoped_ptr<SyncChangeProcessorDelegate> delegate_b( 1191 scoped_ptr<SyncChangeProcessorDelegate> delegate_b(
1044 new SyncChangeProcessorDelegate(model_b())); 1192 new SyncChangeProcessorDelegate(model_b()));
1045 model_a()->MergeDataAndStartSyncing( 1193 model_a()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES,
1046 syncable::SEARCH_ENGINES,
1047 model_b()->GetAllSyncData(syncable::SEARCH_ENGINES), 1194 model_b()->GetAllSyncData(syncable::SEARCH_ENGINES),
1048 delegate_b.PassAs<SyncChangeProcessor>(), 1195 delegate_b.PassAs<SyncChangeProcessor>(),
1049 CreateAndPassSyncErrorFactory()); 1196 CreateAndPassSyncErrorFactory());
1050 1197
1051 // They should be consistent. 1198 // They should be consistent.
1052 AssertEquals(model_a()->GetAllSyncData(syncable::SEARCH_ENGINES), 1199 AssertEquals(model_a()->GetAllSyncData(syncable::SEARCH_ENGINES),
1053 model_b()->GetAllSyncData(syncable::SEARCH_ENGINES)); 1200 model_b()->GetAllSyncData(syncable::SEARCH_ENGINES));
1054 } 1201 }
1055 1202
1056 TEST_F(TemplateURLServiceSyncTest, StopSyncing) { 1203 TEST_F(TemplateURLServiceSyncTest, StopSyncing) {
1057 SyncError error = model()->MergeDataAndStartSyncing( 1204 SyncError error = model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES,
1058 syncable::SEARCH_ENGINES,
1059 CreateInitialSyncData(), PassProcessor(), 1205 CreateInitialSyncData(), PassProcessor(),
1060 CreateAndPassSyncErrorFactory()); 1206 CreateAndPassSyncErrorFactory());
1061 ASSERT_FALSE(error.IsSet()); 1207 ASSERT_FALSE(error.IsSet());
1062 model()->StopSyncing(syncable::SEARCH_ENGINES); 1208 model()->StopSyncing(syncable::SEARCH_ENGINES);
1063 1209
1064 SyncChangeList changes; 1210 SyncChangeList changes;
1065 changes.push_back(CreateTestSyncChange(SyncChange::ACTION_UPDATE, 1211 changes.push_back(CreateTestSyncChange(SyncChange::ACTION_UPDATE,
1066 CreateTestTemplateURL(ASCIIToUTF16("newkeyword"), "http://new.com", 1212 CreateTestTemplateURL(ASCIIToUTF16("newkeyword"), "http://new.com",
1067 "key2"))); 1213 "key2")));
1068 error = model()->ProcessSyncChanges(FROM_HERE, changes); 1214 error = model()->ProcessSyncChanges(FROM_HERE, changes);
1069 EXPECT_TRUE(error.IsSet()); 1215 EXPECT_TRUE(error.IsSet());
1070 1216
1071 // Ensure that the sync changes were not accepted. 1217 // Ensure that the sync changes were not accepted.
1072 EXPECT_TRUE(model()->GetTemplateURLForGUID("key2")); 1218 EXPECT_TRUE(model()->GetTemplateURLForGUID("key2"));
1073 EXPECT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("newkeyword"))); 1219 EXPECT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("newkeyword")));
1074 } 1220 }
1075 1221
1076 TEST_F(TemplateURLServiceSyncTest, SyncErrorOnInitialSync) { 1222 TEST_F(TemplateURLServiceSyncTest, SyncErrorOnInitialSync) {
1077 processor()->set_erroneous(true); 1223 processor()->set_erroneous(true);
1078 SyncError error = model()->MergeDataAndStartSyncing( 1224 SyncError error = model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES,
1079 syncable::SEARCH_ENGINES,
1080 CreateInitialSyncData(), PassProcessor(), 1225 CreateInitialSyncData(), PassProcessor(),
1081 CreateAndPassSyncErrorFactory()); 1226 CreateAndPassSyncErrorFactory());
1082 EXPECT_TRUE(error.IsSet()); 1227 EXPECT_TRUE(error.IsSet());
1083 1228
1084 // Ensure that if the initial merge was erroneous, then subsequence attempts 1229 // Ensure that if the initial merge was erroneous, then subsequence attempts
1085 // to push data into the local model are rejected, since the model was never 1230 // to push data into the local model are rejected, since the model was never
1086 // successfully associated with Sync in the first place. 1231 // successfully associated with Sync in the first place.
1087 SyncChangeList changes; 1232 SyncChangeList changes;
1088 changes.push_back(CreateTestSyncChange(SyncChange::ACTION_UPDATE, 1233 changes.push_back(CreateTestSyncChange(SyncChange::ACTION_UPDATE,
1089 CreateTestTemplateURL(ASCIIToUTF16("newkeyword"), "http://new.com", 1234 CreateTestTemplateURL(ASCIIToUTF16("newkeyword"), "http://new.com",
1090 "key2"))); 1235 "key2")));
1091 processor()->set_erroneous(false); 1236 processor()->set_erroneous(false);
1092 error = model()->ProcessSyncChanges(FROM_HERE, changes); 1237 error = model()->ProcessSyncChanges(FROM_HERE, changes);
1093 EXPECT_TRUE(error.IsSet()); 1238 EXPECT_TRUE(error.IsSet());
1094 1239
1095 // Ensure that the sync changes were not accepted. 1240 // Ensure that the sync changes were not accepted.
1096 EXPECT_TRUE(model()->GetTemplateURLForGUID("key2")); 1241 EXPECT_TRUE(model()->GetTemplateURLForGUID("key2"));
1097 EXPECT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("newkeyword"))); 1242 EXPECT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("newkeyword")));
1098 } 1243 }
1099 1244
1100 TEST_F(TemplateURLServiceSyncTest, SyncErrorOnLaterSync) { 1245 TEST_F(TemplateURLServiceSyncTest, SyncErrorOnLaterSync) {
1101 // Ensure that if the SyncProcessor succeeds in the initial merge, but fails 1246 // Ensure that if the SyncProcessor succeeds in the initial merge, but fails
1102 // in future ProcessSyncChanges, we still return an error. 1247 // in future ProcessSyncChanges, we still return an error.
1103 SyncError error = model()->MergeDataAndStartSyncing( 1248 SyncError error = model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES,
1104 syncable::SEARCH_ENGINES,
1105 CreateInitialSyncData(), PassProcessor(), 1249 CreateInitialSyncData(), PassProcessor(),
1106 CreateAndPassSyncErrorFactory()); 1250 CreateAndPassSyncErrorFactory());
1107 ASSERT_FALSE(error.IsSet()); 1251 ASSERT_FALSE(error.IsSet());
1108 1252
1109 SyncChangeList changes; 1253 SyncChangeList changes;
1110 changes.push_back(CreateTestSyncChange(SyncChange::ACTION_UPDATE, 1254 changes.push_back(CreateTestSyncChange(SyncChange::ACTION_UPDATE,
1111 CreateTestTemplateURL(ASCIIToUTF16("newkeyword"), "http://new.com", 1255 CreateTestTemplateURL(ASCIIToUTF16("newkeyword"), "http://new.com",
1112 "key2"))); 1256 "key2")));
1113 processor()->set_erroneous(true); 1257 processor()->set_erroneous(true);
1114 error = model()->ProcessSyncChanges(FROM_HERE, changes); 1258 error = model()->ProcessSyncChanges(FROM_HERE, changes);
1115 EXPECT_TRUE(error.IsSet()); 1259 EXPECT_TRUE(error.IsSet());
1116 } 1260 }
1117 1261
1118 TEST_F(TemplateURLServiceSyncTest, MergeTwiceWithSameSyncData) { 1262 TEST_F(TemplateURLServiceSyncTest, MergeTwiceWithSameSyncData) {
1119 // Ensure that a second merge with the same data as the first does not 1263 // Ensure that a second merge with the same data as the first does not
1120 // actually update the local data. 1264 // actually update the local data.
1121 SyncDataList initial_data; 1265 SyncDataList initial_data;
1122 initial_data.push_back(CreateInitialSyncData()[0]); 1266 initial_data.push_back(CreateInitialSyncData()[0]);
1123 1267
1124 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com", 1268 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com",
1125 "key1", 10)); // earlier 1269 "key1", 10)); // earlier
1126 1270
1127 SyncError error = model()->MergeDataAndStartSyncing( 1271 SyncError error = model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES,
1128 syncable::SEARCH_ENGINES, 1272 initial_data, PassProcessor(), CreateAndPassSyncErrorFactory());
1129 initial_data, PassProcessor(),
1130 CreateAndPassSyncErrorFactory());
1131 ASSERT_FALSE(error.IsSet()); 1273 ASSERT_FALSE(error.IsSet());
1132 1274
1133 // We should have updated the original TemplateURL with Sync's version. 1275 // We should have updated the original TemplateURL with Sync's version.
1134 // Keep a copy of it so we can compare it after we re-merge. 1276 // Keep a copy of it so we can compare it after we re-merge.
1135 TemplateURL* key1_url = model()->GetTemplateURLForGUID("key1"); 1277 TemplateURL* key1_url = model()->GetTemplateURLForGUID("key1");
1136 ASSERT_TRUE(key1_url); 1278 ASSERT_TRUE(key1_url);
1137 scoped_ptr<TemplateURL> updated_turl(new TemplateURL(key1_url->profile(), 1279 scoped_ptr<TemplateURL> updated_turl(new TemplateURL(key1_url->profile(),
1138 key1_url->data())); 1280 key1_url->data()));
1139 EXPECT_EQ(Time::FromTimeT(90), updated_turl->last_modified()); 1281 EXPECT_EQ(Time::FromTimeT(90), updated_turl->last_modified());
1140 1282
1141 // Modify a single field of the initial data. This should not be updated in 1283 // Modify a single field of the initial data. This should not be updated in
1142 // the second merge, as the last_modified timestamp remains the same. 1284 // the second merge, as the last_modified timestamp remains the same.
1143 scoped_ptr<TemplateURL> temp_turl(Deserialize(initial_data[0])); 1285 scoped_ptr<TemplateURL> temp_turl(Deserialize(initial_data[0]));
1144 TemplateURLData data(temp_turl->data()); 1286 TemplateURLData data(temp_turl->data());
1145 data.short_name = ASCIIToUTF16("SomethingDifferent"); 1287 data.short_name = ASCIIToUTF16("SomethingDifferent");
1146 temp_turl.reset(new TemplateURL(temp_turl->profile(), data)); 1288 temp_turl.reset(new TemplateURL(temp_turl->profile(), data));
1147 initial_data.clear(); 1289 initial_data.clear();
1148 initial_data.push_back( 1290 initial_data.push_back(
1149 TemplateURLService::CreateSyncDataFromTemplateURL(*temp_turl)); 1291 TemplateURLService::CreateSyncDataFromTemplateURL(*temp_turl));
1150 1292
1151 // Remerge the data again. This simulates shutting down and syncing again 1293 // Remerge the data again. This simulates shutting down and syncing again
1152 // at a different time, but the cloud data has not changed. 1294 // at a different time, but the cloud data has not changed.
1153 model()->StopSyncing(syncable::SEARCH_ENGINES); 1295 model()->StopSyncing(syncable::SEARCH_ENGINES);
1154 sync_processor_delegate_.reset(new SyncChangeProcessorDelegate( 1296 sync_processor_delegate_.reset(new SyncChangeProcessorDelegate(
1155 sync_processor_.get())); 1297 sync_processor_.get()));
1156 error = model()->MergeDataAndStartSyncing( 1298 error = model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES,
1157 syncable::SEARCH_ENGINES, 1299 initial_data, PassProcessor(), CreateAndPassSyncErrorFactory());
1158 initial_data, PassProcessor(),
1159 CreateAndPassSyncErrorFactory());
1160 ASSERT_FALSE(error.IsSet()); 1300 ASSERT_FALSE(error.IsSet());
1161 1301
1162 // Check that the TemplateURL was not modified. 1302 // Check that the TemplateURL was not modified.
1163 const TemplateURL* reupdated_turl = model()->GetTemplateURLForGUID("key1"); 1303 const TemplateURL* reupdated_turl = model()->GetTemplateURLForGUID("key1");
1164 ASSERT_TRUE(reupdated_turl); 1304 ASSERT_TRUE(reupdated_turl);
1165 AssertEquals(*updated_turl, *reupdated_turl); 1305 AssertEquals(*updated_turl, *reupdated_turl);
1166 } 1306 }
1167 1307
1168 TEST_F(TemplateURLServiceSyncTest, SyncedDefaultGUIDArrivesFirst) { 1308 TEST_F(TemplateURLServiceSyncTest, SyncedDefaultGUIDArrivesFirst) {
1169 SyncDataList initial_data = CreateInitialSyncData(); 1309 SyncDataList initial_data = CreateInitialSyncData();
1170 // The default search provider should support replacement. 1310 // The default search provider should support replacement.
1171 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("key2"), 1311 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("key2"),
1172 "http://key2.com/{searchTerms}", "key2", 90)); 1312 "http://key2.com/{searchTerms}", "key2", 90));
1173 initial_data[1] = TemplateURLService::CreateSyncDataFromTemplateURL(*turl); 1313 initial_data[1] = TemplateURLService::CreateSyncDataFromTemplateURL(*turl);
1174 model()->MergeDataAndStartSyncing( 1314 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data,
1175 syncable::SEARCH_ENGINES, initial_data, 1315 PassProcessor(), CreateAndPassSyncErrorFactory());
1176 PassProcessor(),
1177 CreateAndPassSyncErrorFactory());
1178 model()->SetDefaultSearchProvider(model()->GetTemplateURLForGUID("key2")); 1316 model()->SetDefaultSearchProvider(model()->GetTemplateURLForGUID("key2"));
1179 1317
1180 EXPECT_EQ(3U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); 1318 EXPECT_EQ(3U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size());
1181 const TemplateURL* default_search = model()->GetDefaultSearchProvider(); 1319 const TemplateURL* default_search = model()->GetDefaultSearchProvider();
1182 ASSERT_TRUE(default_search); 1320 ASSERT_TRUE(default_search);
1183 1321
1184 // Change kSyncedDefaultSearchProviderGUID to a GUID that does not exist in 1322 // Change kSyncedDefaultSearchProviderGUID to a GUID that does not exist in
1185 // the model yet. Ensure that the default has not changed in any way. 1323 // the model yet. Ensure that the default has not changed in any way.
1186 profile_a()->GetTestingPrefService()->SetString( 1324 profile_a()->GetTestingPrefService()->SetString(
1187 prefs::kSyncedDefaultSearchProviderGUID, "newdefault"); 1325 prefs::kSyncedDefaultSearchProviderGUID, "newdefault");
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1233 EXPECT_EQ(default_search, model()->GetDefaultSearchProvider()); 1371 EXPECT_EQ(default_search, model()->GetDefaultSearchProvider());
1234 1372
1235 // Now sync the initial data, which will include the search engine entry 1373 // Now sync the initial data, which will include the search engine entry
1236 // destined to become the new default. 1374 // destined to become the new default.
1237 SyncDataList initial_data = CreateInitialSyncData(); 1375 SyncDataList initial_data = CreateInitialSyncData();
1238 // The default search provider should support replacement. 1376 // The default search provider should support replacement.
1239 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("key2"), 1377 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("key2"),
1240 "http://key2.com/{searchTerms}", "key2", 90)); 1378 "http://key2.com/{searchTerms}", "key2", 90));
1241 initial_data[1] = TemplateURLService::CreateSyncDataFromTemplateURL(*turl); 1379 initial_data[1] = TemplateURLService::CreateSyncDataFromTemplateURL(*turl);
1242 1380
1243 model()->MergeDataAndStartSyncing( 1381 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data,
1244 syncable::SEARCH_ENGINES, initial_data, 1382 PassProcessor(), CreateAndPassSyncErrorFactory());
1245 PassProcessor(),
1246 CreateAndPassSyncErrorFactory());
1247 1383
1248 // Ensure that the new default has been set. 1384 // Ensure that the new default has been set.
1249 EXPECT_EQ(4U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); 1385 EXPECT_EQ(4U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size());
1250 ASSERT_NE(default_search, model()->GetDefaultSearchProvider()); 1386 ASSERT_NE(default_search, model()->GetDefaultSearchProvider());
1251 ASSERT_EQ("key2", model()->GetDefaultSearchProvider()->sync_guid()); 1387 ASSERT_EQ("key2", model()->GetDefaultSearchProvider()->sync_guid());
1252 } 1388 }
1253 1389
1254 TEST_F(TemplateURLServiceSyncTest, SyncedDefaultAlreadySetOnStartup) { 1390 TEST_F(TemplateURLServiceSyncTest, SyncedDefaultAlreadySetOnStartup) {
1255 // Start with the default set to something in the model before we start 1391 // Start with the default set to something in the model before we start
1256 // syncing. 1392 // syncing.
1257 const char kGUID[] = "initdefault"; 1393 const char kGUID[] = "initdefault";
1258 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("what"), 1394 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("what"),
1259 "http://thewhat.com/{searchTerms}", 1395 "http://thewhat.com/{searchTerms}",
1260 kGUID)); 1396 kGUID));
1261 model()->SetDefaultSearchProvider(model()->GetTemplateURLForGUID(kGUID)); 1397 model()->SetDefaultSearchProvider(model()->GetTemplateURLForGUID(kGUID));
1262 1398
1263 const TemplateURL* default_search = model()->GetDefaultSearchProvider(); 1399 const TemplateURL* default_search = model()->GetDefaultSearchProvider();
1264 ASSERT_TRUE(default_search); 1400 ASSERT_TRUE(default_search);
1265 1401
1266 // Set kSyncedDefaultSearchProviderGUID to the current default. 1402 // Set kSyncedDefaultSearchProviderGUID to the current default.
1267 profile_a()->GetTestingPrefService()->SetString( 1403 profile_a()->GetTestingPrefService()->SetString(
1268 prefs::kSyncedDefaultSearchProviderGUID, kGUID); 1404 prefs::kSyncedDefaultSearchProviderGUID, kGUID);
1269 1405
1270 EXPECT_EQ(default_search, model()->GetDefaultSearchProvider()); 1406 EXPECT_EQ(default_search, model()->GetDefaultSearchProvider());
1271 1407
1272 // Now sync the initial data. 1408 // Now sync the initial data.
1273 SyncDataList initial_data = CreateInitialSyncData(); 1409 SyncDataList initial_data = CreateInitialSyncData();
1274 model()->MergeDataAndStartSyncing( 1410 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data,
1275 syncable::SEARCH_ENGINES, initial_data, 1411 PassProcessor(), CreateAndPassSyncErrorFactory());
1276 PassProcessor(),
1277 CreateAndPassSyncErrorFactory());
1278 1412
1279 // Ensure that the new entries were added and the default has not changed. 1413 // Ensure that the new entries were added and the default has not changed.
1280 EXPECT_EQ(4U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); 1414 EXPECT_EQ(4U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size());
1281 ASSERT_EQ(default_search, model()->GetDefaultSearchProvider()); 1415 ASSERT_EQ(default_search, model()->GetDefaultSearchProvider());
1282 } 1416 }
1283 1417
1284 TEST_F(TemplateURLServiceSyncTest, SyncWithManagedDefaultSearch) { 1418 TEST_F(TemplateURLServiceSyncTest, SyncWithManagedDefaultSearch) {
1285 // First start off with a few entries and make sure we can set an unmanaged 1419 // First start off with a few entries and make sure we can set an unmanaged
1286 // default search provider. 1420 // default search provider.
1287 SyncDataList initial_data = CreateInitialSyncData(); 1421 SyncDataList initial_data = CreateInitialSyncData();
1288 model()->MergeDataAndStartSyncing( 1422 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data,
1289 syncable::SEARCH_ENGINES, initial_data, 1423 PassProcessor(), CreateAndPassSyncErrorFactory());
1290 PassProcessor(),
1291 CreateAndPassSyncErrorFactory());
1292 model()->SetDefaultSearchProvider(model()->GetTemplateURLForGUID("key2")); 1424 model()->SetDefaultSearchProvider(model()->GetTemplateURLForGUID("key2"));
1293 1425
1294 EXPECT_EQ(3U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); 1426 EXPECT_EQ(3U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size());
1295 ASSERT_FALSE(model()->is_default_search_managed()); 1427 ASSERT_FALSE(model()->is_default_search_managed());
1296 ASSERT_TRUE(model()->GetDefaultSearchProvider()); 1428 ASSERT_TRUE(model()->GetDefaultSearchProvider());
1297 1429
1298 // Change the default search provider to a managed one. 1430 // Change the default search provider to a managed one.
1299 const char kName[] = "manageddefault"; 1431 const char kName[] = "manageddefault";
1300 const char kSearchURL[] = "http://manageddefault.com/search?t={searchTerms}"; 1432 const char kSearchURL[] = "http://manageddefault.com/search?t={searchTerms}";
1301 const char kIconURL[] = "http://manageddefault.com/icon.jpg"; 1433 const char kIconURL[] = "http://manageddefault.com/icon.jpg";
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1342 "http://key1.com/{searchTerms}", "whateverguid", 10); 1474 "http://key1.com/{searchTerms}", "whateverguid", 10);
1343 model()->Add(default_turl); 1475 model()->Add(default_turl);
1344 model()->SetDefaultSearchProvider(default_turl); 1476 model()->SetDefaultSearchProvider(default_turl);
1345 1477
1346 SyncDataList initial_data = CreateInitialSyncData(); 1478 SyncDataList initial_data = CreateInitialSyncData();
1347 // The key1 entry should be a duplicate of the default. 1479 // The key1 entry should be a duplicate of the default.
1348 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("key1"), 1480 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("key1"),
1349 "http://key1.com/{searchTerms}", "key1", 90)); 1481 "http://key1.com/{searchTerms}", "key1", 90));
1350 initial_data[0] = TemplateURLService::CreateSyncDataFromTemplateURL(*turl); 1482 initial_data[0] = TemplateURLService::CreateSyncDataFromTemplateURL(*turl);
1351 1483
1352 model()->MergeDataAndStartSyncing( 1484 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data,
1353 syncable::SEARCH_ENGINES, 1485 PassProcessor(), CreateAndPassSyncErrorFactory());
1354 initial_data, PassProcessor(),
1355 CreateAndPassSyncErrorFactory());
1356 1486
1357 EXPECT_EQ(3U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); 1487 EXPECT_EQ(3U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size());
1358 EXPECT_FALSE(model()->GetTemplateURLForGUID("whateverguid")); 1488 EXPECT_FALSE(model()->GetTemplateURLForGUID("whateverguid"));
1359 EXPECT_EQ(model()->GetDefaultSearchProvider(), 1489 EXPECT_EQ(model()->GetDefaultSearchProvider(),
1360 model()->GetTemplateURLForGUID("key1")); 1490 model()->GetTemplateURLForGUID("key1"));
1361 } 1491 }
1362 1492
1363 TEST_F(TemplateURLServiceSyncTest, DeleteBogusData) { 1493 TEST_F(TemplateURLServiceSyncTest, DeleteBogusData) {
1364 // Create a couple of bogus entries to sync. 1494 // Create a couple of bogus entries to sync.
1365 SyncDataList initial_data; 1495 SyncDataList initial_data;
1366 scoped_ptr<TemplateURL> turl( 1496 scoped_ptr<TemplateURL> turl(
1367 CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com", "key1")); 1497 CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com", "key1"));
1368 initial_data.push_back( 1498 initial_data.push_back(
1369 CreateBogusSyncData(*turl, std::string(), turl->sync_guid())); 1499 CreateCustomSyncData(*turl, false, std::string(), turl->sync_guid()));
1370 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://key2.com")); 1500 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://key2.com"));
1371 initial_data.push_back( 1501 initial_data.push_back(
1372 CreateBogusSyncData(*turl, turl->url(), std::string())); 1502 CreateCustomSyncData(*turl, false, turl->url(), std::string()));
1373 1503
1374 // Now try to sync the data locally. 1504 // Now try to sync the data locally.
1375 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data, 1505 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data,
1376 PassProcessor(), 1506 PassProcessor(), CreateAndPassSyncErrorFactory());
1377 CreateAndPassSyncErrorFactory());
1378 1507
1379 // Nothing should have been added, and both bogus entries should be marked for 1508 // Nothing should have been added, and both bogus entries should be marked for
1380 // deletion. 1509 // deletion.
1381 EXPECT_EQ(0U, model()->GetTemplateURLs().size()); 1510 EXPECT_EQ(0U, model()->GetTemplateURLs().size());
1382 EXPECT_EQ(2U, processor()->change_list_size()); 1511 EXPECT_EQ(2U, processor()->change_list_size());
1383 ASSERT_TRUE(processor()->contains_guid("key1")); 1512 ASSERT_TRUE(processor()->contains_guid("key1"));
1384 EXPECT_EQ(SyncChange::ACTION_DELETE, 1513 EXPECT_EQ(SyncChange::ACTION_DELETE,
1385 processor()->change_for_guid("key1").change_type()); 1514 processor()->change_for_guid("key1").change_type());
1386 ASSERT_TRUE(processor()->contains_guid(std::string())); 1515 ASSERT_TRUE(processor()->contains_guid(std::string()));
1387 EXPECT_EQ(SyncChange::ACTION_DELETE, 1516 EXPECT_EQ(SyncChange::ACTION_DELETE,
1388 processor()->change_for_guid(std::string()).change_type()); 1517 processor()->change_for_guid(std::string()).change_type());
1389 } 1518 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698