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

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

Issue 1545223002: Switch to standard integer types in chrome/browser/, part 4 of 4. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix Created 4 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
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 <stddef.h>
10 #include <stdint.h>
11
9 #include <map> 12 #include <map>
10 #include <queue> 13 #include <queue>
11 #include <stack> 14 #include <stack>
12 #include <vector> 15 #include <vector>
13 16
14 #include "base/command_line.h" 17 #include "base/command_line.h"
15 #include "base/files/file_path.h" 18 #include "base/files/file_path.h"
16 #include "base/location.h" 19 #include "base/location.h"
20 #include "base/macros.h"
17 #include "base/memory/scoped_ptr.h" 21 #include "base/memory/scoped_ptr.h"
18 #include "base/strings/string16.h" 22 #include "base/strings/string16.h"
19 #include "base/strings/string_number_conversions.h" 23 #include "base/strings/string_number_conversions.h"
20 #include "base/strings/string_util.h" 24 #include "base/strings/string_util.h"
21 #include "base/strings/stringprintf.h" 25 #include "base/strings/stringprintf.h"
22 #include "base/strings/utf_string_conversions.h" 26 #include "base/strings/utf_string_conversions.h"
23 #include "base/time/time.h" 27 #include "base/time/time.h"
28 #include "build/build_config.h"
24 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 29 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
25 #include "chrome/browser/bookmarks/chrome_bookmark_client.h" 30 #include "chrome/browser/bookmarks/chrome_bookmark_client.h"
26 #include "chrome/browser/bookmarks/chrome_bookmark_client_factory.h" 31 #include "chrome/browser/bookmarks/chrome_bookmark_client_factory.h"
27 #include "chrome/browser/bookmarks/managed_bookmark_service_factory.h" 32 #include "chrome/browser/bookmarks/managed_bookmark_service_factory.h"
28 #include "chrome/browser/favicon/favicon_service_factory.h" 33 #include "chrome/browser/favicon/favicon_service_factory.h"
29 #include "chrome/browser/history/history_service_factory.h" 34 #include "chrome/browser/history/history_service_factory.h"
30 #include "chrome/common/chrome_switches.h" 35 #include "chrome/common/chrome_switches.h"
31 #include "chrome/test/base/testing_profile.h" 36 #include "chrome/test/base/testing_profile.h"
32 #include "components/bookmarks/browser/base_bookmark_model_observer.h" 37 #include "components/bookmarks/browser/base_bookmark_model_observer.h"
33 #include "components/bookmarks/browser/bookmark_model.h" 38 #include "components/bookmarks/browser/bookmark_model.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 void MakeServerUpdate(syncer::WriteTransaction* trans, 82 void MakeServerUpdate(syncer::WriteTransaction* trans,
78 syncer::WriteNode* node) { 83 syncer::WriteNode* node) {
79 syncer::syncable::ChangeEntryIDAndUpdateChildren( 84 syncer::syncable::ChangeEntryIDAndUpdateChildren(
80 trans->GetWrappedWriteTrans(), node->GetMutableEntryForTest(), 85 trans->GetWrappedWriteTrans(), node->GetMutableEntryForTest(),
81 syncer::syncable::Id::CreateFromServerId( 86 syncer::syncable::Id::CreateFromServerId(
82 base::Int64ToString(node->GetId()))); 87 base::Int64ToString(node->GetId())));
83 node->GetMutableEntryForTest()->PutBaseVersion(10); 88 node->GetMutableEntryForTest()->PutBaseVersion(10);
84 node->GetMutableEntryForTest()->PutIsUnappliedUpdate(true); 89 node->GetMutableEntryForTest()->PutIsUnappliedUpdate(true);
85 } 90 }
86 91
87 void MakeServerUpdate(syncer::WriteTransaction* trans, int64 id) { 92 void MakeServerUpdate(syncer::WriteTransaction* trans, int64_t id) {
88 syncer::WriteNode node(trans); 93 syncer::WriteNode node(trans);
89 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(id)); 94 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(id));
90 MakeServerUpdate(trans, &node); 95 MakeServerUpdate(trans, &node);
91 } 96 }
92 97
93 class TestSyncClient : public sync_driver::FakeSyncClient { 98 class TestSyncClient : public sync_driver::FakeSyncClient {
94 public: 99 public:
95 explicit TestSyncClient(Profile* profile) : profile_(profile) {} 100 explicit TestSyncClient(Profile* profile) : profile_(profile) {}
96 101
97 bookmarks::BookmarkModel* GetBookmarkModel() override { 102 bookmarks::BookmarkModel* GetBookmarkModel() override {
(...skipping 19 matching lines...) Expand all
117 // syncer::SyncObserver (i.e., the ProfileSyncService) to test the client 122 // syncer::SyncObserver (i.e., the ProfileSyncService) to test the client
118 // change-application behavior. 123 // change-application behavior.
119 // Tests using FakeServerChange should be careful to avoid back-references, 124 // Tests using FakeServerChange should be careful to avoid back-references,
120 // since FakeServerChange will send the edits in the order specified. 125 // since FakeServerChange will send the edits in the order specified.
121 class FakeServerChange { 126 class FakeServerChange {
122 public: 127 public:
123 explicit FakeServerChange(syncer::WriteTransaction* trans) : trans_(trans) { 128 explicit FakeServerChange(syncer::WriteTransaction* trans) : trans_(trans) {
124 } 129 }
125 130
126 // Pretend that the server told the syncer to add a bookmark object. 131 // Pretend that the server told the syncer to add a bookmark object.
127 int64 AddWithMetaInfo(const std::string& title, 132 int64_t AddWithMetaInfo(const std::string& title,
128 const std::string& url, 133 const std::string& url,
129 const BookmarkNode::MetaInfoMap* meta_info_map, 134 const BookmarkNode::MetaInfoMap* meta_info_map,
130 bool is_folder, 135 bool is_folder,
131 int64 parent_id, 136 int64_t parent_id,
132 int64 predecessor_id) { 137 int64_t predecessor_id) {
133 syncer::ReadNode parent(trans_); 138 syncer::ReadNode parent(trans_);
134 EXPECT_EQ(BaseNode::INIT_OK, parent.InitByIdLookup(parent_id)); 139 EXPECT_EQ(BaseNode::INIT_OK, parent.InitByIdLookup(parent_id));
135 syncer::WriteNode node(trans_); 140 syncer::WriteNode node(trans_);
136 if (predecessor_id == 0) { 141 if (predecessor_id == 0) {
137 EXPECT_TRUE(node.InitBookmarkByCreation(parent, NULL)); 142 EXPECT_TRUE(node.InitBookmarkByCreation(parent, NULL));
138 } else { 143 } else {
139 syncer::ReadNode predecessor(trans_); 144 syncer::ReadNode predecessor(trans_);
140 EXPECT_EQ(BaseNode::INIT_OK, predecessor.InitByIdLookup(predecessor_id)); 145 EXPECT_EQ(BaseNode::INIT_OK, predecessor.InitByIdLookup(predecessor_id));
141 EXPECT_EQ(predecessor.GetParentId(), parent.GetId()); 146 EXPECT_EQ(predecessor.GetParentId(), parent.GetId());
142 EXPECT_TRUE(node.InitBookmarkByCreation(parent, &predecessor)); 147 EXPECT_TRUE(node.InitBookmarkByCreation(parent, &predecessor));
(...skipping 12 matching lines...) Expand all
155 SetNodeMetaInfo(*meta_info_map, &specifics); 160 SetNodeMetaInfo(*meta_info_map, &specifics);
156 node.SetBookmarkSpecifics(specifics); 161 node.SetBookmarkSpecifics(specifics);
157 162
158 syncer::ChangeRecord record; 163 syncer::ChangeRecord record;
159 record.action = syncer::ChangeRecord::ACTION_ADD; 164 record.action = syncer::ChangeRecord::ACTION_ADD;
160 record.id = node.GetId(); 165 record.id = node.GetId();
161 changes_.push_back(record); 166 changes_.push_back(record);
162 return node.GetId(); 167 return node.GetId();
163 } 168 }
164 169
165 int64 Add(const std::string& title, 170 int64_t Add(const std::string& title,
166 const std::string& url, 171 const std::string& url,
167 bool is_folder, 172 bool is_folder,
168 int64 parent_id, 173 int64_t parent_id,
169 int64 predecessor_id) { 174 int64_t predecessor_id) {
170 return AddWithMetaInfo(title, url, NULL, is_folder, parent_id, 175 return AddWithMetaInfo(title, url, NULL, is_folder, parent_id,
171 predecessor_id); 176 predecessor_id);
172 } 177 }
173 178
174 // Add a bookmark folder. 179 // Add a bookmark folder.
175 int64 AddFolder(const std::string& title, 180 int64_t AddFolder(const std::string& title,
176 int64 parent_id, 181 int64_t parent_id,
177 int64 predecessor_id) { 182 int64_t predecessor_id) {
178 return Add(title, std::string(), true, parent_id, predecessor_id); 183 return Add(title, std::string(), true, parent_id, predecessor_id);
179 } 184 }
180 int64 AddFolderWithMetaInfo(const std::string& title, 185 int64_t AddFolderWithMetaInfo(const std::string& title,
181 const BookmarkNode::MetaInfoMap* meta_info_map, 186 const BookmarkNode::MetaInfoMap* meta_info_map,
182 int64 parent_id, 187 int64_t parent_id,
183 int64 predecessor_id) { 188 int64_t predecessor_id) {
184 return AddWithMetaInfo(title, std::string(), meta_info_map, true, parent_id, 189 return AddWithMetaInfo(title, std::string(), meta_info_map, true, parent_id,
185 predecessor_id); 190 predecessor_id);
186 } 191 }
187 192
188 // Add a bookmark. 193 // Add a bookmark.
189 int64 AddURL(const std::string& title, 194 int64_t AddURL(const std::string& title,
190 const std::string& url, 195 const std::string& url,
191 int64 parent_id, 196 int64_t parent_id,
192 int64 predecessor_id) { 197 int64_t predecessor_id) {
193 return Add(title, url, false, parent_id, predecessor_id); 198 return Add(title, url, false, parent_id, predecessor_id);
194 } 199 }
195 int64 AddURLWithMetaInfo(const std::string& title, 200 int64_t AddURLWithMetaInfo(const std::string& title,
196 const std::string& url, 201 const std::string& url,
197 const BookmarkNode::MetaInfoMap* meta_info_map, 202 const BookmarkNode::MetaInfoMap* meta_info_map,
198 int64 parent_id, 203 int64_t parent_id,
199 int64 predecessor_id) { 204 int64_t predecessor_id) {
200 return AddWithMetaInfo(title, url, meta_info_map, false, parent_id, 205 return AddWithMetaInfo(title, url, meta_info_map, false, parent_id,
201 predecessor_id); 206 predecessor_id);
202 } 207 }
203 208
204 // Pretend that the server told the syncer to delete an object. 209 // Pretend that the server told the syncer to delete an object.
205 void Delete(int64 id) { 210 void Delete(int64_t id) {
206 { 211 {
207 // Delete the sync node. 212 // Delete the sync node.
208 syncer::WriteNode node(trans_); 213 syncer::WriteNode node(trans_);
209 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(id)); 214 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(id));
210 if (node.GetIsFolder()) 215 if (node.GetIsFolder())
211 EXPECT_FALSE(node.GetFirstChildId()); 216 EXPECT_FALSE(node.GetFirstChildId());
212 node.GetMutableEntryForTest()->PutServerIsDel(true); 217 node.GetMutableEntryForTest()->PutServerIsDel(true);
213 node.Tombstone(); 218 node.Tombstone();
214 } 219 }
215 { 220 {
216 // Verify the deletion. 221 // Verify the deletion.
217 syncer::ReadNode node(trans_); 222 syncer::ReadNode node(trans_);
218 EXPECT_EQ(BaseNode::INIT_FAILED_ENTRY_IS_DEL, node.InitByIdLookup(id)); 223 EXPECT_EQ(BaseNode::INIT_FAILED_ENTRY_IS_DEL, node.InitByIdLookup(id));
219 } 224 }
220 225
221 syncer::ChangeRecord record; 226 syncer::ChangeRecord record;
222 record.action = syncer::ChangeRecord::ACTION_DELETE; 227 record.action = syncer::ChangeRecord::ACTION_DELETE;
223 record.id = id; 228 record.id = id;
224 // Deletions are always first in the changelist, but we can't actually do 229 // Deletions are always first in the changelist, but we can't actually do
225 // WriteNode::Remove() on the node until its children are moved. So, as 230 // WriteNode::Remove() on the node until its children are moved. So, as
226 // a practical matter, users of FakeServerChange must move or delete 231 // a practical matter, users of FakeServerChange must move or delete
227 // children before parents. Thus, we must insert the deletion record 232 // children before parents. Thus, we must insert the deletion record
228 // at the front of the vector. 233 // at the front of the vector.
229 changes_.insert(changes_.begin(), record); 234 changes_.insert(changes_.begin(), record);
230 } 235 }
231 236
232 // Set a new title value, and return the old value. 237 // Set a new title value, and return the old value.
233 std::string ModifyTitle(int64 id, const std::string& new_title) { 238 std::string ModifyTitle(int64_t id, const std::string& new_title) {
234 syncer::WriteNode node(trans_); 239 syncer::WriteNode node(trans_);
235 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(id)); 240 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(id));
236 std::string old_title = node.GetTitle(); 241 std::string old_title = node.GetTitle();
237 node.SetTitle(new_title); 242 node.SetTitle(new_title);
238 SetModified(id); 243 SetModified(id);
239 return old_title; 244 return old_title;
240 } 245 }
241 246
242 // Set a new parent and predecessor value. Return the old parent id. 247 // Set a new parent and predecessor value. Return the old parent id.
243 // We could return the old predecessor id, but it turns out not to be 248 // We could return the old predecessor id, but it turns out not to be
244 // very useful for assertions. 249 // very useful for assertions.
245 int64 ModifyPosition(int64 id, int64 parent_id, int64 predecessor_id) { 250 int64_t ModifyPosition(int64_t id,
251 int64_t parent_id,
252 int64_t predecessor_id) {
246 syncer::ReadNode parent(trans_); 253 syncer::ReadNode parent(trans_);
247 EXPECT_EQ(BaseNode::INIT_OK, parent.InitByIdLookup(parent_id)); 254 EXPECT_EQ(BaseNode::INIT_OK, parent.InitByIdLookup(parent_id));
248 syncer::WriteNode node(trans_); 255 syncer::WriteNode node(trans_);
249 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(id)); 256 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(id));
250 int64 old_parent_id = node.GetParentId(); 257 int64_t old_parent_id = node.GetParentId();
251 if (predecessor_id == 0) { 258 if (predecessor_id == 0) {
252 EXPECT_TRUE(node.SetPosition(parent, NULL)); 259 EXPECT_TRUE(node.SetPosition(parent, NULL));
253 } else { 260 } else {
254 syncer::ReadNode predecessor(trans_); 261 syncer::ReadNode predecessor(trans_);
255 EXPECT_EQ(BaseNode::INIT_OK, predecessor.InitByIdLookup(predecessor_id)); 262 EXPECT_EQ(BaseNode::INIT_OK, predecessor.InitByIdLookup(predecessor_id));
256 EXPECT_EQ(predecessor.GetParentId(), parent.GetId()); 263 EXPECT_EQ(predecessor.GetParentId(), parent.GetId());
257 EXPECT_TRUE(node.SetPosition(parent, &predecessor)); 264 EXPECT_TRUE(node.SetPosition(parent, &predecessor));
258 } 265 }
259 SetModified(id); 266 SetModified(id);
260 return old_parent_id; 267 return old_parent_id;
261 } 268 }
262 269
263 void ModifyCreationTime(int64 id, int64 creation_time_us) { 270 void ModifyCreationTime(int64_t id, int64_t creation_time_us) {
264 syncer::WriteNode node(trans_); 271 syncer::WriteNode node(trans_);
265 ASSERT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(id)); 272 ASSERT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(id));
266 sync_pb::BookmarkSpecifics specifics = node.GetBookmarkSpecifics(); 273 sync_pb::BookmarkSpecifics specifics = node.GetBookmarkSpecifics();
267 specifics.set_creation_time_us(creation_time_us); 274 specifics.set_creation_time_us(creation_time_us);
268 node.SetBookmarkSpecifics(specifics); 275 node.SetBookmarkSpecifics(specifics);
269 SetModified(id); 276 SetModified(id);
270 } 277 }
271 278
272 void ModifyMetaInfo(int64 id, 279 void ModifyMetaInfo(int64_t id,
273 const BookmarkNode::MetaInfoMap& meta_info_map) { 280 const BookmarkNode::MetaInfoMap& meta_info_map) {
274 syncer::WriteNode node(trans_); 281 syncer::WriteNode node(trans_);
275 ASSERT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(id)); 282 ASSERT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(id));
276 sync_pb::BookmarkSpecifics specifics = node.GetBookmarkSpecifics(); 283 sync_pb::BookmarkSpecifics specifics = node.GetBookmarkSpecifics();
277 SetNodeMetaInfo(meta_info_map, &specifics); 284 SetNodeMetaInfo(meta_info_map, &specifics);
278 node.SetBookmarkSpecifics(specifics); 285 node.SetBookmarkSpecifics(specifics);
279 SetModified(id); 286 SetModified(id);
280 } 287 }
281 288
282 // Pass the fake change list to |service|. 289 // Pass the fake change list to |service|.
283 void ApplyPendingChanges(sync_driver::ChangeProcessor* processor) { 290 void ApplyPendingChanges(sync_driver::ChangeProcessor* processor) {
284 processor->ApplyChangesFromSyncModel( 291 processor->ApplyChangesFromSyncModel(
285 trans_, 0, syncer::ImmutableChangeRecordList(&changes_)); 292 trans_, 0, syncer::ImmutableChangeRecordList(&changes_));
286 } 293 }
287 294
288 const syncer::ChangeRecordList& changes() { 295 const syncer::ChangeRecordList& changes() {
289 return changes_; 296 return changes_;
290 } 297 }
291 298
292 private: 299 private:
293 // Helper function to push an ACTION_UPDATE record onto the back 300 // Helper function to push an ACTION_UPDATE record onto the back
294 // of the changelist. 301 // of the changelist.
295 void SetModified(int64 id) { 302 void SetModified(int64_t id) {
296 // Coalesce multi-property edits. 303 // Coalesce multi-property edits.
297 if (!changes_.empty() && changes_.back().id == id && 304 if (!changes_.empty() && changes_.back().id == id &&
298 changes_.back().action == 305 changes_.back().action ==
299 syncer::ChangeRecord::ACTION_UPDATE) 306 syncer::ChangeRecord::ACTION_UPDATE)
300 return; 307 return;
301 syncer::ChangeRecord record; 308 syncer::ChangeRecord record;
302 record.action = syncer::ChangeRecord::ACTION_UPDATE; 309 record.action = syncer::ChangeRecord::ACTION_UPDATE;
303 record.id = id; 310 record.id = id;
304 changes_.push_back(record); 311 changes_.push_back(record);
305 } 312 }
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 } 404 }
398 405
399 // Inserts a folder directly to the share. 406 // Inserts a folder directly to the share.
400 // Do not use this after model association is complete. 407 // Do not use this after model association is complete.
401 // 408 //
402 // This function differs from the AddFolder() function declared elsewhere in 409 // This function differs from the AddFolder() function declared elsewhere in
403 // this file in that it only affects the sync model. It would be invalid to 410 // this file in that it only affects the sync model. It would be invalid to
404 // change the sync model directly after ModelAssociation. This function can 411 // change the sync model directly after ModelAssociation. This function can
405 // be invoked prior to model association to set up first-time sync model 412 // be invoked prior to model association to set up first-time sync model
406 // association scenarios. 413 // association scenarios.
407 int64 AddFolderToShare(syncer::WriteTransaction* trans, 414 int64_t AddFolderToShare(syncer::WriteTransaction* trans,
408 const std::string& title) { 415 const std::string& title) {
409 EXPECT_FALSE(model_associator_); 416 EXPECT_FALSE(model_associator_);
410 417
411 // Be sure to call CreatePermanentBookmarkNodes(), otherwise this will fail. 418 // Be sure to call CreatePermanentBookmarkNodes(), otherwise this will fail.
412 syncer::ReadNode bookmark_bar(trans); 419 syncer::ReadNode bookmark_bar(trans);
413 EXPECT_EQ(BaseNode::INIT_OK, 420 EXPECT_EQ(BaseNode::INIT_OK,
414 bookmark_bar.InitByTagLookupForBookmarks("bookmark_bar")); 421 bookmark_bar.InitByTagLookupForBookmarks("bookmark_bar"));
415 422
416 syncer::WriteNode node(trans); 423 syncer::WriteNode node(trans);
417 EXPECT_TRUE(node.InitBookmarkByCreation(bookmark_bar, NULL)); 424 EXPECT_TRUE(node.InitBookmarkByCreation(bookmark_bar, NULL));
418 node.SetIsFolder(true); 425 node.SetIsFolder(true);
419 node.SetTitle(title); 426 node.SetTitle(title);
420 427
421 return node.GetId(); 428 return node.GetId();
422 } 429 }
423 430
424 // Inserts a bookmark directly to the share. 431 // Inserts a bookmark directly to the share.
425 // Do not use this after model association is complete. 432 // Do not use this after model association is complete.
426 // 433 //
427 // This function differs from the AddURL() function declared elsewhere in this 434 // This function differs from the AddURL() function declared elsewhere in this
428 // file in that it only affects the sync model. It would be invalid to change 435 // file in that it only affects the sync model. It would be invalid to change
429 // the sync model directly after ModelAssociation. This function can be 436 // the sync model directly after ModelAssociation. This function can be
430 // invoked prior to model association to set up first-time sync model 437 // invoked prior to model association to set up first-time sync model
431 // association scenarios. 438 // association scenarios.
432 int64 AddBookmarkToShare(syncer::WriteTransaction* trans, 439 int64_t AddBookmarkToShare(syncer::WriteTransaction* trans,
433 int64 parent_id, 440 int64_t parent_id,
434 const std::string& title, 441 const std::string& title,
435 const std::string& url) { 442 const std::string& url) {
436 EXPECT_FALSE(model_associator_); 443 EXPECT_FALSE(model_associator_);
437 444
438 syncer::ReadNode parent(trans); 445 syncer::ReadNode parent(trans);
439 EXPECT_EQ(BaseNode::INIT_OK, parent.InitByIdLookup(parent_id)); 446 EXPECT_EQ(BaseNode::INIT_OK, parent.InitByIdLookup(parent_id));
440 447
441 sync_pb::BookmarkSpecifics specifics; 448 sync_pb::BookmarkSpecifics specifics;
442 specifics.set_url(url); 449 specifics.set_url(url);
443 specifics.set_title(title); 450 specifics.set_title(title);
444 451
445 syncer::WriteNode node(trans); 452 syncer::WriteNode node(trans);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 "other_bookmarks", 510 "other_bookmarks",
504 #if !defined(OS_IOS) && !defined(OS_ANDROID) 511 #if !defined(OS_IOS) && !defined(OS_ANDROID)
505 "synced_bookmarks", 512 "synced_bookmarks",
506 #endif // !defined(OS_IOS) && !defined(OS_ANDROID) 513 #endif // !defined(OS_IOS) && !defined(OS_ANDROID)
507 }; 514 };
508 syncer::WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); 515 syncer::WriteTransaction trans(FROM_HERE, test_user_share_.user_share());
509 syncer::ReadNode root(&trans); 516 syncer::ReadNode root(&trans);
510 EXPECT_EQ(BaseNode::INIT_OK, root.InitTypeRoot(type)); 517 EXPECT_EQ(BaseNode::INIT_OK, root.InitTypeRoot(type));
511 518
512 // Loop through creating permanent nodes as necessary. 519 // Loop through creating permanent nodes as necessary.
513 int64 last_child_id = syncer::kInvalidId; 520 int64_t last_child_id = syncer::kInvalidId;
514 for (int i = 0; i < kNumPermanentNodes; ++i) { 521 for (int i = 0; i < kNumPermanentNodes; ++i) {
515 // First check if the node already exists. This is for tests that involve 522 // First check if the node already exists. This is for tests that involve
516 // persistence and set up sync more than once. 523 // persistence and set up sync more than once.
517 syncer::ReadNode lookup(&trans); 524 syncer::ReadNode lookup(&trans);
518 if (lookup.InitByTagLookupForBookmarks(permanent_tags[i]) == 525 if (lookup.InitByTagLookupForBookmarks(permanent_tags[i]) ==
519 syncer::ReadNode::INIT_OK) { 526 syncer::ReadNode::INIT_OK) {
520 last_child_id = lookup.GetId(); 527 last_child_id = lookup.GetId();
521 continue; 528 continue;
522 } 529 }
523 530
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 if (!bnode->empty()) 694 if (!bnode->empty())
688 EXPECT_TRUE(gnode.GetFirstChildId()); 695 EXPECT_TRUE(gnode.GetFirstChildId());
689 } 696 }
690 697
691 void ExpectSyncerNodeMatching(const BookmarkNode* bnode) { 698 void ExpectSyncerNodeMatching(const BookmarkNode* bnode) {
692 syncer::ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); 699 syncer::ReadTransaction trans(FROM_HERE, test_user_share_.user_share());
693 ExpectSyncerNodeMatching(&trans, bnode); 700 ExpectSyncerNodeMatching(&trans, bnode);
694 } 701 }
695 702
696 void ExpectBrowserNodeMatching(syncer::BaseTransaction* trans, 703 void ExpectBrowserNodeMatching(syncer::BaseTransaction* trans,
697 int64 sync_id) { 704 int64_t sync_id) {
698 EXPECT_TRUE(sync_id); 705 EXPECT_TRUE(sync_id);
699 const BookmarkNode* bnode = 706 const BookmarkNode* bnode =
700 model_associator_->GetChromeNodeFromSyncId(sync_id); 707 model_associator_->GetChromeNodeFromSyncId(sync_id);
701 ASSERT_TRUE(bnode); 708 ASSERT_TRUE(bnode);
702 ASSERT_TRUE(CanSyncNode(bnode)); 709 ASSERT_TRUE(CanSyncNode(bnode));
703 710
704 int64 id = model_associator_->GetSyncIdFromChromeId(bnode->id()); 711 int64_t id = model_associator_->GetSyncIdFromChromeId(bnode->id());
705 EXPECT_EQ(id, sync_id); 712 EXPECT_EQ(id, sync_id);
706 ExpectSyncerNodeMatching(trans, bnode); 713 ExpectSyncerNodeMatching(trans, bnode);
707 } 714 }
708 715
709 void ExpectBrowserNodeUnknown(int64 sync_id) { 716 void ExpectBrowserNodeUnknown(int64_t sync_id) {
710 EXPECT_FALSE(model_associator_->GetChromeNodeFromSyncId(sync_id)); 717 EXPECT_FALSE(model_associator_->GetChromeNodeFromSyncId(sync_id));
711 } 718 }
712 719
713 void ExpectBrowserNodeKnown(int64 sync_id) { 720 void ExpectBrowserNodeKnown(int64_t sync_id) {
714 EXPECT_TRUE(model_associator_->GetChromeNodeFromSyncId(sync_id)); 721 EXPECT_TRUE(model_associator_->GetChromeNodeFromSyncId(sync_id));
715 } 722 }
716 723
717 void ExpectSyncerNodeKnown(const BookmarkNode* node) { 724 void ExpectSyncerNodeKnown(const BookmarkNode* node) {
718 int64 sync_id = model_associator_->GetSyncIdFromChromeId(node->id()); 725 int64_t sync_id = model_associator_->GetSyncIdFromChromeId(node->id());
719 EXPECT_NE(sync_id, syncer::kInvalidId); 726 EXPECT_NE(sync_id, syncer::kInvalidId);
720 } 727 }
721 728
722 void ExpectSyncerNodeUnknown(const BookmarkNode* node) { 729 void ExpectSyncerNodeUnknown(const BookmarkNode* node) {
723 int64 sync_id = model_associator_->GetSyncIdFromChromeId(node->id()); 730 int64_t sync_id = model_associator_->GetSyncIdFromChromeId(node->id());
724 EXPECT_EQ(sync_id, syncer::kInvalidId); 731 EXPECT_EQ(sync_id, syncer::kInvalidId);
725 } 732 }
726 733
727 void ExpectBrowserNodeTitle(int64 sync_id, const std::string& title) { 734 void ExpectBrowserNodeTitle(int64_t sync_id, const std::string& title) {
728 const BookmarkNode* bnode = 735 const BookmarkNode* bnode =
729 model_associator_->GetChromeNodeFromSyncId(sync_id); 736 model_associator_->GetChromeNodeFromSyncId(sync_id);
730 ASSERT_TRUE(bnode); 737 ASSERT_TRUE(bnode);
731 EXPECT_EQ(bnode->GetTitle(), base::UTF8ToUTF16(title)); 738 EXPECT_EQ(bnode->GetTitle(), base::UTF8ToUTF16(title));
732 } 739 }
733 740
734 void ExpectBrowserNodeURL(int64 sync_id, const std::string& url) { 741 void ExpectBrowserNodeURL(int64_t sync_id, const std::string& url) {
735 const BookmarkNode* bnode = 742 const BookmarkNode* bnode =
736 model_associator_->GetChromeNodeFromSyncId(sync_id); 743 model_associator_->GetChromeNodeFromSyncId(sync_id);
737 ASSERT_TRUE(bnode); 744 ASSERT_TRUE(bnode);
738 EXPECT_EQ(GURL(url), bnode->url()); 745 EXPECT_EQ(GURL(url), bnode->url());
739 } 746 }
740 747
741 void ExpectBrowserNodeParent(int64 sync_id, int64 parent_sync_id) { 748 void ExpectBrowserNodeParent(int64_t sync_id, int64_t parent_sync_id) {
742 const BookmarkNode* node = 749 const BookmarkNode* node =
743 model_associator_->GetChromeNodeFromSyncId(sync_id); 750 model_associator_->GetChromeNodeFromSyncId(sync_id);
744 ASSERT_TRUE(node); 751 ASSERT_TRUE(node);
745 const BookmarkNode* parent = 752 const BookmarkNode* parent =
746 model_associator_->GetChromeNodeFromSyncId(parent_sync_id); 753 model_associator_->GetChromeNodeFromSyncId(parent_sync_id);
747 EXPECT_TRUE(parent); 754 EXPECT_TRUE(parent);
748 EXPECT_EQ(node->parent(), parent); 755 EXPECT_EQ(node->parent(), parent);
749 } 756 }
750 757
751 void ExpectModelMatch(syncer::BaseTransaction* trans) { 758 void ExpectModelMatch(syncer::BaseTransaction* trans) {
752 const BookmarkNode* root = model_->root_node(); 759 const BookmarkNode* root = model_->root_node();
753 #if defined(OS_IOS) || defined(OS_ANDROID) 760 #if defined(OS_IOS) || defined(OS_ANDROID)
754 EXPECT_EQ(root->GetIndexOf(model_->mobile_node()), 0); 761 EXPECT_EQ(root->GetIndexOf(model_->mobile_node()), 0);
755 EXPECT_EQ(root->GetIndexOf(model_->bookmark_bar_node()), 1); 762 EXPECT_EQ(root->GetIndexOf(model_->bookmark_bar_node()), 1);
756 EXPECT_EQ(root->GetIndexOf(model_->other_node()), 2); 763 EXPECT_EQ(root->GetIndexOf(model_->other_node()), 2);
757 #else 764 #else
758 EXPECT_EQ(root->GetIndexOf(model_->bookmark_bar_node()), 0); 765 EXPECT_EQ(root->GetIndexOf(model_->bookmark_bar_node()), 0);
759 EXPECT_EQ(root->GetIndexOf(model_->other_node()), 1); 766 EXPECT_EQ(root->GetIndexOf(model_->other_node()), 1);
760 EXPECT_EQ(root->GetIndexOf(model_->mobile_node()), 2); 767 EXPECT_EQ(root->GetIndexOf(model_->mobile_node()), 2);
761 #endif // defined(OS_IOS) || defined(OS_ANDROID) 768 #endif // defined(OS_IOS) || defined(OS_ANDROID)
762 769
763 std::stack<int64> stack; 770 std::stack<int64_t> stack;
764 stack.push(bookmark_bar_id()); 771 stack.push(bookmark_bar_id());
765 while (!stack.empty()) { 772 while (!stack.empty()) {
766 int64 id = stack.top(); 773 int64_t id = stack.top();
767 stack.pop(); 774 stack.pop();
768 if (!id) continue; 775 if (!id) continue;
769 776
770 ExpectBrowserNodeMatching(trans, id); 777 ExpectBrowserNodeMatching(trans, id);
771 778
772 syncer::ReadNode gnode(trans); 779 syncer::ReadNode gnode(trans);
773 ASSERT_EQ(BaseNode::INIT_OK, gnode.InitByIdLookup(id)); 780 ASSERT_EQ(BaseNode::INIT_OK, gnode.InitByIdLookup(id));
774 stack.push(gnode.GetSuccessorId()); 781 stack.push(gnode.GetSuccessorId());
775 if (gnode.GetIsFolder()) 782 if (gnode.GetIsFolder())
776 stack.push(gnode.GetFirstChildId()); 783 stack.push(gnode.GetFirstChildId());
777 } 784 }
778 } 785 }
779 786
780 void ExpectModelMatch() { 787 void ExpectModelMatch() {
781 syncer::ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); 788 syncer::ReadTransaction trans(FROM_HERE, test_user_share_.user_share());
782 ExpectModelMatch(&trans); 789 ExpectModelMatch(&trans);
783 } 790 }
784 791
785 int64 mobile_bookmarks_id() { 792 int64_t mobile_bookmarks_id() {
786 return 793 return
787 model_associator_->GetSyncIdFromChromeId(model_->mobile_node()->id()); 794 model_associator_->GetSyncIdFromChromeId(model_->mobile_node()->id());
788 } 795 }
789 796
790 int64 other_bookmarks_id() { 797 int64_t other_bookmarks_id() {
791 return 798 return
792 model_associator_->GetSyncIdFromChromeId(model_->other_node()->id()); 799 model_associator_->GetSyncIdFromChromeId(model_->other_node()->id());
793 } 800 }
794 801
795 int64 bookmark_bar_id() { 802 int64_t bookmark_bar_id() {
796 return model_associator_->GetSyncIdFromChromeId( 803 return model_associator_->GetSyncIdFromChromeId(
797 model_->bookmark_bar_node()->id()); 804 model_->bookmark_bar_node()->id());
798 } 805 }
799 806
800 private: 807 private:
801 content::TestBrowserThreadBundle thread_bundle_; 808 content::TestBrowserThreadBundle thread_bundle_;
802 809
803 protected: 810 protected:
804 TestingProfile profile_; 811 TestingProfile profile_;
805 TestSyncClient sync_client_; 812 TestSyncClient sync_client_;
(...skipping 30 matching lines...) Expand all
836 // association code. 843 // association code.
837 TEST_F(ProfileSyncServiceBookmarkTest, InitialModelAssociate) { 844 TEST_F(ProfileSyncServiceBookmarkTest, InitialModelAssociate) {
838 const int kNumBookmarksPerFolder = 10; 845 const int kNumBookmarksPerFolder = 10;
839 const int kNumFolders = 10; 846 const int kNumFolders = 10;
840 847
841 CreatePermanentBookmarkNodes(); 848 CreatePermanentBookmarkNodes();
842 849
843 { 850 {
844 syncer::WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); 851 syncer::WriteTransaction trans(FROM_HERE, test_user_share_.user_share());
845 for (int i = 0; i < kNumFolders; ++i) { 852 for (int i = 0; i < kNumFolders; ++i) {
846 int64 folder_id = 853 int64_t folder_id =
847 AddFolderToShare(&trans, base::StringPrintf("folder%05d", i)); 854 AddFolderToShare(&trans, base::StringPrintf("folder%05d", i));
848 for (int j = 0; j < kNumBookmarksPerFolder; ++j) { 855 for (int j = 0; j < kNumBookmarksPerFolder; ++j) {
849 AddBookmarkToShare( 856 AddBookmarkToShare(
850 &trans, folder_id, base::StringPrintf("bookmark%05d", j), 857 &trans, folder_id, base::StringPrintf("bookmark%05d", j),
851 base::StringPrintf("http://www.google.com/search?q=%05d", j)); 858 base::StringPrintf("http://www.google.com/search?q=%05d", j));
852 } 859 }
853 } 860 }
854 } 861 }
855 862
856 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); 863 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE);
(...skipping 25 matching lines...) Expand all
882 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); 889 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE);
883 const BookmarkNode* folder = model_->AddFolder(model_->bookmark_bar_node(), 0, 890 const BookmarkNode* folder = model_->AddFolder(model_->bookmark_bar_node(), 0,
884 base::ASCIIToUTF16("foobar")); 891 base::ASCIIToUTF16("foobar"));
885 const BookmarkNode* bookmark = 892 const BookmarkNode* bookmark =
886 model_->AddURL(folder, 0, base::ASCIIToUTF16("Airplanes"), 893 model_->AddURL(folder, 0, base::ASCIIToUTF16("Airplanes"),
887 GURL("http://www.easyjet.com/")); 894 GURL("http://www.easyjet.com/"));
888 895
889 CreatePermanentBookmarkNodes(); 896 CreatePermanentBookmarkNodes();
890 897
891 // Create entries matching the folder and the bookmark above. 898 // Create entries matching the folder and the bookmark above.
892 int64 folder_id, bookmark_id; 899 int64_t folder_id, bookmark_id;
893 { 900 {
894 syncer::WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); 901 syncer::WriteTransaction trans(FROM_HERE, test_user_share_.user_share());
895 folder_id = AddFolderToShare(&trans, "foobar"); 902 folder_id = AddFolderToShare(&trans, "foobar");
896 bookmark_id = AddBookmarkToShare(&trans, folder_id, "Airplanes", 903 bookmark_id = AddBookmarkToShare(&trans, folder_id, "Airplanes",
897 "http://www.easyjet.com/"); 904 "http://www.easyjet.com/");
898 } 905 }
899 906
900 // Associate the bookmark sync node with the native model one and make 907 // Associate the bookmark sync node with the native model one and make
901 // it look like it was deleted by a server update. 908 // it look like it was deleted by a server update.
902 { 909 {
(...skipping 20 matching lines...) Expand all
923 // Also tests that the external ID is used to match the right bookmark 930 // Also tests that the external ID is used to match the right bookmark
924 // among multiple identical bookmarks when dealing with the delete journal. 931 // among multiple identical bookmarks when dealing with the delete journal.
925 TEST_F(ProfileSyncServiceBookmarkTest, 932 TEST_F(ProfileSyncServiceBookmarkTest,
926 InitialModelAssociateVerifyExternalIdMatch) { 933 InitialModelAssociateVerifyExternalIdMatch) {
927 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); 934 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE);
928 const int kNumFolders = 10; 935 const int kNumFolders = 10;
929 const int kNumBookmarks = 10; 936 const int kNumBookmarks = 10;
930 const int kFolderToIncludeBookmarks = 7; 937 const int kFolderToIncludeBookmarks = 7;
931 const int kBookmarkToDelete = 4; 938 const int kBookmarkToDelete = 4;
932 939
933 int64 folder_ids[kNumFolders]; 940 int64_t folder_ids[kNumFolders];
934 int64 bookmark_ids[kNumBookmarks]; 941 int64_t bookmark_ids[kNumBookmarks];
935 942
936 // Create native folders and bookmarks with identical names. Only 943 // Create native folders and bookmarks with identical names. Only
937 // one of the folders contains bookmarks and others are empty. Here is the 944 // one of the folders contains bookmarks and others are empty. Here is the
938 // expected tree shape: 945 // expected tree shape:
939 // Bookmarks bar 946 // Bookmarks bar
940 // +- folder (#0) 947 // +- folder (#0)
941 // +- folder (#1) 948 // +- folder (#1)
942 // ... 949 // ...
943 // +- folder (#7) <-- Only this folder contains bookmarks. 950 // +- folder (#7) <-- Only this folder contains bookmarks.
944 // +- bookmark (#0) 951 // +- bookmark (#0)
(...skipping 20 matching lines...) Expand all
965 model_->AddURL(parent_folder, i, base::ASCIIToUTF16("bookmark"), 972 model_->AddURL(parent_folder, i, base::ASCIIToUTF16("bookmark"),
966 GURL("http://www.google.com/")); 973 GURL("http://www.google.com/"));
967 bookmark_ids[i] = bookmark->id(); 974 bookmark_ids[i] = bookmark->id();
968 } 975 }
969 976
970 // Number of nodes in bookmark bar before association. 977 // Number of nodes in bookmark bar before association.
971 int total_node_count = model_->bookmark_bar_node()->GetTotalNodeCount(); 978 int total_node_count = model_->bookmark_bar_node()->GetTotalNodeCount();
972 979
973 CreatePermanentBookmarkNodes(); 980 CreatePermanentBookmarkNodes();
974 981
975 int64 sync_bookmark_id_to_delete = 0; 982 int64_t sync_bookmark_id_to_delete = 0;
976 { 983 {
977 // Create sync folders matching native folders above. 984 // Create sync folders matching native folders above.
978 int64 parent_id = 0; 985 int64_t parent_id = 0;
979 syncer::WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); 986 syncer::WriteTransaction trans(FROM_HERE, test_user_share_.user_share());
980 // Create in reverse order because AddFolderToShare passes NULL for 987 // Create in reverse order because AddFolderToShare passes NULL for
981 // |predecessor| argument. 988 // |predecessor| argument.
982 for (int i = kNumFolders - 1; i >= 0; i--) { 989 for (int i = kNumFolders - 1; i >= 0; i--) {
983 int64 id = AddFolderToShare(&trans, "folder"); 990 int64_t id = AddFolderToShare(&trans, "folder");
984 991
985 // Pre-map sync folders to native folders by setting 992 // Pre-map sync folders to native folders by setting
986 // external ID. This will verify that the association algorithm picks 993 // external ID. This will verify that the association algorithm picks
987 // the right ones despite all of them having identical names. 994 // the right ones despite all of them having identical names.
988 // More specifically this will help to avoid cloning bookmarks from 995 // More specifically this will help to avoid cloning bookmarks from
989 // a wrong folder. 996 // a wrong folder.
990 syncer::WriteNode node(&trans); 997 syncer::WriteNode node(&trans);
991 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(id)); 998 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(id));
992 node.GetMutableEntryForTest()->PutLocalExternalId(folder_ids[i]); 999 node.GetMutableEntryForTest()->PutLocalExternalId(folder_ids[i]);
993 1000
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1058 model_->AddURL(folder, 0, base::ASCIIToUTF16("node1"), 1065 model_->AddURL(folder, 0, base::ASCIIToUTF16("node1"),
1059 GURL("http://www.node1.com/")); 1066 GURL("http://www.node1.com/"));
1060 model_->AddURL(folder, 1, base::ASCIIToUTF16("node2"), 1067 model_->AddURL(folder, 1, base::ASCIIToUTF16("node2"),
1061 GURL("http://www.node2.com/")); 1068 GURL("http://www.node2.com/"));
1062 1069
1063 // On the sync side create a matching folder, one matching node, one 1070 // On the sync side create a matching folder, one matching node, one
1064 // unmatching node, and one node with an invalid URL. 1071 // unmatching node, and one node with an invalid URL.
1065 CreatePermanentBookmarkNodes(); 1072 CreatePermanentBookmarkNodes();
1066 { 1073 {
1067 syncer::WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); 1074 syncer::WriteTransaction trans(FROM_HERE, test_user_share_.user_share());
1068 int64 folder_id = AddFolderToShare(&trans, "folder"); 1075 int64_t folder_id = AddFolderToShare(&trans, "folder");
1069 // Please note that each AddBookmarkToShare inserts the node at the front 1076 // Please note that each AddBookmarkToShare inserts the node at the front
1070 // so the actual order of children in the directory will be opposite. 1077 // so the actual order of children in the directory will be opposite.
1071 AddBookmarkToShare(&trans, folder_id, "node2", "http://www.node2.com/"); 1078 AddBookmarkToShare(&trans, folder_id, "node2", "http://www.node2.com/");
1072 AddBookmarkToShare(&trans, folder_id, "node3", ""); 1079 AddBookmarkToShare(&trans, folder_id, "node3", "");
1073 AddBookmarkToShare(&trans, folder_id, "node4", "http://www.node4.com/"); 1080 AddBookmarkToShare(&trans, folder_id, "node4", "http://www.node4.com/");
1074 } 1081 }
1075 1082
1076 // Perform association. 1083 // Perform association.
1077 StartSync(); 1084 StartSync();
1078 1085
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1149 ExpectModelMatch(); 1156 ExpectModelMatch();
1150 } 1157 }
1151 1158
1152 TEST_F(ProfileSyncServiceBookmarkTest, ServerChangeProcessing) { 1159 TEST_F(ProfileSyncServiceBookmarkTest, ServerChangeProcessing) {
1153 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); 1160 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE);
1154 StartSync(); 1161 StartSync();
1155 1162
1156 syncer::WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); 1163 syncer::WriteTransaction trans(FROM_HERE, test_user_share_.user_share());
1157 1164
1158 FakeServerChange adds(&trans); 1165 FakeServerChange adds(&trans);
1159 int64 f1 = adds.AddFolder("Server Folder B", bookmark_bar_id(), 0); 1166 int64_t f1 = adds.AddFolder("Server Folder B", bookmark_bar_id(), 0);
1160 int64 f2 = adds.AddFolder("Server Folder A", bookmark_bar_id(), f1); 1167 int64_t f2 = adds.AddFolder("Server Folder A", bookmark_bar_id(), f1);
1161 int64 u1 = adds.AddURL("Some old site", "ftp://nifty.andrew.cmu.edu/", 1168 int64_t u1 = adds.AddURL("Some old site", "ftp://nifty.andrew.cmu.edu/",
1162 bookmark_bar_id(), f2); 1169 bookmark_bar_id(), f2);
1163 int64 u2 = adds.AddURL("Nifty", "ftp://nifty.andrew.cmu.edu/", f1, 0); 1170 int64_t u2 = adds.AddURL("Nifty", "ftp://nifty.andrew.cmu.edu/", f1, 0);
1164 // u3 is a duplicate URL 1171 // u3 is a duplicate URL
1165 int64 u3 = adds.AddURL("Nifty2", "ftp://nifty.andrew.cmu.edu/", f1, u2); 1172 int64_t u3 = adds.AddURL("Nifty2", "ftp://nifty.andrew.cmu.edu/", f1, u2);
1166 // u4 is a duplicate title, different URL. 1173 // u4 is a duplicate title, different URL.
1167 adds.AddURL("Some old site", "http://slog.thestranger.com/", 1174 adds.AddURL("Some old site", "http://slog.thestranger.com/",
1168 bookmark_bar_id(), u1); 1175 bookmark_bar_id(), u1);
1169 // u5 tests an empty-string title. 1176 // u5 tests an empty-string title.
1170 std::string javascript_url( 1177 std::string javascript_url(
1171 "javascript:(function(){var w=window.open(" \ 1178 "javascript:(function(){var w=window.open(" \
1172 "'about:blank','gnotesWin','location=0,menubar=0," \ 1179 "'about:blank','gnotesWin','location=0,menubar=0," \
1173 "scrollbars=0,status=0,toolbar=0,width=300," \ 1180 "scrollbars=0,status=0,toolbar=0,width=300," \
1174 "height=300,resizable');});"); 1181 "height=300,resizable');});");
1175 adds.AddURL(std::string(), javascript_url, other_bookmarks_id(), 0); 1182 adds.AddURL(std::string(), javascript_url, other_bookmarks_id(), 0);
1176 int64 u6 = adds.AddURL( 1183 int64_t u6 = adds.AddURL("Sync1", "http://www.syncable.edu/",
1177 "Sync1", "http://www.syncable.edu/", mobile_bookmarks_id(), 0); 1184 mobile_bookmarks_id(), 0);
1178 1185
1179 syncer::ChangeRecordList::const_iterator it; 1186 syncer::ChangeRecordList::const_iterator it;
1180 // The bookmark model shouldn't yet have seen any of the nodes of |adds|. 1187 // The bookmark model shouldn't yet have seen any of the nodes of |adds|.
1181 for (it = adds.changes().begin(); it != adds.changes().end(); ++it) 1188 for (it = adds.changes().begin(); it != adds.changes().end(); ++it)
1182 ExpectBrowserNodeUnknown(it->id); 1189 ExpectBrowserNodeUnknown(it->id);
1183 1190
1184 adds.ApplyPendingChanges(change_processor_.get()); 1191 adds.ApplyPendingChanges(change_processor_.get());
1185 1192
1186 // Make sure the bookmark model received all of the nodes in |adds|. 1193 // Make sure the bookmark model received all of the nodes in |adds|.
1187 for (it = adds.changes().begin(); it != adds.changes().end(); ++it) 1194 for (it = adds.changes().begin(); it != adds.changes().end(); ++it)
1188 ExpectBrowserNodeMatching(&trans, it->id); 1195 ExpectBrowserNodeMatching(&trans, it->id);
1189 ExpectModelMatch(&trans); 1196 ExpectModelMatch(&trans);
1190 1197
1191 // Part two: test modifications. 1198 // Part two: test modifications.
1192 FakeServerChange mods(&trans); 1199 FakeServerChange mods(&trans);
1193 // Mess with u2, and move it into empty folder f2 1200 // Mess with u2, and move it into empty folder f2
1194 // TODO(ncarter): Determine if we allow ModifyURL ops or not. 1201 // TODO(ncarter): Determine if we allow ModifyURL ops or not.
1195 /* std::string u2_old_url = mods.ModifyURL(u2, "http://www.google.com"); */ 1202 /* std::string u2_old_url = mods.ModifyURL(u2, "http://www.google.com"); */
1196 std::string u2_old_title = mods.ModifyTitle(u2, "The Google"); 1203 std::string u2_old_title = mods.ModifyTitle(u2, "The Google");
1197 int64 u2_old_parent = mods.ModifyPosition(u2, f2, 0); 1204 int64_t u2_old_parent = mods.ModifyPosition(u2, f2, 0);
1198 1205
1199 // Now move f1 after u2. 1206 // Now move f1 after u2.
1200 std::string f1_old_title = mods.ModifyTitle(f1, "Server Folder C"); 1207 std::string f1_old_title = mods.ModifyTitle(f1, "Server Folder C");
1201 int64 f1_old_parent = mods.ModifyPosition(f1, f2, u2); 1208 int64_t f1_old_parent = mods.ModifyPosition(f1, f2, u2);
1202 1209
1203 // Then add u3 after f1. 1210 // Then add u3 after f1.
1204 int64 u3_old_parent = mods.ModifyPosition(u3, f2, f1); 1211 int64_t u3_old_parent = mods.ModifyPosition(u3, f2, f1);
1205 1212
1206 std::string u6_old_title = mods.ModifyTitle(u6, "Mobile Folder A"); 1213 std::string u6_old_title = mods.ModifyTitle(u6, "Mobile Folder A");
1207 1214
1208 // Test that the property changes have not yet taken effect. 1215 // Test that the property changes have not yet taken effect.
1209 ExpectBrowserNodeTitle(u2, u2_old_title); 1216 ExpectBrowserNodeTitle(u2, u2_old_title);
1210 /* ExpectBrowserNodeURL(u2, u2_old_url); */ 1217 /* ExpectBrowserNodeURL(u2, u2_old_url); */
1211 ExpectBrowserNodeParent(u2, u2_old_parent); 1218 ExpectBrowserNodeParent(u2, u2_old_parent);
1212 1219
1213 ExpectBrowserNodeTitle(f1, f1_old_title); 1220 ExpectBrowserNodeTitle(f1, f1_old_title);
1214 ExpectBrowserNodeParent(f1, f1_old_parent); 1221 ExpectBrowserNodeParent(f1, f1_old_parent);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1249 TEST_F(ProfileSyncServiceBookmarkTest, ServerChangeRequiringFosterParent) { 1256 TEST_F(ProfileSyncServiceBookmarkTest, ServerChangeRequiringFosterParent) {
1250 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); 1257 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE);
1251 StartSync(); 1258 StartSync();
1252 1259
1253 syncer::WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); 1260 syncer::WriteTransaction trans(FROM_HERE, test_user_share_.user_share());
1254 1261
1255 // Stress the immediate children of other_node because that's where 1262 // Stress the immediate children of other_node because that's where
1256 // ApplyModelChanges puts a temporary foster parent node. 1263 // ApplyModelChanges puts a temporary foster parent node.
1257 std::string url("http://dev.chromium.org/"); 1264 std::string url("http://dev.chromium.org/");
1258 FakeServerChange adds(&trans); 1265 FakeServerChange adds(&trans);
1259 int64 f0 = other_bookmarks_id(); // + other_node 1266 int64_t f0 = other_bookmarks_id(); // + other_node
1260 int64 f1 = adds.AddFolder("f1", f0, 0); // + f1 1267 int64_t f1 = adds.AddFolder("f1", f0, 0); // + f1
1261 int64 f2 = adds.AddFolder("f2", f1, 0); // + f2 1268 int64_t f2 = adds.AddFolder("f2", f1, 0); // + f2
1262 int64 u3 = adds.AddURL( "u3", url, f2, 0); // + u3 NOLINT 1269 int64_t u3 = adds.AddURL("u3", url, f2, 0); // + u3 NOLINT
1263 int64 u4 = adds.AddURL( "u4", url, f2, u3); // + u4 NOLINT 1270 int64_t u4 = adds.AddURL("u4", url, f2, u3); // + u4 NOLINT
1264 int64 u5 = adds.AddURL( "u5", url, f1, f2); // + u5 NOLINT 1271 int64_t u5 = adds.AddURL("u5", url, f1, f2); // + u5 NOLINT
1265 int64 f6 = adds.AddFolder("f6", f1, u5); // + f6 1272 int64_t f6 = adds.AddFolder("f6", f1, u5); // + f6
1266 int64 u7 = adds.AddURL( "u7", url, f0, f1); // + u7 NOLINT 1273 int64_t u7 = adds.AddURL("u7", url, f0, f1); // + u7 NOLINT
1267 1274
1268 syncer::ChangeRecordList::const_iterator it; 1275 syncer::ChangeRecordList::const_iterator it;
1269 // The bookmark model shouldn't yet have seen any of the nodes of |adds|. 1276 // The bookmark model shouldn't yet have seen any of the nodes of |adds|.
1270 for (it = adds.changes().begin(); it != adds.changes().end(); ++it) 1277 for (it = adds.changes().begin(); it != adds.changes().end(); ++it)
1271 ExpectBrowserNodeUnknown(it->id); 1278 ExpectBrowserNodeUnknown(it->id);
1272 1279
1273 adds.ApplyPendingChanges(change_processor_.get()); 1280 adds.ApplyPendingChanges(change_processor_.get());
1274 1281
1275 // Make sure the bookmark model received all of the nodes in |adds|. 1282 // Make sure the bookmark model received all of the nodes in |adds|.
1276 for (it = adds.changes().begin(); it != adds.changes().end(); ++it) 1283 for (it = adds.changes().begin(); it != adds.changes().end(); ++it)
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
1501 } 1508 }
1502 1509
1503 TEST_F(ProfileSyncServiceBookmarkTest, ApplySyncDeletesFromJournal) { 1510 TEST_F(ProfileSyncServiceBookmarkTest, ApplySyncDeletesFromJournal) {
1504 // Initialize sync model and bookmark model as: 1511 // Initialize sync model and bookmark model as:
1505 // URL 0 1512 // URL 0
1506 // Folder 1 1513 // Folder 1
1507 // |-- URL 1 1514 // |-- URL 1
1508 // +-- Folder 2 1515 // +-- Folder 2
1509 // +-- URL 2 1516 // +-- URL 2
1510 LoadBookmarkModel(DELETE_EXISTING_STORAGE, SAVE_TO_STORAGE); 1517 LoadBookmarkModel(DELETE_EXISTING_STORAGE, SAVE_TO_STORAGE);
1511 int64 u0 = 0; 1518 int64_t u0 = 0;
1512 int64 f1 = 0; 1519 int64_t f1 = 0;
1513 int64 u1 = 0; 1520 int64_t u1 = 0;
1514 int64 f2 = 0; 1521 int64_t f2 = 0;
1515 int64 u2 = 0; 1522 int64_t u2 = 0;
1516 StartSync(); 1523 StartSync();
1517 int fixed_sync_bk_count = GetSyncBookmarkCount(); 1524 int fixed_sync_bk_count = GetSyncBookmarkCount();
1518 { 1525 {
1519 syncer::WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); 1526 syncer::WriteTransaction trans(FROM_HERE, test_user_share_.user_share());
1520 FakeServerChange adds(&trans); 1527 FakeServerChange adds(&trans);
1521 u0 = adds.AddURL("URL 0", "http://plus.google.com/", bookmark_bar_id(), 0); 1528 u0 = adds.AddURL("URL 0", "http://plus.google.com/", bookmark_bar_id(), 0);
1522 f1 = adds.AddFolder("Folder 1", bookmark_bar_id(), u0); 1529 f1 = adds.AddFolder("Folder 1", bookmark_bar_id(), u0);
1523 u1 = adds.AddURL("URL 1", "http://www.google.com/", f1, 0); 1530 u1 = adds.AddURL("URL 1", "http://www.google.com/", f1, 0);
1524 f2 = adds.AddFolder("Folder 2", f1, u1); 1531 f2 = adds.AddFolder("Folder 2", f1, u1);
1525 u2 = adds.AddURL("URL 2", "http://mail.google.com/", f2, 0); 1532 u2 = adds.AddURL("URL 2", "http://mail.google.com/", f2, 0);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1584 ASSERT_TRUE(test_user_share_.Reload()); 1591 ASSERT_TRUE(test_user_share_.Reload());
1585 EXPECT_EQ(0u, test_user_share_.GetDeleteJournalSize()); 1592 EXPECT_EQ(0u, test_user_share_.GetDeleteJournalSize());
1586 } 1593 }
1587 1594
1588 struct TestData { 1595 struct TestData {
1589 const char* title; 1596 const char* title;
1590 const char* url; 1597 const char* url;
1591 }; 1598 };
1592 1599
1593 // Map from bookmark node ID to its version. 1600 // Map from bookmark node ID to its version.
1594 typedef std::map<int64, int64> BookmarkNodeVersionMap; 1601 typedef std::map<int64_t, int64_t> BookmarkNodeVersionMap;
1595 1602
1596 // TODO(ncarter): Integrate the existing TestNode/PopulateNodeFromString code 1603 // TODO(ncarter): Integrate the existing TestNode/PopulateNodeFromString code
1597 // in the bookmark model unittest, to make it simpler to set up test data 1604 // in the bookmark model unittest, to make it simpler to set up test data
1598 // here (and reduce the amount of duplication among tests), and to reduce the 1605 // here (and reduce the amount of duplication among tests), and to reduce the
1599 // duplication. 1606 // duplication.
1600 class ProfileSyncServiceBookmarkTestWithData 1607 class ProfileSyncServiceBookmarkTestWithData
1601 : public ProfileSyncServiceBookmarkTest { 1608 : public ProfileSyncServiceBookmarkTest {
1602 public: 1609 public:
1603 ProfileSyncServiceBookmarkTestWithData(); 1610 ProfileSyncServiceBookmarkTestWithData();
1604 1611
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after
2207 EXPECT_TRUE(child_node->is_url()); 2214 EXPECT_TRUE(child_node->is_url());
2208 model_->SetDateAdded(child_node, base::Time::FromInternalValue(10)); 2215 model_->SetDateAdded(child_node, base::Time::FromInternalValue(10));
2209 2216
2210 StartSync(); 2217 StartSync();
2211 StopSync(); 2218 StopSync();
2212 2219
2213 // Verify that transaction versions are in sync between the native model 2220 // Verify that transaction versions are in sync between the native model
2214 // and Sync. 2221 // and Sync.
2215 { 2222 {
2216 syncer::ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); 2223 syncer::ReadTransaction trans(FROM_HERE, test_user_share_.user_share());
2217 int64 sync_version = trans.GetModelVersion(syncer::BOOKMARKS); 2224 int64_t sync_version = trans.GetModelVersion(syncer::BOOKMARKS);
2218 int64 native_version = model_->root_node()->sync_transaction_version(); 2225 int64_t native_version = model_->root_node()->sync_transaction_version();
2219 EXPECT_EQ(native_version, sync_version); 2226 EXPECT_EQ(native_version, sync_version);
2220 } 2227 }
2221 2228
2222 // Since the version is in sync the association above should have skipped 2229 // Since the version is in sync the association above should have skipped
2223 // updating the native node above. That is expected optimization (see 2230 // updating the native node above. That is expected optimization (see
2224 // crbug/464907. 2231 // crbug/464907.
2225 EXPECT_EQ(child_node->date_added(), base::Time::FromInternalValue(10)); 2232 EXPECT_EQ(child_node->date_added(), base::Time::FromInternalValue(10));
2226 2233
2227 // Reset transaction version on the native model to trigger updating data 2234 // Reset transaction version on the native model to trigger updating data
2228 // for all bookmark nodes. 2235 // for all bookmark nodes.
2229 model_->SetNodeSyncTransactionVersion( 2236 model_->SetNodeSyncTransactionVersion(
2230 model_->root_node(), syncer::syncable::kInvalidTransactionVersion); 2237 model_->root_node(), syncer::syncable::kInvalidTransactionVersion);
2231 2238
2232 StartSync(); 2239 StartSync();
2233 2240
2234 // Everything should be back in sync after model association. 2241 // Everything should be back in sync after model association.
2235 ExpectBookmarkModelMatchesTestData(); 2242 ExpectBookmarkModelMatchesTestData();
2236 ExpectModelMatch(); 2243 ExpectModelMatch();
2237 2244
2238 // Now trigger a change while syncing. We add a new bookmark, sync it, then 2245 // Now trigger a change while syncing. We add a new bookmark, sync it, then
2239 // updates it's creation time. 2246 // updates it's creation time.
2240 syncer::WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); 2247 syncer::WriteTransaction trans(FROM_HERE, test_user_share_.user_share());
2241 FakeServerChange adds(&trans); 2248 FakeServerChange adds(&trans);
2242 const std::string kTitle = "Some site"; 2249 const std::string kTitle = "Some site";
2243 const std::string kUrl = "http://www.whatwhat.yeah/"; 2250 const std::string kUrl = "http://www.whatwhat.yeah/";
2244 const int kCreationTime = 30; 2251 const int kCreationTime = 30;
2245 int64 id = adds.AddURL(kTitle, kUrl, 2252 int64_t id = adds.AddURL(kTitle, kUrl, bookmark_bar_id(), 0);
2246 bookmark_bar_id(), 0);
2247 adds.ApplyPendingChanges(change_processor_.get()); 2253 adds.ApplyPendingChanges(change_processor_.get());
2248 FakeServerChange updates(&trans); 2254 FakeServerChange updates(&trans);
2249 updates.ModifyCreationTime(id, kCreationTime); 2255 updates.ModifyCreationTime(id, kCreationTime);
2250 updates.ApplyPendingChanges(change_processor_.get()); 2256 updates.ApplyPendingChanges(change_processor_.get());
2251 2257
2252 const BookmarkNode* node = model_->bookmark_bar_node()->GetChild(0); 2258 const BookmarkNode* node = model_->bookmark_bar_node()->GetChild(0);
2253 ASSERT_TRUE(node); 2259 ASSERT_TRUE(node);
2254 EXPECT_TRUE(node->is_url()); 2260 EXPECT_TRUE(node->is_url());
2255 EXPECT_EQ(base::UTF8ToUTF16(kTitle), node->GetTitle()); 2261 EXPECT_EQ(base::UTF8ToUTF16(kTitle), node->GetTitle());
2256 EXPECT_EQ(kUrl, node->url().possibly_invalid_spec()); 2262 EXPECT_EQ(kUrl, node->url().possibly_invalid_spec());
(...skipping 19 matching lines...) Expand all
2276 model_->root_node(), syncer::syncable::kInvalidTransactionVersion); 2282 model_->root_node(), syncer::syncable::kInvalidTransactionVersion);
2277 2283
2278 // Restart sync. 2284 // Restart sync.
2279 StartSync(); 2285 StartSync();
2280 StopSync(); 2286 StopSync();
2281 2287
2282 // Verify that the native transaction version has been updated and is now 2288 // Verify that the native transaction version has been updated and is now
2283 // in sync with the sync version. 2289 // in sync with the sync version.
2284 { 2290 {
2285 syncer::ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); 2291 syncer::ReadTransaction trans(FROM_HERE, test_user_share_.user_share());
2286 int64 sync_version = trans.GetModelVersion(syncer::BOOKMARKS); 2292 int64_t sync_version = trans.GetModelVersion(syncer::BOOKMARKS);
2287 int64 native_version = model_->root_node()->sync_transaction_version(); 2293 int64_t native_version = model_->root_node()->sync_transaction_version();
2288 EXPECT_EQ(native_version, sync_version); 2294 EXPECT_EQ(native_version, sync_version);
2289 } 2295 }
2290 } 2296 }
2291 2297
2292 // Tests that changes to the sync nodes meta info gets reflected in the local 2298 // Tests that changes to the sync nodes meta info gets reflected in the local
2293 // bookmark model. 2299 // bookmark model.
2294 TEST_F(ProfileSyncServiceBookmarkTestWithData, UpdateMetaInfoFromSync) { 2300 TEST_F(ProfileSyncServiceBookmarkTestWithData, UpdateMetaInfoFromSync) {
2295 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); 2301 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE);
2296 WriteTestDataToBookmarkModel(); 2302 WriteTestDataToBookmarkModel();
2297 StartSync(); 2303 StartSync();
2298 2304
2299 // Create bookmark nodes containing meta info. 2305 // Create bookmark nodes containing meta info.
2300 syncer::WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); 2306 syncer::WriteTransaction trans(FROM_HERE, test_user_share_.user_share());
2301 FakeServerChange adds(&trans); 2307 FakeServerChange adds(&trans);
2302 BookmarkNode::MetaInfoMap folder_meta_info; 2308 BookmarkNode::MetaInfoMap folder_meta_info;
2303 folder_meta_info["folder"] = "foldervalue"; 2309 folder_meta_info["folder"] = "foldervalue";
2304 int64 folder_id = adds.AddFolderWithMetaInfo( 2310 int64_t folder_id = adds.AddFolderWithMetaInfo(
2305 "folder title", &folder_meta_info, bookmark_bar_id(), 0); 2311 "folder title", &folder_meta_info, bookmark_bar_id(), 0);
2306 BookmarkNode::MetaInfoMap node_meta_info; 2312 BookmarkNode::MetaInfoMap node_meta_info;
2307 node_meta_info["node"] = "nodevalue"; 2313 node_meta_info["node"] = "nodevalue";
2308 node_meta_info["other"] = "othervalue"; 2314 node_meta_info["other"] = "othervalue";
2309 int64 id = adds.AddURLWithMetaInfo("node title", "http://www.foo.com", 2315 int64_t id = adds.AddURLWithMetaInfo("node title", "http://www.foo.com",
2310 &node_meta_info, folder_id, 0); 2316 &node_meta_info, folder_id, 0);
2311 adds.ApplyPendingChanges(change_processor_.get()); 2317 adds.ApplyPendingChanges(change_processor_.get());
2312 2318
2313 // Verify that the nodes are created with the correct meta info. 2319 // Verify that the nodes are created with the correct meta info.
2314 ASSERT_LT(0, model_->bookmark_bar_node()->child_count()); 2320 ASSERT_LT(0, model_->bookmark_bar_node()->child_count());
2315 const BookmarkNode* folder_node = model_->bookmark_bar_node()->GetChild(0); 2321 const BookmarkNode* folder_node = model_->bookmark_bar_node()->GetChild(0);
2316 ASSERT_TRUE(folder_node->GetMetaInfoMap()); 2322 ASSERT_TRUE(folder_node->GetMetaInfoMap());
2317 EXPECT_EQ(folder_meta_info, *folder_node->GetMetaInfoMap()); 2323 EXPECT_EQ(folder_meta_info, *folder_node->GetMetaInfoMap());
2318 ASSERT_LT(0, folder_node->child_count()); 2324 ASSERT_LT(0, folder_node->child_count());
2319 const BookmarkNode* node = folder_node->GetChild(0); 2325 const BookmarkNode* node = folder_node->GetChild(0);
2320 ASSERT_TRUE(node->GetMetaInfoMap()); 2326 ASSERT_TRUE(node->GetMetaInfoMap());
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
2368 2374
2369 // Tests that node's specifics doesn't get unnecessarily overwritten (causing 2375 // Tests that node's specifics doesn't get unnecessarily overwritten (causing
2370 // a subsequent commit) when BookmarkChangeProcessor handles a notification 2376 // a subsequent commit) when BookmarkChangeProcessor handles a notification
2371 // (such as BookmarkMetaInfoChanged) without an actual data change. 2377 // (such as BookmarkMetaInfoChanged) without an actual data change.
2372 TEST_F(ProfileSyncServiceBookmarkTestWithData, MetaInfoPreservedOnNonChange) { 2378 TEST_F(ProfileSyncServiceBookmarkTestWithData, MetaInfoPreservedOnNonChange) {
2373 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); 2379 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE);
2374 WriteTestDataToBookmarkModel(); 2380 WriteTestDataToBookmarkModel();
2375 StartSync(); 2381 StartSync();
2376 2382
2377 std::string orig_specifics; 2383 std::string orig_specifics;
2378 int64 sync_id; 2384 int64_t sync_id;
2379 const BookmarkNode* bookmark; 2385 const BookmarkNode* bookmark;
2380 2386
2381 // Create bookmark folder node containing meta info. 2387 // Create bookmark folder node containing meta info.
2382 { 2388 {
2383 syncer::WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); 2389 syncer::WriteTransaction trans(FROM_HERE, test_user_share_.user_share());
2384 FakeServerChange adds(&trans); 2390 FakeServerChange adds(&trans);
2385 2391
2386 int64 folder_id = adds.AddFolder("folder title", bookmark_bar_id(), 0); 2392 int64_t folder_id = adds.AddFolder("folder title", bookmark_bar_id(), 0);
2387 2393
2388 BookmarkNode::MetaInfoMap node_meta_info; 2394 BookmarkNode::MetaInfoMap node_meta_info;
2389 node_meta_info["one"] = "1"; 2395 node_meta_info["one"] = "1";
2390 node_meta_info["two"] = "2"; 2396 node_meta_info["two"] = "2";
2391 node_meta_info["three"] = "3"; 2397 node_meta_info["three"] = "3";
2392 2398
2393 sync_id = adds.AddURLWithMetaInfo("node title", "http://www.foo.com/", 2399 sync_id = adds.AddURLWithMetaInfo("node title", "http://www.foo.com/",
2394 &node_meta_info, folder_id, 0); 2400 &node_meta_info, folder_id, 0);
2395 2401
2396 // Verify that the node propagates to the bookmark model 2402 // Verify that the node propagates to the bookmark model
(...skipping 24 matching lines...) Expand all
2421 void ProfileSyncServiceBookmarkTestWithData::GetTransactionVersions( 2427 void ProfileSyncServiceBookmarkTestWithData::GetTransactionVersions(
2422 const BookmarkNode* root, 2428 const BookmarkNode* root,
2423 BookmarkNodeVersionMap* node_versions) { 2429 BookmarkNodeVersionMap* node_versions) {
2424 node_versions->clear(); 2430 node_versions->clear();
2425 std::queue<const BookmarkNode*> nodes; 2431 std::queue<const BookmarkNode*> nodes;
2426 nodes.push(root); 2432 nodes.push(root);
2427 while (!nodes.empty()) { 2433 while (!nodes.empty()) {
2428 const BookmarkNode* n = nodes.front(); 2434 const BookmarkNode* n = nodes.front();
2429 nodes.pop(); 2435 nodes.pop();
2430 2436
2431 int64 version = n->sync_transaction_version(); 2437 int64_t version = n->sync_transaction_version();
2432 EXPECT_NE(BookmarkNode::kInvalidSyncTransactionVersion, version); 2438 EXPECT_NE(BookmarkNode::kInvalidSyncTransactionVersion, version);
2433 2439
2434 (*node_versions)[n->id()] = version; 2440 (*node_versions)[n->id()] = version;
2435 for (int i = 0; i < n->child_count(); ++i) { 2441 for (int i = 0; i < n->child_count(); ++i) {
2436 if (!CanSyncNode(n->GetChild(i))) 2442 if (!CanSyncNode(n->GetChild(i)))
2437 continue; 2443 continue;
2438 nodes.push(n->GetChild(i)); 2444 nodes.push(n->GetChild(i));
2439 } 2445 }
2440 } 2446 }
2441 } 2447 }
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
2539 } 2545 }
2540 ExpectTransactionVersionMatch(model_->bookmark_bar_node(), 2546 ExpectTransactionVersionMatch(model_->bookmark_bar_node(),
2541 BookmarkNodeVersionMap()); 2547 BookmarkNodeVersionMap());
2542 ExpectTransactionVersionMatch(model_->other_node(), 2548 ExpectTransactionVersionMatch(model_->other_node(),
2543 BookmarkNodeVersionMap()); 2549 BookmarkNodeVersionMap());
2544 ExpectTransactionVersionMatch(model_->mobile_node(), 2550 ExpectTransactionVersionMatch(model_->mobile_node(),
2545 BookmarkNodeVersionMap()); 2551 BookmarkNodeVersionMap());
2546 2552
2547 // Now shut down sync and artificially increment the native model's version. 2553 // Now shut down sync and artificially increment the native model's version.
2548 StopSync(); 2554 StopSync();
2549 int64 root_version = initial_versions[model_->root_node()->id()]; 2555 int64_t root_version = initial_versions[model_->root_node()->id()];
2550 model_->SetNodeSyncTransactionVersion(model_->root_node(), root_version + 1); 2556 model_->SetNodeSyncTransactionVersion(model_->root_node(), root_version + 1);
2551 2557
2552 // Upon association, bookmarks should fail to associate. 2558 // Upon association, bookmarks should fail to associate.
2553 EXPECT_FALSE(AssociateModels()); 2559 EXPECT_FALSE(AssociateModels());
2554 } 2560 }
2555 2561
2556 // It's possible for update/add calls from the bookmark model to be out of 2562 // It's possible for update/add calls from the bookmark model to be out of
2557 // order, or asynchronous. Handle that without triggering an error. 2563 // order, or asynchronous. Handle that without triggering an error.
2558 TEST_F(ProfileSyncServiceBookmarkTest, UpdateThenAdd) { 2564 TEST_F(ProfileSyncServiceBookmarkTest, UpdateThenAdd) {
2559 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); 2565 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
2596 2602
2597 // Create a bookmark under managed_node() permanent folder. 2603 // Create a bookmark under managed_node() permanent folder.
2598 bookmarks::ManagedBookmarkService* managed_bookmark_service = 2604 bookmarks::ManagedBookmarkService* managed_bookmark_service =
2599 ManagedBookmarkServiceFactory::GetForProfile(&profile_); 2605 ManagedBookmarkServiceFactory::GetForProfile(&profile_);
2600 const BookmarkNode* folder = managed_bookmark_service->managed_node(); 2606 const BookmarkNode* folder = managed_bookmark_service->managed_node();
2601 const BookmarkNode* node = model_->AddURL( 2607 const BookmarkNode* node = model_->AddURL(
2602 folder, 0, base::ASCIIToUTF16("node"), GURL("http://www.node.com/")); 2608 folder, 0, base::ASCIIToUTF16("node"), GURL("http://www.node.com/"));
2603 2609
2604 // Verify that these changes are ignored by Sync. 2610 // Verify that these changes are ignored by Sync.
2605 EXPECT_EQ(sync_bookmark_count, GetSyncBookmarkCount()); 2611 EXPECT_EQ(sync_bookmark_count, GetSyncBookmarkCount());
2606 int64 sync_id = model_associator_->GetSyncIdFromChromeId(node->id()); 2612 int64_t sync_id = model_associator_->GetSyncIdFromChromeId(node->id());
2607 EXPECT_EQ(syncer::kInvalidId, sync_id); 2613 EXPECT_EQ(syncer::kInvalidId, sync_id);
2608 2614
2609 // Verify that Sync ignores deleting this node. 2615 // Verify that Sync ignores deleting this node.
2610 model_->Remove(node); 2616 model_->Remove(node);
2611 EXPECT_EQ(sync_bookmark_count, GetSyncBookmarkCount()); 2617 EXPECT_EQ(sync_bookmark_count, GetSyncBookmarkCount());
2612 } 2618 }
2613 2619
2614 } // namespace 2620 } // namespace
2615 2621
2616 } // namespace browser_sync 2622 } // 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_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698