Chromium Code Reviews| 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> |
| 11 #include <stack> | 11 #include <stack> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 15 #include "base/file_util.h" | 15 #include "base/file_util.h" |
| 16 #include "base/files/file_path.h" | 16 #include "base/files/file_path.h" |
| 17 #include "base/location.h" | 17 #include "base/location.h" |
| 18 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
| 19 #include "base/message_loop.h" | 19 #include "base/message_loop.h" |
| 20 #include "base/string16.h" | 20 #include "base/string16.h" |
| 21 #include "base/string_util.h" | 21 #include "base/string_util.h" |
| 22 #include "base/stringprintf.h" | |
| 22 #include "base/strings/string_number_conversions.h" | 23 #include "base/strings/string_number_conversions.h" |
| 23 #include "base/time.h" | 24 #include "base/time.h" |
| 24 #include "base/utf_string_conversions.h" | 25 #include "base/utf_string_conversions.h" |
| 25 #include "chrome/browser/bookmarks/base_bookmark_model_observer.h" | 26 #include "chrome/browser/bookmarks/base_bookmark_model_observer.h" |
| 26 #include "chrome/browser/bookmarks/bookmark_model.h" | 27 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 27 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 28 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 28 #include "chrome/browser/sync/glue/bookmark_change_processor.h" | 29 #include "chrome/browser/sync/glue/bookmark_change_processor.h" |
| 29 #include "chrome/browser/sync/glue/bookmark_model_associator.h" | 30 #include "chrome/browser/sync/glue/bookmark_model_associator.h" |
| 30 #include "chrome/browser/sync/glue/data_type_error_handler.h" | 31 #include "chrome/browser/sync/glue/data_type_error_handler.h" |
| 31 #include "chrome/browser/sync/glue/data_type_error_handler_mock.h" | 32 #include "chrome/browser/sync/glue/data_type_error_handler_mock.h" |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 280 } | 281 } |
| 281 | 282 |
| 282 virtual void SetUp() { | 283 virtual void SetUp() { |
| 283 test_user_share_.SetUp(); | 284 test_user_share_.SetUp(); |
| 284 } | 285 } |
| 285 | 286 |
| 286 virtual void TearDown() { | 287 virtual void TearDown() { |
| 287 test_user_share_.TearDown(); | 288 test_user_share_.TearDown(); |
| 288 } | 289 } |
| 289 | 290 |
| 291 // Inserts a folder directly to the share. | |
| 292 // Do not use this after model association is complete. | |
| 293 int64 AddFolderToShare(syncer::WriteTransaction* trans, std::string title) { | |
|
tim (not reviewing)
2013/05/20 18:26:20
It seems this is actually hard-wired to add a fold
rlarocque
2013/05/20 20:09:54
It is hard-coded to add folders to the bookmark ba
| |
| 294 EXPECT_FALSE(model_associator_); | |
| 295 | |
| 296 // Be sure to call CreatePermanentBookmarkNodes(), otherwise this will fail. | |
| 297 syncer::ReadNode bookmark_bar(trans); | |
| 298 EXPECT_EQ(BaseNode::INIT_OK, bookmark_bar.InitByTagLookup("bookmark_bar")); | |
| 299 | |
| 300 syncer::WriteNode node(trans); | |
| 301 EXPECT_TRUE(node.InitBookmarkByCreation(bookmark_bar, NULL)); | |
| 302 node.SetIsFolder(true); | |
| 303 node.SetTitle(ASCIIToWide(title)); | |
| 304 | |
| 305 return node.GetId(); | |
| 306 } | |
| 307 | |
| 308 // Inserts a bookmark directly to the share. | |
| 309 // Do not use this after model association is complete. | |
| 310 int64 AddBookmarkToShare(syncer::WriteTransaction *trans, | |
| 311 int64 parent_id, | |
| 312 std::string title) { | |
| 313 EXPECT_FALSE(model_associator_); | |
| 314 | |
| 315 syncer::ReadNode parent(trans); | |
| 316 EXPECT_EQ(BaseNode::INIT_OK, parent.InitByIdLookup(parent_id)); | |
| 317 | |
| 318 sync_pb::BookmarkSpecifics specifics; | |
| 319 specifics.set_url("http://www.google.com/search?q=" + title); | |
| 320 specifics.set_title(title); | |
| 321 | |
| 322 syncer::WriteNode node(trans); | |
| 323 EXPECT_TRUE(node.InitBookmarkByCreation(parent, NULL)); | |
| 324 node.SetIsFolder(false); | |
| 325 node.SetTitle(ASCIIToWide(title)); | |
| 326 node.SetBookmarkSpecifics(specifics); | |
| 327 | |
| 328 return node.GetId(); | |
| 329 } | |
| 330 | |
| 290 // Load (or re-load) the bookmark model. |load| controls use of the | 331 // Load (or re-load) the bookmark model. |load| controls use of the |
| 291 // bookmarks file on disk. |save| controls whether the newly loaded | 332 // bookmarks file on disk. |save| controls whether the newly loaded |
| 292 // bookmark model will write out a bookmark file as it goes. | 333 // bookmark model will write out a bookmark file as it goes. |
| 293 void LoadBookmarkModel(LoadOption load, SaveOption save) { | 334 void LoadBookmarkModel(LoadOption load, SaveOption save) { |
| 294 bool delete_bookmarks = load == DELETE_EXISTING_STORAGE; | 335 bool delete_bookmarks = load == DELETE_EXISTING_STORAGE; |
| 295 profile_.CreateBookmarkModel(delete_bookmarks); | 336 profile_.CreateBookmarkModel(delete_bookmarks); |
| 296 model_ = BookmarkModelFactory::GetForProfile(&profile_); | 337 model_ = BookmarkModelFactory::GetForProfile(&profile_); |
| 297 ui_test_utils::WaitForBookmarkModelToLoad(model_); | 338 ui_test_utils::WaitForBookmarkModelToLoad(model_); |
| 298 // This noticeably speeds up the unit tests that request it. | 339 // This noticeably speeds up the unit tests that request it. |
| 299 if (save == DONT_SAVE_TO_STORAGE) | 340 if (save == DONT_SAVE_TO_STORAGE) |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 618 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); | 659 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); |
| 619 StartSync(); | 660 StartSync(); |
| 620 | 661 |
| 621 EXPECT_TRUE(other_bookmarks_id()); | 662 EXPECT_TRUE(other_bookmarks_id()); |
| 622 EXPECT_TRUE(bookmark_bar_id()); | 663 EXPECT_TRUE(bookmark_bar_id()); |
| 623 EXPECT_TRUE(mobile_bookmarks_id()); | 664 EXPECT_TRUE(mobile_bookmarks_id()); |
| 624 | 665 |
| 625 ExpectModelMatch(); | 666 ExpectModelMatch(); |
| 626 } | 667 } |
| 627 | 668 |
| 669 // Populate the sync database then start model association. Sync's bookmarks | |
| 670 // should end up being copied into the native model, resulting in a successful | |
| 671 // "ExpectModelMatch()". | |
| 672 TEST_F(ProfileSyncServiceBookmarkTest, InitialModelAssociate) { | |
| 673 const int kNumBookmarksPerFolder = 10; | |
| 674 const int kNumFolders = 10; | |
| 675 | |
| 676 CreatePermanentBookmarkNodes(); | |
| 677 | |
| 678 { | |
| 679 syncer::WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); | |
| 680 for (int i = 0; i < kNumFolders; ++i) { | |
| 681 int64 folder_id = AddFolderToShare(&trans, | |
| 682 base::StringPrintf("folder%05d", i)); | |
| 683 for (int j = 0; j < kNumBookmarksPerFolder; ++j) { | |
| 684 AddBookmarkToShare(&trans, | |
| 685 folder_id, | |
| 686 base::StringPrintf("bookmark%05d", j)); | |
| 687 } | |
| 688 } | |
| 689 } | |
| 690 | |
| 691 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); | |
| 692 StartSync(); | |
| 693 | |
| 694 ExpectModelMatch(); | |
| 695 } | |
| 696 | |
| 697 | |
| 628 TEST_F(ProfileSyncServiceBookmarkTest, BookmarkModelOperations) { | 698 TEST_F(ProfileSyncServiceBookmarkTest, BookmarkModelOperations) { |
| 629 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); | 699 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); |
| 630 StartSync(); | 700 StartSync(); |
| 631 | 701 |
| 632 // Test addition. | 702 // Test addition. |
| 633 const BookmarkNode* folder = | 703 const BookmarkNode* folder = |
| 634 model_->AddFolder(model_->other_node(), 0, ASCIIToUTF16("foobar")); | 704 model_->AddFolder(model_->other_node(), 0, ASCIIToUTF16("foobar")); |
| 635 ExpectSyncerNodeMatching(folder); | 705 ExpectSyncerNodeMatching(folder); |
| 636 ExpectModelMatch(); | 706 ExpectModelMatch(); |
| 637 const BookmarkNode* folder2 = | 707 const BookmarkNode* folder2 = |
| (...skipping 1190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1828 new_versions[changed_bookmark->id()]); | 1898 new_versions[changed_bookmark->id()]); |
| 1829 initial_versions.erase(changed_bookmark->id()); | 1899 initial_versions.erase(changed_bookmark->id()); |
| 1830 ExpectTransactionVersionMatch(model_->bookmark_bar_node(), initial_versions); | 1900 ExpectTransactionVersionMatch(model_->bookmark_bar_node(), initial_versions); |
| 1831 ExpectTransactionVersionMatch(model_->other_node(), initial_versions); | 1901 ExpectTransactionVersionMatch(model_->other_node(), initial_versions); |
| 1832 ExpectTransactionVersionMatch(model_->mobile_node(), initial_versions); | 1902 ExpectTransactionVersionMatch(model_->mobile_node(), initial_versions); |
| 1833 } | 1903 } |
| 1834 | 1904 |
| 1835 } // namespace | 1905 } // namespace |
| 1836 | 1906 |
| 1837 } // namespace browser_sync | 1907 } // namespace browser_sync |
| OLD | NEW |