| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // TODO(akalin): This file is basically just a unit test for | 5 // TODO(akalin): This file is basically just a unit test for |
| 6 // BookmarkChangeProcessor. Write unit tests for | 6 // BookmarkChangeProcessor. Write unit tests for |
| 7 // BookmarkModelAssociator separately. | 7 // BookmarkModelAssociator separately. |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <queue> | 10 #include <queue> |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 // This function differs from the AddFolder() function declared elsewhere in | 343 // This function differs from the AddFolder() function declared elsewhere in |
| 344 // this file in that it only affects the sync model. It would be invalid to | 344 // this file in that it only affects the sync model. It would be invalid to |
| 345 // change the sync model directly after ModelAssociation. This function can | 345 // change the sync model directly after ModelAssociation. This function can |
| 346 // be invoked prior to model association to set up first-time sync model | 346 // be invoked prior to model association to set up first-time sync model |
| 347 // association scenarios. | 347 // association scenarios. |
| 348 int64 AddFolderToShare(syncer::WriteTransaction* trans, std::string title) { | 348 int64 AddFolderToShare(syncer::WriteTransaction* trans, std::string title) { |
| 349 EXPECT_FALSE(model_associator_); | 349 EXPECT_FALSE(model_associator_); |
| 350 | 350 |
| 351 // Be sure to call CreatePermanentBookmarkNodes(), otherwise this will fail. | 351 // Be sure to call CreatePermanentBookmarkNodes(), otherwise this will fail. |
| 352 syncer::ReadNode bookmark_bar(trans); | 352 syncer::ReadNode bookmark_bar(trans); |
| 353 EXPECT_EQ(BaseNode::INIT_OK, bookmark_bar.InitByTagLookup("bookmark_bar")); | 353 EXPECT_EQ(BaseNode::INIT_OK, |
| 354 bookmark_bar.InitByTagLookupForBookmarks("bookmark_bar")); |
| 354 | 355 |
| 355 syncer::WriteNode node(trans); | 356 syncer::WriteNode node(trans); |
| 356 EXPECT_TRUE(node.InitBookmarkByCreation(bookmark_bar, NULL)); | 357 EXPECT_TRUE(node.InitBookmarkByCreation(bookmark_bar, NULL)); |
| 357 node.SetIsFolder(true); | 358 node.SetIsFolder(true); |
| 358 node.SetTitle(title); | 359 node.SetTitle(title); |
| 359 | 360 |
| 360 return node.GetId(); | 361 return node.GetId(); |
| 361 } | 362 } |
| 362 | 363 |
| 363 // Inserts a bookmark directly to the share. | 364 // Inserts a bookmark directly to the share. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 test::WaitForBookmarkModelToLoad(model_); | 400 test::WaitForBookmarkModelToLoad(model_); |
| 400 // This noticeably speeds up the unit tests that request it. | 401 // This noticeably speeds up the unit tests that request it. |
| 401 if (save == DONT_SAVE_TO_STORAGE) | 402 if (save == DONT_SAVE_TO_STORAGE) |
| 402 model_->ClearStore(); | 403 model_->ClearStore(); |
| 403 message_loop_.RunUntilIdle(); | 404 message_loop_.RunUntilIdle(); |
| 404 } | 405 } |
| 405 | 406 |
| 406 int GetSyncBookmarkCount() { | 407 int GetSyncBookmarkCount() { |
| 407 syncer::ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); | 408 syncer::ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); |
| 408 syncer::ReadNode node(&trans); | 409 syncer::ReadNode node(&trans); |
| 409 if (node.InitByTagLookup(syncer::ModelTypeToRootTag(syncer::BOOKMARKS)) != | 410 if (node.InitTypeRoot(syncer::BOOKMARKS) != syncer::BaseNode::INIT_OK) |
| 410 syncer::BaseNode::INIT_OK) | |
| 411 return 0; | 411 return 0; |
| 412 return node.GetTotalNodeCount(); | 412 return node.GetTotalNodeCount(); |
| 413 } | 413 } |
| 414 | 414 |
| 415 // Creates the bookmark root node and the permanent nodes if they don't | 415 // Creates the bookmark root node and the permanent nodes if they don't |
| 416 // already exist. | 416 // already exist. |
| 417 bool CreatePermanentBookmarkNodes() { | 417 bool CreatePermanentBookmarkNodes() { |
| 418 bool root_exists = false; | 418 bool root_exists = false; |
| 419 syncer::ModelType type = syncer::BOOKMARKS; | 419 syncer::ModelType type = syncer::BOOKMARKS; |
| 420 { | 420 { |
| 421 syncer::WriteTransaction trans(FROM_HERE, | 421 syncer::WriteTransaction trans(FROM_HERE, |
| 422 test_user_share_.user_share()); | 422 test_user_share_.user_share()); |
| 423 syncer::ReadNode uber_root(&trans); | 423 syncer::ReadNode uber_root(&trans); |
| 424 uber_root.InitByRootLookup(); | 424 uber_root.InitByRootLookup(); |
| 425 | 425 |
| 426 syncer::ReadNode root(&trans); | 426 syncer::ReadNode root(&trans); |
| 427 root_exists = (root.InitByTagLookup(syncer::ModelTypeToRootTag(type)) == | 427 root_exists = (root.InitTypeRoot(type) == BaseNode::INIT_OK); |
| 428 BaseNode::INIT_OK); | |
| 429 } | 428 } |
| 430 | 429 |
| 431 if (!root_exists) { | 430 if (!root_exists) { |
| 432 if (!syncer::TestUserShare::CreateRoot(type, | 431 if (!syncer::TestUserShare::CreateRoot(type, |
| 433 test_user_share_.user_share())) | 432 test_user_share_.user_share())) |
| 434 return false; | 433 return false; |
| 435 } | 434 } |
| 436 | 435 |
| 437 const int kNumPermanentNodes = 3; | 436 const int kNumPermanentNodes = 3; |
| 438 const std::string permanent_tags[kNumPermanentNodes] = { | 437 const std::string permanent_tags[kNumPermanentNodes] = { |
| 439 "bookmark_bar", "other_bookmarks", "synced_bookmarks" | 438 "bookmark_bar", "other_bookmarks", "synced_bookmarks" |
| 440 }; | 439 }; |
| 441 syncer::WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); | 440 syncer::WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); |
| 442 syncer::ReadNode root(&trans); | 441 syncer::ReadNode root(&trans); |
| 443 EXPECT_EQ(BaseNode::INIT_OK, root.InitByTagLookup( | 442 EXPECT_EQ(BaseNode::INIT_OK, root.InitTypeRoot(type)); |
| 444 syncer::ModelTypeToRootTag(type))); | |
| 445 | 443 |
| 446 // Loop through creating permanent nodes as necessary. | 444 // Loop through creating permanent nodes as necessary. |
| 447 int64 last_child_id = syncer::kInvalidId; | 445 int64 last_child_id = syncer::kInvalidId; |
| 448 for (int i = 0; i < kNumPermanentNodes; ++i) { | 446 for (int i = 0; i < kNumPermanentNodes; ++i) { |
| 449 // First check if the node already exists. This is for tests that involve | 447 // First check if the node already exists. This is for tests that involve |
| 450 // persistence and set up sync more than once. | 448 // persistence and set up sync more than once. |
| 451 syncer::ReadNode lookup(&trans); | 449 syncer::ReadNode lookup(&trans); |
| 452 if (lookup.InitByTagLookup(permanent_tags[i]) == | 450 if (lookup.InitByTagLookupForBookmarks(permanent_tags[i]) == |
| 453 syncer::ReadNode::INIT_OK) { | 451 syncer::ReadNode::INIT_OK) { |
| 454 last_child_id = lookup.GetId(); | 452 last_child_id = lookup.GetId(); |
| 455 continue; | 453 continue; |
| 456 } | 454 } |
| 457 | 455 |
| 458 // If it doesn't exist, create the permanent node at the end of the | 456 // If it doesn't exist, create the permanent node at the end of the |
| 459 // ordering. | 457 // ordering. |
| 460 syncer::ReadNode predecessor_node(&trans); | 458 syncer::ReadNode predecessor_node(&trans); |
| 461 syncer::ReadNode* predecessor = NULL; | 459 syncer::ReadNode* predecessor = NULL; |
| 462 if (last_child_id != syncer::kInvalidId) { | 460 if (last_child_id != syncer::kInvalidId) { |
| (...skipping 1701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2164 ExpectModelMatch(); | 2162 ExpectModelMatch(); |
| 2165 | 2163 |
| 2166 // Then simulate the add call arriving late. | 2164 // Then simulate the add call arriving late. |
| 2167 change_processor_->BookmarkNodeAdded(model_, model_->bookmark_bar_node(), 0); | 2165 change_processor_->BookmarkNodeAdded(model_, model_->bookmark_bar_node(), 0); |
| 2168 ExpectModelMatch(); | 2166 ExpectModelMatch(); |
| 2169 } | 2167 } |
| 2170 | 2168 |
| 2171 } // namespace | 2169 } // namespace |
| 2172 | 2170 |
| 2173 } // namespace browser_sync | 2171 } // namespace browser_sync |
| OLD | NEW |