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

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

Issue 10698014: [Sync] Rename csync namespace to syncer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 8 years, 5 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 <stack> 9 #include <stack>
10 #include <vector> 10 #include <vector>
(...skipping 26 matching lines...) Expand all
37 #include "sync/internal_api/public/write_node.h" 37 #include "sync/internal_api/public/write_node.h"
38 #include "sync/internal_api/public/write_transaction.h" 38 #include "sync/internal_api/public/write_transaction.h"
39 #include "sync/syncable/mutable_entry.h" // TODO(tim): Remove. Bug 131130. 39 #include "sync/syncable/mutable_entry.h" // TODO(tim): Remove. Bug 131130.
40 #include "sync/test/engine/test_id_factory.h" 40 #include "sync/test/engine/test_id_factory.h"
41 #include "testing/gmock/include/gmock/gmock.h" 41 #include "testing/gmock/include/gmock/gmock.h"
42 #include "testing/gtest/include/gtest/gtest.h" 42 #include "testing/gtest/include/gtest/gtest.h"
43 43
44 namespace browser_sync { 44 namespace browser_sync {
45 45
46 using content::BrowserThread; 46 using content::BrowserThread;
47 using csync::BaseNode; 47 using syncer::BaseNode;
48 using testing::_; 48 using testing::_;
49 using testing::InvokeWithoutArgs; 49 using testing::InvokeWithoutArgs;
50 using testing::Mock; 50 using testing::Mock;
51 using testing::StrictMock; 51 using testing::StrictMock;
52 52
53 class TestBookmarkModelAssociator : public BookmarkModelAssociator { 53 class TestBookmarkModelAssociator : public BookmarkModelAssociator {
54 public: 54 public:
55 TestBookmarkModelAssociator( 55 TestBookmarkModelAssociator(
56 BookmarkModel* bookmark_model, 56 BookmarkModel* bookmark_model,
57 csync::UserShare* user_share, 57 syncer::UserShare* user_share,
58 DataTypeErrorHandler* error_handler) 58 DataTypeErrorHandler* error_handler)
59 : BookmarkModelAssociator(bookmark_model, user_share, 59 : BookmarkModelAssociator(bookmark_model, user_share,
60 error_handler, 60 error_handler,
61 true /* expect_mobile_bookmarks_folder */), 61 true /* expect_mobile_bookmarks_folder */),
62 user_share_(user_share) {} 62 user_share_(user_share) {}
63 63
64 // TODO(akalin): This logic lazily creates any tagged node that is 64 // TODO(akalin): This logic lazily creates any tagged node that is
65 // requested. A better way would be to have utility functions to 65 // requested. A better way would be to have utility functions to
66 // create sync nodes from some bookmark structure and to use that. 66 // create sync nodes from some bookmark structure and to use that.
67 virtual bool GetSyncIdForTaggedNode(const std::string& tag, int64* sync_id) { 67 virtual bool GetSyncIdForTaggedNode(const std::string& tag, int64* sync_id) {
68 std::string tag_str = std::string(tag.c_str(), tag.length()); 68 std::string tag_str = std::string(tag.c_str(), tag.length());
69 bool root_exists = false; 69 bool root_exists = false;
70 syncable::ModelType type = model_type(); 70 syncable::ModelType type = model_type();
71 { 71 {
72 csync::WriteTransaction trans(FROM_HERE, user_share_); 72 syncer::WriteTransaction trans(FROM_HERE, user_share_);
73 csync::ReadNode uber_root(&trans); 73 syncer::ReadNode uber_root(&trans);
74 uber_root.InitByRootLookup(); 74 uber_root.InitByRootLookup();
75 75
76 csync::ReadNode root(&trans); 76 syncer::ReadNode root(&trans);
77 root_exists = root.InitByTagLookup( 77 root_exists = root.InitByTagLookup(
78 ProfileSyncServiceTestHelper::GetTagForType(type)) == 78 ProfileSyncServiceTestHelper::GetTagForType(type)) ==
79 BaseNode::INIT_OK; 79 BaseNode::INIT_OK;
80 } 80 }
81 81
82 if (!root_exists) { 82 if (!root_exists) {
83 bool created = ProfileSyncServiceTestHelper::CreateRoot( 83 bool created = ProfileSyncServiceTestHelper::CreateRoot(
84 type, 84 type,
85 user_share_, 85 user_share_,
86 &id_factory_); 86 &id_factory_);
87 if (!created) 87 if (!created)
88 return false; 88 return false;
89 } 89 }
90 90
91 csync::WriteTransaction trans(FROM_HERE, user_share_); 91 syncer::WriteTransaction trans(FROM_HERE, user_share_);
92 csync::ReadNode root(&trans); 92 syncer::ReadNode root(&trans);
93 EXPECT_EQ(BaseNode::INIT_OK, root.InitByTagLookup( 93 EXPECT_EQ(BaseNode::INIT_OK, root.InitByTagLookup(
94 ProfileSyncServiceTestHelper::GetTagForType(type))); 94 ProfileSyncServiceTestHelper::GetTagForType(type)));
95 95
96 // First, try to find a node with the title among the root's children. 96 // First, try to find a node with the title among the root's children.
97 // This will be the case if we are testing model persistence, and 97 // This will be the case if we are testing model persistence, and
98 // are reloading a sync repository created earlier in the test. 98 // are reloading a sync repository created earlier in the test.
99 int64 last_child_id = csync::kInvalidId; 99 int64 last_child_id = syncer::kInvalidId;
100 for (int64 id = root.GetFirstChildId(); id != csync::kInvalidId; /***/) { 100 for (int64 id = root.GetFirstChildId(); id != syncer::kInvalidId; /***/) {
101 csync::ReadNode child(&trans); 101 syncer::ReadNode child(&trans);
102 EXPECT_EQ(BaseNode::INIT_OK, child.InitByIdLookup(id)); 102 EXPECT_EQ(BaseNode::INIT_OK, child.InitByIdLookup(id));
103 last_child_id = id; 103 last_child_id = id;
104 if (tag_str == child.GetTitle()) { 104 if (tag_str == child.GetTitle()) {
105 *sync_id = id; 105 *sync_id = id;
106 return true; 106 return true;
107 } 107 }
108 id = child.GetSuccessorId(); 108 id = child.GetSuccessorId();
109 } 109 }
110 110
111 csync::ReadNode predecessor_node(&trans); 111 syncer::ReadNode predecessor_node(&trans);
112 csync::ReadNode* predecessor = NULL; 112 syncer::ReadNode* predecessor = NULL;
113 if (last_child_id != csync::kInvalidId) { 113 if (last_child_id != syncer::kInvalidId) {
114 EXPECT_EQ(BaseNode::INIT_OK, 114 EXPECT_EQ(BaseNode::INIT_OK,
115 predecessor_node.InitByIdLookup(last_child_id)); 115 predecessor_node.InitByIdLookup(last_child_id));
116 predecessor = &predecessor_node; 116 predecessor = &predecessor_node;
117 } 117 }
118 csync::WriteNode node(&trans); 118 syncer::WriteNode node(&trans);
119 // Create new fake tagged nodes at the end of the ordering. 119 // Create new fake tagged nodes at the end of the ordering.
120 node.InitByCreation(type, root, predecessor); 120 node.InitByCreation(type, root, predecessor);
121 node.SetIsFolder(true); 121 node.SetIsFolder(true);
122 node.GetMutableEntryForTest()->Put(syncable::UNIQUE_SERVER_TAG, tag); 122 node.GetMutableEntryForTest()->Put(syncable::UNIQUE_SERVER_TAG, tag);
123 node.SetTitle(UTF8ToWide(tag_str)); 123 node.SetTitle(UTF8ToWide(tag_str));
124 node.SetExternalId(0); 124 node.SetExternalId(0);
125 *sync_id = node.GetId(); 125 *sync_id = node.GetId();
126 return true; 126 return true;
127 } 127 }
128 128
129 private: 129 private:
130 csync::UserShare* user_share_; 130 syncer::UserShare* user_share_;
131 csync::TestIdFactory id_factory_; 131 syncer::TestIdFactory id_factory_;
132 }; 132 };
133 133
134 namespace { 134 namespace {
135 135
136 // FakeServerChange constructs a list of csync::ChangeRecords while modifying 136 // FakeServerChange constructs a list of syncer::ChangeRecords while modifying
137 // the sync model, and can pass the ChangeRecord list to a 137 // the sync model, and can pass the ChangeRecord list to a
138 // csync::SyncObserver (i.e., the ProfileSyncService) to test the client 138 // syncer::SyncObserver (i.e., the ProfileSyncService) to test the client
139 // change-application behavior. 139 // change-application behavior.
140 // Tests using FakeServerChange should be careful to avoid back-references, 140 // Tests using FakeServerChange should be careful to avoid back-references,
141 // since FakeServerChange will send the edits in the order specified. 141 // since FakeServerChange will send the edits in the order specified.
142 class FakeServerChange { 142 class FakeServerChange {
143 public: 143 public:
144 explicit FakeServerChange(csync::WriteTransaction* trans) : trans_(trans) { 144 explicit FakeServerChange(syncer::WriteTransaction* trans) : trans_(trans) {
145 } 145 }
146 146
147 // Pretend that the server told the syncer to add a bookmark object. 147 // Pretend that the server told the syncer to add a bookmark object.
148 int64 Add(const std::wstring& title, 148 int64 Add(const std::wstring& title,
149 const std::string& url, 149 const std::string& url,
150 bool is_folder, 150 bool is_folder,
151 int64 parent_id, 151 int64 parent_id,
152 int64 predecessor_id) { 152 int64 predecessor_id) {
153 csync::ReadNode parent(trans_); 153 syncer::ReadNode parent(trans_);
154 EXPECT_EQ(BaseNode::INIT_OK, parent.InitByIdLookup(parent_id)); 154 EXPECT_EQ(BaseNode::INIT_OK, parent.InitByIdLookup(parent_id));
155 csync::WriteNode node(trans_); 155 syncer::WriteNode node(trans_);
156 if (predecessor_id == 0) { 156 if (predecessor_id == 0) {
157 EXPECT_TRUE(node.InitByCreation(syncable::BOOKMARKS, parent, NULL)); 157 EXPECT_TRUE(node.InitByCreation(syncable::BOOKMARKS, parent, NULL));
158 } else { 158 } else {
159 csync::ReadNode predecessor(trans_); 159 syncer::ReadNode predecessor(trans_);
160 EXPECT_EQ(BaseNode::INIT_OK, predecessor.InitByIdLookup(predecessor_id)); 160 EXPECT_EQ(BaseNode::INIT_OK, predecessor.InitByIdLookup(predecessor_id));
161 EXPECT_EQ(predecessor.GetParentId(), parent.GetId()); 161 EXPECT_EQ(predecessor.GetParentId(), parent.GetId());
162 EXPECT_TRUE(node.InitByCreation(syncable::BOOKMARKS, parent, 162 EXPECT_TRUE(node.InitByCreation(syncable::BOOKMARKS, parent,
163 &predecessor)); 163 &predecessor));
164 } 164 }
165 EXPECT_EQ(node.GetPredecessorId(), predecessor_id); 165 EXPECT_EQ(node.GetPredecessorId(), predecessor_id);
166 EXPECT_EQ(node.GetParentId(), parent_id); 166 EXPECT_EQ(node.GetParentId(), parent_id);
167 node.SetIsFolder(is_folder); 167 node.SetIsFolder(is_folder);
168 node.SetTitle(title); 168 node.SetTitle(title);
169 if (!is_folder) 169 if (!is_folder)
170 node.SetURL(GURL(url)); 170 node.SetURL(GURL(url));
171 csync::ChangeRecord record; 171 syncer::ChangeRecord record;
172 record.action = csync::ChangeRecord::ACTION_ADD; 172 record.action = syncer::ChangeRecord::ACTION_ADD;
173 record.id = node.GetId(); 173 record.id = node.GetId();
174 changes_.push_back(record); 174 changes_.push_back(record);
175 return node.GetId(); 175 return node.GetId();
176 } 176 }
177 177
178 // Add a bookmark folder. 178 // Add a bookmark folder.
179 int64 AddFolder(const std::wstring& title, 179 int64 AddFolder(const std::wstring& title,
180 int64 parent_id, 180 int64 parent_id,
181 int64 predecessor_id) { 181 int64 predecessor_id) {
182 return Add(title, std::string(), true, parent_id, predecessor_id); 182 return Add(title, std::string(), true, parent_id, predecessor_id);
183 } 183 }
184 184
185 // Add a bookmark. 185 // Add a bookmark.
186 int64 AddURL(const std::wstring& title, 186 int64 AddURL(const std::wstring& title,
187 const std::string& url, 187 const std::string& url,
188 int64 parent_id, 188 int64 parent_id,
189 int64 predecessor_id) { 189 int64 predecessor_id) {
190 return Add(title, url, false, parent_id, predecessor_id); 190 return Add(title, url, false, parent_id, predecessor_id);
191 } 191 }
192 192
193 // Pretend that the server told the syncer to delete an object. 193 // Pretend that the server told the syncer to delete an object.
194 void Delete(int64 id) { 194 void Delete(int64 id) {
195 { 195 {
196 // Delete the sync node. 196 // Delete the sync node.
197 csync::WriteNode node(trans_); 197 syncer::WriteNode node(trans_);
198 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(id)); 198 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(id));
199 EXPECT_FALSE(node.GetFirstChildId()); 199 EXPECT_FALSE(node.GetFirstChildId());
200 node.Remove(); 200 node.Remove();
201 } 201 }
202 { 202 {
203 // Verify the deletion. 203 // Verify the deletion.
204 csync::ReadNode node(trans_); 204 syncer::ReadNode node(trans_);
205 EXPECT_EQ(BaseNode::INIT_FAILED_ENTRY_IS_DEL, node.InitByIdLookup(id)); 205 EXPECT_EQ(BaseNode::INIT_FAILED_ENTRY_IS_DEL, node.InitByIdLookup(id));
206 } 206 }
207 207
208 csync::ChangeRecord record; 208 syncer::ChangeRecord record;
209 record.action = csync::ChangeRecord::ACTION_DELETE; 209 record.action = syncer::ChangeRecord::ACTION_DELETE;
210 record.id = id; 210 record.id = id;
211 // Deletions are always first in the changelist, but we can't actually do 211 // Deletions are always first in the changelist, but we can't actually do
212 // WriteNode::Remove() on the node until its children are moved. So, as 212 // WriteNode::Remove() on the node until its children are moved. So, as
213 // a practical matter, users of FakeServerChange must move or delete 213 // a practical matter, users of FakeServerChange must move or delete
214 // children before parents. Thus, we must insert the deletion record 214 // children before parents. Thus, we must insert the deletion record
215 // at the front of the vector. 215 // at the front of the vector.
216 changes_.insert(changes_.begin(), record); 216 changes_.insert(changes_.begin(), record);
217 } 217 }
218 218
219 // Set a new title value, and return the old value. 219 // Set a new title value, and return the old value.
220 std::wstring ModifyTitle(int64 id, const std::wstring& new_title) { 220 std::wstring ModifyTitle(int64 id, const std::wstring& new_title) {
221 csync::WriteNode node(trans_); 221 syncer::WriteNode node(trans_);
222 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(id)); 222 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(id));
223 std::string old_title = node.GetTitle(); 223 std::string old_title = node.GetTitle();
224 node.SetTitle(new_title); 224 node.SetTitle(new_title);
225 SetModified(id); 225 SetModified(id);
226 return UTF8ToWide(old_title); 226 return UTF8ToWide(old_title);
227 } 227 }
228 228
229 // Set a new parent and predecessor value. Return the old parent id. 229 // Set a new parent and predecessor value. Return the old parent id.
230 // We could return the old predecessor id, but it turns out not to be 230 // We could return the old predecessor id, but it turns out not to be
231 // very useful for assertions. 231 // very useful for assertions.
232 int64 ModifyPosition(int64 id, int64 parent_id, int64 predecessor_id) { 232 int64 ModifyPosition(int64 id, int64 parent_id, int64 predecessor_id) {
233 csync::ReadNode parent(trans_); 233 syncer::ReadNode parent(trans_);
234 EXPECT_EQ(BaseNode::INIT_OK, parent.InitByIdLookup(parent_id)); 234 EXPECT_EQ(BaseNode::INIT_OK, parent.InitByIdLookup(parent_id));
235 csync::WriteNode node(trans_); 235 syncer::WriteNode node(trans_);
236 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(id)); 236 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(id));
237 int64 old_parent_id = node.GetParentId(); 237 int64 old_parent_id = node.GetParentId();
238 if (predecessor_id == 0) { 238 if (predecessor_id == 0) {
239 EXPECT_TRUE(node.SetPosition(parent, NULL)); 239 EXPECT_TRUE(node.SetPosition(parent, NULL));
240 } else { 240 } else {
241 csync::ReadNode predecessor(trans_); 241 syncer::ReadNode predecessor(trans_);
242 EXPECT_EQ(BaseNode::INIT_OK, predecessor.InitByIdLookup(predecessor_id)); 242 EXPECT_EQ(BaseNode::INIT_OK, predecessor.InitByIdLookup(predecessor_id));
243 EXPECT_EQ(predecessor.GetParentId(), parent.GetId()); 243 EXPECT_EQ(predecessor.GetParentId(), parent.GetId());
244 EXPECT_TRUE(node.SetPosition(parent, &predecessor)); 244 EXPECT_TRUE(node.SetPosition(parent, &predecessor));
245 } 245 }
246 SetModified(id); 246 SetModified(id);
247 return old_parent_id; 247 return old_parent_id;
248 } 248 }
249 249
250 // Pass the fake change list to |service|. 250 // Pass the fake change list to |service|.
251 void ApplyPendingChanges(ChangeProcessor* processor) { 251 void ApplyPendingChanges(ChangeProcessor* processor) {
252 processor->ApplyChangesFromSyncModel( 252 processor->ApplyChangesFromSyncModel(
253 trans_, csync::ImmutableChangeRecordList(&changes_)); 253 trans_, syncer::ImmutableChangeRecordList(&changes_));
254 } 254 }
255 255
256 const csync::ChangeRecordList& changes() { 256 const syncer::ChangeRecordList& changes() {
257 return changes_; 257 return changes_;
258 } 258 }
259 259
260 private: 260 private:
261 // Helper function to push an ACTION_UPDATE record onto the back 261 // Helper function to push an ACTION_UPDATE record onto the back
262 // of the changelist. 262 // of the changelist.
263 void SetModified(int64 id) { 263 void SetModified(int64 id) {
264 // Coalesce multi-property edits. 264 // Coalesce multi-property edits.
265 if (!changes_.empty() && changes_.back().id == id && 265 if (!changes_.empty() && changes_.back().id == id &&
266 changes_.back().action == 266 changes_.back().action ==
267 csync::ChangeRecord::ACTION_UPDATE) 267 syncer::ChangeRecord::ACTION_UPDATE)
268 return; 268 return;
269 csync::ChangeRecord record; 269 syncer::ChangeRecord record;
270 record.action = csync::ChangeRecord::ACTION_UPDATE; 270 record.action = syncer::ChangeRecord::ACTION_UPDATE;
271 record.id = id; 271 record.id = id;
272 changes_.push_back(record); 272 changes_.push_back(record);
273 } 273 }
274 274
275 // The transaction on which everything happens. 275 // The transaction on which everything happens.
276 csync::WriteTransaction *trans_; 276 syncer::WriteTransaction *trans_;
277 277
278 // The change list we construct. 278 // The change list we construct.
279 csync::ChangeRecordList changes_; 279 syncer::ChangeRecordList changes_;
280 }; 280 };
281 281
282 class ExtensiveChangesBookmarkModelObserver : public BaseBookmarkModelObserver { 282 class ExtensiveChangesBookmarkModelObserver : public BaseBookmarkModelObserver {
283 public: 283 public:
284 explicit ExtensiveChangesBookmarkModelObserver() 284 explicit ExtensiveChangesBookmarkModelObserver()
285 : started_count_(0), 285 : started_count_(0),
286 completed_count_at_started_(0), 286 completed_count_at_started_(0),
287 completed_count_(0) {} 287 completed_count_(0) {}
288 288
289 virtual void ExtensiveBookmarkChangesBeginning( 289 virtual void ExtensiveBookmarkChangesBeginning(
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 model_->ClearStore(); 357 model_->ClearStore();
358 message_loop_.RunAllPending(); 358 message_loop_.RunAllPending();
359 } 359 }
360 360
361 void StartSync() { 361 void StartSync() {
362 // Set up model associator. 362 // Set up model associator.
363 model_associator_.reset(new TestBookmarkModelAssociator( 363 model_associator_.reset(new TestBookmarkModelAssociator(
364 profile_.GetBookmarkModel(), 364 profile_.GetBookmarkModel(),
365 test_user_share_.user_share(), 365 test_user_share_.user_share(),
366 &mock_error_handler_)); 366 &mock_error_handler_));
367 csync::SyncError error = model_associator_->AssociateModels(); 367 syncer::SyncError error = model_associator_->AssociateModels();
368 EXPECT_FALSE(error.IsSet()); 368 EXPECT_FALSE(error.IsSet());
369 MessageLoop::current()->RunAllPending(); 369 MessageLoop::current()->RunAllPending();
370 370
371 // Set up change processor. 371 // Set up change processor.
372 change_processor_.reset( 372 change_processor_.reset(
373 new BookmarkChangeProcessor(model_associator_.get(), 373 new BookmarkChangeProcessor(model_associator_.get(),
374 &mock_error_handler_)); 374 &mock_error_handler_));
375 change_processor_->Start(&profile_, test_user_share_.user_share()); 375 change_processor_->Start(&profile_, test_user_share_.user_share());
376 } 376 }
377 377
378 void StopSync() { 378 void StopSync() {
379 change_processor_->Stop(); 379 change_processor_->Stop();
380 change_processor_.reset(); 380 change_processor_.reset();
381 csync::SyncError error = model_associator_->DisassociateModels(); 381 syncer::SyncError error = model_associator_->DisassociateModels();
382 EXPECT_FALSE(error.IsSet()); 382 EXPECT_FALSE(error.IsSet());
383 model_associator_.reset(); 383 model_associator_.reset();
384 384
385 message_loop_.RunAllPending(); 385 message_loop_.RunAllPending();
386 386
387 // TODO(akalin): Actually close the database and flush it to disk 387 // TODO(akalin): Actually close the database and flush it to disk
388 // (and make StartSync reload from disk). This would require 388 // (and make StartSync reload from disk). This would require
389 // refactoring TestUserShare. 389 // refactoring TestUserShare.
390 } 390 }
391 391
392 void UnloadBookmarkModel() { 392 void UnloadBookmarkModel() {
393 profile_.CreateBookmarkModel(false /* delete_bookmarks */); 393 profile_.CreateBookmarkModel(false /* delete_bookmarks */);
394 model_ = NULL; 394 model_ = NULL;
395 message_loop_.RunAllPending(); 395 message_loop_.RunAllPending();
396 } 396 }
397 397
398 bool InitSyncNodeFromChromeNode(const BookmarkNode* bnode, 398 bool InitSyncNodeFromChromeNode(const BookmarkNode* bnode,
399 csync::BaseNode* sync_node) { 399 syncer::BaseNode* sync_node) {
400 return model_associator_->InitSyncNodeFromChromeId(bnode->id(), 400 return model_associator_->InitSyncNodeFromChromeId(bnode->id(),
401 sync_node); 401 sync_node);
402 } 402 }
403 403
404 void ExpectSyncerNodeMatching(csync::BaseTransaction* trans, 404 void ExpectSyncerNodeMatching(syncer::BaseTransaction* trans,
405 const BookmarkNode* bnode) { 405 const BookmarkNode* bnode) {
406 csync::ReadNode gnode(trans); 406 syncer::ReadNode gnode(trans);
407 ASSERT_TRUE(InitSyncNodeFromChromeNode(bnode, &gnode)); 407 ASSERT_TRUE(InitSyncNodeFromChromeNode(bnode, &gnode));
408 // Non-root node titles and parents must match. 408 // Non-root node titles and parents must match.
409 if (!model_->is_permanent_node(bnode)) { 409 if (!model_->is_permanent_node(bnode)) {
410 EXPECT_EQ(bnode->GetTitle(), UTF8ToUTF16(gnode.GetTitle())); 410 EXPECT_EQ(bnode->GetTitle(), UTF8ToUTF16(gnode.GetTitle()));
411 EXPECT_EQ( 411 EXPECT_EQ(
412 model_associator_->GetChromeNodeFromSyncId(gnode.GetParentId()), 412 model_associator_->GetChromeNodeFromSyncId(gnode.GetParentId()),
413 bnode->parent()); 413 bnode->parent());
414 } 414 }
415 EXPECT_EQ(bnode->is_folder(), gnode.GetIsFolder()); 415 EXPECT_EQ(bnode->is_folder(), gnode.GetIsFolder());
416 if (bnode->is_url()) 416 if (bnode->is_url())
417 EXPECT_EQ(bnode->url(), gnode.GetURL()); 417 EXPECT_EQ(bnode->url(), gnode.GetURL());
418 418
419 // Check for position matches. 419 // Check for position matches.
420 int browser_index = bnode->parent()->GetIndexOf(bnode); 420 int browser_index = bnode->parent()->GetIndexOf(bnode);
421 if (browser_index == 0) { 421 if (browser_index == 0) {
422 EXPECT_EQ(gnode.GetPredecessorId(), 0); 422 EXPECT_EQ(gnode.GetPredecessorId(), 0);
423 } else { 423 } else {
424 const BookmarkNode* bprev = 424 const BookmarkNode* bprev =
425 bnode->parent()->GetChild(browser_index - 1); 425 bnode->parent()->GetChild(browser_index - 1);
426 csync::ReadNode gprev(trans); 426 syncer::ReadNode gprev(trans);
427 ASSERT_TRUE(InitSyncNodeFromChromeNode(bprev, &gprev)); 427 ASSERT_TRUE(InitSyncNodeFromChromeNode(bprev, &gprev));
428 EXPECT_EQ(gnode.GetPredecessorId(), gprev.GetId()); 428 EXPECT_EQ(gnode.GetPredecessorId(), gprev.GetId());
429 EXPECT_EQ(gnode.GetParentId(), gprev.GetParentId()); 429 EXPECT_EQ(gnode.GetParentId(), gprev.GetParentId());
430 } 430 }
431 if (browser_index == bnode->parent()->child_count() - 1) { 431 if (browser_index == bnode->parent()->child_count() - 1) {
432 EXPECT_EQ(gnode.GetSuccessorId(), 0); 432 EXPECT_EQ(gnode.GetSuccessorId(), 0);
433 } else { 433 } else {
434 const BookmarkNode* bnext = 434 const BookmarkNode* bnext =
435 bnode->parent()->GetChild(browser_index + 1); 435 bnode->parent()->GetChild(browser_index + 1);
436 csync::ReadNode gnext(trans); 436 syncer::ReadNode gnext(trans);
437 ASSERT_TRUE(InitSyncNodeFromChromeNode(bnext, &gnext)); 437 ASSERT_TRUE(InitSyncNodeFromChromeNode(bnext, &gnext));
438 EXPECT_EQ(gnode.GetSuccessorId(), gnext.GetId()); 438 EXPECT_EQ(gnode.GetSuccessorId(), gnext.GetId());
439 EXPECT_EQ(gnode.GetParentId(), gnext.GetParentId()); 439 EXPECT_EQ(gnode.GetParentId(), gnext.GetParentId());
440 } 440 }
441 if (!bnode->empty()) 441 if (!bnode->empty())
442 EXPECT_TRUE(gnode.GetFirstChildId()); 442 EXPECT_TRUE(gnode.GetFirstChildId());
443 } 443 }
444 444
445 void ExpectSyncerNodeMatching(const BookmarkNode* bnode) { 445 void ExpectSyncerNodeMatching(const BookmarkNode* bnode) {
446 csync::ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); 446 syncer::ReadTransaction trans(FROM_HERE, test_user_share_.user_share());
447 ExpectSyncerNodeMatching(&trans, bnode); 447 ExpectSyncerNodeMatching(&trans, bnode);
448 } 448 }
449 449
450 void ExpectBrowserNodeMatching(csync::BaseTransaction* trans, 450 void ExpectBrowserNodeMatching(syncer::BaseTransaction* trans,
451 int64 sync_id) { 451 int64 sync_id) {
452 EXPECT_TRUE(sync_id); 452 EXPECT_TRUE(sync_id);
453 const BookmarkNode* bnode = 453 const BookmarkNode* bnode =
454 model_associator_->GetChromeNodeFromSyncId(sync_id); 454 model_associator_->GetChromeNodeFromSyncId(sync_id);
455 ASSERT_TRUE(bnode); 455 ASSERT_TRUE(bnode);
456 int64 id = model_associator_->GetSyncIdFromChromeId(bnode->id()); 456 int64 id = model_associator_->GetSyncIdFromChromeId(bnode->id());
457 EXPECT_EQ(id, sync_id); 457 EXPECT_EQ(id, sync_id);
458 ExpectSyncerNodeMatching(trans, bnode); 458 ExpectSyncerNodeMatching(trans, bnode);
459 } 459 }
460 460
461 void ExpectBrowserNodeUnknown(int64 sync_id) { 461 void ExpectBrowserNodeUnknown(int64 sync_id) {
462 EXPECT_FALSE(model_associator_->GetChromeNodeFromSyncId(sync_id)); 462 EXPECT_FALSE(model_associator_->GetChromeNodeFromSyncId(sync_id));
463 } 463 }
464 464
465 void ExpectBrowserNodeKnown(int64 sync_id) { 465 void ExpectBrowserNodeKnown(int64 sync_id) {
466 EXPECT_TRUE(model_associator_->GetChromeNodeFromSyncId(sync_id)); 466 EXPECT_TRUE(model_associator_->GetChromeNodeFromSyncId(sync_id));
467 } 467 }
468 468
469 void ExpectSyncerNodeKnown(const BookmarkNode* node) { 469 void ExpectSyncerNodeKnown(const BookmarkNode* node) {
470 int64 sync_id = model_associator_->GetSyncIdFromChromeId(node->id()); 470 int64 sync_id = model_associator_->GetSyncIdFromChromeId(node->id());
471 EXPECT_NE(sync_id, csync::kInvalidId); 471 EXPECT_NE(sync_id, syncer::kInvalidId);
472 } 472 }
473 473
474 void ExpectSyncerNodeUnknown(const BookmarkNode* node) { 474 void ExpectSyncerNodeUnknown(const BookmarkNode* node) {
475 int64 sync_id = model_associator_->GetSyncIdFromChromeId(node->id()); 475 int64 sync_id = model_associator_->GetSyncIdFromChromeId(node->id());
476 EXPECT_EQ(sync_id, csync::kInvalidId); 476 EXPECT_EQ(sync_id, syncer::kInvalidId);
477 } 477 }
478 478
479 void ExpectBrowserNodeTitle(int64 sync_id, const std::wstring& title) { 479 void ExpectBrowserNodeTitle(int64 sync_id, const std::wstring& title) {
480 const BookmarkNode* bnode = 480 const BookmarkNode* bnode =
481 model_associator_->GetChromeNodeFromSyncId(sync_id); 481 model_associator_->GetChromeNodeFromSyncId(sync_id);
482 ASSERT_TRUE(bnode); 482 ASSERT_TRUE(bnode);
483 EXPECT_EQ(bnode->GetTitle(), WideToUTF16Hack(title)); 483 EXPECT_EQ(bnode->GetTitle(), WideToUTF16Hack(title));
484 } 484 }
485 485
486 void ExpectBrowserNodeURL(int64 sync_id, const std::string& url) { 486 void ExpectBrowserNodeURL(int64 sync_id, const std::string& url) {
487 const BookmarkNode* bnode = 487 const BookmarkNode* bnode =
488 model_associator_->GetChromeNodeFromSyncId(sync_id); 488 model_associator_->GetChromeNodeFromSyncId(sync_id);
489 ASSERT_TRUE(bnode); 489 ASSERT_TRUE(bnode);
490 EXPECT_EQ(GURL(url), bnode->url()); 490 EXPECT_EQ(GURL(url), bnode->url());
491 } 491 }
492 492
493 void ExpectBrowserNodeParent(int64 sync_id, int64 parent_sync_id) { 493 void ExpectBrowserNodeParent(int64 sync_id, int64 parent_sync_id) {
494 const BookmarkNode* node = 494 const BookmarkNode* node =
495 model_associator_->GetChromeNodeFromSyncId(sync_id); 495 model_associator_->GetChromeNodeFromSyncId(sync_id);
496 ASSERT_TRUE(node); 496 ASSERT_TRUE(node);
497 const BookmarkNode* parent = 497 const BookmarkNode* parent =
498 model_associator_->GetChromeNodeFromSyncId(parent_sync_id); 498 model_associator_->GetChromeNodeFromSyncId(parent_sync_id);
499 EXPECT_TRUE(parent); 499 EXPECT_TRUE(parent);
500 EXPECT_EQ(node->parent(), parent); 500 EXPECT_EQ(node->parent(), parent);
501 } 501 }
502 502
503 void ExpectModelMatch(csync::BaseTransaction* trans) { 503 void ExpectModelMatch(syncer::BaseTransaction* trans) {
504 const BookmarkNode* root = model_->root_node(); 504 const BookmarkNode* root = model_->root_node();
505 EXPECT_EQ(root->GetIndexOf(model_->bookmark_bar_node()), 0); 505 EXPECT_EQ(root->GetIndexOf(model_->bookmark_bar_node()), 0);
506 EXPECT_EQ(root->GetIndexOf(model_->other_node()), 1); 506 EXPECT_EQ(root->GetIndexOf(model_->other_node()), 1);
507 EXPECT_EQ(root->GetIndexOf(model_->mobile_node()), 2); 507 EXPECT_EQ(root->GetIndexOf(model_->mobile_node()), 2);
508 508
509 std::stack<int64> stack; 509 std::stack<int64> stack;
510 stack.push(bookmark_bar_id()); 510 stack.push(bookmark_bar_id());
511 while (!stack.empty()) { 511 while (!stack.empty()) {
512 int64 id = stack.top(); 512 int64 id = stack.top();
513 stack.pop(); 513 stack.pop();
514 if (!id) continue; 514 if (!id) continue;
515 515
516 ExpectBrowserNodeMatching(trans, id); 516 ExpectBrowserNodeMatching(trans, id);
517 517
518 csync::ReadNode gnode(trans); 518 syncer::ReadNode gnode(trans);
519 ASSERT_EQ(BaseNode::INIT_OK, gnode.InitByIdLookup(id)); 519 ASSERT_EQ(BaseNode::INIT_OK, gnode.InitByIdLookup(id));
520 stack.push(gnode.GetFirstChildId()); 520 stack.push(gnode.GetFirstChildId());
521 stack.push(gnode.GetSuccessorId()); 521 stack.push(gnode.GetSuccessorId());
522 } 522 }
523 } 523 }
524 524
525 void ExpectModelMatch() { 525 void ExpectModelMatch() {
526 csync::ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); 526 syncer::ReadTransaction trans(FROM_HERE, test_user_share_.user_share());
527 ExpectModelMatch(&trans); 527 ExpectModelMatch(&trans);
528 } 528 }
529 529
530 int64 mobile_bookmarks_id() { 530 int64 mobile_bookmarks_id() {
531 return 531 return
532 model_associator_->GetSyncIdFromChromeId(model_->mobile_node()->id()); 532 model_associator_->GetSyncIdFromChromeId(model_->mobile_node()->id());
533 } 533 }
534 534
535 int64 other_bookmarks_id() { 535 int64 other_bookmarks_id() {
536 return 536 return
(...skipping 10 matching lines...) Expand all
547 MessageLoop message_loop_; 547 MessageLoop message_loop_;
548 content::TestBrowserThread ui_thread_; 548 content::TestBrowserThread ui_thread_;
549 // Needed by |model_|. 549 // Needed by |model_|.
550 content::TestBrowserThread file_thread_; 550 content::TestBrowserThread file_thread_;
551 551
552 TestingProfile profile_; 552 TestingProfile profile_;
553 scoped_ptr<TestBookmarkModelAssociator> model_associator_; 553 scoped_ptr<TestBookmarkModelAssociator> model_associator_;
554 554
555 protected: 555 protected:
556 BookmarkModel* model_; 556 BookmarkModel* model_;
557 csync::TestUserShare test_user_share_; 557 syncer::TestUserShare test_user_share_;
558 scoped_ptr<BookmarkChangeProcessor> change_processor_; 558 scoped_ptr<BookmarkChangeProcessor> change_processor_;
559 StrictMock<DataTypeErrorHandlerMock> mock_error_handler_; 559 StrictMock<DataTypeErrorHandlerMock> mock_error_handler_;
560 }; 560 };
561 561
562 TEST_F(ProfileSyncServiceBookmarkTest, InitialState) { 562 TEST_F(ProfileSyncServiceBookmarkTest, InitialState) {
563 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); 563 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE);
564 StartSync(); 564 StartSync();
565 565
566 EXPECT_TRUE(other_bookmarks_id()); 566 EXPECT_TRUE(other_bookmarks_id());
567 EXPECT_TRUE(bookmark_bar_id()); 567 EXPECT_TRUE(bookmark_bar_id());
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 folder2->parent()->GetIndexOf(folder2)); 625 folder2->parent()->GetIndexOf(folder2));
626 ExpectModelMatch(); 626 ExpectModelMatch();
627 model_->Remove(model_->mobile_node(), 0); 627 model_->Remove(model_->mobile_node(), 0);
628 ExpectModelMatch(); 628 ExpectModelMatch();
629 } 629 }
630 630
631 TEST_F(ProfileSyncServiceBookmarkTest, ServerChangeProcessing) { 631 TEST_F(ProfileSyncServiceBookmarkTest, ServerChangeProcessing) {
632 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); 632 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE);
633 StartSync(); 633 StartSync();
634 634
635 csync::WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); 635 syncer::WriteTransaction trans(FROM_HERE, test_user_share_.user_share());
636 636
637 FakeServerChange adds(&trans); 637 FakeServerChange adds(&trans);
638 int64 f1 = adds.AddFolder(L"Server Folder B", bookmark_bar_id(), 0); 638 int64 f1 = adds.AddFolder(L"Server Folder B", bookmark_bar_id(), 0);
639 int64 f2 = adds.AddFolder(L"Server Folder A", bookmark_bar_id(), f1); 639 int64 f2 = adds.AddFolder(L"Server Folder A", bookmark_bar_id(), f1);
640 int64 u1 = adds.AddURL(L"Some old site", "ftp://nifty.andrew.cmu.edu/", 640 int64 u1 = adds.AddURL(L"Some old site", "ftp://nifty.andrew.cmu.edu/",
641 bookmark_bar_id(), f2); 641 bookmark_bar_id(), f2);
642 int64 u2 = adds.AddURL(L"Nifty", "ftp://nifty.andrew.cmu.edu/", f1, 0); 642 int64 u2 = adds.AddURL(L"Nifty", "ftp://nifty.andrew.cmu.edu/", f1, 0);
643 // u3 is a duplicate URL 643 // u3 is a duplicate URL
644 int64 u3 = adds.AddURL(L"Nifty2", "ftp://nifty.andrew.cmu.edu/", f1, u2); 644 int64 u3 = adds.AddURL(L"Nifty2", "ftp://nifty.andrew.cmu.edu/", f1, u2);
645 // u4 is a duplicate title, different URL. 645 // u4 is a duplicate title, different URL.
646 adds.AddURL(L"Some old site", "http://slog.thestranger.com/", 646 adds.AddURL(L"Some old site", "http://slog.thestranger.com/",
647 bookmark_bar_id(), u1); 647 bookmark_bar_id(), u1);
648 // u5 tests an empty-string title. 648 // u5 tests an empty-string title.
649 std::string javascript_url( 649 std::string javascript_url(
650 "javascript:(function(){var w=window.open(" \ 650 "javascript:(function(){var w=window.open(" \
651 "'about:blank','gnotesWin','location=0,menubar=0," \ 651 "'about:blank','gnotesWin','location=0,menubar=0," \
652 "scrollbars=0,status=0,toolbar=0,width=300," \ 652 "scrollbars=0,status=0,toolbar=0,width=300," \
653 "height=300,resizable');});"); 653 "height=300,resizable');});");
654 adds.AddURL(L"", javascript_url, other_bookmarks_id(), 0); 654 adds.AddURL(L"", javascript_url, other_bookmarks_id(), 0);
655 int64 u6 = adds.AddURL(L"Sync1", "http://www.syncable.edu/", 655 int64 u6 = adds.AddURL(L"Sync1", "http://www.syncable.edu/",
656 mobile_bookmarks_id(), 0); 656 mobile_bookmarks_id(), 0);
657 657
658 csync::ChangeRecordList::const_iterator it; 658 syncer::ChangeRecordList::const_iterator it;
659 // The bookmark model shouldn't yet have seen any of the nodes of |adds|. 659 // The bookmark model shouldn't yet have seen any of the nodes of |adds|.
660 for (it = adds.changes().begin(); it != adds.changes().end(); ++it) 660 for (it = adds.changes().begin(); it != adds.changes().end(); ++it)
661 ExpectBrowserNodeUnknown(it->id); 661 ExpectBrowserNodeUnknown(it->id);
662 662
663 adds.ApplyPendingChanges(change_processor_.get()); 663 adds.ApplyPendingChanges(change_processor_.get());
664 664
665 // Make sure the bookmark model received all of the nodes in |adds|. 665 // Make sure the bookmark model received all of the nodes in |adds|.
666 for (it = adds.changes().begin(); it != adds.changes().end(); ++it) 666 for (it = adds.changes().begin(); it != adds.changes().end(); ++it)
667 ExpectBrowserNodeMatching(&trans, it->id); 667 ExpectBrowserNodeMatching(&trans, it->id);
668 ExpectModelMatch(&trans); 668 ExpectModelMatch(&trans);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
722 } 722 }
723 723
724 // Tests a specific case in ApplyModelChanges where we move the 724 // Tests a specific case in ApplyModelChanges where we move the
725 // children out from under a parent, and then delete the parent 725 // children out from under a parent, and then delete the parent
726 // in the same changelist. The delete shows up first in the changelist, 726 // in the same changelist. The delete shows up first in the changelist,
727 // requiring the children to be moved to a temporary location. 727 // requiring the children to be moved to a temporary location.
728 TEST_F(ProfileSyncServiceBookmarkTest, ServerChangeRequiringFosterParent) { 728 TEST_F(ProfileSyncServiceBookmarkTest, ServerChangeRequiringFosterParent) {
729 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); 729 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE);
730 StartSync(); 730 StartSync();
731 731
732 csync::WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); 732 syncer::WriteTransaction trans(FROM_HERE, test_user_share_.user_share());
733 733
734 // Stress the immediate children of other_node because that's where 734 // Stress the immediate children of other_node because that's where
735 // ApplyModelChanges puts a temporary foster parent node. 735 // ApplyModelChanges puts a temporary foster parent node.
736 std::string url("http://dev.chromium.org/"); 736 std::string url("http://dev.chromium.org/");
737 FakeServerChange adds(&trans); 737 FakeServerChange adds(&trans);
738 int64 f0 = other_bookmarks_id(); // + other_node 738 int64 f0 = other_bookmarks_id(); // + other_node
739 int64 f1 = adds.AddFolder(L"f1", f0, 0); // + f1 739 int64 f1 = adds.AddFolder(L"f1", f0, 0); // + f1
740 int64 f2 = adds.AddFolder(L"f2", f1, 0); // + f2 740 int64 f2 = adds.AddFolder(L"f2", f1, 0); // + f2
741 int64 u3 = adds.AddURL( L"u3", url, f2, 0); // + u3 NOLINT 741 int64 u3 = adds.AddURL( L"u3", url, f2, 0); // + u3 NOLINT
742 int64 u4 = adds.AddURL( L"u4", url, f2, u3); // + u4 NOLINT 742 int64 u4 = adds.AddURL( L"u4", url, f2, u3); // + u4 NOLINT
743 int64 u5 = adds.AddURL( L"u5", url, f1, f2); // + u5 NOLINT 743 int64 u5 = adds.AddURL( L"u5", url, f1, f2); // + u5 NOLINT
744 int64 f6 = adds.AddFolder(L"f6", f1, u5); // + f6 744 int64 f6 = adds.AddFolder(L"f6", f1, u5); // + f6
745 int64 u7 = adds.AddURL( L"u7", url, f0, f1); // + u7 NOLINT 745 int64 u7 = adds.AddURL( L"u7", url, f0, f1); // + u7 NOLINT
746 746
747 csync::ChangeRecordList::const_iterator it; 747 syncer::ChangeRecordList::const_iterator it;
748 // The bookmark model shouldn't yet have seen any of the nodes of |adds|. 748 // The bookmark model shouldn't yet have seen any of the nodes of |adds|.
749 for (it = adds.changes().begin(); it != adds.changes().end(); ++it) 749 for (it = adds.changes().begin(); it != adds.changes().end(); ++it)
750 ExpectBrowserNodeUnknown(it->id); 750 ExpectBrowserNodeUnknown(it->id);
751 751
752 adds.ApplyPendingChanges(change_processor_.get()); 752 adds.ApplyPendingChanges(change_processor_.get());
753 753
754 // Make sure the bookmark model received all of the nodes in |adds|. 754 // Make sure the bookmark model received all of the nodes in |adds|.
755 for (it = adds.changes().begin(); it != adds.changes().end(); ++it) 755 for (it = adds.changes().begin(); it != adds.changes().end(); ++it)
756 ExpectBrowserNodeMatching(&trans, it->id); 756 ExpectBrowserNodeMatching(&trans, it->id);
757 ExpectModelMatch(&trans); 757 ExpectModelMatch(&trans);
(...skipping 13 matching lines...) Expand all
771 771
772 ExpectModelMatch(&trans); 772 ExpectModelMatch(&trans);
773 } 773 }
774 774
775 // Simulate a server change record containing a valid but non-canonical URL. 775 // Simulate a server change record containing a valid but non-canonical URL.
776 TEST_F(ProfileSyncServiceBookmarkTest, ServerChangeWithNonCanonicalURL) { 776 TEST_F(ProfileSyncServiceBookmarkTest, ServerChangeWithNonCanonicalURL) {
777 LoadBookmarkModel(DELETE_EXISTING_STORAGE, SAVE_TO_STORAGE); 777 LoadBookmarkModel(DELETE_EXISTING_STORAGE, SAVE_TO_STORAGE);
778 StartSync(); 778 StartSync();
779 779
780 { 780 {
781 csync::WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); 781 syncer::WriteTransaction trans(FROM_HERE, test_user_share_.user_share());
782 782
783 FakeServerChange adds(&trans); 783 FakeServerChange adds(&trans);
784 std::string url("http://dev.chromium.org"); 784 std::string url("http://dev.chromium.org");
785 EXPECT_NE(GURL(url).spec(), url); 785 EXPECT_NE(GURL(url).spec(), url);
786 adds.AddURL(L"u1", url, other_bookmarks_id(), 0); 786 adds.AddURL(L"u1", url, other_bookmarks_id(), 0);
787 787
788 adds.ApplyPendingChanges(change_processor_.get()); 788 adds.ApplyPendingChanges(change_processor_.get());
789 789
790 EXPECT_TRUE(model_->other_node()->child_count() == 1); 790 EXPECT_TRUE(model_->other_node()->child_count() == 1);
791 ExpectModelMatch(&trans); 791 ExpectModelMatch(&trans);
(...skipping 10 matching lines...) Expand all
802 } 802 }
803 803
804 // Simulate a server change record containing an invalid URL (per GURL). 804 // Simulate a server change record containing an invalid URL (per GURL).
805 // TODO(ncarter): Disabled due to crashes. Fix bug 1677563. 805 // TODO(ncarter): Disabled due to crashes. Fix bug 1677563.
806 TEST_F(ProfileSyncServiceBookmarkTest, DISABLED_ServerChangeWithInvalidURL) { 806 TEST_F(ProfileSyncServiceBookmarkTest, DISABLED_ServerChangeWithInvalidURL) {
807 LoadBookmarkModel(DELETE_EXISTING_STORAGE, SAVE_TO_STORAGE); 807 LoadBookmarkModel(DELETE_EXISTING_STORAGE, SAVE_TO_STORAGE);
808 StartSync(); 808 StartSync();
809 809
810 int child_count = 0; 810 int child_count = 0;
811 { 811 {
812 csync::WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); 812 syncer::WriteTransaction trans(FROM_HERE, test_user_share_.user_share());
813 813
814 FakeServerChange adds(&trans); 814 FakeServerChange adds(&trans);
815 std::string url("x"); 815 std::string url("x");
816 EXPECT_FALSE(GURL(url).is_valid()); 816 EXPECT_FALSE(GURL(url).is_valid());
817 adds.AddURL(L"u1", url, other_bookmarks_id(), 0); 817 adds.AddURL(L"u1", url, other_bookmarks_id(), 0);
818 818
819 adds.ApplyPendingChanges(change_processor_.get()); 819 adds.ApplyPendingChanges(change_processor_.get());
820 820
821 // We're lenient about what should happen -- the model could wind up with 821 // We're lenient about what should happen -- the model could wind up with
822 // the node or without it; but things should be consistent, and we 822 // the node or without it; but things should be consistent, and we
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
919 919
920 // Add a node which will be the target of the consistency violation. 920 // Add a node which will be the target of the consistency violation.
921 const BookmarkNode* node = 921 const BookmarkNode* node =
922 model_->AddFolder(model_->other_node(), 0, ASCIIToUTF16("node")); 922 model_->AddFolder(model_->other_node(), 0, ASCIIToUTF16("node"));
923 ExpectSyncerNodeMatching(node); 923 ExpectSyncerNodeMatching(node);
924 924
925 // Now destroy the syncer node as if we were the ProfileSyncService without 925 // Now destroy the syncer node as if we were the ProfileSyncService without
926 // updating the ProfileSyncService state. This should introduce 926 // updating the ProfileSyncService state. This should introduce
927 // inconsistency between the two models. 927 // inconsistency between the two models.
928 { 928 {
929 csync::WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); 929 syncer::WriteTransaction trans(FROM_HERE, test_user_share_.user_share());
930 csync::WriteNode sync_node(&trans); 930 syncer::WriteNode sync_node(&trans);
931 ASSERT_TRUE(InitSyncNodeFromChromeNode(node, &sync_node)); 931 ASSERT_TRUE(InitSyncNodeFromChromeNode(node, &sync_node));
932 sync_node.Remove(); 932 sync_node.Remove();
933 } 933 }
934 // The models don't match at this point, but the ProfileSyncService 934 // The models don't match at this point, but the ProfileSyncService
935 // doesn't know it yet. 935 // doesn't know it yet.
936 ExpectSyncerNodeKnown(node); 936 ExpectSyncerNodeKnown(node);
937 937
938 // Add a child to the inconsistent node. This should cause detection of the 938 // Add a child to the inconsistent node. This should cause detection of the
939 // problem and the syncer should stop processing changes. 939 // problem and the syncer should stop processing changes.
940 model_->AddFolder(node, 0, ASCIIToUTF16("nested")); 940 model_->AddFolder(node, 0, ASCIIToUTF16("nested"));
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after
1490 EXPECT_EQ(1, observer.get_started()); 1490 EXPECT_EQ(1, observer.get_started());
1491 EXPECT_EQ(0, observer.get_completed_count_at_started()); 1491 EXPECT_EQ(0, observer.get_completed_count_at_started());
1492 EXPECT_EQ(1, observer.get_completed()); 1492 EXPECT_EQ(1, observer.get_completed());
1493 1493
1494 model_->RemoveObserver(&observer); 1494 model_->RemoveObserver(&observer);
1495 } 1495 }
1496 1496
1497 } // namespace 1497 } // namespace
1498 1498
1499 } // namespace browser_sync 1499 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/profile_sync_service_autofill_unittest.cc ('k') | chrome/browser/sync/profile_sync_service_harness.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698