diff options
author | erg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-08 20:44:00 +0000 |
---|---|---|
committer | erg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-08 20:44:00 +0000 |
commit | 28dc42112899ad4c118cb55ddb3af6437471243f (patch) | |
tree | 7a536b151c9e2137c9249e85b01f9e649216367c /chrome/browser | |
parent | b2c71fa0ab3d6a1ef3a8d47b4a827d3539208da6 (diff) | |
download | chromium_src-28dc42112899ad4c118cb55ddb3af6437471243f.zip chromium_src-28dc42112899ad4c118cb55ddb3af6437471243f.tar.gz chromium_src-28dc42112899ad4c118cb55ddb3af6437471243f.tar.bz2 |
Another big out-of-lining of test code. Hits a lot of gmock objects
BUG=none
TEST=compiles
Review URL: http://codereview.chromium.org/6413036
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@74168 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
15 files changed, 196 insertions, 94 deletions
diff --git a/chrome/browser/policy/asynchronous_policy_loader_unittest.cc b/chrome/browser/policy/asynchronous_policy_loader_unittest.cc index 44ab3c2..b3e4534 100644 --- a/chrome/browser/policy/asynchronous_policy_loader_unittest.cc +++ b/chrome/browser/policy/asynchronous_policy_loader_unittest.cc @@ -6,6 +6,7 @@ #include "chrome/browser/policy/asynchronous_policy_provider.h" #include "chrome/browser/policy/asynchronous_policy_test_base.h" #include "chrome/browser/policy/mock_configuration_policy_provider.h" +#include "chrome/browser/policy/mock_configuration_policy_store.h" #include "testing/gmock/include/gmock/gmock.h" using ::testing::_; diff --git a/chrome/browser/policy/asynchronous_policy_test_base.cc b/chrome/browser/policy/asynchronous_policy_test_base.cc new file mode 100644 index 0000000..eadf41f --- /dev/null +++ b/chrome/browser/policy/asynchronous_policy_test_base.cc @@ -0,0 +1,31 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/policy/asynchronous_policy_test_base.h" + +#include "chrome/browser/policy/mock_configuration_policy_store.h" + +namespace policy { + +ProviderDelegateMock::ProviderDelegateMock() + : AsynchronousPolicyProvider::Delegate() {} + +ProviderDelegateMock::~ProviderDelegateMock() {} + +AsynchronousPolicyTestBase::AsynchronousPolicyTestBase() + : ui_thread_(BrowserThread::UI, &loop_), + file_thread_(BrowserThread::FILE, &loop_) {} + +AsynchronousPolicyTestBase::~AsynchronousPolicyTestBase() {} + +void AsynchronousPolicyTestBase::SetUp() { + delegate_.reset(new ProviderDelegateMock()); + store_.reset(new MockConfigurationPolicyStore); +} + +void AsynchronousPolicyTestBase::TearDown() { + loop_.RunAllPending(); +} + +} // namespace policy diff --git a/chrome/browser/policy/asynchronous_policy_test_base.h b/chrome/browser/policy/asynchronous_policy_test_base.h index 0281afd..f567f63 100644 --- a/chrome/browser/policy/asynchronous_policy_test_base.h +++ b/chrome/browser/policy/asynchronous_policy_test_base.h @@ -9,17 +9,18 @@ #include "base/message_loop.h" #include "chrome/browser/browser_thread.h" #include "chrome/browser/policy/asynchronous_policy_provider.h" -#include "chrome/browser/policy/mock_configuration_policy_store.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" namespace policy { +class MockConfigurationPolicyStore; + // A delegate for testing that can feed arbitrary information to the loader. class ProviderDelegateMock : public AsynchronousPolicyProvider::Delegate { public: - ProviderDelegateMock() : AsynchronousPolicyProvider::Delegate() {} - virtual ~ProviderDelegateMock() {} + ProviderDelegateMock(); + virtual ~ProviderDelegateMock(); MOCK_METHOD0(Load, DictionaryValue*()); @@ -29,20 +30,12 @@ class ProviderDelegateMock : public AsynchronousPolicyProvider::Delegate { class AsynchronousPolicyTestBase : public testing::Test { public: - AsynchronousPolicyTestBase() - : ui_thread_(BrowserThread::UI, &loop_), - file_thread_(BrowserThread::FILE, &loop_) {} - - virtual ~AsynchronousPolicyTestBase() {} - - virtual void SetUp() { - delegate_.reset(new ProviderDelegateMock()); - store_.reset(new MockConfigurationPolicyStore); - } + AsynchronousPolicyTestBase(); + virtual ~AsynchronousPolicyTestBase(); - virtual void TearDown() { - loop_.RunAllPending(); - } + // testing::Test: + virtual void SetUp(); + virtual void TearDown(); protected: MessageLoop loop_; diff --git a/chrome/browser/policy/file_based_policy_provider_unittest.cc b/chrome/browser/policy/file_based_policy_provider_unittest.cc index 2948f5f..d5d0811 100644 --- a/chrome/browser/policy/file_based_policy_provider_unittest.cc +++ b/chrome/browser/policy/file_based_policy_provider_unittest.cc @@ -7,6 +7,7 @@ #include "chrome/browser/policy/configuration_policy_pref_store.h" #include "chrome/browser/policy/configuration_policy_store_interface.h" #include "chrome/browser/policy/file_based_policy_provider.h" +#include "chrome/browser/policy/mock_configuration_policy_store.h" #include "policy/policy_constants.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/chrome/browser/policy/mock_device_management_backend.cc b/chrome/browser/policy/mock_device_management_backend.cc new file mode 100644 index 0000000..c817c60 --- /dev/null +++ b/chrome/browser/policy/mock_device_management_backend.cc @@ -0,0 +1,13 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/policy/mock_device_management_backend.h" + +namespace policy { + +MockDeviceManagementBackend::MockDeviceManagementBackend() {} + +MockDeviceManagementBackend::~MockDeviceManagementBackend() {} + +} // namespace policy diff --git a/chrome/browser/policy/mock_device_management_backend.h b/chrome/browser/policy/mock_device_management_backend.h index 83323de..a684e4f 100644 --- a/chrome/browser/policy/mock_device_management_backend.h +++ b/chrome/browser/policy/mock_device_management_backend.h @@ -22,11 +22,10 @@ namespace em = enterprise_management; // Useful for unit testing when a server-based backend isn't // available. Simulates both successful and failed requests to the device // management server. -class MockDeviceManagementBackend - : public DeviceManagementBackend { +class MockDeviceManagementBackend : public DeviceManagementBackend { public: - MockDeviceManagementBackend() {} - virtual ~MockDeviceManagementBackend() {} + MockDeviceManagementBackend(); + virtual ~MockDeviceManagementBackend(); // DeviceManagementBackend method overrides: MOCK_METHOD4(ProcessRegisterRequest, void( diff --git a/chrome/browser/sync/glue/model_associator_mock.cc b/chrome/browser/sync/glue/model_associator_mock.cc new file mode 100644 index 0000000..f05ede4 --- /dev/null +++ b/chrome/browser/sync/glue/model_associator_mock.cc @@ -0,0 +1,13 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// 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/model_associator_mock.h" + +namespace browser_sync { + +ModelAssociatorMock::ModelAssociatorMock() {} + +ModelAssociatorMock::~ModelAssociatorMock() {} + +} // namespace browser_sync diff --git a/chrome/browser/sync/glue/model_associator_mock.h b/chrome/browser/sync/glue/model_associator_mock.h index 219a204..a949932 100644 --- a/chrome/browser/sync/glue/model_associator_mock.h +++ b/chrome/browser/sync/glue/model_associator_mock.h @@ -13,6 +13,9 @@ namespace browser_sync { class ModelAssociatorMock : public AssociatorInterface { public: + ModelAssociatorMock(); + virtual ~ModelAssociatorMock(); + MOCK_METHOD0(AssociateModels, bool()); MOCK_METHOD0(DisassociateModels, bool()); MOCK_METHOD1(SyncModelHasUserCreatedNodes, bool(bool* has_nodes)); diff --git a/chrome/browser/sync/profile_sync_service_unittest.cc b/chrome/browser/sync/profile_sync_service_unittest.cc index ce2134e..4540834 100644 --- a/chrome/browser/sync/profile_sync_service_unittest.cc +++ b/chrome/browser/sync/profile_sync_service_unittest.cc @@ -19,6 +19,7 @@ #include "chrome/browser/net/gaia/token_service.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/sync/abstract_profile_sync_service_test.h" #include "chrome/browser/sync/engine/syncapi.h" #include "chrome/browser/sync/glue/change_processor.h" #include "chrome/browser/sync/glue/bookmark_change_processor.h" diff --git a/chrome/browser/sync/profile_sync_test_util.cc b/chrome/browser/sync/profile_sync_test_util.cc new file mode 100644 index 0000000..a533fd4 --- /dev/null +++ b/chrome/browser/sync/profile_sync_test_util.cc @@ -0,0 +1,78 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/sync/profile_sync_test_util.h" + +#include "base/task.h" +#include "base/threading/thread.h" + +ProfileSyncServiceObserverMock::ProfileSyncServiceObserverMock() {} + +ProfileSyncServiceObserverMock::~ProfileSyncServiceObserverMock() {} + +ThreadNotificationService::ThreadNotificationService( + base::Thread* notification_thread) + : done_event_(false, false), + notification_thread_(notification_thread) {} + +void ThreadNotificationService::Init() { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + notification_thread_->message_loop()->PostTask( + FROM_HERE, + NewRunnableMethod(this, &ThreadNotificationService::InitTask)); + done_event_.Wait(); +} + +void ThreadNotificationService::TearDown() { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + notification_thread_->message_loop()->PostTask( + FROM_HERE, + NewRunnableMethod(this, + &ThreadNotificationService::TearDownTask)); + done_event_.Wait(); +} + +ThreadNotificationService::~ThreadNotificationService() {} + +void ThreadNotificationService::InitTask() { + service_.reset(new NotificationService()); + done_event_.Signal(); +} + +void ThreadNotificationService::TearDownTask() { + service_.reset(NULL); + done_event_.Signal(); +} + +ThreadNotifier::ThreadNotifier(base::Thread* notify_thread) + : done_event_(false, false), + notify_thread_(notify_thread) {} + +void ThreadNotifier::Notify(NotificationType type, + const NotificationDetails& details) { + Notify(type, NotificationService::AllSources(), details); +} + +void ThreadNotifier::Notify(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + notify_thread_->message_loop()->PostTask( + FROM_HERE, + NewRunnableMethod(this, + &ThreadNotifier::NotifyTask, + type, + source, + details)); + done_event_.Wait(); +} + +ThreadNotifier::~ThreadNotifier() {} + +void ThreadNotifier::NotifyTask(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details) { + NotificationService::current()->Notify(type, source, details); + done_event_.Signal(); +} diff --git a/chrome/browser/sync/profile_sync_test_util.h b/chrome/browser/sync/profile_sync_test_util.h index 45f6046..b7d7aa2 100644 --- a/chrome/browser/sync/profile_sync_test_util.h +++ b/chrome/browser/sync/profile_sync_test_util.h @@ -8,34 +8,21 @@ #include <string> -#include "base/logging.h" #include "base/message_loop.h" #include "base/ref_counted.h" #include "base/scoped_ptr.h" -#include "base/task.h" -#include "base/threading/thread.h" #include "base/synchronization/waitable_event.h" -#include "base/utf_string_conversions.h" #include "chrome/browser/browser_thread.h" -#include "chrome/browser/webdata/web_database.h" -#include "chrome/browser/sync/abstract_profile_sync_service_test.h" -#include "chrome/browser/sync/glue/bookmark_change_processor.h" -#include "chrome/browser/sync/glue/bookmark_data_type_controller.h" -#include "chrome/browser/sync/glue/bookmark_model_associator.h" -#include "chrome/browser/sync/glue/change_processor.h" -#include "chrome/browser/sync/glue/data_type_manager_impl.h" -#include "chrome/browser/sync/glue/sync_backend_host.h" -#include "chrome/browser/sync/profile_sync_factory.h" -#include "chrome/browser/sync/profile_sync_service.h" -#include "chrome/browser/sync/syncable/model_type.h" -#include "chrome/browser/sync/unrecoverable_error_handler.h" -#include "chrome/common/notification_details.h" +#include "chrome/browser/sync/profile_sync_service_observer.h" #include "chrome/common/notification_service.h" #include "chrome/common/notification_source.h" #include "chrome/common/notification_type.h" -#include "chrome/test/sync/test_http_bridge_factory.h" #include "testing/gmock/include/gmock/gmock.h" +namespace base { +class Thread; +} + ACTION_P(Notify, type) { NotificationService::current()->Notify(type, NotificationService::AllSources(), @@ -49,45 +36,26 @@ ACTION(QuitUIMessageLoop) { class ProfileSyncServiceObserverMock : public ProfileSyncServiceObserver { public: + ProfileSyncServiceObserverMock(); + virtual ~ProfileSyncServiceObserverMock(); + MOCK_METHOD0(OnStateChanged, void()); }; class ThreadNotificationService : public base::RefCountedThreadSafe<ThreadNotificationService> { public: - explicit ThreadNotificationService(base::Thread* notification_thread) - : done_event_(false, false), - notification_thread_(notification_thread) {} - - void Init() { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - notification_thread_->message_loop()->PostTask( - FROM_HERE, - NewRunnableMethod(this, &ThreadNotificationService::InitTask)); - done_event_.Wait(); - } - - void TearDown() { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - notification_thread_->message_loop()->PostTask( - FROM_HERE, - NewRunnableMethod(this, - &ThreadNotificationService::TearDownTask)); - done_event_.Wait(); - } + explicit ThreadNotificationService(base::Thread* notification_thread); + + void Init(); + void TearDown(); private: friend class base::RefCountedThreadSafe<ThreadNotificationService>; + virtual ~ThreadNotificationService(); - void InitTask() { - service_.reset(new NotificationService()); - done_event_.Signal(); - } - - void TearDownTask() { - service_.reset(NULL); - done_event_.Signal(); - } + void InitTask(); + void TearDownTask(); base::WaitableEvent done_event_; base::Thread* notification_thread_; @@ -97,37 +65,21 @@ class ThreadNotificationService class ThreadNotifier : // NOLINT public base::RefCountedThreadSafe<ThreadNotifier> { public: - explicit ThreadNotifier(base::Thread* notify_thread) - : done_event_(false, false), - notify_thread_(notify_thread) {} + explicit ThreadNotifier(base::Thread* notify_thread); - void Notify(NotificationType type, const NotificationDetails& details) { - Notify(type, NotificationService::AllSources(), details); - } + void Notify(NotificationType type, const NotificationDetails& details); void Notify(NotificationType type, const NotificationSource& source, - const NotificationDetails& details) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - notify_thread_->message_loop()->PostTask( - FROM_HERE, - NewRunnableMethod(this, - &ThreadNotifier::NotifyTask, - type, - source, - details)); - done_event_.Wait(); - } + const NotificationDetails& details); private: friend class base::RefCountedThreadSafe<ThreadNotifier>; + virtual ~ThreadNotifier(); void NotifyTask(NotificationType type, const NotificationSource& source, - const NotificationDetails& details) { - NotificationService::current()->Notify(type, source, details); - done_event_.Signal(); - } + const NotificationDetails& details); base::WaitableEvent done_event_; base::Thread* notify_thread_; diff --git a/chrome/browser/sync/syncable/syncable_mock.cc b/chrome/browser/sync/syncable/syncable_mock.cc new file mode 100644 index 0000000..83851cf --- /dev/null +++ b/chrome/browser/sync/syncable/syncable_mock.cc @@ -0,0 +1,16 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/sync/syncable/syncable_mock.h" + +MockDirectory::MockDirectory() { + init_kernel("myk"); +} + +MockDirectory::~MockDirectory() {} + +MockSyncableWriteTransaction::MockSyncableWriteTransaction( + Directory *directory) + : WriteTransaction(directory, syncable::UNITTEST, "dontcare.cpp", 25) { +} diff --git a/chrome/browser/sync/syncable/syncable_mock.h b/chrome/browser/sync/syncable/syncable_mock.h index 9412fe0..e6e0912 100644 --- a/chrome/browser/sync/syncable/syncable_mock.h +++ b/chrome/browser/sync/syncable/syncable_mock.h @@ -17,9 +17,9 @@ using syncable::EntryKernel; class MockDirectory : public Directory { public: - MockDirectory() { - init_kernel("myk"); - } + MockDirectory(); + virtual ~MockDirectory(); + MOCK_METHOD1(GetEntryByHandle, syncable::EntryKernel*(int64)); MOCK_METHOD2(set_last_downloadstamp, void(syncable::ModelType, int64)); @@ -30,9 +30,7 @@ class MockDirectory : public Directory { class MockSyncableWriteTransaction : public syncable::WriteTransaction { public: - explicit MockSyncableWriteTransaction(Directory *directory) : - WriteTransaction(directory, syncable::UNITTEST, "dontcare.cpp", 25) { - } + explicit MockSyncableWriteTransaction(Directory *directory); }; diff --git a/chrome/browser/sync/test_profile_sync_service.cc b/chrome/browser/sync/test_profile_sync_service.cc index e536282..ed4668e 100644 --- a/chrome/browser/sync/test_profile_sync_service.cc +++ b/chrome/browser/sync/test_profile_sync_service.cc @@ -61,6 +61,8 @@ SyncBackendHostForProfileSyncTest::SyncBackendHostForProfileSyncTest( RequestNudge()).Times(set_initial_sync_ended_on_init ? 0 : 1); } +SyncBackendHostForProfileSyncTest::~SyncBackendHostForProfileSyncTest() {} + void SyncBackendHostForProfileSyncTest::ConfigureDataTypes( const DataTypeController::TypeMap& data_type_controllers, const syncable::ModelTypeSet& types, diff --git a/chrome/browser/sync/test_profile_sync_service.h b/chrome/browser/sync/test_profile_sync_service.h index 377b05c..c027725 100644 --- a/chrome/browser/sync/test_profile_sync_service.h +++ b/chrome/browser/sync/test_profile_sync_service.h @@ -40,6 +40,7 @@ class SyncBackendHostForProfileSyncTest int num_expected_pauses, bool set_initial_sync_ended_on_init, bool synchronous_init); + virtual ~SyncBackendHostForProfileSyncTest(); MOCK_METHOD0(RequestPause, bool()); MOCK_METHOD0(RequestResume, bool()); |