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

Side by Side Diff: components/browser_sync/browser/profile_sync_service_bookmark_unittest.cc

Issue 2289143003: [Sync] Convert DTCs to be not RefCounted and NonThreadSafe. (Closed)
Patch Set: Rebase. Created 4 years, 3 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> 9 #include <stddef.h>
10 #include <stdint.h> 10 #include <stdint.h>
11 11
12 #include <map> 12 #include <map>
13 #include <memory> 13 #include <memory>
14 #include <queue> 14 #include <queue>
15 #include <stack> 15 #include <stack>
16 #include <utility> 16 #include <utility>
17 17
18 #include "base/bind.h" 18 #include "base/bind.h"
19 #include "base/bind_helpers.h" 19 #include "base/bind_helpers.h"
20 #include "base/files/file_util.h" 20 #include "base/files/file_util.h"
21 #include "base/location.h" 21 #include "base/location.h"
22 #include "base/macros.h" 22 #include "base/macros.h"
23 #include "base/memory/ptr_util.h" 23 #include "base/memory/ptr_util.h"
24 #include "base/run_loop.h" 24 #include "base/run_loop.h"
25 #include "base/strings/string16.h" 25 #include "base/strings/string16.h"
26 #include "base/strings/string_number_conversions.h" 26 #include "base/strings/string_number_conversions.h"
27 #include "base/strings/string_util.h" 27 #include "base/strings/string_util.h"
28 #include "base/strings/stringprintf.h" 28 #include "base/strings/stringprintf.h"
29 #include "base/strings/utf_string_conversions.h" 29 #include "base/strings/utf_string_conversions.h"
30 #include "base/test/test_message_loop.h"
30 #include "base/time/time.h" 31 #include "base/time/time.h"
31 #include "build/build_config.h" 32 #include "build/build_config.h"
32 #include "components/bookmarks/browser/base_bookmark_model_observer.h" 33 #include "components/bookmarks/browser/base_bookmark_model_observer.h"
33 #include "components/bookmarks/browser/bookmark_model.h" 34 #include "components/bookmarks/browser/bookmark_model.h"
34 #include "components/bookmarks/browser/bookmark_utils.h" 35 #include "components/bookmarks/browser/bookmark_utils.h"
35 #include "components/bookmarks/managed/managed_bookmark_service.h" 36 #include "components/bookmarks/managed/managed_bookmark_service.h"
36 #include "components/bookmarks/test/bookmark_test_helpers.h" 37 #include "components/bookmarks/test/bookmark_test_helpers.h"
37 #include "components/bookmarks/test/test_bookmark_client.h" 38 #include "components/bookmarks/test/test_bookmark_client.h"
38 #include "components/browser_sync/browser/profile_sync_test_util.h" 39 #include "components/browser_sync/browser/profile_sync_test_util.h"
40 #include "components/sync/api/data_type_error_handler.h"
41 #include "components/sync/api/data_type_error_handler_mock.h"
39 #include "components/sync/api/sync_error.h" 42 #include "components/sync/api/sync_error.h"
40 #include "components/sync/api/sync_merge_result.h" 43 #include "components/sync/api/sync_merge_result.h"
41 #include "components/sync/core/change_record.h" 44 #include "components/sync/core/change_record.h"
42 #include "components/sync/core/data_type_error_handler.h"
43 #include "components/sync/core/read_node.h" 45 #include "components/sync/core/read_node.h"
44 #include "components/sync/core/read_transaction.h" 46 #include "components/sync/core/read_transaction.h"
45 #include "components/sync/core/test/data_type_error_handler_mock.h"
46 #include "components/sync/core/test/test_user_share.h" 47 #include "components/sync/core/test/test_user_share.h"
47 #include "components/sync/core/write_node.h" 48 #include "components/sync/core/write_node.h"
48 #include "components/sync/core/write_transaction.h" 49 #include "components/sync/core/write_transaction.h"
49 #include "components/sync/core_impl/syncapi_internal.h" 50 #include "components/sync/core_impl/syncapi_internal.h"
50 #include "components/sync/driver/fake_sync_client.h" 51 #include "components/sync/driver/fake_sync_client.h"
51 #include "components/sync/syncable/mutable_entry.h" 52 #include "components/sync/syncable/mutable_entry.h"
52 #include "components/sync/syncable/syncable_id.h" 53 #include "components/sync/syncable/syncable_id.h"
53 #include "components/sync/syncable/syncable_util.h" 54 #include "components/sync/syncable/syncable_util.h"
54 #include "components/sync/syncable/syncable_write_transaction.h" 55 #include "components/sync/syncable/syncable_write_transaction.h"
55 #include "components/sync_bookmarks/bookmark_change_processor.h" 56 #include "components/sync_bookmarks/bookmark_change_processor.h"
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 } 539 }
539 return true; 540 return true;
540 } 541 }
541 542
542 bool AssociateModels() { 543 bool AssociateModels() {
543 DCHECK(!model_associator_); 544 DCHECK(!model_associator_);
544 545
545 // Set up model associator. 546 // Set up model associator.
546 model_associator_.reset(new BookmarkModelAssociator( 547 model_associator_.reset(new BookmarkModelAssociator(
547 model_.get(), sync_client_.get(), test_user_share_.user_share(), 548 model_.get(), sync_client_.get(), test_user_share_.user_share(),
548 &mock_error_handler_, kExpectMobileBookmarks)); 549 base::MakeUnique<syncer::DataTypeErrorHandlerMock>(),
550 kExpectMobileBookmarks));
549 551
550 local_merge_result_ = syncer::SyncMergeResult(syncer::BOOKMARKS); 552 local_merge_result_ = syncer::SyncMergeResult(syncer::BOOKMARKS);
551 syncer_merge_result_ = syncer::SyncMergeResult(syncer::BOOKMARKS); 553 syncer_merge_result_ = syncer::SyncMergeResult(syncer::BOOKMARKS);
552 int local_count_before = model_->root_node()->GetTotalNodeCount(); 554 int local_count_before = model_->root_node()->GetTotalNodeCount();
553 int syncer_count_before = GetSyncBookmarkCount(); 555 int syncer_count_before = GetSyncBookmarkCount();
554 556
555 syncer::SyncError error = model_associator_->AssociateModels( 557 syncer::SyncError error = model_associator_->AssociateModels(
556 &local_merge_result_, &syncer_merge_result_); 558 &local_merge_result_, &syncer_merge_result_);
557 if (error.IsSet()) 559 if (error.IsSet())
558 return false; 560 return false;
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 782
781 syncer::TestUserShare* test_user_share() { return &test_user_share_; } 783 syncer::TestUserShare* test_user_share() { return &test_user_share_; }
782 784
783 BookmarkChangeProcessor* change_processor() { 785 BookmarkChangeProcessor* change_processor() {
784 return change_processor_.get(); 786 return change_processor_.get();
785 } 787 }
786 788
787 void delete_change_processor() { change_processor_.reset(); } 789 void delete_change_processor() { change_processor_.reset(); }
788 790
789 void ResetChangeProcessor() { 791 void ResetChangeProcessor() {
792 std::unique_ptr<syncer::DataTypeErrorHandlerMock> error_handler =
793 base::MakeUnique<syncer::DataTypeErrorHandlerMock>();
794 mock_error_handler_ = error_handler.get();
790 change_processor_ = base::MakeUnique<BookmarkChangeProcessor>( 795 change_processor_ = base::MakeUnique<BookmarkChangeProcessor>(
791 sync_client_.get(), model_associator_.get(), &mock_error_handler_); 796 sync_client_.get(), model_associator_.get(), std::move(error_handler));
792 } 797 }
793 798
794 syncer::DataTypeErrorHandlerMock* mock_error_handler() { 799 syncer::DataTypeErrorHandlerMock* mock_error_handler() {
795 return &mock_error_handler_; 800 return mock_error_handler_;
796 } 801 }
797 802
798 void delete_model_associator() { model_associator_.reset(); } 803 void delete_model_associator() { model_associator_.reset(); }
799 804
800 BookmarkModelAssociator* model_associator() { 805 BookmarkModelAssociator* model_associator() {
801 return model_associator_.get(); 806 return model_associator_.get();
802 } 807 }
803 808
804 bookmarks::ManagedBookmarkService* managed_bookmark_service() { 809 bookmarks::ManagedBookmarkService* managed_bookmark_service() {
805 return managed_bookmark_service_.get(); 810 return managed_bookmark_service_.get();
806 } 811 }
807 812
808 private: 813 private:
814 base::TestMessageLoop message_loop_;
809 base::ScopedTempDir data_dir_; 815 base::ScopedTempDir data_dir_;
810 base::MessageLoop message_loop_;
811 browser_sync::ProfileSyncServiceBundle profile_sync_service_bundle_; 816 browser_sync::ProfileSyncServiceBundle profile_sync_service_bundle_;
812 817
813 std::unique_ptr<sync_driver::FakeSyncClient> sync_client_; 818 std::unique_ptr<sync_driver::FakeSyncClient> sync_client_;
814 std::unique_ptr<BookmarkModel> model_; 819 std::unique_ptr<BookmarkModel> model_;
815 syncer::TestUserShare test_user_share_; 820 syncer::TestUserShare test_user_share_;
816 std::unique_ptr<BookmarkChangeProcessor> change_processor_; 821 std::unique_ptr<BookmarkChangeProcessor> change_processor_;
817 StrictMock<syncer::DataTypeErrorHandlerMock> mock_error_handler_; 822 syncer::DataTypeErrorHandlerMock* mock_error_handler_;
818 std::unique_ptr<BookmarkModelAssociator> model_associator_; 823 std::unique_ptr<BookmarkModelAssociator> model_associator_;
819 std::unique_ptr<bookmarks::ManagedBookmarkService> managed_bookmark_service_; 824 std::unique_ptr<bookmarks::ManagedBookmarkService> managed_bookmark_service_;
820 825
821 syncer::SyncMergeResult local_merge_result_; 826 syncer::SyncMergeResult local_merge_result_;
822 syncer::SyncMergeResult syncer_merge_result_; 827 syncer::SyncMergeResult syncer_merge_result_;
823 828
824 DISALLOW_COPY_AND_ASSIGN(ProfileSyncServiceBookmarkTest); 829 DISALLOW_COPY_AND_ASSIGN(ProfileSyncServiceBookmarkTest);
825 }; 830 };
826 831
827 TEST_F(ProfileSyncServiceBookmarkTest, InitialState) { 832 TEST_F(ProfileSyncServiceBookmarkTest, InitialState) {
(...skipping 1757 matching lines...) Expand 10 before | Expand all | Expand 10 after
2585 EXPECT_EQ(syncer::kInvalidId, sync_id); 2590 EXPECT_EQ(syncer::kInvalidId, sync_id);
2586 2591
2587 // Verify that Sync ignores deleting this node. 2592 // Verify that Sync ignores deleting this node.
2588 model()->Remove(node); 2593 model()->Remove(node);
2589 EXPECT_EQ(sync_bookmark_count, GetSyncBookmarkCount()); 2594 EXPECT_EQ(sync_bookmark_count, GetSyncBookmarkCount());
2590 } 2595 }
2591 2596
2592 } // namespace 2597 } // namespace
2593 2598
2594 } // namespace browser_sync 2599 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698