| 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 "chrome/browser/sync/glue/shared_change_processor.h" | 5 #include "chrome/browser/sync/glue/shared_change_processor.h" |
| 6 | 6 |
| 7 #include <cstddef> | 7 #include <cstddef> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
| 13 #include "chrome/browser/sync/api/syncable_service_mock.h" | 13 #include "chrome/browser/sync/api/fake_syncable_service.h" |
| 14 #include "chrome/browser/sync/profile_sync_components_factory_mock.h" | 14 #include "chrome/browser/sync/profile_sync_components_factory_mock.h" |
| 15 #include "chrome/browser/sync/glue/data_type_error_handler_mock.h" | 15 #include "chrome/browser/sync/glue/data_type_error_handler_mock.h" |
| 16 #include "chrome/browser/sync/profile_sync_components_factory_impl.h" | 16 #include "chrome/browser/sync/profile_sync_components_factory_impl.h" |
| 17 #include "chrome/browser/sync/profile_sync_service_mock.h" | 17 #include "chrome/browser/sync/profile_sync_service_mock.h" |
| 18 #include "content/test/test_browser_thread.h" | 18 #include "content/test/test_browser_thread.h" |
| 19 #include "testing/gmock/include/gmock/gmock.h" | 19 #include "testing/gmock/include/gmock/gmock.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 21 | 21 |
| 22 namespace browser_sync { | 22 namespace browser_sync { |
| 23 | 23 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 34 } | 34 } |
| 35 | 35 |
| 36 class SyncSharedChangeProcessorTest : public testing::Test { | 36 class SyncSharedChangeProcessorTest : public testing::Test { |
| 37 public: | 37 public: |
| 38 SyncSharedChangeProcessorTest() | 38 SyncSharedChangeProcessorTest() |
| 39 : ui_thread_(BrowserThread::UI, &ui_loop_), | 39 : ui_thread_(BrowserThread::UI, &ui_loop_), |
| 40 db_thread_(BrowserThread::DB), | 40 db_thread_(BrowserThread::DB), |
| 41 db_syncable_service_(NULL) {} | 41 db_syncable_service_(NULL) {} |
| 42 | 42 |
| 43 virtual ~SyncSharedChangeProcessorTest() { | 43 virtual ~SyncSharedChangeProcessorTest() { |
| 44 EXPECT_FALSE(db_syncable_service_); | 44 EXPECT_FALSE(db_syncable_service_.get()); |
| 45 } | 45 } |
| 46 | 46 |
| 47 protected: | 47 protected: |
| 48 virtual void SetUp() OVERRIDE { | 48 virtual void SetUp() OVERRIDE { |
| 49 shared_change_processor_ = new SharedChangeProcessor(); | 49 shared_change_processor_ = new SharedChangeProcessor(); |
| 50 db_thread_.Start(); | 50 db_thread_.Start(); |
| 51 EXPECT_TRUE(BrowserThread::PostTask( | 51 EXPECT_TRUE(BrowserThread::PostTask( |
| 52 BrowserThread::DB, | 52 BrowserThread::DB, |
| 53 FROM_HERE, | 53 FROM_HERE, |
| 54 base::Bind(&SyncSharedChangeProcessorTest::SetUpDBSyncableService, | 54 base::Bind(&SyncSharedChangeProcessorTest::SetUpDBSyncableService, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 78 FROM_HERE, | 78 FROM_HERE, |
| 79 base::Bind(&SyncSharedChangeProcessorTest::ConnectOnDBThread, | 79 base::Bind(&SyncSharedChangeProcessorTest::ConnectOnDBThread, |
| 80 base::Unretained(this), | 80 base::Unretained(this), |
| 81 shared_change_processor_))); | 81 shared_change_processor_))); |
| 82 } | 82 } |
| 83 | 83 |
| 84 private: | 84 private: |
| 85 // Used by SetUp(). | 85 // Used by SetUp(). |
| 86 void SetUpDBSyncableService() { | 86 void SetUpDBSyncableService() { |
| 87 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 87 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 88 DCHECK(!db_syncable_service_); | 88 DCHECK(!db_syncable_service_.get()); |
| 89 db_syncable_service_ = new NiceMock<SyncableServiceMock>(); | 89 db_syncable_service_.reset(new FakeSyncableService()); |
| 90 } | 90 } |
| 91 | 91 |
| 92 // Used by TearDown(). | 92 // Used by TearDown(). |
| 93 void TearDownDBSyncableService() { | 93 void TearDownDBSyncableService() { |
| 94 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 94 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 95 DCHECK(db_syncable_service_); | 95 DCHECK(db_syncable_service_.get()); |
| 96 delete db_syncable_service_; | 96 db_syncable_service_.reset(); |
| 97 db_syncable_service_ = NULL; | |
| 98 } | 97 } |
| 99 | 98 |
| 100 // Used by Connect(). The SharedChangeProcessor is passed in | 99 // Used by Connect(). The SharedChangeProcessor is passed in |
| 101 // because we modify |shared_change_processor_| on the main thread | 100 // because we modify |shared_change_processor_| on the main thread |
| 102 // (in TearDown()). | 101 // (in TearDown()). |
| 103 void ConnectOnDBThread( | 102 void ConnectOnDBThread( |
| 104 const scoped_refptr<SharedChangeProcessor>& shared_change_processor) { | 103 const scoped_refptr<SharedChangeProcessor>& shared_change_processor) { |
| 105 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 104 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 106 EXPECT_CALL(sync_factory_, GetSyncableServiceForType(syncable::AUTOFILL)). | 105 EXPECT_CALL(sync_factory_, GetSyncableServiceForType(syncable::AUTOFILL)). |
| 107 WillOnce(GetWeakPtrToSyncableService(db_syncable_service_)); | 106 WillOnce(GetWeakPtrToSyncableService(db_syncable_service_.get())); |
| 108 EXPECT_TRUE(shared_change_processor->Connect(&sync_factory_, | 107 EXPECT_TRUE(shared_change_processor->Connect(&sync_factory_, |
| 109 &sync_service_, | 108 &sync_service_, |
| 110 &error_handler_, | 109 &error_handler_, |
| 111 syncable::AUTOFILL)); | 110 syncable::AUTOFILL)); |
| 112 } | 111 } |
| 113 | 112 |
| 114 MessageLoopForUI ui_loop_; | 113 MessageLoopForUI ui_loop_; |
| 115 content::TestBrowserThread ui_thread_; | 114 content::TestBrowserThread ui_thread_; |
| 116 content::TestBrowserThread db_thread_; | 115 content::TestBrowserThread db_thread_; |
| 117 | 116 |
| 118 scoped_refptr<SharedChangeProcessor> shared_change_processor_; | 117 scoped_refptr<SharedChangeProcessor> shared_change_processor_; |
| 119 NiceMock<ProfileSyncComponentsFactoryMock> sync_factory_; | 118 NiceMock<ProfileSyncComponentsFactoryMock> sync_factory_; |
| 120 NiceMock<ProfileSyncServiceMock> sync_service_; | 119 NiceMock<ProfileSyncServiceMock> sync_service_; |
| 121 StrictMock<DataTypeErrorHandlerMock> error_handler_; | 120 StrictMock<DataTypeErrorHandlerMock> error_handler_; |
| 122 | 121 |
| 123 // Used only on DB thread. | 122 // Used only on DB thread. |
| 124 NiceMock<SyncableServiceMock>* db_syncable_service_; | 123 scoped_ptr<FakeSyncableService> db_syncable_service_; |
| 125 }; | 124 }; |
| 126 | 125 |
| 127 // Simply connect the shared change processor. It should succeed, and | 126 // Simply connect the shared change processor. It should succeed, and |
| 128 // nothing further should happen. | 127 // nothing further should happen. |
| 129 TEST_F(SyncSharedChangeProcessorTest, Basic) { | 128 TEST_F(SyncSharedChangeProcessorTest, Basic) { |
| 130 Connect(); | 129 Connect(); |
| 131 } | 130 } |
| 132 | 131 |
| 133 } // namespace | 132 } // namespace |
| 134 | 133 |
| 135 } // namespace browser_sync | 134 } // namespace browser_sync |
| OLD | NEW |