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

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

Issue 7612015: sync: Make BaseNode::GetTitle() return std::string. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix syncapi_unittest Created 9 years, 4 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
« no previous file with comments | « chrome/browser/sync/glue/bookmark_model_associator.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <stack> 9 #include <stack>
10 #include <vector> 10 #include <vector>
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 sync_api::UserShare* user_share, 51 sync_api::UserShare* user_share,
52 UnrecoverableErrorHandler* unrecoverable_error_handler) 52 UnrecoverableErrorHandler* unrecoverable_error_handler)
53 : BookmarkModelAssociator(bookmark_model, user_share, 53 : BookmarkModelAssociator(bookmark_model, user_share,
54 unrecoverable_error_handler), 54 unrecoverable_error_handler),
55 user_share_(user_share) {} 55 user_share_(user_share) {}
56 56
57 // TODO(akalin): This logic lazily creates any tagged node that is 57 // TODO(akalin): This logic lazily creates any tagged node that is
58 // requested. A better way would be to have utility functions to 58 // requested. A better way would be to have utility functions to
59 // create sync nodes from some bookmark structure and to use that. 59 // create sync nodes from some bookmark structure and to use that.
60 virtual bool GetSyncIdForTaggedNode(const std::string& tag, int64* sync_id) { 60 virtual bool GetSyncIdForTaggedNode(const std::string& tag, int64* sync_id) {
61 std::wstring tag_wide; 61 std::string tag_str = std::string(tag.c_str(), tag.length());
62 if (!UTF8ToWide(tag.c_str(), tag.length(), &tag_wide)) {
63 NOTREACHED() << "Unable to convert UTF8 to wide for string: " << tag;
64 return false;
65 }
66
67 bool root_exists = false; 62 bool root_exists = false;
68 syncable::ModelType type = model_type(); 63 syncable::ModelType type = model_type();
69 { 64 {
70 sync_api::WriteTransaction trans(FROM_HERE, user_share_); 65 sync_api::WriteTransaction trans(FROM_HERE, user_share_);
71 sync_api::ReadNode uber_root(&trans); 66 sync_api::ReadNode uber_root(&trans);
72 uber_root.InitByRootLookup(); 67 uber_root.InitByRootLookup();
73 68
74 sync_api::ReadNode root(&trans); 69 sync_api::ReadNode root(&trans);
75 root_exists = root.InitByTagLookup( 70 root_exists = root.InitByTagLookup(
76 ProfileSyncServiceTestHelper::GetTagForType(type)); 71 ProfileSyncServiceTestHelper::GetTagForType(type));
(...skipping 14 matching lines...) Expand all
91 ProfileSyncServiceTestHelper::GetTagForType(type))); 86 ProfileSyncServiceTestHelper::GetTagForType(type)));
92 87
93 // First, try to find a node with the title among the root's children. 88 // First, try to find a node with the title among the root's children.
94 // This will be the case if we are testing model persistence, and 89 // This will be the case if we are testing model persistence, and
95 // are reloading a sync repository created earlier in the test. 90 // are reloading a sync repository created earlier in the test.
96 int64 last_child_id = sync_api::kInvalidId; 91 int64 last_child_id = sync_api::kInvalidId;
97 for (int64 id = root.GetFirstChildId(); id != sync_api::kInvalidId; /***/) { 92 for (int64 id = root.GetFirstChildId(); id != sync_api::kInvalidId; /***/) {
98 sync_api::ReadNode child(&trans); 93 sync_api::ReadNode child(&trans);
99 child.InitByIdLookup(id); 94 child.InitByIdLookup(id);
100 last_child_id = id; 95 last_child_id = id;
101 if (tag_wide == child.GetTitle()) { 96 if (tag_str == child.GetTitle()) {
102 *sync_id = id; 97 *sync_id = id;
103 return true; 98 return true;
104 } 99 }
105 id = child.GetSuccessorId(); 100 id = child.GetSuccessorId();
106 } 101 }
107 102
108 sync_api::ReadNode predecessor_node(&trans); 103 sync_api::ReadNode predecessor_node(&trans);
109 sync_api::ReadNode* predecessor = NULL; 104 sync_api::ReadNode* predecessor = NULL;
110 if (last_child_id != sync_api::kInvalidId) { 105 if (last_child_id != sync_api::kInvalidId) {
111 predecessor_node.InitByIdLookup(last_child_id); 106 predecessor_node.InitByIdLookup(last_child_id);
112 predecessor = &predecessor_node; 107 predecessor = &predecessor_node;
113 } 108 }
114 sync_api::WriteNode node(&trans); 109 sync_api::WriteNode node(&trans);
115 // Create new fake tagged nodes at the end of the ordering. 110 // Create new fake tagged nodes at the end of the ordering.
116 node.InitByCreation(type, root, predecessor); 111 node.InitByCreation(type, root, predecessor);
117 node.SetIsFolder(true); 112 node.SetIsFolder(true);
118 node.SetTitle(tag_wide); 113 node.SetTitle(UTF8ToWide(tag_str));
119 node.SetExternalId(0); 114 node.SetExternalId(0);
120 *sync_id = node.GetId(); 115 *sync_id = node.GetId();
121 return true; 116 return true;
122 } 117 }
123 118
124 private: 119 private:
125 sync_api::UserShare* user_share_; 120 sync_api::UserShare* user_share_;
126 browser_sync::TestIdFactory id_factory_; 121 browser_sync::TestIdFactory id_factory_;
127 }; 122 };
128 123
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 // a practical matter, users of FakeServerChange must move or delete 201 // a practical matter, users of FakeServerChange must move or delete
207 // children before parents. Thus, we must insert the deletion record 202 // children before parents. Thus, we must insert the deletion record
208 // at the front of the vector. 203 // at the front of the vector.
209 changes_.insert(changes_.begin(), record); 204 changes_.insert(changes_.begin(), record);
210 } 205 }
211 206
212 // Set a new title value, and return the old value. 207 // Set a new title value, and return the old value.
213 std::wstring ModifyTitle(int64 id, const std::wstring& new_title) { 208 std::wstring ModifyTitle(int64 id, const std::wstring& new_title) {
214 sync_api::WriteNode node(trans_); 209 sync_api::WriteNode node(trans_);
215 EXPECT_TRUE(node.InitByIdLookup(id)); 210 EXPECT_TRUE(node.InitByIdLookup(id));
216 std::wstring old_title = node.GetTitle(); 211 std::string old_title = node.GetTitle();
217 node.SetTitle(new_title); 212 node.SetTitle(new_title);
218 SetModified(id); 213 SetModified(id);
219 return old_title; 214 return UTF8ToWide(old_title);
220 } 215 }
221 216
222 // Set a new parent and predecessor value. Return the old parent id. 217 // Set a new parent and predecessor value. Return the old parent id.
223 // We could return the old predecessor id, but it turns out not to be 218 // We could return the old predecessor id, but it turns out not to be
224 // very useful for assertions. 219 // very useful for assertions.
225 int64 ModifyPosition(int64 id, int64 parent_id, int64 predecessor_id) { 220 int64 ModifyPosition(int64 id, int64 parent_id, int64 predecessor_id) {
226 sync_api::ReadNode parent(trans_); 221 sync_api::ReadNode parent(trans_);
227 EXPECT_TRUE(parent.InitByIdLookup(parent_id)); 222 EXPECT_TRUE(parent.InitByIdLookup(parent_id));
228 sync_api::WriteNode node(trans_); 223 sync_api::WriteNode node(trans_);
229 EXPECT_TRUE(node.InitByIdLookup(id)); 224 EXPECT_TRUE(node.InitByIdLookup(id));
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 return model_associator_->InitSyncNodeFromChromeId(bnode->id(), 358 return model_associator_->InitSyncNodeFromChromeId(bnode->id(),
364 sync_node); 359 sync_node);
365 } 360 }
366 361
367 void ExpectSyncerNodeMatching(sync_api::BaseTransaction* trans, 362 void ExpectSyncerNodeMatching(sync_api::BaseTransaction* trans,
368 const BookmarkNode* bnode) { 363 const BookmarkNode* bnode) {
369 sync_api::ReadNode gnode(trans); 364 sync_api::ReadNode gnode(trans);
370 ASSERT_TRUE(InitSyncNodeFromChromeNode(bnode, &gnode)); 365 ASSERT_TRUE(InitSyncNodeFromChromeNode(bnode, &gnode));
371 // Non-root node titles and parents must match. 366 // Non-root node titles and parents must match.
372 if (!model_->is_permanent_node(bnode)) { 367 if (!model_->is_permanent_node(bnode)) {
373 EXPECT_EQ(bnode->GetTitle(), WideToUTF16Hack(gnode.GetTitle())); 368 EXPECT_EQ(bnode->GetTitle(), UTF8ToUTF16(gnode.GetTitle()));
374 EXPECT_EQ( 369 EXPECT_EQ(
375 model_associator_->GetChromeNodeFromSyncId(gnode.GetParentId()), 370 model_associator_->GetChromeNodeFromSyncId(gnode.GetParentId()),
376 bnode->parent()); 371 bnode->parent());
377 } 372 }
378 EXPECT_EQ(bnode->is_folder(), gnode.GetIsFolder()); 373 EXPECT_EQ(bnode->is_folder(), gnode.GetIsFolder());
379 if (bnode->is_url()) 374 if (bnode->is_url())
380 EXPECT_EQ(bnode->url(), gnode.GetURL()); 375 EXPECT_EQ(bnode->url(), gnode.GetURL());
381 376
382 // Check for position matches. 377 // Check for position matches.
383 int browser_index = bnode->parent()->GetIndexOf(bnode); 378 int browser_index = bnode->parent()->GetIndexOf(bnode);
(...skipping 1048 matching lines...) Expand 10 before | Expand all | Expand 10 after
1432 // Make sure we're back in sync. In real life, the user would need 1427 // Make sure we're back in sync. In real life, the user would need
1433 // to reauthenticate before this happens, but in the test, authentication 1428 // to reauthenticate before this happens, but in the test, authentication
1434 // is sidestepped. 1429 // is sidestepped.
1435 ExpectBookmarkModelMatchesTestData(); 1430 ExpectBookmarkModelMatchesTestData();
1436 ExpectModelMatch(); 1431 ExpectModelMatch();
1437 } 1432 }
1438 1433
1439 } // namespace 1434 } // namespace
1440 1435
1441 } // namespace browser_sync 1436 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/bookmark_model_associator.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698