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

Side by Side Diff: chrome/browser/sync/profile_sync_service_bookmark_unittest.cc

Issue 120983002: Update some uses of UTF conversions in chrome/browser to use the base:: namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 12 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 // TODO(akalin): This file is basically just a unit test for 5 // TODO(akalin): This file is basically just a unit test for
6 // BookmarkChangeProcessor. Write unit tests for 6 // BookmarkChangeProcessor. Write unit tests for
7 // BookmarkModelAssociator separately. 7 // BookmarkModelAssociator separately.
8 8
9 #include <map> 9 #include <map>
10 #include <queue> 10 #include <queue>
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 changes_.insert(changes_.begin(), record); 176 changes_.insert(changes_.begin(), record);
177 } 177 }
178 178
179 // Set a new title value, and return the old value. 179 // Set a new title value, and return the old value.
180 std::wstring ModifyTitle(int64 id, const std::wstring& new_title) { 180 std::wstring ModifyTitle(int64 id, const std::wstring& new_title) {
181 syncer::WriteNode node(trans_); 181 syncer::WriteNode node(trans_);
182 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(id)); 182 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(id));
183 std::string old_title = node.GetTitle(); 183 std::string old_title = node.GetTitle();
184 node.SetTitle(new_title); 184 node.SetTitle(new_title);
185 SetModified(id); 185 SetModified(id);
186 return UTF8ToWide(old_title); 186 return base::UTF8ToWide(old_title);
187 } 187 }
188 188
189 // Set a new parent and predecessor value. Return the old parent id. 189 // Set a new parent and predecessor value. Return the old parent id.
190 // We could return the old predecessor id, but it turns out not to be 190 // We could return the old predecessor id, but it turns out not to be
191 // very useful for assertions. 191 // very useful for assertions.
192 int64 ModifyPosition(int64 id, int64 parent_id, int64 predecessor_id) { 192 int64 ModifyPosition(int64 id, int64 parent_id, int64 predecessor_id) {
193 syncer::ReadNode parent(trans_); 193 syncer::ReadNode parent(trans_);
194 EXPECT_EQ(BaseNode::INIT_OK, parent.InitByIdLookup(parent_id)); 194 EXPECT_EQ(BaseNode::INIT_OK, parent.InitByIdLookup(parent_id));
195 syncer::WriteNode node(trans_); 195 syncer::WriteNode node(trans_);
196 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(id)); 196 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(id));
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 int64 AddFolderToShare(syncer::WriteTransaction* trans, std::string title) { 347 int64 AddFolderToShare(syncer::WriteTransaction* trans, std::string title) {
348 EXPECT_FALSE(model_associator_); 348 EXPECT_FALSE(model_associator_);
349 349
350 // Be sure to call CreatePermanentBookmarkNodes(), otherwise this will fail. 350 // Be sure to call CreatePermanentBookmarkNodes(), otherwise this will fail.
351 syncer::ReadNode bookmark_bar(trans); 351 syncer::ReadNode bookmark_bar(trans);
352 EXPECT_EQ(BaseNode::INIT_OK, bookmark_bar.InitByTagLookup("bookmark_bar")); 352 EXPECT_EQ(BaseNode::INIT_OK, bookmark_bar.InitByTagLookup("bookmark_bar"));
353 353
354 syncer::WriteNode node(trans); 354 syncer::WriteNode node(trans);
355 EXPECT_TRUE(node.InitBookmarkByCreation(bookmark_bar, NULL)); 355 EXPECT_TRUE(node.InitBookmarkByCreation(bookmark_bar, NULL));
356 node.SetIsFolder(true); 356 node.SetIsFolder(true);
357 node.SetTitle(ASCIIToWide(title)); 357 node.SetTitle(base::ASCIIToWide(title));
358 358
359 return node.GetId(); 359 return node.GetId();
360 } 360 }
361 361
362 // Inserts a bookmark directly to the share. 362 // Inserts a bookmark directly to the share.
363 // Do not use this after model association is complete. 363 // Do not use this after model association is complete.
364 // 364 //
365 // This function differs from the AddURL() function declared elsewhere in this 365 // This function differs from the AddURL() function declared elsewhere in this
366 // file in that it only affects the sync model. It would be invalid to change 366 // file in that it only affects the sync model. It would be invalid to change
367 // the sync model directly after ModelAssociation. This function can be 367 // the sync model directly after ModelAssociation. This function can be
368 // invoked prior to model association to set up first-time sync model 368 // invoked prior to model association to set up first-time sync model
369 // association scenarios. 369 // association scenarios.
370 int64 AddBookmarkToShare(syncer::WriteTransaction *trans, 370 int64 AddBookmarkToShare(syncer::WriteTransaction *trans,
371 int64 parent_id, 371 int64 parent_id,
372 std::string title) { 372 std::string title) {
373 EXPECT_FALSE(model_associator_); 373 EXPECT_FALSE(model_associator_);
374 374
375 syncer::ReadNode parent(trans); 375 syncer::ReadNode parent(trans);
376 EXPECT_EQ(BaseNode::INIT_OK, parent.InitByIdLookup(parent_id)); 376 EXPECT_EQ(BaseNode::INIT_OK, parent.InitByIdLookup(parent_id));
377 377
378 sync_pb::BookmarkSpecifics specifics; 378 sync_pb::BookmarkSpecifics specifics;
379 specifics.set_url("http://www.google.com/search?q=" + title); 379 specifics.set_url("http://www.google.com/search?q=" + title);
380 specifics.set_title(title); 380 specifics.set_title(title);
381 381
382 syncer::WriteNode node(trans); 382 syncer::WriteNode node(trans);
383 EXPECT_TRUE(node.InitBookmarkByCreation(parent, NULL)); 383 EXPECT_TRUE(node.InitBookmarkByCreation(parent, NULL));
384 node.SetIsFolder(false); 384 node.SetIsFolder(false);
385 node.SetTitle(ASCIIToWide(title)); 385 node.SetTitle(base::ASCIIToWide(title));
386 node.SetBookmarkSpecifics(specifics); 386 node.SetBookmarkSpecifics(specifics);
387 387
388 return node.GetId(); 388 return node.GetId();
389 } 389 }
390 390
391 // Load (or re-load) the bookmark model. |load| controls use of the 391 // Load (or re-load) the bookmark model. |load| controls use of the
392 // bookmarks file on disk. |save| controls whether the newly loaded 392 // bookmarks file on disk. |save| controls whether the newly loaded
393 // bookmark model will write out a bookmark file as it goes. 393 // bookmark model will write out a bookmark file as it goes.
394 void LoadBookmarkModel(LoadOption load, SaveOption save) { 394 void LoadBookmarkModel(LoadOption load, SaveOption save) {
395 bool delete_bookmarks = load == DELETE_EXISTING_STORAGE; 395 bool delete_bookmarks = load == DELETE_EXISTING_STORAGE;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 if (last_child_id != syncer::kInvalidId) { 461 if (last_child_id != syncer::kInvalidId) {
462 EXPECT_EQ(BaseNode::INIT_OK, 462 EXPECT_EQ(BaseNode::INIT_OK,
463 predecessor_node.InitByIdLookup(last_child_id)); 463 predecessor_node.InitByIdLookup(last_child_id));
464 predecessor = &predecessor_node; 464 predecessor = &predecessor_node;
465 } 465 }
466 syncer::WriteNode node(&trans); 466 syncer::WriteNode node(&trans);
467 if (!node.InitBookmarkByCreation(root, predecessor)) 467 if (!node.InitBookmarkByCreation(root, predecessor))
468 return false; 468 return false;
469 node.SetIsFolder(true); 469 node.SetIsFolder(true);
470 node.GetMutableEntryForTest()->PutUniqueServerTag(permanent_tags[i]); 470 node.GetMutableEntryForTest()->PutUniqueServerTag(permanent_tags[i]);
471 node.SetTitle(UTF8ToWide(permanent_tags[i])); 471 node.SetTitle(base::UTF8ToWide(permanent_tags[i]));
472 node.SetExternalId(0); 472 node.SetExternalId(0);
473 last_child_id = node.GetId(); 473 last_child_id = node.GetId();
474 } 474 }
475 return true; 475 return true;
476 } 476 }
477 477
478 bool AssociateModels() { 478 bool AssociateModels() {
479 DCHECK(!model_associator_); 479 DCHECK(!model_associator_);
480 480
481 // Set up model associator. 481 // Set up model associator.
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 return model_associator_->InitSyncNodeFromChromeId(bnode->id(), 558 return model_associator_->InitSyncNodeFromChromeId(bnode->id(),
559 sync_node); 559 sync_node);
560 } 560 }
561 561
562 void ExpectSyncerNodeMatching(syncer::BaseTransaction* trans, 562 void ExpectSyncerNodeMatching(syncer::BaseTransaction* trans,
563 const BookmarkNode* bnode) { 563 const BookmarkNode* bnode) {
564 syncer::ReadNode gnode(trans); 564 syncer::ReadNode gnode(trans);
565 ASSERT_TRUE(InitSyncNodeFromChromeNode(bnode, &gnode)); 565 ASSERT_TRUE(InitSyncNodeFromChromeNode(bnode, &gnode));
566 // Non-root node titles and parents must match. 566 // Non-root node titles and parents must match.
567 if (!model_->is_permanent_node(bnode)) { 567 if (!model_->is_permanent_node(bnode)) {
568 EXPECT_EQ(bnode->GetTitle(), UTF8ToUTF16(gnode.GetTitle())); 568 EXPECT_EQ(bnode->GetTitle(), base::UTF8ToUTF16(gnode.GetTitle()));
569 EXPECT_EQ( 569 EXPECT_EQ(
570 model_associator_->GetChromeNodeFromSyncId(gnode.GetParentId()), 570 model_associator_->GetChromeNodeFromSyncId(gnode.GetParentId()),
571 bnode->parent()); 571 bnode->parent());
572 } 572 }
573 EXPECT_EQ(bnode->is_folder(), gnode.GetIsFolder()); 573 EXPECT_EQ(bnode->is_folder(), gnode.GetIsFolder());
574 if (bnode->is_url()) 574 if (bnode->is_url())
575 EXPECT_EQ(bnode->url(), GURL(gnode.GetBookmarkSpecifics().url())); 575 EXPECT_EQ(bnode->url(), GURL(gnode.GetBookmarkSpecifics().url()));
576 576
577 // Check that meta info matches. 577 // Check that meta info matches.
578 const BookmarkNode::MetaInfoMap* meta_info_map = bnode->GetMetaInfoMap(); 578 const BookmarkNode::MetaInfoMap* meta_info_map = bnode->GetMetaInfoMap();
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 ExpectModelMatch(); 782 ExpectModelMatch();
783 } 783 }
784 784
785 785
786 TEST_F(ProfileSyncServiceBookmarkTest, BookmarkModelOperations) { 786 TEST_F(ProfileSyncServiceBookmarkTest, BookmarkModelOperations) {
787 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); 787 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE);
788 StartSync(); 788 StartSync();
789 789
790 // Test addition. 790 // Test addition.
791 const BookmarkNode* folder = 791 const BookmarkNode* folder =
792 model_->AddFolder(model_->other_node(), 0, ASCIIToUTF16("foobar")); 792 model_->AddFolder(model_->other_node(), 0, base::ASCIIToUTF16("foobar"));
793 ExpectSyncerNodeMatching(folder); 793 ExpectSyncerNodeMatching(folder);
794 ExpectModelMatch(); 794 ExpectModelMatch();
795 const BookmarkNode* folder2 = 795 const BookmarkNode* folder2 =
796 model_->AddFolder(folder, 0, ASCIIToUTF16("nested")); 796 model_->AddFolder(folder, 0, base::ASCIIToUTF16("nested"));
797 ExpectSyncerNodeMatching(folder2); 797 ExpectSyncerNodeMatching(folder2);
798 ExpectModelMatch(); 798 ExpectModelMatch();
799 const BookmarkNode* url1 = model_->AddURL( 799 const BookmarkNode* url1 = model_->AddURL(
800 folder, 0, ASCIIToUTF16("Internets #1 Pies Site"), 800 folder, 0, base::ASCIIToUTF16("Internets #1 Pies Site"),
801 GURL("http://www.easypie.com/")); 801 GURL("http://www.easypie.com/"));
802 ExpectSyncerNodeMatching(url1); 802 ExpectSyncerNodeMatching(url1);
803 ExpectModelMatch(); 803 ExpectModelMatch();
804 const BookmarkNode* url2 = model_->AddURL( 804 const BookmarkNode* url2 = model_->AddURL(
805 folder, 1, ASCIIToUTF16("Airplanes"), GURL("http://www.easyjet.com/")); 805 folder, 1, base::ASCIIToUTF16("Airplanes"),
806 GURL("http://www.easyjet.com/"));
806 ExpectSyncerNodeMatching(url2); 807 ExpectSyncerNodeMatching(url2);
807 ExpectModelMatch(); 808 ExpectModelMatch();
808 // Test addition. 809 // Test addition.
809 const BookmarkNode* mobile_folder = 810 const BookmarkNode* mobile_folder =
810 model_->AddFolder(model_->mobile_node(), 0, ASCIIToUTF16("pie")); 811 model_->AddFolder(model_->mobile_node(), 0, base::ASCIIToUTF16("pie"));
811 ExpectSyncerNodeMatching(mobile_folder); 812 ExpectSyncerNodeMatching(mobile_folder);
812 ExpectModelMatch(); 813 ExpectModelMatch();
813 814
814 // Test modification. 815 // Test modification.
815 model_->SetTitle(url2, ASCIIToUTF16("EasyJet")); 816 model_->SetTitle(url2, base::ASCIIToUTF16("EasyJet"));
816 ExpectModelMatch(); 817 ExpectModelMatch();
817 model_->Move(url1, folder2, 0); 818 model_->Move(url1, folder2, 0);
818 ExpectModelMatch(); 819 ExpectModelMatch();
819 model_->Move(folder2, model_->bookmark_bar_node(), 0); 820 model_->Move(folder2, model_->bookmark_bar_node(), 0);
820 ExpectModelMatch(); 821 ExpectModelMatch();
821 model_->SetTitle(folder2, ASCIIToUTF16("Not Nested")); 822 model_->SetTitle(folder2, base::ASCIIToUTF16("Not Nested"));
822 ExpectModelMatch(); 823 ExpectModelMatch();
823 model_->Move(folder, folder2, 0); 824 model_->Move(folder, folder2, 0);
824 ExpectModelMatch(); 825 ExpectModelMatch();
825 model_->SetTitle(folder, ASCIIToUTF16("who's nested now?")); 826 model_->SetTitle(folder, base::ASCIIToUTF16("who's nested now?"));
826 ExpectModelMatch(); 827 ExpectModelMatch();
827 model_->Copy(url2, model_->bookmark_bar_node(), 0); 828 model_->Copy(url2, model_->bookmark_bar_node(), 0);
828 ExpectModelMatch(); 829 ExpectModelMatch();
829 model_->SetTitle(mobile_folder, ASCIIToUTF16("strawberry")); 830 model_->SetTitle(mobile_folder, base::ASCIIToUTF16("strawberry"));
830 ExpectModelMatch(); 831 ExpectModelMatch();
831 832
832 // Test deletion. 833 // Test deletion.
833 // Delete a single item. 834 // Delete a single item.
834 model_->Remove(url2->parent(), url2->parent()->GetIndexOf(url2)); 835 model_->Remove(url2->parent(), url2->parent()->GetIndexOf(url2));
835 ExpectModelMatch(); 836 ExpectModelMatch();
836 // Delete an item with several children. 837 // Delete an item with several children.
837 model_->Remove(folder2->parent(), 838 model_->Remove(folder2->parent(),
838 folder2->parent()->GetIndexOf(folder2)); 839 folder2->parent()->GetIndexOf(folder2));
839 ExpectModelMatch(); 840 ExpectModelMatch();
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
1069 // Files created automatically by the Windows shell. 1070 // Files created automatically by the Windows shell.
1070 "Thumbs.db", ".DS_Store", 1071 "Thumbs.db", ".DS_Store",
1071 // Names including Win32-illegal characters, and path separators. 1072 // Names including Win32-illegal characters, and path separators.
1072 "foo/bar", "foo\\bar", "foo?bar", "foo:bar", "foo|bar", "foo\"bar", 1073 "foo/bar", "foo\\bar", "foo?bar", "foo:bar", "foo|bar", "foo\"bar",
1073 "foo'bar", "foo<bar", "foo>bar", "foo%bar", "foo*bar", "foo]bar", 1074 "foo'bar", "foo<bar", "foo>bar", "foo%bar", "foo*bar", "foo]bar",
1074 "foo[bar", 1075 "foo[bar",
1075 }; 1076 };
1076 // Create both folders and bookmarks using each name. 1077 // Create both folders and bookmarks using each name.
1077 GURL url("http://www.doublemint.com"); 1078 GURL url("http://www.doublemint.com");
1078 for (size_t i = 0; i < arraysize(names); ++i) { 1079 for (size_t i = 0; i < arraysize(names); ++i) {
1079 model_->AddFolder(model_->other_node(), 0, ASCIIToUTF16(names[i])); 1080 model_->AddFolder(model_->other_node(), 0, base::ASCIIToUTF16(names[i]));
1080 model_->AddURL(model_->other_node(), 0, ASCIIToUTF16(names[i]), url); 1081 model_->AddURL(model_->other_node(), 0, base::ASCIIToUTF16(names[i]), url);
1081 } 1082 }
1082 1083
1083 // Verify that the browser model matches the sync model. 1084 // Verify that the browser model matches the sync model.
1084 EXPECT_TRUE(model_->other_node()->child_count() == 2*arraysize(names)); 1085 EXPECT_TRUE(model_->other_node()->child_count() == 2*arraysize(names));
1085 ExpectModelMatch(); 1086 ExpectModelMatch();
1086 } 1087 }
1087 1088
1088 // Stress the internal representation of position by sparse numbers. We want 1089 // Stress the internal representation of position by sparse numbers. We want
1089 // to repeatedly bisect the range of available positions, to force the 1090 // to repeatedly bisect the range of available positions, to force the
1090 // syncer code to renumber its ranges. Pick a number big enough so that it 1091 // syncer code to renumber its ranges. Pick a number big enough so that it
1091 // would exhaust 32bits of room between items a couple of times. 1092 // would exhaust 32bits of room between items a couple of times.
1092 TEST_F(ProfileSyncServiceBookmarkTest, RepeatedMiddleInsertion) { 1093 TEST_F(ProfileSyncServiceBookmarkTest, RepeatedMiddleInsertion) {
1093 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); 1094 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE);
1094 StartSync(); 1095 StartSync();
1095 1096
1096 static const int kTimesToInsert = 256; 1097 static const int kTimesToInsert = 256;
1097 1098
1098 // Create two book-end nodes to insert between. 1099 // Create two book-end nodes to insert between.
1099 model_->AddFolder(model_->other_node(), 0, ASCIIToUTF16("Alpha")); 1100 model_->AddFolder(model_->other_node(), 0, base::ASCIIToUTF16("Alpha"));
1100 model_->AddFolder(model_->other_node(), 1, ASCIIToUTF16("Omega")); 1101 model_->AddFolder(model_->other_node(), 1, base::ASCIIToUTF16("Omega"));
1101 int count = 2; 1102 int count = 2;
1102 1103
1103 // Test insertion in first half of range by repeatedly inserting in second 1104 // Test insertion in first half of range by repeatedly inserting in second
1104 // position. 1105 // position.
1105 for (int i = 0; i < kTimesToInsert; ++i) { 1106 for (int i = 0; i < kTimesToInsert; ++i) {
1106 base::string16 title = 1107 base::string16 title =
1107 ASCIIToUTF16("Pre-insertion ") + base::IntToString16(i); 1108 base::ASCIIToUTF16("Pre-insertion ") + base::IntToString16(i);
1108 model_->AddFolder(model_->other_node(), 1, title); 1109 model_->AddFolder(model_->other_node(), 1, title);
1109 count++; 1110 count++;
1110 } 1111 }
1111 1112
1112 // Test insertion in second half of range by repeatedly inserting in 1113 // Test insertion in second half of range by repeatedly inserting in
1113 // second-to-last position. 1114 // second-to-last position.
1114 for (int i = 0; i < kTimesToInsert; ++i) { 1115 for (int i = 0; i < kTimesToInsert; ++i) {
1115 base::string16 title = 1116 base::string16 title =
1116 ASCIIToUTF16("Post-insertion ") + base::IntToString16(i); 1117 base::ASCIIToUTF16("Post-insertion ") + base::IntToString16(i);
1117 model_->AddFolder(model_->other_node(), count - 1, title); 1118 model_->AddFolder(model_->other_node(), count - 1, title);
1118 count++; 1119 count++;
1119 } 1120 }
1120 1121
1121 // Verify that the browser model matches the sync model. 1122 // Verify that the browser model matches the sync model.
1122 EXPECT_EQ(model_->other_node()->child_count(), count); 1123 EXPECT_EQ(model_->other_node()->child_count(), count);
1123 ExpectModelMatch(); 1124 ExpectModelMatch();
1124 } 1125 }
1125 1126
1126 // Introduce a consistency violation into the model, and see that it 1127 // Introduce a consistency violation into the model, and see that it
1127 // puts itself into a lame, error state. 1128 // puts itself into a lame, error state.
1128 TEST_F(ProfileSyncServiceBookmarkTest, UnrecoverableErrorSuspendsService) { 1129 TEST_F(ProfileSyncServiceBookmarkTest, UnrecoverableErrorSuspendsService) {
1129 EXPECT_CALL(mock_error_handler_, 1130 EXPECT_CALL(mock_error_handler_,
1130 OnSingleDatatypeUnrecoverableError(_, _)); 1131 OnSingleDatatypeUnrecoverableError(_, _));
1131 1132
1132 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); 1133 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE);
1133 StartSync(); 1134 StartSync();
1134 1135
1135 // Add a node which will be the target of the consistency violation. 1136 // Add a node which will be the target of the consistency violation.
1136 const BookmarkNode* node = 1137 const BookmarkNode* node =
1137 model_->AddFolder(model_->other_node(), 0, ASCIIToUTF16("node")); 1138 model_->AddFolder(model_->other_node(), 0, base::ASCIIToUTF16("node"));
1138 ExpectSyncerNodeMatching(node); 1139 ExpectSyncerNodeMatching(node);
1139 1140
1140 // Now destroy the syncer node as if we were the ProfileSyncService without 1141 // Now destroy the syncer node as if we were the ProfileSyncService without
1141 // updating the ProfileSyncService state. This should introduce 1142 // updating the ProfileSyncService state. This should introduce
1142 // inconsistency between the two models. 1143 // inconsistency between the two models.
1143 { 1144 {
1144 syncer::WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); 1145 syncer::WriteTransaction trans(FROM_HERE, test_user_share_.user_share());
1145 syncer::WriteNode sync_node(&trans); 1146 syncer::WriteNode sync_node(&trans);
1146 ASSERT_TRUE(InitSyncNodeFromChromeNode(node, &sync_node)); 1147 ASSERT_TRUE(InitSyncNodeFromChromeNode(node, &sync_node));
1147 sync_node.Tombstone(); 1148 sync_node.Tombstone();
1148 } 1149 }
1149 // The models don't match at this point, but the ProfileSyncService 1150 // The models don't match at this point, but the ProfileSyncService
1150 // doesn't know it yet. 1151 // doesn't know it yet.
1151 ExpectSyncerNodeKnown(node); 1152 ExpectSyncerNodeKnown(node);
1152 1153
1153 // Add a child to the inconsistent node. This should cause detection of the 1154 // Add a child to the inconsistent node. This should cause detection of the
1154 // problem and the syncer should stop processing changes. 1155 // problem and the syncer should stop processing changes.
1155 model_->AddFolder(node, 0, ASCIIToUTF16("nested")); 1156 model_->AddFolder(node, 0, base::ASCIIToUTF16("nested"));
1156 } 1157 }
1157 1158
1158 // See what happens if we run model association when there are two exact URL 1159 // See what happens if we run model association when there are two exact URL
1159 // duplicate bookmarks. The BookmarkModelAssociator should not fall over when 1160 // duplicate bookmarks. The BookmarkModelAssociator should not fall over when
1160 // this happens. 1161 // this happens.
1161 TEST_F(ProfileSyncServiceBookmarkTest, MergeDuplicates) { 1162 TEST_F(ProfileSyncServiceBookmarkTest, MergeDuplicates) {
1162 LoadBookmarkModel(DELETE_EXISTING_STORAGE, SAVE_TO_STORAGE); 1163 LoadBookmarkModel(DELETE_EXISTING_STORAGE, SAVE_TO_STORAGE);
1163 StartSync(); 1164 StartSync();
1164 1165
1165 model_->AddURL(model_->other_node(), 0, ASCIIToUTF16("Dup"), 1166 model_->AddURL(model_->other_node(), 0, base::ASCIIToUTF16("Dup"),
1166 GURL("http://dup.com/")); 1167 GURL("http://dup.com/"));
1167 model_->AddURL(model_->other_node(), 0, ASCIIToUTF16("Dup"), 1168 model_->AddURL(model_->other_node(), 0, base::ASCIIToUTF16("Dup"),
1168 GURL("http://dup.com/")); 1169 GURL("http://dup.com/"));
1169 1170
1170 EXPECT_EQ(2, model_->other_node()->child_count()); 1171 EXPECT_EQ(2, model_->other_node()->child_count());
1171 1172
1172 // Restart the sync service to trigger model association. 1173 // Restart the sync service to trigger model association.
1173 StopSync(); 1174 StopSync();
1174 StartSync(); 1175 StartSync();
1175 1176
1176 EXPECT_EQ(2, model_->other_node()->child_count()); 1177 EXPECT_EQ(2, model_->other_node()->child_count());
1177 ExpectModelMatch(); 1178 ExpectModelMatch();
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1223 StopSync(); 1224 StopSync();
1224 // Bookmark bar itself and u0 remain. 1225 // Bookmark bar itself and u0 remain.
1225 EXPECT_EQ(2, model_->bookmark_bar_node()->GetTotalNodeCount()); 1226 EXPECT_EQ(2, model_->bookmark_bar_node()->GetTotalNodeCount());
1226 1227
1227 // Reload bookmarks including ones deleted in sync model from storage. 1228 // Reload bookmarks including ones deleted in sync model from storage.
1228 LoadBookmarkModel(LOAD_FROM_STORAGE, DONT_SAVE_TO_STORAGE); 1229 LoadBookmarkModel(LOAD_FROM_STORAGE, DONT_SAVE_TO_STORAGE);
1229 EXPECT_EQ(6, model_->bookmark_bar_node()->GetTotalNodeCount()); 1230 EXPECT_EQ(6, model_->bookmark_bar_node()->GetTotalNodeCount());
1230 // Add a bookmark under f1 when sync is off so that f1 will not be 1231 // Add a bookmark under f1 when sync is off so that f1 will not be
1231 // deleted even when f1 matches delete journal because it's not empty. 1232 // deleted even when f1 matches delete journal because it's not empty.
1232 model_->AddURL(model_->bookmark_bar_node()->GetChild(1), 1233 model_->AddURL(model_->bookmark_bar_node()->GetChild(1),
1233 0, UTF8ToUTF16("local"), GURL("http://www.youtube.com")); 1234 0, base::UTF8ToUTF16("local"), GURL("http://www.youtube.com"));
1234 // Sync model has fixed bookmarks nodes and u3. 1235 // Sync model has fixed bookmarks nodes and u3.
1235 EXPECT_EQ(fixed_sync_bk_count + 1, GetSyncBookmarkCount()); 1236 EXPECT_EQ(fixed_sync_bk_count + 1, GetSyncBookmarkCount());
1236 StartSync(); 1237 StartSync();
1237 // Expect 4 bookmarks after model association because u2, f2, u1 are removed 1238 // Expect 4 bookmarks after model association because u2, f2, u1 are removed
1238 // by delete journal, f1 is not removed by delete journal because it's 1239 // by delete journal, f1 is not removed by delete journal because it's
1239 // not empty due to www.youtube.com added above. 1240 // not empty due to www.youtube.com added above.
1240 EXPECT_EQ(4, model_->bookmark_bar_node()->GetTotalNodeCount()); 1241 EXPECT_EQ(4, model_->bookmark_bar_node()->GetTotalNodeCount());
1241 EXPECT_EQ(UTF8ToUTF16("URL 0"), 1242 EXPECT_EQ(base::UTF8ToUTF16("URL 0"),
1242 model_->bookmark_bar_node()->GetChild(0)->GetTitle()); 1243 model_->bookmark_bar_node()->GetChild(0)->GetTitle());
1243 EXPECT_EQ(UTF8ToUTF16("Folder 1"), 1244 EXPECT_EQ(base::UTF8ToUTF16("Folder 1"),
1244 model_->bookmark_bar_node()->GetChild(1)->GetTitle()); 1245 model_->bookmark_bar_node()->GetChild(1)->GetTitle());
1245 EXPECT_EQ(UTF8ToUTF16("local"), 1246 EXPECT_EQ(base::UTF8ToUTF16("local"),
1246 model_->bookmark_bar_node()->GetChild(1)->GetChild(0)->GetTitle()); 1247 model_->bookmark_bar_node()->GetChild(1)->GetChild(0)->GetTitle());
1247 StopSync(); 1248 StopSync();
1248 1249
1249 // Verify purging of delete journals. 1250 // Verify purging of delete journals.
1250 // Delete journals for u2, f2, u1 remains because they are used in last 1251 // Delete journals for u2, f2, u1 remains because they are used in last
1251 // association. 1252 // association.
1252 EXPECT_EQ(3u, test_user_share_.GetDeleteJournalSize()); 1253 EXPECT_EQ(3u, test_user_share_.GetDeleteJournalSize());
1253 StartSync(); 1254 StartSync();
1254 StopSync(); 1255 StopSync();
1255 // Reload again and all delete journals should be gone because none is used 1256 // Reload again and all delete journals should be gone because none is used
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after
1769 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); 1770 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE);
1770 WriteTestDataToBookmarkModel(); 1771 WriteTestDataToBookmarkModel();
1771 StartSync(); 1772 StartSync();
1772 ExpectModelMatch(); 1773 ExpectModelMatch();
1773 // Force sync to shut down and write itself to disk. 1774 // Force sync to shut down and write itself to disk.
1774 StopSync(); 1775 StopSync();
1775 // Change the bookmark model before restarting sync service to simulate 1776 // Change the bookmark model before restarting sync service to simulate
1776 // the situation where bookmark model is different from sync model and 1777 // the situation where bookmark model is different from sync model and
1777 // make sure model associator correctly rebuilds associations. 1778 // make sure model associator correctly rebuilds associations.
1778 const BookmarkNode* bookmark_bar_node = model_->bookmark_bar_node(); 1779 const BookmarkNode* bookmark_bar_node = model_->bookmark_bar_node();
1779 model_->AddURL(bookmark_bar_node, 0, ASCIIToUTF16("xtra"), 1780 model_->AddURL(bookmark_bar_node, 0, base::ASCIIToUTF16("xtra"),
1780 GURL("http://www.xtra.com")); 1781 GURL("http://www.xtra.com"));
1781 // Now restart sync. This time it will try to use the persistent 1782 // Now restart sync. This time it will try to use the persistent
1782 // associations and realize that they are invalid and hence will rebuild 1783 // associations and realize that they are invalid and hence will rebuild
1783 // associations. 1784 // associations.
1784 StartSync(); 1785 StartSync();
1785 ExpectModelMatch(); 1786 ExpectModelMatch();
1786 } 1787 }
1787 1788
1788 TEST_F(ProfileSyncServiceBookmarkTestWithData, SortChildren) { 1789 TEST_F(ProfileSyncServiceBookmarkTestWithData, SortChildren) {
1789 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); 1790 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE);
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
1949 // Tests that changes to the local bookmark nodes meta info gets reflected in 1950 // Tests that changes to the local bookmark nodes meta info gets reflected in
1950 // the sync nodes. 1951 // the sync nodes.
1951 TEST_F(ProfileSyncServiceBookmarkTestWithData, UpdateMetaInfoFromModel) { 1952 TEST_F(ProfileSyncServiceBookmarkTestWithData, UpdateMetaInfoFromModel) {
1952 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); 1953 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE);
1953 WriteTestDataToBookmarkModel(); 1954 WriteTestDataToBookmarkModel();
1954 StartSync(); 1955 StartSync();
1955 ExpectBookmarkModelMatchesTestData(); 1956 ExpectBookmarkModelMatchesTestData();
1956 1957
1957 const BookmarkNode* folder_node = 1958 const BookmarkNode* folder_node =
1958 model_->AddFolder(model_->bookmark_bar_node(), 0, 1959 model_->AddFolder(model_->bookmark_bar_node(), 0,
1959 ASCIIToUTF16("folder title")); 1960 base::ASCIIToUTF16("folder title"));
1960 const BookmarkNode* node = model_->AddURL(folder_node, 0, 1961 const BookmarkNode* node = model_->AddURL(folder_node, 0,
1961 ASCIIToUTF16("node title"), 1962 base::ASCIIToUTF16("node title"),
1962 GURL("http://www.foo.com")); 1963 GURL("http://www.foo.com"));
1963 ExpectModelMatch(); 1964 ExpectModelMatch();
1964 1965
1965 // Add some meta info and verify sync model matches the changes. 1966 // Add some meta info and verify sync model matches the changes.
1966 model_->SetNodeMetaInfo(folder_node, "folder", "foldervalue"); 1967 model_->SetNodeMetaInfo(folder_node, "folder", "foldervalue");
1967 model_->SetNodeMetaInfo(node, "node", "nodevalue"); 1968 model_->SetNodeMetaInfo(node, "node", "nodevalue");
1968 model_->SetNodeMetaInfo(node, "other", "othervalue"); 1969 model_->SetNodeMetaInfo(node, "other", "othervalue");
1969 ExpectModelMatch(); 1970 ExpectModelMatch();
1970 1971
1971 // Change/delete existing meta info and verify. 1972 // Change/delete existing meta info and verify.
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
2105 int64 root_version = initial_versions[model_->root_node()->id()]; 2106 int64 root_version = initial_versions[model_->root_node()->id()];
2106 model_->SetNodeSyncTransactionVersion(model_->root_node(), root_version + 1); 2107 model_->SetNodeSyncTransactionVersion(model_->root_node(), root_version + 1);
2107 2108
2108 // Upon association, bookmarks should fail to associate. 2109 // Upon association, bookmarks should fail to associate.
2109 EXPECT_FALSE(AssociateModels()); 2110 EXPECT_FALSE(AssociateModels());
2110 } 2111 }
2111 2112
2112 } // namespace 2113 } // namespace
2113 2114
2114 } // namespace browser_sync 2115 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698