Index: components/sync_driver/shared_change_processor_unittest.cc |
diff --git a/chrome/browser/sync/glue/shared_change_processor_unittest.cc b/components/sync_driver/shared_change_processor_unittest.cc |
similarity index 63% |
rename from chrome/browser/sync/glue/shared_change_processor_unittest.cc |
rename to components/sync_driver/shared_change_processor_unittest.cc |
index 46190b1a72d3f67d3c2e9c7ca62595c8233885b1..cf6ec712b51cdbb3126d602a05496b3b1eeff9c6 100644 |
--- a/chrome/browser/sync/glue/shared_change_processor_unittest.cc |
+++ b/components/sync_driver/shared_change_processor_unittest.cc |
@@ -2,7 +2,7 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "chrome/browser/sync/glue/shared_change_processor.h" |
+#include "components/sync_driver/shared_change_processor.h" |
#include <cstddef> |
@@ -10,13 +10,12 @@ |
#include "base/bind_helpers.h" |
#include "base/compiler_specific.h" |
#include "base/message_loop/message_loop.h" |
-#include "chrome/browser/sync/profile_sync_components_factory_impl.h" |
-#include "chrome/browser/sync/profile_sync_components_factory_mock.h" |
-#include "chrome/browser/sync/profile_sync_service_mock.h" |
+#include "base/threading/thread.h" |
#include "components/sync_driver/data_type_error_handler_mock.h" |
#include "components/sync_driver/generic_change_processor.h" |
#include "components/sync_driver/generic_change_processor_factory.h" |
-#include "content/public/test/test_browser_thread.h" |
+#include "components/sync_driver/sync_api_component_factory.h" |
+#include "sync/api/attachments/attachment_service_impl.h" |
#include "sync/api/fake_syncable_service.h" |
#include "testing/gmock/include/gmock/gmock.h" |
#include "testing/gtest/include/gtest/gtest.h" |
@@ -25,41 +24,42 @@ namespace browser_sync { |
namespace { |
-using content::BrowserThread; |
using ::testing::NiceMock; |
using ::testing::StrictMock; |
-ACTION_P(GetWeakPtrToSyncableService, syncable_service) { |
- // Have to do this within an Action to ensure it's not evaluated on the wrong |
- // thread. |
- return syncable_service->AsWeakPtr(); |
-} |
- |
-class SyncSharedChangeProcessorTest : public testing::Test { |
+class SyncSharedChangeProcessorTest : |
+ public testing::Test, |
+ public browser_sync::SyncApiComponentFactory { |
public: |
- SyncSharedChangeProcessorTest() |
- : ui_thread_(BrowserThread::UI, &ui_loop_), |
- db_thread_(BrowserThread::DB), |
- sync_service_(&profile_) {} |
+ SyncSharedChangeProcessorTest() : backend_thread_("dbthread"), |
+ did_connect_(false) {} |
virtual ~SyncSharedChangeProcessorTest() { |
EXPECT_FALSE(db_syncable_service_.get()); |
} |
+ virtual base::WeakPtr<syncer::SyncableService> GetSyncableServiceForType( |
+ syncer::ModelType type) OVERRIDE { |
+ return db_syncable_service_->AsWeakPtr(); |
+ } |
+ |
+ virtual scoped_ptr<syncer::AttachmentService> CreateAttachmentService( |
+ syncer::AttachmentService::Delegate* delegate) OVERRIDE { |
+ return syncer::AttachmentServiceImpl::CreateForTest(); |
+ } |
+ |
protected: |
virtual void SetUp() OVERRIDE { |
shared_change_processor_ = new SharedChangeProcessor(); |
- db_thread_.Start(); |
- EXPECT_TRUE(BrowserThread::PostTask( |
- BrowserThread::DB, |
+ ASSERT_TRUE(backend_thread_.Start()); |
+ ASSERT_TRUE(backend_thread_.message_loop_proxy()->PostTask( |
FROM_HERE, |
base::Bind(&SyncSharedChangeProcessorTest::SetUpDBSyncableService, |
base::Unretained(this)))); |
} |
virtual void TearDown() OVERRIDE { |
- EXPECT_TRUE(BrowserThread::PostTask( |
- BrowserThread::DB, |
+ EXPECT_TRUE(backend_thread_.message_loop_proxy()->PostTask( |
FROM_HERE, |
base::Bind(&SyncSharedChangeProcessorTest::TearDownDBSyncableService, |
base::Unretained(this)))); |
@@ -70,13 +70,18 @@ class SyncSharedChangeProcessorTest : public testing::Test { |
// TODO(akalin): Write deterministic tests for the destruction of |
// |shared_change_processor_| on the UI and DB threads. |
shared_change_processor_ = NULL; |
- db_thread_.Stop(); |
+ backend_thread_.Stop(); |
+ |
+ // Note: Stop() joins the threads, and that barrier prevents this read |
+ // from being moved (e.g by compiler optimization) in such a way that it |
+ // would race with the write in ConnectOnDBThread (because by this time, |
+ // everything that could have run on |backend_thread_| has done so). |
+ ASSERT_TRUE(did_connect_); |
} |
// Connect |shared_change_processor_| on the DB thread. |
void Connect() { |
- EXPECT_TRUE(BrowserThread::PostTask( |
- BrowserThread::DB, |
+ EXPECT_TRUE(backend_thread_.message_loop_proxy()->PostTask( |
FROM_HERE, |
base::Bind(&SyncSharedChangeProcessorTest::ConnectOnDBThread, |
base::Unretained(this), |
@@ -86,14 +91,14 @@ class SyncSharedChangeProcessorTest : public testing::Test { |
private: |
// Used by SetUp(). |
void SetUpDBSyncableService() { |
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
+ DCHECK(backend_thread_.message_loop_proxy()->BelongsToCurrentThread()); |
DCHECK(!db_syncable_service_.get()); |
db_syncable_service_.reset(new syncer::FakeSyncableService()); |
} |
// Used by TearDown(). |
void TearDownDBSyncableService() { |
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
+ DCHECK(backend_thread_.message_loop_proxy()->BelongsToCurrentThread()); |
DCHECK(db_syncable_service_.get()); |
db_syncable_service_.reset(); |
} |
@@ -103,32 +108,26 @@ class SyncSharedChangeProcessorTest : public testing::Test { |
// (in TearDown()). |
void ConnectOnDBThread( |
const scoped_refptr<SharedChangeProcessor>& shared_change_processor) { |
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
- EXPECT_CALL(sync_factory_, GetSyncableServiceForType(syncer::AUTOFILL)). |
- WillOnce(GetWeakPtrToSyncableService(db_syncable_service_.get())); |
+ DCHECK(backend_thread_.message_loop_proxy()->BelongsToCurrentThread()); |
syncer::UserShare share; |
- EXPECT_CALL(sync_service_, GetUserShare()).WillOnce( |
- ::testing::Return(&share)); |
EXPECT_TRUE(shared_change_processor->Connect( |
- &sync_factory_, |
+ this, |
&processor_factory_, |
- sync_service_.GetUserShare(), |
+ &share, |
&error_handler_, |
syncer::AUTOFILL, |
base::WeakPtr<syncer::SyncMergeResult>())); |
+ did_connect_ = true; |
} |
- base::MessageLoopForUI ui_loop_; |
- content::TestBrowserThread ui_thread_; |
- content::TestBrowserThread db_thread_; |
+ base::MessageLoop frontend_loop_; |
+ base::Thread backend_thread_; |
scoped_refptr<SharedChangeProcessor> shared_change_processor_; |
- NiceMock<ProfileSyncComponentsFactoryMock> sync_factory_; |
- TestingProfile profile_; |
- NiceMock<ProfileSyncServiceMock> sync_service_; |
StrictMock<DataTypeErrorHandlerMock> error_handler_; |
GenericChangeProcessorFactory processor_factory_; |
+ bool did_connect_; |
// Used only on DB thread. |
scoped_ptr<syncer::FakeSyncableService> db_syncable_service_; |