| 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 #include "components/sync_bookmarks/bookmark_data_type_controller.h" | 5 #include "components/sync_bookmarks/bookmark_data_type_controller.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 #include "components/sync/driver/data_type_controller_mock.h" | 23 #include "components/sync/driver/data_type_controller_mock.h" |
| 24 #include "components/sync/driver/fake_sync_client.h" | 24 #include "components/sync/driver/fake_sync_client.h" |
| 25 #include "components/sync/driver/fake_sync_service.h" | 25 #include "components/sync/driver/fake_sync_service.h" |
| 26 #include "components/sync/driver/model_associator_mock.h" | 26 #include "components/sync/driver/model_associator_mock.h" |
| 27 #include "components/sync/driver/sync_api_component_factory_mock.h" | 27 #include "components/sync/driver/sync_api_component_factory_mock.h" |
| 28 #include "testing/gmock/include/gmock/gmock.h" | 28 #include "testing/gmock/include/gmock/gmock.h" |
| 29 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
| 30 | 30 |
| 31 using bookmarks::BookmarkModel; | 31 using bookmarks::BookmarkModel; |
| 32 using sync_bookmarks::BookmarkDataTypeController; | 32 using sync_bookmarks::BookmarkDataTypeController; |
| 33 using sync_driver::ChangeProcessorMock; | 33 using syncer::ChangeProcessorMock; |
| 34 using sync_driver::DataTypeController; | 34 using syncer::DataTypeController; |
| 35 using sync_driver::ModelAssociatorMock; | 35 using syncer::ModelAssociatorMock; |
| 36 using sync_driver::ModelLoadCallbackMock; | 36 using syncer::ModelLoadCallbackMock; |
| 37 using sync_driver::StartCallbackMock; | 37 using syncer::StartCallbackMock; |
| 38 using testing::_; | 38 using testing::_; |
| 39 using testing::DoAll; | 39 using testing::DoAll; |
| 40 using testing::InvokeWithoutArgs; | 40 using testing::InvokeWithoutArgs; |
| 41 using testing::Return; | 41 using testing::Return; |
| 42 using testing::SetArgumentPointee; | 42 using testing::SetArgumentPointee; |
| 43 | 43 |
| 44 namespace { | 44 namespace { |
| 45 | 45 |
| 46 class HistoryMock : public history::HistoryService { | 46 class HistoryMock : public history::HistoryService { |
| 47 public: | 47 public: |
| 48 HistoryMock() : history::HistoryService() {} | 48 HistoryMock() : history::HistoryService() {} |
| 49 MOCK_METHOD0(BackendLoaded, bool(void)); | 49 MOCK_METHOD0(BackendLoaded, bool(void)); |
| 50 | 50 |
| 51 ~HistoryMock() override {} | 51 ~HistoryMock() override {} |
| 52 }; | 52 }; |
| 53 | 53 |
| 54 } // namespace | 54 } // namespace |
| 55 | 55 |
| 56 class SyncBookmarkDataTypeControllerTest : public testing::Test, | 56 class SyncBookmarkDataTypeControllerTest : public testing::Test, |
| 57 public sync_driver::FakeSyncClient { | 57 public syncer::FakeSyncClient { |
| 58 public: | 58 public: |
| 59 SyncBookmarkDataTypeControllerTest() {} | 59 SyncBookmarkDataTypeControllerTest() {} |
| 60 | 60 |
| 61 // FakeSyncClient overrides. | 61 // FakeSyncClient overrides. |
| 62 BookmarkModel* GetBookmarkModel() override { return bookmark_model_.get(); } | 62 BookmarkModel* GetBookmarkModel() override { return bookmark_model_.get(); } |
| 63 history::HistoryService* GetHistoryService() override { | 63 history::HistoryService* GetHistoryService() override { |
| 64 return history_service_.get(); | 64 return history_service_.get(); |
| 65 } | 65 } |
| 66 sync_driver::SyncService* GetSyncService() override { | 66 syncer::SyncService* GetSyncService() override { return &service_; } |
| 67 return &service_; | 67 syncer::SyncApiComponentFactory* GetSyncApiComponentFactory() override { |
| 68 } | |
| 69 sync_driver::SyncApiComponentFactory* GetSyncApiComponentFactory() override { | |
| 70 return profile_sync_factory_.get(); | 68 return profile_sync_factory_.get(); |
| 71 } | 69 } |
| 72 | 70 |
| 73 void SetUp() override { | 71 void SetUp() override { |
| 74 model_associator_ = new ModelAssociatorMock(); | 72 model_associator_ = new ModelAssociatorMock(); |
| 75 change_processor_ = new ChangeProcessorMock(); | 73 change_processor_ = new ChangeProcessorMock(); |
| 76 history_service_.reset(new HistoryMock()); | 74 history_service_.reset(new HistoryMock()); |
| 77 profile_sync_factory_.reset( | 75 profile_sync_factory_.reset(new syncer::SyncApiComponentFactoryMock( |
| 78 new SyncApiComponentFactoryMock(model_associator_, | 76 model_associator_, change_processor_)); |
| 79 change_processor_)); | |
| 80 bookmark_dtc_.reset( | 77 bookmark_dtc_.reset( |
| 81 new BookmarkDataTypeController(base::Bind(&base::DoNothing), this)); | 78 new BookmarkDataTypeController(base::Bind(&base::DoNothing), this)); |
| 82 } | 79 } |
| 83 | 80 |
| 84 protected: | 81 protected: |
| 85 enum BookmarkLoadPolicy { | 82 enum BookmarkLoadPolicy { |
| 86 DONT_LOAD_MODEL, | 83 DONT_LOAD_MODEL, |
| 87 LOAD_MODEL, | 84 LOAD_MODEL, |
| 88 }; | 85 }; |
| 89 | 86 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 base::Bind(&StartCallbackMock::Run, | 124 base::Bind(&StartCallbackMock::Run, |
| 128 base::Unretained(&start_callback_))); | 125 base::Unretained(&start_callback_))); |
| 129 base::RunLoop().RunUntilIdle(); | 126 base::RunLoop().RunUntilIdle(); |
| 130 } | 127 } |
| 131 | 128 |
| 132 void NotifyHistoryServiceLoaded() { | 129 void NotifyHistoryServiceLoaded() { |
| 133 history_service_->NotifyHistoryServiceLoaded(); | 130 history_service_->NotifyHistoryServiceLoaded(); |
| 134 } | 131 } |
| 135 | 132 |
| 136 base::MessageLoop message_loop_; | 133 base::MessageLoop message_loop_; |
| 137 std::unique_ptr<SyncApiComponentFactoryMock> profile_sync_factory_; | 134 std::unique_ptr<syncer::SyncApiComponentFactoryMock> profile_sync_factory_; |
| 138 std::unique_ptr<BookmarkModel> bookmark_model_; | 135 std::unique_ptr<BookmarkModel> bookmark_model_; |
| 139 std::unique_ptr<HistoryMock> history_service_; | 136 std::unique_ptr<HistoryMock> history_service_; |
| 140 std::unique_ptr<BookmarkDataTypeController> bookmark_dtc_; | 137 std::unique_ptr<BookmarkDataTypeController> bookmark_dtc_; |
| 141 sync_driver::FakeSyncService service_; | 138 syncer::FakeSyncService service_; |
| 142 ModelAssociatorMock* model_associator_; | 139 ModelAssociatorMock* model_associator_; |
| 143 ChangeProcessorMock* change_processor_; | 140 ChangeProcessorMock* change_processor_; |
| 144 StartCallbackMock start_callback_; | 141 StartCallbackMock start_callback_; |
| 145 ModelLoadCallbackMock model_load_callback_; | 142 ModelLoadCallbackMock model_load_callback_; |
| 146 }; | 143 }; |
| 147 | 144 |
| 148 TEST_F(SyncBookmarkDataTypeControllerTest, StartDependentsReady) { | 145 TEST_F(SyncBookmarkDataTypeControllerTest, StartDependentsReady) { |
| 149 CreateBookmarkModel(LOAD_MODEL); | 146 CreateBookmarkModel(LOAD_MODEL); |
| 150 SetStartExpectations(); | 147 SetStartExpectations(); |
| 151 SetAssociateExpectations(); | 148 SetAssociateExpectations(); |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 SetStopExpectations(); | 290 SetStopExpectations(); |
| 294 | 291 |
| 295 EXPECT_EQ(DataTypeController::NOT_RUNNING, bookmark_dtc_->state()); | 292 EXPECT_EQ(DataTypeController::NOT_RUNNING, bookmark_dtc_->state()); |
| 296 | 293 |
| 297 EXPECT_CALL(start_callback_, Run(DataTypeController::OK, _, _)); | 294 EXPECT_CALL(start_callback_, Run(DataTypeController::OK, _, _)); |
| 298 Start(); | 295 Start(); |
| 299 EXPECT_EQ(DataTypeController::RUNNING, bookmark_dtc_->state()); | 296 EXPECT_EQ(DataTypeController::RUNNING, bookmark_dtc_->state()); |
| 300 bookmark_dtc_->Stop(); | 297 bookmark_dtc_->Stop(); |
| 301 EXPECT_EQ(DataTypeController::NOT_RUNNING, bookmark_dtc_->state()); | 298 EXPECT_EQ(DataTypeController::NOT_RUNNING, bookmark_dtc_->state()); |
| 302 } | 299 } |
| OLD | NEW |